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 "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();
}

View File

@ -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();
}

View File

@ -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);

View File

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

View File

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

View File

@ -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<UStaticMeshComponent> StaticMeshComponent;
FTimerHandle DespawnHandle;
public:
ALMItemDrop();
virtual void BeginPlay() override;
UFUNCTION(BlueprintCallable)
virtual void ConsumePack(ALMPlayer* Player);
UFUNCTION(BlueprintImplementableEvent)
void OnPackConsumed();
protected:
UFUNCTION(BlueprintCallable)