[10465] Implement SPELL_EFFECT_REDIRECT_THREAT

Note: all spells with effect expect additional code for redirection reset.
Until code adding redirection work longer that expected.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>

Patch partly rewrited with move new data into HostileRefManager
and added redirection to threatAssist. Also bug fixed with
redirection threat to unit not in hostile list yet.
This commit is contained in:
ascent 2010-09-11 00:03:27 +04:00 committed by VladimirMangos
parent f441216aa0
commit 88cc2d440f
7 changed files with 85 additions and 9 deletions

View file

@ -21,6 +21,12 @@
#include "Unit.h"
#include "DBCStructure.h"
#include "SpellMgr.h"
#include "Map.h"
HostileRefManager::HostileRefManager( Unit *pOwner ) : iOwner(pOwner), m_redirectionMod(0.0f)
{
}
HostileRefManager::~HostileRefManager()
{
@ -34,17 +40,34 @@ HostileRefManager::~HostileRefManager()
void HostileRefManager::threatAssist(Unit *pVictim, float pThreat, SpellEntry const *pThreatSpell, bool pSingleTarget)
{
HostileReference* ref;
float redirectedMod = pVictim->getHostileRefManager().GetThreatRedirectionMod();
Unit* redirectedTarget = redirectedMod ? pVictim->getHostileRefManager().GetThreatRedirectionTarget() : NULL;
uint32 size = pSingleTarget ? 1 : getSize(); // if pSingleTarget do not devide threat
ref = getFirst();
HostileReference* ref = getFirst();
while(ref != NULL)
{
float threat = ThreatCalcHelper::calcThreat(pVictim, iOwner, pThreat, false, (pThreatSpell ? GetSpellSchoolMask(pThreatSpell) : SPELL_SCHOOL_MASK_NORMAL), pThreatSpell);
if(pVictim == getOwner())
if (threat > 0.0f)
{
if (redirectedTarget && redirectedTarget != ref->getTarget() && redirectedTarget->isAlive())
{
float redirectedThreat = threat * redirectedMod;
threat -= redirectedThreat;
if(redirectedTarget == getOwner()) // It is faster to modify the threat durectly if possible
ref->addThreat(float (threat) / size);
else
ref->getSource()->addThreat(redirectedTarget, redirectedThreat);
}
}
if (pVictim == getOwner())
ref->addThreat(float (threat) / size); // It is faster to modify the threat durectly if possible
else
ref->getSource()->addThreat(pVictim, float (threat) / size);
ref = ref->next();
}
}
@ -162,4 +185,10 @@ void HostileRefManager::setOnlineOfflineState(Unit *pCreature,bool pIsOnline)
}
}
Unit* HostileRefManager::GetThreatRedirectionTarget() const
{
return !m_redirectionTargetGuid.IsEmpty() ? iOwner->GetMap()->GetUnit(m_redirectionTargetGuid) : NULL;
}
//=================================================