[11136] Add Creature::FillGuidsListFromThreatList for safe guid iteration from threat list.

Often not 100%-safe iterate by live threat list because called code can modify threat list (reset for example).
This commit is contained in:
VladimirMangos 2011-02-11 21:32:25 +03:00
parent 37afce30e0
commit 5858aae4d9
3 changed files with 19 additions and 1 deletions

View file

@ -2392,3 +2392,18 @@ void Creature::ApplyGameEventSpells(GameEventCreatureData const* eventData, bool
if (cast_spell)
CastSpell(this, cast_spell, true);
}
void Creature::FillGuidsListFromThreatList( std::vector<ObjectGuid>& guids, uint32 maxamount /*= 0*/ )
{
if (!CanHaveThreatList())
return;
ThreatList const& threats = getThreatManager().getThreatList();
maxamount = maxamount > 0 ? std::min(maxamount,uint32(threats.size())) : threats.size();
guids.reserve(guids.size() + maxamount);
for (ThreatList::const_iterator itr = threats.begin(); maxamount && itr != threats.end(); ++itr, --maxamount)
guids.push_back((*itr)->getUnitGuid());
}