aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game/ThreatManager.cpp44
-rw-r--r--src/game/ThreatManager.h41
2 files changed, 48 insertions, 37 deletions
diff --git a/src/game/ThreatManager.cpp b/src/game/ThreatManager.cpp
index 60bb05b40b4..336f02c4470 100644
--- a/src/game/ThreatManager.cpp
+++ b/src/game/ThreatManager.cpp
@@ -83,7 +83,7 @@ void HostilReference::sourceObjectDestroyLink()
//============================================================
// Inform the source, that the status of the reference changed
-void HostilReference::fireStatusChanged(const ThreatRefStatusChangeEvent& pThreatRefStatusChangeEvent)
+void HostilReference::fireStatusChanged(ThreatRefStatusChangeEvent& pThreatRefStatusChangeEvent)
{
if(getSource())
getSource()->processThreatEvent(&pThreatRefStatusChangeEvent);
@@ -99,7 +99,11 @@ void HostilReference::addThreat(float pMod)
if(!isOnline())
updateOnlineStatus();
if(pMod != 0.0f)
- fireStatusChanged(ThreatRefStatusChangeEvent(UEV_THREAT_REF_THREAT_CHANGE, this, pMod));
+ {
+ ThreatRefStatusChangeEvent event(UEV_THREAT_REF_THREAT_CHANGE, this, pMod);
+ fireStatusChanged(event);
+ }
+
if(isValid() && pMod >= 0)
{
Unit* victim_owner = getTarget()->GetCharmerOrOwner();
@@ -154,8 +158,10 @@ void HostilReference::setOnlineOfflineState(bool pIsOnline)
{
iOnline = pIsOnline;
if(!iOnline)
- setAccessibleState(false); // if not online that not accessible as well
- fireStatusChanged(ThreatRefStatusChangeEvent(UEV_THREAT_REF_ONLINE_STATUS, this));
+ setAccessibleState(false); // if not online that not accessable as well
+
+ ThreatRefStatusChangeEvent event(UEV_THREAT_REF_ONLINE_STATUS, this);
+ fireStatusChanged(event);
}
}
@@ -166,7 +172,9 @@ void HostilReference::setAccessibleState(bool pIsAccessible)
if(iAccessible != pIsAccessible)
{
iAccessible = pIsAccessible;
- fireStatusChanged(ThreatRefStatusChangeEvent(UEV_THREAT_REF_ASSECCIBLE_STATUS, this));
+
+ ThreatRefStatusChangeEvent event(UEV_THREAT_REF_ASSECCIBLE_STATUS, this);
+ fireStatusChanged(event);
}
}
@@ -177,7 +185,9 @@ void HostilReference::setAccessibleState(bool pIsAccessible)
void HostilReference::removeReference()
{
invalidate();
- fireStatusChanged(ThreatRefStatusChangeEvent(UEV_THREAT_REF_REMOVE_FROM_LIST, this));
+
+ ThreatRefStatusChangeEvent event(UEV_THREAT_REF_REMOVE_FROM_LIST, this);
+ fireStatusChanged(event);
}
//============================================================
@@ -357,12 +367,18 @@ void ThreatManager::addThreat(Unit* pVictim, float pThreat, SpellSchoolMask scho
//players and pets have only InHateListOf
//HateOfflineList is used co contain unattackable victims (in-flight, in-water, GM etc.)
- if (pVictim == getOwner()) // only for same creatures :)
+ // not to self
+ if (pVictim == getOwner())
return;
+ // not to GM
if(!pVictim || (pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster()) )
return;
+ // not to dead and not for dead
+ if(!pVictim->isAlive() || !getOwner()->isAlive() )
+ return;
+
assert(getOwner()->GetTypeId()== TYPEID_UNIT);
float threat = ThreatCalcHelper::calcThreat(pVictim, iOwner, pThreat, schoolMask, pThreatSpell);
@@ -460,18 +476,13 @@ void ThreatManager::setCurrentVictim(HostilReference* pHostilReference)
// The hated unit is gone, dead or deleted
// return true, if the event is consumed
-bool ThreatManager::processThreatEvent(const UnitBaseEvent* pUnitBaseEvent)
+void ThreatManager::processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusChangeEvent)
{
- bool consumed = false;
-
- ThreatRefStatusChangeEvent* threatRefStatusChangeEvent;
- HostilReference* hostilReference;
-
- threatRefStatusChangeEvent = (ThreatRefStatusChangeEvent*) pUnitBaseEvent;
threatRefStatusChangeEvent->setThreatManager(this); // now we can set the threat manager
- hostilReference = threatRefStatusChangeEvent->getReference();
- switch(pUnitBaseEvent->getType())
+ HostilReference* hostilReference = threatRefStatusChangeEvent->getReference();
+
+ switch(threatRefStatusChangeEvent->getType())
{
case UEV_THREAT_REF_THREAT_CHANGE:
if((getCurrentVictim() == hostilReference && threatRefStatusChangeEvent->getFValue()<0.0f) ||
@@ -509,6 +520,5 @@ bool ThreatManager::processThreatEvent(const UnitBaseEvent* pUnitBaseEvent)
iThreatOfflineContainer.remove(hostilReference);
break;
}
- return consumed;
}
diff --git a/src/game/ThreatManager.h b/src/game/ThreatManager.h
index 3b07a4ec43d..aa84cb7d52c 100644
--- a/src/game/ThreatManager.h
+++ b/src/game/ThreatManager.h
@@ -45,20 +45,8 @@ class ThreatCalcHelper
};
//==============================================================
-
class TRINITY_DLL_SPEC HostilReference : public Reference<Unit, ThreatManager>
{
- private:
- float iThreat;
- float iTempThreatModifyer; // used for taunt
- uint64 iUnitGuid;
- bool iOnline;
- bool iAccessible;
- private:
- // Inform the source, that the status of that reference was changed
- void fireStatusChanged(const ThreatRefStatusChangeEvent& pThreatRefStatusChangeEvent);
-
- Unit* getSourceUnit();
public:
HostilReference(Unit* pUnit, ThreatManager *pThreatManager, float pThreat);
@@ -125,6 +113,17 @@ class TRINITY_DLL_SPEC HostilReference : public Reference<Unit, ThreatManager>
// Tell our refFrom (source) object, that the link is cut (Target destroyed)
void sourceObjectDestroyLink();
+ private:
+ // Inform the source, that the status of that reference was changed
+ void fireStatusChanged(ThreatRefStatusChangeEvent& pThreatRefStatusChangeEvent);
+
+ Unit* getSourceUnit();
+ private:
+ float iThreat;
+ float iTempThreatModifyer; // used for taunt
+ uint64 iUnitGuid;
+ bool iOnline;
+ bool iAccessible;
};
//==============================================================
@@ -170,14 +169,9 @@ class TRINITY_DLL_SPEC ThreatContainer
class TRINITY_DLL_SPEC ThreatManager
{
- private:
- HostilReference* iCurrentVictim;
- Unit* iOwner;
- ThreatContainer iThreatContainer;
- ThreatContainer iThreatOfflineContainer;
-
- void _addThreat(Unit* target, float threat);
public:
+ friend class HostilReference;
+
explicit ThreatManager(Unit *pOwner);
~ThreatManager() { clearReferences(); }
@@ -191,7 +185,7 @@ class TRINITY_DLL_SPEC ThreatManager
bool isThreatListEmpty() { return iThreatContainer.empty();}
- bool processThreatEvent(const UnitBaseEvent* pUnitBaseEvent);
+ void processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusChangeEvent);
HostilReference* getCurrentVictim() { return iCurrentVictim; }
@@ -212,6 +206,13 @@ class TRINITY_DLL_SPEC ThreatManager
std::list<HostilReference*>& getOfflieThreatList() { return iThreatOfflineContainer.getThreatList(); }
ThreatContainer& getOnlineContainer() { return iThreatContainer; }
ThreatContainer& getOfflineContainer() { return iThreatOfflineContainer; }
+ private:
+ void _addThreat(Unit *pVictim, float threat);
+
+ HostilReference* iCurrentVictim;
+ Unit* iOwner;
+ ThreatContainer iThreatContainer;
+ ThreatContainer iThreatOfflineContainer;
};
//=================================================