feat(Core/AI): Implement delay option to the Talk() function (#14950)

This commit is contained in:
Skjalf
2023-02-11 17:23:57 -03:00
committed by GitHub
parent af88c2428b
commit 76c9eb9159
3 changed files with 39 additions and 26 deletions

View File

@@ -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)