feat(Core/AI): Implement delay option to the Talk() function (#14950)
This commit is contained in:
@@ -40,9 +40,26 @@ void CreatureAI::OnCharmed(bool /*apply*/)
|
|||||||
AISpellInfoType* UnitAI::AISpellInfo;
|
AISpellInfoType* UnitAI::AISpellInfo;
|
||||||
AISpellInfoType* GetAISpellInfo(uint32 i) { return &CreatureAI::AISpellInfo[i]; }
|
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)
|
inline bool IsValidCombatTarget(Creature* source, Player* target)
|
||||||
|
|||||||
@@ -92,7 +92,8 @@ public:
|
|||||||
EVADE_REASON_OTHER
|
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) { }
|
explicit CreatureAI(Creature* creature) : UnitAI(creature), me(creature), _boundary(nullptr), _negateBoundary(false), m_MoveInLineOfSight_locked(false) { }
|
||||||
|
|
||||||
|
|||||||
+18
-23
@@ -67,13 +67,11 @@ public:
|
|||||||
boss_captain_skarlocAI(Creature* creature) : ScriptedAI(creature), summons(me) { }
|
boss_captain_skarlocAI(Creature* creature) : ScriptedAI(creature), summons(me) { }
|
||||||
|
|
||||||
EventMap events;
|
EventMap events;
|
||||||
EventMap events2;
|
|
||||||
SummonList summons;
|
SummonList summons;
|
||||||
|
|
||||||
void Reset() override
|
void Reset() override
|
||||||
{
|
{
|
||||||
events.Reset();
|
events.Reset();
|
||||||
events2.Reset();
|
|
||||||
summons.DespawnAll();
|
summons.DespawnAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,8 +128,24 @@ public:
|
|||||||
|
|
||||||
if (me->movespline->Finalized())
|
if (me->movespline->Finalized())
|
||||||
{
|
{
|
||||||
events2.ScheduleEvent(EVENT_INITIAL_TALK, 500);
|
Talk(SAY_ENTER, 500ms);
|
||||||
events2.ScheduleEvent(EVENT_START_FIGHT, 8000);
|
|
||||||
|
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
|
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())
|
if (!UpdateVictim())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user