diff options
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 17 | ||||
-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, 15 insertions, 17 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 8523dce6fab..d0c64c1f9c4 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -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 diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 553af72e229..275f4aa4e2e 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -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 diff --git a/src/server/game/AI/SmartScripts/SmartScript.h b/src/server/game/AI/SmartScripts/SmartScript.h index def103140be..b79532f4c14 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.h +++ b/src/server/game/AI/SmartScripts/SmartScript.h @@ -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; |