mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 17:19:07 +00:00
feat(Core/SAI): SetData now has invoker (#19296)
* cherry-pick commit (cfc77fd843) * cherry-pick commit (beb333738d) * Move IsSmart function from headerfile Co-authored-by: Treeston <14020072+Treeston@users.noreply.github.com> Co-authored-by: Shauren <shauren.trinity@gmail.com>
This commit is contained in:
@@ -63,7 +63,46 @@ SmartScript::SmartScript()
|
||||
|
||||
SmartScript::~SmartScript()
|
||||
{
|
||||
}
|
||||
|
||||
bool SmartScript::IsSmart(Creature* c, bool silent) const
|
||||
{
|
||||
if (!c)
|
||||
return false;
|
||||
|
||||
bool smart = true;
|
||||
if (!dynamic_cast<SmartAI*>(c->AI()))
|
||||
smart = false;
|
||||
|
||||
if (!smart && !silent)
|
||||
LOG_ERROR("sql.sql", "SmartScript: Action target Creature(entry: {}) is not using SmartAI, action skipped to prevent crash.", c ? c->GetEntry() : (me ? me->GetEntry() : 0));
|
||||
|
||||
return smart;
|
||||
}
|
||||
|
||||
bool SmartScript::IsSmart(GameObject* g, bool silent) const
|
||||
{
|
||||
if (!g)
|
||||
return false;
|
||||
|
||||
bool smart = true;
|
||||
if (!dynamic_cast<SmartGameObjectAI*>(g->AI()))
|
||||
smart = false;
|
||||
|
||||
if (!smart && !silent)
|
||||
LOG_ERROR("sql.sql", "SmartScript: Action target GameObject(entry: {}) is not using SmartGameObjectAI, action skipped to prevent crash.", g ? g->GetEntry() : (go ? go->GetEntry() : 0));
|
||||
|
||||
return smart;
|
||||
}
|
||||
|
||||
bool SmartScript::IsSmart(bool silent) const
|
||||
{
|
||||
if (me)
|
||||
return IsSmart(me, silent);
|
||||
if (go)
|
||||
return IsSmart(go, silent);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void SmartScript::OnReset()
|
||||
@@ -1355,10 +1394,22 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
{
|
||||
for (WorldObject* target : targets)
|
||||
{
|
||||
if (IsCreature(target))
|
||||
target->ToCreature()->AI()->SetData(e.action.setData.field, e.action.setData.data);
|
||||
else if (IsGameObject(target))
|
||||
target->ToGameObject()->AI()->SetData(e.action.setData.field, e.action.setData.data);
|
||||
if (Creature* cTarget = target->ToCreature())
|
||||
{
|
||||
CreatureAI* ai = cTarget->AI();
|
||||
if (IsSmart(cTarget))
|
||||
ENSURE_AI(SmartAI, ai)->SetData(e.action.setData.field, e.action.setData.data, me);
|
||||
else
|
||||
ai->SetData(e.action.setData.field, e.action.setData.data);
|
||||
}
|
||||
else if (GameObject* oTarget = target->ToGameObject())
|
||||
{
|
||||
GameObjectAI* ai = oTarget->AI();
|
||||
if (IsSmart(oTarget))
|
||||
ENSURE_AI(SmartGameObjectAI, ai)->SetData(e.action.setData.field, e.action.setData.data, me);
|
||||
else
|
||||
ai->SetData(e.action.setData.field, e.action.setData.data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1974,7 +2025,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
}
|
||||
else if (GameObject* go = target->ToGameObject())
|
||||
{
|
||||
if (IsSmartGO(go))
|
||||
if (IsSmart(go))
|
||||
CAST_AI(SmartGameObjectAI, go->AI())->SetScript9(e, e.action.timedActionList.id, GetLastInvoker());
|
||||
}
|
||||
}
|
||||
@@ -2061,7 +2112,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
}
|
||||
else if (GameObject* go = target->ToGameObject())
|
||||
{
|
||||
if (IsSmartGO(go))
|
||||
if (IsSmart(go))
|
||||
CAST_AI(SmartGameObjectAI, go->AI())->SetScript9(e, id, GetLastInvoker());
|
||||
}
|
||||
}
|
||||
@@ -2085,7 +2136,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
}
|
||||
else if (GameObject* go = target->ToGameObject())
|
||||
{
|
||||
if (IsSmartGO(go))
|
||||
if (IsSmart(go))
|
||||
CAST_AI(SmartGameObjectAI, go->AI())->SetScript9(e, id, GetLastInvoker());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user