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:
@@ -720,9 +720,18 @@ void BossAI::DamageTaken(Unit* /*attacker*/, uint32& damage, DamageEffectType /*
|
|||||||
{
|
{
|
||||||
if (!_healthCheckEvents.empty())
|
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
|
_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 - for non-instanced bosses
|
||||||
|
|
||||||
WorldBossAI::WorldBossAI(Creature* creature) :
|
WorldBossAI::WorldBossAI(Creature* creature) :
|
||||||
|
|||||||
@@ -449,10 +449,11 @@ private:
|
|||||||
|
|
||||||
struct HealthCheckEventData
|
struct HealthCheckEventData
|
||||||
{
|
{
|
||||||
HealthCheckEventData(uint8 healthPct, std::function<void()> exec) : _healthPct(healthPct), _exec(exec) { };
|
HealthCheckEventData(uint8 healthPct, std::function<void()> exec, bool valid = true) : _healthPct(healthPct), _exec(exec), _valid(valid) { };
|
||||||
|
|
||||||
uint8 _healthPct;
|
uint8 _healthPct;
|
||||||
std::function<void()> _exec;
|
std::function<void()> _exec;
|
||||||
|
bool _valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BossAI : public ScriptedAI
|
class BossAI : public ScriptedAI
|
||||||
@@ -497,7 +498,6 @@ protected:
|
|||||||
void _JustDied();
|
void _JustDied();
|
||||||
void _JustReachedHome() { me->setActive(false); }
|
void _JustReachedHome() { me->setActive(false); }
|
||||||
void _EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER);
|
void _EnterEvadeMode(EvadeReason why = EVADE_REASON_OTHER);
|
||||||
[[nodiscard]] bool _ProccessHealthCheckEvent(uint8 healthPct, uint32 damage, std::function<void()> exec) const;
|
|
||||||
|
|
||||||
void TeleportCheaters();
|
void TeleportCheaters();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user