From 34c7810fe507eca1b8b9389630db5d5d26d92e77 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. (cherry picked from commit 532ab1c7f8653d1a2e48aa1f1f8a9ba1041d4bb7) --- src/server/scripts/World/npcs_special.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/server/scripts/World') diff --git a/src/server/scripts/World/npcs_special.cpp b/src/server/scripts/World/npcs_special.cpp index 3c8dac9d8de..0591f7c4a76 100644 --- a/src/server/scripts/World/npcs_special.cpp +++ b/src/server/scripts/World/npcs_special.cpp @@ -1806,21 +1806,28 @@ public: { case EVENT_TD_CHECK_COMBAT: { - time_t now = GameTime::GetGameTime(); - for (std::unordered_map::iterator itr = _damageTimes.begin(); itr != _damageTimes.end();) + time_t const now = GameTime::GetGameTime(); + auto const& pveRefs = me->GetCombatManager().GetPvECombatRefs(); + for (auto itr = _damageTimes.begin(); itr != _damageTimes.end();) { // If unit has not dealt damage to training dummy for 5 seconds, remove him from combat if (itr->second < now - 5) { - if (Unit* unit = ObjectAccessor::GetUnit(*me, itr->first)) - unit->getHostileRefManager().deleteReference(me); + auto it = pveRefs.find(itr->first); + if (it != pveRefs.end()) + it->second->EndCombat(); itr = _damageTimes.erase(itr); } else ++itr; } - _events.ScheduleEvent(EVENT_TD_CHECK_COMBAT, 1000); + + for (auto const& pair : pveRefs) + if (_damageTimes.find(pair.first) == _damageTimes.end()) + _damageTimes[pair.first] = now; + + _events.Repeat(1s); break; } case EVENT_TD_DESPAWN: -- cgit v1.2.3