From 4f8ab3697abdb5aa0ca9628f8dcb890c5fd348c9 Mon Sep 17 00:00:00 2001 From: TjgL Date: Fri, 21 Mar 2025 10:17:07 +0100 Subject: [PATCH] Implemented item pack effect Signed-off-by: TjgL --- Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp | 12 ++++++++++++ Source/LegumeMix/Private/LMHealthPack.cpp | 10 ++++++++++ Source/LegumeMix/Private/LMItemDrop.cpp | 4 ++++ Source/LegumeMix/Public/Ammo/LMAmmoPack.h | 2 ++ Source/LegumeMix/Public/LMHealthPack.h | 2 ++ Source/LegumeMix/Public/LMItemDrop.h | 11 +++++++++-- 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp b/Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp index cfc4560..5986eed 100644 --- a/Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp +++ b/Source/LegumeMix/Private/Ammo/LMAmmoPack.cpp @@ -3,8 +3,20 @@ #include "Ammo/LMAmmoPack.h" +#include "Player/LMPlayer.h" +#include "Weapon/LMWeaponManager.h" + ALMAmmoPack::ALMAmmoPack() { PrimaryActorTick.bCanEverTick = false; } + +void ALMAmmoPack::ConsumePack(ALMPlayer* Player) +{ + Super::ConsumePack(Player); + + Player->GetWeaponManager()->AddAmmoType(AmmoType, AmmoCount); + OnPackConsumed(); + Despawn(); +} diff --git a/Source/LegumeMix/Private/LMHealthPack.cpp b/Source/LegumeMix/Private/LMHealthPack.cpp index 51b9614..7adcdaa 100644 --- a/Source/LegumeMix/Private/LMHealthPack.cpp +++ b/Source/LegumeMix/Private/LMHealthPack.cpp @@ -3,9 +3,19 @@ #include "LMHealthPack.h" +#include "Player/LMHealthComponent.h" +#include "Player/LMPlayer.h" + ALMHealthPack::ALMHealthPack() { PrimaryActorTick.bCanEverTick = false; } +void ALMHealthPack::ConsumePack(ALMPlayer* Player) +{ + Player->GetHealthComponent()->AddHealth(HealthGain); + OnPackConsumed(); + Despawn(); +} + diff --git a/Source/LegumeMix/Private/LMItemDrop.cpp b/Source/LegumeMix/Private/LMItemDrop.cpp index de74b26..36448f4 100644 --- a/Source/LegumeMix/Private/LMItemDrop.cpp +++ b/Source/LegumeMix/Private/LMItemDrop.cpp @@ -17,6 +17,10 @@ void ALMItemDrop::BeginPlay() GetWorldTimerManager().SetTimer(DespawnHandle, this, &ALMItemDrop::Despawn, TimeBeforeDespawn); } +void ALMItemDrop::ConsumePack(ALMPlayer* Player) +{ +} + void ALMItemDrop::Despawn() { GetWorldTimerManager().ClearTimer(DespawnHandle); diff --git a/Source/LegumeMix/Public/Ammo/LMAmmoPack.h b/Source/LegumeMix/Public/Ammo/LMAmmoPack.h index 71d1d65..835babd 100644 --- a/Source/LegumeMix/Public/Ammo/LMAmmoPack.h +++ b/Source/LegumeMix/Public/Ammo/LMAmmoPack.h @@ -21,4 +21,6 @@ public: public: ALMAmmoPack(); + + virtual void ConsumePack(ALMPlayer* Player) override; }; diff --git a/Source/LegumeMix/Public/LMHealthPack.h b/Source/LegumeMix/Public/LMHealthPack.h index ef6f956..db6a4fd 100644 --- a/Source/LegumeMix/Public/LMHealthPack.h +++ b/Source/LegumeMix/Public/LMHealthPack.h @@ -17,4 +17,6 @@ public: public: ALMHealthPack(); + + virtual void ConsumePack(ALMPlayer* Player) override; }; diff --git a/Source/LegumeMix/Public/LMItemDrop.h b/Source/LegumeMix/Public/LMItemDrop.h index 423c7dd..f11843c 100644 --- a/Source/LegumeMix/Public/LMItemDrop.h +++ b/Source/LegumeMix/Public/LMItemDrop.h @@ -6,6 +6,7 @@ #include "GameFramework/Actor.h" #include "LMItemDrop.generated.h" +class ALMPlayer; class ULMDropData; UCLASS() @@ -17,15 +18,21 @@ protected: UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix) float TimeBeforeDespawn = 30.f; + FTimerHandle DespawnHandle; + private: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true)) TObjectPtr StaticMeshComponent; - - FTimerHandle DespawnHandle; public: ALMItemDrop(); virtual void BeginPlay() override; + + UFUNCTION(BlueprintCallable) + virtual void ConsumePack(ALMPlayer* Player); + + UFUNCTION(BlueprintImplementableEvent) + void OnPackConsumed(); protected: UFUNCTION(BlueprintCallable)