Core/Scripts: Added ExecuteEvent BossAI hook designed to contain event code which would otherwise be in while (uint32 eventId = events.ExecuteEvent()) switch blocks. This allows to define a base class sharing spells with other scripts

This commit is contained in:
Shauren
2011-05-25 18:50:44 +02:00
parent 5f5af1e95d
commit c8f71c00a1
2 changed files with 24 additions and 2 deletions

View File

@@ -624,6 +624,22 @@ void BossAI::SummonedCreatureDespawn(Creature* summon)
summons.Despawn(summon);
}
void BossAI::UpdateAI(uint32 const diff)
{
if (!UpdateVictim())
return;
events.Update(diff);
if (me->HasUnitState(UNIT_STAT_CASTING))
return;
while (uint32 eventId = events.ExecuteEvent())
ExecuteEvent(eventId);
DoMeleeAttackIfReady();
}
// SD2 grid searchers.
Creature* GetClosestCreatureWithEntry(WorldObject* source, uint32 entry, float maxSearchRange, bool alive /*= true*/)
{

View File

@@ -266,7 +266,13 @@ class BossAI : public ScriptedAI
void JustSummoned(Creature* summon);
void SummonedCreatureDespawn(Creature* summon);
void UpdateAI(uint32 const diff) = 0;
virtual void UpdateAI(uint32 const diff);
// Hook used to execute events scheduled into EventMap without the need
// to override UpdateAI
// note: You must re-schedule the event within this method if the event
// is supposed to run more than once
virtual void ExecuteEvent(uint32 const eventId) { }
void Reset() { _Reset(); }
void EnterCombat(Unit* /*who*/) { _EnterCombat(); }
@@ -296,7 +302,7 @@ class BossAI : public ScriptedAI
private:
BossBoundaryMap const* const _boundary;
const uint32 _bossId;
uint32 const _bossId;
};
// SD2 grid searchers.