18 #ifndef TRINITY_THREATMANAGER_H
19 #define TRINITY_THREATMANAGER_H
27#include <unordered_map>
95 static const uint32 THREAT_UPDATE_INTERVAL = 1000u;
97 static bool CanHaveThreatList(
Unit const* who);
106 void Update(
uint32 tdiff);
114 Unit* GetCurrentVictim();
115 Unit* GetLastVictim()
const;
117 Unit* GetAnyTarget()
const;
120 bool IsThreatListEmpty(
bool includeOffline =
false)
const;
122 bool IsThreatenedBy(
ObjectGuid const& who,
bool includeOffline =
false)
const;
124 bool IsThreatenedBy(
Unit const* who,
bool includeOffline =
false)
const;
126 float GetThreat(
Unit const* who,
bool includeOffline =
false)
const;
127 size_t GetThreatListSize()
const;
128 uint32 GetThreatListPlayerCount(
bool includeOffline =
false)
const;
137 std::vector<ThreatReference*> GetModifiableThreatList();
140 bool IsThreateningAnyone(
bool includeOffline =
false)
const;
142 bool IsThreateningTo(
ObjectGuid const& who,
bool includeOffline =
false)
const;
144 bool IsThreateningTo(
Unit const* who,
bool includeOffline =
false)
const;
148 void EvaluateSuppressed(
bool canExpire =
false);
150 void AddThreat(
Unit* target,
float amount,
SpellInfo const* spell =
nullptr,
bool ignoreModifiers =
false,
bool ignoreRedirects =
false);
151 void ScaleThreat(
Unit* target,
float factor);
157 void MatchUnitThreatToHighestThreat(
Unit* target);
161 void ResetAllThreat();
163 void ClearThreat(
Unit* target);
166 void ClearAllThreat();
170 void FixateTarget(
Unit* target);
172 Unit* GetFixateTarget()
const;
176 void ForwardThreatForAssistingMe(
Unit* assistant,
float baseAmount,
SpellInfo const* spell =
nullptr,
bool ignoreModifiers =
false);
178 void RemoveMeFromThreatLists();
180 void UpdateMyTempModifiers();
182 void UpdateMySpellSchoolModifiers();
188 void UnregisterRedirectThreat(
uint32 spellId);
198 static float CalculateModifiedThreat(
float threat,
Unit const* victim,
SpellInfo const* spell);
201 void SendClearAllThreatToClients()
const;
202 void SendRemoveToClients(
Unit const* victim)
const;
203 void SendThreatListToClients(
bool newHighest)
const;
207 void PurgeThreatListRef(
ObjectGuid const& guid);
216 void ProcessAIUpdates();
228 void PurgeThreatenedByMeRef(
ObjectGuid const& guid);
234 void UpdateRedirectInfo();
250 : _generator(
std::move(generator)), _current(_generator()) {}
258 bool operator==(std::nullptr_t)
const {
return _current ==
nullptr; }
259 bool operator!=(std::nullptr_t)
const {
return _current !=
nullptr; }
272 enum TauntState :
uint32 { TAUNT_STATE_DETAUNT = 0, TAUNT_STATE_NONE = 1, TAUNT_STATE_TAUNT = 2 };
273 enum OnlineState { ONLINE_STATE_ONLINE = 2, ONLINE_STATE_SUPPRESSED = 1, ONLINE_STATE_OFFLINE = 0 };
277 float GetThreat()
const {
return std::max<float>(_baseAmount + (
float)_tempModifier, 0.0f); }
279 bool IsOnline()
const {
return (_online >= ONLINE_STATE_ONLINE); }
280 bool IsAvailable()
const {
return (_online > ONLINE_STATE_OFFLINE); }
281 bool IsSuppressed()
const {
return (_online == ONLINE_STATE_SUPPRESSED); }
282 bool IsOffline()
const {
return (_online <= ONLINE_STATE_OFFLINE); }
284 bool IsTaunting()
const {
return _taunted >= TAUNT_STATE_TAUNT; }
285 bool IsDetaunted()
const {
return _taunted == TAUNT_STATE_DETAUNT; }
287 void AddThreat(
float amount);
288 void ScaleThreat(
float factor);
290 void UpdateOffline();
295 static bool FlagsAllowFighting(
Unit const* a,
Unit const* b);
298 _owner(reinterpret_cast<
Creature*>(mgr->_owner)), _mgr(*mgr), _victim(victim),
299 _baseAmount(0.0f), _tempModifier(0), _taunted(TAUNT_STATE_NONE)
301 _online = ONLINE_STATE_OFFLINE;
306 void UnregisterAndFree();
308 bool ShouldBeOffline()
const;
309 bool ShouldBeSuppressed()
const;
310 void UpdateTauntState(
TauntState state = TAUNT_STATE_NONE);
313 void HeapNotifyIncreased();
314 void HeapNotifyDecreased();
#define DEFINE_ENUM_FLAG(enumType)
ThreatListClientUpdateFlags
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)
EnumFlag< ThreatListClientUpdateFlags > _updateFlags
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