2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "HostileRefManager.h"
20 #include "ThreatManager.h"
22 #include "DBCStructure.h"
25 HostileRefManager::~HostileRefManager()
30 //=================================================
31 // send threat to all my hateres for the pVictim
32 // The pVictim is hated than by them as well
33 // use for buffs and healing threat functionality
35 void HostileRefManager::threatAssist(Unit
*pVictim
, float pThreat
, SpellEntry
const *pThreatSpell
, bool pSingleTarget
)
37 HostileReference
* ref
;
39 uint32 size
= pSingleTarget
? 1 : getSize(); // if pSingleTarget do not devide threat
43 float threat
= ThreatCalcHelper::calcThreat(pVictim
, iOwner
, pThreat
, false, (pThreatSpell
? GetSpellSchoolMask(pThreatSpell
) : SPELL_SCHOOL_MASK_NORMAL
), pThreatSpell
);
44 if(pVictim
== getOwner())
45 ref
->addThreat(float (threat
) / size
); // It is faster to modify the threat durectly if possible
47 ref
->getSource()->addThreat(pVictim
, float (threat
) / size
);
52 //=================================================
54 void HostileRefManager::addThreatPercent(int32 pValue
)
56 HostileReference
* ref
;
61 ref
->addThreatPercent(pValue
);
66 //=================================================
67 // The online / offline status is given to the method. The calculation has to be done before
69 void HostileRefManager::setOnlineOfflineState(bool pIsOnline
)
71 HostileReference
* ref
;
76 ref
->setOnlineOfflineState(pIsOnline
);
81 //=================================================
82 // The online / offline status is calculated and set
84 void HostileRefManager::updateThreatTables()
86 HostileReference
* ref
= getFirst();
89 ref
->updateOnlineStatus();
94 //=================================================
95 // The references are not needed anymore
96 // tell the source to remove them from the list and free the mem
98 void HostileRefManager::deleteReferences()
100 HostileReference
* ref
= getFirst();
103 HostileReference
* nextRef
= ref
->next();
104 ref
->removeReference();
110 //=================================================
111 // delete one reference, defined by faction
113 void HostileRefManager::deleteReferencesForFaction(uint32 faction
)
115 HostileReference
* ref
= getFirst();
118 HostileReference
* nextRef
= ref
->next();
119 if(ref
->getSource()->getOwner()->getFactionTemplateEntry()->faction
== faction
)
121 ref
->removeReference();
128 //=================================================
129 // delete one reference, defined by Unit
131 void HostileRefManager::deleteReference(Unit
*pCreature
)
133 HostileReference
* ref
= getFirst();
136 HostileReference
* nextRef
= ref
->next();
137 if(ref
->getSource()->getOwner() == pCreature
)
139 ref
->removeReference();
147 //=================================================
148 // set state for one reference, defined by Unit
150 void HostileRefManager::setOnlineOfflineState(Unit
*pCreature
,bool pIsOnline
)
152 HostileReference
* ref
= getFirst();
155 HostileReference
* nextRef
= ref
->next();
156 if(ref
->getSource()->getOwner() == pCreature
)
158 ref
->setOnlineOfflineState(pIsOnline
);
165 //=================================================