1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
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. |
---|
8 | * |
---|
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. |
---|
13 | * |
---|
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 |
---|
17 | */ |
---|
18 | |
---|
19 | #include "HostilRefManager.h" |
---|
20 | #include "ThreatManager.h" |
---|
21 | #include "Unit.h" |
---|
22 | #include "Database/DBCStructure.h" |
---|
23 | #include "SpellMgr.h" |
---|
24 | |
---|
25 | HostilRefManager::~HostilRefManager() |
---|
26 | { |
---|
27 | deleteReferences(); |
---|
28 | } |
---|
29 | |
---|
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 |
---|
34 | |
---|
35 | void HostilRefManager::threatAssist(Unit *pVictim, float pThreat, SpellEntry const *pThreatSpell, bool pSingleTarget) |
---|
36 | { |
---|
37 | HostilReference* ref; |
---|
38 | |
---|
39 | uint32 size = pSingleTarget ? 1 : getSize(); // if pSingleTarget do not devide threat |
---|
40 | ref = getFirst(); |
---|
41 | while(ref != NULL) |
---|
42 | { |
---|
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(); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | //================================================= |
---|
53 | |
---|
54 | void HostilRefManager::addThreatPercent(int32 pValue) |
---|
55 | { |
---|
56 | HostilReference* ref; |
---|
57 | |
---|
58 | ref = getFirst(); |
---|
59 | while(ref != NULL) |
---|
60 | { |
---|
61 | ref->addThreatPercent(pValue); |
---|
62 | ref = ref->next(); |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | //================================================= |
---|
67 | // The online / offline status is given to the method. The calculation has to be done before |
---|
68 | |
---|
69 | void HostilRefManager::setOnlineOfflineState(bool pIsOnline) |
---|
70 | { |
---|
71 | HostilReference* ref; |
---|
72 | |
---|
73 | ref = getFirst(); |
---|
74 | while(ref != NULL) |
---|
75 | { |
---|
76 | ref->setOnlineOfflineState(pIsOnline); |
---|
77 | ref = ref->next(); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | //================================================= |
---|
82 | // The online / offline status is calculated and set |
---|
83 | |
---|
84 | void HostilRefManager::updateThreatTables() |
---|
85 | { |
---|
86 | HostilReference* ref = getFirst(); |
---|
87 | while(ref) |
---|
88 | { |
---|
89 | ref->updateOnlineStatus(); |
---|
90 | ref = ref->next(); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | //================================================= |
---|
95 | // The references are not needed anymore |
---|
96 | // tell the source to remove them from the list and free the mem |
---|
97 | |
---|
98 | void HostilRefManager::deleteReferences() |
---|
99 | { |
---|
100 | HostilReference* ref = getFirst(); |
---|
101 | while(ref) |
---|
102 | { |
---|
103 | HostilReference* nextRef = ref->next(); |
---|
104 | ref->removeReference(); |
---|
105 | delete ref; |
---|
106 | ref = nextRef; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | //================================================= |
---|
111 | // delete one reference, defined by Unit |
---|
112 | |
---|
113 | void HostilRefManager::deleteReference(Unit *pCreature) |
---|
114 | { |
---|
115 | HostilReference* ref = getFirst(); |
---|
116 | while(ref) |
---|
117 | { |
---|
118 | HostilReference* nextRef = ref->next(); |
---|
119 | if(ref->getSource()->getOwner() == pCreature) |
---|
120 | { |
---|
121 | ref->removeReference(); |
---|
122 | delete ref; |
---|
123 | break; |
---|
124 | } |
---|
125 | ref = nextRef; |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | //================================================= |
---|
130 | // set state for one reference, defined by Unit |
---|
131 | |
---|
132 | void HostilRefManager::setOnlineOfflineState(Unit *pCreature,bool pIsOnline) |
---|
133 | { |
---|
134 | HostilReference* ref = getFirst(); |
---|
135 | while(ref) |
---|
136 | { |
---|
137 | HostilReference* nextRef = ref->next(); |
---|
138 | if(ref->getSource()->getOwner() == pCreature) |
---|
139 | { |
---|
140 | ref->setOnlineOfflineState(pIsOnline); |
---|
141 | break; |
---|
142 | } |
---|
143 | ref = nextRef; |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | //================================================= |
---|