aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Combat/ThreatManager.h
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2017-07-01 20:18:02 +0200
committerShauren <shauren.trinity@gmail.com>2020-08-13 22:46:44 +0200
commit8be23fcbbdf26e8169defd761e61765f301bebe0 (patch)
tree6309b79f7dd617a8ddc801624dbbd4ed7ac22174 /src/server/game/Combat/ThreatManager.h
parent2c99678118798279372f17d4bb5f5a88ac95c413 (diff)
[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)
Diffstat (limited to 'src/server/game/Combat/ThreatManager.h')
-rw-r--r--src/server/game/Combat/ThreatManager.h42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/server/game/Combat/ThreatManager.h b/src/server/game/Combat/ThreatManager.h
index 118fbd2a328..1b9a4c9c8eb 100644
--- a/src/server/game/Combat/ThreatManager.h
+++ b/src/server/game/Combat/ThreatManager.h
@@ -23,6 +23,7 @@
#include "LinkedReference/Reference.h"
#include "UnitEvents.h"
#include "ObjectGuid.h"
+#include "IteratorPair.h"
#include <list>
@@ -50,6 +51,19 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager>
public:
HostileReference(Unit* refUnit, ThreatManager* threatManager, float threat);
+ // -- compatibility layer for combat rewrite (PR #19930)
+ Unit* GetOwner() const;
+ Unit* GetVictim() const { return getTarget(); }
+ void AddThreat(float amt) { addThreat(amt); }
+ void SetThreat(float amt) { setThreat(amt); }
+ void ModifyThreatByPercent(int32 pct) { addThreatPercent(pct); }
+ void ScaleThreat(float factor) { setThreat(iThreat*factor); }
+ bool IsOnline() const { return iOnline; }
+ bool IsAvailable() const { return iOnline; }
+ bool IsOffline() const { return !iOnline; }
+ float GetThreat() const { return getThreat(); }
+ void ClearThreat() { removeReference(); }
+
//=================================================
void addThreat(float modThreat);
@@ -156,7 +170,7 @@ class TC_GAME_API ThreatContainer
HostileReference* addThreat(Unit* victim, float threat);
- void modifyThreatPercent(Unit* victim, int32 percent);
+ void ModifyThreatByPercent(Unit* victim, int32 percent);
HostileReference* selectNextVictim(Creature* attacker, HostileReference* currentVictim) const;
@@ -174,7 +188,7 @@ class TC_GAME_API ThreatContainer
return iThreatList.empty() ? nullptr : iThreatList.front();
}
- HostileReference* getReferenceByTarget(Unit* victim) const;
+ HostileReference* getReferenceByTarget(Unit const* victim) const;
StorageType const & getThreatList() const { return iThreatList; }
@@ -200,9 +214,31 @@ class TC_GAME_API ThreatContainer
//=================================================
+typedef HostileReference ThreatReference;
class TC_GAME_API ThreatManager
{
public:
+ // -- compatibility layer for combat rewrite (PR #19930)
+ Trinity::IteratorPair<std::list<ThreatReference*>::const_iterator> GetSortedThreatList() const { auto& list = iThreatContainer.getThreatList(); return { list.cbegin(), list.cend() }; }
+ Trinity::IteratorPair<std::list<ThreatReference*>::const_iterator> GetUnsortedThreatList() const { return GetSortedThreatList(); }
+ Unit* SelectVictim() { return getHostilTarget(); }
+ Unit* GetCurrentVictim() const { if (ThreatReference* ref = getCurrentVictim()) return ref->GetVictim(); else return nullptr; }
+ bool IsThreatListEmpty(bool includeOffline = false) const { return includeOffline ? areThreatListsEmpty() : isThreatListEmpty(); }
+ bool IsThreatenedBy(Unit const* who, bool includeOffline = false) const { return (FindReference(who, includeOffline) != nullptr); }
+ size_t GetThreatListSize() const { return iThreatContainer.iThreatList.size(); }
+ void ForwardThreatForAssistingMe(Unit* victim, float amount, SpellInfo const* spell, bool ignoreModifiers = false, bool ignoreRedirection = false);
+ Unit* GetAnyTarget() const { auto const& list = getThreatList(); if (!list.empty()) return list.front()->getTarget(); return nullptr; }
+ void ResetThreat(Unit const* who) { if (auto* ref = FindReference(who, true)) ref->setThreat(0.0f); }
+ void ResetAllThreat() { resetAllAggro(); }
+ float GetThreat(Unit const* who, bool includeOffline = false) const { if (auto* ref = FindReference(who, includeOffline)) return ref->GetThreat(); return 0.0f; }
+ void ClearThreat(Unit const* who) { if (auto* ref = FindReference(who, true)) ref->removeReference(); }
+ void ClearAllThreat();
+ void AddThreat(Unit* victim, float amount, SpellInfo const* spell = nullptr, bool ignoreModifiers = false, bool ignoreRedirection = false);
+ private:
+ HostileReference* FindReference(Unit const* who, bool includeOffline) const { if (auto* ref = iThreatContainer.getReferenceByTarget(who)) return ref; if (includeOffline) if (auto* ref = iThreatOfflineContainer.getReferenceByTarget(who)) return ref; return nullptr; }
+
+ public:
+
friend class HostileReference;
explicit ThreatManager(Unit* owner);
@@ -215,7 +251,7 @@ class TC_GAME_API ThreatManager
void doAddThreat(Unit* victim, float threat);
- void modifyThreatPercent(Unit* victim, int32 percent);
+ void ModifyThreatByPercent(Unit* victim, int32 percent);
float getThreat(Unit* victim, bool alsoSearchOfflineList = false);