Add extra checking for when an enemy can fire a weapon
This commit is contained in:
parent
9d32a0a0e3
commit
4ab591e4b9
|
@ -51,6 +51,17 @@ void AEnemyCharacter::OnFire()
|
|||
// TODO: Play some animation here
|
||||
|
||||
CurrentWeapon->SetCurrentWeaponStatus(Cooldown);
|
||||
|
||||
GetWorldTimerManager().SetTimer(CooldownTimerHandle, this, &AEnemyCharacter::WeaponCooldownHandler,
|
||||
CurrentWeapon->GetWeaponProperties()->WeaponCooldown, true);
|
||||
}
|
||||
|
||||
void AEnemyCharacter::WeaponCooldownHandler()
|
||||
{
|
||||
if (CurrentWeapon->GetCurrentWeaponStatus()->GetValue() != Idle)
|
||||
{
|
||||
CurrentWeapon->SetCurrentWeaponStatus(Idle);
|
||||
}
|
||||
}
|
||||
|
||||
void AEnemyCharacter::BeginPlay()
|
||||
|
|
|
@ -31,6 +31,8 @@ private:
|
|||
UPROPERTY(VisibleAnywhere)
|
||||
URandomWeaponParameters* RandomWeaponParameters;
|
||||
|
||||
FTimerHandle CooldownTimerHandle;
|
||||
|
||||
public:
|
||||
AEnemyCharacter();
|
||||
|
||||
|
@ -40,6 +42,8 @@ public:
|
|||
|
||||
virtual void OnFire() override;
|
||||
|
||||
void WeaponCooldownHandler();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ EBTNodeResult::Type UTaskFireWeapon::ExecuteTask(UBehaviorTreeComponent& owner,
|
|||
auto blackboardComponent = owner.GetBlackboardComponent();
|
||||
auto playerCharacter = Cast<APlayerCharacter>(blackboardComponent->GetValueAsObject(TargetActor.SelectedKeyName));
|
||||
|
||||
if (enemyPawn && playerCharacter)
|
||||
if (enemyPawn && playerCharacter && enemyPawn->GetCurrentWeapon()->GetCurrentWeaponStatus()->GetValue() == Idle)
|
||||
{
|
||||
enemyPawn->OnFire();
|
||||
return EBTNodeResult::Succeeded;
|
||||
|
|
Loading…
Reference in New Issue