aboutsummaryrefslogtreecommitdiff
path: root/src/game/ThreatManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/ThreatManager.cpp')
-rw-r--r--src/game/ThreatManager.cpp44
1 files changed, 27 insertions, 17 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;
}