Fix non-parallel timers in CombatAIComponent (#1008)

* Fix non-parelell timers
This commit is contained in:
David Markowitz 2023-03-03 18:45:01 -08:00 committed by GitHub
parent b6fc959433
commit 3e482602d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 31 deletions

View File

@ -22,6 +22,7 @@
#include "SkillComponent.h"
#include "RebuildComponent.h"
#include "DestroyableComponent.h"
#include "Metrics.hpp"
BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): Component(parent) {
m_Target = LWOOBJID_EMPTY;
@ -228,6 +229,18 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
bool hasSkillToCast = false;
for (auto& entry : m_SkillEntries) {
if (entry.cooldown > 0.0f) {
entry.cooldown -= deltaTime;
} else {
hasSkillToCast = true;
}
}
bool hadRemainingDowntime = m_SkillTime > 0.0f;
if (m_SkillTime > 0.0f) m_SkillTime -= deltaTime;
auto* rebuild = m_Parent->GetComponent<RebuildComponent>();
if (rebuild != nullptr) {
@ -258,9 +271,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
m_Stunned = false;
}
if (m_Stunned) {
return;
}
if (m_Stunned || hadRemainingDowntime) return;
auto newTarget = FindTarget();
@ -325,27 +336,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
SetAiState(AiState::idle);
}
for (auto i = 0; i < m_SkillEntries.size(); ++i) {
auto entry = m_SkillEntries.at(i);
if (entry.cooldown > 0) {
entry.cooldown -= deltaTime;
m_SkillEntries[i] = entry;
}
}
if (m_SkillTime > 0) {
m_SkillTime -= deltaTime;
return;
}
if (m_Downtime > 0) {
m_Downtime -= deltaTime;
return;
}
if (!hasSkillToCast) return;
if (m_Target == LWOOBJID_EMPTY) {
SetAiState(AiState::idle);
@ -353,8 +344,6 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
return;
}
m_Downtime = 0.5f;
auto* target = GetTargetEntity();
if (target != nullptr) {

View File

@ -340,11 +340,6 @@ private:
*/
bool m_StunImmune = false;
/**
* Time taken between actions
*/
float m_Downtime = 0;
/**
* How long this entity needs to execute its skill
*/