Files
TCPlayerbotCore/src/server/game/Combat/HostileRefManager.cpp
T

197 lines
5.2 KiB
C++
Raw Normal View History

/*
2011-01-01 15:01:13 +01:00
* Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2010-03-09 11:11:10 +01:00
#include "HostileRefManager.h"
2008-10-02 16:23:55 -05:00
#include "ThreatManager.h"
#include "Unit.h"
#include "DBCStructure.h"
2008-10-02 16:23:55 -05:00
#include "SpellMgr.h"
#include "SpellInfo.h"
2009-10-17 15:51:44 -07:00
2010-03-09 11:11:10 +01:00
HostileRefManager::~HostileRefManager()
2008-10-02 16:23:55 -05:00
{
deleteReferences();
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//=================================================
// send threat to all my hateres for the victim
// The victim is hated than by them as well
2008-10-02 16:23:55 -05:00
// use for buffs and healing threat functionality
2009-10-17 15:51:44 -07:00
void HostileRefManager::threatAssist(Unit* victim, float baseThreat, SpellInfo const* threatSpell)
2008-10-02 16:23:55 -05:00
{
HostileReference* ref = getFirst();
float threat = ThreatCalcHelper::calcThreat(victim, iOwner, baseThreat, (threatSpell ? threatSpell->GetSchoolMask() : SPELL_SCHOOL_MASK_NORMAL), threatSpell);
threat /= getSize();
while (ref)
2008-10-02 16:23:55 -05:00
{
if (victim == getOwner())
ref->addThreat(threat); // It is faster to modify the threat durectly if possible
2008-10-02 16:23:55 -05:00
else
ref->getSource()->addThreat(victim, threat);
2008-10-02 16:23:55 -05:00
ref = ref->next();
}
}
2009-10-17 15:51:44 -07:00
//=================================================
void HostileRefManager::addTempThreat(float threat, bool apply)
{
2010-03-09 11:11:10 +01:00
HostileReference* ref = getFirst();
while (ref)
{
if (apply)
{
if (ref->getTempThreatModifier() == 0.0f)
ref->addTempThreat(threat);
}
else
ref->resetTempThreat();
ref = ref->next();
}
}
2008-10-02 16:23:55 -05:00
//=================================================
2009-10-17 15:51:44 -07:00
void HostileRefManager::addThreatPercent(int32 percent)
2008-10-02 16:23:55 -05:00
{
HostileReference* ref = getFirst();
while (ref)
2008-10-02 16:23:55 -05:00
{
ref->addThreatPercent(percent);
2008-10-02 16:23:55 -05:00
ref = ref->next();
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//=================================================
// The online / offline status is given to the method. The calculation has to be done before
2009-10-17 15:51:44 -07:00
void HostileRefManager::setOnlineOfflineState(bool isOnline)
2008-10-02 16:23:55 -05:00
{
HostileReference* ref = getFirst();
while (ref)
2008-10-02 16:23:55 -05:00
{
ref->setOnlineOfflineState(isOnline);
2008-10-02 16:23:55 -05:00
ref = ref->next();
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//=================================================
// The online / offline status is calculated and set
2009-10-17 15:51:44 -07:00
2010-03-09 11:11:10 +01:00
void HostileRefManager::updateThreatTables()
2008-10-02 16:23:55 -05:00
{
2010-03-09 11:11:10 +01:00
HostileReference* ref = getFirst();
2010-04-07 19:13:19 +02:00
while (ref)
2008-10-02 16:23:55 -05:00
{
ref->updateOnlineStatus();
ref = ref->next();
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//=================================================
// The references are not needed anymore
// tell the source to remove them from the list and free the mem
2009-10-17 15:51:44 -07:00
2010-03-09 11:11:10 +01:00
void HostileRefManager::deleteReferences()
2008-10-02 16:23:55 -05:00
{
2010-03-09 11:11:10 +01:00
HostileReference* ref = getFirst();
2010-04-07 19:13:19 +02:00
while (ref)
2008-10-02 16:23:55 -05:00
{
2010-03-09 11:11:10 +01:00
HostileReference* nextRef = ref->next();
2008-10-02 16:23:55 -05:00
ref->removeReference();
delete ref;
ref = nextRef;
}
}
2009-10-17 15:51:44 -07:00
//=================================================
// delete one reference, defined by faction
2010-03-09 11:11:10 +01:00
void HostileRefManager::deleteReferencesForFaction(uint32 faction)
{
2010-03-09 11:11:10 +01:00
HostileReference* ref = getFirst();
2010-04-07 19:13:19 +02:00
while (ref)
{
2010-03-09 11:11:10 +01:00
HostileReference* nextRef = ref->next();
2010-04-07 19:14:10 +02:00
if (ref->getSource()->getOwner()->getFactionTemplateEntry()->faction == faction)
{
ref->removeReference();
delete ref;
}
ref = nextRef;
}
}
2008-10-02 16:23:55 -05:00
//=================================================
// delete one reference, defined by Unit
2009-10-17 15:51:44 -07:00
void HostileRefManager::deleteReference(Unit *creature)
2008-10-02 16:23:55 -05:00
{
2010-03-09 11:11:10 +01:00
HostileReference* ref = getFirst();
2010-04-07 19:13:19 +02:00
while (ref)
2008-10-02 16:23:55 -05:00
{
2010-03-09 11:11:10 +01:00
HostileReference* nextRef = ref->next();
if (ref->getSource()->getOwner() == creature)
2008-10-02 16:23:55 -05:00
{
ref->removeReference();
delete ref;
break;
}
ref = nextRef;
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//=================================================
// set state for one reference, defined by Unit
2009-10-17 15:51:44 -07:00
void HostileRefManager::setOnlineOfflineState(Unit *creature, bool isOnline)
2008-10-02 16:23:55 -05:00
{
2010-03-09 11:11:10 +01:00
HostileReference* ref = getFirst();
2010-04-07 19:13:19 +02:00
while (ref)
2008-10-02 16:23:55 -05:00
{
2010-03-09 11:11:10 +01:00
HostileReference* nextRef = ref->next();
if (ref->getSource()->getOwner() == creature)
2008-10-02 16:23:55 -05:00
{
ref->setOnlineOfflineState(isOnline);
2008-10-02 16:23:55 -05:00
break;
}
ref = nextRef;
}
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//=================================================
2009-02-17 20:07:49 -06:00
2010-11-13 18:04:56 +01:00
void HostileRefManager::UpdateVisibility()
{
HostileReference* ref = getFirst();
while (ref)
{
HostileReference* nextRef = ref->next();
if (!ref->getSource()->getOwner()->canSeeOrDetect(getOwner()))
{
2010-11-16 14:08:12 +01:00
nextRef = ref->next();
2010-11-13 18:04:56 +01:00
ref->removeReference();
delete ref;
}
ref = nextRef;
}
}