refactor(Core/Combat): Port TrinityCore heap-based threat system (#24715)

Co-authored-by: blinkysc <blinkysc@users.noreply.github.com>
Co-authored-by: Treeston <treeston.mmoc@gmail.com>
Co-authored-by: killerwife <killerwife@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
blinkysc
2026-03-18 13:36:59 -05:00
committed by GitHub
parent c80a0f1fad
commit 984baa92dd
101 changed files with 7045 additions and 2659 deletions
@@ -85,15 +85,16 @@ struct boss_blackheart_the_inciter : public BossAI
DoCastAOE(SPELL_INCITE_CHAOS);
DoCastSelf(SPELL_LAUGHTER, true);
uint32 inciteTriggerID = NPC_INCITE_TRIGGER;
std::list<HostileReference*> t_list = me->GetThreatMgr().GetThreatList();
for (std::list<HostileReference*>::const_iterator itr = t_list.begin(); itr != t_list.end(); ++itr)
for (ThreatReference const* ref : me->GetThreatMgr().GetUnsortedThreatList())
{
Unit* target = ObjectAccessor::GetUnit(*me, (*itr)->getUnitGuid());
if (target && target->IsPlayer())
if (Unit* target = ref->GetVictim())
{
if (Creature* inciteTrigger = me->SummonCreature(inciteTriggerID++, *target, TEMPSUMMON_TIMED_DESPAWN, 15 * IN_MILLISECONDS))
if (target->IsPlayer())
{
inciteTrigger->CastSpell(target, SPELL_INCITE_CHAOS_B, true);
if (Creature* inciteTrigger = me->SummonCreature(inciteTriggerID++, *target, TEMPSUMMON_TIMED_DESPAWN, 15 * IN_MILLISECONDS))
{
inciteTrigger->CastSpell(target, SPELL_INCITE_CHAOS_B, true);
}
}
}
}
@@ -87,7 +87,7 @@ struct boss_murmur : public BossAI
void EnterEvadeMode(EvadeReason why) override
{
if (me->GetThreatMgr().GetThreatList().empty())
if (me->GetThreatMgr().IsThreatListEmpty())
{
BossAI::EnterEvadeMode(why);
}
@@ -1104,7 +1104,7 @@ struct npc_maiev_illidan : public ScriptedAI
void Reset() override
{
scheduler.CancelAll();
me->m_Events.KillAllEvents(true);
me->m_Events.KillAllEvents(false);
}
void DoAction(int32 param) override
@@ -168,13 +168,14 @@ struct boss_supremus : public BossAI
Unit* FindHatefulStrikeTarget()
{
Unit* target = nullptr;
ThreatContainer::StorageType const& threatlist = me->GetThreatMgr().GetThreatList();
for (ThreatContainer::StorageType::const_iterator i = threatlist.begin(); i != threatlist.end(); ++i)
for (ThreatReference const* ref : me->GetThreatMgr().GetUnsortedThreatList())
{
Unit* unit = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid());
if (unit && me->IsWithinMeleeRange(unit))
if (!target || unit->GetHealth() > target->GetHealth())
target = unit;
if (Unit* unit = ref->GetVictim())
{
if (me->IsWithinMeleeRange(unit))
if (!target || unit->GetHealth() > target->GetHealth())
target = unit;
}
}
return target;
@@ -215,8 +215,9 @@ class spell_black_template_harpooners_mark_aura : public AuraScript
GetUnitOwner()->GetCreaturesWithEntryInRange(creatureList, 80.0f, NPC_DRAGON_TURTLE);
for (std::list<Creature*>::const_iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr)
{
(*itr)->TauntApply(GetUnitOwner());
(*itr)->AddThreat(GetUnitOwner(), 10000000.0f);
if ((*itr)->AI())
(*itr)->AI()->AttackStart(GetUnitOwner());
_turtleSet.insert((*itr)->GetGUID());
}
}
@@ -226,7 +227,6 @@ class spell_black_template_harpooners_mark_aura : public AuraScript
for (ObjectGuid const& guid : _turtleSet)
if (Creature* turtle = ObjectAccessor::GetCreature(*GetUnitOwner(), guid))
{
turtle->TauntFadeOut(GetUnitOwner());
turtle->AddThreat(GetUnitOwner(), -10000000.0f);
}
}
@@ -212,10 +212,9 @@ struct boss_the_lurker_below : public BossAI
}
else
{
ThreatContainer::StorageType const& t_list = me->GetThreatMgr().GetThreatList();
for (ThreatReference const* ref : t_list)
for (ThreatReference const* ref : me->GetThreatMgr().GetUnsortedThreatList())
{
if (Unit* threatTarget = ObjectAccessor::GetUnit(*me, ref->getUnitGuid()))
if (Unit* threatTarget = ref->GetVictim())
{
if (me->IsWithinMeleeRange(threatTarget))
{
@@ -172,7 +172,7 @@ struct boss_alar : public BossAI
{
if (why == EVADE_REASON_BOUNDARY)
BossAI::EnterEvadeMode(why);
else if (me->GetThreatMgr().GetThreatList().empty())
else if (me->GetThreatMgr().IsThreatListEmpty())
BossAI::EnterEvadeMode(why);
}
@@ -1083,13 +1083,14 @@ class spell_kaelthas_nether_beam : public SpellScript
{
PreventHitEffect(effIndex);
ThreatContainer::StorageType const& ThreatList = GetCaster()-> GetThreatMgr().GetThreatList();
std::list<Unit*> targetList;
for (ThreatContainer::StorageType::const_iterator itr = ThreatList.begin(); itr != ThreatList.end(); ++itr)
for (ThreatReference const* ref : GetCaster()->GetThreatMgr().GetUnsortedThreatList())
{
Unit* target = ObjectAccessor::GetUnit(*GetCaster(), (*itr)->getUnitGuid());
if (target && target->IsPlayer())
targetList.push_back(target);
if (Unit* target = ref->GetVictim())
{
if (target->IsPlayer())
targetList.push_back(target);
}
}
Acore::Containers::RandomResize(targetList, 5);
@@ -59,8 +59,9 @@ class spell_botanica_call_of_the_falcon_aura : public AuraScript
GetUnitOwner()->GetCreaturesWithEntryInRange(creatureList, 80.0f, NPC_BLOODFALCON);
for (std::list<Creature*>::const_iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr)
{
(*itr)->TauntApply(GetUnitOwner());
(*itr)->AddThreat(GetUnitOwner(), 10000000.0f);
if ((*itr)->AI())
(*itr)->AI()->AttackStart(GetUnitOwner());
_falconSet.insert((*itr)->GetGUID());
}
}
@@ -70,7 +71,6 @@ class spell_botanica_call_of_the_falcon_aura : public AuraScript
for (ObjectGuid const& guid : _falconSet)
if (Creature* falcon = ObjectAccessor::GetCreature(*GetUnitOwner(), guid))
{
falcon->TauntFadeOut(GetUnitOwner());
falcon->AddThreat(GetUnitOwner(), -10000000.0f);
}
}
@@ -195,7 +195,6 @@ public:
if (Creature* Target = GetClosestCreatureWithEntry(me, NPC_DEATHS_DOOR_FEL_CANNON_TARGET_BUNNY, 200.0f))
{
me->SetFacingToObject(Target);
me->TauntFadeOut(Target);
me->CombatStop(); // force
}