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;
127 std::vector<ThreatReference*> GetModifiableThreatList();
130 bool IsThreateningAnyone(
bool includeOffline =
false)
const;
132 bool IsThreateningTo(
ObjectGuid const& who,
bool includeOffline =
false)
const;
134 bool IsThreateningTo(
Unit const* who,
bool includeOffline =
false)
const;
138 void EvaluateSuppressed(
bool canExpire =
false);
140 void AddThreat(
Unit* target,
float amount,
SpellInfo const* spell =
nullptr,
bool ignoreModifiers =
false,
bool ignoreRedirects =
false);
141 void ScaleThreat(
Unit* target,
float factor);
147 void MatchUnitThreatToHighestThreat(
Unit* target);
151 void ResetAllThreat();
153 void ClearThreat(
Unit* target);
156 void ClearAllThreat();
160 void FixateTarget(
Unit* target);
162 Unit* GetFixateTarget()
const;
166 void ForwardThreatForAssistingMe(
Unit* assistant,
float baseAmount,
SpellInfo const* spell =
nullptr,
bool ignoreModifiers =
false);
168 void RemoveMeFromThreatLists(
bool (*unitFilter)(
Unit const* otherUnit));
170 void UpdateMyTempModifiers();
172 void UpdateMySpellSchoolModifiers();
178 void UnregisterRedirectThreat(
uint32 spellId);
188 static float CalculateModifiedThreat(
float threat,
Unit const* victim,
SpellInfo const* spell);
191 void SendClearAllThreatToClients()
const;
192 void SendRemoveToClients(
Unit const* victim)
const;
193 void SendThreatListToClients(
bool newHighest)
const;
197 void PurgeThreatListRef(
ObjectGuid const& guid);
206 void ProcessAIUpdates();
218 void PurgeThreatenedByMeRef(
ObjectGuid const& guid);
224 void UpdateRedirectInfo();
240 : _generator(
std::move(generator)), _current(_generator()) {}
248 bool operator==(std::nullptr_t)
const {
return _current ==
nullptr; }
249 bool operator!=(std::nullptr_t)
const {
return _current !=
nullptr; }
262 enum TauntState :
uint32 { TAUNT_STATE_DETAUNT = 0, TAUNT_STATE_NONE = 1, TAUNT_STATE_TAUNT = 2 };
263 enum OnlineState { ONLINE_STATE_ONLINE = 2, ONLINE_STATE_SUPPRESSED = 1, ONLINE_STATE_OFFLINE = 0 };
267 float GetThreat()
const {
return std::max<float>(_baseAmount + (
float)_tempModifier, 0.0f); }
269 bool IsOnline()
const {
return (_online >= ONLINE_STATE_ONLINE); }
270 bool IsAvailable()
const {
return (_online > ONLINE_STATE_OFFLINE); }
271 bool IsSuppressed()
const {
return (_online == ONLINE_STATE_SUPPRESSED); }
272 bool IsOffline()
const {
return (_online <= ONLINE_STATE_OFFLINE); }
274 bool IsTaunting()
const {
return _taunted >= TAUNT_STATE_TAUNT; }
275 bool IsDetaunted()
const {
return _taunted == TAUNT_STATE_DETAUNT; }
277 void AddThreat(
float amount);
278 void ScaleThreat(
float factor);
280 void UpdateOffline();
285 static bool FlagsAllowFighting(
Unit const* a,
Unit const* b);
288 _owner(reinterpret_cast<
Creature*>(mgr->_owner)), _mgr(*mgr), _victim(victim),
289 _baseAmount(0.0f), _tempModifier(0), _taunted(TAUNT_STATE_NONE)
291 _online = ONLINE_STATE_OFFLINE;
296 void UnregisterAndFree();
298 bool ShouldBeOffline()
const;
299 bool ShouldBeSuppressed()
const;
300 void UpdateTauntState(
TauntState state = TAUNT_STATE_NONE);
303 void HeapNotifyIncreased();
304 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.
void Update(VignetteData &vignette, WorldObject const *owner)
bool operator()(ThreatReference const *a, ThreatReference const *b) const