Some more refactoring prep for combat/threat (#19930).

(cherry picked from commit 2739a5c5f5)
This commit is contained in:
treeston
2017-07-03 17:33:34 +02:00
committed by Shauren
parent bacc5ef94e
commit 2c88d9f162
13 changed files with 17 additions and 20 deletions

View File

@@ -221,6 +221,7 @@ class TC_GAME_API ThreatManager
// -- compatibility layer for combat rewrite (PR #19930)
Trinity::IteratorPair<std::list<ThreatReference*>::const_iterator> GetSortedThreatList() const { auto& list = iThreatContainer.getThreatList(); return { list.cbegin(), list.cend() }; }
Trinity::IteratorPair<std::list<ThreatReference*>::const_iterator> GetUnsortedThreatList() const { return GetSortedThreatList(); }
std::list<ThreatReference*> GetModifiableThreatList() const { return iThreatContainer.getThreatList(); }
Unit* SelectVictim() { return getHostilTarget(); }
Unit* GetCurrentVictim() const { if (ThreatReference* ref = getCurrentVictim()) return ref->GetVictim(); else return nullptr; }
bool IsThreatListEmpty(bool includeOffline = false) const { return includeOffline ? areThreatListsEmpty() : isThreatListEmpty(); }

View File

@@ -318,7 +318,7 @@ public:
Unit* tank = me->GetThreatManager().GetCurrentVictim();
std::vector<Unit*> targets;
for (ThreatReference* ref : me->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference const* ref : me->GetThreatManager().GetUnsortedThreatList())
{
Unit* target = ref->GetVictim();
if (target != tank && target->IsAlive() && target->GetTypeId() == TYPEID_PLAYER)

View File

@@ -992,7 +992,7 @@ public:
if (FelfirePortalTimer <= diff)
{
if (Creature* pPortal = DoSpawnCreature(NPC_FELFIRE_PORTAL, 0, 0, 0, 0, TEMPSUMMON_TIMED_DESPAWN, 20000))
for (ThreatReference* ref : me->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference const* ref : me->GetThreatManager().GetUnsortedThreatList())
AddThreat(ref->GetVictim(), 1.0f, pPortal);
FelfirePortalTimer = 20000;
} else FelfirePortalTimer -= diff;

View File

@@ -148,7 +148,7 @@ class boss_moam : public CreatureScript
{
std::list<Unit*> targetList;
{
for (ThreatReference* ref : me->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference const* ref : me->GetThreatManager().GetUnsortedThreatList())
if (ref->GetVictim()->GetTypeId() == TYPEID_PLAYER && ref->GetVictim()->GetPowerType() == POWER_MANA)
targetList.push_back(ref->GetVictim());
}

View File

@@ -649,7 +649,7 @@ public:
//Place all units in threat list on outside of stomach
Stomach_Map.clear();
for (ThreatReference* ref : me->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference const* ref : me->GetThreatManager().GetUnsortedThreatList())
Stomach_Map[ref->GetVictim()->GetGUID()] = false; //Outside stomach
//Spawn 2 flesh tentacles

View File

@@ -610,7 +610,7 @@ struct boss_faction_championsAI : public BossAI
void UpdateThreat()
{
for (ThreatReference* ref : me->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference* ref : me->GetThreatManager().GetModifiableThreatList())
if (Player* victim = ref->GetVictim()->ToPlayer())
ref->SetThreat(1000000.0f * CalculateThreat(me->GetDistance2d(victim), victim->GetArmor(), victim->GetHealth()));
}
@@ -695,7 +695,7 @@ struct boss_faction_championsAI : public BossAI
uint32 EnemiesInRange(float distance)
{
uint32 count = 0;
for (ThreatReference* ref : me->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference const* ref : me->GetThreatManager().GetUnsortedThreatList())
if (me->GetDistance2d(ref->GetVictim()) < distance)
++count;
return count;

View File

@@ -960,12 +960,9 @@ class npc_jaina_or_sylvanas_escape_hor : public CreatureScript
void DeleteAllFromThreatList(Unit* target, ObjectGuid except)
{
std::vector<ThreatReference*> toClear;
for (ThreatReference* ref : target->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference* ref : target->GetThreatManager().GetModifiableThreatList())
if (ref->GetVictim()->GetGUID() != except)
toClear.push_back(ref);
for (ThreatReference* ref : toClear)
ref->ClearThreat();
ref->ClearThreat();
}
void UpdateAI(uint32 diff) override

View File

@@ -490,7 +490,7 @@ class boss_blood_queen_lana_thel : public CreatureScript
std::list<Player*> tempTargets;
Unit* maintank = me->GetThreatManager().GetCurrentVictim();
for (ThreatReference* ref : me->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference const* ref : me->GetThreatManager().GetUnsortedThreatList())
if (Player* refTarget = ref->GetVictim()->ToPlayer())
if (refTarget != maintank && (includeOfftank || (refTarget->GetGUID() != _offtankGUID)))
tempTargets.push_back(refTarget->ToPlayer());

View File

@@ -505,7 +505,7 @@ class boss_professor_putricide : public CreatureScript
{
std::list<Unit*> targetList;
{
for (ThreatReference* ref : me->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference const* ref : me->GetThreatManager().GetUnsortedThreatList())
if (Player* target = ref->GetVictim()->ToPlayer())
targetList.push_back(target);
}

View File

@@ -124,8 +124,8 @@ public:
ThreatManager const& mgr = me->GetThreatManager();
Unit* currentVictim = mgr.GetCurrentVictim();
auto const& pair = mgr.GetSortedThreatList();
auto it = pair.begin(), end = pair.end();
auto list = mgr.GetModifiableThreatList();
auto it = list.begin(), end = list.end();
if (it == end)
EnterEvadeMode(EVADE_REASON_NO_HOSTILES);
@@ -151,8 +151,7 @@ public:
DoCast(pHatefulTarget, SPELL_HATEFUL_STRIKE, true);
// add threat to highest threat targets
if (me->GetVictim() && me->IsWithinMeleeRange(me->GetVictim()))
AddThreat(me->GetVictim(), HATEFUL_THREAT_AMT);
AddThreat(currentVictim, HATEFUL_THREAT_AMT);
if (secondThreat)
secondThreat->AddThreat(HATEFUL_THREAT_AMT);
if (thirdThreat)

View File

@@ -1831,7 +1831,7 @@ class spell_malygos_vortex_visual : public SpellScriptLoader
{
if (Creature* caster = GetCaster()->ToCreature())
{
for (ThreatReference* ref : caster->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference const* ref : caster->GetThreatManager().GetUnsortedThreatList())
{
if (Player* targetPlayer = ref->GetVictim()->ToPlayer())
{

View File

@@ -109,7 +109,7 @@ class boss_blackheart_the_inciter : public CreatureScript
{
DoCast(me, SPELL_INCITE_CHAOS);
for (ThreatReference* ref : me->GetThreatManager().GetUnsortedThreatList())
for (ThreatReference const* ref : me->GetThreatManager().GetUnsortedThreatList())
if (ref->GetVictim()->GetTypeId() == TYPEID_PLAYER)
me->CastSpell(ref->GetVictim(), SPELL_INCITE_CHAOS_B, true);

View File

@@ -527,7 +527,7 @@ public:
ThreatManager const& mgr = me->GetThreatManager();
std::list<Unit*> TargetList;
Unit* currentVictim = mgr.GetCurrentVictim();
for (ThreatReference* ref : mgr.GetSortedThreatList())
for (ThreatReference const* ref : mgr.GetSortedThreatList())
{
if (Player* tempTarget = ref->GetVictim()->ToPlayer())
if (tempTarget != currentVictim && TargetList.size()<5)