refactor(Core/BossAI): Improve the ScheduleHealthCheck() code (#19743)

* refactor(Core/BossAI): Improve the ScheduleHealthCheck() code

* Update ScriptedCreature.cpp

---------

Co-authored-by: sudlud <sudlud@users.noreply.github.com>
This commit is contained in:
Andrew
2024-08-26 14:44:05 -03:00
committed by GitHub
parent 4ed1815de6
commit 83f8871c31
2 changed files with 12 additions and 14 deletions

View File

@@ -720,9 +720,18 @@ void BossAI::DamageTaken(Unit* /*attacker*/, uint32& damage, DamageEffectType /*
{
if (!_healthCheckEvents.empty())
{
for (auto& check : _healthCheckEvents)
{
if (check._valid && me->HealthBelowPctDamaged(check._healthPct, damage))
{
check._exec();
check._valid = false;
}
}
_healthCheckEvents.remove_if([&](HealthCheckEventData data) -> bool
{
return _ProccessHealthCheckEvent(data._healthPct, damage, data._exec);
return !data._valid;
});
}
}
@@ -746,17 +755,6 @@ void BossAI::ScheduleHealthCheckEvent(std::initializer_list<uint8> healthPct, st
}
}
bool BossAI::_ProccessHealthCheckEvent(uint8 healthPct, uint32 damage, std::function<void()> exec) const
{
if (me->HealthBelowPctDamaged(healthPct, damage))
{
exec();
return true;
}
return false;
}
// WorldBossAI - for non-instanced bosses
WorldBossAI::WorldBossAI(Creature* creature) :