From c8f71c00a157970f0a76d4917d571690821114da Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 25 May 2011 18:50:44 +0200 Subject: 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 --- src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 16 ++++++++++++++++ src/server/game/AI/ScriptedAI/ScriptedCreature.h | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src/server') diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 269f760ab58..51e377c21d5 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -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*/) { diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index fad3388a187..66e4b276fe8 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -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. -- cgit v1.2.3