[3.3.5] Combat/Threat rewrite - prep & refactor (#19966)

* Combat/Threat rewrite (PR #19930) prep work. Mostly refactors, and a compatibility layer on ThreatManager/HostileReference that allows scripts to be changed already.

(cherry picked from commit e2a1ccd118d129b96e09ff1a15ed0adb1d4a3897)
This commit is contained in:
Treeston
2020-08-13 22:46:44 +02:00
committed by Shauren
parent 2c99678118
commit 8be23fcbbd
187 changed files with 981 additions and 1133 deletions
+7 -38
View File
@@ -83,21 +83,13 @@ class npc_pet_mage_mirror_image : public CreatureScript
continue;
}
// else compare best fit unit with current unit
ThreatContainer::StorageType triggers = (*iter)->getThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator trig_citr = triggers.begin(); trig_citr != triggers.end(); ++trig_citr)
float threat = (*iter)->GetThreatManager().GetThreat(owner);
// Check if best fit hostile unit hs lower threat than this current unit
if (highestThreat < threat)
{
// Try to find threat referenced to owner
if ((*trig_citr)->getTarget() == owner)
{
// Check if best fit hostile unit hs lower threat than this current unit
if (highestThreat < (*trig_citr)->getThreat())
{
// If so, update best fit unit
highestThreat = (*trig_citr)->getThreat();
highestThreatUnit = (*iter);
break;
}
}
// If so, update best fit unit
highestThreat = threat;
highestThreatUnit = (*iter);
}
// In case no unit with threat was found so far, always check for nearest unit (only for players)
if ((*iter)->GetTypeId() == TYPEID_PLAYER)
@@ -119,30 +111,7 @@ class npc_pet_mage_mirror_image : public CreatureScript
bool IsInThreatList(Unit* target)
{
Unit* owner = me->GetCharmerOrOwner();
std::list<Unit*> targets;
Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, 30.0f);
Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
Cell::VisitAllObjects(me, searcher, 40.0f);
for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
{
if ((*iter) == target)
{
// Consider only units without CC
if (!(*iter)->HasBreakableByDamageCrowdControlAura((*iter)))
{
ThreatContainer::StorageType triggers = (*iter)->getThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator trig_citr = triggers.begin(); trig_citr != triggers.end(); ++trig_citr)
{
// Try to find threat referenced to owner
if ((*trig_citr)->getTarget() == owner)
return true;
}
}
}
}
return false;
return owner && target->IsThreatenedBy(owner);
}
void InitializeAI() override