From ad2d62dc73fc3f2cd4835215b606f5f023dc048e Mon Sep 17 00:00:00 2001 From: MARCEL HARA Date: Thu, 23 Nov 2023 12:03:15 +0000 Subject: [PATCH] Added Start Functionality for weapons to inventory --- .../Blueprints/BP_FirstPersonCharacter.uasset | 4 ++-- .../EndlessVendettaCharacter.cpp | 2 ++ .../EndlessVendettaCharacter.h | 3 +++ .../Inventory/InventoryComponent.cpp | 22 ++++++++++++++++++- .../Inventory/InventoryComponent.h | 10 +++++++-- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index 8e4ecbd1..0fe23856 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:722ad362b974f8cd884e1852c963e27f75f4ed6f285759adbd3c3571b1f477c0 -size 57740 +oid sha256:c3117b45f4b1be99dd1bd0cdd1cb1d167237a1105a9c1ce14bc1c6f15a095551 +size 58414 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 601240df..7ea63865 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -65,6 +65,8 @@ void AEndlessVendettaCharacter::BeginPlay() GadgetManager->SpawnGadgetsOnBeginPlay(Cast(PlayersCamera)); break; } + + InventoryComponent = Cast(GetWorld()->GetFirstPlayerController()->GetComponentByClass(UInventoryComponent::StaticClass())); } void AEndlessVendettaCharacter::Tick(float DeltaTime) diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index 106416a8..33a2d04b 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -8,6 +8,7 @@ #include "InputActionValue.h" #include "Components/ArrowComponent.h" #include "GadgetSystem/GadgetManager.h" + #include "EndlessVendettaCharacter.generated.h" class UWeaponInventory; @@ -200,4 +201,6 @@ public: // Returns true if successfully changed to a new gadget, can fail if the target gadget to replace is being used bool UpdateGadgetType(TSubclassOf NewGadgetClass); + + UInventoryComponent* InventoryComponent; }; diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.cpp b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.cpp index 2d09885f..ff316f09 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.cpp @@ -19,7 +19,7 @@ UInventoryComponent::UInventoryComponent() void UInventoryComponent::InitializeComponent() { Super::InitializeComponent(); - PlayerCharacter = Cast(GetOwner()); + PlayerCharacter = GetOwner(); ItemToPickup = nullptr; } @@ -188,6 +188,26 @@ void UInventoryComponent::UpdateInventorySize_Implementation(const int _Columns, InventoryItems.SetNum(Columns * Rows); } +void UInventoryComponent::SetPrimaryWeapon(AActor* const _PrimaryWeapon) +{ + PrimaryWeapon = _PrimaryWeapon; +} + +AActor* UInventoryComponent::GetPrimaryWeapon() const +{ + return PrimaryWeapon; +} + +void UInventoryComponent::SetSecondaryWeapon(AActor* const _SecondaryWeapon) +{ + SecondaryWeapon = _SecondaryWeapon; +} + +AActor* UInventoryComponent::GetSecondaryWeapon() const +{ + return SecondaryWeapon; +} + bool UInventoryComponent::IsTileValid(const FInventoryTile InventoryTile) const { if (InventoryTile.X >= 0 && InventoryTile.Y >= 0 && InventoryTile.X < Columns && InventoryTile.Y < Columns && InventoryTile.Y <= Rows) diff --git a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h index 813a181b..84810c30 100644 --- a/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h +++ b/EndlessVendetta/Source/EndlessVendetta/Inventory/InventoryComponent.h @@ -5,7 +5,6 @@ #include "CoreMinimal.h" #include "Components/ActorComponent.h" #include "InventoryStructs.h" -#include "EndlessVendetta/EndlessVendettaCharacter.h" #include "InventoryComponent.generated.h" @@ -64,14 +63,21 @@ public: void UpdateInventorySize(const int _Columns, const int _Rows); virtual void UpdateInventorySize_Implementation(const int _Columns, const int _Rows); + void SetPrimaryWeapon(AActor* const _PrimaryWeapon); + AActor* GetPrimaryWeapon() const; + void SetSecondaryWeapon(AActor* const _SecondaryWeapon); + AActor* GetSecondaryWeapon() const; + private: bool IsTileValid(const FInventoryTile InventoryTile) const; UPROPERTY() - AEndlessVendettaCharacter* PlayerCharacter; + AActor* PlayerCharacter; UPROPERTY() AActor* ItemToPickup; bool IsDirty = false; UPROPERTY() TArray InventoryItems; + AActor* PrimaryWeapon; + AActor* SecondaryWeapon; };