[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / HostilRefManager.cpp
blob149f91494881dd720a22380e955b658939be5cc3
1 /*
2 * Copyright (C) 2005-2009 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 "HostilRefManager.h"
20 #include "ThreatManager.h"
21 #include "Unit.h"
22 #include "Database/DBCStructure.h"
23 #include "SpellMgr.h"
25 HostilRefManager::~HostilRefManager()
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 HostilRefManager::threatAssist(Unit *pVictim, float pThreat, SpellEntry const *pThreatSpell, bool pSingleTarget)
37 HostilReference* 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, (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 HostilRefManager::addThreatPercent(int32 pValue)
56 HostilReference* 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 HostilRefManager::setOnlineOfflineState(bool pIsOnline)
71 HostilReference* 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 HostilRefManager::updateThreatTables()
86 HostilReference* 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 HostilRefManager::deleteReferences()
100 HostilReference* ref = getFirst();
101 while(ref)
103 HostilReference* nextRef = ref->next();
104 ref->removeReference();
105 delete ref;
106 ref = nextRef;
110 //=================================================
111 // delete one reference, defined by Unit
113 void HostilRefManager::deleteReference(Unit *pCreature)
115 HostilReference* ref = getFirst();
116 while(ref)
118 HostilReference* nextRef = ref->next();
119 if(ref->getSource()->getOwner() == pCreature)
121 ref->removeReference();
122 delete ref;
123 break;
125 ref = nextRef;
129 //=================================================
130 // set state for one reference, defined by Unit
132 void HostilRefManager::setOnlineOfflineState(Unit *pCreature,bool pIsOnline)
134 HostilReference* ref = getFirst();
135 while(ref)
137 HostilReference* nextRef = ref->next();
138 if(ref->getSource()->getOwner() == pCreature)
140 ref->setOnlineOfflineState(pIsOnline);
141 break;
143 ref = nextRef;
147 //=================================================