summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorAndrew <47818697+Nyeriah@users.noreply.github.com>2025-09-14 18:48:33 -0300
committerGitHub <noreply@github.com>2025-09-14 18:48:33 -0300
commit28532bc1e0e0268af0555a0168cbe72566e80c38 (patch)
tree23656997f646e722f72d69aaaaeb559d7b408e43 /src/server
parent3d828a65686467a08f3da4bbbd00d50e44cfc209 (diff)
feat(Core/AI): Allow preventing health check events while casting (#22897)
Diffstat (limited to 'src/server')
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedCreature.cpp16
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedCreature.h7
2 files changed, 14 insertions, 9 deletions
diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
index b112332171..1b6733e503 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
+++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp
@@ -751,6 +751,10 @@ void BossAI::DamageTaken(Unit* attacker, uint32& damage, DamageEffectType damage
ScriptedAI::DamageTaken(attacker, damage, damagetype, damageSchoolMask);
if (_nextHealthCheck._valid)
+ {
+ if (!_nextHealthCheck._allowedWhileCasting && me->HasUnitState(UNIT_STATE_CASTING))
+ return;
+
if (me->HealthBelowPctDamaged(_nextHealthCheck._healthPct, damage))
{
_nextHealthCheck._exec();
@@ -764,6 +768,7 @@ void BossAI::DamageTaken(Unit* attacker, uint32& damage, DamageEffectType damage
if (!_healthCheckEvents.empty())
_nextHealthCheck = _healthCheckEvents.front();
}
+ }
}
/**
@@ -771,19 +776,18 @@ void BossAI::DamageTaken(Unit* attacker, uint32& damage, DamageEffectType damage
*
* @param healthPct The health percent at which the code will be executed.
* @param exec The fuction to be executed.
+ * @param allowedWhileCasting If false, the event will not be checked while the creature is casting.
*/
-void BossAI::ScheduleHealthCheckEvent(uint32 healthPct, std::function<void()> exec)
+void BossAI::ScheduleHealthCheckEvent(uint32 healthPct, std::function<void()> exec, bool allowedWhileCasting /*=true*/)
{
- _healthCheckEvents.push_back(HealthCheckEventData(healthPct, exec));
+ _healthCheckEvents.push_back(HealthCheckEventData(healthPct, exec, true, allowedWhileCasting));
_nextHealthCheck = _healthCheckEvents.front();
};
-void BossAI::ScheduleHealthCheckEvent(std::initializer_list<uint8> healthPct, std::function<void()> exec)
+void BossAI::ScheduleHealthCheckEvent(std::initializer_list<uint8> healthPct, std::function<void()> exec, bool allowedWhileCasting /*=true*/)
{
for (auto const& checks : healthPct)
- {
- _healthCheckEvents.push_back(HealthCheckEventData(checks, exec));
- }
+ _healthCheckEvents.push_back(HealthCheckEventData(checks, exec, true, allowedWhileCasting));
_nextHealthCheck = _healthCheckEvents.front();
}
diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h
index 9cb004a894..82f50542b3 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h
+++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h
@@ -456,11 +456,12 @@ private:
struct HealthCheckEventData
{
- HealthCheckEventData(uint8 healthPct, std::function<void()> exec, bool valid = true) : _healthPct(healthPct), _exec(exec), _valid(valid) { };
+ HealthCheckEventData(uint8 healthPct, std::function<void()> exec, bool valid = true, bool allowedWhileCasting = true) : _healthPct(healthPct), _exec(exec), _valid(valid), _allowedWhileCasting(allowedWhileCasting) { };
uint8 _healthPct;
std::function<void()> _exec;
bool _valid;
+ bool _allowedWhileCasting;
};
class BossAI : public ScriptedAI
@@ -482,8 +483,8 @@ public:
void UpdateAI(uint32 diff) override;
- void ScheduleHealthCheckEvent(uint32 healthPct, std::function<void()> exec);
- void ScheduleHealthCheckEvent(std::initializer_list<uint8> healthPct, std::function<void()> exec);
+ void ScheduleHealthCheckEvent(uint32 healthPct, std::function<void()> exec, bool allowedWhileCasting = true);
+ void ScheduleHealthCheckEvent(std::initializer_list<uint8> healthPct, std::function<void()> exec, bool allowedWhileCasting = true);
// @brief Casts the spell after the fixed time and says the text id if provided. Timer will run even if the creature is casting or out of combat.
// @param spellId The spell to cast.