mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 01:37:37 +01:00
Scripts/SmartAI: Forward invoker to invoked action list actions. Also JustAppeared -> InitializeAI.
(cherry picked from commit 6fb0bc1038)
This commit is contained in:
@@ -513,7 +513,7 @@ bool SmartAI::AssistPlayerInCombatAgainst(Unit* who)
|
||||
return false;
|
||||
}
|
||||
|
||||
void SmartAI::JustAppeared()
|
||||
void SmartAI::InitializeAI()
|
||||
{
|
||||
mDespawnTime = 0;
|
||||
mRespawnTime = 0;
|
||||
@@ -839,9 +839,7 @@ void SmartAI::StopFollow(bool complete)
|
||||
|
||||
void SmartAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker)
|
||||
{
|
||||
if (invoker)
|
||||
GetScript()->mLastInvoker = invoker->GetGUID();
|
||||
GetScript()->SetScript9(e, entry);
|
||||
GetScript()->SetScript9(e, entry, invoker);
|
||||
}
|
||||
|
||||
void SmartAI::OnGameEvent(bool start, uint16 eventId)
|
||||
@@ -989,9 +987,6 @@ void SmartGameObjectAI::InitializeAI()
|
||||
|
||||
void SmartGameObjectAI::Reset()
|
||||
{
|
||||
// call respawn event on reset
|
||||
GetScript()->ProcessEventsFor(SMART_EVENT_RESPAWN);
|
||||
|
||||
GetScript()->OnReset();
|
||||
}
|
||||
|
||||
@@ -1049,9 +1044,7 @@ void SmartGameObjectAI::SetData(uint32 id, uint32 value)
|
||||
|
||||
void SmartGameObjectAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker)
|
||||
{
|
||||
if (invoker)
|
||||
GetScript()->mLastInvoker = invoker->GetGUID();
|
||||
GetScript()->SetScript9(e, entry);
|
||||
GetScript()->SetScript9(e, entry, invoker);
|
||||
}
|
||||
|
||||
void SmartGameObjectAI::OnGameEvent(bool start, uint16 eventId)
|
||||
@@ -1110,9 +1103,7 @@ void SmartAreaTriggerAI::OnUnitEnter(Unit* unit)
|
||||
|
||||
void SmartAreaTriggerAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker)
|
||||
{
|
||||
if (invoker)
|
||||
GetScript()->mLastInvoker = invoker->GetGUID();
|
||||
GetScript()->SetScript9(e, entry);
|
||||
GetScript()->SetScript9(e, entry, invoker);
|
||||
}
|
||||
|
||||
class SmartAreaTriggerEntityScript : public AreaTriggerEntityScript
|
||||
|
||||
@@ -212,7 +212,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
if (!roll_chance_i(e.event.event_chance))
|
||||
return;
|
||||
}
|
||||
e.runOnce = true;//used for repeat check
|
||||
e.runOnce = true; //used for repeat check
|
||||
|
||||
if (unit)
|
||||
mLastInvoker = unit->GetGUID();
|
||||
@@ -3556,9 +3556,12 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff)
|
||||
case SMART_EVENT_DISTANCE_CREATURE:
|
||||
case SMART_EVENT_DISTANCE_GAMEOBJECT:
|
||||
{
|
||||
ProcessEvent(e);
|
||||
if (e.GetScriptType() == SMART_SCRIPT_TYPE_TIMED_ACTIONLIST)
|
||||
{
|
||||
Unit* invoker9 = nullptr;
|
||||
if (me && !mTimedActionListInvoker.IsEmpty())
|
||||
invoker9 = ObjectAccessor::GetUnit(*me, mTimedActionListInvoker);
|
||||
ProcessEvent(e, invoker9);
|
||||
e.enableTimed = false;//disable event if it is in an ActionList and was processed once
|
||||
for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i)
|
||||
{
|
||||
@@ -3570,6 +3573,8 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
ProcessEvent(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -3936,7 +3941,7 @@ Unit* SmartScript::DoFindClosestFriendlyInRange(float range, bool playerOnly) co
|
||||
return unit;
|
||||
}
|
||||
|
||||
void SmartScript::SetScript9(SmartScriptHolder& e, uint32 entry)
|
||||
void SmartScript::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker)
|
||||
{
|
||||
//do NOT clear mTimedActionList if it's being iterated because it will invalidate the iterator and delete
|
||||
// any SmartScriptHolder contained like the "e" parameter passed to this function
|
||||
@@ -3950,6 +3955,7 @@ void SmartScript::SetScript9(SmartScriptHolder& e, uint32 entry)
|
||||
mTimedActionList = sSmartScriptMgr->GetScript(entry, SMART_SCRIPT_TYPE_TIMED_ACTIONLIST);
|
||||
if (mTimedActionList.empty())
|
||||
return;
|
||||
mTimedActionListInvoker = invoker ? invoker->GetGUID() : ObjectGuid::Empty;
|
||||
for (SmartAIEventList::iterator i = mTimedActionList.begin(); i != mTimedActionList.end(); ++i)
|
||||
{
|
||||
i->enableTimed = i == mTimedActionList.begin();//enable processing only for the first action
|
||||
|
||||
@@ -101,7 +101,7 @@ class TC_GAME_API SmartScript
|
||||
void ResetBaseObject();
|
||||
|
||||
//TIMED_ACTIONLIST (script type 9 aka script9)
|
||||
void SetScript9(SmartScriptHolder& e, uint32 entry);
|
||||
void SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker);
|
||||
Unit* GetLastInvoker(Unit* invoker = nullptr) const;
|
||||
ObjectGuid mLastInvoker;
|
||||
typedef std::unordered_map<uint32, uint32> CounterMap;
|
||||
@@ -118,6 +118,7 @@ class TC_GAME_API SmartScript
|
||||
SmartAIEventList mEvents;
|
||||
SmartAIEventList mInstallEvents;
|
||||
SmartAIEventList mTimedActionList;
|
||||
ObjectGuid mTimedActionListInvoker;
|
||||
bool isProcessingTimedActionList;
|
||||
Creature* me;
|
||||
ObjectGuid meOrigGUID;
|
||||
|
||||
Reference in New Issue
Block a user