Core/SAI: merge followups to resolve conflicts

This commit is contained in:
Ovahlord committed 2018-09-17 15:47:07 +02:00
1 parent 1a1790b737
commit 65ff7abd6d
1 file changed
+43 -12
+43 -12
View File
@@ -63,29 +63,48 @@ SmartScript::~SmartScript()
{
}
bool SmartScript::IsSmart(Creature* c /*= nullptr*/)
// @todo this is an utter clusterfuck in terms of design - why in the world does this thing side effect?
// seriously, WHO WRITES THIS SHIT
bool SmartScript::IsSmart(Creature* c, bool silent)
{
if (!c)
return false;
bool smart = true;
if (!me || me->GetAIName() != "SmartAI")
smart = false;
if (!smart)
if (!smart && !silent)
TC_LOG_ERROR("sql.sql", "SmartScript: Action target Creature (GUID: %u Entry: %u) is not using SmartAI, action called by Creature (GUID: %u Entry: %u) skipped to prevent crash.", c ? c->GetSpawnId() : 0, c ? c->GetEntry() : 0, me ? me->GetSpawnId() : 0, me ? me->GetEntry() : 0);
return smart;
}
bool SmartScript::IsSmartGO(GameObject* g /*= nullptr*/)
// @todo this, too
bool SmartScript::IsSmart(GameObject* g, bool silent)
{
if (!g)
return false;
bool smart = true;
if (!go || go->GetAIName() != "SmartGameObjectAI")
if (g && g->GetAIName() != "SmartGameObjectAI")
smart = false;
if (!smart)
if (!smart && !silent)
TC_LOG_ERROR("sql.sql", "SmartScript: Action target GameObject (GUID: %u Entry: %u) is not using SmartGameObjectAI, action called by GameObject (GUID: %u Entry: %u) skipped to prevent crash.", g ? g->GetSpawnId() : 0, g ? g->GetEntry() : 0, go ? go->GetSpawnId() : 0, go ? go->GetEntry() : 0);
return smart;
}
bool SmartScript::IsSmart(bool silent)
{
if (me)
return IsSmart(me, silent);
if (go)
return IsSmart(go, silent);
return false;
}
void SmartScript::StoreTargetList(ObjectVector const& targets, uint32 id)
{
// insert or replace
@@ -1160,10 +1179,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;
}
@@ -1661,7 +1692,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
else if (GameObject* goTarget = target->ToGameObject())
{
if (IsSmartGO(goTarget))
if (IsSmart(goTarget))
ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetScript9(e, e.action.timedActionList.id, GetLastInvoker());
}
}
@@ -1751,7 +1782,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
else if (GameObject* goTarget = target->ToGameObject())
{
if (IsSmartGO(goTarget))
if (IsSmart(goTarget))
ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetScript9(e, id, GetLastInvoker());
}
}
@@ -1775,7 +1806,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
else if (GameObject* goTarget = target->ToGameObject())
{
if (IsSmartGO(goTarget))
if (IsSmart(goTarget))
ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetScript9(e, id, GetLastInvoker());
}
}