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"
22 #include "DBCStructure.h"
25 HostilRefManager::~HostilRefManager()
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
)
39 uint32 size
= pSingleTarget
? 1 : getSize(); // if pSingleTarget do not devide threat
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
47 ref
->getSource()->addThreat(pVictim
, float (threat
) / size
);
52 //=================================================
54 void HostilRefManager::addThreatPercent(int32 pValue
)
61 ref
->addThreatPercent(pValue
);
66 //=================================================
67 // The online / offline status is given to the method. The calculation has to be done before
69 void HostilRefManager::setOnlineOfflineState(bool pIsOnline
)
76 ref
->setOnlineOfflineState(pIsOnline
);
81 //=================================================
82 // The online / offline status is calculated and set
84 void HostilRefManager::updateThreatTables()
86 HostilReference
* 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 HostilRefManager::deleteReferences()
100 HostilReference
* ref
= getFirst();
103 HostilReference
* nextRef
= ref
->next();
104 ref
->removeReference();
110 //=================================================
111 // delete one reference, defined by Unit
113 void HostilRefManager::deleteReference(Unit
*pCreature
)
115 HostilReference
* ref
= getFirst();
118 HostilReference
* nextRef
= ref
->next();
119 if(ref
->getSource()->getOwner() == pCreature
)
121 ref
->removeReference();
129 //=================================================
130 // set state for one reference, defined by Unit
132 void HostilRefManager::setOnlineOfflineState(Unit
*pCreature
,bool pIsOnline
)
134 HostilReference
* ref
= getFirst();
137 HostilReference
* nextRef
= ref
->next();
138 if(ref
->getSource()->getOwner() == pCreature
)
140 ref
->setOnlineOfflineState(pIsOnline
);
147 //=================================================