diff options
| author | Rat <gmstreetrat@gmail.com> | 2011-02-21 22:23:43 +0100 | 
|---|---|---|
| committer | Rat <gmstreetrat@gmail.com> | 2011-02-21 22:23:43 +0100 | 
| commit | 8b37ac4688e8a376cf0a1307f86a9b91df3e4af7 (patch) | |
| tree | 626fbc6863855acc7668afc0b8a2a459fb44f89f | |
| parent | 4c8130235e02578f46b93cc8873f5823f403475f (diff) | |
Core/SAI: Fix invoker logic and possible crashes
Signed-off-by: Rat <gmstreetrat@gmail.com>
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartAI.cpp | 4 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.cpp | 45 | ||||
| -rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.h | 3 | 
3 files changed, 29 insertions, 23 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 422096b3798..cc8bdc00d12 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -793,7 +793,7 @@ void SmartAI::SetFollow(Unit* target, float dist, float angle, uint32 credit, ui  void SmartAI::SetScript9(SmartScriptHolder &e, uint32 entry, Unit* invoker)  {      if (invoker) -        GetScript()->mLastInvoker = invoker; +        GetScript()->mLastInvoker = invoker->GetGUID();      GetScript()->SetScript9(e, entry);  }  /* @@ -894,7 +894,7 @@ void SmartGameObjectAI::SetData(uint32 id, uint32 value)  void SmartGameObjectAI::SetScript9(SmartScriptHolder &e, uint32 entry, Unit* invoker)  {      if (invoker) -        GetScript()->mLastInvoker = invoker; +        GetScript()->mLastInvoker = invoker->GetGUID();      GetScript()->SetScript9(e, entry);  } diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index d15ea7ed12f..4abf17049b2 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -109,7 +109,7 @@ void SmartScript::ProcessAction(SmartScriptHolder &e, Unit* unit, uint32 var0, u      e.runOnce = true;//used for repeat check      if (unit) -        mLastInvoker = unit; +        mLastInvoker = unit->GetGUID();      if (e.link && e.link != e.event_id)      { @@ -120,8 +120,8 @@ void SmartScript::ProcessAction(SmartScriptHolder &e, Unit* unit, uint32 var0, u              sLog->outErrorDb("SmartScript::ProcessAction: Entry %d SourceType %u, Event %u, Link Event %u not found or invalid, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.link);      } -    if (mLastInvoker) -        sLog->outDebug(LOG_FILTER_DATABASE_AI, "SmartScript::ProcessAction: Invoker: %s (guidlow: %u)", mLastInvoker->GetName(), mLastInvoker->GetGUIDLow()); +    if (Unit* tempInvoker = GetLastInvoker()) +        sLog->outDebug(LOG_FILTER_DATABASE_AI, "SmartScript::ProcessAction: Invoker: %s (guidlow: %u)", tempInvoker->GetName(), tempInvoker->GetGUIDLow());      switch (e.GetActionType())      { @@ -142,7 +142,7 @@ void SmartScript::ProcessAction(SmartScriptHolder &e, Unit* unit, uint32 var0, u                  }                  mLastTextID = e.action.talk.textGroupID;                  mTextTimer = e.action.talk.duration; -                mTextGUID = IsPlayer(mLastInvoker)? mLastInvoker->GetGUID() : NULL;//invoker, used for $vars in texts +                mTextGUID = IsPlayer(GetLastInvoker())? GetLastInvoker()->GetGUID() : NULL;//invoker, used for $vars in texts                  mUseTextTimer = true;                  sCreatureTextMgr->SendChat(talker, uint8(e.action.talk.textGroupID), mTextGUID); @@ -159,10 +159,12 @@ void SmartScript::ProcessAction(SmartScriptHolder &e, Unit* unit, uint32 var0, u                      for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); itr++)                      {                          if (IsCreature((*itr))) -                            sCreatureTextMgr->SendChat((*itr)->ToCreature(), uint8(e.action.talk.textGroupID), IsPlayer(mLastInvoker)? mLastInvoker->GetGUID() : NULL); +                            sCreatureTextMgr->SendChat((*itr)->ToCreature(), uint8(e.action.talk.textGroupID), IsPlayer(GetLastInvoker())? GetLastInvoker()->GetGUID() : NULL);                          else if (IsPlayer((*itr))) -                            sCreatureTextMgr->SendChat(me, uint8(e.action.talk.textGroupID),IsPlayer(mLastInvoker)? mLastInvoker->GetGUID() : NULL,CHAT_TYPE_END,LANG_ADDON,TEXT_RANGE_NORMAL,NULL,TEAM_OTHER,false, (*itr)->ToPlayer()); - +                        { +                            Unit* templastInvoker = GetLastInvoker(); +                            sCreatureTextMgr->SendChat(me, uint8(e.action.talk.textGroupID),IsPlayer(templastInvoker)? templastInvoker->GetGUID() : NULL,CHAT_TYPE_END,LANG_ADDON,TEXT_RANGE_NORMAL,NULL,TEAM_OTHER,false, (*itr)->ToPlayer()); +                        }                          sLog->outDebug(LOG_FILTER_DATABASE_AI, "SmartScript::ProcessAction:: SMART_ACTION_SIMPLE_TALK: talker: %s (GuidLow: %u), textGroupId: %u",                              (*itr)->GetName(), (*itr)->GetGUIDLow(), uint8(e.action.talk.textGroupID));                      } @@ -419,20 +421,20 @@ void SmartScript::ProcessAction(SmartScriptHolder &e, Unit* unit, uint32 var0, u              }          case SMART_ACTION_INVOKER_CAST:              { -                if (!mLastInvoker) +                Unit* tempLastInvoker = GetLastInvoker(); +                if (!tempLastInvoker)                      return; -                  ObjectList* targets = GetTargets(e, unit);                  if (!targets) return;                  for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); itr++)                      if (IsUnit((*itr)))                      {                          if (e.action.cast.flags & SMARTCAST_INTERRUPT_PREVIOUS) -                            mLastInvoker->InterruptNonMeleeSpells(false); +                            tempLastInvoker->InterruptNonMeleeSpells(false); -                        mLastInvoker->CastSpell((*itr)->ToUnit(), e.action.cast.spell,(e.action.cast.flags & SMARTCAST_TRIGGERED) ? true : false); +                        tempLastInvoker->CastSpell((*itr)->ToUnit(), e.action.cast.spell,(e.action.cast.flags & SMARTCAST_TRIGGERED) ? true : false);                          sLog->outDebug(LOG_FILTER_DATABASE_AI, "SmartScript::ProcessAction:: SMART_ACTION_INVOKER_CAST: Invoker %u casts spell % on target %u with castflags %u", -                            mLastInvoker->GetGUIDLow(), (*itr)->GetGUIDLow(), e.action.cast.spell, e.action.cast.flags); +                            tempLastInvoker->GetGUIDLow(), (*itr)->GetGUIDLow(), e.action.cast.spell, e.action.cast.flags);                      }                  break;              } @@ -1269,11 +1271,11 @@ void SmartScript::ProcessAction(SmartScriptHolder &e, Unit* unit, uint32 var0, u                          if (Creature* target = (*itr)->ToCreature())                          {                              if (IsSmart(target)) -                                CAST_AI(SmartAI, target->AI())->SetScript9(e, e.action.timedActionList.id, mLastInvoker); +                                CAST_AI(SmartAI, target->AI())->SetScript9(e, e.action.timedActionList.id, GetLastInvoker());                          } else if (GameObject* target = (*itr)->ToGameObject())                          {                              if (IsSmartGO(target)) -                                CAST_AI(SmartGameObjectAI, target->AI())->SetScript9(e, e.action.timedActionList.id, mLastInvoker); +                                CAST_AI(SmartGameObjectAI, target->AI())->SetScript9(e, e.action.timedActionList.id, GetLastInvoker());                          }                      }                  } @@ -1362,11 +1364,11 @@ void SmartScript::ProcessAction(SmartScriptHolder &e, Unit* unit, uint32 var0, u                          if (Creature* target = (*itr)->ToCreature())                          {                              if (IsSmart(target)) -                                CAST_AI(SmartAI, target->AI())->SetScript9(e, id, mLastInvoker); +                                CAST_AI(SmartAI, target->AI())->SetScript9(e, id, GetLastInvoker());                          } else if (GameObject* target = (*itr)->ToGameObject())                          {                              if (IsSmartGO(target)) -                                CAST_AI(SmartGameObjectAI, target->AI())->SetScript9(e, id, mLastInvoker); +                                CAST_AI(SmartGameObjectAI, target->AI())->SetScript9(e, id, GetLastInvoker());                          }                      }                  } @@ -1388,11 +1390,11 @@ void SmartScript::ProcessAction(SmartScriptHolder &e, Unit* unit, uint32 var0, u                          if (Creature* target = (*itr)->ToCreature())                          {                              if (IsSmart(target)) -                                CAST_AI(SmartAI, target->AI())->SetScript9(e, id, mLastInvoker); +                                CAST_AI(SmartAI, target->AI())->SetScript9(e, id, GetLastInvoker());                          } else if (GameObject* target = (*itr)->ToGameObject())                          {                              if (IsSmartGO(target)) -                                CAST_AI(SmartGameObjectAI, target->AI())->SetScript9(e, id, mLastInvoker); +                                CAST_AI(SmartGameObjectAI, target->AI())->SetScript9(e, id, GetLastInvoker());                          }                      }                  } @@ -1570,8 +1572,8 @@ ObjectList* SmartScript::GetTargets(SmartScriptHolder e, Unit* invoker)      Unit* trigger = NULL;      if (invoker)          trigger = invoker; -    else if (mLastInvoker) -        trigger = mLastInvoker; +    else if (Unit* tempLastInvoker = GetLastInvoker()) +        trigger = tempLastInvoker;      ObjectList* l = new ObjectList();      switch (e.GetTargetType())      { @@ -2572,4 +2574,7 @@ void SmartScript::SetScript9(SmartScriptHolder &e, uint32 entry)          mResumeActionList = e.action.timedActionList.dontResume ? false : true;          InitTimer((*i));      } +}Unit* SmartScript::GetLastInvoker() +{ +    return ObjectAccessor::FindUnit(mLastInvoker);  } diff --git a/src/server/game/AI/SmartScripts/SmartScript.h b/src/server/game/AI/SmartScripts/SmartScript.h index 08ee5570a89..a5331672803 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.h +++ b/src/server/game/AI/SmartScripts/SmartScript.h @@ -191,7 +191,8 @@ class SmartScript          //TIMED_ACTIONLIST (script type 9 aka script9)          void SetScript9(SmartScriptHolder &e, uint32 entry); -        Unit* mLastInvoker; +        Unit* GetLastInvoker(); +        uint64 mLastInvoker;      private:          void IncPhase(int32 p = 1) {  | 
