diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index b1a101da7..df37d78b6 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -40,9 +40,26 @@ void CreatureAI::OnCharmed(bool /*apply*/) AISpellInfoType* UnitAI::AISpellInfo; AISpellInfoType* GetAISpellInfo(uint32 i) { return &CreatureAI::AISpellInfo[i]; } -void CreatureAI::Talk(uint8 id, WorldObject const* target /*= nullptr*/) +/** + * @brief Causes the creature to talk/say the text assigned to their entry in the `creature_text` database table. + * + * @param uint8 id Text ID from `creature_text`. + * @param WorldObject target The target of the speech, in case it has elements such as $n, where the target's name will be referrenced. + * @param Milliseconds delay Delay until the creature says the text line. Creatures will talk immediately by default. + */ +void CreatureAI::Talk(uint8 id, WorldObject const* target /*= nullptr*/, Milliseconds delay /*= 0s*/) { - sCreatureTextMgr->SendChat(me, id, target); + if (delay > Seconds::zero()) + { + me->m_Events.AddEventAtOffset([this, id, target]() + { + sCreatureTextMgr->SendChat(me, id, target); + }, delay); + } + else + { + sCreatureTextMgr->SendChat(me, id, target); + } } inline bool IsValidCombatTarget(Creature* source, Player* target) diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index c4343a548..5cf63a319 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -92,7 +92,8 @@ public: EVADE_REASON_OTHER }; - void Talk(uint8 id, WorldObject const* whisperTarget = nullptr); + void Talk(uint8 id, WorldObject const* whisperTarget = nullptr, Milliseconds delay = 0s); + void Talk(uint8 id, Milliseconds delay) { Talk(id, nullptr, delay); } explicit CreatureAI(Creature* creature) : UnitAI(creature), me(creature), _boundary(nullptr), _negateBoundary(false), m_MoveInLineOfSight_locked(false) { } diff --git a/src/server/scripts/Kalimdor/CavernsOfTime/EscapeFromDurnholdeKeep/boss_captain_skarloc.cpp b/src/server/scripts/Kalimdor/CavernsOfTime/EscapeFromDurnholdeKeep/boss_captain_skarloc.cpp index e994c7d5b..b213e8295 100644 --- a/src/server/scripts/Kalimdor/CavernsOfTime/EscapeFromDurnholdeKeep/boss_captain_skarloc.cpp +++ b/src/server/scripts/Kalimdor/CavernsOfTime/EscapeFromDurnholdeKeep/boss_captain_skarloc.cpp @@ -67,13 +67,11 @@ public: boss_captain_skarlocAI(Creature* creature) : ScriptedAI(creature), summons(me) { } EventMap events; - EventMap events2; SummonList summons; void Reset() override { events.Reset(); - events2.Reset(); summons.DespawnAll(); } @@ -130,8 +128,24 @@ public: if (me->movespline->Finalized()) { - events2.ScheduleEvent(EVENT_INITIAL_TALK, 500); - events2.ScheduleEvent(EVENT_START_FIGHT, 8000); + Talk(SAY_ENTER, 500ms); + + me->m_Events.AddEventAtOffset([this]() + { + me->SetImmuneToAll(false); + me->SetInCombatWithZone(); + for (SummonList::const_iterator itr = summons.begin(); itr != summons.end(); ++itr) + { + if (Creature* summon = ObjectAccessor::GetCreature(*me, *itr)) + { + if (summon->GetEntry() != NPC_SKARLOC_MOUNT) + { + summon->SetImmuneToAll(false); + summon->SetInCombatWithZone(); + } + } + } + }, 8s); } } @@ -161,25 +175,6 @@ public: void UpdateAI(uint32 diff) override { - events2.Update(diff); - switch (events2.ExecuteEvent()) - { - case EVENT_INITIAL_TALK: - Talk(SAY_ENTER); - break; - case EVENT_START_FIGHT: - me->SetImmuneToAll(false); - me->SetInCombatWithZone(); - for (SummonList::const_iterator itr = summons.begin(); itr != summons.end(); ++itr) - if (Creature* summon = ObjectAccessor::GetCreature(*me, *itr)) - if (summon->GetEntry() != NPC_SKARLOC_MOUNT) - { - summon->SetImmuneToAll(false); - summon->SetInCombatWithZone(); - } - break; - } - if (!UpdateVictim()) return;