mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-13 11:43:18 -04:00
Scripts/SmartAI: SetData now has an invoker (if the setting is done by something using SmartAI).
Also, some refactors. SMARTAI IS SUCH A FUCKING CLUSTERFUCK I SWEAR.
(cherry picked from commit cfc77fd843)
This commit is contained in:
@@ -66,35 +66,63 @@ 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 (c && c->GetAIName() != "SmartAI")
|
||||
smart = false;
|
||||
|
||||
if (!me || me->GetAIName() != "SmartAI")
|
||||
smart = false;
|
||||
|
||||
if (!smart)
|
||||
if (!smart && !silent)
|
||||
TC_LOG_ERROR("sql.sql", "SmartScript: Action target Creature (GUID: " UI64FMTD " Entry: %u) is not using SmartAI, action called by Creature (GUID: " UI64FMTD " Entry: %u) skipped to prevent crash.", uint64(c ? c->GetSpawnId() : UI64LIT(0)), c ? c->GetEntry() : 0, uint64(me ? me->GetSpawnId() : UI64LIT(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 (g && g->GetAIName() != "SmartGameObjectAI")
|
||||
smart = false;
|
||||
|
||||
if (!go || go->GetAIName() != "SmartGameObjectAI")
|
||||
smart = false;
|
||||
if (!smart)
|
||||
if (!smart && !silent)
|
||||
TC_LOG_ERROR("sql.sql", "SmartScript: Action target GameObject (GUID: " UI64FMTD " Entry: %u) is not using SmartGameObjectAI, action called by GameObject (GUID: " UI64FMTD " Entry: %u) skipped to prevent crash.", uint64(g ? g->GetSpawnId() : UI64LIT(0)), g ? g->GetEntry() : 0, uint64(go ? go->GetSpawnId() : UI64LIT(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
|
||||
_storedTargets.erase(id);
|
||||
_storedTargets.emplace(id, ObjectGuidVector(targets));
|
||||
}
|
||||
|
||||
ObjectVector const* SmartScript::GetStoredTargetVector(uint32 id, WorldObject const& ref) const
|
||||
{
|
||||
auto itr = _storedTargets.find(id);
|
||||
if (itr != _storedTargets.end())
|
||||
return itr->second.GetObjectVector(ref);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SmartScript::StoreCounter(uint32 id, uint32 value, uint32 reset)
|
||||
{
|
||||
CounterMap::iterator itr = mCounterList.find(id);
|
||||
@@ -1124,10 +1152,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;
|
||||
}
|
||||
@@ -1623,7 +1663,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())->SetTimedActionList(e, e.action.timedActionList.id, GetLastInvoker());
|
||||
}
|
||||
else if (AreaTrigger* areaTriggerTarget = target->ToAreaTrigger())
|
||||
@@ -1713,7 +1753,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())->SetTimedActionList(e, id, GetLastInvoker());
|
||||
}
|
||||
else if (AreaTrigger* areaTriggerTarget = target->ToAreaTrigger())
|
||||
@@ -1740,7 +1780,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())->SetTimedActionList(e, id, GetLastInvoker());
|
||||
}
|
||||
else if (AreaTrigger* areaTriggerTarget = target->ToAreaTrigger())
|
||||
|
||||
Reference in New Issue
Block a user