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);
105 Unit* GetCurrentVictim();
106 Unit* GetLastVictim()
const;
108 Unit* GetAnyTarget()
const;
111 bool IsThreatListEmpty(
bool includeOffline =
false)
const;
113 bool IsThreatenedBy(
ObjectGuid const& who,
bool includeOffline =
false)
const;
115 bool IsThreatenedBy(
Unit const* who,
bool includeOffline =
false)
const;
117 float GetThreat(
Unit const* who,
bool includeOffline =
false)
const;
118 size_t GetThreatListSize()
const;
119 uint32 GetThreatListPlayerCount(
bool includeOffline =
false)
const;
128 std::vector<ThreatReference*> GetModifiableThreatList();
131 bool IsThreateningAnyone(
bool includeOffline =
false)
const;
133 bool IsThreateningTo(
ObjectGuid const& who,
bool includeOffline =
false)
const;
135 bool IsThreateningTo(
Unit const* who,
bool includeOffline =
false)
const;
139 void EvaluateSuppressed(
bool canExpire =
false);
141 void AddThreat(
Unit* target,
float amount,
SpellInfo const* spell =
nullptr,
bool ignoreModifiers =
false,
bool ignoreRedirects =
false);
142 void ScaleThreat(
Unit* target,
float factor);
148 void MatchUnitThreatToHighestThreat(
Unit* target);
152 void ResetAllThreat();
154 void ClearThreat(
Unit* target);
157 void ClearAllThreat();
161 void FixateTarget(
Unit* target);
163 Unit* GetFixateTarget()
const;
167 void ForwardThreatForAssistingMe(
Unit* assistant,
float baseAmount,
SpellInfo const* spell =
nullptr,
bool ignoreModifiers =
false);
169 void RemoveMeFromThreatLists();
171 void UpdateMyTempModifiers();
173 void UpdateMySpellSchoolModifiers();
179 void UnregisterRedirectThreat(
uint32 spellId);
189 static float CalculateModifiedThreat(
float threat,
Unit const* victim,
SpellInfo const* spell);
192 void SendClearAllThreatToClients()
const;
193 void SendRemoveToClients(
Unit const* victim)
const;
194 void SendThreatListToClients(
bool newHighest)
const;
198 void PurgeThreatListRef(
ObjectGuid const& guid);
207 void ProcessAIUpdates();
219 void PurgeThreatenedByMeRef(
ObjectGuid const& guid);
225 void UpdateRedirectInfo();
241 : _generator(
std::move(generator)), _current(_generator()) {}
249 bool operator==(std::nullptr_t)
const {
return _current ==
nullptr; }
250 bool operator!=(std::nullptr_t)
const {
return _current !=
nullptr; }
263 enum TauntState :
uint32 { TAUNT_STATE_DETAUNT = 0, TAUNT_STATE_NONE = 1, TAUNT_STATE_TAUNT = 2 };
264 enum OnlineState { ONLINE_STATE_ONLINE = 2, ONLINE_STATE_SUPPRESSED = 1, ONLINE_STATE_OFFLINE = 0 };
268 float GetThreat()
const {
return std::max<float>(_baseAmount + (
float)_tempModifier, 0.0f); }
270 bool IsOnline()
const {
return (_online >= ONLINE_STATE_ONLINE); }
271 bool IsAvailable()
const {
return (_online > ONLINE_STATE_OFFLINE); }
272 bool IsSuppressed()
const {
return (_online == ONLINE_STATE_SUPPRESSED); }
273 bool IsOffline()
const {
return (_online <= ONLINE_STATE_OFFLINE); }
275 bool IsTaunting()
const {
return _taunted >= TAUNT_STATE_TAUNT; }
276 bool IsDetaunted()
const {
return _taunted == TAUNT_STATE_DETAUNT; }
278 void AddThreat(
float amount);
279 void ScaleThreat(
float factor);
281 void UpdateOffline();
286 static bool FlagsAllowFighting(
Unit const* a,
Unit const* b);
289 _owner(reinterpret_cast<
Creature*>(mgr->_owner)), _mgr(*mgr), _victim(victim),
290 _baseAmount(0.0f), _tempModifier(0), _taunted(TAUNT_STATE_NONE)
292 _online = ONLINE_STATE_OFFLINE;
297 void UnregisterAndFree();
299 bool ShouldBeOffline()
const;
300 bool ShouldBeSuppressed()
const;
301 void UpdateTauntState(
TauntState state = TAUNT_STATE_NONE);
304 void HeapNotifyIncreased();
305 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
void ModifyThreatByPercent(Unit *target, int32 percent)
ThreatManager & operator=(ThreatManager const &)=delete
std::vector< std::pair< ObjectGuid, uint32 > > _redirectInfo
void RegisterForAIUpdate(ObjectGuid const &guid)
void ResetThreat(Unit *target)
std::array< float, MAX_SPELL_SCHOOL > _singleSchoolModifiers
static bool CompareReferencesLT(ThreatReference const *a, ThreatReference const *b, float aWeight)
std::unordered_map< uint32, std::unordered_map< ObjectGuid, uint32 > > _redirectRegistry
auto const & GetThreatenedByMeList() const
static const CompareThreatLessThan CompareThreat
std::unique_ptr< Heap > _sortedThreatList
ThreatReference const * _currentVictimRef
std::unordered_map< ObjectGuid, ThreatReference * > _myThreatListEntries
bool _ownerCanHaveThreatList
std::vector< ObjectGuid > _needsAIUpdate
ThreatManager(ThreatManager const &)=delete
ThreatReference const * _fixateRef
std::unordered_map< std::underlying_type< SpellSchoolMask >::type, float > _multiSchoolModifiers
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