fix(Core/Scripts): Further improve the ScheduleHealthCheck() function (#20163)

This commit is contained in:
Andrew
2024-10-09 08:08:37 -03:00
committed by GitHub
parent 0fa770d567
commit 31cb7579e0
2 changed files with 18 additions and 15 deletions

View File

@@ -584,7 +584,8 @@ Player* ScriptedAI::SelectTargetFromPlayerList(float maxdist, uint32 excludeAura
BossAI::BossAI(Creature* creature, uint32 bossId) : ScriptedAI(creature), BossAI::BossAI(Creature* creature, uint32 bossId) : ScriptedAI(creature),
instance(creature->GetInstanceScript()), instance(creature->GetInstanceScript()),
summons(creature), summons(creature),
_bossId(bossId) _bossId(bossId),
_nextHealthCheck(0, { }, false)
{ {
callForHelpRange = 0.0f; callForHelpRange = 0.0f;
if (instance) if (instance)
@@ -733,22 +734,20 @@ void BossAI::UpdateAI(uint32 diff)
void BossAI::DamageTaken(Unit* /*attacker*/, uint32& damage, DamageEffectType /*damagetype*/, SpellSchoolMask /*damageSchoolMask*/) void BossAI::DamageTaken(Unit* /*attacker*/, uint32& damage, DamageEffectType /*damagetype*/, SpellSchoolMask /*damageSchoolMask*/)
{ {
if (!_healthCheckEvents.empty()) if (_nextHealthCheck._valid)
{ if (me->HealthBelowPctDamaged(_nextHealthCheck._healthPct, damage))
for (auto& check : _healthCheckEvents)
{ {
if (check._valid && me->HealthBelowPctDamaged(check._healthPct, damage)) _nextHealthCheck._exec();
{ _nextHealthCheck._valid = false;
check._exec();
check._valid = false;
}
}
_healthCheckEvents.remove_if([&](HealthCheckEventData data) -> bool _healthCheckEvents.remove_if([&](HealthCheckEventData data) -> bool
{ {
return !data._valid; return data._healthPct == _nextHealthCheck._healthPct;
}); });
}
if (!_healthCheckEvents.empty())
_nextHealthCheck = _healthCheckEvents.front();
}
} }
/** /**
@@ -760,6 +759,7 @@ void BossAI::DamageTaken(Unit* /*attacker*/, uint32& damage, DamageEffectType /*
void BossAI::ScheduleHealthCheckEvent(uint32 healthPct, std::function<void()> exec) void BossAI::ScheduleHealthCheckEvent(uint32 healthPct, std::function<void()> exec)
{ {
_healthCheckEvents.push_back(HealthCheckEventData(healthPct, exec)); _healthCheckEvents.push_back(HealthCheckEventData(healthPct, exec));
_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)
@@ -768,6 +768,8 @@ void BossAI::ScheduleHealthCheckEvent(std::initializer_list<uint8> healthPct, st
{ {
_healthCheckEvents.push_back(HealthCheckEventData(checks, exec)); _healthCheckEvents.push_back(HealthCheckEventData(checks, exec));
} }
_nextHealthCheck = _healthCheckEvents.front();
} }
// WorldBossAI - for non-instanced bosses // WorldBossAI - for non-instanced bosses

View File

@@ -503,6 +503,7 @@ protected:
private: private:
uint32 const _bossId; uint32 const _bossId;
std::list<HealthCheckEventData> _healthCheckEvents; std::list<HealthCheckEventData> _healthCheckEvents;
HealthCheckEventData _nextHealthCheck;
}; };
class WorldBossAI : public ScriptedAI class WorldBossAI : public ScriptedAI