Added timer for reload

This commit is contained in:
TjgL 2025-01-24 11:39:23 +01:00
parent 954ae7c36d
commit 8a385a3f86
4 changed files with 18 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@ -93,12 +93,19 @@ bool ALMWeaponBase::DefaultReload()
// TODO: Use Animations // TODO: Use Animations
OnDefaultReload(); OnDefaultReload();
GetWorldTimerManager().SetTimer(ReloadTimer, this, &ALMWeaponBase::AllowRefire, ReloadDelay);
return true; return true;
} }
void ALMWeaponBase::AllowRefire() void ALMWeaponBase::AllowRefire()
{ {
GetWorldTimerManager().ClearTimer(FireTimer); // TODO : improve this
if (FireTimer.IsValid())
GetWorldTimerManager().ClearTimer(FireTimer);
else if (ReloadTimer.IsValid())
GetWorldTimerManager().ClearTimer(ReloadTimer);
State = EWeaponState::EWS_Idle; State = EWeaponState::EWS_Idle;
if (ClipAmmo <= 0) if (ClipAmmo <= 0)

View File

@ -48,6 +48,7 @@ public:
void OnDefaultReload(); void OnDefaultReload();
protected: protected:
UFUNCTION(BlueprintCallable)
void AllowRefire(); void AllowRefire();
private: private:
@ -57,9 +58,10 @@ public:
/** The current state of the weapon. */ /** The current state of the weapon. */
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category="Legumix|Weapon") UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category="Legumix|Weapon")
EWeaponState State; EWeaponState State;
protected: /* Weapon Data */ protected: /* Weapon Data */
FTimerHandle FireTimer; FTimerHandle FireTimer;
FTimerHandle ReloadTimer;
/** The sound to play when firing. */ /** The sound to play when firing. */
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Legumix|Sounds") UPROPERTY(EditAnywhere, BlueprintReadWrite,Category="Legumix|Sounds")
@ -84,6 +86,9 @@ protected: /* Weapon Data */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|Weapon", meta=(AllowPrivateAccess=true)) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|Weapon", meta=(AllowPrivateAccess=true))
float RefireDelay = 0.5f; float RefireDelay = 0.5f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix|Weapon", meta=(AllowPrivateAccess=true))
float ReloadDelay = 0.5f;
/** The flat damage number of one bullet. */ /** The flat damage number of one bullet. */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Legumix|Weapon", meta=(AllowPrivateAccess=true)) UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Legumix|Weapon", meta=(AllowPrivateAccess=true))
float Damage = 10.f; float Damage = 10.f;