diff options
author | megamage <none@none> | 2009-08-02 10:17:07 +0800 |
---|---|---|
committer | megamage <none@none> | 2009-08-02 10:17:07 +0800 |
commit | 84694a1f92a2aa791e820145e017fb4e92d4c00c (patch) | |
tree | ebc7fb1e99ec72f79975265de4fe384e3a80aa37 /src/game/PetAI.cpp | |
parent | 41ba5c232a58f818ac43d3459787e34be5d80297 (diff) |
[8291] Now allow auto-casting pet spells out of combat by PetAI, related code cleanups. Author: VladimirMangos
--HG--
branch : trunk
Diffstat (limited to 'src/game/PetAI.cpp')
-rw-r--r-- | src/game/PetAI.cpp | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp index 7c2889d1ef1..9515cbba46d 100644 --- a/src/game/PetAI.cpp +++ b/src/game/PetAI.cpp @@ -120,11 +120,14 @@ void PetAI::UpdateAI(const uint32 diff) if(!me->GetCharmInfo()) return; - if (m_creature->GetGlobalCooldown() == 0 && !m_creature->hasUnitState(UNIT_STAT_CASTING)) + bool inCombat = me->getVictim(); + + //Autocast (casted only in combat) + if (inCombat && m_creature->GetGlobalCooldown() == 0 && !m_creature->hasUnitState(UNIT_STAT_CASTING)) { - bool inCombat = me->getVictim(); + typedef std::vector<std::pair<Unit*, Spell*> > TargetSpellList; + TargetSpellList targetSpellStore; - //Autocast for (uint8 i = 0; i < m_creature->GetPetAutoSpellSize(); ++i) { uint32 spellID = m_creature->GetPetAutoSpellOnPos(i); @@ -136,22 +139,14 @@ void PetAI::UpdateAI(const uint32 diff) continue; // ignore some combinations of combat state and combat/noncombat spells - if (!inCombat) - { - if (!IsPositiveSpell(spellInfo->Id)) - continue; - } - else - { - if (IsNonCombatSpell(spellInfo)) - continue; - } + if (IsNonCombatSpell(spellInfo)) + continue; Spell *spell = new Spell(m_creature, spellInfo, false, 0); - if(inCombat && !m_creature->hasUnitState(UNIT_STAT_FOLLOW) && spell->CanAutoCast(m_creature->getVictim())) + if (!m_creature->hasUnitState(UNIT_STAT_FOLLOW) && spell->CanAutoCast(m_creature->getVictim())) { - m_targetSpellStore.push_back(std::make_pair<Unit*, Spell*>(m_creature->getVictim(), spell)); + targetSpellStore.push_back(std::make_pair<Unit*, Spell*>(m_creature->getVictim(), spell)); continue; } else @@ -167,7 +162,7 @@ void PetAI::UpdateAI(const uint32 diff) if(spell->CanAutoCast(Target)) { - m_targetSpellStore.push_back(std::make_pair<Unit*, Spell*>(Target, spell)); + targetSpellStore.push_back(std::make_pair<Unit*, Spell*>(Target, spell)); spellUsed = true; break; } @@ -178,14 +173,14 @@ void PetAI::UpdateAI(const uint32 diff) } //found units to cast on to - if(!m_targetSpellStore.empty()) + if (!targetSpellStore.empty()) { - uint32 index = urand(0, m_targetSpellStore.size() - 1); + uint32 index = urand(0, targetSpellStore.size() - 1); - Spell* spell = m_targetSpellStore[index].second; - Unit* target = m_targetSpellStore[index].first; + Spell* spell = targetSpellStore[index].second; + Unit* target = targetSpellStore[index].first; - m_targetSpellStore.erase(m_targetSpellStore.begin() + index); + targetSpellStore.erase(targetSpellStore.begin() + index); SpellCastTargets targets; targets.setUnitTarget( target ); @@ -204,11 +199,10 @@ void PetAI::UpdateAI(const uint32 diff) spell->prepare(&targets); } - while (!m_targetSpellStore.empty()) - { - delete m_targetSpellStore.begin()->second; - m_targetSpellStore.erase(m_targetSpellStore.begin()); - } + + // deleted cached Spell objects + for(TargetSpellList::const_iterator itr = targetSpellStore.begin(); itr != targetSpellStore.end(); ++itr) + delete itr->second; } } |