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;
130 std::vector<ThreatReference*> GetModifiableThreatList();
133 bool IsThreateningAnyone(
bool includeOffline =
false)
const;
135 bool IsThreateningTo(
ObjectGuid const& who,
bool includeOffline =
false)
const;
137 bool IsThreateningTo(
Unit const* who,
bool includeOffline =
false)
const;
141 void EvaluateSuppressed(
bool canExpire =
false);
143 void AddThreat(
Unit* target,
float amount,
SpellInfo const* spell =
nullptr,
bool ignoreModifiers =
false,
bool ignoreRedirects =
false);
144 void ScaleThreat(
Unit* target,
float factor);
150 void MatchUnitThreatToHighestThreat(
Unit* target);
154 void ResetAllThreat();
156 void ClearThreat(
Unit* target);
159 void ClearAllThreat();
163 void FixateTarget(
Unit* target);
165 Unit* GetFixateTarget()
const;
169 void ForwardThreatForAssistingMe(
Unit* assistant,
float baseAmount,
SpellInfo const* spell =
nullptr,
bool ignoreModifiers =
false);
171 void RemoveMeFromThreatLists(
bool (*unitFilter)(
Unit const* otherUnit));
173 void UpdateMyTempModifiers();
175 void UpdateMySpellSchoolModifiers();
179 void RegisterRedirectThreat(
uint32 spellId,
ObjectGuid const& victim,
float pct);
181 void UnregisterRedirectThreat(
uint32 spellId);
191 static float CalculateModifiedThreat(
float threat,
Unit const* victim,
SpellInfo const* spell);
194 void SendClearAllThreatToClients()
const;
195 void SendRemoveToClients(
Unit const* victim)
const;
196 void SendThreatListToClients(
bool newHighest)
const;
200 void PurgeThreatListRef(
ObjectGuid const& guid);
210 void ProcessAIUpdates();
211 void RegisterForAIUpdate(
ObjectGuid const& guid);
222 void PurgeThreatenedByMeRef(
ObjectGuid const& guid);
228 void UpdateRedirectInfo();
244 : _generator(
std::move(generator)), _current(_generator()) {}
252 bool operator==(std::nullptr_t)
const {
return _current ==
nullptr; }
253 bool operator!=(std::nullptr_t)
const {
return _current !=
nullptr; }
266 enum TauntState :
uint32 { TAUNT_STATE_DETAUNT = 0, TAUNT_STATE_NONE = 1, TAUNT_STATE_TAUNT = 2 };
267 enum OnlineState { ONLINE_STATE_ONLINE = 2, ONLINE_STATE_SUPPRESSED = 1, ONLINE_STATE_OFFLINE = 0 };
271 float GetThreat()
const {
return std::max<float>(_baseAmount + _tempModifier, 0.0f); }
273 bool IsOnline()
const {
return (_online >= ONLINE_STATE_ONLINE); }
274 bool IsAvailable()
const {
return (_online > ONLINE_STATE_OFFLINE); }
275 bool IsSuppressed()
const {
return (_online == ONLINE_STATE_SUPPRESSED); }
276 bool IsOffline()
const {
return (_online <= ONLINE_STATE_OFFLINE); }
278 bool IsTaunting()
const {
return _taunted >= TAUNT_STATE_TAUNT; }
279 bool IsDetaunted()
const {
return _taunted == TAUNT_STATE_DETAUNT; }
281 void AddThreat(
float amount);
282 void ScaleThreat(
float factor);
284 void UpdateOffline();
289 static bool FlagsAllowFighting(
Unit const* a,
Unit const* b);
292 _owner(reinterpret_cast<
Creature*>(mgr->_owner)), _mgr(*mgr), _victim(victim),
293 _baseAmount(0.0f), _tempModifier(0.0f), _taunted(TAUNT_STATE_NONE)
295 _online = ONLINE_STATE_OFFLINE;
300 void UnregisterAndFree();
302 bool ShouldBeOffline()
const;
303 bool ShouldBeSuppressed()
const;
304 void UpdateTauntState(
TauntState state = TAUNT_STATE_NONE);
307 void HeapNotifyIncreased();
308 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