fix(Core/Creature): ensure target is valid when acquiring GUID (#22937)

This commit is contained in:
Andrew
2025-09-15 19:05:50 -03:00
committed by GitHub
parent 1aa5788f72
commit 9e0b6ff7a6
+7 -5
View File
@@ -53,17 +53,19 @@ void CreatureAI::Talk(uint8 id, WorldObject const* target /*= nullptr*/, Millise
{ {
if (delay > Seconds::zero()) if (delay > Seconds::zero())
{ {
ObjectGuid targetGuid = target->GetGUID(); ObjectGuid targetGuid;
if (target)
targetGuid = target->GetGUID();
me->m_Events.AddEventAtOffset([this, id, targetGuid]() me->m_Events.AddEventAtOffset([this, id, targetGuid]()
{ {
if (Unit* textTarget = ObjectAccessor::GetUnit(*me, targetGuid)) // Target can be nullptr here, it will be handled inside the function.
sCreatureTextMgr->SendChat(me, id, textTarget); sCreatureTextMgr->SendChat(me, id, ObjectAccessor::GetUnit(*me, targetGuid));
}, delay); }, delay);
} }
else else
{
sCreatureTextMgr->SendChat(me, id, target); sCreatureTextMgr->SendChat(me, id, target);
}
} }
/** /**