Files
TCPlayerbotCore/src/game/HostileRefManager.cpp
T

190 lines
5.0 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* 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
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* 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, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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"
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 pVictim
// The pVictim is hated than by them as well
// use for buffs and healing threat functionality
2009-10-17 15:51:44 -07:00
2010-03-09 11:11:10 +01:00
void HostileRefManager::threatAssist(Unit *pVictim, float fThreat, SpellEntry const *pThreatSpell, bool pSingleTarget)
2008-10-02 16:23:55 -05:00
{
2010-03-09 11:11:10 +01:00
HostileReference* ref;
2009-10-17 15:51:44 -07:00
2009-10-18 18:38:46 -07:00
float size = pSingleTarget ? 1.0f : getSize(); // if pSingleTarget do not divide threat
2008-10-02 16:23:55 -05:00
ref = getFirst();
2010-04-07 19:13:19 +02:00
while (ref != NULL)
2008-10-02 16:23:55 -05:00
{
2009-10-18 18:38:46 -07:00
float threat = ThreatCalcHelper::calcThreat(pVictim, iOwner, fThreat, (pThreatSpell ? GetSpellSchoolMask(pThreatSpell) : SPELL_SCHOOL_MASK_NORMAL), pThreatSpell);
2010-04-07 19:14:10 +02:00
if (pVictim == getOwner())
2009-10-18 18:38:46 -07:00
ref->addThreat(threat / size); // It is faster to modify the threat durectly if possible
2008-10-02 16:23:55 -05:00
else
2009-10-18 18:38:46 -07:00
ref->getSource()->addThreat(pVictim, threat / size);
2008-10-02 16:23:55 -05:00
ref = ref->next();
}
}
2009-10-17 15:51:44 -07:00
//=================================================
2010-03-09 11:11:10 +01:00
void HostileRefManager::addTempThreat(float fThreat, bool apply)
{
2010-03-09 11:11:10 +01:00
HostileReference* ref = getFirst();
2010-04-07 19:13:19 +02:00
while (ref != NULL)
{
if (apply)
{
if (ref->getTempThreatModifier() == 0.0f)
ref->addTempThreat(fThreat);
}
else
ref->resetTempThreat();
ref = ref->next();
}
}
2008-10-02 16:23:55 -05:00
//=================================================
2009-10-17 15:51:44 -07:00
2010-03-09 11:11:10 +01:00
void HostileRefManager::addThreatPercent(int32 iPercent)
2008-10-02 16:23:55 -05:00
{
2010-03-09 11:11:10 +01:00
HostileReference* ref;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
ref = getFirst();
2009-10-18 18:38:46 -07:00
while (ref != NULL)
2008-10-02 16:23:55 -05:00
{
2009-10-18 18:38:46 -07:00
ref->addThreatPercent(iPercent);
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
2010-03-09 11:11:10 +01:00
void HostileRefManager::setOnlineOfflineState(bool bIsOnline)
2008-10-02 16:23:55 -05:00
{
2010-03-09 11:11:10 +01:00
HostileReference* ref;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
ref = getFirst();
2010-04-07 19:13:19 +02:00
while (ref != NULL)
2008-10-02 16:23:55 -05:00
{
2009-10-18 18:38:46 -07:00
ref->setOnlineOfflineState(bIsOnline);
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
2010-03-09 11:11:10 +01:00
void HostileRefManager::deleteReference(Unit *pCreature)
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();
2010-04-07 19:14:10 +02:00
if (ref->getSource()->getOwner() == pCreature)
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
2010-03-09 11:11:10 +01:00
void HostileRefManager::setOnlineOfflineState(Unit *pCreature, bool bIsOnline)
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();
2010-04-07 19:14:10 +02:00
if (ref->getSource()->getOwner() == pCreature)
2008-10-02 16:23:55 -05:00
{
2009-10-18 18:38:46 -07:00
ref->setOnlineOfflineState(bIsOnline);
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