[8291] Now allow auto-casting pet spells out of combat by PetAI, related code cleanups.

This commit is contained in:
VladimirMangos 2009-08-01 23:18:55 +04:00
parent f27a29faef
commit f10653833f
3 changed files with 20 additions and 29 deletions

View file

@ -194,9 +194,12 @@ void PetAI::UpdateAI(const uint32 diff)
}
}
if (m_creature->GetGlobalCooldown() == 0 && !m_creature->IsNonMeleeSpellCasted(false))
//Autocast (casted only in combat)
if (inCombat && m_creature->GetGlobalCooldown() == 0 && !m_creature->IsNonMeleeSpellCasted(false))
{
//Autocast
typedef std::vector<std::pair<Unit*, Spell*> > TargetSpellList;
TargetSpellList targetSpellStore;
for (uint8 i = 0; i < m_creature->GetPetAutoSpellSize(); ++i)
{
uint32 spellID = m_creature->GetPetAutoSpellOnPos(i);
@ -208,22 +211,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;
}
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
@ -239,7 +234,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;
}
@ -250,14 +245,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 );
@ -276,11 +271,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;
}
}

View file

@ -52,8 +52,5 @@ class MANGOS_DLL_DECL PetAI : public CreatureAI
bool inCombat;
std::set<uint64> m_AllySet;
uint32 m_updateAlliesTimer;
typedef std::pair<Unit*, Spell*> TargetSpellPair;
std::vector<TargetSpellPair> m_targetSpellStore;
};
#endif

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "8290"
#define REVISION_NR "8291"
#endif // __REVISION_NR_H__