diff options
author | Treeston <treeston.mmoc@gmail.com> | 2018-02-13 18:29:38 +0100 |
---|---|---|
committer | Treeston <treeston.mmoc@gmail.com> | 2018-02-13 18:29:38 +0100 |
commit | 6fb0bc10387b73836cea9a3c0eaaafcf58794b7d (patch) | |
tree | 18eeb98daafd9062b681a4276c31bc3195043910 /src | |
parent | 0e401c7d963f983d31573d108ccd2343fda40094 (diff) |
Scripts/SmartAI: Forward invoker to invoked action list actions. Also JustAppeared -> InitializeAI.
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 13 | ||||
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.cpp | 12 | ||||
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.h | 3 |
3 files changed, 14 insertions, 14 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index a2a5d6dfa57..82915d61e85 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -511,7 +511,7 @@ bool SmartAI::AssistPlayerInCombatAgainst(Unit* who) return false; } -void SmartAI::JustAppeared() +void SmartAI::InitializeAI() { mDespawnTime = 0; mDespawnState = 0; @@ -836,9 +836,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) @@ -986,9 +984,6 @@ void SmartGameObjectAI::InitializeAI() void SmartGameObjectAI::Reset() { - // call respawn event on reset - GetScript()->ProcessEventsFor(SMART_EVENT_RESPAWN); - GetScript()->OnReset(); } @@ -1046,9 +1041,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) diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index cf9d2100832..d3b47e89600 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -221,7 +221,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(); @@ -3364,9 +3364,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) + 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) { @@ -3378,6 +3381,8 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff) } } } + else + ProcessEvent(e); break; } } @@ -3670,7 +3675,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 @@ -3684,6 +3689,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 diff --git a/src/server/game/AI/SmartScripts/SmartScript.h b/src/server/game/AI/SmartScripts/SmartScript.h index 65c3f7950ae..3c9cb468f2d 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.h +++ b/src/server/game/AI/SmartScripts/SmartScript.h @@ -85,7 +85,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; @@ -102,6 +102,7 @@ class TC_GAME_API SmartScript SmartAIEventList mEvents; SmartAIEventList mInstallEvents; SmartAIEventList mTimedActionList; + ObjectGuid mTimedActionListInvoker; bool isProcessingTimedActionList; Creature* me; ObjectGuid meOrigGUID; |