[7618] Fixed: Prevent adding threat to dead creature and for dead target. Author: VladimirMangos
Also remove horriable typecast in ThreatManager code and some other cleanups. --HG-- branch : trunk
This commit is contained in:
+27
-17
@@ -83,7 +83,7 @@ void HostilReference::sourceObjectDestroyLink()
|
|||||||
//============================================================
|
//============================================================
|
||||||
// Inform the source, that the status of the reference changed
|
// Inform the source, that the status of the reference changed
|
||||||
|
|
||||||
void HostilReference::fireStatusChanged(const ThreatRefStatusChangeEvent& pThreatRefStatusChangeEvent)
|
void HostilReference::fireStatusChanged(ThreatRefStatusChangeEvent& pThreatRefStatusChangeEvent)
|
||||||
{
|
{
|
||||||
if(getSource())
|
if(getSource())
|
||||||
getSource()->processThreatEvent(&pThreatRefStatusChangeEvent);
|
getSource()->processThreatEvent(&pThreatRefStatusChangeEvent);
|
||||||
@@ -99,7 +99,11 @@ void HostilReference::addThreat(float pMod)
|
|||||||
if(!isOnline())
|
if(!isOnline())
|
||||||
updateOnlineStatus();
|
updateOnlineStatus();
|
||||||
if(pMod != 0.0f)
|
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)
|
if(isValid() && pMod >= 0)
|
||||||
{
|
{
|
||||||
Unit* victim_owner = getTarget()->GetCharmerOrOwner();
|
Unit* victim_owner = getTarget()->GetCharmerOrOwner();
|
||||||
@@ -154,8 +158,10 @@ void HostilReference::setOnlineOfflineState(bool pIsOnline)
|
|||||||
{
|
{
|
||||||
iOnline = pIsOnline;
|
iOnline = pIsOnline;
|
||||||
if(!iOnline)
|
if(!iOnline)
|
||||||
setAccessibleState(false); // if not online that not accessible as well
|
setAccessibleState(false); // if not online that not accessable as well
|
||||||
fireStatusChanged(ThreatRefStatusChangeEvent(UEV_THREAT_REF_ONLINE_STATUS, this));
|
|
||||||
|
ThreatRefStatusChangeEvent event(UEV_THREAT_REF_ONLINE_STATUS, this);
|
||||||
|
fireStatusChanged(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +172,9 @@ void HostilReference::setAccessibleState(bool pIsAccessible)
|
|||||||
if(iAccessible != pIsAccessible)
|
if(iAccessible != pIsAccessible)
|
||||||
{
|
{
|
||||||
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()
|
void HostilReference::removeReference()
|
||||||
{
|
{
|
||||||
invalidate();
|
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
|
//players and pets have only InHateListOf
|
||||||
//HateOfflineList is used co contain unattackable victims (in-flight, in-water, GM etc.)
|
//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;
|
return;
|
||||||
|
|
||||||
|
// not to GM
|
||||||
if(!pVictim || (pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster()) )
|
if(!pVictim || (pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->isGameMaster()) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// not to dead and not for dead
|
||||||
|
if(!pVictim->isAlive() || !getOwner()->isAlive() )
|
||||||
|
return;
|
||||||
|
|
||||||
assert(getOwner()->GetTypeId()== TYPEID_UNIT);
|
assert(getOwner()->GetTypeId()== TYPEID_UNIT);
|
||||||
|
|
||||||
float threat = ThreatCalcHelper::calcThreat(pVictim, iOwner, pThreat, schoolMask, pThreatSpell);
|
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
|
// The hated unit is gone, dead or deleted
|
||||||
// return true, if the event is consumed
|
// 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
|
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:
|
case UEV_THREAT_REF_THREAT_CHANGE:
|
||||||
if((getCurrentVictim() == hostilReference && threatRefStatusChangeEvent->getFValue()<0.0f) ||
|
if((getCurrentVictim() == hostilReference && threatRefStatusChangeEvent->getFValue()<0.0f) ||
|
||||||
@@ -509,6 +520,5 @@ bool ThreatManager::processThreatEvent(const UnitBaseEvent* pUnitBaseEvent)
|
|||||||
iThreatOfflineContainer.remove(hostilReference);
|
iThreatOfflineContainer.remove(hostilReference);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return consumed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-20
@@ -45,20 +45,8 @@ class ThreatCalcHelper
|
|||||||
};
|
};
|
||||||
|
|
||||||
//==============================================================
|
//==============================================================
|
||||||
|
|
||||||
class TRINITY_DLL_SPEC HostilReference : public Reference<Unit, ThreatManager>
|
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:
|
public:
|
||||||
HostilReference(Unit* pUnit, ThreatManager *pThreatManager, float pThreat);
|
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)
|
// Tell our refFrom (source) object, that the link is cut (Target destroyed)
|
||||||
void sourceObjectDestroyLink();
|
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
|
class TRINITY_DLL_SPEC ThreatManager
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
HostilReference* iCurrentVictim;
|
|
||||||
Unit* iOwner;
|
|
||||||
ThreatContainer iThreatContainer;
|
|
||||||
ThreatContainer iThreatOfflineContainer;
|
|
||||||
|
|
||||||
void _addThreat(Unit* target, float threat);
|
|
||||||
public:
|
public:
|
||||||
|
friend class HostilReference;
|
||||||
|
|
||||||
explicit ThreatManager(Unit *pOwner);
|
explicit ThreatManager(Unit *pOwner);
|
||||||
|
|
||||||
~ThreatManager() { clearReferences(); }
|
~ThreatManager() { clearReferences(); }
|
||||||
@@ -191,7 +185,7 @@ class TRINITY_DLL_SPEC ThreatManager
|
|||||||
|
|
||||||
bool isThreatListEmpty() { return iThreatContainer.empty();}
|
bool isThreatListEmpty() { return iThreatContainer.empty();}
|
||||||
|
|
||||||
bool processThreatEvent(const UnitBaseEvent* pUnitBaseEvent);
|
void processThreatEvent(ThreatRefStatusChangeEvent* threatRefStatusChangeEvent);
|
||||||
|
|
||||||
HostilReference* getCurrentVictim() { return iCurrentVictim; }
|
HostilReference* getCurrentVictim() { return iCurrentVictim; }
|
||||||
|
|
||||||
@@ -212,6 +206,13 @@ class TRINITY_DLL_SPEC ThreatManager
|
|||||||
std::list<HostilReference*>& getOfflieThreatList() { return iThreatOfflineContainer.getThreatList(); }
|
std::list<HostilReference*>& getOfflieThreatList() { return iThreatOfflineContainer.getThreatList(); }
|
||||||
ThreatContainer& getOnlineContainer() { return iThreatContainer; }
|
ThreatContainer& getOnlineContainer() { return iThreatContainer; }
|
||||||
ThreatContainer& getOfflineContainer() { return iThreatOfflineContainer; }
|
ThreatContainer& getOfflineContainer() { return iThreatOfflineContainer; }
|
||||||
|
private:
|
||||||
|
void _addThreat(Unit *pVictim, float threat);
|
||||||
|
|
||||||
|
HostilReference* iCurrentVictim;
|
||||||
|
Unit* iOwner;
|
||||||
|
ThreatContainer iThreatContainer;
|
||||||
|
ThreatContainer iThreatOfflineContainer;
|
||||||
};
|
};
|
||||||
|
|
||||||
//=================================================
|
//=================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user