18 #ifndef TRINITY_THREATMANAGER_H
19 #define TRINITY_THREATMANAGER_H
27#include <unordered_map>
86 static const uint32 THREAT_UPDATE_INTERVAL = 1000u;
88 static bool CanHaveThreatList(
Unit const* who);
100 void ResetUpdateTimer();
108 Unit* GetCurrentVictim();
109 Unit* GetLastVictim()
const;
111 Unit* GetAnyTarget()
const;
114 bool IsThreatListEmpty(
bool includeOffline =
false)
const;
116 bool IsThreatenedBy(
ObjectGuid const& who,
bool includeOffline =
false)
const;
118 bool IsThreatenedBy(
Unit const* who,
bool includeOffline =
false)
const;
120 float GetThreat(
Unit const* who,
bool includeOffline =
false)
const;
121 size_t GetThreatListSize()
const;
122 uint32 GetThreatListPlayerCount(
bool includeOffline =
false)
const;
131 std::vector<ThreatReference*> GetModifiableThreatList();
134 bool IsThreateningAnyone(
bool includeOffline =
false)
const;
136 bool IsThreateningTo(
ObjectGuid const& who,
bool includeOffline =
false)
const;
138 bool IsThreateningTo(
Unit const* who,
bool includeOffline =
false)
const;
142 void EvaluateSuppressed(
bool canExpire =
false);
144 void AddThreat(
Unit* target,
float amount,
SpellInfo const* spell =
nullptr,
bool ignoreModifiers =
false,
bool ignoreRedirects =
false);
145 void ScaleThreat(
Unit* target,
float factor);
151 void MatchUnitThreatToHighestThreat(
Unit* target);
155 void ResetAllThreat();
157 void ClearThreat(
Unit* target);
160 void ClearAllThreat();
164 void FixateTarget(
Unit* target);
166 Unit* GetFixateTarget()
const;
170 void ForwardThreatForAssistingMe(
Unit* assistant,
float baseAmount,
SpellInfo const* spell =
nullptr,
bool ignoreModifiers =
false);
172 void RemoveMeFromThreatLists(
bool (*unitFilter)(
Unit const* otherUnit));
174 void UpdateMyTempModifiers();
176 void UpdateMySpellSchoolModifiers();
180 void RegisterRedirectThreat(
uint32 spellId,
ObjectGuid const& victim,
float pct);
182 void UnregisterRedirectThreat(
uint32 spellId);
192 static float CalculateModifiedThreat(
float threat,
Unit const* victim,
SpellInfo const* spell);
195 void SendClearAllThreatToClients()
const;
196 void SendRemoveToClients(
Unit const* victim)
const;
197 void SendThreatListToClients(
bool newHighest)
const;
201 void PurgeThreatListRef(
ObjectGuid const& guid);
211 void ProcessAIUpdates();
212 void RegisterForAIUpdate(
ObjectGuid const& guid);
223 void PurgeThreatenedByMeRef(
ObjectGuid const& guid);
229 void UpdateRedirectInfo();
245 : _generator(
std::move(generator)), _current(_generator()) {}
253 bool operator==(std::nullptr_t)
const {
return _current ==
nullptr; }
254 bool operator!=(std::nullptr_t)
const {
return _current !=
nullptr; }
267 enum TauntState :
uint32 { TAUNT_STATE_DETAUNT = 0, TAUNT_STATE_NONE = 1, TAUNT_STATE_TAUNT = 2 };
268 enum OnlineState { ONLINE_STATE_ONLINE = 2, ONLINE_STATE_SUPPRESSED = 1, ONLINE_STATE_OFFLINE = 0 };
272 float GetThreat()
const {
return std::max<float>(_baseAmount + _tempModifier, 0.0f); }
274 bool IsOnline()
const {
return (_online >= ONLINE_STATE_ONLINE); }
275 bool IsAvailable()
const {
return (_online > ONLINE_STATE_OFFLINE); }
276 bool IsSuppressed()
const {
return (_online == ONLINE_STATE_SUPPRESSED); }
277 bool IsOffline()
const {
return (_online <= ONLINE_STATE_OFFLINE); }
279 bool IsTaunting()
const {
return _taunted >= TAUNT_STATE_TAUNT; }
280 bool IsDetaunted()
const {
return _taunted == TAUNT_STATE_DETAUNT; }
282 void AddThreat(
float amount);
283 void ScaleThreat(
float factor);
285 void UpdateOffline();
290 static bool FlagsAllowFighting(
Unit const* a,
Unit const* b);
293 _owner(reinterpret_cast<
Creature*>(mgr->_owner)), _mgr(*mgr), _victim(victim),
294 _baseAmount(0.0f), _tempModifier(0.0f), _taunted(TAUNT_STATE_NONE)
296 _online = ONLINE_STATE_OFFLINE;
301 void UnregisterAndFree();
303 bool ShouldBeOffline()
const;
304 bool ShouldBeSuppressed()
const;
305 void UpdateTauntState(
TauntState state = TAUNT_STATE_NONE);
308 void HeapNotifyIncreased();
309 void HeapNotifyDecreased();
ThreatReference const * operator*() const
ThreatListIterator(std::function< ThreatReference const *()> &&generator)
ThreatReference const * operator->() const
ThreatReference const * _current
bool operator==(ThreatListIterator const &o) const
bool operator!=(std::nullptr_t) const
bool operator==(std::nullptr_t) const
bool operator!=(ThreatListIterator const &o) const
ThreatListIterator & operator++()
std::unordered_map< ObjectGuid, ThreatReference * > _threatenedByMe
bool CanHaveThreatList() const
ThreatManager & operator=(ThreatManager const &)=delete
void ResetThreat(Unit *target)
std::array< float, MAX_SPELL_SCHOOL > _singleSchoolModifiers
static bool CompareReferencesLT(ThreatReference const *a, ThreatReference const *b, float aWeight)
auto const & GetThreatenedByMeList() const
static const CompareThreatLessThan CompareThreat
std::unique_ptr< Heap > _sortedThreatList
ThreatReference const * _currentVictimRef
std::unordered_map< ObjectGuid, ThreatReference * > _myThreatListEntries
void ModifyThreatByPercent(Unit *target, float percent)
bool _ownerCanHaveThreatList
std::vector< ObjectGuid > _needsAIUpdate
ThreatManager(ThreatManager const &)=delete
std::unordered_map< uint32, std::unordered_map< ObjectGuid, float > > _redirectRegistry
ThreatReference const * _fixateRef
std::unordered_map< std::underlying_type< SpellSchoolMask >::type, float > _multiSchoolModifiers
std::vector< std::pair< ObjectGuid, float > > _redirectInfo
bool _needThreatClearUpdate
void ModifyThreatByPercent(int32 percent)
bool IsSuppressed() const
Creature * GetOwner() const
OnlineState GetOnlineState() const
ThreatReference(ThreatReference const &)=delete
TauntState GetTauntState() const
ThreatReference(ThreatManager *mgr, Unit *victim)
virtual ~ThreatReference()=default
ThreatReference & operator=(ThreatReference const &)=delete
Utility class to enable range for loop syntax for multimap.equal_range uses.
bool operator()(ThreatReference const *a, ThreatReference const *b) const