[11991] Use unMaxTargets for GO-target fills

Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
Schmoozerd 2012-05-09 23:06:46 +02:00
parent 414d432d24
commit 3c3db7311c
2 changed files with 41 additions and 9 deletions

View file

@ -1790,6 +1790,8 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
unMaxTargets += (*m)->GetModifier()->m_amount;
}
std::list<GameObject*> tempTargetGOList;
switch (targetMode)
{
case TARGET_RANDOM_NEARBY_LOC:
@ -2184,8 +2186,6 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
SpellScriptTargetBounds bounds = sSpellMgr.GetSpellScriptTargetBounds(m_spellInfo->Id);
std::list<GameObject*> tempTargetGOList;
for(SpellScriptTarget::const_iterator i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST)
{
if (i_spellST->second.type == SPELL_TARGET_TYPE_GAMEOBJECT)
@ -2197,12 +2197,6 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
}
}
if (!tempTargetGOList.empty())
{
for(std::list<GameObject*>::iterator iter = tempTargetGOList.begin(); iter != tempTargetGOList.end(); ++iter)
AddGOTarget(*iter, effIndex);
}
break;
}
case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
@ -2980,6 +2974,44 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
if (removed_utarget && m_targets.getUnitTarget())
targetUnitMap.push_back(m_targets.getUnitTarget());
}
if (!tempTargetGOList.empty()) // GO CASE
{
if (unMaxTargets && tempTargetGOList.size() > unMaxTargets)
{
// make sure one go is always removed per iteration
uint32 removed_utarget = 0;
for (std::list<GameObject*>::iterator itr = tempTargetGOList.begin(), next; itr != tempTargetGOList.end(); itr = next)
{
next = itr;
++next;
if (!*itr) continue;
if ((*itr) == m_targets.getGOTarget())
{
tempTargetGOList.erase(itr);
removed_utarget = 1;
// break;
}
}
// remove random units from the map
while (tempTargetGOList.size() > unMaxTargets - removed_utarget)
{
uint32 poz = urand(0, tempTargetGOList.size()-1);
for (std::list<GameObject*>::iterator itr = tempTargetGOList.begin(); itr != tempTargetGOList.end(); ++itr, --poz)
{
if (!*itr) continue;
if (!poz)
{
tempTargetGOList.erase(itr);
break;
}
}
}
}
// Add resulting GOs as GOTargets
for (std::list<GameObject*>::iterator iter = tempTargetGOList.begin(); iter != tempTargetGOList.end(); ++iter)
AddGOTarget(*iter, effIndex);
}
}
void Spell::prepare(SpellCastTargets const* targets, Aura* triggeredByAura)