diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 3ad842ed30..95942bd10d 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -597,16 +597,20 @@ bool SmartAI::AssistPlayerInCombatAgainst(Unit* who) void SmartAI::InitializeAI() { + GetScript()->OnInitialize(me); + mDespawnTime = 0; mDespawnState = 0; _escortState = SMART_ESCORT_NONE; me->SetVisible(true); - if (me->GetFaction() != me->GetCreatureTemplate()->faction) - me->RestoreFaction(); + if (!me->isDead()) + { + GetScript()->ProcessEventsFor(SMART_EVENT_RESPAWN); + GetScript()->OnReset(); + } - GetScript()->ProcessEventsFor(SMART_EVENT_RESPAWN); mFollowGuid.Clear(); // do not reset follower on Reset(), we need it after combat evade mFollowDist = 0; mFollowAngle = 0; @@ -738,17 +742,6 @@ void SmartAI::PassengerBoarded(Unit* who, int8 seatId, bool apply) GetScript()->ProcessEventsFor(apply ? SMART_EVENT_PASSENGER_BOARDED : SMART_EVENT_PASSENGER_REMOVED, who, uint32(seatId), 0, apply); } -void SmartAI::InitializeAI() -{ - GetScript()->OnInitialize(me); - - if (!me->isDead()) - { - GetScript()->OnReset(); - GetScript()->ProcessEventsFor(SMART_EVENT_RESPAWN); - } -} - void SmartAI::OnCharmed(bool apply) { if (apply) // do this before we change charmed state, as charmed state might prevent these things from processing @@ -928,9 +921,9 @@ void SmartAI::StopFollow(bool complete) GetScript()->ProcessEventsFor(SMART_EVENT_FOLLOW_COMPLETED, player); } -void SmartAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker) +void SmartAI::SetTimedActionList(SmartScriptHolder& e, uint32 entry, Unit* invoker) { - GetScript()->SetScript9(e, entry, invoker); + GetScript()->SetTimedActionList(e, entry, invoker); } void SmartAI::OnGameEvent(bool start, uint16 eventId) @@ -1047,9 +1040,9 @@ void SmartGameObjectAI::SetData(uint32 id, uint32 value, Unit* invoker) GetScript()->ProcessEventsFor(SMART_EVENT_DATA_SET, invoker, id, value); } -void SmartGameObjectAI::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker) +void SmartGameObjectAI::SetTimedActionList(SmartScriptHolder& e, uint32 entry, Unit* invoker) { - GetScript()->SetScript9(e, entry, invoker); + GetScript()->SetTimedActionList(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 6d318425c4..40cfdd1533 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -1688,12 +1688,12 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u if (Creature* creature = target->ToCreature()) { if (IsSmart(creature)) - ENSURE_AI(SmartAI, creature->AI())->SetScript9(e, e.action.timedActionList.id, GetLastInvoker()); + ENSURE_AI(SmartAI, creature->AI())->SetTimedActionList(e, e.action.timedActionList.id, GetLastInvoker()); } else if (GameObject* goTarget = target->ToGameObject()) { if (IsSmart(goTarget)) - ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetScript9(e, e.action.timedActionList.id, GetLastInvoker()); + ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetTimedActionList(e, e.action.timedActionList.id, GetLastInvoker()); } } break; @@ -1778,12 +1778,12 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u if (Creature* creature = target->ToCreature()) { if (IsSmart(creature)) - ENSURE_AI(SmartAI, creature->AI())->SetScript9(e, id, GetLastInvoker()); + ENSURE_AI(SmartAI, creature->AI())->SetTimedActionList(e, id, GetLastInvoker()); } else if (GameObject* goTarget = target->ToGameObject()) { if (IsSmart(goTarget)) - ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetScript9(e, id, GetLastInvoker()); + ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetTimedActionList(e, id, GetLastInvoker()); } } break; @@ -1802,12 +1802,12 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u if (Creature* creature = target->ToCreature()) { if (IsSmart(creature)) - ENSURE_AI(SmartAI, creature->AI())->SetScript9(e, id, GetLastInvoker()); + ENSURE_AI(SmartAI, creature->AI())->SetTimedActionList(e, id, GetLastInvoker()); } else if (GameObject* goTarget = target->ToGameObject()) { if (IsSmart(goTarget)) - ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetScript9(e, id, GetLastInvoker()); + ENSURE_AI(SmartGameObjectAI, goTarget->AI())->SetTimedActionList(e, id, GetLastInvoker()); } } break; @@ -3535,10 +3535,10 @@ void SmartScript::UpdateTimer(SmartScriptHolder& e, uint32 const diff) { if (e.GetScriptType() == SMART_SCRIPT_TYPE_TIMED_ACTIONLIST) { - Unit* invoker9 = nullptr; + Unit* invoker = nullptr; if (me && mTimedActionListInvoker) - invoker9 = ObjectAccessor::GetUnit(*me, mTimedActionListInvoker); - ProcessEvent(e, invoker9); + invoker = ObjectAccessor::GetUnit(*me, mTimedActionListInvoker); + ProcessEvent(e, invoker); 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) { @@ -3845,7 +3845,7 @@ Unit* SmartScript::DoFindClosestFriendlyInRange(float range, bool playerOnly) return unit; } -void SmartScript::SetScript9(SmartScriptHolder& e, uint32 entry, Unit* invoker) +void SmartScript::SetTimedActionList(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