mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-17 17:24:33 +00:00
refactor(Core/Combat): Code style and improvement of ThreatMgr (#12992)
This commit is contained in:
@@ -136,7 +136,7 @@ SpellCastResult UnitAI::DoAddAuraToAllHostilePlayers(uint32 spellid)
|
||||
{
|
||||
if (me->IsInCombat())
|
||||
{
|
||||
ThreatContainer::StorageType threatlist = me->GetThreatMgr().getThreatList();
|
||||
ThreatContainer::StorageType threatlist = me->GetThreatMgr().GetThreatList();
|
||||
for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr)
|
||||
{
|
||||
if (Unit* unit = ObjectAccessor::GetUnit(*me, (*itr)->getUnitGuid()))
|
||||
@@ -159,7 +159,7 @@ SpellCastResult UnitAI::DoCastToAllHostilePlayers(uint32 spellid, bool triggered
|
||||
{
|
||||
if (me->IsInCombat())
|
||||
{
|
||||
ThreatContainer::StorageType threatlist = me->GetThreatMgr().getThreatList();
|
||||
ThreatContainer::StorageType threatlist = me->GetThreatMgr().GetThreatList();
|
||||
for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr)
|
||||
{
|
||||
if (Unit* unit = ObjectAccessor::GetUnit(*me, (*itr)->getUnitGuid()))
|
||||
|
||||
@@ -216,7 +216,7 @@ public:
|
||||
template <class PREDICATE>
|
||||
Unit* SelectTarget(SelectTargetMethod targetType, uint32 position, PREDICATE const& predicate)
|
||||
{
|
||||
ThreatContainer::StorageType const& threatlist = me->GetThreatMgr().getThreatList();
|
||||
ThreatContainer::StorageType const& threatlist = me->GetThreatMgr().GetThreatList();
|
||||
if (position >= threatlist.size())
|
||||
return nullptr;
|
||||
|
||||
@@ -278,7 +278,7 @@ public:
|
||||
template <class PREDICATE>
|
||||
void SelectTargetList(std::list<Unit*>& targetList, PREDICATE const& predicate, uint32 maxTargets, SelectTargetMethod targetType)
|
||||
{
|
||||
ThreatContainer::StorageType const& threatlist = me->GetThreatMgr().getThreatList();
|
||||
ThreatContainer::StorageType const& threatlist = me->GetThreatMgr().GetThreatList();
|
||||
if (threatlist.empty())
|
||||
return;
|
||||
|
||||
|
||||
@@ -399,14 +399,14 @@ float ScriptedAI::DoGetThreat(Unit* unit)
|
||||
{
|
||||
if (!unit)
|
||||
return 0.0f;
|
||||
return me->GetThreatMgr().getThreat(unit);
|
||||
return me->GetThreatMgr().GetThreat(unit);
|
||||
}
|
||||
|
||||
void ScriptedAI::DoModifyThreatPercent(Unit* unit, int32 pct)
|
||||
{
|
||||
if (!unit)
|
||||
return;
|
||||
me->GetThreatMgr().modifyThreatPercent(unit, pct);
|
||||
me->GetThreatMgr().ModifyThreatByPercent(unit, pct);
|
||||
}
|
||||
|
||||
void ScriptedAI::DoTeleportPlayer(Unit* unit, float x, float y, float z, float o)
|
||||
@@ -580,7 +580,7 @@ void BossAI::TeleportCheaters()
|
||||
float x, y, z;
|
||||
me->GetPosition(x, y, z);
|
||||
|
||||
ThreatContainer::StorageType threatList = me->GetThreatMgr().getThreatList();
|
||||
ThreatContainer::StorageType threatList = me->GetThreatMgr().GetThreatList();
|
||||
for (ThreatContainer::StorageType::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
|
||||
if (Unit* target = (*itr)->getTarget())
|
||||
if (target->GetTypeId() == TYPEID_PLAYER && !IsInBoundary(target))
|
||||
|
||||
@@ -522,12 +522,12 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
if (!me)
|
||||
break;
|
||||
|
||||
ThreatContainer::StorageType threatList = me->GetThreatMgr().getThreatList();
|
||||
ThreatContainer::StorageType threatList = me->GetThreatMgr().GetThreatList();
|
||||
for (ThreatContainer::StorageType::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
|
||||
{
|
||||
if (Unit* target = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()))
|
||||
{
|
||||
me->GetThreatMgr().modifyThreatPercent(target, e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
|
||||
me->GetThreatMgr().ModifyThreatByPercent(target, e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
|
||||
LOG_DEBUG("sql.sql", "SmartScript::ProcessAction:: SMART_ACTION_THREAT_ALL_PCT: Creature {} modify threat for unit {}, value {}",
|
||||
me->GetGUID().ToString(), target->GetGUID().ToString(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
|
||||
}
|
||||
@@ -543,7 +543,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
{
|
||||
if (IsUnit(target))
|
||||
{
|
||||
me->GetThreatMgr().modifyThreatPercent(target->ToUnit(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
|
||||
me->GetThreatMgr().ModifyThreatByPercent(target->ToUnit(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
|
||||
LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_THREAT_SINGLE_PCT: Creature guidLow {} modify threat for unit {}, value %i",
|
||||
me->GetGUID().ToString(), target->GetGUID().ToString(), e.action.threatPCT.threatINC ? (int32)e.action.threatPCT.threatINC : -(int32)e.action.threatPCT.threatDEC);
|
||||
}
|
||||
@@ -3219,7 +3219,7 @@ void SmartScript::GetTargets(ObjectVector& targets, SmartScriptHolder const& e,
|
||||
{
|
||||
if (me)
|
||||
{
|
||||
ThreatContainer::StorageType threatList = me->GetThreatMgr().getThreatList();
|
||||
ThreatContainer::StorageType threatList = me->GetThreatMgr().GetThreatList();
|
||||
for (ThreatContainer::StorageType::const_iterator i = threatList.begin(); i != threatList.end(); ++i)
|
||||
if (Unit* temp = ObjectAccessor::GetUnit(*me, (*i)->getUnitGuid()))
|
||||
// Xinef: added distance check
|
||||
|
||||
@@ -53,7 +53,7 @@ void HostileRefMgr::threatAssist(Unit* victim, float baseThreat, SpellInfo const
|
||||
}
|
||||
}
|
||||
|
||||
ref->GetSource()->doAddThreat(victim, threat);
|
||||
ref->GetSource()->DoAddThreat(victim, threat);
|
||||
}
|
||||
|
||||
ref = ref->next();
|
||||
@@ -239,7 +239,7 @@ void HostileRefMgr::UpdateVisibility(bool checkThreat)
|
||||
while (ref)
|
||||
{
|
||||
HostileReference* nextRef = ref->next();
|
||||
if ((!checkThreat || ref->GetSource()->getThreatList().size() <= 1))
|
||||
if ((!checkThreat || ref->GetSource()->GetThreatListSize() <= 1))
|
||||
{
|
||||
nextRef = ref->next();
|
||||
ref->removeReference();
|
||||
|
||||
@@ -131,14 +131,17 @@ void HostileReference::fireStatusChanged(ThreatRefStatusChangeEvent& threatRefSt
|
||||
GetSource()->processThreatEvent(&threatRefStatusChangeEvent);
|
||||
}
|
||||
|
||||
// -- compatibility layer for combat rewrite
|
||||
Unit* HostileReference::GetOwner() const { return GetSource()->GetOwner(); }
|
||||
|
||||
//============================================================
|
||||
|
||||
void HostileReference::addThreat(float modThreat)
|
||||
void HostileReference::AddThreat(float modThreat)
|
||||
{
|
||||
iThreat += modThreat;
|
||||
// the threat is changed. Source and target unit have to be available
|
||||
// if the link was cut before relink it again
|
||||
if (!isOnline())
|
||||
if (!IsOnline())
|
||||
updateOnlineStatus();
|
||||
if (modThreat != 0.0f)
|
||||
{
|
||||
@@ -154,7 +157,7 @@ void HostileReference::addThreat(float modThreat)
|
||||
Unit* victimOwner = target->GetCharmerOrOwner();
|
||||
if (victimOwner && victimOwner->IsAlive())
|
||||
{
|
||||
GetSource()->addThreat(victimOwner, 0.0f); // create a threat to the owner of a pet, if the pet attacks
|
||||
GetSource()->AddThreat(victimOwner, 0.0f); // create a threat to the owner of a pet, if the pet attacks
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,7 +172,7 @@ void HostileReference::addThreatPercent(int32 percent)
|
||||
|
||||
float tmpThreat = iThreat;
|
||||
AddPct(tmpThreat, percent);
|
||||
addThreat(tmpThreat - iThreat);
|
||||
AddThreat(tmpThreat - iThreat);
|
||||
}
|
||||
|
||||
//============================================================
|
||||
@@ -256,7 +259,7 @@ void ThreatContainer::clearReferences()
|
||||
|
||||
//============================================================
|
||||
// Return the HostileReference of nullptr, if not found
|
||||
HostileReference* ThreatContainer::getReferenceByTarget(Unit* victim) const
|
||||
HostileReference* ThreatContainer::getReferenceByTarget(Unit const* victim) const
|
||||
{
|
||||
if (!victim)
|
||||
return nullptr;
|
||||
@@ -281,17 +284,17 @@ HostileReference* ThreatContainer::getReferenceByTarget(ObjectGuid const& guid)
|
||||
//============================================================
|
||||
// Add the threat, if we find the reference
|
||||
|
||||
HostileReference* ThreatContainer::addThreat(Unit* victim, float threat)
|
||||
HostileReference* ThreatContainer::AddThreat(Unit* victim, float threat)
|
||||
{
|
||||
HostileReference* ref = getReferenceByTarget(victim);
|
||||
if (ref)
|
||||
ref->addThreat(threat);
|
||||
ref->AddThreat(threat);
|
||||
return ref;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
|
||||
void ThreatContainer::modifyThreatPercent(Unit* victim, int32 percent)
|
||||
void ThreatContainer::ModifyThreatByPercent(Unit* victim, int32 percent)
|
||||
{
|
||||
if (HostileReference* ref = getReferenceByTarget(victim))
|
||||
ref->addThreatPercent(percent);
|
||||
@@ -312,7 +315,7 @@ void ThreatContainer::update()
|
||||
// return the next best victim
|
||||
// could be the current victim
|
||||
|
||||
HostileReference* ThreatContainer::selectNextVictim(Creature* attacker, HostileReference* currentVictim) const
|
||||
HostileReference* ThreatContainer::SelectNextVictim(Creature* attacker, HostileReference* currentVictim) const
|
||||
{
|
||||
// pussywizard: pretty much remade this whole function
|
||||
|
||||
@@ -370,12 +373,12 @@ HostileReference* ThreatContainer::selectNextVictim(Creature* attacker, HostileR
|
||||
}
|
||||
|
||||
// pussywizard: implement 110% threat rule for targets in melee range and 130% rule for targets in ranged distances
|
||||
if (currentRef->getThreat() > 1.3f * currentVictim->getThreat()) // pussywizard: enough in all cases, end
|
||||
if (currentRef->GetThreat() > 1.3f * currentVictim->GetThreat()) // pussywizard: enough in all cases, end
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
else if (currentRef->getThreat() > 1.1f * currentVictim->getThreat()) // pussywizard: enought only if target in melee range
|
||||
else if (currentRef->GetThreat() > 1.1f * currentVictim->GetThreat()) // pussywizard: enought only if target in melee range
|
||||
{
|
||||
if (attacker->IsWithinMeleeRange(target))
|
||||
{
|
||||
@@ -431,7 +434,7 @@ void ThreatMgr::clearReferences()
|
||||
|
||||
//============================================================
|
||||
|
||||
void ThreatMgr::addThreat(Unit* victim, float threat, SpellSchoolMask schoolMask, SpellInfo const* threatSpell)
|
||||
void ThreatMgr::AddThreat(Unit* victim, float threat, SpellSchoolMask schoolMask, SpellInfo const* threatSpell)
|
||||
{
|
||||
if (!ThreatCalcHelper::isValidProcess(victim, iOwner, threatSpell))
|
||||
return;
|
||||
@@ -445,10 +448,10 @@ void ThreatMgr::addThreat(Unit* victim, float threat, SpellSchoolMask schoolMask
|
||||
}
|
||||
}
|
||||
|
||||
doAddThreat(victim, threat);
|
||||
DoAddThreat(victim, threat);
|
||||
}
|
||||
|
||||
void ThreatMgr::doAddThreat(Unit* victim, float threat)
|
||||
void ThreatMgr::DoAddThreat(Unit* victim, float threat)
|
||||
{
|
||||
uint32 redirectThreadPct = victim->GetRedirectThreatPercent();
|
||||
|
||||
@@ -469,17 +472,17 @@ void ThreatMgr::doAddThreat(Unit* victim, float threat)
|
||||
|
||||
void ThreatMgr::_addThreat(Unit* victim, float threat)
|
||||
{
|
||||
HostileReference* ref = iThreatContainer.addThreat(victim, threat);
|
||||
HostileReference* ref = iThreatContainer.AddThreat(victim, threat);
|
||||
// Ref is not in the online refs, search the offline refs next
|
||||
if (!ref)
|
||||
ref = iThreatOfflineContainer.addThreat(victim, threat);
|
||||
ref = iThreatOfflineContainer.AddThreat(victim, threat);
|
||||
|
||||
if (!ref) // there was no ref => create a new one
|
||||
{
|
||||
// threat has to be 0 here
|
||||
HostileReference* hostileRef = new HostileReference(victim, this, 0);
|
||||
iThreatContainer.addReference(hostileRef);
|
||||
hostileRef->addThreat(threat); // now we add the real threat
|
||||
hostileRef->AddThreat(threat); // now we add the real threat
|
||||
if (victim->GetTypeId() == TYPEID_PLAYER && victim->ToPlayer()->IsGameMaster())
|
||||
hostileRef->setOnlineOfflineState(false); // GM is always offline
|
||||
}
|
||||
@@ -487,9 +490,9 @@ void ThreatMgr::_addThreat(Unit* victim, float threat)
|
||||
|
||||
//============================================================
|
||||
|
||||
void ThreatMgr::modifyThreatPercent(Unit* victim, int32 percent)
|
||||
void ThreatMgr::ModifyThreatByPercent(Unit* victim, int32 percent)
|
||||
{
|
||||
iThreatContainer.modifyThreatPercent(victim, percent);
|
||||
iThreatContainer.ModifyThreatByPercent(victim, percent);
|
||||
}
|
||||
|
||||
//============================================================
|
||||
@@ -497,21 +500,21 @@ void ThreatMgr::modifyThreatPercent(Unit* victim, int32 percent)
|
||||
Unit* ThreatMgr::getHostileTarget()
|
||||
{
|
||||
iThreatContainer.update();
|
||||
HostileReference* nextVictim = iThreatContainer.selectNextVictim(GetOwner()->ToCreature(), getCurrentVictim());
|
||||
HostileReference* nextVictim = iThreatContainer.SelectNextVictim(GetOwner()->ToCreature(), getCurrentVictim());
|
||||
setCurrentVictim(nextVictim);
|
||||
return getCurrentVictim() != nullptr ? getCurrentVictim()->getTarget() : nullptr;
|
||||
}
|
||||
|
||||
//============================================================
|
||||
|
||||
float ThreatMgr::getThreat(Unit* victim, bool alsoSearchOfflineList)
|
||||
float ThreatMgr::GetThreat(Unit* victim, bool alsoSearchOfflineList)
|
||||
{
|
||||
float threat = 0.0f;
|
||||
HostileReference* ref = iThreatContainer.getReferenceByTarget(victim);
|
||||
if (!ref && alsoSearchOfflineList)
|
||||
ref = iThreatOfflineContainer.getReferenceByTarget(victim);
|
||||
if (ref)
|
||||
threat = ref->getThreat();
|
||||
threat = ref->GetThreat();
|
||||
return threat;
|
||||
}
|
||||
|
||||
@@ -524,7 +527,7 @@ float ThreatMgr::getThreatWithoutTemp(Unit* victim, bool alsoSearchOfflineList)
|
||||
if (!ref && alsoSearchOfflineList)
|
||||
ref = iThreatOfflineContainer.getReferenceByTarget(victim);
|
||||
if (ref)
|
||||
threat = ref->getThreat() - ref->getTempThreatModifier();
|
||||
threat = ref->GetThreat() - ref->getTempThreatModifier();
|
||||
return threat;
|
||||
}
|
||||
|
||||
@@ -533,10 +536,10 @@ float ThreatMgr::getThreatWithoutTemp(Unit* victim, bool alsoSearchOfflineList)
|
||||
void ThreatMgr::tauntApply(Unit* taunter)
|
||||
{
|
||||
HostileReference* ref = iThreatContainer.getReferenceByTarget(taunter);
|
||||
if (getCurrentVictim() && ref && (ref->getThreat() < getCurrentVictim()->getThreat()))
|
||||
if (getCurrentVictim() && ref && (ref->GetThreat() < getCurrentVictim()->GetThreat()))
|
||||
{
|
||||
if (ref->getTempThreatModifier() == 0.0f) // Ok, temp threat is unused
|
||||
ref->setTempThreat(getCurrentVictim()->getThreat());
|
||||
ref->setTempThreat(getCurrentVictim()->GetThreat());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -578,7 +581,7 @@ void ThreatMgr::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusCh
|
||||
setDirty(true); // the order in the threat list might have changed
|
||||
break;
|
||||
case UEV_THREAT_REF_ONLINE_STATUS:
|
||||
if (!hostileRef->isOnline())
|
||||
if (!hostileRef->IsOnline())
|
||||
{
|
||||
if (hostileRef == getCurrentVictim())
|
||||
{
|
||||
@@ -594,7 +597,7 @@ void ThreatMgr::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusCh
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getCurrentVictim() && hostileRef->getThreat() > (1.1f * getCurrentVictim()->getThreat()))
|
||||
if (getCurrentVictim() && hostileRef->GetThreat() > (1.1f * getCurrentVictim()->GetThreat()))
|
||||
setDirty(true);
|
||||
iThreatContainer.addReference(hostileRef);
|
||||
iThreatOfflineContainer.remove(hostileRef);
|
||||
@@ -607,7 +610,7 @@ void ThreatMgr::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusCh
|
||||
setDirty(true);
|
||||
}
|
||||
iOwner->SendRemoveFromThreatListOpcode(hostileRef);
|
||||
if (hostileRef->isOnline())
|
||||
if (hostileRef->IsOnline())
|
||||
iThreatContainer.remove(hostileRef);
|
||||
else
|
||||
iThreatOfflineContainer.remove(hostileRef);
|
||||
@@ -630,14 +633,14 @@ bool ThreatMgr::isNeedUpdateToClient(uint32 time)
|
||||
}
|
||||
|
||||
// Reset all aggro without modifying the threatlist.
|
||||
void ThreatMgr::resetAllAggro()
|
||||
void ThreatMgr::ResetAllThreat()
|
||||
{
|
||||
ThreatContainer::StorageType& threatList = iThreatContainer.iThreatList;
|
||||
if (threatList.empty())
|
||||
return;
|
||||
|
||||
for (ThreatContainer::StorageType::iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
|
||||
(*itr)->setThreat(0);
|
||||
(*itr)->SetThreat(0);
|
||||
|
||||
setDirty(true);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define _THREATMANAGER
|
||||
|
||||
#include "Common.h"
|
||||
#include "IteratorPair.h"
|
||||
#include "ObjectGuid.h"
|
||||
#include "Reference.h"
|
||||
#include "SharedDefines.h"
|
||||
@@ -49,36 +50,43 @@ class HostileReference : public Reference<Unit, ThreatMgr>
|
||||
public:
|
||||
HostileReference(Unit* refUnit, ThreatMgr* threatMgr, float threat);
|
||||
|
||||
//=================================================
|
||||
void addThreat(float modThreat);
|
||||
Unit* GetOwner() const;
|
||||
Unit* GetVictim() const { return getTarget(); }
|
||||
|
||||
void setThreat(float threat) { addThreat(threat - getThreat()); }
|
||||
//=================================================
|
||||
void AddThreat(float modThreat);
|
||||
|
||||
void SetThreat(float threat) { AddThreat(threat - GetThreat()); }
|
||||
|
||||
void addThreatPercent(int32 percent);
|
||||
|
||||
[[nodiscard]] float getThreat() const { return iThreat; }
|
||||
[[nodiscard]] float GetThreat() const { return iThreat; }
|
||||
|
||||
[[nodiscard]] bool isOnline() const { return iOnline; }
|
||||
void ClearThreat() { removeReference(); }
|
||||
|
||||
[[nodiscard]] bool IsOnline() const { return iOnline; }
|
||||
[[nodiscard]] bool IsAvailable() const { return iOnline; } // unused for now
|
||||
[[nodiscard]] bool IsOffline() const { return !iOnline; } // unused for now
|
||||
|
||||
// used for temporary setting a threat and reducting it later again.
|
||||
// the threat modification is stored
|
||||
void setTempThreat(float threat)
|
||||
{
|
||||
addTempThreat(threat - getThreat());
|
||||
addTempThreat(threat - GetThreat());
|
||||
}
|
||||
|
||||
void addTempThreat(float threat)
|
||||
{
|
||||
iTempThreatModifier = threat;
|
||||
if (iTempThreatModifier != 0.0f)
|
||||
addThreat(iTempThreatModifier);
|
||||
AddThreat(iTempThreatModifier);
|
||||
}
|
||||
|
||||
void resetTempThreat()
|
||||
{
|
||||
if (iTempThreatModifier != 0.0f)
|
||||
{
|
||||
addThreat(-iTempThreatModifier);
|
||||
AddThreat(-iTempThreatModifier);
|
||||
iTempThreatModifier = 0.0f;
|
||||
}
|
||||
}
|
||||
@@ -143,11 +151,11 @@ public:
|
||||
|
||||
~ThreatContainer() { clearReferences(); }
|
||||
|
||||
HostileReference* addThreat(Unit* victim, float threat);
|
||||
HostileReference* AddThreat(Unit* victim, float threat);
|
||||
|
||||
void modifyThreatPercent(Unit* victim, int32 percent);
|
||||
void ModifyThreatByPercent(Unit* victim, int32 percent);
|
||||
|
||||
HostileReference* selectNextVictim(Creature* attacker, HostileReference* currentVictim) const;
|
||||
HostileReference* SelectNextVictim(Creature* attacker, HostileReference* currentVictim) const;
|
||||
|
||||
void setDirty(bool isDirty) { iDirty = isDirty; }
|
||||
|
||||
@@ -163,10 +171,10 @@ public:
|
||||
return iThreatList.empty() ? nullptr : iThreatList.front();
|
||||
}
|
||||
|
||||
HostileReference* getReferenceByTarget(Unit* victim) const;
|
||||
HostileReference* getReferenceByTarget(Unit const* victim) const;
|
||||
HostileReference* getReferenceByTarget(ObjectGuid const& guid) const;
|
||||
|
||||
[[nodiscard]] StorageType const& getThreatList() const { return iThreatList; }
|
||||
[[nodiscard]] StorageType const& GetThreatList() const { return iThreatList; }
|
||||
|
||||
private:
|
||||
void remove(HostileReference* hostileRef)
|
||||
@@ -190,6 +198,8 @@ private:
|
||||
|
||||
//=================================================
|
||||
|
||||
typedef HostileReference ThreatReference;
|
||||
|
||||
class ThreatMgr
|
||||
{
|
||||
public:
|
||||
@@ -199,16 +209,17 @@ public:
|
||||
|
||||
~ThreatMgr() { clearReferences(); }
|
||||
|
||||
Unit* SelectVictim() { return getHostileTarget(); }
|
||||
Unit* GetCurrentVictim() const { if (ThreatReference* ref = getCurrentVictim()) return ref->GetVictim(); else return nullptr; }
|
||||
Unit* GetAnyTarget() const { auto const& list = GetThreatList(); if (!list.empty()) return list.front()->getTarget(); return nullptr; }
|
||||
|
||||
void clearReferences();
|
||||
|
||||
void addThreat(Unit* victim, float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL, SpellInfo const* threatSpell = nullptr);
|
||||
|
||||
void doAddThreat(Unit* victim, float threat);
|
||||
|
||||
void modifyThreatPercent(Unit* victim, int32 percent);
|
||||
|
||||
float getThreat(Unit* victim, bool alsoSearchOfflineList = false);
|
||||
|
||||
void AddThreat(Unit* victim, float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL, SpellInfo const* threatSpell = nullptr);
|
||||
void DoAddThreat(Unit* victim, float threat);
|
||||
void ModifyThreatByPercent(Unit* victim, int32 percent);
|
||||
float GetThreat(Unit* victim, bool alsoSearchOfflineList = false);
|
||||
float GetThreatListSize() const { return GetThreatList().size(); }
|
||||
float getThreatWithoutTemp(Unit* victim, bool alsoSearchOfflineList = false);
|
||||
|
||||
[[nodiscard]] bool isThreatListEmpty() const { return iThreatContainer.empty(); }
|
||||
@@ -232,11 +243,10 @@ public:
|
||||
void setDirty(bool isDirty) { iThreatContainer.setDirty(isDirty); }
|
||||
|
||||
// Reset all aggro without modifying the threadlist.
|
||||
void resetAllAggro();
|
||||
|
||||
// -- compatibility layer for combat rewrite
|
||||
void ResetAllThreat() { resetAllAggro(); }
|
||||
void ResetThreat(Unit const* who) { if (auto* ref = FindReference(who, true)) ref->SetThreat(0.0f); }
|
||||
void ResetAllThreat();
|
||||
|
||||
void ClearThreat(Unit const* who) { if (auto* ref = FindReference(who, true)) ref->removeReference(); }
|
||||
void ClearAllThreat();
|
||||
|
||||
// Reset all aggro of unit in threadlist satisfying the predicate.
|
||||
@@ -250,7 +260,7 @@ public:
|
||||
{
|
||||
if (predicate(ref->getTarget()))
|
||||
{
|
||||
ref->setThreat(0);
|
||||
ref->SetThreat(0);
|
||||
setDirty(true);
|
||||
}
|
||||
}
|
||||
@@ -258,11 +268,14 @@ public:
|
||||
|
||||
// methods to access the lists from the outside to do some dirty manipulation (scriping and such)
|
||||
// I hope they are used as little as possible.
|
||||
[[nodiscard]] ThreatContainer::StorageType const& getThreatList() const { return iThreatContainer.getThreatList(); }
|
||||
[[nodiscard]] ThreatContainer::StorageType const& getOfflineThreatList() const { return iThreatOfflineContainer.getThreatList(); }
|
||||
ThreatContainer& getOnlineContainer() { return iThreatContainer; }
|
||||
ThreatContainer& getOfflineContainer() { return iThreatOfflineContainer; }
|
||||
[[nodiscard]] ThreatContainer::StorageType const& GetThreatList() const { return iThreatContainer.GetThreatList(); }
|
||||
[[nodiscard]] ThreatContainer::StorageType const& GetOfflineThreatList() const { return iThreatOfflineContainer.GetThreatList(); }
|
||||
ThreatContainer& GetOnlineContainer() { return iThreatContainer; }
|
||||
ThreatContainer& GetOfflineContainer() { return iThreatOfflineContainer; }
|
||||
|
||||
private:
|
||||
HostileReference* FindReference(Unit const* who, bool includeOffline) const { if (auto* ref = iThreatContainer.getReferenceByTarget(who)) return ref; if (includeOffline) if (auto* ref = iThreatOfflineContainer.getReferenceByTarget(who)) return ref; return nullptr; }
|
||||
|
||||
void _addThreat(Unit* victim, float threat);
|
||||
|
||||
HostileReference* iCurrentVictim;
|
||||
@@ -283,7 +296,7 @@ namespace Acore
|
||||
ThreatOrderPred(bool ascending = false) : m_ascending(ascending) {}
|
||||
bool operator() (HostileReference const* a, HostileReference const* b) const
|
||||
{
|
||||
return m_ascending ? a->getThreat() < b->getThreat() : a->getThreat() > b->getThreat();
|
||||
return m_ascending ? a->GetThreat() < b->GetThreat() : a->GetThreat() > b->GetThreat();
|
||||
}
|
||||
private:
|
||||
const bool m_ascending;
|
||||
|
||||
@@ -207,8 +207,8 @@ bool TemporaryThreatModifierEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
|
||||
{
|
||||
if (m_owner.IsInCombatWith(victim))
|
||||
{
|
||||
m_owner.GetThreatMgr().modifyThreatPercent(victim, -100); // Reset threat to zero.
|
||||
m_owner.GetThreatMgr().addThreat(victim, m_threatValue); // Set to the previous value it had, first before modification.
|
||||
m_owner.GetThreatMgr().ModifyThreatByPercent(victim, -100); // Reset threat to zero.
|
||||
m_owner.GetThreatMgr().AddThreat(victim, m_threatValue); // Set to the previous value it had, first before modification.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -839,13 +839,13 @@ void Creature::Update(uint32 diff)
|
||||
}
|
||||
};
|
||||
|
||||
if (GetThreatMgr().getThreatList().size() <= 1)
|
||||
if (GetThreatMgr().GetThreatListSize() <= 1)
|
||||
{
|
||||
EnterEvade();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (HostileReference* ref = GetThreatMgr().getOnlineContainer().getReferenceByTarget(m_cannotReachTarget))
|
||||
if (HostileReference* ref = GetThreatMgr().GetOnlineContainer().getReferenceByTarget(m_cannotReachTarget))
|
||||
{
|
||||
ref->removeReference();
|
||||
SetCannotReachTarget();
|
||||
@@ -3626,11 +3626,11 @@ void Creature::ModifyThreatPercentTemp(Unit* victim, int32 percent, Milliseconds
|
||||
{
|
||||
if (victim)
|
||||
{
|
||||
float currentThreat = GetThreatMgr().getThreat(victim);
|
||||
float currentThreat = GetThreatMgr().GetThreat(victim);
|
||||
|
||||
if (percent != 0.0f)
|
||||
{
|
||||
GetThreatMgr().modifyThreatPercent(victim, percent);
|
||||
GetThreatMgr().ModifyThreatByPercent(victim, percent);
|
||||
}
|
||||
|
||||
TemporaryThreatModifierEvent* pEvent = new TemporaryThreatModifierEvent(*this, victim->GetGUID(), currentThreat);
|
||||
|
||||
@@ -8977,7 +8977,7 @@ bool Unit::HandleProcTriggerSpell(Unit* victim, uint32 damage, AuraEffect* trigg
|
||||
return false;
|
||||
|
||||
if (victim && victim->IsAlive())
|
||||
victim->GetThreatMgr().modifyThreatPercent(this, -10);
|
||||
victim->GetThreatMgr().ModifyThreatByPercent(this, -10);
|
||||
|
||||
basepoints0 = int32(CountPctFromMaxHealth(triggerAmount));
|
||||
trigger_spell_id = 31616;
|
||||
@@ -14104,7 +14104,7 @@ void Unit::AddThreat(Unit* victim, float fThreat, SpellSchoolMask schoolMask, Sp
|
||||
// Only mobs can manage threat lists
|
||||
if (CanHaveThreatList() && !HasUnitState(UNIT_STATE_EVADE))
|
||||
{
|
||||
m_ThreatMgr.addThreat(victim, fThreat, schoolMask, threatSpell);
|
||||
m_ThreatMgr.AddThreat(victim, fThreat, schoolMask, threatSpell);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18679,8 +18679,8 @@ void Unit::SetPhaseMask(uint32 newPhaseMask, bool update)
|
||||
// modify threat lists for new phasemask
|
||||
if (GetTypeId() != TYPEID_PLAYER)
|
||||
{
|
||||
ThreatContainer::StorageType threatList = GetThreatMgr().getThreatList();
|
||||
ThreatContainer::StorageType offlineThreatList = GetThreatMgr().getOfflineThreatList();
|
||||
ThreatContainer::StorageType threatList = GetThreatMgr().GetThreatList();
|
||||
ThreatContainer::StorageType offlineThreatList = GetThreatMgr().GetOfflineThreatList();
|
||||
|
||||
// merge expects sorted lists
|
||||
threatList.sort();
|
||||
@@ -19654,17 +19654,17 @@ void Unit::SendThreatListUpdate()
|
||||
{
|
||||
if (!GetThreatMgr().isThreatListEmpty())
|
||||
{
|
||||
uint32 count = GetThreatMgr().getThreatList().size();
|
||||
uint32 count = GetThreatMgr().GetThreatList().size();
|
||||
|
||||
//LOG_DEBUG("entities.unit", "WORLD: Send SMSG_THREAT_UPDATE Message");
|
||||
WorldPacket data(SMSG_THREAT_UPDATE, 8 + count * 8);
|
||||
data << GetPackGUID();
|
||||
data << uint32(count);
|
||||
ThreatContainer::StorageType const& tlist = GetThreatMgr().getThreatList();
|
||||
ThreatContainer::StorageType const& tlist = GetThreatMgr().GetThreatList();
|
||||
for (ThreatContainer::StorageType::const_iterator itr = tlist.begin(); itr != tlist.end(); ++itr)
|
||||
{
|
||||
data << (*itr)->getUnitGuid().WriteAsPacked();
|
||||
data << uint32((*itr)->getThreat() * 100);
|
||||
data << uint32((*itr)->GetThreat() * 100);
|
||||
}
|
||||
SendMessageToSet(&data, false);
|
||||
}
|
||||
@@ -19674,18 +19674,18 @@ void Unit::SendChangeCurrentVictimOpcode(HostileReference* pHostileReference)
|
||||
{
|
||||
if (!GetThreatMgr().isThreatListEmpty())
|
||||
{
|
||||
uint32 count = GetThreatMgr().getThreatList().size();
|
||||
uint32 count = GetThreatMgr().GetThreatList().size();
|
||||
|
||||
LOG_DEBUG("entities.unit", "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message");
|
||||
WorldPacket data(SMSG_HIGHEST_THREAT_UPDATE, 8 + 8 + count * 8);
|
||||
data << GetPackGUID();
|
||||
data << pHostileReference->getUnitGuid().WriteAsPacked();
|
||||
data << uint32(count);
|
||||
ThreatContainer::StorageType const& tlist = GetThreatMgr().getThreatList();
|
||||
ThreatContainer::StorageType const& tlist = GetThreatMgr().GetThreatList();
|
||||
for (ThreatContainer::StorageType::const_iterator itr = tlist.begin(); itr != tlist.end(); ++itr)
|
||||
{
|
||||
data << (*itr)->getUnitGuid().WriteAsPacked();
|
||||
data << uint32((*itr)->getThreat() * 100);
|
||||
data << uint32((*itr)->GetThreat() * 100);
|
||||
}
|
||||
SendMessageToSet(&data, false);
|
||||
}
|
||||
@@ -20615,7 +20615,7 @@ bool Unit::IsInCombatWith(Unit const* who) const
|
||||
return false;
|
||||
// Search in threat list
|
||||
ObjectGuid guid = who->GetGUID();
|
||||
for (ThreatContainer::StorageType::const_iterator i = m_ThreatMgr.getThreatList().begin(); i != m_ThreatMgr.getThreatList().end(); ++i)
|
||||
for (ThreatContainer::StorageType::const_iterator i = m_ThreatMgr.GetThreatList().begin(); i != m_ThreatMgr.GetThreatList().end(); ++i)
|
||||
{
|
||||
HostileReference* ref = (*i);
|
||||
// Return true if the unit matches
|
||||
|
||||
@@ -3299,16 +3299,16 @@ void Spell::EffectTaunt(SpellEffIndex /*effIndex*/)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!unitTarget->GetThreatMgr().getOnlineContainer().empty())
|
||||
if (!unitTarget->GetThreatMgr().GetOnlineContainer().empty())
|
||||
{
|
||||
// Also use this effect to set the taunter's threat to the taunted creature's highest value
|
||||
float myThreat = unitTarget->GetThreatMgr().getThreat(m_caster);
|
||||
float topThreat = unitTarget->GetThreatMgr().getOnlineContainer().getMostHated()->getThreat();
|
||||
float myThreat = unitTarget->GetThreatMgr().GetThreat(m_caster);
|
||||
float topThreat = unitTarget->GetThreatMgr().GetOnlineContainer().getMostHated()->GetThreat();
|
||||
if (topThreat > myThreat)
|
||||
unitTarget->GetThreatMgr().doAddThreat(m_caster, topThreat - myThreat);
|
||||
unitTarget->GetThreatMgr().DoAddThreat(m_caster, topThreat - myThreat);
|
||||
|
||||
//Set aggro victim to caster
|
||||
if (HostileReference* forcedVictim = unitTarget->GetThreatMgr().getOnlineContainer().getReferenceByTarget(m_caster))
|
||||
if (HostileReference* forcedVictim = unitTarget->GetThreatMgr().GetOnlineContainer().getReferenceByTarget(m_caster))
|
||||
unitTarget->GetThreatMgr().setCurrentVictim(forcedVictim);
|
||||
}
|
||||
|
||||
@@ -5386,7 +5386,7 @@ void Spell::EffectModifyThreatPercent(SpellEffIndex /*effIndex*/)
|
||||
if (!unitTarget)
|
||||
return;
|
||||
|
||||
unitTarget->GetThreatMgr().modifyThreatPercent(m_caster, damage);
|
||||
unitTarget->GetThreatMgr().ModifyThreatByPercent(m_caster, damage);
|
||||
}
|
||||
|
||||
void Spell::EffectTransmitted(SpellEffIndex effIndex)
|
||||
|
||||
Reference in New Issue
Block a user