Implemented item pack effect

Signed-off-by: TjgL <lithmoneo@gmail.com>
This commit is contained in:
TjgL 2025-03-21 10:17:07 +01:00
parent d221a9ffcc
commit 4f8ab3697a
6 changed files with 39 additions and 2 deletions

View File

@ -3,8 +3,20 @@
#include "Ammo/LMAmmoPack.h" #include "Ammo/LMAmmoPack.h"
#include "Player/LMPlayer.h"
#include "Weapon/LMWeaponManager.h"
ALMAmmoPack::ALMAmmoPack() ALMAmmoPack::ALMAmmoPack()
{ {
PrimaryActorTick.bCanEverTick = false; PrimaryActorTick.bCanEverTick = false;
} }
void ALMAmmoPack::ConsumePack(ALMPlayer* Player)
{
Super::ConsumePack(Player);
Player->GetWeaponManager()->AddAmmoType(AmmoType, AmmoCount);
OnPackConsumed();
Despawn();
}

View File

@ -3,9 +3,19 @@
#include "LMHealthPack.h" #include "LMHealthPack.h"
#include "Player/LMHealthComponent.h"
#include "Player/LMPlayer.h"
ALMHealthPack::ALMHealthPack() ALMHealthPack::ALMHealthPack()
{ {
PrimaryActorTick.bCanEverTick = false; PrimaryActorTick.bCanEverTick = false;
} }
void ALMHealthPack::ConsumePack(ALMPlayer* Player)
{
Player->GetHealthComponent()->AddHealth(HealthGain);
OnPackConsumed();
Despawn();
}

View File

@ -17,6 +17,10 @@ void ALMItemDrop::BeginPlay()
GetWorldTimerManager().SetTimer(DespawnHandle, this, &ALMItemDrop::Despawn, TimeBeforeDespawn); GetWorldTimerManager().SetTimer(DespawnHandle, this, &ALMItemDrop::Despawn, TimeBeforeDespawn);
} }
void ALMItemDrop::ConsumePack(ALMPlayer* Player)
{
}
void ALMItemDrop::Despawn() void ALMItemDrop::Despawn()
{ {
GetWorldTimerManager().ClearTimer(DespawnHandle); GetWorldTimerManager().ClearTimer(DespawnHandle);

View File

@ -21,4 +21,6 @@ public:
public: public:
ALMAmmoPack(); ALMAmmoPack();
virtual void ConsumePack(ALMPlayer* Player) override;
}; };

View File

@ -17,4 +17,6 @@ public:
public: public:
ALMHealthPack(); ALMHealthPack();
virtual void ConsumePack(ALMPlayer* Player) override;
}; };

View File

@ -6,6 +6,7 @@
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include "LMItemDrop.generated.h" #include "LMItemDrop.generated.h"
class ALMPlayer;
class ULMDropData; class ULMDropData;
UCLASS() UCLASS()
@ -17,16 +18,22 @@ protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix) UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix)
float TimeBeforeDespawn = 30.f; float TimeBeforeDespawn = 30.f;
FTimerHandle DespawnHandle;
private: private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true)) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Legumix, meta = (AllowPrivateAccess = true))
TObjectPtr<UStaticMeshComponent> StaticMeshComponent; TObjectPtr<UStaticMeshComponent> StaticMeshComponent;
FTimerHandle DespawnHandle;
public: public:
ALMItemDrop(); ALMItemDrop();
virtual void BeginPlay() override; virtual void BeginPlay() override;
UFUNCTION(BlueprintCallable)
virtual void ConsumePack(ALMPlayer* Player);
UFUNCTION(BlueprintImplementableEvent)
void OnPackConsumed();
protected: protected:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void Despawn(); void Despawn();