From 532ab1c7f8653d1a2e48aa1f1f8a9ba1041d4bb7 Mon Sep 17 00:00:00 2001 From: Treeston Date: Wed, 3 Jan 2018 20:04:19 +0100 Subject: Core: Combat/threat system rewrite (PR #19930) - PvE combat is now always mutual. UNIT_FLAG_IN_COMBAT is backed by actual references to the units we're in combat with. - PvP combat is now also tracked, and almost always mutual; spells like Vanish and Feign Death can break this rule. That means we can easily determine a list of players we're fighting. - By extension, IsInCombatWith now has sensible behavior when invoked on nonplayers. - Threat and combat systems are no longer the same. - They still have an enforced relationship (threat implies combat - clearing combat clears threat)... - ...but we can have combat without threat. A creature (with threat list) isn't considered to be engaged until it has an entry on its threat list... - ...which means we can now faithfully replicate retail engage behavior. Combat on projectile launch - engagement start on projectile impact. Yay for progress! - AI method refactor, as already ported in 6113b9d - `JustEngagedWith`, `JustEnteredCombat` and `JustExitedCombat`. - Vehicle threat is now properly pooled on the main vehicle body (fixes #16542). - Various edge case bug fixes for threat redirects (Misdirection "cancelling" Vigilance and similar). - Target re-selection is now significantly faster. - Fixed a ton of other smaller edge case bugs, probably. Closes #7951 and #19998. --- .../MagistersTerrace/boss_felblood_kaelthas.cpp | 52 ++++++++-------------- .../MagistersTerrace/boss_priestess_delrissa.cpp | 26 ++++------- 2 files changed, 26 insertions(+), 52 deletions(-) (limited to 'src/server/scripts/EasternKingdoms') diff --git a/src/server/scripts/EasternKingdoms/MagistersTerrace/boss_felblood_kaelthas.cpp b/src/server/scripts/EasternKingdoms/MagistersTerrace/boss_felblood_kaelthas.cpp index 6635fc0bc7b..4ffaf1c5f42 100644 --- a/src/server/scripts/EasternKingdoms/MagistersTerrace/boss_felblood_kaelthas.cpp +++ b/src/server/scripts/EasternKingdoms/MagistersTerrace/boss_felblood_kaelthas.cpp @@ -199,30 +199,21 @@ public: if (!summonedUnit) return; - ThreatContainer::StorageType const& threatlist = me->GetThreatManager().getThreatList(); - ThreatContainer::StorageType::const_iterator i = threatlist.begin(); - for (i = threatlist.begin(); i != threatlist.end(); ++i) + for (auto* ref : me->GetThreatManager().GetUnsortedThreatList()) { - Unit* unit = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()); + Unit* unit = ref->GetVictim(); if (unit && unit->IsAlive()) - { - float threat = me->GetThreatManager().getThreat(unit); - AddThreat(unit, threat, summonedUnit); - } + AddThreat(unit, ref->GetThreat(), summonedUnit); } } void TeleportPlayersToSelf() { - float x = KaelLocations[0][0]; - float y = KaelLocations[0][1]; - me->UpdatePosition(x, y, LOCATION_Z, 0.0f); - ThreatContainer::StorageType threatlist = me->GetThreatManager().getThreatList(); - ThreatContainer::StorageType::const_iterator i = threatlist.begin(); - for (i = threatlist.begin(); i != threatlist.end(); ++i) + me->UpdatePosition(KaelLocations[0][0], KaelLocations[0][1], LOCATION_Z, 0.0f); + for (auto const& pair : me->GetCombatManager().GetPvECombatRefs()) { - Unit* unit = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()); - if (unit && (unit->GetTypeId() == TYPEID_PLAYER)) + Unit* unit = pair.second->GetOther(me); + if (unit->GetTypeId() == TYPEID_PLAYER) unit->CastSpell(unit, SPELL_TELEPORT_CENTER, true); } DoCast(me, SPELL_TELEPORT_CENTER, true); @@ -230,14 +221,11 @@ public: void CastGravityLapseKnockUp() { - ThreatContainer::StorageType threatlist = me->GetThreatManager().getThreatList(); - ThreatContainer::StorageType::const_iterator i = threatlist.begin(); - for (i = threatlist.begin(); i != threatlist.end(); ++i) + for (auto const& pair : me->GetCombatManager().GetPvECombatRefs()) { - Unit* unit = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()); - if (unit && (unit->GetTypeId() == TYPEID_PLAYER)) + Unit* unit = pair.second->GetOther(me); + if (unit->GetTypeId() == TYPEID_PLAYER) { - // Knockback into the air CastSpellExtraArgs args; args.TriggerFlags = TRIGGERED_FULL_MASK; args.OriginalCaster = me->GetGUID(); @@ -248,12 +236,10 @@ public: void CastGravityLapseFly() // Use Fly Packet hack for now as players can't cast "fly" spells unless in map 530. Has to be done a while after they get knocked into the air... { - ThreatContainer::StorageType threatlist = me->GetThreatManager().getThreatList(); - ThreatContainer::StorageType::const_iterator i = threatlist.begin(); - for (i = threatlist.begin(); i != threatlist.end(); ++i) + for (auto const& pair : me->GetCombatManager().GetPvECombatRefs()) { - Unit* unit = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()); - if (unit && (unit->GetTypeId() == TYPEID_PLAYER)) + Unit* unit = pair.second->GetOther(me); + if (unit->GetTypeId() == TYPEID_PLAYER) { // Also needs an exception in spell system. CastSpellExtraArgs args; @@ -267,12 +253,10 @@ public: void RemoveGravityLapse() { - ThreatContainer::StorageType threatlist = me->GetThreatManager().getThreatList(); - ThreatContainer::StorageType::const_iterator i = threatlist.begin(); - for (i = threatlist.begin(); i != threatlist.end(); ++i) + for (auto const& pair : me->GetCombatManager().GetPvECombatRefs()) { - Unit* unit = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()); - if (unit && (unit->GetTypeId() == TYPEID_PLAYER)) + Unit* unit = pair.second->GetOther(me); + if (unit->GetTypeId() == TYPEID_PLAYER) { unit->RemoveAurasDueToSpell(SPELL_GRAVITY_LAPSE_FLY); unit->RemoveAurasDueToSpell(SPELL_GRAVITY_LAPSE_DOT); @@ -684,8 +668,8 @@ public: { if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 100, true)) { - AddThreat(target, 1.0f); - me->TauntApply(target); + ResetThreatList(); + AddThreat(target, 1000000.0f); AttackStart(target); } diff --git a/src/server/scripts/EasternKingdoms/MagistersTerrace/boss_priestess_delrissa.cpp b/src/server/scripts/EasternKingdoms/MagistersTerrace/boss_priestess_delrissa.cpp index 9480bf038a5..6d7816ff0d8 100644 --- a/src/server/scripts/EasternKingdoms/MagistersTerrace/boss_priestess_delrissa.cpp +++ b/src/server/scripts/EasternKingdoms/MagistersTerrace/boss_priestess_delrissa.cpp @@ -855,17 +855,12 @@ public: if (Blink_Timer <= diff) { bool InMeleeRange = false; - ThreatContainer::StorageType const& t_list = me->GetThreatManager().getThreatList(); - for (ThreatContainer::StorageType::const_iterator itr = t_list.begin(); itr!= t_list.end(); ++itr) + for (auto const& pair : me->GetCombatManager().GetPvECombatRefs()) { - if (Unit* target = ObjectAccessor::GetUnit(*me, (*itr)->getUnitGuid())) + if (pair.second->GetOther(me)->IsWithinMeleeRange(me)) { - //if in melee range - if (target->IsWithinDistInMap(me, 5)) - { - InMeleeRange = true; - break; - } + InMeleeRange = true; + break; } } @@ -949,17 +944,12 @@ public: if (Intercept_Stun_Timer <= diff) { bool InMeleeRange = false; - ThreatContainer::StorageType const& t_list = me->GetThreatManager().getThreatList(); - for (ThreatContainer::StorageType::const_iterator itr = t_list.begin(); itr!= t_list.end(); ++itr) + for (auto const& pair : me->GetCombatManager().GetPvECombatRefs()) { - if (Unit* target = ObjectAccessor::GetUnit(*me, (*itr)->getUnitGuid())) + if (pair.second->GetOther(me)->IsWithinMeleeRange(me)) { - //if in melee range - if (target->IsWithinDistInMap(me, ATTACK_DISTANCE)) - { - InMeleeRange = true; - break; - } + InMeleeRange = true; + break; } } -- cgit v1.2.3