mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-04-27 17:16:31 +00:00
Fix non-parallel timers in CombatAIComponent (#1008)
* Fix non-parelell timers
This commit is contained in:
parent
b6fc959433
commit
3e482602d4
@ -22,6 +22,7 @@
|
|||||||
#include "SkillComponent.h"
|
#include "SkillComponent.h"
|
||||||
#include "RebuildComponent.h"
|
#include "RebuildComponent.h"
|
||||||
#include "DestroyableComponent.h"
|
#include "DestroyableComponent.h"
|
||||||
|
#include "Metrics.hpp"
|
||||||
|
|
||||||
BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): Component(parent) {
|
BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): Component(parent) {
|
||||||
m_Target = LWOOBJID_EMPTY;
|
m_Target = LWOOBJID_EMPTY;
|
||||||
@ -228,6 +229,18 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
|
|||||||
|
|
||||||
|
|
||||||
void BaseCombatAIComponent::CalculateCombat(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>();
|
auto* rebuild = m_Parent->GetComponent<RebuildComponent>();
|
||||||
|
|
||||||
if (rebuild != nullptr) {
|
if (rebuild != nullptr) {
|
||||||
@ -258,9 +271,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
|||||||
m_Stunned = false;
|
m_Stunned = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_Stunned) {
|
if (m_Stunned || hadRemainingDowntime) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto newTarget = FindTarget();
|
auto newTarget = FindTarget();
|
||||||
|
|
||||||
@ -325,27 +336,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
|||||||
SetAiState(AiState::idle);
|
SetAiState(AiState::idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < m_SkillEntries.size(); ++i) {
|
if (!hasSkillToCast) return;
|
||||||
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 (m_Target == LWOOBJID_EMPTY) {
|
if (m_Target == LWOOBJID_EMPTY) {
|
||||||
SetAiState(AiState::idle);
|
SetAiState(AiState::idle);
|
||||||
@ -353,8 +344,6 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Downtime = 0.5f;
|
|
||||||
|
|
||||||
auto* target = GetTargetEntity();
|
auto* target = GetTargetEntity();
|
||||||
|
|
||||||
if (target != nullptr) {
|
if (target != nullptr) {
|
||||||
|
@ -340,11 +340,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
bool m_StunImmune = false;
|
bool m_StunImmune = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Time taken between actions
|
|
||||||
*/
|
|
||||||
float m_Downtime = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How long this entity needs to execute its skill
|
* How long this entity needs to execute its skill
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user