aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Combat
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2016-10-06 23:14:51 -0300
committerjoschiwald <joschiwald.trinity@gmail.com>2017-08-21 21:49:36 +0200
commitec3dc0a43101dcbe2e469891acf0b654106eccfc (patch)
tree88f8c416d14b54fc5a71ba7f7cdb039aa66af44c /src/server/game/Combat
parentab916fd1b37ca39071c2253be68e60ac2a735ada (diff)
Core/Misc: fix interaction of spells like Shadowmeld with Threat reducing effects
- SPELL_AURA_MOD_TOTAL_THREAT should be temporary and not added/subtracted from total, only computed - Cleanup of reference related code - Kill getLast() and reverse iterator obsevers, LinkedList iterator can't be used as a standard reverse_iterator (ie with operator++). They weren't used anyways (cherry picked from commit 3b6fd226bedb689847dadaeeba36a588ee9bc928) # Conflicts: # src/server/game/Combat/ThreatManager.cpp # src/server/game/Loot/LootMgr.h
Diffstat (limited to 'src/server/game/Combat')
-rw-r--r--src/server/game/Combat/HostileRefManager.cpp8
-rw-r--r--src/server/game/Combat/HostileRefManager.h11
-rw-r--r--src/server/game/Combat/ThreatManager.cpp27
-rw-r--r--src/server/game/Combat/ThreatManager.h37
-rw-r--r--src/server/game/Combat/UnitEvents.h39
5 files changed, 57 insertions, 65 deletions
diff --git a/src/server/game/Combat/HostileRefManager.cpp b/src/server/game/Combat/HostileRefManager.cpp
index 2c977f61941..e6153f0acff 100644
--- a/src/server/game/Combat/HostileRefManager.cpp
+++ b/src/server/game/Combat/HostileRefManager.cpp
@@ -28,8 +28,8 @@ HostileRefManager::~HostileRefManager()
}
//=================================================
-// send threat to all my hateres for the victim
-// The victim is hated than by them as well
+// send threat to all my haters for the victim
+// The victim is then hated by them as well
// use for buffs and healing threat functionality
void HostileRefManager::threatAssist(Unit* victim, float baseThreat, SpellInfo const* threatSpell)
@@ -37,9 +37,10 @@ void HostileRefManager::threatAssist(Unit* victim, float baseThreat, SpellInfo c
if (getSize() == 0)
return;
- HostileReference* ref = getFirst();
float threat = ThreatCalcHelper::calcThreat(victim, iOwner, baseThreat, (threatSpell ? threatSpell->GetSchoolMask() : SPELL_SCHOOL_MASK_NORMAL), threatSpell);
threat /= getSize();
+
+ HostileReference* ref = getFirst();
while (ref)
{
if (ThreatCalcHelper::isValidProcess(victim, ref->GetSource()->GetOwner(), threatSpell))
@@ -54,7 +55,6 @@ void HostileRefManager::threatAssist(Unit* victim, float baseThreat, SpellInfo c
void HostileRefManager::addTempThreat(float threat, bool apply)
{
HostileReference* ref = getFirst();
-
while (ref)
{
if (apply)
diff --git a/src/server/game/Combat/HostileRefManager.h b/src/server/game/Combat/HostileRefManager.h
index ada7113ce52..e7a9b364cdd 100644
--- a/src/server/game/Combat/HostileRefManager.h
+++ b/src/server/game/Combat/HostileRefManager.h
@@ -31,18 +31,16 @@ class SpellInfo;
class TC_GAME_API HostileRefManager : public RefManager<Unit, ThreatManager>
{
- private:
- Unit* iOwner;
public:
- explicit HostileRefManager(Unit* owner) { iOwner = owner; }
+ explicit HostileRefManager(Unit* owner) : iOwner(owner) { }
~HostileRefManager();
- Unit* GetOwner() { return iOwner; }
+ Unit* GetOwner() const { return iOwner; }
// send threat to all my hateres for the victim
// The victim is hated than by them as well
// use for buffs and healing threat functionality
- void threatAssist(Unit* victim, float baseThreat, SpellInfo const* threatSpell = NULL);
+ void threatAssist(Unit* victim, float baseThreat, SpellInfo const* threatSpell = nullptr);
void addTempThreat(float threat, bool apply);
@@ -68,6 +66,9 @@ class TC_GAME_API HostileRefManager : public RefManager<Unit, ThreatManager>
void deleteReference(Unit* creature);
void UpdateVisibility();
+
+ private:
+ Unit* iOwner;
};
//=================================================
#endif
diff --git a/src/server/game/Combat/ThreatManager.cpp b/src/server/game/Combat/ThreatManager.cpp
index 879138c090f..f330711c515 100644
--- a/src/server/game/Combat/ThreatManager.cpp
+++ b/src/server/game/Combat/ThreatManager.cpp
@@ -31,7 +31,7 @@
//==============================================================
// The hatingUnit is not used yet
-float ThreatCalcHelper::calcThreat(Unit* hatedUnit, Unit* /*hatingUnit*/, float threat, SpellSchoolMask schoolMask, SpellInfo const* threatSpell)
+float ThreatCalcHelper::calcThreat(Unit* hatedUnit, Unit* /*hatingUnit*/, float threat, SpellSchoolMask schoolMask, SpellInfo const* threatSpell /*= nullptr*/)
{
if (threatSpell)
{
@@ -40,7 +40,7 @@ float ThreatCalcHelper::calcThreat(Unit* hatedUnit, Unit* /*hatingUnit*/, float
threat *= threatEntry->pctMod;
// Energize is not affected by Mods
- for (SpellEffectInfo const* effect : threatSpell->GetEffectsForDifficulty(hatedUnit->GetMap()->GetDifficultyID()))
+ for (SpellEffectInfo const* effect : threatSpell->GetEffectsForDifficulty(hatedUnit->GetMap()->GetDifficultyID()))
if (effect && (effect->Effect == SPELL_EFFECT_ENERGIZE || effect->ApplyAuraName == SPELL_AURA_PERIODIC_ENERGIZE))
return threat;
@@ -51,7 +51,7 @@ float ThreatCalcHelper::calcThreat(Unit* hatedUnit, Unit* /*hatingUnit*/, float
return hatedUnit->ApplyTotalThreatModifier(threat, schoolMask);
}
-bool ThreatCalcHelper::isValidProcess(Unit* hatedUnit, Unit* hatingUnit, SpellInfo const* threatSpell)
+bool ThreatCalcHelper::isValidProcess(Unit* hatedUnit, Unit* hatingUnit, SpellInfo const* threatSpell /*= nullptr*/)
{
//function deals with adding threat and adding players and pets into ThreatList
//mobs, NPCs, guards have ThreatList and HateOfflineList
@@ -135,18 +135,20 @@ void HostileReference::fireStatusChanged(ThreatRefStatusChangeEvent& threatRefSt
void HostileReference::addThreat(float modThreat)
{
+ if (!modThreat)
+ return;
+
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())
updateOnlineStatus();
- if (modThreat != 0.0f)
- {
- ThreatRefStatusChangeEvent event(UEV_THREAT_REF_THREAT_CHANGE, this, modThreat);
- fireStatusChanged(event);
- }
- if (isValid() && modThreat >= 0.0f)
+ ThreatRefStatusChangeEvent event(UEV_THREAT_REF_THREAT_CHANGE, this, modThreat);
+ fireStatusChanged(event);
+
+ if (isValid() && modThreat > 0.0f)
{
Unit* victimOwner = getTarget()->GetCharmerOrOwner();
if (victimOwner && victimOwner->IsAlive())
@@ -156,9 +158,7 @@ void HostileReference::addThreat(float modThreat)
void HostileReference::addThreatPercent(int32 percent)
{
- float tmpThreat = iThreat;
- AddPct(tmpThreat, percent);
- addThreat(tmpThreat - iThreat);
+ addThreat(CalculatePct(iThreat, percent));
}
//============================================================
@@ -194,6 +194,7 @@ void HostileReference::updateOnlineStatus()
else
accessible = true;
}
+
setAccessibleState(accessible);
setOnlineOfflineState(online);
}
@@ -222,7 +223,7 @@ void HostileReference::setAccessibleState(bool isAccessible)
{
iAccessible = isAccessible;
- ThreatRefStatusChangeEvent event(UEV_THREAT_REF_ASSECCIBLE_STATUS, this);
+ ThreatRefStatusChangeEvent event(UEV_THREAT_REF_ACCESSIBLE_STATUS, this);
fireStatusChanged(event);
}
}
diff --git a/src/server/game/Combat/ThreatManager.h b/src/server/game/Combat/ThreatManager.h
index 493192248ca..4b739d192c1 100644
--- a/src/server/game/Combat/ThreatManager.h
+++ b/src/server/game/Combat/ThreatManager.h
@@ -41,8 +41,8 @@ class SpellInfo;
struct TC_GAME_API ThreatCalcHelper
{
- static float calcThreat(Unit* hatedUnit, Unit* hatingUnit, float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL, SpellInfo const* threatSpell = NULL);
- static bool isValidProcess(Unit* hatedUnit, Unit* hatingUnit, SpellInfo const* threatSpell = NULL);
+ static float calcThreat(Unit* hatedUnit, Unit* hatingUnit, float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL, SpellInfo const* threatSpell = nullptr);
+ static bool isValidProcess(Unit* hatedUnit, Unit* hatingUnit, SpellInfo const* threatSpell = nullptr);
};
//==============================================================
@@ -54,11 +54,11 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager>
//=================================================
void addThreat(float modThreat);
- void setThreat(float threat) { addThreat(threat - getThreat()); }
+ void setThreat(float threat) { addThreat(threat - iThreat); }
void addThreatPercent(int32 percent);
- float getThreat() const { return iThreat; }
+ float getThreat() const { return iThreat + iTempThreatModifier; }
bool isOnline() const { return iOnline; }
@@ -66,27 +66,27 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager>
// in this case online = true, but accessible = false
bool isAccessible() const { return iAccessible; }
- // used for temporary setting a threat and reducting it later again.
+ // used for temporary setting a threat and reducing it later again.
// the threat modification is stored
void setTempThreat(float threat)
{
- addTempThreat(threat - getThreat());
+ addTempThreat(threat - iTempThreatModifier);
}
void addTempThreat(float threat)
{
- iTempThreatModifier = threat;
- if (iTempThreatModifier != 0.0f)
- addThreat(iTempThreatModifier);
+ if (!threat)
+ return;
+
+ iTempThreatModifier += threat;
+
+ ThreatRefStatusChangeEvent event(UEV_THREAT_REF_THREAT_CHANGE, this, threat);
+ fireStatusChanged(event);
}
void resetTempThreat()
{
- if (iTempThreatModifier != 0.0f)
- {
- addThreat(-iTempThreatModifier);
- iTempThreatModifier = 0.0f;
- }
+ addTempThreat(-iTempThreatModifier);
}
float getTempThreatModifier() { return iTempThreatModifier; }
@@ -100,7 +100,7 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager>
void setAccessibleState(bool isAccessible);
//=================================================
- bool operator == (const HostileReference& hostileRef) const { return hostileRef.getUnitGuid() == getUnitGuid(); }
+ bool operator==(HostileReference const& hostileRef) const { return hostileRef.getUnitGuid() == getUnitGuid(); }
//=================================================
@@ -113,7 +113,7 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager>
//=================================================
- HostileReference* next() { return ((HostileReference*) Reference<Unit, ThreatManager>::next()); }
+ HostileReference* next() { return static_cast<HostileReference*>(Reference<Unit, ThreatManager>::next()); }
//=================================================
@@ -125,14 +125,17 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager>
// Tell our refFrom (source) object, that the link is cut (Target destroyed)
void sourceObjectDestroyLink() override;
+
private:
// Inform the source, that the status of that reference was changed
void fireStatusChanged(ThreatRefStatusChangeEvent& threatRefStatusChangeEvent);
Unit* GetSourceUnit();
+
private:
float iThreat;
- float iTempThreatModifier; // used for taunt
+ float iTempThreatModifier; // used for SPELL_AURA_MOD_TOTAL_THREAT
+
ObjectGuid iUnitGuid;
bool iOnline;
bool iAccessible;
diff --git a/src/server/game/Combat/UnitEvents.h b/src/server/game/Combat/UnitEvents.h
index d8899ca49ab..35b7e7ecb5f 100644
--- a/src/server/game/Combat/UnitEvents.h
+++ b/src/server/game/Combat/UnitEvents.h
@@ -40,7 +40,7 @@ enum UNIT_EVENT_TYPE
UEV_THREAT_REF_REMOVE_FROM_LIST = 1<<2,
// Player/Pet entered/left water or some other place where it is/was not accessible for the creature
- UEV_THREAT_REF_ASSECCIBLE_STATUS = 1<<3,
+ UEV_THREAT_REF_ACCESSIBLE_STATUS = 1<<3,
// Threat list is going to be sorted (if dirty flag is set)
UEV_THREAT_SORT_LIST = 1<<4,
@@ -58,7 +58,7 @@ enum UNIT_EVENT_TYPE
//UEV_UNIT_HEALTH_CHANGE = 1<<8,
};
-#define UEV_THREAT_REF_EVENT_MASK (UEV_THREAT_REF_ONLINE_STATUS | UEV_THREAT_REF_THREAT_CHANGE | UEV_THREAT_REF_REMOVE_FROM_LIST | UEV_THREAT_REF_ASSECCIBLE_STATUS)
+#define UEV_THREAT_REF_EVENT_MASK (UEV_THREAT_REF_ONLINE_STATUS | UEV_THREAT_REF_THREAT_CHANGE | UEV_THREAT_REF_REMOVE_FROM_LIST | UEV_THREAT_REF_ACCESSIBLE_STATUS)
#define UEV_THREAT_MANAGER_EVENT_MASK (UEV_THREAT_SORT_LIST | UEV_THREAT_SET_NEXT_TARGET | UEV_THREAT_VICTIM_CHANGED)
#define UEV_ALL_EVENT_MASK (0xffffffff)
@@ -69,14 +69,16 @@ enum UNIT_EVENT_TYPE
class UnitBaseEvent
{
- private:
- uint32 iType;
public:
- UnitBaseEvent(uint32 pType) { iType = pType; }
+ explicit UnitBaseEvent(uint32 pType) { iType = pType; }
uint32 getType() const { return iType; }
bool matchesTypeMask(uint32 pMask) const { return (iType & pMask) != 0; }
- void setType(uint32 pType) { iType = pType; }
+ private:
+ uint32 iType;
+
+ protected:
+ ~UnitBaseEvent() { }
};
//==============================================================
@@ -92,14 +94,15 @@ class TC_GAME_API ThreatRefStatusChangeEvent : public UnitBaseEvent
bool iBValue;
};
ThreatManager* iThreatManager;
+
public:
- ThreatRefStatusChangeEvent(uint32 pType) : UnitBaseEvent(pType), iThreatManager(NULL) { iHostileReference = NULL; }
+ explicit ThreatRefStatusChangeEvent(uint32 pType) : UnitBaseEvent(pType), iHostileReference(nullptr), iThreatManager(nullptr) { }
- ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference) : UnitBaseEvent(pType), iThreatManager(NULL) { iHostileReference = pHostileReference; }
+ ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference) : UnitBaseEvent(pType), iHostileReference(pHostileReference), iThreatManager(nullptr) { }
- ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference, float pValue) : UnitBaseEvent(pType), iThreatManager(NULL) { iHostileReference = pHostileReference; iFValue = pValue; }
+ ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference, float pValue) : UnitBaseEvent(pType), iHostileReference(pHostileReference), iFValue(pValue), iThreatManager(nullptr) { }
- ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference, bool pValue) : UnitBaseEvent(pType), iThreatManager(NULL) { iHostileReference = pHostileReference; iBValue = pValue; }
+ ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference, bool pValue) : UnitBaseEvent(pType), iHostileReference(pHostileReference), iBValue(pValue), iThreatManager(nullptr) { }
int32 getIValue() const { return iIValue; }
@@ -116,20 +119,4 @@ class TC_GAME_API ThreatRefStatusChangeEvent : public UnitBaseEvent
ThreatManager* getThreatManager() const { return iThreatManager; }
};
-//==============================================================
-
-class ThreatManagerEvent : public ThreatRefStatusChangeEvent
-{
- private:
- ThreatContainer* iThreatContainer;
- public:
- ThreatManagerEvent(uint32 pType) : ThreatRefStatusChangeEvent(pType), iThreatContainer(NULL) { }
- ThreatManagerEvent(uint32 pType, HostileReference* pHostileReference) : ThreatRefStatusChangeEvent(pType, pHostileReference), iThreatContainer(NULL) { }
-
- void setThreatContainer(ThreatContainer* pThreatContainer) { iThreatContainer = pThreatContainer; }
-
- ThreatContainer* getThreatContainer() const { return iThreatContainer; }
-};
-
-//==============================================================
#endif