[9581] Fixed apply damage reduction to melee/ranged damage.
[getmangos.git] / src / game / HostileRefManager.cpp
blob1ba8f4b2becad5640c3fef9d08d95938b1b5b7dd
1 /*
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"
21 #include "Unit.h"
22 #include "DBCStructure.h"
23 #include "SpellMgr.h"
25 HostileRefManager::~HostileRefManager()
27 deleteReferences();
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
40 ref = getFirst();
41 while(ref != NULL)
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
46 else
47 ref->getSource()->addThreat(pVictim, float (threat) / size);
48 ref = ref->next();
52 //=================================================
54 void HostileRefManager::addThreatPercent(int32 pValue)
56 HostileReference* ref;
58 ref = getFirst();
59 while(ref != NULL)
61 ref->addThreatPercent(pValue);
62 ref = ref->next();
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;
73 ref = getFirst();
74 while(ref != NULL)
76 ref->setOnlineOfflineState(pIsOnline);
77 ref = ref->next();
81 //=================================================
82 // The online / offline status is calculated and set
84 void HostileRefManager::updateThreatTables()
86 HostileReference* ref = getFirst();
87 while(ref)
89 ref->updateOnlineStatus();
90 ref = ref->next();
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();
101 while(ref)
103 HostileReference* nextRef = ref->next();
104 ref->removeReference();
105 delete ref;
106 ref = nextRef;
110 //=================================================
111 // delete one reference, defined by faction
113 void HostileRefManager::deleteReferencesForFaction(uint32 faction)
115 HostileReference* ref = getFirst();
116 while(ref)
118 HostileReference* nextRef = ref->next();
119 if(ref->getSource()->getOwner()->getFactionTemplateEntry()->faction == faction)
121 ref->removeReference();
122 delete ref;
124 ref = nextRef;
128 //=================================================
129 // delete one reference, defined by Unit
131 void HostileRefManager::deleteReference(Unit *pCreature)
133 HostileReference* ref = getFirst();
134 while(ref)
136 HostileReference* nextRef = ref->next();
137 if(ref->getSource()->getOwner() == pCreature)
139 ref->removeReference();
140 delete ref;
141 break;
143 ref = nextRef;
147 //=================================================
148 // set state for one reference, defined by Unit
150 void HostileRefManager::setOnlineOfflineState(Unit *pCreature,bool pIsOnline)
152 HostileReference* ref = getFirst();
153 while(ref)
155 HostileReference* nextRef = ref->next();
156 if(ref->getSource()->getOwner() == pCreature)
158 ref->setOnlineOfflineState(pIsOnline);
159 break;
161 ref = nextRef;
165 //=================================================