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. --- src/server/game/AI/ScriptedAI/ScriptedCreature.cpp | 11 ++++++----- src/server/game/AI/ScriptedAI/ScriptedCreature.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/server/game/AI/ScriptedAI') diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index 6f0c378f61f..d3aba9f9a04 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -520,11 +520,12 @@ void BossAI::TeleportCheaters() float x, y, z; me->GetPosition(x, y, z); - ThreatContainer::StorageType threatList = me->GetThreatManager().getThreatList(); - for (ThreatContainer::StorageType::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr) - if (Unit* target = (*itr)->getTarget()) - if (target->GetTypeId() == TYPEID_PLAYER && !CheckBoundary(target)) - target->NearTeleportTo(x, y, z, 0); + for (auto const& pair : me->GetCombatManager().GetPvECombatRefs()) + { + Unit* target = pair.second->GetOther(me); + if (target->IsControlledByPlayer() && !CheckBoundary(target)) + target->NearTeleportTo(x, y, z, 0); + } } void BossAI::JustSummoned(Creature* summon) diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index bd3e33307b6..1aeb6a65db7 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -186,7 +186,7 @@ struct TC_GAME_API ScriptedAI : public CreatureAI void Reset() override { } //Called at creature aggro either by MoveInLOS or Attack Start - void JustEngagedWith(Unit* /*victim*/) override { } + void JustEngagedWith(Unit* /*who*/) override { } // Called before JustEngagedWith even before the creature is in combat. void AttackStart(Unit* /*target*/) override; -- cgit v1.2.3