fix(Scripts/AzjolNerub): Fix Anubarak impale sequence (#22717)

This commit is contained in:
Andrew
2025-09-23 05:49:23 -03:00
committed by GitHub
parent 7a0b9785bb
commit 78dea88d5d
3 changed files with 125 additions and 64 deletions

View File

@@ -746,27 +746,39 @@ void BossAI::UpdateAI(uint32 diff)
DoMeleeAttackIfReady();
}
void BossAI::OnSpellCastFinished(SpellInfo const* spellInfo, SpellFinishReason reason)
{
ScriptedAI::OnSpellCastFinished(spellInfo, reason);
// Check if any health check events are pending (i.e. waiting for the boss to stop casting.
if (_nextHealthCheck.IsPending() && me->IsInCombat())
{
_nextHealthCheck.UpdateStatus(HEALTH_CHECK_PROCESSED);
// This must be delayed because creature might still have unit state casting at this point, which might break scripts.
scheduler.Schedule(1s, [this](TaskContext context)
{
if (me->HasUnitState(UNIT_STATE_CASTING))
context.Repeat();
else
ProcessHealthCheck();
});
}
}
void BossAI::DamageTaken(Unit* attacker, uint32& damage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask)
{
ScriptedAI::DamageTaken(attacker, damage, damagetype, damageSchoolMask);
if (_nextHealthCheck._valid)
if (!_nextHealthCheck.HasBeenProcessed())
{
if (!_nextHealthCheck._allowedWhileCasting && me->HasUnitState(UNIT_STATE_CASTING))
return;
if (me->HealthBelowPctDamaged(_nextHealthCheck._healthPct, damage))
{
_nextHealthCheck._exec();
_nextHealthCheck._valid = false;
_healthCheckEvents.remove_if([&](HealthCheckEventData data) -> bool
if (!_nextHealthCheck._allowedWhileCasting && me->HasUnitState(UNIT_STATE_CASTING))
{
return data._healthPct == _nextHealthCheck._healthPct;
});
_nextHealthCheck.UpdateStatus(HEALTH_CHECK_PENDING);
return;
}
if (!_healthCheckEvents.empty())
_nextHealthCheck = _healthCheckEvents.front();
ProcessHealthCheck();
}
}
}
@@ -780,18 +792,32 @@ void BossAI::DamageTaken(Unit* attacker, uint32& damage, DamageEffectType damage
*/
void BossAI::ScheduleHealthCheckEvent(uint32 healthPct, std::function<void()> exec, bool allowedWhileCasting /*=true*/)
{
_healthCheckEvents.push_back(HealthCheckEventData(healthPct, exec, true, allowedWhileCasting));
_healthCheckEvents.push_back(HealthCheckEventData(healthPct, exec, HEALTH_CHECK_SCHEDULED, allowedWhileCasting));
_nextHealthCheck = _healthCheckEvents.front();
};
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, true, allowedWhileCasting));
_healthCheckEvents.push_back(HealthCheckEventData(checks, exec, HEALTH_CHECK_SCHEDULED, allowedWhileCasting));
_nextHealthCheck = _healthCheckEvents.front();
}
void BossAI::ProcessHealthCheck()
{
_nextHealthCheck.UpdateStatus(HEALTH_CHECK_PROCESSED);
_nextHealthCheck._exec();
_healthCheckEvents.remove_if([&](HealthCheckEventData data) -> bool
{
return data._healthPct == _nextHealthCheck._healthPct;
});
if (!_healthCheckEvents.empty())
_nextHealthCheck = _healthCheckEvents.front();
}
void BossAI::ScheduleEnrageTimer(uint32 spellId, Milliseconds timer, uint8 textId /*= 0*/)
{
me->m_Events.AddEventAtOffset([this, spellId, textId]