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
|
// TODO: Play some animation here
|
||||||
|
|
||||||
CurrentWeapon->SetCurrentWeaponStatus(Cooldown);
|
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()
|
void AEnemyCharacter::BeginPlay()
|
||||||
|
|
|
@ -31,6 +31,8 @@ private:
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
URandomWeaponParameters* RandomWeaponParameters;
|
URandomWeaponParameters* RandomWeaponParameters;
|
||||||
|
|
||||||
|
FTimerHandle CooldownTimerHandle;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AEnemyCharacter();
|
AEnemyCharacter();
|
||||||
|
|
||||||
|
@ -40,6 +42,8 @@ public:
|
||||||
|
|
||||||
virtual void OnFire() override;
|
virtual void OnFire() override;
|
||||||
|
|
||||||
|
void WeaponCooldownHandler();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ EBTNodeResult::Type UTaskFireWeapon::ExecuteTask(UBehaviorTreeComponent& owner,
|
||||||
auto blackboardComponent = owner.GetBlackboardComponent();
|
auto blackboardComponent = owner.GetBlackboardComponent();
|
||||||
auto playerCharacter = Cast<APlayerCharacter>(blackboardComponent->GetValueAsObject(TargetActor.SelectedKeyName));
|
auto playerCharacter = Cast<APlayerCharacter>(blackboardComponent->GetValueAsObject(TargetActor.SelectedKeyName));
|
||||||
|
|
||||||
if (enemyPawn && playerCharacter)
|
if (enemyPawn && playerCharacter && enemyPawn->GetCurrentWeapon()->GetCurrentWeaponStatus()->GetValue() == Idle)
|
||||||
{
|
{
|
||||||
enemyPawn->OnFire();
|
enemyPawn->OnFire();
|
||||||
return EBTNodeResult::Succeeded;
|
return EBTNodeResult::Succeeded;
|
||||||
|
|
Loading…
Reference in New Issue