From 04512d17172c0cb1b6c25c5b38f8c2af43e0c737 Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 13 Sep 2023 16:53:39 +0100 Subject: [PATCH] Add ThrowableInventory to NakatomiCharacter --- Source/Nakatomi/NakatomiCharacter.cpp | 18 ++++++++++++++++++ Source/Nakatomi/NakatomiCharacter.h | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/Source/Nakatomi/NakatomiCharacter.cpp b/Source/Nakatomi/NakatomiCharacter.cpp index d759281..0824d72 100644 --- a/Source/Nakatomi/NakatomiCharacter.cpp +++ b/Source/Nakatomi/NakatomiCharacter.cpp @@ -214,6 +214,24 @@ void ANakatomiCharacter::OnFire() OnFired.ExecuteIfBound(); } +AThrowable* ANakatomiCharacter::PopThrowableFromInventory() +{ + if (ThrowableInventory.Num() > 0) + { + return ThrowableInventory.Pop(); + } + + return {}; +} + +void ANakatomiCharacter::PushThrowableToInventory(AThrowable* Throwable) +{ + if (ThrowableInventory.Num() < MaximumThrowableInventorySize) + { + ThrowableInventory.Push(Throwable); + } +} + void ANakatomiCharacter::CalculateHits(TArray* hits) { } diff --git a/Source/Nakatomi/NakatomiCharacter.h b/Source/Nakatomi/NakatomiCharacter.h index 49eef2b..22e9498 100644 --- a/Source/Nakatomi/NakatomiCharacter.h +++ b/Source/Nakatomi/NakatomiCharacter.h @@ -5,6 +5,7 @@ #include "CoreMinimal.h" #include "GameFramework/Character.h" #include "HealthComponent.h" +#include "Throwable.h" #include "Weapon.h" #include "NakatomiCharacter.generated.h" @@ -34,12 +35,18 @@ public: UPROPERTY() AWeapon* CurrentWeapon = nullptr; + UPROPERTY() + TArray ThrowableInventory; + private: UPROPERTY(VisibleDefaultsOnly) UHealthComponent* HealthComponent = nullptr; int CurrentInventorySlot = 0; + UPROPERTY(EditDefaultsOnly) + int MaximumThrowableInventorySize = 4; + public: // Sets default values for this character's properties ANakatomiCharacter(); @@ -87,6 +94,10 @@ public: virtual void OnFire(); + AThrowable* PopThrowableFromInventory(); + + void PushThrowableToInventory(AThrowable* Throwable); + protected: virtual void CalculateHits(TArray* hits);