mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-08 15:58:04 +00:00
fix(Core/Scripts): Further improve the ScheduleHealthCheck() function (#20163)
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user