1 | /* |
---|
2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
3 | * |
---|
4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #include "Common.h" |
---|
22 | #include "Database/DatabaseEnv.h" |
---|
23 | #include "WorldPacket.h" |
---|
24 | #include "WorldSession.h" |
---|
25 | #include "GridNotifiers.h" |
---|
26 | #include "GridNotifiersImpl.h" |
---|
27 | #include "Opcodes.h" |
---|
28 | #include "Log.h" |
---|
29 | #include "UpdateMask.h" |
---|
30 | #include "World.h" |
---|
31 | #include "ObjectMgr.h" |
---|
32 | #include "SpellMgr.h" |
---|
33 | #include "Player.h" |
---|
34 | #include "Pet.h" |
---|
35 | #include "Unit.h" |
---|
36 | #include "Spell.h" |
---|
37 | #include "DynamicObject.h" |
---|
38 | #include "SpellAuras.h" |
---|
39 | #include "Group.h" |
---|
40 | #include "UpdateData.h" |
---|
41 | #include "MapManager.h" |
---|
42 | #include "ObjectAccessor.h" |
---|
43 | #include "CellImpl.h" |
---|
44 | #include "Policies/SingletonImp.h" |
---|
45 | #include "SharedDefines.h" |
---|
46 | #include "Tools.h" |
---|
47 | #include "LootMgr.h" |
---|
48 | #include "VMapFactory.h" |
---|
49 | #include "BattleGround.h" |
---|
50 | #include "Util.h" |
---|
51 | |
---|
52 | #define SPELL_CHANNEL_UPDATE_INTERVAL 1000 |
---|
53 | |
---|
54 | extern pEffect SpellEffects[TOTAL_SPELL_EFFECTS]; |
---|
55 | |
---|
56 | bool IsQuestTameSpell(uint32 spellId) |
---|
57 | { |
---|
58 | SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId); |
---|
59 | if (!spellproto) return false; |
---|
60 | |
---|
61 | return spellproto->Effect[0] == SPELL_EFFECT_THREAT |
---|
62 | && spellproto->Effect[1] == SPELL_EFFECT_APPLY_AURA && spellproto->EffectApplyAuraName[1] == SPELL_AURA_DUMMY; |
---|
63 | } |
---|
64 | |
---|
65 | SpellCastTargets::SpellCastTargets() |
---|
66 | { |
---|
67 | m_unitTarget = NULL; |
---|
68 | m_itemTarget = NULL; |
---|
69 | m_GOTarget = NULL; |
---|
70 | |
---|
71 | m_unitTargetGUID = 0; |
---|
72 | m_GOTargetGUID = 0; |
---|
73 | m_CorpseTargetGUID = 0; |
---|
74 | m_itemTargetGUID = 0; |
---|
75 | m_itemTargetEntry = 0; |
---|
76 | |
---|
77 | m_srcX = m_srcY = m_srcZ = m_destX = m_destY = m_destZ = 0; |
---|
78 | m_strTarget = ""; |
---|
79 | m_targetMask = 0; |
---|
80 | } |
---|
81 | |
---|
82 | SpellCastTargets::~SpellCastTargets() |
---|
83 | { |
---|
84 | } |
---|
85 | |
---|
86 | void SpellCastTargets::setUnitTarget(Unit *target) |
---|
87 | { |
---|
88 | if (!target) |
---|
89 | return; |
---|
90 | |
---|
91 | m_destX = target->GetPositionX(); |
---|
92 | m_destY = target->GetPositionY(); |
---|
93 | m_destZ = target->GetPositionZ(); |
---|
94 | m_unitTarget = target; |
---|
95 | m_unitTargetGUID = target->GetGUID(); |
---|
96 | m_targetMask |= TARGET_FLAG_UNIT; |
---|
97 | } |
---|
98 | |
---|
99 | void SpellCastTargets::setDestination(float x, float y, float z) |
---|
100 | { |
---|
101 | m_destX = x; |
---|
102 | m_destY = y; |
---|
103 | m_destZ = z; |
---|
104 | m_targetMask |= TARGET_FLAG_DEST_LOCATION; |
---|
105 | } |
---|
106 | |
---|
107 | void SpellCastTargets::setGOTarget(GameObject *target) |
---|
108 | { |
---|
109 | m_GOTarget = target; |
---|
110 | m_GOTargetGUID = target->GetGUID(); |
---|
111 | // m_targetMask |= TARGET_FLAG_OBJECT; |
---|
112 | } |
---|
113 | |
---|
114 | void SpellCastTargets::setItemTarget(Item* item) |
---|
115 | { |
---|
116 | if(!item) |
---|
117 | return; |
---|
118 | |
---|
119 | m_itemTarget = item; |
---|
120 | m_itemTargetGUID = item->GetGUID(); |
---|
121 | m_itemTargetEntry = item->GetEntry(); |
---|
122 | m_targetMask |= TARGET_FLAG_ITEM; |
---|
123 | } |
---|
124 | |
---|
125 | void SpellCastTargets::setCorpseTarget(Corpse* corpse) |
---|
126 | { |
---|
127 | m_CorpseTargetGUID = corpse->GetGUID(); |
---|
128 | } |
---|
129 | |
---|
130 | void SpellCastTargets::Update(Unit* caster) |
---|
131 | { |
---|
132 | m_GOTarget = m_GOTargetGUID ? ObjectAccessor::GetGameObject(*caster,m_GOTargetGUID) : NULL; |
---|
133 | m_unitTarget = m_unitTargetGUID ? |
---|
134 | ( m_unitTargetGUID==caster->GetGUID() ? caster : ObjectAccessor::GetUnit(*caster, m_unitTargetGUID) ) : |
---|
135 | NULL; |
---|
136 | |
---|
137 | m_itemTarget = NULL; |
---|
138 | if(caster->GetTypeId()==TYPEID_PLAYER) |
---|
139 | { |
---|
140 | if(m_targetMask & TARGET_FLAG_ITEM) |
---|
141 | m_itemTarget = ((Player*)caster)->GetItemByGuid(m_itemTargetGUID); |
---|
142 | else |
---|
143 | { |
---|
144 | Player* pTrader = ((Player*)caster)->GetTrader(); |
---|
145 | if(pTrader && m_itemTargetGUID < TRADE_SLOT_COUNT) |
---|
146 | m_itemTarget = pTrader->GetItemByPos(pTrader->GetItemPosByTradeSlot(m_itemTargetGUID)); |
---|
147 | } |
---|
148 | if(m_itemTarget) |
---|
149 | m_itemTargetEntry = m_itemTarget->GetEntry(); |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | bool SpellCastTargets::read ( WorldPacket * data, Unit *caster ) |
---|
154 | { |
---|
155 | if(data->rpos()+4 > data->size()) |
---|
156 | return false; |
---|
157 | |
---|
158 | *data >> m_targetMask; |
---|
159 | |
---|
160 | if(m_targetMask == TARGET_FLAG_SELF) |
---|
161 | { |
---|
162 | m_destX = caster->GetPositionX(); |
---|
163 | m_destY = caster->GetPositionY(); |
---|
164 | m_destZ = caster->GetPositionZ(); |
---|
165 | m_unitTarget = caster; |
---|
166 | m_unitTargetGUID = caster->GetGUID(); |
---|
167 | return true; |
---|
168 | } |
---|
169 | // TARGET_FLAG_UNK2 is used for non-combat pets, maybe other? |
---|
170 | if( m_targetMask & (TARGET_FLAG_UNIT|TARGET_FLAG_UNK2) ) |
---|
171 | if(!readGUID(*data, m_unitTargetGUID)) |
---|
172 | return false; |
---|
173 | |
---|
174 | if( m_targetMask & ( TARGET_FLAG_OBJECT | TARGET_FLAG_OBJECT_UNK )) |
---|
175 | if(!readGUID(*data, m_GOTargetGUID)) |
---|
176 | return false; |
---|
177 | |
---|
178 | if(( m_targetMask & ( TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM )) && caster->GetTypeId() == TYPEID_PLAYER) |
---|
179 | if(!readGUID(*data, m_itemTargetGUID)) |
---|
180 | return false; |
---|
181 | |
---|
182 | if( m_targetMask & TARGET_FLAG_SOURCE_LOCATION ) |
---|
183 | { |
---|
184 | if(data->rpos()+4+4+4 > data->size()) |
---|
185 | return false; |
---|
186 | |
---|
187 | *data >> m_srcX >> m_srcY >> m_srcZ; |
---|
188 | if(!Trinity::IsValidMapCoord(m_srcX, m_srcY, m_srcZ)) |
---|
189 | return false; |
---|
190 | } |
---|
191 | |
---|
192 | if( m_targetMask & TARGET_FLAG_DEST_LOCATION ) |
---|
193 | { |
---|
194 | if(data->rpos()+4+4+4 > data->size()) |
---|
195 | return false; |
---|
196 | |
---|
197 | *data >> m_destX >> m_destY >> m_destZ; |
---|
198 | if(!Trinity::IsValidMapCoord(m_destX, m_destY, m_destZ)) |
---|
199 | return false; |
---|
200 | } |
---|
201 | |
---|
202 | if( m_targetMask & TARGET_FLAG_STRING ) |
---|
203 | { |
---|
204 | if(data->rpos()+1 > data->size()) |
---|
205 | return false; |
---|
206 | |
---|
207 | *data >> m_strTarget; |
---|
208 | } |
---|
209 | |
---|
210 | if( m_targetMask & (TARGET_FLAG_CORPSE | TARGET_FLAG_PVP_CORPSE ) ) |
---|
211 | if(!readGUID(*data, m_CorpseTargetGUID)) |
---|
212 | return false; |
---|
213 | |
---|
214 | // find real units/GOs |
---|
215 | Update(caster); |
---|
216 | return true; |
---|
217 | } |
---|
218 | |
---|
219 | void SpellCastTargets::write ( WorldPacket * data ) |
---|
220 | { |
---|
221 | *data << uint32(m_targetMask); |
---|
222 | |
---|
223 | if( m_targetMask & ( TARGET_FLAG_UNIT | TARGET_FLAG_PVP_CORPSE | TARGET_FLAG_OBJECT | TARGET_FLAG_CORPSE | TARGET_FLAG_UNK2 ) ) |
---|
224 | { |
---|
225 | if(m_targetMask & TARGET_FLAG_UNIT) |
---|
226 | { |
---|
227 | if(m_unitTarget) |
---|
228 | data->append(m_unitTarget->GetPackGUID()); |
---|
229 | else |
---|
230 | *data << uint8(0); |
---|
231 | } |
---|
232 | else if( m_targetMask & ( TARGET_FLAG_OBJECT | TARGET_FLAG_OBJECT_UNK ) ) |
---|
233 | { |
---|
234 | if(m_GOTarget) |
---|
235 | data->append(m_GOTarget->GetPackGUID()); |
---|
236 | else |
---|
237 | *data << uint8(0); |
---|
238 | } |
---|
239 | else if( m_targetMask & ( TARGET_FLAG_CORPSE | TARGET_FLAG_PVP_CORPSE ) ) |
---|
240 | data->appendPackGUID(m_CorpseTargetGUID); |
---|
241 | else |
---|
242 | *data << uint8(0); |
---|
243 | } |
---|
244 | |
---|
245 | if( m_targetMask & ( TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM ) ) |
---|
246 | { |
---|
247 | if(m_itemTarget) |
---|
248 | data->append(m_itemTarget->GetPackGUID()); |
---|
249 | else |
---|
250 | *data << uint8(0); |
---|
251 | } |
---|
252 | |
---|
253 | if( m_targetMask & TARGET_FLAG_SOURCE_LOCATION ) |
---|
254 | *data << m_srcX << m_srcY << m_srcZ; |
---|
255 | |
---|
256 | if( m_targetMask & TARGET_FLAG_DEST_LOCATION ) |
---|
257 | *data << m_destX << m_destY << m_destZ; |
---|
258 | |
---|
259 | if( m_targetMask & TARGET_FLAG_STRING ) |
---|
260 | *data << m_strTarget; |
---|
261 | } |
---|
262 | |
---|
263 | Spell::Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID, Spell** triggeringContainer ) |
---|
264 | { |
---|
265 | ASSERT( Caster != NULL && info != NULL ); |
---|
266 | ASSERT( info == sSpellStore.LookupEntry( info->Id ) && "`info` must be pointer to sSpellStore element"); |
---|
267 | |
---|
268 | m_spellInfo = info; |
---|
269 | m_caster = Caster; |
---|
270 | m_selfContainer = NULL; |
---|
271 | m_triggeringContainer = triggeringContainer; |
---|
272 | m_magnetPair.first = false; |
---|
273 | m_magnetPair.second = NULL; |
---|
274 | m_deletable = true; |
---|
275 | m_delayAtDamageCount = 0; |
---|
276 | |
---|
277 | m_applyMultiplierMask = 0; |
---|
278 | |
---|
279 | // Get data for type of attack |
---|
280 | switch (m_spellInfo->DmgClass) |
---|
281 | { |
---|
282 | case SPELL_DAMAGE_CLASS_MELEE: |
---|
283 | if (m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_REQ_OFFHAND) |
---|
284 | m_attackType = OFF_ATTACK; |
---|
285 | else |
---|
286 | m_attackType = BASE_ATTACK; |
---|
287 | break; |
---|
288 | case SPELL_DAMAGE_CLASS_RANGED: |
---|
289 | m_attackType = RANGED_ATTACK; |
---|
290 | break; |
---|
291 | default: |
---|
292 | // Wands |
---|
293 | if (m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_REQ_WAND) |
---|
294 | m_attackType = RANGED_ATTACK; |
---|
295 | else |
---|
296 | m_attackType = BASE_ATTACK; |
---|
297 | break; |
---|
298 | } |
---|
299 | |
---|
300 | m_spellSchoolMask = GetSpellSchoolMask(info); // Can be override for some spell (wand shoot for example) |
---|
301 | |
---|
302 | if(m_attackType == RANGED_ATTACK) |
---|
303 | { |
---|
304 | // wand case |
---|
305 | if((m_caster->getClassMask() & CLASSMASK_WAND_USERS) != 0 && m_caster->GetTypeId()==TYPEID_PLAYER) |
---|
306 | { |
---|
307 | if(Item* pItem = ((Player*)m_caster)->GetWeaponForAttack(RANGED_ATTACK)) |
---|
308 | m_spellSchoolMask = SpellSchoolMask(1 << pItem->GetProto()->Damage->DamageType); |
---|
309 | } |
---|
310 | } |
---|
311 | |
---|
312 | if(originalCasterGUID) |
---|
313 | m_originalCasterGUID = originalCasterGUID; |
---|
314 | else |
---|
315 | m_originalCasterGUID = m_caster->GetGUID(); |
---|
316 | |
---|
317 | if(m_originalCasterGUID==m_caster->GetGUID()) |
---|
318 | m_originalCaster = m_caster; |
---|
319 | else |
---|
320 | { |
---|
321 | m_originalCaster = ObjectAccessor::GetUnit(*m_caster,m_originalCasterGUID); |
---|
322 | if(m_originalCaster && !m_originalCaster->IsInWorld()) m_originalCaster = NULL; |
---|
323 | } |
---|
324 | |
---|
325 | for(int i=0; i <3; ++i) |
---|
326 | m_currentBasePoints[i] = m_spellInfo->EffectBasePoints[i]; |
---|
327 | |
---|
328 | m_spellState = SPELL_STATE_NULL; |
---|
329 | |
---|
330 | m_castPositionX = m_castPositionY = m_castPositionZ = 0; |
---|
331 | m_TriggerSpells.clear(); |
---|
332 | m_IsTriggeredSpell = triggered; |
---|
333 | //m_AreaAura = false; |
---|
334 | m_CastItem = NULL; |
---|
335 | |
---|
336 | unitTarget = NULL; |
---|
337 | itemTarget = NULL; |
---|
338 | gameObjTarget = NULL; |
---|
339 | focusObject = NULL; |
---|
340 | m_cast_count = 0; |
---|
341 | m_triggeredByAuraSpell = NULL; |
---|
342 | |
---|
343 | //Auto Shot & Shoot |
---|
344 | if( m_spellInfo->AttributesEx2 == 0x000020 && !triggered ) |
---|
345 | m_autoRepeat = true; |
---|
346 | else |
---|
347 | m_autoRepeat = false; |
---|
348 | |
---|
349 | m_powerCost = 0; // setup to correct value in Spell::prepare, don't must be used before. |
---|
350 | m_casttime = 0; // setup to correct value in Spell::prepare, don't must be used before. |
---|
351 | m_timer = 0; // will set to castime in preper |
---|
352 | |
---|
353 | m_needAliveTargetMask = 0; |
---|
354 | |
---|
355 | // determine reflection |
---|
356 | m_canReflect = false; |
---|
357 | |
---|
358 | if(m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC && (m_spellInfo->AttributesEx2 & 0x4)==0) |
---|
359 | { |
---|
360 | for(int j=0;j<3;j++) |
---|
361 | { |
---|
362 | if (m_spellInfo->Effect[j]==0) |
---|
363 | continue; |
---|
364 | |
---|
365 | if(!IsPositiveTarget(m_spellInfo->EffectImplicitTargetA[j],m_spellInfo->EffectImplicitTargetB[j])) |
---|
366 | m_canReflect = true; |
---|
367 | else |
---|
368 | m_canReflect = (m_spellInfo->AttributesEx & (1<<7)) ? true : false; |
---|
369 | |
---|
370 | if(m_canReflect) |
---|
371 | continue; |
---|
372 | else |
---|
373 | break; |
---|
374 | } |
---|
375 | } |
---|
376 | |
---|
377 | CleanupTargetList(); |
---|
378 | } |
---|
379 | |
---|
380 | Spell::~Spell() |
---|
381 | { |
---|
382 | } |
---|
383 | |
---|
384 | void Spell::FillTargetMap() |
---|
385 | { |
---|
386 | // TODO: ADD the correct target FILLS!!!!!! |
---|
387 | |
---|
388 | for(uint32 i=0;i<3;i++) |
---|
389 | { |
---|
390 | // not call for empty effect. |
---|
391 | // Also some spells use not used effect targets for store targets for dummy effect in triggered spells |
---|
392 | if(m_spellInfo->Effect[i]==0) |
---|
393 | continue; |
---|
394 | |
---|
395 | // targets for TARGET_SCRIPT_COORDINATES (A) and TARGET_SCRIPT filled in Spell::canCast call |
---|
396 | if( m_spellInfo->EffectImplicitTargetA[i] == TARGET_SCRIPT_COORDINATES || |
---|
397 | m_spellInfo->EffectImplicitTargetA[i] == TARGET_SCRIPT || |
---|
398 | m_spellInfo->EffectImplicitTargetB[i] == TARGET_SCRIPT && m_spellInfo->EffectImplicitTargetA[i] != TARGET_SELF ) |
---|
399 | continue; |
---|
400 | |
---|
401 | // TODO: find a way so this is not needed? |
---|
402 | // for area auras always add caster as target (needed for totems for example) |
---|
403 | if(IsAreaAuraEffect(m_spellInfo->Effect[i])) |
---|
404 | AddUnitTarget(m_caster, i); |
---|
405 | |
---|
406 | std::list<Unit*> tmpUnitMap; |
---|
407 | |
---|
408 | // TargetA/TargetB dependent from each other, we not switch to full support this dependences |
---|
409 | // but need it support in some know cases |
---|
410 | switch(m_spellInfo->EffectImplicitTargetA[i]) |
---|
411 | { |
---|
412 | case TARGET_ALL_AROUND_CASTER: |
---|
413 | if( m_spellInfo->EffectImplicitTargetB[i]==TARGET_ALL_PARTY || |
---|
414 | m_spellInfo->EffectImplicitTargetB[i]==TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER || |
---|
415 | m_spellInfo->EffectImplicitTargetB[i]==TARGET_RANDOM_RAID_MEMBER ) |
---|
416 | { |
---|
417 | SetTargetMap(i,m_spellInfo->EffectImplicitTargetB[i],tmpUnitMap); |
---|
418 | } |
---|
419 | // Note: this hack with search required until GO casting not implemented |
---|
420 | // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support |
---|
421 | // currently each enemy selected explicitly and self cast damage |
---|
422 | else if(m_spellInfo->EffectImplicitTargetB[i]==TARGET_ALL_ENEMY_IN_AREA && m_spellInfo->Effect[i]==SPELL_EFFECT_ENVIRONMENTAL_DAMAGE) |
---|
423 | { |
---|
424 | if(m_targets.getUnitTarget()) |
---|
425 | tmpUnitMap.push_back(m_targets.getUnitTarget()); |
---|
426 | } |
---|
427 | else |
---|
428 | { |
---|
429 | SetTargetMap(i,m_spellInfo->EffectImplicitTargetA[i],tmpUnitMap); |
---|
430 | SetTargetMap(i,m_spellInfo->EffectImplicitTargetB[i],tmpUnitMap); |
---|
431 | } |
---|
432 | break; |
---|
433 | case TARGET_TABLE_X_Y_Z_COORDINATES: |
---|
434 | // Only if target A, for target B (used in teleports) dest select in effect |
---|
435 | SetTargetMap(i,m_spellInfo->EffectImplicitTargetA[i],tmpUnitMap); |
---|
436 | break; |
---|
437 | default: |
---|
438 | switch(m_spellInfo->EffectImplicitTargetB[i]) |
---|
439 | { |
---|
440 | case TARGET_SCRIPT_COORDINATES: // B case filled in canCast but we need fill unit list base at A case |
---|
441 | SetTargetMap(i,m_spellInfo->EffectImplicitTargetA[i],tmpUnitMap); |
---|
442 | break; |
---|
443 | default: |
---|
444 | SetTargetMap(i,m_spellInfo->EffectImplicitTargetA[i],tmpUnitMap); |
---|
445 | SetTargetMap(i,m_spellInfo->EffectImplicitTargetB[i],tmpUnitMap); |
---|
446 | break; |
---|
447 | } |
---|
448 | break; |
---|
449 | } |
---|
450 | |
---|
451 | if( (m_spellInfo->EffectImplicitTargetA[i]==0 || m_spellInfo->EffectImplicitTargetA[i]==TARGET_EFFECT_SELECT) && |
---|
452 | (m_spellInfo->EffectImplicitTargetB[i]==0 || m_spellInfo->EffectImplicitTargetB[i]==TARGET_EFFECT_SELECT) ) |
---|
453 | { |
---|
454 | // add here custom effects that need default target. |
---|
455 | // FOR EVERY TARGET TYPE THERE IS A DIFFERENT FILL!! |
---|
456 | switch(m_spellInfo->Effect[i]) |
---|
457 | { |
---|
458 | case SPELL_EFFECT_DUMMY: |
---|
459 | { |
---|
460 | switch(m_spellInfo->Id) |
---|
461 | { |
---|
462 | case 20577: // Cannibalize |
---|
463 | { |
---|
464 | // non-standard target selection |
---|
465 | SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex); |
---|
466 | float max_range = GetSpellMaxRange(srange); |
---|
467 | |
---|
468 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
469 | Cell cell(p); |
---|
470 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
471 | cell.SetNoCreate(); |
---|
472 | |
---|
473 | WorldObject* result = NULL; |
---|
474 | |
---|
475 | Trinity::CannibalizeObjectCheck u_check(m_caster, max_range); |
---|
476 | Trinity::WorldObjectSearcher<Trinity::CannibalizeObjectCheck > searcher(result, u_check); |
---|
477 | |
---|
478 | TypeContainerVisitor<Trinity::WorldObjectSearcher<Trinity::CannibalizeObjectCheck >, GridTypeMapContainer > grid_searcher(searcher); |
---|
479 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
480 | cell_lock->Visit(cell_lock, grid_searcher, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
481 | |
---|
482 | if(!result) |
---|
483 | { |
---|
484 | TypeContainerVisitor<Trinity::WorldObjectSearcher<Trinity::CannibalizeObjectCheck >, WorldTypeMapContainer > world_searcher(searcher); |
---|
485 | cell_lock->Visit(cell_lock, world_searcher, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
486 | } |
---|
487 | |
---|
488 | if(result) |
---|
489 | { |
---|
490 | switch(result->GetTypeId()) |
---|
491 | { |
---|
492 | case TYPEID_UNIT: |
---|
493 | case TYPEID_PLAYER: |
---|
494 | tmpUnitMap.push_back((Unit*)result); |
---|
495 | break; |
---|
496 | case TYPEID_CORPSE: |
---|
497 | m_targets.setCorpseTarget((Corpse*)result); |
---|
498 | if(Player* owner = ObjectAccessor::FindPlayer(((Corpse*)result)->GetOwnerGUID())) |
---|
499 | tmpUnitMap.push_back(owner); |
---|
500 | break; |
---|
501 | } |
---|
502 | } |
---|
503 | else |
---|
504 | { |
---|
505 | // clear cooldown at fail |
---|
506 | if(m_caster->GetTypeId()==TYPEID_PLAYER) |
---|
507 | { |
---|
508 | ((Player*)m_caster)->RemoveSpellCooldown(m_spellInfo->Id); |
---|
509 | |
---|
510 | WorldPacket data(SMSG_CLEAR_COOLDOWN, (4+8)); |
---|
511 | data << uint32(m_spellInfo->Id); |
---|
512 | data << uint64(m_caster->GetGUID()); |
---|
513 | ((Player*)m_caster)->GetSession()->SendPacket(&data); |
---|
514 | } |
---|
515 | |
---|
516 | SendCastResult(SPELL_FAILED_NO_EDIBLE_CORPSES); |
---|
517 | finish(false); |
---|
518 | } |
---|
519 | break; |
---|
520 | } |
---|
521 | default: |
---|
522 | if(m_targets.getUnitTarget()) |
---|
523 | tmpUnitMap.push_back(m_targets.getUnitTarget()); |
---|
524 | break; |
---|
525 | } |
---|
526 | break; |
---|
527 | } |
---|
528 | case SPELL_EFFECT_RESURRECT: |
---|
529 | case SPELL_EFFECT_PARRY: |
---|
530 | case SPELL_EFFECT_BLOCK: |
---|
531 | case SPELL_EFFECT_CREATE_ITEM: |
---|
532 | case SPELL_EFFECT_TRIGGER_SPELL: |
---|
533 | case SPELL_EFFECT_TRIGGER_MISSILE: |
---|
534 | case SPELL_EFFECT_LEARN_SPELL: |
---|
535 | case SPELL_EFFECT_SKILL_STEP: |
---|
536 | case SPELL_EFFECT_PROFICIENCY: |
---|
537 | case SPELL_EFFECT_SUMMON_POSSESSED: |
---|
538 | case SPELL_EFFECT_SUMMON_OBJECT_WILD: |
---|
539 | case SPELL_EFFECT_SELF_RESURRECT: |
---|
540 | case SPELL_EFFECT_REPUTATION: |
---|
541 | if(m_targets.getUnitTarget()) |
---|
542 | tmpUnitMap.push_back(m_targets.getUnitTarget()); |
---|
543 | break; |
---|
544 | case SPELL_EFFECT_SUMMON_PLAYER: |
---|
545 | if(m_caster->GetTypeId()==TYPEID_PLAYER && ((Player*)m_caster)->GetSelection()) |
---|
546 | { |
---|
547 | Player* target = objmgr.GetPlayer(((Player*)m_caster)->GetSelection()); |
---|
548 | if(target) |
---|
549 | tmpUnitMap.push_back(target); |
---|
550 | } |
---|
551 | break; |
---|
552 | case SPELL_EFFECT_RESURRECT_NEW: |
---|
553 | if(m_targets.getUnitTarget()) |
---|
554 | tmpUnitMap.push_back(m_targets.getUnitTarget()); |
---|
555 | if(m_targets.getCorpseTargetGUID()) |
---|
556 | { |
---|
557 | Corpse *corpse = ObjectAccessor::GetCorpse(*m_caster,m_targets.getCorpseTargetGUID()); |
---|
558 | if(corpse) |
---|
559 | { |
---|
560 | Player* owner = ObjectAccessor::FindPlayer(corpse->GetOwnerGUID()); |
---|
561 | if(owner) |
---|
562 | tmpUnitMap.push_back(owner); |
---|
563 | } |
---|
564 | } |
---|
565 | break; |
---|
566 | case SPELL_EFFECT_SUMMON: |
---|
567 | if(m_spellInfo->EffectMiscValueB[i] == SUMMON_TYPE_POSESSED || m_spellInfo->EffectMiscValueB[i] == SUMMON_TYPE_POSESSED2) |
---|
568 | { |
---|
569 | if(m_targets.getUnitTarget()) |
---|
570 | tmpUnitMap.push_back(m_targets.getUnitTarget()); |
---|
571 | } |
---|
572 | else |
---|
573 | tmpUnitMap.push_back(m_caster); |
---|
574 | break; |
---|
575 | case SPELL_EFFECT_SUMMON_CHANGE_ITEM: |
---|
576 | case SPELL_EFFECT_SUMMON_WILD: |
---|
577 | case SPELL_EFFECT_SUMMON_GUARDIAN: |
---|
578 | case SPELL_EFFECT_TRANS_DOOR: |
---|
579 | case SPELL_EFFECT_ADD_FARSIGHT: |
---|
580 | case SPELL_EFFECT_STUCK: |
---|
581 | case SPELL_EFFECT_DESTROY_ALL_TOTEMS: |
---|
582 | case SPELL_EFFECT_SUMMON_DEMON: |
---|
583 | case SPELL_EFFECT_SKILL: |
---|
584 | tmpUnitMap.push_back(m_caster); |
---|
585 | break; |
---|
586 | case SPELL_EFFECT_LEARN_PET_SPELL: |
---|
587 | if(Pet* pet = m_caster->GetPet()) |
---|
588 | tmpUnitMap.push_back(pet); |
---|
589 | break; |
---|
590 | case SPELL_EFFECT_ENCHANT_ITEM: |
---|
591 | case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY: |
---|
592 | case SPELL_EFFECT_DISENCHANT: |
---|
593 | case SPELL_EFFECT_FEED_PET: |
---|
594 | case SPELL_EFFECT_PROSPECTING: |
---|
595 | if(m_targets.getItemTarget()) |
---|
596 | AddItemTarget(m_targets.getItemTarget(), i); |
---|
597 | break; |
---|
598 | case SPELL_EFFECT_APPLY_AURA: |
---|
599 | switch(m_spellInfo->EffectApplyAuraName[i]) |
---|
600 | { |
---|
601 | case SPELL_AURA_ADD_FLAT_MODIFIER: // some spell mods auras have 0 target modes instead expected TARGET_SELF(1) (and present for other ranks for same spell for example) |
---|
602 | case SPELL_AURA_ADD_PCT_MODIFIER: |
---|
603 | tmpUnitMap.push_back(m_caster); |
---|
604 | break; |
---|
605 | default: // apply to target in other case |
---|
606 | if(m_targets.getUnitTarget()) |
---|
607 | tmpUnitMap.push_back(m_targets.getUnitTarget()); |
---|
608 | break; |
---|
609 | } |
---|
610 | break; |
---|
611 | case SPELL_EFFECT_APPLY_AREA_AURA_PARTY: |
---|
612 | // AreaAura |
---|
613 | if(m_spellInfo->Attributes == 0x9050000 || m_spellInfo->Attributes == 0x10000) |
---|
614 | SetTargetMap(i,TARGET_AREAEFFECT_PARTY,tmpUnitMap); |
---|
615 | break; |
---|
616 | case SPELL_EFFECT_SKIN_PLAYER_CORPSE: |
---|
617 | if(m_targets.getUnitTarget()) |
---|
618 | { |
---|
619 | tmpUnitMap.push_back(m_targets.getUnitTarget()); |
---|
620 | } |
---|
621 | else if (m_targets.getCorpseTargetGUID()) |
---|
622 | { |
---|
623 | Corpse *corpse = ObjectAccessor::GetCorpse(*m_caster,m_targets.getCorpseTargetGUID()); |
---|
624 | if(corpse) |
---|
625 | { |
---|
626 | Player* owner = ObjectAccessor::FindPlayer(corpse->GetOwnerGUID()); |
---|
627 | if(owner) |
---|
628 | tmpUnitMap.push_back(owner); |
---|
629 | } |
---|
630 | } |
---|
631 | break; |
---|
632 | default: |
---|
633 | break; |
---|
634 | } |
---|
635 | } |
---|
636 | if(IsChanneledSpell(m_spellInfo) && !tmpUnitMap.empty()) |
---|
637 | m_needAliveTargetMask |= (1<<i); |
---|
638 | |
---|
639 | if(m_caster->GetTypeId() == TYPEID_PLAYER) |
---|
640 | { |
---|
641 | Player *me = (Player*)m_caster; |
---|
642 | for (std::list<Unit*>::const_iterator itr = tmpUnitMap.begin(); itr != tmpUnitMap.end(); itr++) |
---|
643 | { |
---|
644 | Unit *owner = (*itr)->GetOwner(); |
---|
645 | Unit *u = owner ? owner : (*itr); |
---|
646 | if(u!=m_caster && u->IsPvP() && (!me->duel || me->duel->opponent != u)) |
---|
647 | { |
---|
648 | me->UpdatePvP(true); |
---|
649 | me->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT); |
---|
650 | break; |
---|
651 | } |
---|
652 | } |
---|
653 | } |
---|
654 | |
---|
655 | for (std::list<Unit*>::iterator itr = tmpUnitMap.begin() ; itr != tmpUnitMap.end();) |
---|
656 | { |
---|
657 | if(!CheckTarget(*itr, i, false )) |
---|
658 | { |
---|
659 | itr = tmpUnitMap.erase(itr); |
---|
660 | continue; |
---|
661 | } |
---|
662 | else |
---|
663 | ++itr; |
---|
664 | } |
---|
665 | |
---|
666 | for(std::list<Unit*>::iterator iunit= tmpUnitMap.begin();iunit != tmpUnitMap.end();++iunit) |
---|
667 | AddUnitTarget((*iunit), i); |
---|
668 | } |
---|
669 | } |
---|
670 | |
---|
671 | void Spell::CleanupTargetList() |
---|
672 | { |
---|
673 | m_UniqueTargetInfo.clear(); |
---|
674 | m_UniqueGOTargetInfo.clear(); |
---|
675 | m_UniqueItemInfo.clear(); |
---|
676 | m_countOfHit = 0; |
---|
677 | m_countOfMiss = 0; |
---|
678 | m_delayMoment = 0; |
---|
679 | } |
---|
680 | |
---|
681 | void Spell::AddUnitTarget(Unit* pVictim, uint32 effIndex) |
---|
682 | { |
---|
683 | if( m_spellInfo->Effect[effIndex]==0 ) |
---|
684 | return; |
---|
685 | |
---|
686 | uint64 targetGUID = pVictim->GetGUID(); |
---|
687 | |
---|
688 | // Lookup target in already in list |
---|
689 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit) |
---|
690 | { |
---|
691 | if (targetGUID == ihit->targetGUID) // Found in list |
---|
692 | { |
---|
693 | ihit->effectMask |= 1<<effIndex; // Add only effect mask |
---|
694 | return; |
---|
695 | } |
---|
696 | } |
---|
697 | |
---|
698 | // This is new target calculate data for him |
---|
699 | |
---|
700 | // Get spell hit result on target |
---|
701 | TargetInfo target; |
---|
702 | target.targetGUID = targetGUID; // Store target GUID |
---|
703 | target.effectMask = 1<<effIndex; // Store index of effect |
---|
704 | target.processed = false; // Effects not apply on target |
---|
705 | |
---|
706 | // Calculate hit result |
---|
707 | target.missCondition = m_caster->SpellHitResult(pVictim, m_spellInfo, m_canReflect); |
---|
708 | if (target.missCondition == SPELL_MISS_NONE) |
---|
709 | ++m_countOfHit; |
---|
710 | else |
---|
711 | ++m_countOfMiss; |
---|
712 | |
---|
713 | // Spell have speed - need calculate incoming time |
---|
714 | if (m_spellInfo->speed > 0.0f) |
---|
715 | { |
---|
716 | // calculate spell incoming interval |
---|
717 | float dist = m_caster->GetDistance(pVictim->GetPositionX(), pVictim->GetPositionY(), pVictim->GetPositionZ()); |
---|
718 | if (dist < 5.0f) dist = 5.0f; |
---|
719 | target.timeDelay = (uint64) floor(dist / m_spellInfo->speed * 1000.0f); |
---|
720 | |
---|
721 | // Calculate minimum incoming time |
---|
722 | if (m_delayMoment==0 || m_delayMoment>target.timeDelay) |
---|
723 | m_delayMoment = target.timeDelay; |
---|
724 | } |
---|
725 | else |
---|
726 | target.timeDelay = 0LL; |
---|
727 | |
---|
728 | // If target reflect spell back to caster |
---|
729 | if (target.missCondition==SPELL_MISS_REFLECT) |
---|
730 | { |
---|
731 | // Calculate reflected spell result on caster |
---|
732 | target.reflectResult = m_caster->SpellHitResult(m_caster, m_spellInfo, m_canReflect); |
---|
733 | |
---|
734 | if (target.reflectResult == SPELL_MISS_REFLECT) // Impossible reflect again, so simply deflect spell |
---|
735 | target.reflectResult = SPELL_MISS_PARRY; |
---|
736 | |
---|
737 | // Increase time interval for reflected spells by 1.5 |
---|
738 | target.timeDelay+=target.timeDelay>>1; |
---|
739 | } |
---|
740 | else |
---|
741 | target.reflectResult = SPELL_MISS_NONE; |
---|
742 | |
---|
743 | // Add target to list |
---|
744 | m_UniqueTargetInfo.push_back(target); |
---|
745 | } |
---|
746 | |
---|
747 | void Spell::AddUnitTarget(uint64 unitGUID, uint32 effIndex) |
---|
748 | { |
---|
749 | Unit* unit = m_caster->GetGUID()==unitGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, unitGUID); |
---|
750 | if (unit) |
---|
751 | AddUnitTarget(unit, effIndex); |
---|
752 | } |
---|
753 | |
---|
754 | void Spell::AddGOTarget(GameObject* pVictim, uint32 effIndex) |
---|
755 | { |
---|
756 | if( m_spellInfo->Effect[effIndex]==0 ) |
---|
757 | return; |
---|
758 | |
---|
759 | uint64 targetGUID = pVictim->GetGUID(); |
---|
760 | |
---|
761 | // Lookup target in already in list |
---|
762 | for(std::list<GOTargetInfo>::iterator ihit= m_UniqueGOTargetInfo.begin();ihit != m_UniqueGOTargetInfo.end();++ihit) |
---|
763 | { |
---|
764 | if (targetGUID == ihit->targetGUID) // Found in list |
---|
765 | { |
---|
766 | ihit->effectMask |= 1<<effIndex; // Add only effect mask |
---|
767 | return; |
---|
768 | } |
---|
769 | } |
---|
770 | |
---|
771 | // This is new target calculate data for him |
---|
772 | |
---|
773 | GOTargetInfo target; |
---|
774 | target.targetGUID = targetGUID; |
---|
775 | target.effectMask = 1<<effIndex; |
---|
776 | target.processed = false; // Effects not apply on target |
---|
777 | |
---|
778 | // Spell have speed - need calculate incoming time |
---|
779 | if (m_spellInfo->speed > 0.0f) |
---|
780 | { |
---|
781 | // calculate spell incoming interval |
---|
782 | float dist = m_caster->GetDistance(pVictim->GetPositionX(), pVictim->GetPositionY(), pVictim->GetPositionZ()); |
---|
783 | if (dist < 5.0f) dist = 5.0f; |
---|
784 | target.timeDelay = (uint64) floor(dist / m_spellInfo->speed * 1000.0f); |
---|
785 | if (m_delayMoment==0 || m_delayMoment>target.timeDelay) |
---|
786 | m_delayMoment = target.timeDelay; |
---|
787 | } |
---|
788 | else |
---|
789 | target.timeDelay = 0LL; |
---|
790 | |
---|
791 | ++m_countOfHit; |
---|
792 | |
---|
793 | // Add target to list |
---|
794 | m_UniqueGOTargetInfo.push_back(target); |
---|
795 | } |
---|
796 | |
---|
797 | void Spell::AddGOTarget(uint64 goGUID, uint32 effIndex) |
---|
798 | { |
---|
799 | GameObject* go = ObjectAccessor::GetGameObject(*m_caster, goGUID); |
---|
800 | if (go) |
---|
801 | AddGOTarget(go, effIndex); |
---|
802 | } |
---|
803 | |
---|
804 | void Spell::AddItemTarget(Item* pitem, uint32 effIndex) |
---|
805 | { |
---|
806 | if( m_spellInfo->Effect[effIndex]==0 ) |
---|
807 | return; |
---|
808 | |
---|
809 | // Lookup target in already in list |
---|
810 | for(std::list<ItemTargetInfo>::iterator ihit= m_UniqueItemInfo.begin();ihit != m_UniqueItemInfo.end();++ihit) |
---|
811 | { |
---|
812 | if (pitem == ihit->item) // Found in list |
---|
813 | { |
---|
814 | ihit->effectMask |= 1<<effIndex; // Add only effect mask |
---|
815 | return; |
---|
816 | } |
---|
817 | } |
---|
818 | |
---|
819 | // This is new target add data |
---|
820 | |
---|
821 | ItemTargetInfo target; |
---|
822 | target.item = pitem; |
---|
823 | target.effectMask = 1<<effIndex; |
---|
824 | m_UniqueItemInfo.push_back(target); |
---|
825 | } |
---|
826 | |
---|
827 | void Spell::doTriggers(SpellMissInfo missInfo, uint32 damage, SpellSchoolMask damageSchoolMask, uint32 block, uint32 absorb, bool crit) |
---|
828 | { |
---|
829 | // Do triggers depends from hit result (triggers on hit do in effects) |
---|
830 | // Set aura states depends from hit result |
---|
831 | if (missInfo!=SPELL_MISS_NONE) |
---|
832 | { |
---|
833 | // Miss/dodge/parry/block only for melee based spells |
---|
834 | // Resist only for magic based spells |
---|
835 | switch (missInfo) |
---|
836 | { |
---|
837 | case SPELL_MISS_MISS: |
---|
838 | if(m_caster->GetTypeId()== TYPEID_PLAYER) |
---|
839 | ((Player*)m_caster)->UpdateWeaponSkill(BASE_ATTACK); |
---|
840 | |
---|
841 | m_caster->CastMeleeProcDamageAndSpell(unitTarget, 0, damageSchoolMask, m_attackType, MELEE_HIT_MISS, m_spellInfo, m_IsTriggeredSpell); |
---|
842 | break; |
---|
843 | case SPELL_MISS_RESIST: |
---|
844 | m_caster->ProcDamageAndSpell(unitTarget, PROC_FLAG_TARGET_RESISTS, PROC_FLAG_RESIST_SPELL, 0, damageSchoolMask, m_spellInfo, m_IsTriggeredSpell); |
---|
845 | break; |
---|
846 | case SPELL_MISS_DODGE: |
---|
847 | if(unitTarget->GetTypeId() == TYPEID_PLAYER) |
---|
848 | ((Player*)unitTarget)->UpdateDefense(); |
---|
849 | |
---|
850 | // Overpower |
---|
851 | if (m_caster->GetTypeId() == TYPEID_PLAYER && m_caster->getClass() == CLASS_WARRIOR) |
---|
852 | { |
---|
853 | ((Player*) m_caster)->AddComboPoints(unitTarget, 1); |
---|
854 | m_caster->StartReactiveTimer( REACTIVE_OVERPOWER ); |
---|
855 | } |
---|
856 | |
---|
857 | // Riposte |
---|
858 | if (unitTarget->getClass() != CLASS_ROGUE) |
---|
859 | { |
---|
860 | unitTarget->ModifyAuraState(AURA_STATE_DEFENSE, true); |
---|
861 | unitTarget->StartReactiveTimer( REACTIVE_DEFENSE ); |
---|
862 | } |
---|
863 | |
---|
864 | m_caster->CastMeleeProcDamageAndSpell(unitTarget, 0, damageSchoolMask, m_attackType, MELEE_HIT_DODGE, m_spellInfo, m_IsTriggeredSpell); |
---|
865 | break; |
---|
866 | case SPELL_MISS_PARRY: |
---|
867 | // Update victim defense ? |
---|
868 | if(unitTarget->GetTypeId() == TYPEID_PLAYER) |
---|
869 | ((Player*)unitTarget)->UpdateDefense(); |
---|
870 | // Mongoose bite - set only Counterattack here |
---|
871 | if (unitTarget->getClass() == CLASS_HUNTER) |
---|
872 | { |
---|
873 | unitTarget->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true); |
---|
874 | unitTarget->StartReactiveTimer( REACTIVE_HUNTER_PARRY ); |
---|
875 | } |
---|
876 | else |
---|
877 | { |
---|
878 | unitTarget->ModifyAuraState(AURA_STATE_DEFENSE, true); |
---|
879 | unitTarget->StartReactiveTimer( REACTIVE_DEFENSE ); |
---|
880 | } |
---|
881 | m_caster->CastMeleeProcDamageAndSpell(unitTarget, 0, damageSchoolMask, m_attackType, MELEE_HIT_PARRY, m_spellInfo, m_IsTriggeredSpell); |
---|
882 | break; |
---|
883 | case SPELL_MISS_BLOCK: |
---|
884 | unitTarget->ModifyAuraState(AURA_STATE_DEFENSE, true); |
---|
885 | unitTarget->StartReactiveTimer( REACTIVE_DEFENSE ); |
---|
886 | |
---|
887 | m_caster->CastMeleeProcDamageAndSpell(unitTarget, 0, damageSchoolMask, m_attackType, MELEE_HIT_BLOCK, m_spellInfo, m_IsTriggeredSpell); |
---|
888 | break; |
---|
889 | // Trigger from this events not supported |
---|
890 | case SPELL_MISS_EVADE: |
---|
891 | case SPELL_MISS_IMMUNE: |
---|
892 | case SPELL_MISS_IMMUNE2: |
---|
893 | case SPELL_MISS_DEFLECT: |
---|
894 | case SPELL_MISS_ABSORB: |
---|
895 | // Trigger from reflects need do after get reflect result |
---|
896 | case SPELL_MISS_REFLECT: |
---|
897 | break; |
---|
898 | default: |
---|
899 | break; |
---|
900 | } |
---|
901 | } |
---|
902 | } |
---|
903 | |
---|
904 | void Spell::DoAllEffectOnTarget(TargetInfo *target) |
---|
905 | { |
---|
906 | if (target->processed) // Check target |
---|
907 | return; |
---|
908 | target->processed = true; // Target checked in apply effects procedure |
---|
909 | |
---|
910 | // Get mask of effects for target |
---|
911 | uint32 mask = target->effectMask; |
---|
912 | if (mask == 0) // No effects |
---|
913 | return; |
---|
914 | |
---|
915 | Unit* unit = m_caster->GetGUID()==target->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster,target->targetGUID); |
---|
916 | if (!unit) |
---|
917 | return; |
---|
918 | |
---|
919 | SpellMissInfo missInfo = target->missCondition; |
---|
920 | // Need init unitTarget by default unit (can changed in code on reflect) |
---|
921 | // Or on missInfo!=SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem) |
---|
922 | unitTarget = unit; |
---|
923 | |
---|
924 | if (missInfo==SPELL_MISS_NONE) // In case spell hit target, do all effect on that target |
---|
925 | DoSpellHitOnUnit(unit, mask); |
---|
926 | else if (missInfo == SPELL_MISS_REFLECT) // In case spell reflect from target, do all effect on caster (if hit) |
---|
927 | { |
---|
928 | if (target->reflectResult == SPELL_MISS_NONE) // If reflected spell hit caster -> do all effect on him |
---|
929 | DoSpellHitOnUnit(m_caster, mask); |
---|
930 | } |
---|
931 | |
---|
932 | // Do triggers only on miss/resist/parry/dodge |
---|
933 | if (missInfo!=SPELL_MISS_NONE) |
---|
934 | doTriggers(missInfo); |
---|
935 | |
---|
936 | // Call scripted function for AI if this spell is casted upon a creature (except pets) |
---|
937 | if(IS_CREATURE_GUID(target->targetGUID)) |
---|
938 | { |
---|
939 | // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished) |
---|
940 | // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... ) |
---|
941 | if( m_caster->GetTypeId() == TYPEID_PLAYER && !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() ) |
---|
942 | ((Player*)m_caster)->CastedCreatureOrGO(unit->GetEntry(),unit->GetGUID(),m_spellInfo->Id); |
---|
943 | |
---|
944 | if(((Creature*)unit)->AI()) |
---|
945 | ((Creature*)unit)->AI()->SpellHit(m_caster ,m_spellInfo); |
---|
946 | } |
---|
947 | |
---|
948 | if(m_caster->GetTypeId() == TYPEID_UNIT && ((Creature*)m_caster)->AI()) |
---|
949 | ((Creature*)m_caster)->AI()->SpellHitTarget(unit, m_spellInfo); |
---|
950 | } |
---|
951 | |
---|
952 | void Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask) |
---|
953 | { |
---|
954 | if(!unit || !effectMask) |
---|
955 | return; |
---|
956 | |
---|
957 | // remove spell_magnet aura after first spell redirect and destroy target if its totem |
---|
958 | if(m_magnetPair.first && m_magnetPair.second && m_magnetPair.second == unit) |
---|
959 | { |
---|
960 | if(unit->GetTypeId() == TYPEID_UNIT && ((Creature*)unit)->isTotem()) |
---|
961 | unit->DealDamage(unit,unit->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); |
---|
962 | return; |
---|
963 | } |
---|
964 | |
---|
965 | // Recheck immune (only for delayed spells) |
---|
966 | if( m_spellInfo->speed && ( |
---|
967 | unit->IsImmunedToDamage(GetSpellSchoolMask(m_spellInfo),true) || |
---|
968 | unit->IsImmunedToSpell(m_spellInfo,true) )) |
---|
969 | { |
---|
970 | m_caster->SendSpellMiss(unit, m_spellInfo->Id, SPELL_MISS_IMMUNE); |
---|
971 | return; |
---|
972 | } |
---|
973 | |
---|
974 | if( m_caster != unit ) |
---|
975 | { |
---|
976 | if( !m_caster->IsFriendlyTo(unit) ) |
---|
977 | { |
---|
978 | // for delayed spells ignore not visible explicit target |
---|
979 | if(m_spellInfo->speed > 0.0f && unit==m_targets.getUnitTarget() && !unit->isVisibleForOrDetect(m_caster,false)) |
---|
980 | { |
---|
981 | m_caster->SendSpellMiss(unit, m_spellInfo->Id, SPELL_MISS_EVADE); |
---|
982 | return; |
---|
983 | } |
---|
984 | |
---|
985 | // exclude Arcane Missiles Dummy Aura aura for now (attack on hit) |
---|
986 | // TODO: find way to not need this? |
---|
987 | if(!(m_spellInfo->SpellFamilyName == SPELLFAMILY_MAGE && |
---|
988 | m_spellInfo->SpellFamilyFlags & 0x800LL)) |
---|
989 | { |
---|
990 | unit->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); |
---|
991 | |
---|
992 | if( !(m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_NO_INITIAL_AGGRO) ) |
---|
993 | { |
---|
994 | if(!unit->IsStandState() && !unit->hasUnitState(UNIT_STAT_STUNNED)) |
---|
995 | unit->SetStandState(PLAYER_STATE_NONE); |
---|
996 | |
---|
997 | if(!unit->isInCombat() && unit->GetTypeId() != TYPEID_PLAYER && ((Creature*)unit)->AI()) |
---|
998 | ((Creature*)unit)->AI()->AttackStart(m_caster); |
---|
999 | |
---|
1000 | unit->SetInCombatWith(m_caster); |
---|
1001 | m_caster->SetInCombatWith(unit); |
---|
1002 | |
---|
1003 | if(Player *attackedPlayer = unit->GetCharmerOrOwnerPlayerOrPlayerItself()) |
---|
1004 | { |
---|
1005 | m_caster->SetContestedPvP(attackedPlayer); |
---|
1006 | } |
---|
1007 | unit->AddThreat(m_caster, 0.0f); |
---|
1008 | } |
---|
1009 | } |
---|
1010 | } |
---|
1011 | else |
---|
1012 | { |
---|
1013 | // for delayed spells ignore negative spells (after duel end) for friendly targets |
---|
1014 | if(m_spellInfo->speed > 0.0f && !IsPositiveSpell(m_spellInfo->Id)) |
---|
1015 | { |
---|
1016 | m_caster->SendSpellMiss(unit, m_spellInfo->Id, SPELL_MISS_EVADE); |
---|
1017 | return; |
---|
1018 | } |
---|
1019 | |
---|
1020 | // assisting case, healing and resurrection |
---|
1021 | if(unit->hasUnitState(UNIT_STAT_ATTACK_PLAYER)) |
---|
1022 | m_caster->SetContestedPvP(); |
---|
1023 | if( unit->isInCombat() && !(m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_NO_INITIAL_AGGRO) ) |
---|
1024 | { |
---|
1025 | m_caster->SetInCombatState(unit->GetCombatTimer() > 0); |
---|
1026 | unit->getHostilRefManager().threatAssist(m_caster, 0.0f); |
---|
1027 | } |
---|
1028 | } |
---|
1029 | } |
---|
1030 | |
---|
1031 | // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add |
---|
1032 | m_diminishGroup = GetDiminishingReturnsGroupForSpell(m_spellInfo,m_triggeredByAuraSpell); |
---|
1033 | m_diminishLevel = unit->GetDiminishing(m_diminishGroup); |
---|
1034 | // Increase Diminishing on unit, current informations for actually casts will use values above |
---|
1035 | if((GetDiminishingReturnsGroupType(m_diminishGroup) == DRTYPE_PLAYER && unit->GetTypeId() == TYPEID_PLAYER) || GetDiminishingReturnsGroupType(m_diminishGroup) == DRTYPE_ALL) |
---|
1036 | unit->IncrDiminishing(m_diminishGroup); |
---|
1037 | |
---|
1038 | for(uint32 effectNumber=0;effectNumber<3;effectNumber++) |
---|
1039 | { |
---|
1040 | if (effectMask & (1<<effectNumber)) |
---|
1041 | { |
---|
1042 | HandleEffects(unit,NULL,NULL,effectNumber,m_damageMultipliers[effectNumber]); |
---|
1043 | if ( m_applyMultiplierMask & (1 << effectNumber) ) |
---|
1044 | { |
---|
1045 | // Get multiplier |
---|
1046 | float multiplier = m_spellInfo->DmgMultiplier[effectNumber]; |
---|
1047 | // Apply multiplier mods |
---|
1048 | if(Player* modOwner = m_originalCaster->GetSpellModOwner()) |
---|
1049 | modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_EFFECT_PAST_FIRST, multiplier,this); |
---|
1050 | m_damageMultipliers[effectNumber] *= multiplier; |
---|
1051 | } |
---|
1052 | } |
---|
1053 | } |
---|
1054 | } |
---|
1055 | |
---|
1056 | void Spell::DoAllEffectOnTarget(GOTargetInfo *target) |
---|
1057 | { |
---|
1058 | if (target->processed) // Check target |
---|
1059 | return; |
---|
1060 | target->processed = true; // Target checked in apply effects procedure |
---|
1061 | |
---|
1062 | uint32 effectMask = target->effectMask; |
---|
1063 | if(!effectMask) |
---|
1064 | return; |
---|
1065 | |
---|
1066 | GameObject* go = ObjectAccessor::GetGameObject(*m_caster, target->targetGUID); |
---|
1067 | if(!go) |
---|
1068 | return; |
---|
1069 | |
---|
1070 | for(uint32 effectNumber=0;effectNumber<3;effectNumber++) |
---|
1071 | if (effectMask & (1<<effectNumber)) |
---|
1072 | HandleEffects(NULL,NULL,go,effectNumber); |
---|
1073 | |
---|
1074 | // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished) |
---|
1075 | // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... ) |
---|
1076 | if( m_caster->GetTypeId() == TYPEID_PLAYER && !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() ) |
---|
1077 | ((Player*)m_caster)->CastedCreatureOrGO(go->GetEntry(),go->GetGUID(),m_spellInfo->Id); |
---|
1078 | } |
---|
1079 | |
---|
1080 | void Spell::DoAllEffectOnTarget(ItemTargetInfo *target) |
---|
1081 | { |
---|
1082 | uint32 effectMask = target->effectMask; |
---|
1083 | if(!target->item || !effectMask) |
---|
1084 | return; |
---|
1085 | |
---|
1086 | for(uint32 effectNumber=0;effectNumber<3;effectNumber++) |
---|
1087 | if (effectMask & (1<<effectNumber)) |
---|
1088 | HandleEffects(NULL, target->item, NULL, effectNumber); |
---|
1089 | } |
---|
1090 | |
---|
1091 | bool Spell::IsAliveUnitPresentInTargetList() |
---|
1092 | { |
---|
1093 | // Not need check return true |
---|
1094 | if (m_needAliveTargetMask == 0) |
---|
1095 | return true; |
---|
1096 | |
---|
1097 | uint8 needAliveTargetMask = m_needAliveTargetMask; |
---|
1098 | |
---|
1099 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit) |
---|
1100 | { |
---|
1101 | if( ihit->missCondition == SPELL_MISS_NONE && (needAliveTargetMask & ihit->effectMask) ) |
---|
1102 | { |
---|
1103 | Unit *unit = m_caster->GetGUID()==ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID); |
---|
1104 | |
---|
1105 | if (unit && unit->isAlive()) |
---|
1106 | needAliveTargetMask &= ~ihit->effectMask; // remove from need alive mask effect that have alive target |
---|
1107 | } |
---|
1108 | } |
---|
1109 | |
---|
1110 | // is all effects from m_needAliveTargetMask have alive targets |
---|
1111 | return needAliveTargetMask==0; |
---|
1112 | } |
---|
1113 | |
---|
1114 | // Helper for Chain Healing |
---|
1115 | // Spell target first |
---|
1116 | // Raidmates then descending by injury suffered (MaxHealth - Health) |
---|
1117 | // Other players/mobs then descending by injury suffered (MaxHealth - Health) |
---|
1118 | struct ChainHealingOrder : public std::binary_function<const Unit*, const Unit*, bool> |
---|
1119 | { |
---|
1120 | const Unit* MainTarget; |
---|
1121 | ChainHealingOrder(Unit const* Target) : MainTarget(Target) {}; |
---|
1122 | // functor for operator ">" |
---|
1123 | bool operator()(Unit const* _Left, Unit const* _Right) const |
---|
1124 | { |
---|
1125 | return (ChainHealingHash(_Left) < ChainHealingHash(_Right)); |
---|
1126 | } |
---|
1127 | int32 ChainHealingHash(Unit const* Target) const |
---|
1128 | { |
---|
1129 | if (Target == MainTarget) |
---|
1130 | return 0; |
---|
1131 | else if (Target->GetTypeId() == TYPEID_PLAYER && MainTarget->GetTypeId() == TYPEID_PLAYER && |
---|
1132 | ((Player const*)Target)->IsInSameRaidWith((Player const*)MainTarget)) |
---|
1133 | { |
---|
1134 | if (Target->GetHealth() == Target->GetMaxHealth()) |
---|
1135 | return 40000; |
---|
1136 | else |
---|
1137 | return 20000 - Target->GetMaxHealth() + Target->GetHealth(); |
---|
1138 | } |
---|
1139 | else |
---|
1140 | return 40000 - Target->GetMaxHealth() + Target->GetHealth(); |
---|
1141 | } |
---|
1142 | }; |
---|
1143 | |
---|
1144 | class ChainHealingFullHealth: std::unary_function<const Unit*, bool> |
---|
1145 | { |
---|
1146 | public: |
---|
1147 | const Unit* MainTarget; |
---|
1148 | ChainHealingFullHealth(const Unit* Target) : MainTarget(Target) {}; |
---|
1149 | |
---|
1150 | bool operator()(const Unit* Target) |
---|
1151 | { |
---|
1152 | return (Target != MainTarget && Target->GetHealth() == Target->GetMaxHealth()); |
---|
1153 | } |
---|
1154 | }; |
---|
1155 | |
---|
1156 | // Helper for targets nearest to the spell target |
---|
1157 | // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case) |
---|
1158 | struct TargetDistanceOrder : public std::binary_function<const Unit, const Unit, bool> |
---|
1159 | { |
---|
1160 | const Unit* MainTarget; |
---|
1161 | TargetDistanceOrder(const Unit* Target) : MainTarget(Target) {}; |
---|
1162 | // functor for operator ">" |
---|
1163 | bool operator()(const Unit* _Left, const Unit* _Right) const |
---|
1164 | { |
---|
1165 | return (MainTarget->GetDistance(_Left) < MainTarget->GetDistance(_Right)); |
---|
1166 | } |
---|
1167 | }; |
---|
1168 | |
---|
1169 | void Spell::SetTargetMap(uint32 i,uint32 cur,std::list<Unit*> &TagUnitMap) |
---|
1170 | { |
---|
1171 | float radius; |
---|
1172 | if (m_spellInfo->EffectRadiusIndex[i]) |
---|
1173 | radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i])); |
---|
1174 | else |
---|
1175 | radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex)); |
---|
1176 | |
---|
1177 | if(m_originalCaster) |
---|
1178 | if(Player* modOwner = m_originalCaster->GetSpellModOwner()) |
---|
1179 | modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RADIUS, radius,this); |
---|
1180 | |
---|
1181 | uint32 EffectChainTarget = m_spellInfo->EffectChainTarget[i]; |
---|
1182 | if(m_originalCaster) |
---|
1183 | if(Player* modOwner = m_originalCaster->GetSpellModOwner()) |
---|
1184 | modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_JUMP_TARGETS, EffectChainTarget, this); |
---|
1185 | |
---|
1186 | uint32 unMaxTargets = m_spellInfo->MaxAffectedTargets; |
---|
1187 | switch(cur) |
---|
1188 | { |
---|
1189 | // destination around caster |
---|
1190 | case TARGET_DEST_CASTER_FRONT_LEFT: |
---|
1191 | case TARGET_DEST_CASTER_BACK_LEFT: |
---|
1192 | case TARGET_DEST_CASTER_BACK_RIGHT: |
---|
1193 | case TARGET_DEST_CASTER_FRONT_RIGHT: |
---|
1194 | case TARGET_DEST_CASTER_FRONT: |
---|
1195 | case TARGET_DEST_CASTER_BACK: |
---|
1196 | case TARGET_DEST_CASTER_RIGHT: |
---|
1197 | case TARGET_DEST_CASTER_LEFT: |
---|
1198 | case TARGET_DEST_CASTER_RANDOM: |
---|
1199 | case TARGET_DEST_CASTER_RADIUS: |
---|
1200 | { |
---|
1201 | float x, y, z, angle, dist; |
---|
1202 | |
---|
1203 | if (m_spellInfo->EffectRadiusIndex[i]) |
---|
1204 | dist = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i])); |
---|
1205 | else |
---|
1206 | dist = 3.0f;//do we need this? |
---|
1207 | if (cur == TARGET_DEST_CASTER_RANDOM) |
---|
1208 | dist *= rand_norm(); // This case we need to consider caster size |
---|
1209 | else |
---|
1210 | dist -= m_caster->GetObjectSize(); // Size is calculated in GetNearPoint(), but we do not need it |
---|
1211 | //need a new function to remove this repeated work |
---|
1212 | |
---|
1213 | switch(cur) |
---|
1214 | { |
---|
1215 | case TARGET_DEST_CASTER_FRONT_LEFT: angle = -M_PI/4; break; |
---|
1216 | case TARGET_DEST_CASTER_BACK_LEFT: angle = -3*M_PI/4; break; |
---|
1217 | case TARGET_DEST_CASTER_BACK_RIGHT: angle = 3*M_PI/4; break; |
---|
1218 | case TARGET_DEST_CASTER_FRONT_RIGHT:angle = M_PI/4; break; |
---|
1219 | case TARGET_DEST_CASTER_FRONT: angle = 0.0f; break; |
---|
1220 | case TARGET_DEST_CASTER_BACK: angle = M_PI; break; |
---|
1221 | case TARGET_DEST_CASTER_RIGHT: angle = M_PI/2; break; |
---|
1222 | case TARGET_DEST_CASTER_LEFT: angle = -M_PI/2; break; |
---|
1223 | default: angle = rand_norm()*2*M_PI; break; |
---|
1224 | } |
---|
1225 | |
---|
1226 | m_caster->GetClosePoint(x, y, z, 0, dist, angle); |
---|
1227 | m_targets.setDestination(x, y, z); // do not know if has ground visual |
---|
1228 | TagUnitMap.push_back(m_caster); // may remove this in the future, if unitmap is empty, push m_caster |
---|
1229 | }break; |
---|
1230 | |
---|
1231 | // destination around target |
---|
1232 | case TARGET_DEST_TARGET_FRONT: |
---|
1233 | case TARGET_DEST_TARGET_BACK: |
---|
1234 | case TARGET_DEST_TARGET_RIGHT: |
---|
1235 | case TARGET_DEST_TARGET_LEFT: |
---|
1236 | case TARGET_DEST_TARGET_RANDOM: |
---|
1237 | case TARGET_DEST_TARGET_RADIUS: |
---|
1238 | { |
---|
1239 | Unit *target = m_targets.getUnitTarget(); |
---|
1240 | if(!target) |
---|
1241 | { |
---|
1242 | sLog.outError("SPELL: no unit target for spell ID %u\n", m_spellInfo->Id); |
---|
1243 | break; |
---|
1244 | } |
---|
1245 | |
---|
1246 | float x, y, z, angle, dist; |
---|
1247 | |
---|
1248 | if (m_spellInfo->EffectRadiusIndex[i]) |
---|
1249 | dist = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i])); |
---|
1250 | else |
---|
1251 | dist = 3.0f;//do we need this? |
---|
1252 | if (cur == TARGET_DEST_TARGET_RANDOM) |
---|
1253 | dist *= rand_norm(); // This case we need to consider caster size |
---|
1254 | else |
---|
1255 | dist -= target->GetObjectSize(); // Size is calculated in GetNearPoint(), but we do not need it |
---|
1256 | //need a new function to remove this repeated work |
---|
1257 | |
---|
1258 | switch(cur) |
---|
1259 | { |
---|
1260 | case TARGET_DEST_TARGET_FRONT: angle = 0.0f; break; |
---|
1261 | case TARGET_DEST_TARGET_BACK: angle = M_PI; break; |
---|
1262 | case TARGET_DEST_TARGET_RIGHT: angle = M_PI/2; break; |
---|
1263 | case TARGET_DEST_TARGET_LEFT: angle = -M_PI/2; break; |
---|
1264 | default: angle = rand_norm()*2*M_PI; break; |
---|
1265 | } |
---|
1266 | |
---|
1267 | target->GetClosePoint(x, y, z, 0, dist, angle); |
---|
1268 | m_targets.setDestination(x, y, z); // do not know if has ground visual |
---|
1269 | TagUnitMap.push_back(m_caster); // may remove this in the future, if unitmap is empty, push m_caster |
---|
1270 | }break; |
---|
1271 | |
---|
1272 | // destination around destination |
---|
1273 | case TARGET_DEST_DEST_RANDOM: |
---|
1274 | { |
---|
1275 | if(!(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)) |
---|
1276 | { |
---|
1277 | sLog.outError("SPELL: no destination for spell ID %u\n", m_spellInfo->Id); |
---|
1278 | break; |
---|
1279 | } |
---|
1280 | float x, y, z, dist, px, py, pz; |
---|
1281 | dist = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i])); |
---|
1282 | x = m_targets.m_destX; |
---|
1283 | y = m_targets.m_destY; |
---|
1284 | z = m_targets.m_destZ; |
---|
1285 | m_caster->GetRandomPoint(x, y, z, dist, px, py, pz); |
---|
1286 | m_targets.setDestination(px, py, pz); |
---|
1287 | TagUnitMap.push_back(m_caster); |
---|
1288 | }break; |
---|
1289 | case TARGET_SELF2: |
---|
1290 | { |
---|
1291 | TagUnitMap.push_back(m_caster); |
---|
1292 | }break; |
---|
1293 | |
---|
1294 | case TARGET_SELF: |
---|
1295 | case TARGET_AREAEFFECT_CUSTOM: |
---|
1296 | case TARGET_AREAEFFECT_CUSTOM_2: |
---|
1297 | { |
---|
1298 | TagUnitMap.push_back(m_caster); |
---|
1299 | break; |
---|
1300 | } |
---|
1301 | case TARGET_RANDOM_ENEMY_CHAIN_IN_AREA: |
---|
1302 | { |
---|
1303 | m_targets.m_targetMask = 0; |
---|
1304 | unMaxTargets = EffectChainTarget; |
---|
1305 | float max_range = radius + unMaxTargets * CHAIN_SPELL_JUMP_RADIUS; |
---|
1306 | |
---|
1307 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
1308 | Cell cell(p); |
---|
1309 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1310 | cell.SetNoCreate(); |
---|
1311 | |
---|
1312 | std::list<Unit *> tempUnitMap; |
---|
1313 | |
---|
1314 | { |
---|
1315 | Trinity::AnyAoETargetUnitInObjectRangeCheck u_check(m_caster, m_caster, max_range); |
---|
1316 | Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck> searcher(tempUnitMap, u_check); |
---|
1317 | |
---|
1318 | TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher); |
---|
1319 | TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher); |
---|
1320 | |
---|
1321 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1322 | cell_lock->Visit(cell_lock, world_unit_searcher, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1323 | cell_lock->Visit(cell_lock, grid_unit_searcher, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1324 | } |
---|
1325 | |
---|
1326 | if(tempUnitMap.empty()) |
---|
1327 | break; |
---|
1328 | |
---|
1329 | tempUnitMap.sort(TargetDistanceOrder(m_caster)); |
---|
1330 | |
---|
1331 | //Now to get us a random target that's in the initial range of the spell |
---|
1332 | uint32 t = 0; |
---|
1333 | std::list<Unit *>::iterator itr = tempUnitMap.begin(); |
---|
1334 | while(itr!= tempUnitMap.end() && (*itr)->GetDistance(m_caster) < radius) |
---|
1335 | ++t, ++itr; |
---|
1336 | |
---|
1337 | if(!t) |
---|
1338 | break; |
---|
1339 | |
---|
1340 | itr = tempUnitMap.begin(); |
---|
1341 | std::advance(itr, rand()%t); |
---|
1342 | Unit *pUnitTarget = *itr; |
---|
1343 | TagUnitMap.push_back(pUnitTarget); |
---|
1344 | |
---|
1345 | tempUnitMap.erase(itr); |
---|
1346 | |
---|
1347 | tempUnitMap.sort(TargetDistanceOrder(pUnitTarget)); |
---|
1348 | |
---|
1349 | t = unMaxTargets - 1; |
---|
1350 | Unit *prev = pUnitTarget; |
---|
1351 | std::list<Unit*>::iterator next = tempUnitMap.begin(); |
---|
1352 | |
---|
1353 | while(t && next != tempUnitMap.end() ) |
---|
1354 | { |
---|
1355 | if(prev->GetDistance(*next) > CHAIN_SPELL_JUMP_RADIUS) |
---|
1356 | break; |
---|
1357 | |
---|
1358 | if(!prev->IsWithinLOSInMap(*next)) |
---|
1359 | { |
---|
1360 | ++next; |
---|
1361 | continue; |
---|
1362 | } |
---|
1363 | |
---|
1364 | prev = *next; |
---|
1365 | TagUnitMap.push_back(prev); |
---|
1366 | tempUnitMap.erase(next); |
---|
1367 | tempUnitMap.sort(TargetDistanceOrder(prev)); |
---|
1368 | next = tempUnitMap.begin(); |
---|
1369 | |
---|
1370 | --t; |
---|
1371 | } |
---|
1372 | }break; |
---|
1373 | case TARGET_PET: |
---|
1374 | { |
---|
1375 | Pet* tmpUnit = m_caster->GetPet(); |
---|
1376 | if (!tmpUnit) break; |
---|
1377 | TagUnitMap.push_back(tmpUnit); |
---|
1378 | break; |
---|
1379 | } |
---|
1380 | case TARGET_CHAIN_DAMAGE: |
---|
1381 | { |
---|
1382 | if (EffectChainTarget <= 1) |
---|
1383 | { |
---|
1384 | Unit* pUnitTarget = SelectMagnetTarget(); |
---|
1385 | if(pUnitTarget) |
---|
1386 | TagUnitMap.push_back(pUnitTarget); |
---|
1387 | } |
---|
1388 | else |
---|
1389 | { |
---|
1390 | Unit* pUnitTarget = m_targets.getUnitTarget(); |
---|
1391 | if(!pUnitTarget) |
---|
1392 | break; |
---|
1393 | |
---|
1394 | unMaxTargets = EffectChainTarget; |
---|
1395 | |
---|
1396 | float max_range; |
---|
1397 | if(m_spellInfo->DmgClass==SPELL_DAMAGE_CLASS_MELEE) |
---|
1398 | max_range = radius; // |
---|
1399 | else |
---|
1400 | //FIXME: This very like horrible hack and wrong for most spells |
---|
1401 | max_range = radius + unMaxTargets * CHAIN_SPELL_JUMP_RADIUS; |
---|
1402 | |
---|
1403 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
1404 | Cell cell(p); |
---|
1405 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1406 | cell.SetNoCreate(); |
---|
1407 | |
---|
1408 | Unit* originalCaster = GetOriginalCaster(); |
---|
1409 | if(originalCaster) |
---|
1410 | { |
---|
1411 | std::list<Unit *> tempUnitMap; |
---|
1412 | |
---|
1413 | { |
---|
1414 | Trinity::AnyAoETargetUnitInObjectRangeCheck u_check(pUnitTarget, originalCaster, max_range); |
---|
1415 | Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck> searcher(tempUnitMap, u_check); |
---|
1416 | |
---|
1417 | TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher); |
---|
1418 | TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyAoETargetUnitInObjectRangeCheck>, GridTypeMapContainer > grid_unit_searcher(searcher); |
---|
1419 | |
---|
1420 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1421 | cell_lock->Visit(cell_lock, world_unit_searcher, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1422 | cell_lock->Visit(cell_lock, grid_unit_searcher, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1423 | } |
---|
1424 | |
---|
1425 | tempUnitMap.sort(TargetDistanceOrder(pUnitTarget)); |
---|
1426 | |
---|
1427 | if(tempUnitMap.empty()) |
---|
1428 | break; |
---|
1429 | |
---|
1430 | if(*tempUnitMap.begin() == pUnitTarget) |
---|
1431 | tempUnitMap.erase(tempUnitMap.begin()); |
---|
1432 | |
---|
1433 | TagUnitMap.push_back(pUnitTarget); |
---|
1434 | uint32 t = unMaxTargets - 1; |
---|
1435 | Unit *prev = pUnitTarget; |
---|
1436 | std::list<Unit*>::iterator next = tempUnitMap.begin(); |
---|
1437 | |
---|
1438 | while(t && next != tempUnitMap.end() ) |
---|
1439 | { |
---|
1440 | if(prev->GetDistance(*next) > CHAIN_SPELL_JUMP_RADIUS) |
---|
1441 | break; |
---|
1442 | |
---|
1443 | if(!prev->IsWithinLOSInMap(*next)) |
---|
1444 | { |
---|
1445 | ++next; |
---|
1446 | continue; |
---|
1447 | } |
---|
1448 | |
---|
1449 | prev = *next; |
---|
1450 | TagUnitMap.push_back(prev); |
---|
1451 | tempUnitMap.erase(next); |
---|
1452 | tempUnitMap.sort(TargetDistanceOrder(prev)); |
---|
1453 | next = tempUnitMap.begin(); |
---|
1454 | |
---|
1455 | --t; |
---|
1456 | } |
---|
1457 | } |
---|
1458 | } |
---|
1459 | }break; |
---|
1460 | case TARGET_ALL_ENEMY_IN_AREA: |
---|
1461 | { |
---|
1462 | }break; |
---|
1463 | case TARGET_ALL_ENEMY_IN_AREA_INSTANT: |
---|
1464 | { |
---|
1465 | // targets the ground, not the units in the area |
---|
1466 | if (m_spellInfo->Effect[i]!=SPELL_EFFECT_PERSISTENT_AREA_AURA) |
---|
1467 | { |
---|
1468 | CellPair p(Trinity::ComputeCellPair(m_targets.m_destX, m_targets.m_destY)); |
---|
1469 | Cell cell(p); |
---|
1470 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1471 | cell.SetNoCreate(); |
---|
1472 | |
---|
1473 | Trinity::SpellNotifierCreatureAndPlayer notifier(*this, TagUnitMap, radius, PUSH_DEST_CENTER,SPELL_TARGETS_AOE_DAMAGE); |
---|
1474 | |
---|
1475 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, WorldTypeMapContainer > world_object_notifier(notifier); |
---|
1476 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, GridTypeMapContainer > grid_object_notifier(notifier); |
---|
1477 | |
---|
1478 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1479 | cell_lock->Visit(cell_lock, world_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1480 | cell_lock->Visit(cell_lock, grid_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1481 | |
---|
1482 | // exclude caster (this can be important if this not original caster) |
---|
1483 | TagUnitMap.remove(m_caster); |
---|
1484 | } |
---|
1485 | }break; |
---|
1486 | case TARGET_DUELVSPLAYER_COORDINATES: |
---|
1487 | { |
---|
1488 | if(Unit* currentTarget = m_targets.getUnitTarget()) |
---|
1489 | { |
---|
1490 | m_targets.setDestination(currentTarget->GetPositionX(), currentTarget->GetPositionY(), currentTarget->GetPositionZ()); |
---|
1491 | TagUnitMap.push_back(currentTarget); |
---|
1492 | } |
---|
1493 | }break; |
---|
1494 | case TARGET_ALL_PARTY_AROUND_CASTER: |
---|
1495 | case TARGET_ALL_PARTY_AROUND_CASTER_2: |
---|
1496 | case TARGET_ALL_PARTY: |
---|
1497 | { |
---|
1498 | Player *pTarget = m_caster->GetCharmerOrOwnerPlayerOrPlayerItself(); |
---|
1499 | Group *pGroup = pTarget ? pTarget->GetGroup() : NULL; |
---|
1500 | |
---|
1501 | if(pGroup) |
---|
1502 | { |
---|
1503 | uint8 subgroup = pTarget->GetSubGroup(); |
---|
1504 | |
---|
1505 | for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next()) |
---|
1506 | { |
---|
1507 | Player* Target = itr->getSource(); |
---|
1508 | |
---|
1509 | // IsHostileTo check duel and controlled by enemy |
---|
1510 | if( Target && Target->GetSubGroup()==subgroup && !m_caster->IsHostileTo(Target) ) |
---|
1511 | { |
---|
1512 | if( m_caster->IsWithinDistInMap(Target, radius) ) |
---|
1513 | TagUnitMap.push_back(Target); |
---|
1514 | |
---|
1515 | if(Pet* pet = Target->GetPet()) |
---|
1516 | if( m_caster->IsWithinDistInMap(pet, radius) ) |
---|
1517 | TagUnitMap.push_back(pet); |
---|
1518 | } |
---|
1519 | } |
---|
1520 | } |
---|
1521 | else |
---|
1522 | { |
---|
1523 | Unit* ownerOrSelf = pTarget ? pTarget : m_caster->GetCharmerOrOwnerOrSelf(); |
---|
1524 | if(ownerOrSelf==m_caster || m_caster->IsWithinDistInMap(ownerOrSelf, radius)) |
---|
1525 | TagUnitMap.push_back(ownerOrSelf); |
---|
1526 | if(Pet* pet = ownerOrSelf->GetPet()) |
---|
1527 | if( m_caster->IsWithinDistInMap(pet, radius) ) |
---|
1528 | TagUnitMap.push_back(pet); |
---|
1529 | } |
---|
1530 | }break; |
---|
1531 | case TARGET_RANDOM_RAID_MEMBER: |
---|
1532 | { |
---|
1533 | if (m_caster->GetTypeId() == TYPEID_PLAYER) |
---|
1534 | if(Player* target = ((Player*)m_caster)->GetNextRandomRaidMember(radius)) |
---|
1535 | TagUnitMap.push_back(target); |
---|
1536 | }break; |
---|
1537 | case TARGET_SINGLE_FRIEND: |
---|
1538 | case TARGET_SINGLE_FRIEND_2: |
---|
1539 | { |
---|
1540 | if(m_targets.getUnitTarget()) |
---|
1541 | TagUnitMap.push_back(m_targets.getUnitTarget()); |
---|
1542 | }break; |
---|
1543 | case TARGET_NONCOMBAT_PET: |
---|
1544 | { |
---|
1545 | if(Unit* target = m_targets.getUnitTarget()) |
---|
1546 | if( target->GetTypeId() == TYPEID_UNIT && ((Creature*)target)->isPet() && ((Pet*)target)->getPetType() == MINI_PET) |
---|
1547 | TagUnitMap.push_back(target); |
---|
1548 | }break; |
---|
1549 | case TARGET_ALL_AROUND_CASTER: |
---|
1550 | { |
---|
1551 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
1552 | Cell cell(p); |
---|
1553 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1554 | cell.SetNoCreate(); |
---|
1555 | |
---|
1556 | Trinity::SpellNotifierCreatureAndPlayer notifier(*this, TagUnitMap, radius, PUSH_SELF_CENTER,SPELL_TARGETS_AOE_DAMAGE); |
---|
1557 | |
---|
1558 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, WorldTypeMapContainer > world_object_notifier(notifier); |
---|
1559 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, GridTypeMapContainer > grid_object_notifier(notifier); |
---|
1560 | |
---|
1561 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1562 | cell_lock->Visit(cell_lock, world_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1563 | cell_lock->Visit(cell_lock, grid_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1564 | }break; |
---|
1565 | case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER: |
---|
1566 | { |
---|
1567 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
1568 | Cell cell(p); |
---|
1569 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1570 | cell.SetNoCreate(); |
---|
1571 | |
---|
1572 | Trinity::SpellNotifierCreatureAndPlayer notifier(*this, TagUnitMap, radius, PUSH_SELF_CENTER,SPELL_TARGETS_FRIENDLY); |
---|
1573 | |
---|
1574 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, WorldTypeMapContainer > world_object_notifier(notifier); |
---|
1575 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, GridTypeMapContainer > grid_object_notifier(notifier); |
---|
1576 | |
---|
1577 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1578 | cell_lock->Visit(cell_lock, world_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1579 | cell_lock->Visit(cell_lock, grid_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1580 | }break; |
---|
1581 | case TARGET_ALL_FRIENDLY_UNITS_IN_AREA: |
---|
1582 | { |
---|
1583 | CellPair p(Trinity::ComputeCellPair(m_targets.m_destX, m_targets.m_destY)); |
---|
1584 | Cell cell(p); |
---|
1585 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1586 | cell.SetNoCreate(); |
---|
1587 | |
---|
1588 | Trinity::SpellNotifierCreatureAndPlayer notifier(*this, TagUnitMap, radius, PUSH_DEST_CENTER,SPELL_TARGETS_FRIENDLY); |
---|
1589 | |
---|
1590 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, WorldTypeMapContainer > world_object_notifier(notifier); |
---|
1591 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, GridTypeMapContainer > grid_object_notifier(notifier); |
---|
1592 | |
---|
1593 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1594 | cell_lock->Visit(cell_lock, world_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1595 | cell_lock->Visit(cell_lock, grid_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1596 | }break; |
---|
1597 | // TARGET_SINGLE_PARTY means that the spells can only be casted on a party member and not on the caster (some sceals, fire shield from imp, etc..) |
---|
1598 | case TARGET_SINGLE_PARTY: |
---|
1599 | { |
---|
1600 | Unit *target = m_targets.getUnitTarget(); |
---|
1601 | // Thoses spells apparently can't be casted on the caster. |
---|
1602 | if( target && target != m_caster) |
---|
1603 | { |
---|
1604 | // Can only be casted on group's members or its pets |
---|
1605 | Group *pGroup = NULL; |
---|
1606 | |
---|
1607 | Unit* owner = m_caster->GetCharmerOrOwner(); |
---|
1608 | Unit *targetOwner = target->GetCharmerOrOwner(); |
---|
1609 | if(owner) |
---|
1610 | { |
---|
1611 | if(owner->GetTypeId() == TYPEID_PLAYER) |
---|
1612 | { |
---|
1613 | if( target == owner ) |
---|
1614 | { |
---|
1615 | TagUnitMap.push_back(target); |
---|
1616 | break; |
---|
1617 | } |
---|
1618 | pGroup = ((Player*)owner)->GetGroup(); |
---|
1619 | } |
---|
1620 | } |
---|
1621 | else if (m_caster->GetTypeId() == TYPEID_PLAYER) |
---|
1622 | { |
---|
1623 | if( targetOwner == m_caster && target->GetTypeId()==TYPEID_UNIT && ((Creature*)target)->isPet()) |
---|
1624 | { |
---|
1625 | TagUnitMap.push_back(target); |
---|
1626 | break; |
---|
1627 | } |
---|
1628 | pGroup = ((Player*)m_caster)->GetGroup(); |
---|
1629 | } |
---|
1630 | |
---|
1631 | if(pGroup) |
---|
1632 | { |
---|
1633 | // Our target can also be a player's pet who's grouped with us or our pet. But can't be controlled player |
---|
1634 | if(targetOwner) |
---|
1635 | { |
---|
1636 | if( targetOwner->GetTypeId() == TYPEID_PLAYER && |
---|
1637 | target->GetTypeId()==TYPEID_UNIT && (((Creature*)target)->isPet()) && |
---|
1638 | target->GetOwnerGUID()==targetOwner->GetGUID() && |
---|
1639 | pGroup->IsMember(((Player*)targetOwner)->GetGUID())) |
---|
1640 | { |
---|
1641 | TagUnitMap.push_back(target); |
---|
1642 | } |
---|
1643 | } |
---|
1644 | // 1Our target can be a player who is on our group |
---|
1645 | else if (target->GetTypeId() == TYPEID_PLAYER && pGroup->IsMember(((Player*)target)->GetGUID())) |
---|
1646 | { |
---|
1647 | TagUnitMap.push_back(target); |
---|
1648 | } |
---|
1649 | } |
---|
1650 | } |
---|
1651 | }break; |
---|
1652 | case TARGET_GAMEOBJECT: |
---|
1653 | { |
---|
1654 | if(m_targets.getGOTarget()) |
---|
1655 | AddGOTarget(m_targets.getGOTarget(), i); |
---|
1656 | }break; |
---|
1657 | case TARGET_IN_FRONT_OF_CASTER: |
---|
1658 | { |
---|
1659 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
1660 | Cell cell(p); |
---|
1661 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1662 | cell.SetNoCreate(); |
---|
1663 | |
---|
1664 | bool inFront = m_spellInfo->SpellVisual != 3879; |
---|
1665 | Trinity::SpellNotifierCreatureAndPlayer notifier(*this, TagUnitMap, radius, inFront ? PUSH_IN_FRONT : PUSH_IN_BACK,SPELL_TARGETS_AOE_DAMAGE); |
---|
1666 | |
---|
1667 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, WorldTypeMapContainer > world_object_notifier(notifier); |
---|
1668 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, GridTypeMapContainer > grid_object_notifier(notifier); |
---|
1669 | |
---|
1670 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1671 | cell_lock->Visit(cell_lock, world_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1672 | cell_lock->Visit(cell_lock, grid_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1673 | }break; |
---|
1674 | case TARGET_DUELVSPLAYER: |
---|
1675 | { |
---|
1676 | Unit *target = m_targets.getUnitTarget(); |
---|
1677 | if(target) |
---|
1678 | { |
---|
1679 | if(m_caster->IsFriendlyTo(target)) |
---|
1680 | { |
---|
1681 | TagUnitMap.push_back(target); |
---|
1682 | } |
---|
1683 | else |
---|
1684 | { |
---|
1685 | Unit* pUnitTarget = SelectMagnetTarget(); |
---|
1686 | if(pUnitTarget) |
---|
1687 | TagUnitMap.push_back(pUnitTarget); |
---|
1688 | } |
---|
1689 | } |
---|
1690 | }break; |
---|
1691 | case TARGET_GAMEOBJECT_ITEM: |
---|
1692 | { |
---|
1693 | if(m_targets.getGOTargetGUID()) |
---|
1694 | AddGOTarget(m_targets.getGOTarget(), i); |
---|
1695 | else if(m_targets.getItemTarget()) |
---|
1696 | AddItemTarget(m_targets.getItemTarget(), i); |
---|
1697 | break; |
---|
1698 | } |
---|
1699 | case TARGET_MASTER: |
---|
1700 | { |
---|
1701 | if(Unit* owner = m_caster->GetCharmerOrOwner()) |
---|
1702 | TagUnitMap.push_back(owner); |
---|
1703 | break; |
---|
1704 | } |
---|
1705 | case TARGET_ALL_ENEMY_IN_AREA_CHANNELED: |
---|
1706 | { |
---|
1707 | // targets the ground, not the units in the area |
---|
1708 | if (m_spellInfo->Effect[i]!=SPELL_EFFECT_PERSISTENT_AREA_AURA) |
---|
1709 | { |
---|
1710 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
1711 | Cell cell(p); |
---|
1712 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1713 | cell.SetNoCreate(); |
---|
1714 | |
---|
1715 | Trinity::SpellNotifierCreatureAndPlayer notifier(*this, TagUnitMap, radius, PUSH_DEST_CENTER,SPELL_TARGETS_AOE_DAMAGE); |
---|
1716 | |
---|
1717 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, WorldTypeMapContainer > world_object_notifier(notifier); |
---|
1718 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, GridTypeMapContainer > grid_object_notifier(notifier); |
---|
1719 | |
---|
1720 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1721 | cell_lock->Visit(cell_lock, world_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1722 | cell_lock->Visit(cell_lock, grid_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1723 | } |
---|
1724 | }break; |
---|
1725 | case TARGET_MINION: |
---|
1726 | { |
---|
1727 | if(m_spellInfo->Effect[i] != SPELL_EFFECT_DUEL) |
---|
1728 | TagUnitMap.push_back(m_caster); |
---|
1729 | }break; |
---|
1730 | case TARGET_SINGLE_ENEMY: |
---|
1731 | { |
---|
1732 | Unit* pUnitTarget = SelectMagnetTarget(); |
---|
1733 | if(pUnitTarget) |
---|
1734 | TagUnitMap.push_back(pUnitTarget); |
---|
1735 | }break; |
---|
1736 | case TARGET_AREAEFFECT_PARTY: |
---|
1737 | { |
---|
1738 | Unit* owner = m_caster->GetCharmerOrOwner(); |
---|
1739 | Player *pTarget = NULL; |
---|
1740 | |
---|
1741 | if(owner) |
---|
1742 | { |
---|
1743 | TagUnitMap.push_back(m_caster); |
---|
1744 | if(owner->GetTypeId() == TYPEID_PLAYER) |
---|
1745 | pTarget = (Player*)owner; |
---|
1746 | } |
---|
1747 | else if (m_caster->GetTypeId() == TYPEID_PLAYER) |
---|
1748 | { |
---|
1749 | if(Unit* target = m_targets.getUnitTarget()) |
---|
1750 | { |
---|
1751 | if( target->GetTypeId() != TYPEID_PLAYER) |
---|
1752 | { |
---|
1753 | if(((Creature*)target)->isPet()) |
---|
1754 | { |
---|
1755 | Unit *targetOwner = target->GetOwner(); |
---|
1756 | if(targetOwner->GetTypeId() == TYPEID_PLAYER) |
---|
1757 | pTarget = (Player*)targetOwner; |
---|
1758 | } |
---|
1759 | } |
---|
1760 | else |
---|
1761 | pTarget = (Player*)target; |
---|
1762 | } |
---|
1763 | } |
---|
1764 | |
---|
1765 | Group* pGroup = pTarget ? pTarget->GetGroup() : NULL; |
---|
1766 | |
---|
1767 | if(pGroup) |
---|
1768 | { |
---|
1769 | uint8 subgroup = pTarget->GetSubGroup(); |
---|
1770 | |
---|
1771 | for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next()) |
---|
1772 | { |
---|
1773 | Player* Target = itr->getSource(); |
---|
1774 | |
---|
1775 | // IsHostileTo check duel and controlled by enemy |
---|
1776 | if(Target && Target->GetSubGroup()==subgroup && !m_caster->IsHostileTo(Target)) |
---|
1777 | { |
---|
1778 | if( pTarget->IsWithinDistInMap(Target, radius) ) |
---|
1779 | TagUnitMap.push_back(Target); |
---|
1780 | |
---|
1781 | if(Pet* pet = Target->GetPet()) |
---|
1782 | if( pTarget->IsWithinDistInMap(pet, radius) ) |
---|
1783 | TagUnitMap.push_back(pet); |
---|
1784 | } |
---|
1785 | } |
---|
1786 | } |
---|
1787 | else if (owner) |
---|
1788 | { |
---|
1789 | if(m_caster->IsWithinDistInMap(owner, radius)) |
---|
1790 | TagUnitMap.push_back(owner); |
---|
1791 | } |
---|
1792 | else if(pTarget) |
---|
1793 | { |
---|
1794 | TagUnitMap.push_back(pTarget); |
---|
1795 | |
---|
1796 | if(Pet* pet = pTarget->GetPet()) |
---|
1797 | if( m_caster->IsWithinDistInMap(pet, radius) ) |
---|
1798 | TagUnitMap.push_back(pet); |
---|
1799 | } |
---|
1800 | |
---|
1801 | }break; |
---|
1802 | case TARGET_SCRIPT: |
---|
1803 | { |
---|
1804 | if(m_targets.getUnitTarget()) |
---|
1805 | TagUnitMap.push_back(m_targets.getUnitTarget()); |
---|
1806 | if(m_targets.getItemTarget()) |
---|
1807 | AddItemTarget(m_targets.getItemTarget(), i); |
---|
1808 | }break; |
---|
1809 | case TARGET_SELF_FISHING: |
---|
1810 | { |
---|
1811 | TagUnitMap.push_back(m_caster); |
---|
1812 | }break; |
---|
1813 | case TARGET_CHAIN_HEAL: |
---|
1814 | { |
---|
1815 | Unit* pUnitTarget = m_targets.getUnitTarget(); |
---|
1816 | if(!pUnitTarget) |
---|
1817 | break; |
---|
1818 | |
---|
1819 | if (EffectChainTarget <= 1) |
---|
1820 | TagUnitMap.push_back(pUnitTarget); |
---|
1821 | else |
---|
1822 | { |
---|
1823 | unMaxTargets = EffectChainTarget; |
---|
1824 | float max_range = radius + unMaxTargets * CHAIN_SPELL_JUMP_RADIUS; |
---|
1825 | |
---|
1826 | std::list<Unit *> tempUnitMap; |
---|
1827 | |
---|
1828 | { |
---|
1829 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
1830 | Cell cell(p); |
---|
1831 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1832 | cell.SetNoCreate(); |
---|
1833 | |
---|
1834 | Trinity::SpellNotifierCreatureAndPlayer notifier(*this, tempUnitMap, max_range, PUSH_SELF_CENTER, SPELL_TARGETS_FRIENDLY); |
---|
1835 | |
---|
1836 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, WorldTypeMapContainer > world_object_notifier(notifier); |
---|
1837 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, GridTypeMapContainer > grid_object_notifier(notifier); |
---|
1838 | |
---|
1839 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1840 | cell_lock->Visit(cell_lock, world_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1841 | cell_lock->Visit(cell_lock, grid_object_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1842 | |
---|
1843 | } |
---|
1844 | |
---|
1845 | if(m_caster != pUnitTarget && std::find(tempUnitMap.begin(),tempUnitMap.end(),m_caster) == tempUnitMap.end() ) |
---|
1846 | tempUnitMap.push_front(m_caster); |
---|
1847 | |
---|
1848 | tempUnitMap.sort(TargetDistanceOrder(pUnitTarget)); |
---|
1849 | |
---|
1850 | if(tempUnitMap.empty()) |
---|
1851 | break; |
---|
1852 | |
---|
1853 | if(*tempUnitMap.begin() == pUnitTarget) |
---|
1854 | tempUnitMap.erase(tempUnitMap.begin()); |
---|
1855 | |
---|
1856 | TagUnitMap.push_back(pUnitTarget); |
---|
1857 | uint32 t = unMaxTargets - 1; |
---|
1858 | Unit *prev = pUnitTarget; |
---|
1859 | std::list<Unit*>::iterator next = tempUnitMap.begin(); |
---|
1860 | |
---|
1861 | while(t && next != tempUnitMap.end() ) |
---|
1862 | { |
---|
1863 | if(prev->GetDistance(*next) > CHAIN_SPELL_JUMP_RADIUS) |
---|
1864 | break; |
---|
1865 | |
---|
1866 | if(!prev->IsWithinLOSInMap(*next)) |
---|
1867 | { |
---|
1868 | ++next; |
---|
1869 | continue; |
---|
1870 | } |
---|
1871 | |
---|
1872 | if((*next)->GetHealth() == (*next)->GetMaxHealth()) |
---|
1873 | { |
---|
1874 | next = tempUnitMap.erase(next); |
---|
1875 | continue; |
---|
1876 | } |
---|
1877 | |
---|
1878 | prev = *next; |
---|
1879 | TagUnitMap.push_back(prev); |
---|
1880 | tempUnitMap.erase(next); |
---|
1881 | tempUnitMap.sort(TargetDistanceOrder(prev)); |
---|
1882 | next = tempUnitMap.begin(); |
---|
1883 | |
---|
1884 | --t; |
---|
1885 | } |
---|
1886 | } |
---|
1887 | }break; |
---|
1888 | case TARGET_CURRENT_ENEMY_COORDINATES: |
---|
1889 | { |
---|
1890 | Unit* currentTarget = m_targets.getUnitTarget(); |
---|
1891 | if(currentTarget) |
---|
1892 | { |
---|
1893 | TagUnitMap.push_back(currentTarget); |
---|
1894 | m_targets.setDestination(currentTarget->GetPositionX(), currentTarget->GetPositionY(), currentTarget->GetPositionZ()); |
---|
1895 | if(m_spellInfo->EffectImplicitTargetB[i]==TARGET_ALL_ENEMY_IN_AREA_INSTANT) |
---|
1896 | { |
---|
1897 | CellPair p(Trinity::ComputeCellPair(currentTarget->GetPositionX(), currentTarget->GetPositionY())); |
---|
1898 | Cell cell(p); |
---|
1899 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1900 | cell.SetNoCreate(); |
---|
1901 | Trinity::SpellNotifierCreatureAndPlayer notifier(*this, TagUnitMap, radius,PUSH_TARGET_CENTER, SPELL_TARGETS_AOE_DAMAGE); |
---|
1902 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, WorldTypeMapContainer > world_notifier(notifier); |
---|
1903 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, GridTypeMapContainer > grid_notifier(notifier); |
---|
1904 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1905 | cell_lock->Visit(cell_lock, world_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1906 | cell_lock->Visit(cell_lock, grid_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1907 | } |
---|
1908 | } |
---|
1909 | }break; |
---|
1910 | case TARGET_AREAEFFECT_PARTY_AND_CLASS: |
---|
1911 | { |
---|
1912 | Player* targetPlayer = m_targets.getUnitTarget() && m_targets.getUnitTarget()->GetTypeId() == TYPEID_PLAYER |
---|
1913 | ? (Player*)m_targets.getUnitTarget() : NULL; |
---|
1914 | |
---|
1915 | Group* pGroup = targetPlayer ? targetPlayer->GetGroup() : NULL; |
---|
1916 | if(pGroup) |
---|
1917 | { |
---|
1918 | for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next()) |
---|
1919 | { |
---|
1920 | Player* Target = itr->getSource(); |
---|
1921 | |
---|
1922 | // IsHostileTo check duel and controlled by enemy |
---|
1923 | if( Target && targetPlayer->IsWithinDistInMap(Target, radius) && |
---|
1924 | targetPlayer->getClass() == Target->getClass() && |
---|
1925 | !m_caster->IsHostileTo(Target) ) |
---|
1926 | { |
---|
1927 | TagUnitMap.push_back(Target); |
---|
1928 | } |
---|
1929 | } |
---|
1930 | } |
---|
1931 | else if(m_targets.getUnitTarget()) |
---|
1932 | TagUnitMap.push_back(m_targets.getUnitTarget()); |
---|
1933 | break; |
---|
1934 | } |
---|
1935 | case TARGET_TABLE_X_Y_Z_COORDINATES: |
---|
1936 | { |
---|
1937 | SpellTargetPosition const* st = spellmgr.GetSpellTargetPosition(m_spellInfo->Id); |
---|
1938 | if(st) |
---|
1939 | { |
---|
1940 | if (st->target_mapId == m_caster->GetMapId()) |
---|
1941 | m_targets.setDestination(st->target_X, st->target_Y, st->target_Z); |
---|
1942 | |
---|
1943 | // if B==TARGET_TABLE_X_Y_Z_COORDINATES then A already fill all required targets |
---|
1944 | if (m_spellInfo->EffectImplicitTargetB[i] && m_spellInfo->EffectImplicitTargetB[i]!=TARGET_TABLE_X_Y_Z_COORDINATES) |
---|
1945 | { |
---|
1946 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
1947 | Cell cell(p); |
---|
1948 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
1949 | cell.SetNoCreate(); |
---|
1950 | |
---|
1951 | SpellTargets targetB = SPELL_TARGETS_AOE_DAMAGE; |
---|
1952 | // Select friendly targets for positive effect |
---|
1953 | if (IsPositiveEffect(m_spellInfo->Id, i)) |
---|
1954 | targetB = SPELL_TARGETS_FRIENDLY; |
---|
1955 | |
---|
1956 | Trinity::SpellNotifierCreatureAndPlayer notifier(*this, TagUnitMap, radius,PUSH_DEST_CENTER, targetB); |
---|
1957 | |
---|
1958 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, WorldTypeMapContainer > world_notifier(notifier); |
---|
1959 | TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, GridTypeMapContainer > grid_notifier(notifier); |
---|
1960 | |
---|
1961 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
1962 | cell_lock->Visit(cell_lock, world_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1963 | cell_lock->Visit(cell_lock, grid_notifier, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
1964 | } |
---|
1965 | } |
---|
1966 | else |
---|
1967 | sLog.outError( "SPELL: unknown target coordinates for spell ID %u\n", m_spellInfo->Id ); |
---|
1968 | }break; |
---|
1969 | default: |
---|
1970 | break; |
---|
1971 | } |
---|
1972 | |
---|
1973 | if (unMaxTargets && TagUnitMap.size() > unMaxTargets) |
---|
1974 | { |
---|
1975 | // make sure one unit is always removed per iteration |
---|
1976 | uint32 removed_utarget = 0; |
---|
1977 | for (std::list<Unit*>::iterator itr = TagUnitMap.begin(), next; itr != TagUnitMap.end(); itr = next) |
---|
1978 | { |
---|
1979 | next = itr; |
---|
1980 | ++next; |
---|
1981 | if (!*itr) continue; |
---|
1982 | if ((*itr) == m_targets.getUnitTarget()) |
---|
1983 | { |
---|
1984 | TagUnitMap.erase(itr); |
---|
1985 | removed_utarget = 1; |
---|
1986 | // break; |
---|
1987 | } |
---|
1988 | } |
---|
1989 | // remove random units from the map |
---|
1990 | while (TagUnitMap.size() > unMaxTargets - removed_utarget) |
---|
1991 | { |
---|
1992 | uint32 poz = urand(0, TagUnitMap.size()-1); |
---|
1993 | for (std::list<Unit*>::iterator itr = TagUnitMap.begin(); itr != TagUnitMap.end(); ++itr, --poz) |
---|
1994 | { |
---|
1995 | if (!*itr) continue; |
---|
1996 | if (!poz) |
---|
1997 | { |
---|
1998 | TagUnitMap.erase(itr); |
---|
1999 | break; |
---|
2000 | } |
---|
2001 | } |
---|
2002 | } |
---|
2003 | // the player's target will always be added to the map |
---|
2004 | if (removed_utarget && m_targets.getUnitTarget()) |
---|
2005 | TagUnitMap.push_back(m_targets.getUnitTarget()); |
---|
2006 | } |
---|
2007 | } |
---|
2008 | |
---|
2009 | void Spell::prepare(SpellCastTargets * targets, Aura* triggeredByAura) |
---|
2010 | { |
---|
2011 | m_targets = *targets; |
---|
2012 | |
---|
2013 | m_spellState = SPELL_STATE_PREPARING; |
---|
2014 | |
---|
2015 | m_castPositionX = m_caster->GetPositionX(); |
---|
2016 | m_castPositionY = m_caster->GetPositionY(); |
---|
2017 | m_castPositionZ = m_caster->GetPositionZ(); |
---|
2018 | m_castOrientation = m_caster->GetOrientation(); |
---|
2019 | |
---|
2020 | if(triggeredByAura) |
---|
2021 | m_triggeredByAuraSpell = triggeredByAura->GetSpellProto(); |
---|
2022 | |
---|
2023 | // create and add update event for this spell |
---|
2024 | SpellEvent* Event = new SpellEvent(this); |
---|
2025 | m_caster->m_Events.AddEvent(Event, m_caster->m_Events.CalculateTime(1)); |
---|
2026 | |
---|
2027 | //Prevent casting at cast another spell (ServerSide check) |
---|
2028 | if(m_caster->IsNonMeleeSpellCasted(false, true) && m_cast_count) |
---|
2029 | { |
---|
2030 | SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS); |
---|
2031 | finish(false); |
---|
2032 | return; |
---|
2033 | } |
---|
2034 | |
---|
2035 | // Fill cost data |
---|
2036 | m_powerCost = CalculatePowerCost(); |
---|
2037 | |
---|
2038 | uint8 result = CanCast(true); |
---|
2039 | if(result != 0 && !IsAutoRepeat()) //always cast autorepeat dummy for triggering |
---|
2040 | { |
---|
2041 | if(triggeredByAura) |
---|
2042 | { |
---|
2043 | SendChannelUpdate(0); |
---|
2044 | triggeredByAura->SetAuraDuration(0); |
---|
2045 | } |
---|
2046 | SendCastResult(result); |
---|
2047 | finish(false); |
---|
2048 | return; |
---|
2049 | } |
---|
2050 | |
---|
2051 | // calculate cast time (calculated after first CanCast check to prevent charge counting for first CanCast fail) |
---|
2052 | m_casttime = GetSpellCastTime(m_spellInfo, this); |
---|
2053 | |
---|
2054 | // set timer base at cast time |
---|
2055 | ReSetTimer(); |
---|
2056 | |
---|
2057 | // stealth must be removed at cast starting (at show channel bar) |
---|
2058 | // skip triggered spell (item equip spell casting and other not explicit character casts/item uses) |
---|
2059 | if ( !m_IsTriggeredSpell && isSpellBreakStealth(m_spellInfo) ) |
---|
2060 | { |
---|
2061 | m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); |
---|
2062 | m_caster->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); |
---|
2063 | } |
---|
2064 | |
---|
2065 | if(m_IsTriggeredSpell) |
---|
2066 | cast(true); |
---|
2067 | else |
---|
2068 | { |
---|
2069 | m_caster->SetCurrentCastedSpell( this ); |
---|
2070 | m_selfContainer = &(m_caster->m_currentSpells[GetCurrentContainer()]); |
---|
2071 | SendSpellStart(); |
---|
2072 | } |
---|
2073 | } |
---|
2074 | |
---|
2075 | void Spell::cancel() |
---|
2076 | { |
---|
2077 | if(m_spellState == SPELL_STATE_FINISHED) |
---|
2078 | return; |
---|
2079 | |
---|
2080 | m_autoRepeat = false; |
---|
2081 | switch (m_spellState) |
---|
2082 | { |
---|
2083 | case SPELL_STATE_PREPARING: |
---|
2084 | case SPELL_STATE_DELAYED: |
---|
2085 | { |
---|
2086 | SendInterrupted(0); |
---|
2087 | SendCastResult(SPELL_FAILED_INTERRUPTED); |
---|
2088 | } break; |
---|
2089 | |
---|
2090 | case SPELL_STATE_CASTING: |
---|
2091 | { |
---|
2092 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit) |
---|
2093 | { |
---|
2094 | if( ihit->missCondition == SPELL_MISS_NONE ) |
---|
2095 | { |
---|
2096 | Unit* unit = m_caster->GetGUID()==(*ihit).targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID); |
---|
2097 | if( unit && unit->isAlive() ) |
---|
2098 | unit->RemoveAurasDueToSpell(m_spellInfo->Id); |
---|
2099 | } |
---|
2100 | } |
---|
2101 | |
---|
2102 | m_caster->RemoveAurasDueToSpell(m_spellInfo->Id); |
---|
2103 | SendChannelUpdate(0); |
---|
2104 | SendInterrupted(0); |
---|
2105 | SendCastResult(SPELL_FAILED_INTERRUPTED); |
---|
2106 | } break; |
---|
2107 | |
---|
2108 | default: |
---|
2109 | { |
---|
2110 | } break; |
---|
2111 | } |
---|
2112 | |
---|
2113 | finish(false); |
---|
2114 | m_caster->RemoveDynObject(m_spellInfo->Id); |
---|
2115 | m_caster->RemoveGameObject(m_spellInfo->Id,true); |
---|
2116 | } |
---|
2117 | |
---|
2118 | void Spell::cast(bool skipCheck) |
---|
2119 | { |
---|
2120 | uint8 castResult = 0; |
---|
2121 | |
---|
2122 | // update pointers base at GUIDs to prevent access to non-existed already object |
---|
2123 | UpdatePointers(); |
---|
2124 | |
---|
2125 | // cancel at lost main target unit |
---|
2126 | if(!m_targets.getUnitTarget() && m_targets.getUnitTargetGUID() && m_targets.getUnitTargetGUID() != m_caster->GetGUID()) |
---|
2127 | { |
---|
2128 | cancel(); |
---|
2129 | return; |
---|
2130 | } |
---|
2131 | |
---|
2132 | if(m_caster->GetTypeId() != TYPEID_PLAYER && m_targets.getUnitTarget() && m_targets.getUnitTarget() != m_caster) |
---|
2133 | m_caster->SetInFront(m_targets.getUnitTarget()); |
---|
2134 | |
---|
2135 | castResult = CheckPower(); |
---|
2136 | if(castResult != 0) |
---|
2137 | { |
---|
2138 | SendCastResult(castResult); |
---|
2139 | finish(false); |
---|
2140 | return; |
---|
2141 | } |
---|
2142 | |
---|
2143 | // triggered cast called from Spell::prepare where it was already checked |
---|
2144 | if(!skipCheck) |
---|
2145 | { |
---|
2146 | castResult = CanCast(false); |
---|
2147 | if(castResult != 0) |
---|
2148 | { |
---|
2149 | SendCastResult(castResult); |
---|
2150 | finish(false); |
---|
2151 | return; |
---|
2152 | } |
---|
2153 | } |
---|
2154 | |
---|
2155 | // Conflagrate - consumes immolate |
---|
2156 | if ((m_spellInfo->TargetAuraState == AURA_STATE_IMMOLATE) && m_targets.getUnitTarget()) |
---|
2157 | { |
---|
2158 | // for caster applied auras only |
---|
2159 | Unit::AuraList const &mPeriodic = m_targets.getUnitTarget()->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE); |
---|
2160 | for(Unit::AuraList::const_iterator i = mPeriodic.begin(); i != mPeriodic.end(); ++i) |
---|
2161 | { |
---|
2162 | if( (*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK && ((*i)->GetSpellProto()->SpellFamilyFlags & 4) && |
---|
2163 | (*i)->GetCasterGUID()==m_caster->GetGUID() ) |
---|
2164 | { |
---|
2165 | m_targets.getUnitTarget()->RemoveAura((*i)->GetId(), (*i)->GetEffIndex()); |
---|
2166 | break; |
---|
2167 | } |
---|
2168 | } |
---|
2169 | } |
---|
2170 | |
---|
2171 | // traded items have trade slot instead of guid in m_itemTargetGUID |
---|
2172 | // set to real guid to be sent later to the client |
---|
2173 | m_targets.updateTradeSlotItem(); |
---|
2174 | |
---|
2175 | // CAST SPELL |
---|
2176 | SendSpellCooldown(); |
---|
2177 | |
---|
2178 | TakePower(); |
---|
2179 | TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot |
---|
2180 | FillTargetMap(); |
---|
2181 | |
---|
2182 | if(m_spellState == SPELL_STATE_FINISHED) // stop cast if spell marked as finish somewhere in Take*/FillTargetMap |
---|
2183 | return; |
---|
2184 | |
---|
2185 | SendCastResult(castResult); |
---|
2186 | SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()... |
---|
2187 | |
---|
2188 | // Pass cast spell event to handler (not send triggered by aura spells) |
---|
2189 | if (m_spellInfo->DmgClass != SPELL_DAMAGE_CLASS_MELEE && m_spellInfo->DmgClass != SPELL_DAMAGE_CLASS_RANGED && !m_triggeredByAuraSpell) |
---|
2190 | { |
---|
2191 | m_caster->ProcDamageAndSpell(m_targets.getUnitTarget(), PROC_FLAG_CAST_SPELL, PROC_FLAG_NONE, 0, SPELL_SCHOOL_MASK_NONE, m_spellInfo, m_IsTriggeredSpell); |
---|
2192 | |
---|
2193 | // update pointers base at GUIDs to prevent access to non-existed already object |
---|
2194 | UpdatePointers(); // pointers can be invalidate at triggered spell casting |
---|
2195 | } |
---|
2196 | |
---|
2197 | // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells |
---|
2198 | if (m_spellInfo->speed > 0.0f) |
---|
2199 | { |
---|
2200 | |
---|
2201 | // Remove used for cast item if need (it can be already NULL after TakeReagents call |
---|
2202 | // in case delayed spell remove item at cast delay start |
---|
2203 | TakeCastItem(); |
---|
2204 | |
---|
2205 | // Okay, maps created, now prepare flags |
---|
2206 | m_immediateHandled = false; |
---|
2207 | m_spellState = SPELL_STATE_DELAYED; |
---|
2208 | SetDelayStart(0); |
---|
2209 | } |
---|
2210 | else |
---|
2211 | { |
---|
2212 | // Immediate spell, no big deal |
---|
2213 | handle_immediate(); |
---|
2214 | } |
---|
2215 | } |
---|
2216 | |
---|
2217 | void Spell::handle_immediate() |
---|
2218 | { |
---|
2219 | // start channeling if applicable |
---|
2220 | if(IsChanneledSpell(m_spellInfo)) |
---|
2221 | { |
---|
2222 | m_spellState = SPELL_STATE_CASTING; |
---|
2223 | SendChannelStart(GetSpellDuration(m_spellInfo)); |
---|
2224 | } |
---|
2225 | |
---|
2226 | // process immediate effects (items, ground, etc.) also initialize some variables |
---|
2227 | _handle_immediate_phase(); |
---|
2228 | |
---|
2229 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit) |
---|
2230 | DoAllEffectOnTarget(&(*ihit)); |
---|
2231 | |
---|
2232 | for(std::list<GOTargetInfo>::iterator ihit= m_UniqueGOTargetInfo.begin();ihit != m_UniqueGOTargetInfo.end();++ihit) |
---|
2233 | DoAllEffectOnTarget(&(*ihit)); |
---|
2234 | |
---|
2235 | // spell is finished, perform some last features of the spell here |
---|
2236 | _handle_finish_phase(); |
---|
2237 | |
---|
2238 | // Remove used for cast item if need (it can be already NULL after TakeReagents call |
---|
2239 | TakeCastItem(); |
---|
2240 | |
---|
2241 | if(m_spellState != SPELL_STATE_CASTING) |
---|
2242 | finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell) |
---|
2243 | } |
---|
2244 | |
---|
2245 | uint64 Spell::handle_delayed(uint64 t_offset) |
---|
2246 | { |
---|
2247 | uint64 next_time = 0; |
---|
2248 | |
---|
2249 | if (!m_immediateHandled) |
---|
2250 | { |
---|
2251 | _handle_immediate_phase(); |
---|
2252 | m_immediateHandled = true; |
---|
2253 | } |
---|
2254 | |
---|
2255 | // now recheck units targeting correctness (need before any effects apply to prevent adding immunity at first effect not allow apply second spell effect and similar cases) |
---|
2256 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end();++ihit) |
---|
2257 | { |
---|
2258 | if (ihit->processed == false) |
---|
2259 | { |
---|
2260 | if ( ihit->timeDelay <= t_offset ) |
---|
2261 | DoAllEffectOnTarget(&(*ihit)); |
---|
2262 | else if( next_time == 0 || ihit->timeDelay < next_time ) |
---|
2263 | next_time = ihit->timeDelay; |
---|
2264 | } |
---|
2265 | } |
---|
2266 | |
---|
2267 | // now recheck gameobject targeting correctness |
---|
2268 | for(std::list<GOTargetInfo>::iterator ighit= m_UniqueGOTargetInfo.begin(); ighit != m_UniqueGOTargetInfo.end();++ighit) |
---|
2269 | { |
---|
2270 | if (ighit->processed == false) |
---|
2271 | { |
---|
2272 | if ( ighit->timeDelay <= t_offset ) |
---|
2273 | DoAllEffectOnTarget(&(*ighit)); |
---|
2274 | else if( next_time == 0 || ighit->timeDelay < next_time ) |
---|
2275 | next_time = ighit->timeDelay; |
---|
2276 | } |
---|
2277 | } |
---|
2278 | // All targets passed - need finish phase |
---|
2279 | if (next_time == 0) |
---|
2280 | { |
---|
2281 | // spell is finished, perform some last features of the spell here |
---|
2282 | _handle_finish_phase(); |
---|
2283 | |
---|
2284 | finish(true); // successfully finish spell cast |
---|
2285 | |
---|
2286 | // return zero, spell is finished now |
---|
2287 | return 0; |
---|
2288 | } |
---|
2289 | else |
---|
2290 | { |
---|
2291 | // spell is unfinished, return next execution time |
---|
2292 | return next_time; |
---|
2293 | } |
---|
2294 | } |
---|
2295 | |
---|
2296 | void Spell::_handle_immediate_phase() |
---|
2297 | { |
---|
2298 | // handle some immediate features of the spell here |
---|
2299 | HandleThreatSpells(m_spellInfo->Id); |
---|
2300 | |
---|
2301 | m_needSpellLog = IsNeedSendToClient(); |
---|
2302 | for(uint32 j = 0;j<3;j++) |
---|
2303 | { |
---|
2304 | if(m_spellInfo->Effect[j]==0) |
---|
2305 | continue; |
---|
2306 | |
---|
2307 | // apply Send Event effect to ground in case empty target lists |
---|
2308 | if( m_spellInfo->Effect[j] == SPELL_EFFECT_SEND_EVENT && !HaveTargetsForEffect(j) ) |
---|
2309 | { |
---|
2310 | HandleEffects(NULL,NULL,NULL, j); |
---|
2311 | continue; |
---|
2312 | } |
---|
2313 | |
---|
2314 | // Don't do spell log, if is school damage spell |
---|
2315 | if(m_spellInfo->Effect[j] == SPELL_EFFECT_SCHOOL_DAMAGE || m_spellInfo->Effect[j] == 0) |
---|
2316 | m_needSpellLog = false; |
---|
2317 | |
---|
2318 | uint32 EffectChainTarget = m_spellInfo->EffectChainTarget[j]; |
---|
2319 | if(m_originalCaster) |
---|
2320 | if(Player* modOwner = m_originalCaster->GetSpellModOwner()) |
---|
2321 | modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_JUMP_TARGETS, EffectChainTarget, this); |
---|
2322 | |
---|
2323 | // initialize multipliers |
---|
2324 | m_damageMultipliers[j] = 1.0f; |
---|
2325 | if( (m_spellInfo->EffectImplicitTargetA[j] == TARGET_CHAIN_DAMAGE || m_spellInfo->EffectImplicitTargetA[j] == TARGET_CHAIN_HEAL) && |
---|
2326 | (EffectChainTarget > 1) ) |
---|
2327 | m_applyMultiplierMask |= 1 << j; |
---|
2328 | } |
---|
2329 | |
---|
2330 | // initialize Diminishing Returns Data |
---|
2331 | m_diminishLevel = DIMINISHING_LEVEL_1; |
---|
2332 | m_diminishGroup = DIMINISHING_NONE; |
---|
2333 | |
---|
2334 | // process items |
---|
2335 | for(std::list<ItemTargetInfo>::iterator ihit= m_UniqueItemInfo.begin();ihit != m_UniqueItemInfo.end();++ihit) |
---|
2336 | DoAllEffectOnTarget(&(*ihit)); |
---|
2337 | |
---|
2338 | // process ground |
---|
2339 | for(uint32 j = 0;j<3;j++) |
---|
2340 | { |
---|
2341 | // persistent area auras target only the ground |
---|
2342 | if(m_spellInfo->Effect[j] == SPELL_EFFECT_PERSISTENT_AREA_AURA) |
---|
2343 | HandleEffects(NULL,NULL,NULL, j); |
---|
2344 | } |
---|
2345 | } |
---|
2346 | |
---|
2347 | void Spell::_handle_finish_phase() |
---|
2348 | { |
---|
2349 | // spell log |
---|
2350 | if(m_needSpellLog) |
---|
2351 | SendLogExecute(); |
---|
2352 | } |
---|
2353 | |
---|
2354 | void Spell::SendSpellCooldown() |
---|
2355 | { |
---|
2356 | if(m_caster->GetTypeId() != TYPEID_PLAYER) |
---|
2357 | return; |
---|
2358 | |
---|
2359 | Player* _player = (Player*)m_caster; |
---|
2360 | // Add cooldown for max (disable spell) |
---|
2361 | // Cooldown started on SendCooldownEvent call |
---|
2362 | if (m_spellInfo->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE) |
---|
2363 | { |
---|
2364 | _player->AddSpellCooldown(m_spellInfo->Id, 0, time(NULL) - 1); |
---|
2365 | return; |
---|
2366 | } |
---|
2367 | |
---|
2368 | // init cooldown values |
---|
2369 | uint32 cat = 0; |
---|
2370 | int32 rec = -1; |
---|
2371 | int32 catrec = -1; |
---|
2372 | |
---|
2373 | // some special item spells without correct cooldown in SpellInfo |
---|
2374 | // cooldown information stored in item prototype |
---|
2375 | // This used in same way in WorldSession::HandleItemQuerySingleOpcode data sending to client. |
---|
2376 | |
---|
2377 | if(m_CastItem) |
---|
2378 | { |
---|
2379 | ItemPrototype const* proto = m_CastItem->GetProto(); |
---|
2380 | if(proto) |
---|
2381 | { |
---|
2382 | for(int idx = 0; idx < 5; ++idx) |
---|
2383 | { |
---|
2384 | if(proto->Spells[idx].SpellId == m_spellInfo->Id) |
---|
2385 | { |
---|
2386 | cat = proto->Spells[idx].SpellCategory; |
---|
2387 | rec = proto->Spells[idx].SpellCooldown; |
---|
2388 | catrec = proto->Spells[idx].SpellCategoryCooldown; |
---|
2389 | break; |
---|
2390 | } |
---|
2391 | } |
---|
2392 | } |
---|
2393 | } |
---|
2394 | |
---|
2395 | // if no cooldown found above then base at DBC data |
---|
2396 | if(rec < 0 && catrec < 0) |
---|
2397 | { |
---|
2398 | cat = m_spellInfo->Category; |
---|
2399 | rec = m_spellInfo->RecoveryTime; |
---|
2400 | catrec = m_spellInfo->CategoryRecoveryTime; |
---|
2401 | } |
---|
2402 | |
---|
2403 | // shoot spells used equipped item cooldown values already assigned in GetAttackTime(RANGED_ATTACK) |
---|
2404 | // prevent 0 cooldowns set by another way |
---|
2405 | if (rec <= 0 && catrec <= 0 && (cat == 76 || cat == 351)) |
---|
2406 | rec = _player->GetAttackTime(RANGED_ATTACK); |
---|
2407 | |
---|
2408 | // Now we have cooldown data (if found any), time to apply mods |
---|
2409 | if(rec > 0) |
---|
2410 | _player->ApplySpellMod(m_spellInfo->Id, SPELLMOD_COOLDOWN, rec, this); |
---|
2411 | |
---|
2412 | if(catrec > 0) |
---|
2413 | _player->ApplySpellMod(m_spellInfo->Id, SPELLMOD_COOLDOWN, catrec, this); |
---|
2414 | |
---|
2415 | // replace negative cooldowns by 0 |
---|
2416 | if (rec < 0) rec = 0; |
---|
2417 | if (catrec < 0) catrec = 0; |
---|
2418 | |
---|
2419 | // no cooldown after applying spell mods |
---|
2420 | if( rec == 0 && catrec == 0) |
---|
2421 | return; |
---|
2422 | |
---|
2423 | time_t curTime = time(NULL); |
---|
2424 | |
---|
2425 | time_t catrecTime = catrec ? curTime+catrec/1000 : 0; // in secs |
---|
2426 | time_t recTime = rec ? curTime+rec/1000 : catrecTime;// in secs |
---|
2427 | |
---|
2428 | // self spell cooldown |
---|
2429 | if(recTime > 0) |
---|
2430 | _player->AddSpellCooldown(m_spellInfo->Id, m_CastItem ? m_CastItem->GetEntry() : 0, recTime); |
---|
2431 | |
---|
2432 | // category spells |
---|
2433 | if (catrec > 0) |
---|
2434 | { |
---|
2435 | SpellCategoryStore::const_iterator i_scstore = sSpellCategoryStore.find(cat); |
---|
2436 | if(i_scstore != sSpellCategoryStore.end()) |
---|
2437 | { |
---|
2438 | for(SpellCategorySet::const_iterator i_scset = i_scstore->second.begin(); i_scset != i_scstore->second.end(); ++i_scset) |
---|
2439 | { |
---|
2440 | if(*i_scset == m_spellInfo->Id) // skip main spell, already handled above |
---|
2441 | continue; |
---|
2442 | |
---|
2443 | _player->AddSpellCooldown(m_spellInfo->Id, m_CastItem ? m_CastItem->GetEntry() : 0, catrecTime); |
---|
2444 | } |
---|
2445 | } |
---|
2446 | } |
---|
2447 | } |
---|
2448 | |
---|
2449 | void Spell::update(uint32 difftime) |
---|
2450 | { |
---|
2451 | // update pointers based at it's GUIDs |
---|
2452 | UpdatePointers(); |
---|
2453 | |
---|
2454 | if(m_targets.getUnitTargetGUID() && !m_targets.getUnitTarget()) |
---|
2455 | { |
---|
2456 | cancel(); |
---|
2457 | return; |
---|
2458 | } |
---|
2459 | |
---|
2460 | // check if the player caster has moved before the spell finished |
---|
2461 | if ((m_caster->GetTypeId() == TYPEID_PLAYER && m_timer != 0) && |
---|
2462 | (m_castPositionX != m_caster->GetPositionX() || m_castPositionY != m_caster->GetPositionY() || m_castPositionZ != m_caster->GetPositionZ()) && |
---|
2463 | (m_spellInfo->Effect[0] != SPELL_EFFECT_STUCK || !m_caster->HasUnitMovementFlag(MOVEMENTFLAG_FALLING))) |
---|
2464 | { |
---|
2465 | // always cancel for channeled spells |
---|
2466 | if( m_spellState == SPELL_STATE_CASTING ) |
---|
2467 | cancel(); |
---|
2468 | // don't cancel for melee, autorepeat, triggered and instant spells |
---|
2469 | else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_MOVEMENT)) |
---|
2470 | cancel(); |
---|
2471 | } |
---|
2472 | |
---|
2473 | switch(m_spellState) |
---|
2474 | { |
---|
2475 | case SPELL_STATE_PREPARING: |
---|
2476 | { |
---|
2477 | if(m_timer) |
---|
2478 | { |
---|
2479 | if(difftime >= m_timer) |
---|
2480 | m_timer = 0; |
---|
2481 | else |
---|
2482 | m_timer -= difftime; |
---|
2483 | } |
---|
2484 | |
---|
2485 | if(m_timer == 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat()) |
---|
2486 | cast(); |
---|
2487 | } break; |
---|
2488 | case SPELL_STATE_CASTING: |
---|
2489 | { |
---|
2490 | if(m_timer > 0) |
---|
2491 | { |
---|
2492 | if( m_caster->GetTypeId() == TYPEID_PLAYER ) |
---|
2493 | { |
---|
2494 | // check if player has jumped before the channeling finished |
---|
2495 | if(m_caster->HasUnitMovementFlag(MOVEMENTFLAG_JUMPING)) |
---|
2496 | cancel(); |
---|
2497 | |
---|
2498 | // check for incapacitating player states |
---|
2499 | if( m_caster->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_CONFUSED)) |
---|
2500 | cancel(); |
---|
2501 | |
---|
2502 | // check if player has turned if flag is set |
---|
2503 | if( m_spellInfo->ChannelInterruptFlags & CHANNEL_FLAG_TURNING && m_castOrientation != m_caster->GetOrientation() ) |
---|
2504 | cancel(); |
---|
2505 | } |
---|
2506 | |
---|
2507 | // check if there are alive targets left |
---|
2508 | if (!IsAliveUnitPresentInTargetList()) |
---|
2509 | { |
---|
2510 | SendChannelUpdate(0); |
---|
2511 | finish(); |
---|
2512 | } |
---|
2513 | |
---|
2514 | if(difftime >= m_timer) |
---|
2515 | m_timer = 0; |
---|
2516 | else |
---|
2517 | m_timer -= difftime; |
---|
2518 | } |
---|
2519 | |
---|
2520 | if(m_timer == 0) |
---|
2521 | { |
---|
2522 | SendChannelUpdate(0); |
---|
2523 | |
---|
2524 | // channeled spell processed independently for quest targeting |
---|
2525 | // cast at creature (or GO) quest objectives update at successful cast channel finished |
---|
2526 | // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... ) |
---|
2527 | if( m_caster->GetTypeId() == TYPEID_PLAYER && !IsAutoRepeat() && !IsNextMeleeSwingSpell() ) |
---|
2528 | { |
---|
2529 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit) |
---|
2530 | { |
---|
2531 | TargetInfo* target = &*ihit; |
---|
2532 | if(!IS_CREATURE_GUID(target->targetGUID)) |
---|
2533 | continue; |
---|
2534 | |
---|
2535 | Unit* unit = m_caster->GetGUID()==target->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster,target->targetGUID); |
---|
2536 | if (unit==NULL) |
---|
2537 | continue; |
---|
2538 | |
---|
2539 | ((Player*)m_caster)->CastedCreatureOrGO(unit->GetEntry(),unit->GetGUID(),m_spellInfo->Id); |
---|
2540 | } |
---|
2541 | |
---|
2542 | for(std::list<GOTargetInfo>::iterator ihit= m_UniqueGOTargetInfo.begin();ihit != m_UniqueGOTargetInfo.end();++ihit) |
---|
2543 | { |
---|
2544 | GOTargetInfo* target = &*ihit; |
---|
2545 | |
---|
2546 | GameObject* go = ObjectAccessor::GetGameObject(*m_caster, target->targetGUID); |
---|
2547 | if(!go) |
---|
2548 | continue; |
---|
2549 | |
---|
2550 | ((Player*)m_caster)->CastedCreatureOrGO(go->GetEntry(),go->GetGUID(),m_spellInfo->Id); |
---|
2551 | } |
---|
2552 | } |
---|
2553 | |
---|
2554 | finish(); |
---|
2555 | } |
---|
2556 | } break; |
---|
2557 | default: |
---|
2558 | { |
---|
2559 | }break; |
---|
2560 | } |
---|
2561 | } |
---|
2562 | |
---|
2563 | void Spell::finish(bool ok) |
---|
2564 | { |
---|
2565 | if(!m_caster) |
---|
2566 | return; |
---|
2567 | |
---|
2568 | if(m_spellState == SPELL_STATE_FINISHED) |
---|
2569 | return; |
---|
2570 | |
---|
2571 | m_spellState = SPELL_STATE_FINISHED; |
---|
2572 | |
---|
2573 | //remove spell mods |
---|
2574 | if (m_caster->GetTypeId() == TYPEID_PLAYER) |
---|
2575 | ((Player*)m_caster)->RemoveSpellMods(this); |
---|
2576 | |
---|
2577 | // other code related only to successfully finished spells |
---|
2578 | if(!ok) |
---|
2579 | return; |
---|
2580 | |
---|
2581 | //handle SPELL_AURA_ADD_TARGET_TRIGGER auras |
---|
2582 | Unit::AuraList const& targetTriggers = m_caster->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER); |
---|
2583 | for(Unit::AuraList::const_iterator i = targetTriggers.begin(); i != targetTriggers.end(); ++i) |
---|
2584 | { |
---|
2585 | SpellEntry const *auraSpellInfo = (*i)->GetSpellProto(); |
---|
2586 | uint32 auraSpellIdx = (*i)->GetEffIndex(); |
---|
2587 | if (IsAffectedBy(auraSpellInfo, auraSpellIdx)) |
---|
2588 | { |
---|
2589 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit) |
---|
2590 | if( ihit->effectMask & (1<<auraSpellIdx) ) |
---|
2591 | { |
---|
2592 | // check m_caster->GetGUID() let load auras at login and speedup most often case |
---|
2593 | Unit *unit = m_caster->GetGUID()== ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID); |
---|
2594 | if (unit && unit->isAlive()) |
---|
2595 | { |
---|
2596 | // Calculate chance at that moment (can be depend for example from combo points) |
---|
2597 | int32 chance = m_caster->CalculateSpellDamage(auraSpellInfo, auraSpellIdx, (*i)->GetBasePoints(),unit); |
---|
2598 | |
---|
2599 | if(roll_chance_i(chance)) |
---|
2600 | m_caster->CastSpell(unit, auraSpellInfo->EffectTriggerSpell[auraSpellIdx], true, NULL, (*i)); |
---|
2601 | } |
---|
2602 | } |
---|
2603 | } |
---|
2604 | } |
---|
2605 | |
---|
2606 | if (IsMeleeAttackResetSpell()) |
---|
2607 | { |
---|
2608 | m_caster->resetAttackTimer(BASE_ATTACK); |
---|
2609 | if(m_caster->haveOffhandWeapon()) |
---|
2610 | m_caster->resetAttackTimer(OFF_ATTACK); |
---|
2611 | } |
---|
2612 | |
---|
2613 | /*if (IsRangedAttackResetSpell()) |
---|
2614 | m_caster->resetAttackTimer(RANGED_ATTACK);*/ |
---|
2615 | |
---|
2616 | // Clear combo at finish state |
---|
2617 | if(m_caster->GetTypeId() == TYPEID_PLAYER && NeedsComboPoints(m_spellInfo)) |
---|
2618 | ((Player*)m_caster)->ClearComboPoints(); |
---|
2619 | |
---|
2620 | // call triggered spell only at successful cast (after clear combo points -> for add some if need) |
---|
2621 | if(!m_TriggerSpells.empty()) |
---|
2622 | TriggerSpell(); |
---|
2623 | |
---|
2624 | // Stop Attack for some spells |
---|
2625 | if( m_spellInfo->Attributes & SPELL_ATTR_STOP_ATTACK_TARGET ) |
---|
2626 | m_caster->AttackStop(); |
---|
2627 | } |
---|
2628 | |
---|
2629 | void Spell::SendCastResult(uint8 result) |
---|
2630 | { |
---|
2631 | if (m_caster->GetTypeId() != TYPEID_PLAYER) |
---|
2632 | return; |
---|
2633 | |
---|
2634 | if(((Player*)m_caster)->GetSession()->PlayerLoading()) // don't send cast results at loading time |
---|
2635 | return; |
---|
2636 | |
---|
2637 | if(result != 0) |
---|
2638 | { |
---|
2639 | WorldPacket data(SMSG_CAST_FAILED, (4+1+1)); |
---|
2640 | data << uint32(m_spellInfo->Id); |
---|
2641 | data << uint8(result); // problem |
---|
2642 | data << uint8(m_cast_count); // single cast or multi 2.3 (0/1) |
---|
2643 | switch (result) |
---|
2644 | { |
---|
2645 | case SPELL_FAILED_REQUIRES_SPELL_FOCUS: |
---|
2646 | data << uint32(m_spellInfo->RequiresSpellFocus); |
---|
2647 | break; |
---|
2648 | case SPELL_FAILED_REQUIRES_AREA: |
---|
2649 | // hardcode areas limitation case |
---|
2650 | if( m_spellInfo->Id==41618 || m_spellInfo->Id==41620 ) |
---|
2651 | data << uint32(3842); |
---|
2652 | else if( m_spellInfo->Id==41617 || m_spellInfo->Id==41619 ) |
---|
2653 | data << uint32(3905); |
---|
2654 | // normal case |
---|
2655 | else |
---|
2656 | data << uint32(m_spellInfo->AreaId); |
---|
2657 | break; |
---|
2658 | case SPELL_FAILED_TOTEMS: |
---|
2659 | if(m_spellInfo->Totem[0]) |
---|
2660 | data << uint32(m_spellInfo->Totem[0]); |
---|
2661 | if(m_spellInfo->Totem[1]) |
---|
2662 | data << uint32(m_spellInfo->Totem[1]); |
---|
2663 | break; |
---|
2664 | case SPELL_FAILED_TOTEM_CATEGORY: |
---|
2665 | if(m_spellInfo->TotemCategory[0]) |
---|
2666 | data << uint32(m_spellInfo->TotemCategory[0]); |
---|
2667 | if(m_spellInfo->TotemCategory[1]) |
---|
2668 | data << uint32(m_spellInfo->TotemCategory[1]); |
---|
2669 | break; |
---|
2670 | case SPELL_FAILED_EQUIPPED_ITEM_CLASS: |
---|
2671 | data << uint32(m_spellInfo->EquippedItemClass); |
---|
2672 | data << uint32(m_spellInfo->EquippedItemSubClassMask); |
---|
2673 | data << uint32(m_spellInfo->EquippedItemInventoryTypeMask); |
---|
2674 | break; |
---|
2675 | } |
---|
2676 | ((Player*)m_caster)->GetSession()->SendPacket(&data); |
---|
2677 | } |
---|
2678 | else |
---|
2679 | { |
---|
2680 | WorldPacket data(SMSG_CLEAR_EXTRA_AURA_INFO, (8+4)); |
---|
2681 | data.append(m_caster->GetPackGUID()); |
---|
2682 | data << uint32(m_spellInfo->Id); |
---|
2683 | ((Player*)m_caster)->GetSession()->SendPacket(&data); |
---|
2684 | } |
---|
2685 | } |
---|
2686 | |
---|
2687 | void Spell::SendSpellStart() |
---|
2688 | { |
---|
2689 | if(!IsNeedSendToClient()) |
---|
2690 | return; |
---|
2691 | |
---|
2692 | sLog.outDebug("Sending SMSG_SPELL_START id=%u",m_spellInfo->Id); |
---|
2693 | |
---|
2694 | uint16 castFlags = CAST_FLAG_UNKNOWN1; |
---|
2695 | if(IsRangedSpell()) |
---|
2696 | castFlags |= CAST_FLAG_AMMO; |
---|
2697 | |
---|
2698 | Unit * target; |
---|
2699 | if(!m_targets.getUnitTarget()) |
---|
2700 | target = m_caster; |
---|
2701 | else |
---|
2702 | target = m_targets.getUnitTarget(); |
---|
2703 | |
---|
2704 | WorldPacket data(SMSG_SPELL_START, (8+8+4+4+2)); |
---|
2705 | if(m_CastItem) |
---|
2706 | data.append(m_CastItem->GetPackGUID()); |
---|
2707 | else |
---|
2708 | data.append(m_caster->GetPackGUID()); |
---|
2709 | |
---|
2710 | data.append(m_caster->GetPackGUID()); |
---|
2711 | data << uint32(m_spellInfo->Id); |
---|
2712 | data << uint8(m_cast_count); // single cast or multi 2.3 (0/1) |
---|
2713 | data << uint16(castFlags); |
---|
2714 | data << uint32(m_timer); |
---|
2715 | |
---|
2716 | m_targets.write(&data); |
---|
2717 | |
---|
2718 | if( castFlags & CAST_FLAG_AMMO ) |
---|
2719 | WriteAmmoToPacket(&data); |
---|
2720 | |
---|
2721 | m_caster->SendMessageToSet(&data, true); |
---|
2722 | } |
---|
2723 | |
---|
2724 | void Spell::SendSpellGo() |
---|
2725 | { |
---|
2726 | // not send invisible spell casting |
---|
2727 | if(!IsNeedSendToClient()) |
---|
2728 | return; |
---|
2729 | |
---|
2730 | sLog.outDebug("Sending SMSG_SPELL_GO id=%u",m_spellInfo->Id); |
---|
2731 | |
---|
2732 | Unit * target; |
---|
2733 | if(!m_targets.getUnitTarget()) |
---|
2734 | target = m_caster; |
---|
2735 | else |
---|
2736 | target = m_targets.getUnitTarget(); |
---|
2737 | |
---|
2738 | uint16 castFlags = CAST_FLAG_UNKNOWN3; |
---|
2739 | if(IsRangedSpell()) |
---|
2740 | castFlags |= CAST_FLAG_AMMO; |
---|
2741 | |
---|
2742 | WorldPacket data(SMSG_SPELL_GO, 50); // guess size |
---|
2743 | if(m_CastItem) |
---|
2744 | data.append(m_CastItem->GetPackGUID()); |
---|
2745 | else |
---|
2746 | data.append(m_caster->GetPackGUID()); |
---|
2747 | |
---|
2748 | data.append(m_caster->GetPackGUID()); |
---|
2749 | data << uint32(m_spellInfo->Id); |
---|
2750 | data << uint16(castFlags); |
---|
2751 | data << uint32(getMSTime()); // timestamp |
---|
2752 | |
---|
2753 | WriteSpellGoTargets(&data); |
---|
2754 | |
---|
2755 | m_targets.write(&data); |
---|
2756 | |
---|
2757 | if( castFlags & CAST_FLAG_AMMO ) |
---|
2758 | WriteAmmoToPacket(&data); |
---|
2759 | |
---|
2760 | m_caster->SendMessageToSet(&data, true); |
---|
2761 | } |
---|
2762 | |
---|
2763 | void Spell::WriteAmmoToPacket( WorldPacket * data ) |
---|
2764 | { |
---|
2765 | uint32 ammoInventoryType = 0; |
---|
2766 | uint32 ammoDisplayID = 0; |
---|
2767 | |
---|
2768 | if (m_caster->GetTypeId() == TYPEID_PLAYER) |
---|
2769 | { |
---|
2770 | Item *pItem = ((Player*)m_caster)->GetWeaponForAttack( RANGED_ATTACK ); |
---|
2771 | if(pItem) |
---|
2772 | { |
---|
2773 | ammoInventoryType = pItem->GetProto()->InventoryType; |
---|
2774 | if( ammoInventoryType == INVTYPE_THROWN ) |
---|
2775 | ammoDisplayID = pItem->GetProto()->DisplayInfoID; |
---|
2776 | else |
---|
2777 | { |
---|
2778 | uint32 ammoID = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID); |
---|
2779 | if(ammoID) |
---|
2780 | { |
---|
2781 | ItemPrototype const *pProto = objmgr.GetItemPrototype( ammoID ); |
---|
2782 | if(pProto) |
---|
2783 | { |
---|
2784 | ammoDisplayID = pProto->DisplayInfoID; |
---|
2785 | ammoInventoryType = pProto->InventoryType; |
---|
2786 | } |
---|
2787 | } |
---|
2788 | else if(m_caster->GetDummyAura(46699)) // Requires No Ammo |
---|
2789 | { |
---|
2790 | ammoDisplayID = 5996; // normal arrow |
---|
2791 | ammoInventoryType = INVTYPE_AMMO; |
---|
2792 | } |
---|
2793 | } |
---|
2794 | } |
---|
2795 | } |
---|
2796 | // TODO: implement selection ammo data based at ranged weapon stored in equipmodel/equipinfo/equipslot fields |
---|
2797 | |
---|
2798 | *data << uint32(ammoDisplayID); |
---|
2799 | *data << uint32(ammoInventoryType); |
---|
2800 | } |
---|
2801 | |
---|
2802 | void Spell::WriteSpellGoTargets( WorldPacket * data ) |
---|
2803 | { |
---|
2804 | *data << (uint8)m_countOfHit; |
---|
2805 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit) |
---|
2806 | if ((*ihit).missCondition == SPELL_MISS_NONE) // Add only hits |
---|
2807 | *data << uint64(ihit->targetGUID); |
---|
2808 | |
---|
2809 | for(std::list<GOTargetInfo>::iterator ighit= m_UniqueGOTargetInfo.begin();ighit != m_UniqueGOTargetInfo.end();++ighit) |
---|
2810 | *data << uint64(ighit->targetGUID); // Always hits |
---|
2811 | |
---|
2812 | *data << (uint8)m_countOfMiss; |
---|
2813 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit) |
---|
2814 | { |
---|
2815 | if( ihit->missCondition != SPELL_MISS_NONE ) // Add only miss |
---|
2816 | { |
---|
2817 | *data << uint64(ihit->targetGUID); |
---|
2818 | *data << uint8(ihit->missCondition); |
---|
2819 | if( ihit->missCondition == SPELL_MISS_REFLECT ) |
---|
2820 | *data << uint8(ihit->reflectResult); |
---|
2821 | } |
---|
2822 | } |
---|
2823 | } |
---|
2824 | |
---|
2825 | void Spell::SendLogExecute() |
---|
2826 | { |
---|
2827 | Unit *target = m_targets.getUnitTarget() ? m_targets.getUnitTarget() : m_caster; |
---|
2828 | |
---|
2829 | WorldPacket data(SMSG_SPELLLOGEXECUTE, (8+4+4+4+4+8)); |
---|
2830 | |
---|
2831 | if(m_caster->GetTypeId() == TYPEID_PLAYER) |
---|
2832 | data.append(m_caster->GetPackGUID()); |
---|
2833 | else |
---|
2834 | data.append(target->GetPackGUID()); |
---|
2835 | |
---|
2836 | data << uint32(m_spellInfo->Id); |
---|
2837 | uint32 count1 = 1; |
---|
2838 | data << uint32(count1); // count1 (effect count?) |
---|
2839 | for(uint32 i = 0; i < count1; ++i) |
---|
2840 | { |
---|
2841 | data << uint32(m_spellInfo->Effect[0]); // spell effect? |
---|
2842 | uint32 count2 = 1; |
---|
2843 | data << uint32(count2); // count2 (target count?) |
---|
2844 | for(uint32 j = 0; j < count2; ++j) |
---|
2845 | { |
---|
2846 | switch(m_spellInfo->Effect[0]) |
---|
2847 | { |
---|
2848 | case SPELL_EFFECT_POWER_DRAIN: |
---|
2849 | if(Unit *unit = m_targets.getUnitTarget()) |
---|
2850 | data.append(unit->GetPackGUID()); |
---|
2851 | else |
---|
2852 | data << uint8(0); |
---|
2853 | data << uint32(0); |
---|
2854 | data << uint32(0); |
---|
2855 | data << float(0); |
---|
2856 | break; |
---|
2857 | case SPELL_EFFECT_ADD_EXTRA_ATTACKS: |
---|
2858 | if(Unit *unit = m_targets.getUnitTarget()) |
---|
2859 | data.append(unit->GetPackGUID()); |
---|
2860 | else |
---|
2861 | data << uint8(0); |
---|
2862 | data << uint32(0); // count? |
---|
2863 | break; |
---|
2864 | case SPELL_EFFECT_INTERRUPT_CAST: |
---|
2865 | if(Unit *unit = m_targets.getUnitTarget()) |
---|
2866 | data.append(unit->GetPackGUID()); |
---|
2867 | else |
---|
2868 | data << uint8(0); |
---|
2869 | data << uint32(0); // spellid |
---|
2870 | break; |
---|
2871 | case SPELL_EFFECT_DURABILITY_DAMAGE: |
---|
2872 | if(Unit *unit = m_targets.getUnitTarget()) |
---|
2873 | data.append(unit->GetPackGUID()); |
---|
2874 | else |
---|
2875 | data << uint8(0); |
---|
2876 | data << uint32(0); |
---|
2877 | data << uint32(0); |
---|
2878 | break; |
---|
2879 | case SPELL_EFFECT_OPEN_LOCK: |
---|
2880 | case SPELL_EFFECT_OPEN_LOCK_ITEM: |
---|
2881 | if(Item *item = m_targets.getItemTarget()) |
---|
2882 | data.append(item->GetPackGUID()); |
---|
2883 | else |
---|
2884 | data << uint8(0); |
---|
2885 | break; |
---|
2886 | case SPELL_EFFECT_CREATE_ITEM: |
---|
2887 | data << uint32(m_spellInfo->EffectItemType[0]); |
---|
2888 | break; |
---|
2889 | case SPELL_EFFECT_SUMMON: |
---|
2890 | case SPELL_EFFECT_SUMMON_WILD: |
---|
2891 | case SPELL_EFFECT_SUMMON_GUARDIAN: |
---|
2892 | case SPELL_EFFECT_TRANS_DOOR: |
---|
2893 | case SPELL_EFFECT_SUMMON_PET: |
---|
2894 | case SPELL_EFFECT_SUMMON_POSSESSED: |
---|
2895 | case SPELL_EFFECT_SUMMON_TOTEM: |
---|
2896 | case SPELL_EFFECT_SUMMON_OBJECT_WILD: |
---|
2897 | case SPELL_EFFECT_CREATE_HOUSE: |
---|
2898 | case SPELL_EFFECT_DUEL: |
---|
2899 | case SPELL_EFFECT_SUMMON_TOTEM_SLOT1: |
---|
2900 | case SPELL_EFFECT_SUMMON_TOTEM_SLOT2: |
---|
2901 | case SPELL_EFFECT_SUMMON_TOTEM_SLOT3: |
---|
2902 | case SPELL_EFFECT_SUMMON_TOTEM_SLOT4: |
---|
2903 | case SPELL_EFFECT_SUMMON_PHANTASM: |
---|
2904 | case SPELL_EFFECT_SUMMON_CRITTER: |
---|
2905 | case SPELL_EFFECT_SUMMON_OBJECT_SLOT1: |
---|
2906 | case SPELL_EFFECT_SUMMON_OBJECT_SLOT2: |
---|
2907 | case SPELL_EFFECT_SUMMON_OBJECT_SLOT3: |
---|
2908 | case SPELL_EFFECT_SUMMON_OBJECT_SLOT4: |
---|
2909 | case SPELL_EFFECT_SUMMON_DEMON: |
---|
2910 | case SPELL_EFFECT_150: |
---|
2911 | if(Unit *unit = m_targets.getUnitTarget()) |
---|
2912 | data.append(unit->GetPackGUID()); |
---|
2913 | else if(m_targets.getItemTargetGUID()) |
---|
2914 | data.appendPackGUID(m_targets.getItemTargetGUID()); |
---|
2915 | else if(GameObject *go = m_targets.getGOTarget()) |
---|
2916 | data.append(go->GetPackGUID()); |
---|
2917 | else |
---|
2918 | data << uint8(0); // guid |
---|
2919 | break; |
---|
2920 | case SPELL_EFFECT_FEED_PET: |
---|
2921 | data << uint32(m_targets.getItemTargetEntry()); |
---|
2922 | break; |
---|
2923 | case SPELL_EFFECT_DISMISS_PET: |
---|
2924 | if(Unit *unit = m_targets.getUnitTarget()) |
---|
2925 | data.append(unit->GetPackGUID()); |
---|
2926 | else |
---|
2927 | data << uint8(0); |
---|
2928 | break; |
---|
2929 | default: |
---|
2930 | return; |
---|
2931 | } |
---|
2932 | } |
---|
2933 | } |
---|
2934 | |
---|
2935 | m_caster->SendMessageToSet(&data, true); |
---|
2936 | } |
---|
2937 | |
---|
2938 | void Spell::SendInterrupted(uint8 result) |
---|
2939 | { |
---|
2940 | WorldPacket data(SMSG_SPELL_FAILURE, (8+4+1)); |
---|
2941 | data.append(m_caster->GetPackGUID()); |
---|
2942 | data << m_spellInfo->Id; |
---|
2943 | data << result; |
---|
2944 | m_caster->SendMessageToSet(&data, true); |
---|
2945 | |
---|
2946 | data.Initialize(SMSG_SPELL_FAILED_OTHER, (8+4)); |
---|
2947 | data.append(m_caster->GetPackGUID()); |
---|
2948 | data << m_spellInfo->Id; |
---|
2949 | m_caster->SendMessageToSet(&data, true); |
---|
2950 | } |
---|
2951 | |
---|
2952 | void Spell::SendChannelUpdate(uint32 time) |
---|
2953 | { |
---|
2954 | if(time == 0) |
---|
2955 | { |
---|
2956 | m_caster->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT,0); |
---|
2957 | m_caster->SetUInt32Value(UNIT_CHANNEL_SPELL,0); |
---|
2958 | } |
---|
2959 | |
---|
2960 | if (m_caster->GetTypeId() != TYPEID_PLAYER) |
---|
2961 | return; |
---|
2962 | |
---|
2963 | WorldPacket data( MSG_CHANNEL_UPDATE, 8+4 ); |
---|
2964 | data.append(m_caster->GetPackGUID()); |
---|
2965 | data << time; |
---|
2966 | |
---|
2967 | ((Player*)m_caster)->GetSession()->SendPacket( &data ); |
---|
2968 | } |
---|
2969 | |
---|
2970 | void Spell::SendChannelStart(uint32 duration) |
---|
2971 | { |
---|
2972 | WorldObject* target = NULL; |
---|
2973 | |
---|
2974 | // select first not rsusted target from target list for _0_ effect |
---|
2975 | if(!m_UniqueTargetInfo.empty()) |
---|
2976 | { |
---|
2977 | for(std::list<TargetInfo>::iterator itr= m_UniqueTargetInfo.begin();itr != m_UniqueTargetInfo.end();++itr) |
---|
2978 | { |
---|
2979 | if( (itr->effectMask & (1<<0)) && itr->reflectResult==SPELL_MISS_NONE && itr->targetGUID != m_caster->GetGUID()) |
---|
2980 | { |
---|
2981 | target = ObjectAccessor::GetUnit(*m_caster, itr->targetGUID); |
---|
2982 | break; |
---|
2983 | } |
---|
2984 | } |
---|
2985 | } |
---|
2986 | else if(!m_UniqueGOTargetInfo.empty()) |
---|
2987 | { |
---|
2988 | for(std::list<GOTargetInfo>::iterator itr= m_UniqueGOTargetInfo.begin();itr != m_UniqueGOTargetInfo.end();++itr) |
---|
2989 | { |
---|
2990 | if(itr->effectMask & (1<<0) ) |
---|
2991 | { |
---|
2992 | target = ObjectAccessor::GetGameObject(*m_caster, itr->targetGUID); |
---|
2993 | break; |
---|
2994 | } |
---|
2995 | } |
---|
2996 | } |
---|
2997 | |
---|
2998 | if (m_caster->GetTypeId() == TYPEID_PLAYER) |
---|
2999 | { |
---|
3000 | WorldPacket data( MSG_CHANNEL_START, (8+4+4) ); |
---|
3001 | data.append(m_caster->GetPackGUID()); |
---|
3002 | data << m_spellInfo->Id; |
---|
3003 | data << duration; |
---|
3004 | |
---|
3005 | ((Player*)m_caster)->GetSession()->SendPacket( &data ); |
---|
3006 | } |
---|
3007 | |
---|
3008 | m_timer = duration; |
---|
3009 | if(target) |
---|
3010 | m_caster->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, target->GetGUID()); |
---|
3011 | m_caster->SetUInt32Value(UNIT_CHANNEL_SPELL, m_spellInfo->Id); |
---|
3012 | } |
---|
3013 | |
---|
3014 | void Spell::SendResurrectRequest(Player* target) |
---|
3015 | { |
---|
3016 | WorldPacket data(SMSG_RESURRECT_REQUEST, (8+4+2+4)); |
---|
3017 | data << m_caster->GetGUID(); |
---|
3018 | data << uint32(1) << uint16(0) << uint32(1); |
---|
3019 | |
---|
3020 | target->GetSession()->SendPacket(&data); |
---|
3021 | } |
---|
3022 | |
---|
3023 | void Spell::SendPlaySpellVisual(uint32 SpellID) |
---|
3024 | { |
---|
3025 | if (m_caster->GetTypeId() != TYPEID_PLAYER) |
---|
3026 | return; |
---|
3027 | |
---|
3028 | WorldPacket data(SMSG_PLAY_SPELL_VISUAL, 12); |
---|
3029 | data << m_caster->GetGUID(); |
---|
3030 | data << SpellID; |
---|
3031 | ((Player*)m_caster)->GetSession()->SendPacket(&data); |
---|
3032 | } |
---|
3033 | |
---|
3034 | void Spell::TakeCastItem() |
---|
3035 | { |
---|
3036 | if(!m_CastItem || m_caster->GetTypeId() != TYPEID_PLAYER) |
---|
3037 | return; |
---|
3038 | |
---|
3039 | // not remove cast item at triggered spell (equipping, weapon damage, etc) |
---|
3040 | if(m_IsTriggeredSpell) |
---|
3041 | return; |
---|
3042 | |
---|
3043 | ItemPrototype const *proto = m_CastItem->GetProto(); |
---|
3044 | |
---|
3045 | if(!proto) |
---|
3046 | { |
---|
3047 | // This code is to avoid a crash |
---|
3048 | // I'm not sure, if this is really an error, but I guess every item needs a prototype |
---|
3049 | sLog.outError("Cast item has no item prototype highId=%d, lowId=%d",m_CastItem->GetGUIDHigh(), m_CastItem->GetGUIDLow()); |
---|
3050 | return; |
---|
3051 | } |
---|
3052 | |
---|
3053 | bool expendable = false; |
---|
3054 | bool withoutCharges = false; |
---|
3055 | |
---|
3056 | for (int i = 0; i<5; i++) |
---|
3057 | { |
---|
3058 | if (proto->Spells[i].SpellId) |
---|
3059 | { |
---|
3060 | // item has limited charges |
---|
3061 | if (proto->Spells[i].SpellCharges) |
---|
3062 | { |
---|
3063 | if (proto->Spells[i].SpellCharges < 0) |
---|
3064 | expendable = true; |
---|
3065 | |
---|
3066 | int32 charges = m_CastItem->GetSpellCharges(i); |
---|
3067 | |
---|
3068 | // item has charges left |
---|
3069 | if (charges) |
---|
3070 | { |
---|
3071 | (charges > 0) ? --charges : ++charges; // abs(charges) less at 1 after use |
---|
3072 | if (proto->Stackable < 2) |
---|
3073 | m_CastItem->SetSpellCharges(i, charges); |
---|
3074 | m_CastItem->SetState(ITEM_CHANGED, (Player*)m_caster); |
---|
3075 | } |
---|
3076 | |
---|
3077 | // all charges used |
---|
3078 | withoutCharges = (charges == 0); |
---|
3079 | } |
---|
3080 | } |
---|
3081 | } |
---|
3082 | |
---|
3083 | if (expendable && withoutCharges) |
---|
3084 | { |
---|
3085 | uint32 count = 1; |
---|
3086 | ((Player*)m_caster)->DestroyItemCount(m_CastItem, count, true); |
---|
3087 | |
---|
3088 | // prevent crash at access to deleted m_targets.getItemTarget |
---|
3089 | if(m_CastItem==m_targets.getItemTarget()) |
---|
3090 | m_targets.setItemTarget(NULL); |
---|
3091 | |
---|
3092 | m_CastItem = NULL; |
---|
3093 | } |
---|
3094 | } |
---|
3095 | |
---|
3096 | void Spell::TakePower() |
---|
3097 | { |
---|
3098 | if(m_CastItem || m_triggeredByAuraSpell) |
---|
3099 | return; |
---|
3100 | |
---|
3101 | // health as power used |
---|
3102 | if(m_spellInfo->powerType == POWER_HEALTH) |
---|
3103 | { |
---|
3104 | m_caster->ModifyHealth( -(int32)m_powerCost ); |
---|
3105 | return; |
---|
3106 | } |
---|
3107 | |
---|
3108 | if(m_spellInfo->powerType >= MAX_POWERS) |
---|
3109 | { |
---|
3110 | sLog.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo->powerType); |
---|
3111 | return; |
---|
3112 | } |
---|
3113 | |
---|
3114 | Powers powerType = Powers(m_spellInfo->powerType); |
---|
3115 | |
---|
3116 | m_caster->ModifyPower(powerType, -(int32)m_powerCost); |
---|
3117 | |
---|
3118 | // Set the five second timer |
---|
3119 | if (powerType == POWER_MANA && m_powerCost > 0) |
---|
3120 | m_caster->SetLastManaUse(getMSTime()); |
---|
3121 | } |
---|
3122 | |
---|
3123 | void Spell::TakeReagents() |
---|
3124 | { |
---|
3125 | if(m_IsTriggeredSpell) // reagents used in triggered spell removed by original spell or don't must be removed. |
---|
3126 | return; |
---|
3127 | |
---|
3128 | if (m_caster->GetTypeId() != TYPEID_PLAYER) |
---|
3129 | return; |
---|
3130 | |
---|
3131 | if (m_spellInfo->AttributesEx5 & SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP && |
---|
3132 | m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION)) |
---|
3133 | return; |
---|
3134 | |
---|
3135 | Player* p_caster = (Player*)m_caster; |
---|
3136 | |
---|
3137 | for(uint32 x=0;x<8;x++) |
---|
3138 | { |
---|
3139 | if(m_spellInfo->Reagent[x] <= 0) |
---|
3140 | continue; |
---|
3141 | |
---|
3142 | uint32 itemid = m_spellInfo->Reagent[x]; |
---|
3143 | uint32 itemcount = m_spellInfo->ReagentCount[x]; |
---|
3144 | |
---|
3145 | // if CastItem is also spell reagent |
---|
3146 | if (m_CastItem) |
---|
3147 | { |
---|
3148 | ItemPrototype const *proto = m_CastItem->GetProto(); |
---|
3149 | if( proto && proto->ItemId == itemid ) |
---|
3150 | { |
---|
3151 | for(int s=0;s<5;s++) |
---|
3152 | { |
---|
3153 | // CastItem will be used up and does not count as reagent |
---|
3154 | int32 charges = m_CastItem->GetSpellCharges(s); |
---|
3155 | if (proto->Spells[s].SpellCharges < 0 && abs(charges) < 2) |
---|
3156 | { |
---|
3157 | ++itemcount; |
---|
3158 | break; |
---|
3159 | } |
---|
3160 | } |
---|
3161 | |
---|
3162 | m_CastItem = NULL; |
---|
3163 | } |
---|
3164 | } |
---|
3165 | |
---|
3166 | // if getItemTarget is also spell reagent |
---|
3167 | if (m_targets.getItemTargetEntry()==itemid) |
---|
3168 | m_targets.setItemTarget(NULL); |
---|
3169 | |
---|
3170 | p_caster->DestroyItemCount(itemid, itemcount, true); |
---|
3171 | } |
---|
3172 | } |
---|
3173 | |
---|
3174 | void Spell::HandleThreatSpells(uint32 spellId) |
---|
3175 | { |
---|
3176 | if(!m_targets.getUnitTarget() || !spellId) |
---|
3177 | return; |
---|
3178 | |
---|
3179 | if(!m_targets.getUnitTarget()->CanHaveThreatList()) |
---|
3180 | return; |
---|
3181 | |
---|
3182 | SpellThreatEntry const *threatSpell = sSpellThreatStore.LookupEntry<SpellThreatEntry>(spellId); |
---|
3183 | if(!threatSpell) |
---|
3184 | return; |
---|
3185 | |
---|
3186 | m_targets.getUnitTarget()->AddThreat(m_caster, float(threatSpell->threat)); |
---|
3187 | |
---|
3188 | DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId, spellmgr.GetSpellRank(spellId), threatSpell->threat); |
---|
3189 | } |
---|
3190 | |
---|
3191 | void Spell::HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i, float DamageMultiplier) |
---|
3192 | { |
---|
3193 | unitTarget = pUnitTarget; |
---|
3194 | itemTarget = pItemTarget; |
---|
3195 | gameObjTarget = pGOTarget; |
---|
3196 | |
---|
3197 | uint8 eff = m_spellInfo->Effect[i]; |
---|
3198 | uint32 mechanic = m_spellInfo->EffectMechanic[i]; |
---|
3199 | |
---|
3200 | damage = int32(CalculateDamage((uint8)i,unitTarget)*DamageMultiplier); |
---|
3201 | |
---|
3202 | sLog.outDebug( "Spell: Effect : %u", eff); |
---|
3203 | |
---|
3204 | //Simply return. Do not display "immune" in red text on client |
---|
3205 | if(unitTarget && unitTarget->IsImmunedToSpellEffect(eff, mechanic)) |
---|
3206 | return; |
---|
3207 | |
---|
3208 | if(eff<TOTAL_SPELL_EFFECTS) |
---|
3209 | { |
---|
3210 | //sLog.outDebug( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff); |
---|
3211 | (*this.*SpellEffects[eff])(i); |
---|
3212 | } |
---|
3213 | /* |
---|
3214 | else |
---|
3215 | { |
---|
3216 | sLog.outDebug( "WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff); |
---|
3217 | if (m_CastItem) |
---|
3218 | EffectEnchantItemTmp(i); |
---|
3219 | else |
---|
3220 | { |
---|
3221 | sLog.outError("SPELL: unknown effect %u spell id %u\n", |
---|
3222 | eff, m_spellInfo->Id); |
---|
3223 | } |
---|
3224 | } |
---|
3225 | */ |
---|
3226 | } |
---|
3227 | |
---|
3228 | void Spell::TriggerSpell() |
---|
3229 | { |
---|
3230 | for(TriggerSpells::iterator si=m_TriggerSpells.begin(); si!=m_TriggerSpells.end(); ++si) |
---|
3231 | { |
---|
3232 | Spell* spell = new Spell(m_caster, (*si), true, m_originalCasterGUID, this->m_selfContainer); |
---|
3233 | spell->prepare(&m_targets); // use original spell original targets |
---|
3234 | } |
---|
3235 | } |
---|
3236 | |
---|
3237 | uint8 Spell::CanCast(bool strict) |
---|
3238 | { |
---|
3239 | // check cooldowns to prevent cheating |
---|
3240 | if(m_caster->GetTypeId()==TYPEID_PLAYER && ((Player*)m_caster)->HasSpellCooldown(m_spellInfo->Id)) |
---|
3241 | { |
---|
3242 | if(m_triggeredByAuraSpell) |
---|
3243 | return SPELL_FAILED_DONT_REPORT; |
---|
3244 | else |
---|
3245 | return SPELL_FAILED_NOT_READY; |
---|
3246 | } |
---|
3247 | |
---|
3248 | // only allow triggered spells if at an ended battleground |
---|
3249 | if( !m_IsTriggeredSpell && m_caster->GetTypeId() == TYPEID_PLAYER) |
---|
3250 | if(BattleGround * bg = ((Player*)m_caster)->GetBattleGround()) |
---|
3251 | if(bg->GetStatus() == STATUS_WAIT_LEAVE) |
---|
3252 | return SPELL_FAILED_DONT_REPORT; |
---|
3253 | |
---|
3254 | // only check at first call, Stealth auras are already removed at second call |
---|
3255 | // for now, ignore triggered spells |
---|
3256 | if( strict && !m_IsTriggeredSpell) |
---|
3257 | { |
---|
3258 | // Cannot be used in this stance/form |
---|
3259 | if(uint8 shapeError = GetErrorAtShapeshiftedCast(m_spellInfo, m_caster->m_form)) |
---|
3260 | return shapeError; |
---|
3261 | |
---|
3262 | if ((m_spellInfo->Attributes & SPELL_ATTR_ONLY_STEALTHED) && !(m_caster->HasStealthAura())) |
---|
3263 | return SPELL_FAILED_ONLY_STEALTHED; |
---|
3264 | } |
---|
3265 | |
---|
3266 | // caster state requirements |
---|
3267 | if(m_spellInfo->CasterAuraState && !m_caster->HasAuraState(AuraState(m_spellInfo->CasterAuraState))) |
---|
3268 | return SPELL_FAILED_CASTER_AURASTATE; |
---|
3269 | if(m_spellInfo->CasterAuraStateNot && m_caster->HasAuraState(AuraState(m_spellInfo->CasterAuraStateNot))) |
---|
3270 | return SPELL_FAILED_CASTER_AURASTATE; |
---|
3271 | |
---|
3272 | // cancel autorepeat spells if cast start when moving |
---|
3273 | // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code) |
---|
3274 | if( m_caster->GetTypeId()==TYPEID_PLAYER && ((Player*)m_caster)->isMoving() ) |
---|
3275 | { |
---|
3276 | // skip stuck spell to allow use it in falling case and apply spell limitations at movement |
---|
3277 | if( (!m_caster->HasUnitMovementFlag(MOVEMENTFLAG_FALLING) || m_spellInfo->Effect[0] != SPELL_EFFECT_STUCK) && |
---|
3278 | (IsAutoRepeat() || (m_spellInfo->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED) != 0) ) |
---|
3279 | return SPELL_FAILED_MOVING; |
---|
3280 | } |
---|
3281 | |
---|
3282 | Unit *target = m_targets.getUnitTarget(); |
---|
3283 | |
---|
3284 | if(target) |
---|
3285 | { |
---|
3286 | // target state requirements (not allowed state), apply to self also |
---|
3287 | if(m_spellInfo->TargetAuraStateNot && target->HasAuraState(AuraState(m_spellInfo->TargetAuraStateNot))) |
---|
3288 | return SPELL_FAILED_TARGET_AURASTATE; |
---|
3289 | |
---|
3290 | |
---|
3291 | if(target != m_caster) |
---|
3292 | { |
---|
3293 | // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds |
---|
3294 | if(m_spellInfo->TargetAuraState && !target->HasAuraState(AuraState(m_spellInfo->TargetAuraState))) |
---|
3295 | return SPELL_FAILED_TARGET_AURASTATE; |
---|
3296 | |
---|
3297 | // Not allow casting on flying player |
---|
3298 | if (target->isInFlight()) |
---|
3299 | return SPELL_FAILED_BAD_TARGETS; |
---|
3300 | |
---|
3301 | if(VMAP::VMapFactory::checkSpellForLoS(m_spellInfo->Id) && !m_caster->IsWithinLOSInMap(target)) |
---|
3302 | return SPELL_FAILED_LINE_OF_SIGHT; |
---|
3303 | |
---|
3304 | // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode |
---|
3305 | // this case can be triggered if rank not found (too low-level target for first rank) |
---|
3306 | if(m_caster->GetTypeId() == TYPEID_PLAYER && !IsPassiveSpell(m_spellInfo->Id) && !m_CastItem) |
---|
3307 | { |
---|
3308 | for(int i=0;i<3;i++) |
---|
3309 | { |
---|
3310 | if(IsPositiveEffect(m_spellInfo->Id, i) && m_spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA) |
---|
3311 | if(target->getLevel() + 10 < m_spellInfo->spellLevel) |
---|
3312 | return SPELL_FAILED_LOWLEVEL; |
---|
3313 | } |
---|
3314 | } |
---|
3315 | } |
---|
3316 | |
---|
3317 | // check pet presents |
---|
3318 | for(int j=0;j<3;j++) |
---|
3319 | { |
---|
3320 | if(m_spellInfo->EffectImplicitTargetA[j] == TARGET_PET) |
---|
3321 | { |
---|
3322 | target = m_caster->GetPet(); |
---|
3323 | if(!target) |
---|
3324 | { |
---|
3325 | if(m_triggeredByAuraSpell) // not report pet not existence for triggered spells |
---|
3326 | return SPELL_FAILED_DONT_REPORT; |
---|
3327 | else |
---|
3328 | return SPELL_FAILED_NO_PET; |
---|
3329 | } |
---|
3330 | break; |
---|
3331 | } |
---|
3332 | } |
---|
3333 | |
---|
3334 | //check creature type |
---|
3335 | //ignore self casts (including area casts when caster selected as target) |
---|
3336 | if(target != m_caster) |
---|
3337 | { |
---|
3338 | if(!CheckTargetCreatureType(target)) |
---|
3339 | { |
---|
3340 | if(target->GetTypeId()==TYPEID_PLAYER) |
---|
3341 | return SPELL_FAILED_TARGET_IS_PLAYER; |
---|
3342 | else |
---|
3343 | return SPELL_FAILED_BAD_TARGETS; |
---|
3344 | } |
---|
3345 | } |
---|
3346 | |
---|
3347 | // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result. |
---|
3348 | // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc |
---|
3349 | if(m_caster != target && m_caster->GetTypeId()==TYPEID_UNIT && m_caster->GetCharmerOrOwnerGUID()) |
---|
3350 | { |
---|
3351 | // check correctness positive/negative cast target (pet cast real check and cheating check) |
---|
3352 | if(IsPositiveSpell(m_spellInfo->Id)) |
---|
3353 | { |
---|
3354 | if(m_caster->IsHostileTo(target)) |
---|
3355 | return SPELL_FAILED_BAD_TARGETS; |
---|
3356 | } |
---|
3357 | else |
---|
3358 | { |
---|
3359 | if(m_caster->IsFriendlyTo(target)) |
---|
3360 | return SPELL_FAILED_BAD_TARGETS; |
---|
3361 | } |
---|
3362 | } |
---|
3363 | |
---|
3364 | if(IsPositiveSpell(m_spellInfo->Id)) |
---|
3365 | { |
---|
3366 | if(target->IsImmunedToSpell(m_spellInfo,false)) |
---|
3367 | return SPELL_FAILED_TARGET_AURASTATE; |
---|
3368 | } |
---|
3369 | |
---|
3370 | //Must be behind the target. |
---|
3371 | if( m_spellInfo->AttributesEx2 == 0x100000 && (m_spellInfo->AttributesEx & 0x200) == 0x200 && target->HasInArc(M_PI, m_caster) ) |
---|
3372 | { |
---|
3373 | SendInterrupted(2); |
---|
3374 | return SPELL_FAILED_NOT_BEHIND; |
---|
3375 | } |
---|
3376 | |
---|
3377 | //Target must be facing you. |
---|
3378 | if((m_spellInfo->Attributes == 0x150010) && !target->HasInArc(M_PI, m_caster) ) |
---|
3379 | { |
---|
3380 | SendInterrupted(2); |
---|
3381 | return SPELL_FAILED_NOT_INFRONT; |
---|
3382 | } |
---|
3383 | |
---|
3384 | // check if target is in combat |
---|
3385 | if (target != m_caster && (m_spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET) && target->isInCombat()) |
---|
3386 | { |
---|
3387 | return SPELL_FAILED_TARGET_AFFECTING_COMBAT; |
---|
3388 | } |
---|
3389 | } |
---|
3390 | // Spell casted only on battleground |
---|
3391 | if((m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_BATTLEGROUND) && m_caster->GetTypeId()==TYPEID_PLAYER) |
---|
3392 | if(!((Player*)m_caster)->InBattleGround()) |
---|
3393 | return SPELL_FAILED_ONLY_BATTLEGROUNDS; |
---|
3394 | |
---|
3395 | // do not allow spells to be cast in arenas |
---|
3396 | // - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag |
---|
3397 | // - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag |
---|
3398 | if( (m_spellInfo->AttributesEx4 & SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA) || |
---|
3399 | GetSpellRecoveryTime(m_spellInfo) > 15 * MINUTE * 1000 && !(m_spellInfo->AttributesEx4 & SPELL_ATTR_EX4_USABLE_IN_ARENA) ) |
---|
3400 | if(MapEntry const* mapEntry = sMapStore.LookupEntry(m_caster->GetMapId())) |
---|
3401 | if(mapEntry->IsBattleArena()) |
---|
3402 | return SPELL_FAILED_NOT_IN_ARENA; |
---|
3403 | |
---|
3404 | // zone check |
---|
3405 | if(!IsSpellAllowedInLocation(m_spellInfo,m_caster->GetMapId(),m_caster->GetZoneId(),m_caster->GetAreaId())) |
---|
3406 | return SPELL_FAILED_REQUIRES_AREA; |
---|
3407 | |
---|
3408 | // not let players cast spells at mount (and let do it to creatures) |
---|
3409 | if( m_caster->IsMounted() && m_caster->GetTypeId()==TYPEID_PLAYER && !m_IsTriggeredSpell && |
---|
3410 | !IsPassiveSpell(m_spellInfo->Id) && !(m_spellInfo->Attributes & SPELL_ATTR_CASTABLE_WHILE_MOUNTED) ) |
---|
3411 | { |
---|
3412 | if(m_caster->isInFlight()) |
---|
3413 | return SPELL_FAILED_NOT_FLYING; |
---|
3414 | else |
---|
3415 | return SPELL_FAILED_NOT_MOUNTED; |
---|
3416 | } |
---|
3417 | |
---|
3418 | // always (except passive spells) check items (focus object can be required for any type casts) |
---|
3419 | if(!IsPassiveSpell(m_spellInfo->Id)) |
---|
3420 | if(uint8 castResult = CheckItems()) |
---|
3421 | return castResult; |
---|
3422 | |
---|
3423 | //ImpliciteTargetA-B = 38, If fact there is 0 Spell with ImpliciteTargetB=38 |
---|
3424 | if(m_UniqueTargetInfo.empty()) // skip second canCast apply (for delayed spells for example) |
---|
3425 | { |
---|
3426 | for(uint8 j = 0; j < 3; j++) |
---|
3427 | { |
---|
3428 | if( m_spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT || |
---|
3429 | m_spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT && m_spellInfo->EffectImplicitTargetA[j] != TARGET_SELF || |
---|
3430 | m_spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT_COORDINATES || |
---|
3431 | m_spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT_COORDINATES ) |
---|
3432 | { |
---|
3433 | bool okDoo = false; |
---|
3434 | |
---|
3435 | SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(m_spellInfo->Id); |
---|
3436 | SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(m_spellInfo->Id); |
---|
3437 | if(lower==upper) |
---|
3438 | sLog.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = TARGET_SCRIPT or TARGET_SCRIPT_COORDINATES, but does not have record in `spell_script_target`",m_spellInfo->Id); |
---|
3439 | |
---|
3440 | SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex); |
---|
3441 | float range = GetSpellMaxRange(srange); |
---|
3442 | |
---|
3443 | Creature* creatureScriptTarget = NULL; |
---|
3444 | GameObject* goScriptTarget = NULL; |
---|
3445 | |
---|
3446 | for(SpellScriptTarget::const_iterator i_spellST = lower; i_spellST != upper; ++i_spellST) |
---|
3447 | { |
---|
3448 | switch(i_spellST->second.type) |
---|
3449 | { |
---|
3450 | case SPELL_TARGET_TYPE_GAMEOBJECT: |
---|
3451 | { |
---|
3452 | GameObject* p_GameObject = NULL; |
---|
3453 | |
---|
3454 | if(i_spellST->second.targetEntry) |
---|
3455 | { |
---|
3456 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
3457 | Cell cell(p); |
---|
3458 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
3459 | |
---|
3460 | Trinity::NearestGameObjectEntryInObjectRangeCheck go_check(*m_caster,i_spellST->second.targetEntry,range); |
---|
3461 | Trinity::GameObjectLastSearcher<Trinity::NearestGameObjectEntryInObjectRangeCheck> checker(p_GameObject,go_check); |
---|
3462 | |
---|
3463 | TypeContainerVisitor<Trinity::GameObjectLastSearcher<Trinity::NearestGameObjectEntryInObjectRangeCheck>, GridTypeMapContainer > object_checker(checker); |
---|
3464 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
3465 | cell_lock->Visit(cell_lock, object_checker, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
3466 | |
---|
3467 | if(p_GameObject) |
---|
3468 | { |
---|
3469 | // remember found target and range, next attempt will find more near target with another entry |
---|
3470 | creatureScriptTarget = NULL; |
---|
3471 | goScriptTarget = p_GameObject; |
---|
3472 | range = go_check.GetLastRange(); |
---|
3473 | } |
---|
3474 | } |
---|
3475 | else if( focusObject ) //Focus Object |
---|
3476 | { |
---|
3477 | float frange = m_caster->GetDistance(focusObject); |
---|
3478 | if(range >= frange) |
---|
3479 | { |
---|
3480 | creatureScriptTarget = NULL; |
---|
3481 | goScriptTarget = focusObject; |
---|
3482 | range = frange; |
---|
3483 | } |
---|
3484 | } |
---|
3485 | break; |
---|
3486 | } |
---|
3487 | case SPELL_TARGET_TYPE_CREATURE: |
---|
3488 | case SPELL_TARGET_TYPE_DEAD: |
---|
3489 | default: |
---|
3490 | { |
---|
3491 | Creature *p_Creature = NULL; |
---|
3492 | |
---|
3493 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
3494 | Cell cell(p); |
---|
3495 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
3496 | cell.SetNoCreate(); // Really don't know what is that??? |
---|
3497 | |
---|
3498 | Trinity::NearestCreatureEntryWithLiveStateInObjectRangeCheck u_check(*m_caster,i_spellST->second.targetEntry,i_spellST->second.type!=SPELL_TARGET_TYPE_DEAD,range); |
---|
3499 | Trinity::CreatureLastSearcher<Trinity::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(p_Creature, u_check); |
---|
3500 | |
---|
3501 | TypeContainerVisitor<Trinity::CreatureLastSearcher<Trinity::NearestCreatureEntryWithLiveStateInObjectRangeCheck>, GridTypeMapContainer > grid_creature_searcher(searcher); |
---|
3502 | |
---|
3503 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
3504 | cell_lock->Visit(cell_lock, grid_creature_searcher, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
3505 | |
---|
3506 | if(p_Creature ) |
---|
3507 | { |
---|
3508 | creatureScriptTarget = p_Creature; |
---|
3509 | goScriptTarget = NULL; |
---|
3510 | range = u_check.GetLastRange(); |
---|
3511 | } |
---|
3512 | break; |
---|
3513 | } |
---|
3514 | } |
---|
3515 | } |
---|
3516 | |
---|
3517 | if(creatureScriptTarget) |
---|
3518 | { |
---|
3519 | // store coordinates for TARGET_SCRIPT_COORDINATES |
---|
3520 | if (m_spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT_COORDINATES || |
---|
3521 | m_spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT_COORDINATES ) |
---|
3522 | { |
---|
3523 | m_targets.setDestination(creatureScriptTarget->GetPositionX(),creatureScriptTarget->GetPositionY(),creatureScriptTarget->GetPositionZ()); |
---|
3524 | |
---|
3525 | if(m_spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT_COORDINATES && m_spellInfo->EffectImplicitTargetB[j] == 0 && m_spellInfo->Effect[j]!=SPELL_EFFECT_PERSISTENT_AREA_AURA) |
---|
3526 | AddUnitTarget(creatureScriptTarget, j); |
---|
3527 | } |
---|
3528 | // store explicit target for TARGET_SCRIPT |
---|
3529 | else |
---|
3530 | AddUnitTarget(creatureScriptTarget, j); |
---|
3531 | } |
---|
3532 | else if(goScriptTarget) |
---|
3533 | { |
---|
3534 | // store coordinates for TARGET_SCRIPT_COORDINATES |
---|
3535 | if (m_spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT_COORDINATES || |
---|
3536 | m_spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT_COORDINATES ) |
---|
3537 | { |
---|
3538 | m_targets.setDestination(goScriptTarget->GetPositionX(),goScriptTarget->GetPositionY(),goScriptTarget->GetPositionZ()); |
---|
3539 | |
---|
3540 | if(m_spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT_COORDINATES && m_spellInfo->EffectImplicitTargetB[j] == 0 && m_spellInfo->Effect[j]!=SPELL_EFFECT_PERSISTENT_AREA_AURA) |
---|
3541 | AddGOTarget(goScriptTarget, j); |
---|
3542 | } |
---|
3543 | // store explicit target for TARGET_SCRIPT |
---|
3544 | else |
---|
3545 | AddGOTarget(goScriptTarget, j); |
---|
3546 | } |
---|
3547 | //Missing DB Entry or targets for this spellEffect. |
---|
3548 | else |
---|
3549 | { |
---|
3550 | // not report target not existence for triggered spells |
---|
3551 | if(m_triggeredByAuraSpell || m_IsTriggeredSpell) |
---|
3552 | return SPELL_FAILED_DONT_REPORT; |
---|
3553 | else |
---|
3554 | return SPELL_FAILED_BAD_TARGETS; |
---|
3555 | } |
---|
3556 | } |
---|
3557 | } |
---|
3558 | } |
---|
3559 | |
---|
3560 | if(uint8 castResult = CheckRange(strict)) |
---|
3561 | return castResult; |
---|
3562 | |
---|
3563 | { |
---|
3564 | if(uint8 castResult = CheckPower()) |
---|
3565 | return castResult; |
---|
3566 | } |
---|
3567 | |
---|
3568 | if(!m_triggeredByAuraSpell) // triggered spell not affected by stun/etc |
---|
3569 | if(uint8 castResult = CheckCasterAuras()) |
---|
3570 | return castResult; |
---|
3571 | |
---|
3572 | for (int i = 0; i < 3; i++) |
---|
3573 | { |
---|
3574 | // for effects of spells that have only one target |
---|
3575 | switch(m_spellInfo->Effect[i]) |
---|
3576 | { |
---|
3577 | case SPELL_EFFECT_DUMMY: |
---|
3578 | { |
---|
3579 | if(m_spellInfo->SpellIconID == 1648) // Execute |
---|
3580 | { |
---|
3581 | if(!m_targets.getUnitTarget() || m_targets.getUnitTarget()->GetHealth() > m_targets.getUnitTarget()->GetMaxHealth()*0.2) |
---|
3582 | return SPELL_FAILED_BAD_TARGETS; |
---|
3583 | } |
---|
3584 | else if (m_spellInfo->Id == 51582) // Rocket Boots Engaged |
---|
3585 | { |
---|
3586 | if(m_caster->IsInWater()) |
---|
3587 | return SPELL_FAILED_ONLY_ABOVEWATER; |
---|
3588 | } |
---|
3589 | else if(m_spellInfo->SpellIconID==156) // Holy Shock |
---|
3590 | { |
---|
3591 | // spell different for friends and enemies |
---|
3592 | // hart version required facing |
---|
3593 | if(m_targets.getUnitTarget() && !m_caster->IsFriendlyTo(m_targets.getUnitTarget()) && !m_caster->HasInArc( M_PI, target )) |
---|
3594 | return SPELL_FAILED_UNIT_NOT_INFRONT; |
---|
3595 | } |
---|
3596 | break; |
---|
3597 | } |
---|
3598 | case SPELL_EFFECT_SCHOOL_DAMAGE: |
---|
3599 | { |
---|
3600 | // Hammer of Wrath |
---|
3601 | if(m_spellInfo->SpellVisual == 7250) |
---|
3602 | { |
---|
3603 | if (!m_targets.getUnitTarget()) |
---|
3604 | return SPELL_FAILED_BAD_IMPLICIT_TARGETS; |
---|
3605 | |
---|
3606 | if(m_targets.getUnitTarget()->GetHealth() > m_targets.getUnitTarget()->GetMaxHealth()*0.2) |
---|
3607 | return SPELL_FAILED_BAD_TARGETS; |
---|
3608 | } |
---|
3609 | break; |
---|
3610 | } |
---|
3611 | case SPELL_EFFECT_TAMECREATURE: |
---|
3612 | { |
---|
3613 | if (!m_targets.getUnitTarget() || m_targets.getUnitTarget()->GetTypeId() == TYPEID_PLAYER) |
---|
3614 | return SPELL_FAILED_BAD_IMPLICIT_TARGETS; |
---|
3615 | |
---|
3616 | if (m_targets.getUnitTarget()->getLevel() > m_caster->getLevel()) |
---|
3617 | return SPELL_FAILED_HIGHLEVEL; |
---|
3618 | |
---|
3619 | CreatureInfo const *cinfo = ((Creature*)m_targets.getUnitTarget())->GetCreatureInfo(); |
---|
3620 | if( cinfo->type != CREATURE_TYPE_BEAST ) |
---|
3621 | return SPELL_FAILED_BAD_TARGETS; |
---|
3622 | |
---|
3623 | // use SMSG_PET_TAME_FAILURE? |
---|
3624 | if( !(cinfo->flag1 & 1) || !(cinfo->family) ) |
---|
3625 | return SPELL_FAILED_BAD_TARGETS; |
---|
3626 | |
---|
3627 | if(m_caster->GetPetGUID()) |
---|
3628 | return SPELL_FAILED_ALREADY_HAVE_SUMMON; |
---|
3629 | |
---|
3630 | if(m_caster->GetCharmGUID()) |
---|
3631 | return SPELL_FAILED_ALREADY_HAVE_CHARM; |
---|
3632 | |
---|
3633 | break; |
---|
3634 | } |
---|
3635 | case SPELL_EFFECT_LEARN_SPELL: |
---|
3636 | { |
---|
3637 | if(m_spellInfo->EffectImplicitTargetA[i] != TARGET_PET) |
---|
3638 | break; |
---|
3639 | |
---|
3640 | Pet* pet = m_caster->GetPet(); |
---|
3641 | |
---|
3642 | if(!pet) |
---|
3643 | return SPELL_FAILED_NO_PET; |
---|
3644 | |
---|
3645 | SpellEntry const *learn_spellproto = sSpellStore.LookupEntry(m_spellInfo->EffectTriggerSpell[i]); |
---|
3646 | |
---|
3647 | if(!learn_spellproto) |
---|
3648 | return SPELL_FAILED_NOT_KNOWN; |
---|
3649 | |
---|
3650 | if(!pet->CanTakeMoreActiveSpells(learn_spellproto->Id)) |
---|
3651 | return SPELL_FAILED_TOO_MANY_SKILLS; |
---|
3652 | |
---|
3653 | if(m_spellInfo->spellLevel > pet->getLevel()) |
---|
3654 | return SPELL_FAILED_LOWLEVEL; |
---|
3655 | |
---|
3656 | if(!pet->HasTPForSpell(learn_spellproto->Id)) |
---|
3657 | return SPELL_FAILED_TRAINING_POINTS; |
---|
3658 | |
---|
3659 | break; |
---|
3660 | } |
---|
3661 | case SPELL_EFFECT_LEARN_PET_SPELL: |
---|
3662 | { |
---|
3663 | Pet* pet = m_caster->GetPet(); |
---|
3664 | |
---|
3665 | if(!pet) |
---|
3666 | return SPELL_FAILED_NO_PET; |
---|
3667 | |
---|
3668 | SpellEntry const *learn_spellproto = sSpellStore.LookupEntry(m_spellInfo->EffectTriggerSpell[i]); |
---|
3669 | |
---|
3670 | if(!learn_spellproto) |
---|
3671 | return SPELL_FAILED_NOT_KNOWN; |
---|
3672 | |
---|
3673 | if(!pet->CanTakeMoreActiveSpells(learn_spellproto->Id)) |
---|
3674 | return SPELL_FAILED_TOO_MANY_SKILLS; |
---|
3675 | |
---|
3676 | if(m_spellInfo->spellLevel > pet->getLevel()) |
---|
3677 | return SPELL_FAILED_LOWLEVEL; |
---|
3678 | |
---|
3679 | if(!pet->HasTPForSpell(learn_spellproto->Id)) |
---|
3680 | return SPELL_FAILED_TRAINING_POINTS; |
---|
3681 | |
---|
3682 | break; |
---|
3683 | } |
---|
3684 | case SPELL_EFFECT_FEED_PET: |
---|
3685 | { |
---|
3686 | if (m_caster->GetTypeId() != TYPEID_PLAYER || !m_targets.getItemTarget() ) |
---|
3687 | return SPELL_FAILED_BAD_TARGETS; |
---|
3688 | |
---|
3689 | Pet* pet = m_caster->GetPet(); |
---|
3690 | |
---|
3691 | if(!pet) |
---|
3692 | return SPELL_FAILED_NO_PET; |
---|
3693 | |
---|
3694 | if(!pet->HaveInDiet(m_targets.getItemTarget()->GetProto())) |
---|
3695 | return SPELL_FAILED_WRONG_PET_FOOD; |
---|
3696 | |
---|
3697 | if(!pet->GetCurrentFoodBenefitLevel(m_targets.getItemTarget()->GetProto()->ItemLevel)) |
---|
3698 | return SPELL_FAILED_FOOD_LOWLEVEL; |
---|
3699 | |
---|
3700 | if(m_caster->isInCombat() || pet->isInCombat()) |
---|
3701 | return SPELL_FAILED_AFFECTING_COMBAT; |
---|
3702 | |
---|
3703 | break; |
---|
3704 | } |
---|
3705 | case SPELL_EFFECT_POWER_BURN: |
---|
3706 | case SPELL_EFFECT_POWER_DRAIN: |
---|
3707 | { |
---|
3708 | // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects) |
---|
3709 | if(m_caster->GetTypeId() == TYPEID_PLAYER) |
---|
3710 | if(Unit* target = m_targets.getUnitTarget()) |
---|
3711 | if(target!=m_caster && target->getPowerType()!=m_spellInfo->EffectMiscValue[i]) |
---|
3712 | return SPELL_FAILED_BAD_TARGETS; |
---|
3713 | break; |
---|
3714 | } |
---|
3715 | case SPELL_EFFECT_CHARGE: |
---|
3716 | { |
---|
3717 | if (m_caster->hasUnitState(UNIT_STAT_ROOT)) |
---|
3718 | return SPELL_FAILED_ROOTED; |
---|
3719 | |
---|
3720 | break; |
---|
3721 | } |
---|
3722 | case SPELL_EFFECT_SKINNING: |
---|
3723 | { |
---|
3724 | if (m_caster->GetTypeId() != TYPEID_PLAYER || !m_targets.getUnitTarget() || m_targets.getUnitTarget()->GetTypeId() != TYPEID_UNIT) |
---|
3725 | return SPELL_FAILED_BAD_TARGETS; |
---|
3726 | |
---|
3727 | if( !(m_targets.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS) & UNIT_FLAG_SKINNABLE) ) |
---|
3728 | return SPELL_FAILED_TARGET_UNSKINNABLE; |
---|
3729 | |
---|
3730 | Creature* creature = (Creature*)m_targets.getUnitTarget(); |
---|
3731 | if ( creature->GetCreatureType() != CREATURE_TYPE_CRITTER && ( !creature->lootForBody || !creature->loot.empty() ) ) |
---|
3732 | { |
---|
3733 | return SPELL_FAILED_TARGET_NOT_LOOTED; |
---|
3734 | } |
---|
3735 | |
---|
3736 | uint32 skill; |
---|
3737 | if(creature->GetCreatureInfo()->flag1 & 256) |
---|
3738 | skill = SKILL_HERBALISM; // special case |
---|
3739 | else if(creature->GetCreatureInfo()->flag1 & 512) |
---|
3740 | skill = SKILL_MINING; // special case |
---|
3741 | else |
---|
3742 | skill = SKILL_SKINNING; // normal case |
---|
3743 | |
---|
3744 | int32 skillValue = ((Player*)m_caster)->GetSkillValue(skill); |
---|
3745 | int32 TargetLevel = m_targets.getUnitTarget()->getLevel(); |
---|
3746 | int32 ReqValue = (skillValue < 100 ? (TargetLevel-10)*10 : TargetLevel*5); |
---|
3747 | if (ReqValue > skillValue) |
---|
3748 | return SPELL_FAILED_LOW_CASTLEVEL; |
---|
3749 | |
---|
3750 | // chance for fail at orange skinning attempt |
---|
3751 | if( (m_selfContainer && (*m_selfContainer) == this) && |
---|
3752 | skillValue < sWorld.GetConfigMaxSkillValue() && |
---|
3753 | (ReqValue < 0 ? 0 : ReqValue) > irand(skillValue-25, skillValue+37) ) |
---|
3754 | return SPELL_FAILED_TRY_AGAIN; |
---|
3755 | |
---|
3756 | break; |
---|
3757 | } |
---|
3758 | case SPELL_EFFECT_OPEN_LOCK_ITEM: |
---|
3759 | case SPELL_EFFECT_OPEN_LOCK: |
---|
3760 | { |
---|
3761 | if( m_spellInfo->EffectImplicitTargetA[i] != TARGET_GAMEOBJECT && |
---|
3762 | m_spellInfo->EffectImplicitTargetA[i] != TARGET_GAMEOBJECT_ITEM ) |
---|
3763 | break; |
---|
3764 | |
---|
3765 | if( m_caster->GetTypeId() != TYPEID_PLAYER // only players can open locks, gather etc. |
---|
3766 | // we need a go target in case of TARGET_GAMEOBJECT |
---|
3767 | || m_spellInfo->EffectImplicitTargetA[i] == TARGET_GAMEOBJECT && !m_targets.getGOTarget() |
---|
3768 | // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM |
---|
3769 | || m_spellInfo->EffectImplicitTargetA[i] == TARGET_GAMEOBJECT_ITEM && !m_targets.getGOTarget() && |
---|
3770 | (!m_targets.getItemTarget() || !m_targets.getItemTarget()->GetProto()->LockID || m_targets.getItemTarget()->GetOwner() != m_caster ) ) |
---|
3771 | return SPELL_FAILED_BAD_TARGETS; |
---|
3772 | |
---|
3773 | // In BattleGround players can use only flags and banners |
---|
3774 | if( ((Player*)m_caster)->InBattleGround() && |
---|
3775 | !((Player*)m_caster)->isAllowUseBattleGroundObject() ) |
---|
3776 | return SPELL_FAILED_TRY_AGAIN; |
---|
3777 | |
---|
3778 | // get the lock entry |
---|
3779 | LockEntry const *lockInfo = NULL; |
---|
3780 | if (GameObject* go=m_targets.getGOTarget()) |
---|
3781 | lockInfo = sLockStore.LookupEntry(go->GetLockId()); |
---|
3782 | else if(Item* itm=m_targets.getItemTarget()) |
---|
3783 | lockInfo = sLockStore.LookupEntry(itm->GetProto()->LockID); |
---|
3784 | |
---|
3785 | // check lock compatibility |
---|
3786 | if (lockInfo) |
---|
3787 | { |
---|
3788 | // check for lock - key pair (checked by client also, just prevent cheating |
---|
3789 | bool ok_key = false; |
---|
3790 | for(int it = 0; it < 5; ++it) |
---|
3791 | { |
---|
3792 | switch(lockInfo->keytype[it]) |
---|
3793 | { |
---|
3794 | case LOCK_KEY_NONE: |
---|
3795 | break; |
---|
3796 | case LOCK_KEY_ITEM: |
---|
3797 | { |
---|
3798 | if(lockInfo->key[it]) |
---|
3799 | { |
---|
3800 | if(m_CastItem && m_CastItem->GetEntry()==lockInfo->key[it]) |
---|
3801 | ok_key =true; |
---|
3802 | break; |
---|
3803 | } |
---|
3804 | } |
---|
3805 | case LOCK_KEY_SKILL: |
---|
3806 | { |
---|
3807 | if(uint32(m_spellInfo->EffectMiscValue[i])!=lockInfo->key[it]) |
---|
3808 | break; |
---|
3809 | |
---|
3810 | switch(lockInfo->key[it]) |
---|
3811 | { |
---|
3812 | case LOCKTYPE_HERBALISM: |
---|
3813 | if(((Player*)m_caster)->HasSkill(SKILL_HERBALISM)) |
---|
3814 | ok_key =true; |
---|
3815 | break; |
---|
3816 | case LOCKTYPE_MINING: |
---|
3817 | if(((Player*)m_caster)->HasSkill(SKILL_MINING)) |
---|
3818 | ok_key =true; |
---|
3819 | break; |
---|
3820 | default: |
---|
3821 | ok_key =true; |
---|
3822 | break; |
---|
3823 | } |
---|
3824 | } |
---|
3825 | } |
---|
3826 | if(ok_key) |
---|
3827 | break; |
---|
3828 | } |
---|
3829 | |
---|
3830 | if(!ok_key) |
---|
3831 | return SPELL_FAILED_BAD_TARGETS; |
---|
3832 | } |
---|
3833 | |
---|
3834 | // chance for fail at orange mining/herb/LockPicking gathering attempt |
---|
3835 | if (!m_selfContainer || ((*m_selfContainer) != this)) |
---|
3836 | break; |
---|
3837 | |
---|
3838 | // get the skill value of the player |
---|
3839 | int32 SkillValue = 0; |
---|
3840 | bool canFailAtMax = true; |
---|
3841 | if (m_spellInfo->EffectMiscValue[i] == LOCKTYPE_HERBALISM) |
---|
3842 | { |
---|
3843 | SkillValue = ((Player*)m_caster)->GetSkillValue(SKILL_HERBALISM); |
---|
3844 | canFailAtMax = false; |
---|
3845 | } |
---|
3846 | else if (m_spellInfo->EffectMiscValue[i] == LOCKTYPE_MINING) |
---|
3847 | { |
---|
3848 | SkillValue = ((Player*)m_caster)->GetSkillValue(SKILL_MINING); |
---|
3849 | canFailAtMax = false; |
---|
3850 | } |
---|
3851 | else if (m_spellInfo->EffectMiscValue[i] == LOCKTYPE_PICKLOCK) |
---|
3852 | SkillValue = ((Player*)m_caster)->GetSkillValue(SKILL_LOCKPICKING); |
---|
3853 | |
---|
3854 | // castitem check: rogue using skeleton keys. the skill values should not be added in this case. |
---|
3855 | if(m_CastItem) |
---|
3856 | SkillValue = 0; |
---|
3857 | |
---|
3858 | // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value) |
---|
3859 | SkillValue += m_currentBasePoints[i]+1; |
---|
3860 | |
---|
3861 | // get the required lock value |
---|
3862 | int32 ReqValue=0; |
---|
3863 | if (lockInfo) |
---|
3864 | { |
---|
3865 | // check for lock - key pair |
---|
3866 | bool ok = false; |
---|
3867 | for(int it = 0; it < 5; ++it) |
---|
3868 | { |
---|
3869 | if(lockInfo->keytype[it]==LOCK_KEY_ITEM && lockInfo->key[it] && m_CastItem && m_CastItem->GetEntry()==lockInfo->key[it]) |
---|
3870 | { |
---|
3871 | // if so, we're good to go |
---|
3872 | ok = true; |
---|
3873 | break; |
---|
3874 | } |
---|
3875 | } |
---|
3876 | if(ok) |
---|
3877 | break; |
---|
3878 | |
---|
3879 | if (m_spellInfo->EffectMiscValue[i] == LOCKTYPE_PICKLOCK) |
---|
3880 | ReqValue = lockInfo->requiredlockskill; |
---|
3881 | else |
---|
3882 | ReqValue = lockInfo->requiredminingskill; |
---|
3883 | } |
---|
3884 | |
---|
3885 | // skill doesn't meet the required value |
---|
3886 | if (ReqValue > SkillValue) |
---|
3887 | return SPELL_FAILED_LOW_CASTLEVEL; |
---|
3888 | |
---|
3889 | // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill) |
---|
3890 | if((canFailAtMax || SkillValue < sWorld.GetConfigMaxSkillValue()) && ReqValue > irand(SkillValue-25, SkillValue+37)) |
---|
3891 | return SPELL_FAILED_TRY_AGAIN; |
---|
3892 | |
---|
3893 | break; |
---|
3894 | } |
---|
3895 | case SPELL_EFFECT_SUMMON_DEAD_PET: |
---|
3896 | { |
---|
3897 | Creature *pet = m_caster->GetPet(); |
---|
3898 | if(!pet) |
---|
3899 | return SPELL_FAILED_NO_PET; |
---|
3900 | |
---|
3901 | if(pet->isAlive()) |
---|
3902 | return SPELL_FAILED_ALREADY_HAVE_SUMMON; |
---|
3903 | |
---|
3904 | break; |
---|
3905 | } |
---|
3906 | // This is generic summon effect now and don't make this check for summon types similar |
---|
3907 | // SPELL_EFFECT_SUMMON_CRITTER, SPELL_EFFECT_SUMMON_WILD or SPELL_EFFECT_SUMMON_GUARDIAN. |
---|
3908 | // These won't show up in m_caster->GetPetGUID() |
---|
3909 | case SPELL_EFFECT_SUMMON: |
---|
3910 | { |
---|
3911 | switch(m_spellInfo->EffectMiscValueB[i]) |
---|
3912 | { |
---|
3913 | case SUMMON_TYPE_POSESSED: |
---|
3914 | case SUMMON_TYPE_POSESSED2: |
---|
3915 | case SUMMON_TYPE_DEMON: |
---|
3916 | case SUMMON_TYPE_SUMMON: |
---|
3917 | { |
---|
3918 | if(m_caster->GetPetGUID()) |
---|
3919 | return SPELL_FAILED_ALREADY_HAVE_SUMMON; |
---|
3920 | |
---|
3921 | if(m_caster->GetCharmGUID()) |
---|
3922 | return SPELL_FAILED_ALREADY_HAVE_CHARM; |
---|
3923 | break; |
---|
3924 | } |
---|
3925 | } |
---|
3926 | break; |
---|
3927 | } |
---|
3928 | // Don't make this check for SPELL_EFFECT_SUMMON_CRITTER, SPELL_EFFECT_SUMMON_WILD or SPELL_EFFECT_SUMMON_GUARDIAN. |
---|
3929 | // These won't show up in m_caster->GetPetGUID() |
---|
3930 | case SPELL_EFFECT_SUMMON_POSSESSED: |
---|
3931 | case SPELL_EFFECT_SUMMON_PHANTASM: |
---|
3932 | case SPELL_EFFECT_SUMMON_DEMON: |
---|
3933 | { |
---|
3934 | if(m_caster->GetPetGUID()) |
---|
3935 | return SPELL_FAILED_ALREADY_HAVE_SUMMON; |
---|
3936 | |
---|
3937 | if(m_caster->GetCharmGUID()) |
---|
3938 | return SPELL_FAILED_ALREADY_HAVE_CHARM; |
---|
3939 | |
---|
3940 | break; |
---|
3941 | } |
---|
3942 | case SPELL_EFFECT_SUMMON_PET: |
---|
3943 | { |
---|
3944 | if(m_caster->GetPetGUID()) //let warlock do a replacement summon |
---|
3945 | { |
---|
3946 | |
---|
3947 | Pet* pet = ((Player*)m_caster)->GetPet(); |
---|
3948 | |
---|
3949 | if (m_caster->GetTypeId()==TYPEID_PLAYER && m_caster->getClass()==CLASS_WARLOCK) |
---|
3950 | { |
---|
3951 | if (strict) //starting cast, trigger pet stun (cast by pet so it doesn't attack player) |
---|
3952 | pet->CastSpell(pet, 32752, true, NULL, NULL, pet->GetGUID()); |
---|
3953 | } |
---|
3954 | else |
---|
3955 | return SPELL_FAILED_ALREADY_HAVE_SUMMON; |
---|
3956 | } |
---|
3957 | |
---|
3958 | if(m_caster->GetCharmGUID()) |
---|
3959 | return SPELL_FAILED_ALREADY_HAVE_CHARM; |
---|
3960 | |
---|
3961 | break; |
---|
3962 | } |
---|
3963 | case SPELL_EFFECT_SUMMON_PLAYER: |
---|
3964 | { |
---|
3965 | if(m_caster->GetTypeId()!=TYPEID_PLAYER) |
---|
3966 | return SPELL_FAILED_BAD_TARGETS; |
---|
3967 | if(!((Player*)m_caster)->GetSelection()) |
---|
3968 | return SPELL_FAILED_BAD_TARGETS; |
---|
3969 | |
---|
3970 | Player* target = objmgr.GetPlayer(((Player*)m_caster)->GetSelection()); |
---|
3971 | if( !target || ((Player*)m_caster)==target || !target->IsInSameRaidWith((Player*)m_caster) ) |
---|
3972 | return SPELL_FAILED_BAD_TARGETS; |
---|
3973 | |
---|
3974 | // check if our map is dungeon |
---|
3975 | if( sMapStore.LookupEntry(m_caster->GetMapId())->IsDungeon() ) |
---|
3976 | { |
---|
3977 | InstanceTemplate const* instance = ObjectMgr::GetInstanceTemplate(m_caster->GetMapId()); |
---|
3978 | if(!instance) |
---|
3979 | return SPELL_FAILED_TARGET_NOT_IN_INSTANCE; |
---|
3980 | if ( instance->levelMin > target->getLevel() ) |
---|
3981 | return SPELL_FAILED_LOWLEVEL; |
---|
3982 | if ( instance->levelMax && instance->levelMax < target->getLevel() ) |
---|
3983 | return SPELL_FAILED_HIGHLEVEL; |
---|
3984 | } |
---|
3985 | break; |
---|
3986 | } |
---|
3987 | case SPELL_EFFECT_LEAP: |
---|
3988 | case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER: |
---|
3989 | { |
---|
3990 | float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i])); |
---|
3991 | float fx = m_caster->GetPositionX() + dis * cos(m_caster->GetOrientation()); |
---|
3992 | float fy = m_caster->GetPositionY() + dis * sin(m_caster->GetOrientation()); |
---|
3993 | // teleport a bit above terrain level to avoid falling below it |
---|
3994 | float fz = MapManager::Instance().GetBaseMap(m_caster->GetMapId())->GetHeight(fx,fy,m_caster->GetPositionZ(),true); |
---|
3995 | if(fz <= INVALID_HEIGHT) // note: this also will prevent use effect in instances without vmaps height enabled |
---|
3996 | return SPELL_FAILED_TRY_AGAIN; |
---|
3997 | |
---|
3998 | float caster_pos_z = m_caster->GetPositionZ(); |
---|
3999 | // Control the caster to not climb or drop when +-fz > 8 |
---|
4000 | if(!(fz<=caster_pos_z+8 && fz>=caster_pos_z-8)) |
---|
4001 | return SPELL_FAILED_TRY_AGAIN; |
---|
4002 | |
---|
4003 | // not allow use this effect at battleground until battleground start |
---|
4004 | if(m_caster->GetTypeId()==TYPEID_PLAYER) |
---|
4005 | if(BattleGround const *bg = ((Player*)m_caster)->GetBattleGround()) |
---|
4006 | if(bg->GetStatus() != STATUS_IN_PROGRESS) |
---|
4007 | return SPELL_FAILED_TRY_AGAIN; |
---|
4008 | break; |
---|
4009 | } |
---|
4010 | case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF: |
---|
4011 | { |
---|
4012 | if (m_targets.getUnitTarget()==m_caster) |
---|
4013 | return SPELL_FAILED_BAD_TARGETS; |
---|
4014 | break; |
---|
4015 | } |
---|
4016 | default:break; |
---|
4017 | } |
---|
4018 | } |
---|
4019 | |
---|
4020 | for (int i = 0; i < 3; i++) |
---|
4021 | { |
---|
4022 | switch(m_spellInfo->EffectApplyAuraName[i]) |
---|
4023 | { |
---|
4024 | case SPELL_AURA_MOD_POSSESS: |
---|
4025 | case SPELL_AURA_MOD_CHARM: |
---|
4026 | { |
---|
4027 | if(m_caster->GetPetGUID()) |
---|
4028 | return SPELL_FAILED_ALREADY_HAVE_SUMMON; |
---|
4029 | |
---|
4030 | if(m_caster->GetCharmGUID()) |
---|
4031 | return SPELL_FAILED_ALREADY_HAVE_CHARM; |
---|
4032 | |
---|
4033 | if(m_caster->GetCharmerGUID()) |
---|
4034 | return SPELL_FAILED_CHARMED; |
---|
4035 | |
---|
4036 | if(!m_targets.getUnitTarget()) |
---|
4037 | return SPELL_FAILED_BAD_IMPLICIT_TARGETS; |
---|
4038 | |
---|
4039 | if(m_targets.getUnitTarget()->GetCharmerGUID()) |
---|
4040 | return SPELL_FAILED_CHARMED; |
---|
4041 | |
---|
4042 | if(int32(m_targets.getUnitTarget()->getLevel()) > CalculateDamage(i,m_targets.getUnitTarget())) |
---|
4043 | return SPELL_FAILED_HIGHLEVEL; |
---|
4044 | };break; |
---|
4045 | case SPELL_AURA_MOUNTED: |
---|
4046 | { |
---|
4047 | if (m_caster->IsInWater()) |
---|
4048 | return SPELL_FAILED_ONLY_ABOVEWATER; |
---|
4049 | |
---|
4050 | if (m_caster->GetTypeId()==TYPEID_PLAYER && ((Player*)m_caster)->GetTransport()) |
---|
4051 | return SPELL_FAILED_NO_MOUNTS_ALLOWED; |
---|
4052 | |
---|
4053 | // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells |
---|
4054 | if (m_caster->GetTypeId()==TYPEID_PLAYER && !sMapStore.LookupEntry(m_caster->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell && !m_spellInfo->AreaId) |
---|
4055 | return SPELL_FAILED_NO_MOUNTS_ALLOWED; |
---|
4056 | |
---|
4057 | if (m_caster->GetAreaId()==35) |
---|
4058 | return SPELL_FAILED_NO_MOUNTS_ALLOWED; |
---|
4059 | |
---|
4060 | ShapeshiftForm form = m_caster->m_form; |
---|
4061 | if( form == FORM_CAT || form == FORM_TREE || form == FORM_TRAVEL || |
---|
4062 | form == FORM_AQUA || form == FORM_BEAR || form == FORM_DIREBEAR || |
---|
4063 | form == FORM_CREATUREBEAR || form == FORM_GHOSTWOLF || form == FORM_FLIGHT || |
---|
4064 | form == FORM_FLIGHT_EPIC || form == FORM_MOONKIN ) |
---|
4065 | return SPELL_FAILED_NOT_SHAPESHIFT; |
---|
4066 | |
---|
4067 | break; |
---|
4068 | } |
---|
4069 | case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS: |
---|
4070 | { |
---|
4071 | if(!m_targets.getUnitTarget()) |
---|
4072 | return SPELL_FAILED_BAD_IMPLICIT_TARGETS; |
---|
4073 | |
---|
4074 | // can be casted at non-friendly unit or own pet/charm |
---|
4075 | if(m_caster->IsFriendlyTo(m_targets.getUnitTarget())) |
---|
4076 | return SPELL_FAILED_TARGET_FRIENDLY; |
---|
4077 | };break; |
---|
4078 | case SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED: |
---|
4079 | case SPELL_AURA_FLY: |
---|
4080 | { |
---|
4081 | // not allow cast fly spells at old maps by players (all spells is self target) |
---|
4082 | if(m_caster->GetTypeId()==TYPEID_PLAYER) |
---|
4083 | { |
---|
4084 | if( !((Player*)m_caster)->isGameMaster() && |
---|
4085 | GetVirtualMapForMapAndZone(m_caster->GetMapId(),m_caster->GetZoneId()) != 530) |
---|
4086 | return SPELL_FAILED_NOT_HERE; |
---|
4087 | } |
---|
4088 | };break; |
---|
4089 | case SPELL_AURA_PERIODIC_MANA_LEECH: |
---|
4090 | { |
---|
4091 | if (!m_targets.getUnitTarget()) |
---|
4092 | return SPELL_FAILED_BAD_IMPLICIT_TARGETS; |
---|
4093 | |
---|
4094 | if (m_caster->GetTypeId()!=TYPEID_PLAYER || m_CastItem) |
---|
4095 | break; |
---|
4096 | |
---|
4097 | if(m_targets.getUnitTarget()->getPowerType()!=POWER_MANA) |
---|
4098 | return SPELL_FAILED_BAD_TARGETS; |
---|
4099 | break; |
---|
4100 | } |
---|
4101 | default:break; |
---|
4102 | } |
---|
4103 | } |
---|
4104 | |
---|
4105 | // all ok |
---|
4106 | return 0; |
---|
4107 | } |
---|
4108 | |
---|
4109 | int16 Spell::PetCanCast(Unit* target) |
---|
4110 | { |
---|
4111 | if(!m_caster->isAlive()) |
---|
4112 | return SPELL_FAILED_CASTER_DEAD; |
---|
4113 | |
---|
4114 | if(m_caster->IsNonMeleeSpellCasted(false)) //prevent spellcast interuption by another spellcast |
---|
4115 | return SPELL_FAILED_SPELL_IN_PROGRESS; |
---|
4116 | if(m_caster->isInCombat() && IsNonCombatSpell(m_spellInfo)) |
---|
4117 | return SPELL_FAILED_AFFECTING_COMBAT; |
---|
4118 | |
---|
4119 | if(m_caster->GetTypeId()==TYPEID_UNIT && (((Creature*)m_caster)->isPet() || m_caster->isCharmed())) |
---|
4120 | { |
---|
4121 | //dead owner (pets still alive when owners ressed?) |
---|
4122 | if(m_caster->GetCharmerOrOwner() && !m_caster->GetCharmerOrOwner()->isAlive()) |
---|
4123 | return SPELL_FAILED_CASTER_DEAD; |
---|
4124 | |
---|
4125 | if(!target && m_targets.getUnitTarget()) |
---|
4126 | target = m_targets.getUnitTarget(); |
---|
4127 | |
---|
4128 | bool need = false; |
---|
4129 | for(uint32 i = 0;i<3;i++) |
---|
4130 | { |
---|
4131 | if(m_spellInfo->EffectImplicitTargetA[i] == TARGET_CHAIN_DAMAGE || m_spellInfo->EffectImplicitTargetA[i] == TARGET_SINGLE_FRIEND || m_spellInfo->EffectImplicitTargetA[i] == TARGET_DUELVSPLAYER || m_spellInfo->EffectImplicitTargetA[i] == TARGET_SINGLE_PARTY || m_spellInfo->EffectImplicitTargetA[i] == TARGET_CURRENT_ENEMY_COORDINATES) |
---|
4132 | { |
---|
4133 | need = true; |
---|
4134 | if(!target) |
---|
4135 | return SPELL_FAILED_BAD_IMPLICIT_TARGETS; |
---|
4136 | break; |
---|
4137 | } |
---|
4138 | } |
---|
4139 | if(need) |
---|
4140 | m_targets.setUnitTarget(target); |
---|
4141 | |
---|
4142 | Unit* _target = m_targets.getUnitTarget(); |
---|
4143 | |
---|
4144 | if(_target) //for target dead/target not valid |
---|
4145 | { |
---|
4146 | if(!_target->isAlive()) |
---|
4147 | return SPELL_FAILED_BAD_TARGETS; |
---|
4148 | |
---|
4149 | if(IsPositiveSpell(m_spellInfo->Id)) |
---|
4150 | { |
---|
4151 | if(m_caster->IsHostileTo(_target)) |
---|
4152 | return SPELL_FAILED_BAD_TARGETS; |
---|
4153 | } |
---|
4154 | else |
---|
4155 | { |
---|
4156 | bool duelvsplayertar = false; |
---|
4157 | for(int j=0;j<3;j++) |
---|
4158 | { |
---|
4159 | //TARGET_DUELVSPLAYER is positive AND negative |
---|
4160 | duelvsplayertar |= (m_spellInfo->EffectImplicitTargetA[j] == TARGET_DUELVSPLAYER); |
---|
4161 | } |
---|
4162 | if(m_caster->IsFriendlyTo(target) && !duelvsplayertar) |
---|
4163 | { |
---|
4164 | return SPELL_FAILED_BAD_TARGETS; |
---|
4165 | } |
---|
4166 | } |
---|
4167 | } |
---|
4168 | //cooldown |
---|
4169 | if(((Creature*)m_caster)->HasSpellCooldown(m_spellInfo->Id)) |
---|
4170 | return SPELL_FAILED_NOT_READY; |
---|
4171 | } |
---|
4172 | |
---|
4173 | uint16 result = CanCast(true); |
---|
4174 | if(result != 0) |
---|
4175 | return result; |
---|
4176 | else |
---|
4177 | return -1; //this allows to check spell fail 0, in combat |
---|
4178 | } |
---|
4179 | |
---|
4180 | uint8 Spell::CheckCasterAuras() const |
---|
4181 | { |
---|
4182 | // Flag drop spells totally immuned to caster auras |
---|
4183 | // FIXME: find more nice check for all totally immuned spells |
---|
4184 | // AttributesEx3 & 0x10000000? |
---|
4185 | if(m_spellInfo->Id==23336 || m_spellInfo->Id==23334 || m_spellInfo->Id==34991) |
---|
4186 | return 0; |
---|
4187 | |
---|
4188 | uint8 school_immune = 0; |
---|
4189 | uint32 mechanic_immune = 0; |
---|
4190 | uint32 dispel_immune = 0; |
---|
4191 | |
---|
4192 | //Check if the spell grants school or mechanic immunity. |
---|
4193 | //We use bitmasks so the loop is done only once and not on every aura check below. |
---|
4194 | if ( m_spellInfo->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY ) |
---|
4195 | { |
---|
4196 | for(int i = 0;i < 3; i ++) |
---|
4197 | { |
---|
4198 | if(m_spellInfo->EffectApplyAuraName[i] == SPELL_AURA_SCHOOL_IMMUNITY) |
---|
4199 | school_immune |= uint32(m_spellInfo->EffectMiscValue[i]); |
---|
4200 | else if(m_spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MECHANIC_IMMUNITY) |
---|
4201 | mechanic_immune |= 1 << uint32(m_spellInfo->EffectMiscValue[i]); |
---|
4202 | else if(m_spellInfo->EffectApplyAuraName[i] == SPELL_AURA_DISPEL_IMMUNITY) |
---|
4203 | dispel_immune |= GetDispellMask(DispelType(m_spellInfo->EffectMiscValue[i])); |
---|
4204 | } |
---|
4205 | //immune movement impairement and loss of control |
---|
4206 | if(m_spellInfo->Id==(uint32)42292) |
---|
4207 | mechanic_immune = IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK; |
---|
4208 | } |
---|
4209 | |
---|
4210 | //Check whether the cast should be prevented by any state you might have. |
---|
4211 | uint8 prevented_reason = 0; |
---|
4212 | // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out |
---|
4213 | if(!(m_spellInfo->AttributesEx5 & SPELL_ATTR_EX5_USABLE_WHILE_STUNNED) && m_caster->HasAuraType(SPELL_AURA_MOD_STUN)) |
---|
4214 | prevented_reason = SPELL_FAILED_STUNNED; |
---|
4215 | else if(m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED) && !(m_spellInfo->AttributesEx5 & SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED)) |
---|
4216 | prevented_reason = SPELL_FAILED_CONFUSED; |
---|
4217 | else if(m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING) && !(m_spellInfo->AttributesEx5 & SPELL_ATTR_EX5_USABLE_WHILE_FEARED)) |
---|
4218 | prevented_reason = SPELL_FAILED_FLEEING; |
---|
4219 | else if(m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED) && m_spellInfo->PreventionType==SPELL_PREVENTION_TYPE_SILENCE) |
---|
4220 | prevented_reason = SPELL_FAILED_SILENCED; |
---|
4221 | else if(m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED) && m_spellInfo->PreventionType==SPELL_PREVENTION_TYPE_PACIFY) |
---|
4222 | prevented_reason = SPELL_FAILED_PACIFIED; |
---|
4223 | |
---|
4224 | // Attr must make flag drop spell totally immuned from all effects |
---|
4225 | if(prevented_reason) |
---|
4226 | { |
---|
4227 | if(school_immune || mechanic_immune || dispel_immune) |
---|
4228 | { |
---|
4229 | //Checking auras is needed now, because you are prevented by some state but the spell grants immunity. |
---|
4230 | Unit::AuraMap const& auras = m_caster->GetAuras(); |
---|
4231 | for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); itr++) |
---|
4232 | { |
---|
4233 | if(itr->second) |
---|
4234 | { |
---|
4235 | if( GetSpellMechanicMask(itr->second->GetSpellProto(), itr->second->GetEffIndex()) & mechanic_immune ) |
---|
4236 | continue; |
---|
4237 | if( GetSpellSchoolMask(itr->second->GetSpellProto()) & school_immune ) |
---|
4238 | continue; |
---|
4239 | if( (1<<(itr->second->GetSpellProto()->Dispel)) & dispel_immune) |
---|
4240 | continue; |
---|
4241 | |
---|
4242 | //Make a second check for spell failed so the right SPELL_FAILED message is returned. |
---|
4243 | //That is needed when your casting is prevented by multiple states and you are only immune to some of them. |
---|
4244 | switch(itr->second->GetModifier()->m_auraname) |
---|
4245 | { |
---|
4246 | case SPELL_AURA_MOD_STUN: |
---|
4247 | if (!(m_spellInfo->AttributesEx5 & SPELL_ATTR_EX5_USABLE_WHILE_STUNNED)) |
---|
4248 | return SPELL_FAILED_STUNNED; |
---|
4249 | break; |
---|
4250 | case SPELL_AURA_MOD_CONFUSE: |
---|
4251 | if (!(m_spellInfo->AttributesEx5 & SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED)) |
---|
4252 | return SPELL_FAILED_CONFUSED; |
---|
4253 | break; |
---|
4254 | case SPELL_AURA_MOD_FEAR: |
---|
4255 | if (!(m_spellInfo->AttributesEx5 & SPELL_ATTR_EX5_USABLE_WHILE_FEARED)) |
---|
4256 | return SPELL_FAILED_FLEEING; |
---|
4257 | break; |
---|
4258 | case SPELL_AURA_MOD_SILENCE: |
---|
4259 | case SPELL_AURA_MOD_PACIFY: |
---|
4260 | case SPELL_AURA_MOD_PACIFY_SILENCE: |
---|
4261 | if( m_spellInfo->PreventionType==SPELL_PREVENTION_TYPE_PACIFY) |
---|
4262 | return SPELL_FAILED_PACIFIED; |
---|
4263 | else if ( m_spellInfo->PreventionType==SPELL_PREVENTION_TYPE_SILENCE) |
---|
4264 | return SPELL_FAILED_SILENCED; |
---|
4265 | break; |
---|
4266 | } |
---|
4267 | } |
---|
4268 | } |
---|
4269 | } |
---|
4270 | //You are prevented from casting and the spell casted does not grant immunity. Return a failed error. |
---|
4271 | else |
---|
4272 | return prevented_reason; |
---|
4273 | } |
---|
4274 | return 0; // all ok |
---|
4275 | } |
---|
4276 | |
---|
4277 | bool Spell::CanAutoCast(Unit* target) |
---|
4278 | { |
---|
4279 | uint64 targetguid = target->GetGUID(); |
---|
4280 | |
---|
4281 | for(uint32 j = 0;j<3;j++) |
---|
4282 | { |
---|
4283 | if(m_spellInfo->Effect[j] == SPELL_EFFECT_APPLY_AURA) |
---|
4284 | { |
---|
4285 | if( m_spellInfo->StackAmount <= 1) |
---|
4286 | { |
---|
4287 | if( target->HasAura(m_spellInfo->Id, j) ) |
---|
4288 | return false; |
---|
4289 | } |
---|
4290 | else |
---|
4291 | { |
---|
4292 | if( target->GetAuras().count(Unit::spellEffectPair(m_spellInfo->Id, j)) >= m_spellInfo->StackAmount) |
---|
4293 | return false; |
---|
4294 | } |
---|
4295 | } |
---|
4296 | else if ( IsAreaAuraEffect( m_spellInfo->Effect[j] )) |
---|
4297 | { |
---|
4298 | if( target->HasAura(m_spellInfo->Id, j) ) |
---|
4299 | return false; |
---|
4300 | } |
---|
4301 | } |
---|
4302 | |
---|
4303 | int16 result = PetCanCast(target); |
---|
4304 | |
---|
4305 | if(result == -1 || result == SPELL_FAILED_UNIT_NOT_INFRONT) |
---|
4306 | { |
---|
4307 | FillTargetMap(); |
---|
4308 | //check if among target units, our WANTED target is as well (->only self cast spells return false) |
---|
4309 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit) |
---|
4310 | if( ihit->targetGUID == targetguid ) |
---|
4311 | return true; |
---|
4312 | } |
---|
4313 | return false; //target invalid |
---|
4314 | } |
---|
4315 | |
---|
4316 | uint8 Spell::CheckRange(bool strict) |
---|
4317 | { |
---|
4318 | float range_mod; |
---|
4319 | |
---|
4320 | // self cast doesn't need range checking -- also for Starshards fix |
---|
4321 | if (m_spellInfo->rangeIndex == 1) return 0; |
---|
4322 | |
---|
4323 | if (strict) //add radius of caster |
---|
4324 | range_mod = 1.25; |
---|
4325 | else //add radius of caster and ~5 yds "give" |
---|
4326 | range_mod = 6.25; |
---|
4327 | |
---|
4328 | SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex); |
---|
4329 | float max_range = GetSpellMaxRange(srange) + range_mod; |
---|
4330 | float min_range = GetSpellMinRange(srange); |
---|
4331 | |
---|
4332 | if(Player* modOwner = m_caster->GetSpellModOwner()) |
---|
4333 | modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RANGE, max_range, this); |
---|
4334 | |
---|
4335 | Unit *target = m_targets.getUnitTarget(); |
---|
4336 | |
---|
4337 | if(target && target != m_caster) |
---|
4338 | { |
---|
4339 | // distance from target center in checks |
---|
4340 | if(!m_caster->IsWithinCombatDist(target, max_range)) |
---|
4341 | return SPELL_FAILED_OUT_OF_RANGE; //0x5A; |
---|
4342 | if(min_range && m_caster->IsWithinCombatDist(target, min_range)) // skip this check if min_range = 0 |
---|
4343 | return SPELL_FAILED_TOO_CLOSE; |
---|
4344 | if( m_caster->GetTypeId() == TYPEID_PLAYER && |
---|
4345 | (m_spellInfo->FacingCasterFlags & SPELL_FACING_FLAG_INFRONT) && !m_caster->HasInArc( M_PI, target ) ) |
---|
4346 | return SPELL_FAILED_UNIT_NOT_INFRONT; |
---|
4347 | } |
---|
4348 | |
---|
4349 | if(m_targets.m_targetMask == TARGET_FLAG_DEST_LOCATION && m_targets.m_destX != 0 && m_targets.m_destY != 0 && m_targets.m_destZ != 0) |
---|
4350 | { |
---|
4351 | float dist = m_caster->GetDistance(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ); |
---|
4352 | if(dist > max_range) |
---|
4353 | return SPELL_FAILED_OUT_OF_RANGE; |
---|
4354 | if(dist < min_range) |
---|
4355 | return SPELL_FAILED_TOO_CLOSE; |
---|
4356 | } |
---|
4357 | |
---|
4358 | return 0; // ok |
---|
4359 | } |
---|
4360 | |
---|
4361 | int32 Spell::CalculatePowerCost() |
---|
4362 | { |
---|
4363 | // item cast not used power |
---|
4364 | if(m_CastItem) |
---|
4365 | return 0; |
---|
4366 | |
---|
4367 | // Spell drain all exist power on cast (Only paladin lay of Hands) |
---|
4368 | if (m_spellInfo->AttributesEx & SPELL_ATTR_EX_DRAIN_ALL_POWER) |
---|
4369 | { |
---|
4370 | // If power type - health drain all |
---|
4371 | if (m_spellInfo->powerType == POWER_HEALTH) |
---|
4372 | return m_caster->GetHealth(); |
---|
4373 | // Else drain all power |
---|
4374 | if (m_spellInfo->powerType < MAX_POWERS) |
---|
4375 | return m_caster->GetPower(Powers(m_spellInfo->powerType)); |
---|
4376 | sLog.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo->powerType, m_spellInfo->Id); |
---|
4377 | return 0; |
---|
4378 | } |
---|
4379 | |
---|
4380 | // Base powerCost |
---|
4381 | int32 powerCost = m_spellInfo->manaCost; |
---|
4382 | // PCT cost from total amount |
---|
4383 | if (m_spellInfo->ManaCostPercentage) |
---|
4384 | { |
---|
4385 | switch (m_spellInfo->powerType) |
---|
4386 | { |
---|
4387 | // health as power used |
---|
4388 | case POWER_HEALTH: |
---|
4389 | powerCost += m_spellInfo->ManaCostPercentage * m_caster->GetCreateHealth() / 100; |
---|
4390 | break; |
---|
4391 | case POWER_MANA: |
---|
4392 | powerCost += m_spellInfo->ManaCostPercentage * m_caster->GetCreateMana() / 100; |
---|
4393 | break; |
---|
4394 | case POWER_RAGE: |
---|
4395 | case POWER_FOCUS: |
---|
4396 | case POWER_ENERGY: |
---|
4397 | case POWER_HAPPINESS: |
---|
4398 | // case POWER_RUNES: |
---|
4399 | powerCost += m_spellInfo->ManaCostPercentage * m_caster->GetMaxPower(Powers(m_spellInfo->powerType)) / 100; |
---|
4400 | break; |
---|
4401 | default: |
---|
4402 | sLog.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo->powerType, m_spellInfo->Id); |
---|
4403 | return 0; |
---|
4404 | } |
---|
4405 | } |
---|
4406 | SpellSchools school = GetFirstSchoolInMask(m_spellSchoolMask); |
---|
4407 | // Flat mod from caster auras by spell school |
---|
4408 | powerCost += m_caster->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER + school); |
---|
4409 | // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost) |
---|
4410 | if ( m_spellInfo->AttributesEx4 & SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST ) |
---|
4411 | powerCost += m_caster->GetAttackTime(OFF_ATTACK)/100; |
---|
4412 | // Apply cost mod by spell |
---|
4413 | if(Player* modOwner = m_caster->GetSpellModOwner()) |
---|
4414 | modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_COST, powerCost, this); |
---|
4415 | |
---|
4416 | if(m_spellInfo->Attributes & SPELL_ATTR_LEVEL_DAMAGE_CALCULATION) |
---|
4417 | powerCost = int32(powerCost/ (1.117f* m_spellInfo->spellLevel / m_caster->getLevel() -0.1327f)); |
---|
4418 | |
---|
4419 | // PCT mod from user auras by school |
---|
4420 | powerCost = int32(powerCost * (1.0f+m_caster->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER+school))); |
---|
4421 | if (powerCost < 0) |
---|
4422 | powerCost = 0; |
---|
4423 | return powerCost; |
---|
4424 | } |
---|
4425 | |
---|
4426 | uint8 Spell::CheckPower() |
---|
4427 | { |
---|
4428 | // item cast not used power |
---|
4429 | if(m_CastItem) |
---|
4430 | return 0; |
---|
4431 | |
---|
4432 | // health as power used - need check health amount |
---|
4433 | if(m_spellInfo->powerType == POWER_HEALTH) |
---|
4434 | { |
---|
4435 | if(m_caster->GetHealth() <= m_powerCost) |
---|
4436 | return SPELL_FAILED_CASTER_AURASTATE; |
---|
4437 | return 0; |
---|
4438 | } |
---|
4439 | // Check valid power type |
---|
4440 | if( m_spellInfo->powerType >= MAX_POWERS ) |
---|
4441 | { |
---|
4442 | sLog.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo->powerType); |
---|
4443 | return SPELL_FAILED_UNKNOWN; |
---|
4444 | } |
---|
4445 | // Check power amount |
---|
4446 | Powers powerType = Powers(m_spellInfo->powerType); |
---|
4447 | if(m_caster->GetPower(powerType) < m_powerCost) |
---|
4448 | return SPELL_FAILED_NO_POWER; |
---|
4449 | else |
---|
4450 | return 0; |
---|
4451 | } |
---|
4452 | |
---|
4453 | uint8 Spell::CheckItems() |
---|
4454 | { |
---|
4455 | if (m_caster->GetTypeId() != TYPEID_PLAYER) |
---|
4456 | return 0; |
---|
4457 | |
---|
4458 | uint32 itemid, itemcount; |
---|
4459 | Player* p_caster = (Player*)m_caster; |
---|
4460 | |
---|
4461 | if(m_CastItem) |
---|
4462 | { |
---|
4463 | itemid = m_CastItem->GetEntry(); |
---|
4464 | if( !p_caster->HasItemCount(itemid,1) ) |
---|
4465 | return SPELL_FAILED_ITEM_NOT_READY; |
---|
4466 | else |
---|
4467 | { |
---|
4468 | ItemPrototype const *proto = m_CastItem->GetProto(); |
---|
4469 | if(!proto) |
---|
4470 | return SPELL_FAILED_ITEM_NOT_READY; |
---|
4471 | |
---|
4472 | for (int i = 0; i<5; i++) |
---|
4473 | { |
---|
4474 | if (proto->Spells[i].SpellCharges) |
---|
4475 | { |
---|
4476 | if(m_CastItem->GetSpellCharges(i)==0) |
---|
4477 | return SPELL_FAILED_NO_CHARGES_REMAIN; |
---|
4478 | } |
---|
4479 | } |
---|
4480 | |
---|
4481 | uint32 ItemClass = proto->Class; |
---|
4482 | if (ItemClass == ITEM_CLASS_CONSUMABLE && m_targets.getUnitTarget()) |
---|
4483 | { |
---|
4484 | for (int i = 0; i < 3; i++) |
---|
4485 | { |
---|
4486 | // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster |
---|
4487 | if (m_spellInfo->EffectImplicitTargetA[i] == TARGET_PET) |
---|
4488 | continue; |
---|
4489 | |
---|
4490 | if (m_spellInfo->Effect[i] == SPELL_EFFECT_HEAL) |
---|
4491 | if (m_targets.getUnitTarget()->GetHealth() == m_targets.getUnitTarget()->GetMaxHealth()) |
---|
4492 | return (uint8)SPELL_FAILED_ALREADY_AT_FULL_HEALTH; |
---|
4493 | |
---|
4494 | // Mana Potion, Rage Potion, Thistle Tea(Rogue), ... |
---|
4495 | if (m_spellInfo->Effect[i] == SPELL_EFFECT_ENERGIZE) |
---|
4496 | { |
---|
4497 | if(m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS) |
---|
4498 | return (uint8)SPELL_FAILED_ALREADY_AT_FULL_POWER; |
---|
4499 | |
---|
4500 | Powers power = Powers(m_spellInfo->EffectMiscValue[i]); |
---|
4501 | |
---|
4502 | if (m_targets.getUnitTarget()->GetPower(power) == m_targets.getUnitTarget()->GetMaxPower(power)) |
---|
4503 | return (uint8)SPELL_FAILED_ALREADY_AT_FULL_POWER; |
---|
4504 | } |
---|
4505 | } |
---|
4506 | } |
---|
4507 | } |
---|
4508 | } |
---|
4509 | |
---|
4510 | if(m_targets.getItemTargetGUID()) |
---|
4511 | { |
---|
4512 | if(m_caster->GetTypeId() != TYPEID_PLAYER) |
---|
4513 | return SPELL_FAILED_BAD_TARGETS; |
---|
4514 | |
---|
4515 | if(!m_targets.getItemTarget()) |
---|
4516 | return SPELL_FAILED_ITEM_GONE; |
---|
4517 | |
---|
4518 | if(!m_targets.getItemTarget()->IsFitToSpellRequirements(m_spellInfo)) |
---|
4519 | return SPELL_FAILED_EQUIPPED_ITEM_CLASS; |
---|
4520 | } |
---|
4521 | // if not item target then required item must be equipped |
---|
4522 | else |
---|
4523 | { |
---|
4524 | if(m_caster->GetTypeId() == TYPEID_PLAYER && !((Player*)m_caster)->HasItemFitToSpellReqirements(m_spellInfo)) |
---|
4525 | return SPELL_FAILED_EQUIPPED_ITEM_CLASS; |
---|
4526 | } |
---|
4527 | |
---|
4528 | if(m_spellInfo->RequiresSpellFocus) |
---|
4529 | { |
---|
4530 | CellPair p(Trinity::ComputeCellPair(m_caster->GetPositionX(), m_caster->GetPositionY())); |
---|
4531 | Cell cell(p); |
---|
4532 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
4533 | |
---|
4534 | GameObject* ok = NULL; |
---|
4535 | Trinity::GameObjectFocusCheck go_check(m_caster,m_spellInfo->RequiresSpellFocus); |
---|
4536 | Trinity::GameObjectSearcher<Trinity::GameObjectFocusCheck> checker(ok,go_check); |
---|
4537 | |
---|
4538 | TypeContainerVisitor<Trinity::GameObjectSearcher<Trinity::GameObjectFocusCheck>, GridTypeMapContainer > object_checker(checker); |
---|
4539 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
4540 | cell_lock->Visit(cell_lock, object_checker, *MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)); |
---|
4541 | |
---|
4542 | if(!ok) |
---|
4543 | return (uint8)SPELL_FAILED_REQUIRES_SPELL_FOCUS; |
---|
4544 | |
---|
4545 | focusObject = ok; // game object found in range |
---|
4546 | } |
---|
4547 | |
---|
4548 | if (!(m_spellInfo->AttributesEx5 & SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP && |
---|
4549 | m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PREPARATION))) |
---|
4550 | { |
---|
4551 | for(uint32 i=0;i<8;i++) |
---|
4552 | { |
---|
4553 | if(m_spellInfo->Reagent[i] <= 0) |
---|
4554 | continue; |
---|
4555 | |
---|
4556 | itemid = m_spellInfo->Reagent[i]; |
---|
4557 | itemcount = m_spellInfo->ReagentCount[i]; |
---|
4558 | |
---|
4559 | // if CastItem is also spell reagent |
---|
4560 | if( m_CastItem && m_CastItem->GetEntry() == itemid ) |
---|
4561 | { |
---|
4562 | ItemPrototype const *proto = m_CastItem->GetProto(); |
---|
4563 | if(!proto) |
---|
4564 | return SPELL_FAILED_ITEM_NOT_READY; |
---|
4565 | for(int s=0;s<5;s++) |
---|
4566 | { |
---|
4567 | // CastItem will be used up and does not count as reagent |
---|
4568 | int32 charges = m_CastItem->GetSpellCharges(s); |
---|
4569 | if (proto->Spells[s].SpellCharges < 0 && abs(charges) < 2) |
---|
4570 | { |
---|
4571 | ++itemcount; |
---|
4572 | break; |
---|
4573 | } |
---|
4574 | } |
---|
4575 | } |
---|
4576 | if( !p_caster->HasItemCount(itemid,itemcount) ) |
---|
4577 | return (uint8)SPELL_FAILED_ITEM_NOT_READY; //0x54 |
---|
4578 | } |
---|
4579 | } |
---|
4580 | |
---|
4581 | uint32 totems = 2; |
---|
4582 | for(int i=0;i<2;++i) |
---|
4583 | { |
---|
4584 | if(m_spellInfo->Totem[i] != 0) |
---|
4585 | { |
---|
4586 | if( p_caster->HasItemCount(m_spellInfo->Totem[i],1) ) |
---|
4587 | { |
---|
4588 | totems -= 1; |
---|
4589 | continue; |
---|
4590 | } |
---|
4591 | }else |
---|
4592 | totems -= 1; |
---|
4593 | } |
---|
4594 | if(totems != 0) |
---|
4595 | return (uint8)SPELL_FAILED_TOTEMS; //0x7C |
---|
4596 | |
---|
4597 | //Check items for TotemCategory |
---|
4598 | uint32 TotemCategory = 2; |
---|
4599 | for(int i=0;i<2;++i) |
---|
4600 | { |
---|
4601 | if(m_spellInfo->TotemCategory[i] != 0) |
---|
4602 | { |
---|
4603 | if( p_caster->HasItemTotemCategory(m_spellInfo->TotemCategory[i]) ) |
---|
4604 | { |
---|
4605 | TotemCategory -= 1; |
---|
4606 | continue; |
---|
4607 | } |
---|
4608 | } |
---|
4609 | else |
---|
4610 | TotemCategory -= 1; |
---|
4611 | } |
---|
4612 | if(TotemCategory != 0) |
---|
4613 | return (uint8)SPELL_FAILED_TOTEM_CATEGORY; //0x7B |
---|
4614 | |
---|
4615 | for(int i = 0; i < 3; i++) |
---|
4616 | { |
---|
4617 | switch (m_spellInfo->Effect[i]) |
---|
4618 | { |
---|
4619 | case SPELL_EFFECT_CREATE_ITEM: |
---|
4620 | { |
---|
4621 | if (!m_IsTriggeredSpell && m_spellInfo->EffectItemType[i]) |
---|
4622 | { |
---|
4623 | ItemPosCountVec dest; |
---|
4624 | uint8 msg = p_caster->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, m_spellInfo->EffectItemType[i], 1 ); |
---|
4625 | if (msg != EQUIP_ERR_OK ) |
---|
4626 | { |
---|
4627 | p_caster->SendEquipError( msg, NULL, NULL ); |
---|
4628 | return SPELL_FAILED_DONT_REPORT; |
---|
4629 | } |
---|
4630 | } |
---|
4631 | break; |
---|
4632 | } |
---|
4633 | case SPELL_EFFECT_ENCHANT_ITEM: |
---|
4634 | { |
---|
4635 | Item* targetItem = m_targets.getItemTarget(); |
---|
4636 | if(!targetItem) |
---|
4637 | return SPELL_FAILED_ITEM_NOT_FOUND; |
---|
4638 | |
---|
4639 | if( targetItem->GetProto()->ItemLevel < m_spellInfo->baseLevel ) |
---|
4640 | return SPELL_FAILED_LOWLEVEL; |
---|
4641 | // Not allow enchant in trade slot for some enchant type |
---|
4642 | if( targetItem->GetOwner() != m_caster ) |
---|
4643 | { |
---|
4644 | uint32 enchant_id = m_spellInfo->EffectMiscValue[i]; |
---|
4645 | SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id); |
---|
4646 | if(!pEnchant) |
---|
4647 | return SPELL_FAILED_ERROR; |
---|
4648 | if (pEnchant->slot & ENCHANTMENT_CAN_SOULBOUND) |
---|
4649 | return SPELL_FAILED_NOT_TRADEABLE; |
---|
4650 | } |
---|
4651 | break; |
---|
4652 | } |
---|
4653 | case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY: |
---|
4654 | { |
---|
4655 | Item *item = m_targets.getItemTarget(); |
---|
4656 | if(!item) |
---|
4657 | return SPELL_FAILED_ITEM_NOT_FOUND; |
---|
4658 | // Not allow enchant in trade slot for some enchant type |
---|
4659 | if( item->GetOwner() != m_caster ) |
---|
4660 | { |
---|
4661 | uint32 enchant_id = m_spellInfo->EffectMiscValue[i]; |
---|
4662 | SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id); |
---|
4663 | if(!pEnchant) |
---|
4664 | return SPELL_FAILED_ERROR; |
---|
4665 | if (pEnchant->slot & ENCHANTMENT_CAN_SOULBOUND) |
---|
4666 | return SPELL_FAILED_NOT_TRADEABLE; |
---|
4667 | } |
---|
4668 | break; |
---|
4669 | } |
---|
4670 | case SPELL_EFFECT_ENCHANT_HELD_ITEM: |
---|
4671 | // check item existence in effect code (not output errors at offhand hold item effect to main hand for example |
---|
4672 | break; |
---|
4673 | case SPELL_EFFECT_DISENCHANT: |
---|
4674 | { |
---|
4675 | if(!m_targets.getItemTarget()) |
---|
4676 | return SPELL_FAILED_CANT_BE_DISENCHANTED; |
---|
4677 | |
---|
4678 | // prevent disenchanting in trade slot |
---|
4679 | if( m_targets.getItemTarget()->GetOwnerGUID() != m_caster->GetGUID() ) |
---|
4680 | return SPELL_FAILED_CANT_BE_DISENCHANTED; |
---|
4681 | |
---|
4682 | ItemPrototype const* itemProto = m_targets.getItemTarget()->GetProto(); |
---|
4683 | if(!itemProto) |
---|
4684 | return SPELL_FAILED_CANT_BE_DISENCHANTED; |
---|
4685 | |
---|
4686 | uint32 item_quality = itemProto->Quality; |
---|
4687 | // 2.0.x addon: Check player enchanting level agains the item desenchanting requirements |
---|
4688 | uint32 item_disenchantskilllevel = itemProto->RequiredDisenchantSkill; |
---|
4689 | if (item_disenchantskilllevel == uint32(-1)) |
---|
4690 | return SPELL_FAILED_CANT_BE_DISENCHANTED; |
---|
4691 | if (item_disenchantskilllevel > p_caster->GetSkillValue(SKILL_ENCHANTING)) |
---|
4692 | return SPELL_FAILED_LOW_CASTLEVEL; |
---|
4693 | if(item_quality > 4 || item_quality < 2) |
---|
4694 | return SPELL_FAILED_CANT_BE_DISENCHANTED; |
---|
4695 | if(itemProto->Class != ITEM_CLASS_WEAPON && itemProto->Class != ITEM_CLASS_ARMOR) |
---|
4696 | return SPELL_FAILED_CANT_BE_DISENCHANTED; |
---|
4697 | if (!itemProto->DisenchantID) |
---|
4698 | return SPELL_FAILED_CANT_BE_DISENCHANTED; |
---|
4699 | break; |
---|
4700 | } |
---|
4701 | case SPELL_EFFECT_PROSPECTING: |
---|
4702 | { |
---|
4703 | if(!m_targets.getItemTarget()) |
---|
4704 | return SPELL_FAILED_CANT_BE_PROSPECTED; |
---|
4705 | //ensure item is a prospectable ore |
---|
4706 | if(!(m_targets.getItemTarget()->GetProto()->BagFamily & BAG_FAMILY_MASK_MINING_SUPP) || m_targets.getItemTarget()->GetProto()->Class != ITEM_CLASS_TRADE_GOODS) |
---|
4707 | return SPELL_FAILED_CANT_BE_PROSPECTED; |
---|
4708 | //prevent prospecting in trade slot |
---|
4709 | if( m_targets.getItemTarget()->GetOwnerGUID() != m_caster->GetGUID() ) |
---|
4710 | return SPELL_FAILED_CANT_BE_PROSPECTED; |
---|
4711 | //Check for enough skill in jewelcrafting |
---|
4712 | uint32 item_prospectingskilllevel = m_targets.getItemTarget()->GetProto()->RequiredSkillRank; |
---|
4713 | if(item_prospectingskilllevel >p_caster->GetSkillValue(SKILL_JEWELCRAFTING)) |
---|
4714 | return SPELL_FAILED_LOW_CASTLEVEL; |
---|
4715 | //make sure the player has the required ores in inventory |
---|
4716 | if(m_targets.getItemTarget()->GetCount() < 5) |
---|
4717 | return SPELL_FAILED_PROSPECT_NEED_MORE; |
---|
4718 | |
---|
4719 | if(!LootTemplates_Prospecting.HaveLootFor(m_targets.getItemTargetEntry())) |
---|
4720 | return SPELL_FAILED_CANT_BE_PROSPECTED; |
---|
4721 | |
---|
4722 | break; |
---|
4723 | } |
---|
4724 | case SPELL_EFFECT_WEAPON_DAMAGE: |
---|
4725 | case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL: |
---|
4726 | { |
---|
4727 | if(m_caster->GetTypeId() != TYPEID_PLAYER) return SPELL_FAILED_TARGET_NOT_PLAYER; |
---|
4728 | if( m_attackType != RANGED_ATTACK ) |
---|
4729 | break; |
---|
4730 | Item *pItem = ((Player*)m_caster)->GetWeaponForAttack(m_attackType); |
---|
4731 | if(!pItem || pItem->IsBroken()) |
---|
4732 | return SPELL_FAILED_EQUIPPED_ITEM; |
---|
4733 | |
---|
4734 | switch(pItem->GetProto()->SubClass) |
---|
4735 | { |
---|
4736 | case ITEM_SUBCLASS_WEAPON_THROWN: |
---|
4737 | { |
---|
4738 | uint32 ammo = pItem->GetEntry(); |
---|
4739 | if( !((Player*)m_caster)->HasItemCount( ammo, 1 ) ) |
---|
4740 | return SPELL_FAILED_NO_AMMO; |
---|
4741 | }; break; |
---|
4742 | case ITEM_SUBCLASS_WEAPON_GUN: |
---|
4743 | case ITEM_SUBCLASS_WEAPON_BOW: |
---|
4744 | case ITEM_SUBCLASS_WEAPON_CROSSBOW: |
---|
4745 | { |
---|
4746 | uint32 ammo = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID); |
---|
4747 | if(!ammo) |
---|
4748 | { |
---|
4749 | // Requires No Ammo |
---|
4750 | if(m_caster->GetDummyAura(46699)) |
---|
4751 | break; // skip other checks |
---|
4752 | |
---|
4753 | return SPELL_FAILED_NO_AMMO; |
---|
4754 | } |
---|
4755 | |
---|
4756 | ItemPrototype const *ammoProto = objmgr.GetItemPrototype( ammo ); |
---|
4757 | if(!ammoProto) |
---|
4758 | return SPELL_FAILED_NO_AMMO; |
---|
4759 | |
---|
4760 | if(ammoProto->Class != ITEM_CLASS_PROJECTILE) |
---|
4761 | return SPELL_FAILED_NO_AMMO; |
---|
4762 | |
---|
4763 | // check ammo ws. weapon compatibility |
---|
4764 | switch(pItem->GetProto()->SubClass) |
---|
4765 | { |
---|
4766 | case ITEM_SUBCLASS_WEAPON_BOW: |
---|
4767 | case ITEM_SUBCLASS_WEAPON_CROSSBOW: |
---|
4768 | if(ammoProto->SubClass!=ITEM_SUBCLASS_ARROW) |
---|
4769 | return SPELL_FAILED_NO_AMMO; |
---|
4770 | break; |
---|
4771 | case ITEM_SUBCLASS_WEAPON_GUN: |
---|
4772 | if(ammoProto->SubClass!=ITEM_SUBCLASS_BULLET) |
---|
4773 | return SPELL_FAILED_NO_AMMO; |
---|
4774 | break; |
---|
4775 | default: |
---|
4776 | return SPELL_FAILED_NO_AMMO; |
---|
4777 | } |
---|
4778 | |
---|
4779 | if( !((Player*)m_caster)->HasItemCount( ammo, 1 ) ) |
---|
4780 | return SPELL_FAILED_NO_AMMO; |
---|
4781 | }; break; |
---|
4782 | case ITEM_SUBCLASS_WEAPON_WAND: |
---|
4783 | default: |
---|
4784 | break; |
---|
4785 | } |
---|
4786 | break; |
---|
4787 | } |
---|
4788 | default:break; |
---|
4789 | } |
---|
4790 | } |
---|
4791 | |
---|
4792 | return uint8(0); |
---|
4793 | } |
---|
4794 | |
---|
4795 | void Spell::Delayed() |
---|
4796 | { |
---|
4797 | if(!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER) |
---|
4798 | return; |
---|
4799 | |
---|
4800 | if (m_spellState == SPELL_STATE_DELAYED) |
---|
4801 | return; // spell is active and can't be time-backed |
---|
4802 | |
---|
4803 | // spells not loosing casting time ( slam, dynamites, bombs.. ) |
---|
4804 | if(!(m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_DAMAGE)) |
---|
4805 | return; |
---|
4806 | |
---|
4807 | //check resist chance |
---|
4808 | int32 resistChance = 100; //must be initialized to 100 for percent modifiers |
---|
4809 | ((Player*)m_caster)->ApplySpellMod(m_spellInfo->Id,SPELLMOD_NOT_LOSE_CASTING_TIME,resistChance, this); |
---|
4810 | resistChance += m_caster->GetTotalAuraModifier(SPELL_AURA_RESIST_PUSHBACK) - 100; |
---|
4811 | if (roll_chance_i(resistChance)) |
---|
4812 | return; |
---|
4813 | |
---|
4814 | int32 delaytime = GetNextDelayAtDamageMsTime(); |
---|
4815 | |
---|
4816 | if(int32(m_timer) + delaytime > m_casttime) |
---|
4817 | { |
---|
4818 | delaytime = m_casttime - m_timer; |
---|
4819 | m_timer = m_casttime; |
---|
4820 | } |
---|
4821 | else |
---|
4822 | m_timer += delaytime; |
---|
4823 | |
---|
4824 | sLog.outDetail("Spell %u partially interrupted for (%d) ms at damage",m_spellInfo->Id,delaytime); |
---|
4825 | |
---|
4826 | WorldPacket data(SMSG_SPELL_DELAYED, 8+4); |
---|
4827 | data.append(m_caster->GetPackGUID()); |
---|
4828 | data << uint32(delaytime); |
---|
4829 | |
---|
4830 | m_caster->SendMessageToSet(&data,true); |
---|
4831 | } |
---|
4832 | |
---|
4833 | void Spell::DelayedChannel() |
---|
4834 | { |
---|
4835 | if(!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER || getState() != SPELL_STATE_CASTING) |
---|
4836 | return; |
---|
4837 | |
---|
4838 | //check resist chance |
---|
4839 | int32 resistChance = 100; //must be initialized to 100 for percent modifiers |
---|
4840 | ((Player*)m_caster)->ApplySpellMod(m_spellInfo->Id,SPELLMOD_NOT_LOSE_CASTING_TIME,resistChance, this); |
---|
4841 | resistChance += m_caster->GetTotalAuraModifier(SPELL_AURA_RESIST_PUSHBACK) - 100; |
---|
4842 | if (roll_chance_i(resistChance)) |
---|
4843 | return; |
---|
4844 | |
---|
4845 | int32 delaytime = GetNextDelayAtDamageMsTime(); |
---|
4846 | |
---|
4847 | if(int32(m_timer) < delaytime) |
---|
4848 | { |
---|
4849 | delaytime = m_timer; |
---|
4850 | m_timer = 0; |
---|
4851 | } |
---|
4852 | else |
---|
4853 | m_timer -= delaytime; |
---|
4854 | |
---|
4855 | sLog.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo->Id, delaytime, m_timer); |
---|
4856 | |
---|
4857 | for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit) |
---|
4858 | { |
---|
4859 | if ((*ihit).missCondition == SPELL_MISS_NONE) |
---|
4860 | { |
---|
4861 | Unit* unit = m_caster->GetGUID()==ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID); |
---|
4862 | if (unit) |
---|
4863 | { |
---|
4864 | for (int j=0;j<3;j++) |
---|
4865 | if( ihit->effectMask & (1<<j) ) |
---|
4866 | unit->DelayAura(m_spellInfo->Id, j, delaytime); |
---|
4867 | } |
---|
4868 | |
---|
4869 | } |
---|
4870 | } |
---|
4871 | |
---|
4872 | for(int j = 0; j < 3; j++) |
---|
4873 | { |
---|
4874 | // partially interrupt persistent area auras |
---|
4875 | DynamicObject* dynObj = m_caster->GetDynObject(m_spellInfo->Id, j); |
---|
4876 | if(dynObj) |
---|
4877 | dynObj->Delay(delaytime); |
---|
4878 | } |
---|
4879 | |
---|
4880 | SendChannelUpdate(m_timer); |
---|
4881 | } |
---|
4882 | |
---|
4883 | void Spell::UpdatePointers() |
---|
4884 | { |
---|
4885 | if(m_originalCasterGUID==m_caster->GetGUID()) |
---|
4886 | m_originalCaster = m_caster; |
---|
4887 | else |
---|
4888 | { |
---|
4889 | m_originalCaster = ObjectAccessor::GetUnit(*m_caster,m_originalCasterGUID); |
---|
4890 | if(m_originalCaster && !m_originalCaster->IsInWorld()) m_originalCaster = NULL; |
---|
4891 | } |
---|
4892 | |
---|
4893 | m_targets.Update(m_caster); |
---|
4894 | } |
---|
4895 | |
---|
4896 | bool Spell::IsAffectedBy(SpellEntry const *spellInfo, uint32 effectId) |
---|
4897 | { |
---|
4898 | return spellmgr.IsAffectedBySpell(m_spellInfo,spellInfo->Id,effectId,spellInfo->EffectItemType[effectId]); |
---|
4899 | } |
---|
4900 | |
---|
4901 | bool Spell::CheckTargetCreatureType(Unit* target) const |
---|
4902 | { |
---|
4903 | uint32 spellCreatureTargetMask = m_spellInfo->TargetCreatureType; |
---|
4904 | |
---|
4905 | // Curse of Doom : not find another way to fix spell target check :/ |
---|
4906 | if(m_spellInfo->SpellFamilyName==SPELLFAMILY_WARLOCK && m_spellInfo->SpellFamilyFlags == 0x0200000000LL) |
---|
4907 | { |
---|
4908 | // not allow cast at player |
---|
4909 | if(target->GetTypeId()==TYPEID_PLAYER) |
---|
4910 | return false; |
---|
4911 | |
---|
4912 | spellCreatureTargetMask = 0x7FF; |
---|
4913 | } |
---|
4914 | |
---|
4915 | // Dismiss Pet and Taming Lesson skipped |
---|
4916 | if(m_spellInfo->Id == 2641 || m_spellInfo->Id == 23356) |
---|
4917 | spellCreatureTargetMask = 0; |
---|
4918 | |
---|
4919 | if (spellCreatureTargetMask) |
---|
4920 | { |
---|
4921 | uint32 TargetCreatureType = target->GetCreatureTypeMask(); |
---|
4922 | |
---|
4923 | return !TargetCreatureType || (spellCreatureTargetMask & TargetCreatureType); |
---|
4924 | } |
---|
4925 | return true; |
---|
4926 | } |
---|
4927 | |
---|
4928 | CurrentSpellTypes Spell::GetCurrentContainer() |
---|
4929 | { |
---|
4930 | if (IsNextMeleeSwingSpell()) |
---|
4931 | return(CURRENT_MELEE_SPELL); |
---|
4932 | else if (IsAutoRepeat()) |
---|
4933 | return(CURRENT_AUTOREPEAT_SPELL); |
---|
4934 | else if (IsChanneledSpell(m_spellInfo)) |
---|
4935 | return(CURRENT_CHANNELED_SPELL); |
---|
4936 | else |
---|
4937 | return(CURRENT_GENERIC_SPELL); |
---|
4938 | } |
---|
4939 | |
---|
4940 | bool Spell::CheckTarget( Unit* target, uint32 eff, bool hitPhase ) |
---|
4941 | { |
---|
4942 | // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets) |
---|
4943 | if(m_spellInfo->EffectImplicitTargetA[eff]!=TARGET_SELF && !m_magnetPair.first) |
---|
4944 | { |
---|
4945 | if (!CheckTargetCreatureType(target)) |
---|
4946 | return false; |
---|
4947 | } |
---|
4948 | |
---|
4949 | // Check targets for not_selectable unit flag and remove |
---|
4950 | // A player can cast spells on his pet (or other controlled unit) though in any state |
---|
4951 | if (target != m_caster && target->GetCharmerOrOwnerGUID() != m_caster->GetGUID()) |
---|
4952 | { |
---|
4953 | // any unattackable target skipped |
---|
4954 | if (target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE)) |
---|
4955 | return false; |
---|
4956 | |
---|
4957 | // unselectable targets skipped in all cases except TARGET_SCRIPT targeting |
---|
4958 | // in case TARGET_SCRIPT target selected by server always and can't be cheated |
---|
4959 | if( target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE) && |
---|
4960 | m_spellInfo->EffectImplicitTargetA[eff] != TARGET_SCRIPT && |
---|
4961 | m_spellInfo->EffectImplicitTargetB[eff] != TARGET_SCRIPT ) |
---|
4962 | return false; |
---|
4963 | } |
---|
4964 | |
---|
4965 | //Check player targets and remove if in GM mode or GM invisibility (for not self casting case) |
---|
4966 | if( target != m_caster && target->GetTypeId()==TYPEID_PLAYER) |
---|
4967 | { |
---|
4968 | if(((Player*)target)->GetVisibility()==VISIBILITY_OFF) |
---|
4969 | return false; |
---|
4970 | |
---|
4971 | if(((Player*)target)->isGameMaster() && !IsPositiveSpell(m_spellInfo->Id)) |
---|
4972 | return false; |
---|
4973 | } |
---|
4974 | |
---|
4975 | //Check targets for LOS visibility (except spells without range limitations ) |
---|
4976 | switch(m_spellInfo->Effect[eff]) |
---|
4977 | { |
---|
4978 | case SPELL_EFFECT_SUMMON_PLAYER: // from anywhere |
---|
4979 | break; |
---|
4980 | case SPELL_EFFECT_DUMMY: |
---|
4981 | if(m_spellInfo->Id!=20577) // Cannibalize |
---|
4982 | break; |
---|
4983 | //fall through |
---|
4984 | case SPELL_EFFECT_RESURRECT_NEW: |
---|
4985 | // player far away, maybe his corpse near? |
---|
4986 | if(target!=m_caster && !target->IsWithinLOSInMap(m_caster)) |
---|
4987 | { |
---|
4988 | if(!m_targets.getCorpseTargetGUID()) |
---|
4989 | return false; |
---|
4990 | |
---|
4991 | Corpse *corpse = ObjectAccessor::GetCorpse(*m_caster,m_targets.getCorpseTargetGUID()); |
---|
4992 | if(!corpse) |
---|
4993 | return false; |
---|
4994 | |
---|
4995 | if(target->GetGUID()!=corpse->GetOwnerGUID()) |
---|
4996 | return false; |
---|
4997 | |
---|
4998 | if(!corpse->IsWithinLOSInMap(m_caster)) |
---|
4999 | return false; |
---|
5000 | } |
---|
5001 | |
---|
5002 | // all ok by some way or another, skip normal check |
---|
5003 | break; |
---|
5004 | default: // normal case |
---|
5005 | if(target!=m_caster && !target->IsWithinLOSInMap(m_caster)) |
---|
5006 | return false; |
---|
5007 | break; |
---|
5008 | } |
---|
5009 | |
---|
5010 | return true; |
---|
5011 | } |
---|
5012 | |
---|
5013 | Unit* Spell::SelectMagnetTarget() |
---|
5014 | { |
---|
5015 | Unit* target = m_targets.getUnitTarget(); |
---|
5016 | |
---|
5017 | if(target && target->HasAuraType(SPELL_AURA_SPELL_MAGNET) && !(m_spellInfo->Attributes & 0x10)) |
---|
5018 | { |
---|
5019 | Unit::AuraList const& magnetAuras = target->GetAurasByType(SPELL_AURA_SPELL_MAGNET); |
---|
5020 | for(Unit::AuraList::const_iterator itr = magnetAuras.begin(); itr != magnetAuras.end(); ++itr) |
---|
5021 | { |
---|
5022 | if(Unit* magnet = (*itr)->GetCaster()) |
---|
5023 | { |
---|
5024 | if((*itr)->m_procCharges>0 && magnet->IsWithinLOSInMap(m_caster)) |
---|
5025 | { |
---|
5026 | (*itr)->SetAuraProcCharges((*itr)->m_procCharges-1); |
---|
5027 | m_magnetPair.first = true; |
---|
5028 | m_magnetPair.second = magnet; |
---|
5029 | |
---|
5030 | target = magnet; |
---|
5031 | m_targets.setUnitTarget(target); |
---|
5032 | break; |
---|
5033 | } |
---|
5034 | } |
---|
5035 | } |
---|
5036 | } |
---|
5037 | |
---|
5038 | return target; |
---|
5039 | } |
---|
5040 | |
---|
5041 | bool Spell::IsNeedSendToClient() const |
---|
5042 | { |
---|
5043 | return m_spellInfo->SpellVisual!=0 || IsChanneledSpell(m_spellInfo) || |
---|
5044 | m_spellInfo->speed > 0.0f || !m_triggeredByAuraSpell && !m_IsTriggeredSpell; |
---|
5045 | } |
---|
5046 | |
---|
5047 | bool Spell::HaveTargetsForEffect( uint8 effect ) const |
---|
5048 | { |
---|
5049 | for(std::list<TargetInfo>::const_iterator itr= m_UniqueTargetInfo.begin();itr != m_UniqueTargetInfo.end();++itr) |
---|
5050 | if(itr->effectMask & (1<<effect)) |
---|
5051 | return true; |
---|
5052 | |
---|
5053 | for(std::list<GOTargetInfo>::const_iterator itr= m_UniqueGOTargetInfo.begin();itr != m_UniqueGOTargetInfo.end();++itr) |
---|
5054 | if(itr->effectMask & (1<<effect)) |
---|
5055 | return true; |
---|
5056 | |
---|
5057 | for(std::list<ItemTargetInfo>::const_iterator itr= m_UniqueItemInfo.begin();itr != m_UniqueItemInfo.end();++itr) |
---|
5058 | if(itr->effectMask & (1<<effect)) |
---|
5059 | return true; |
---|
5060 | |
---|
5061 | return false; |
---|
5062 | } |
---|
5063 | |
---|
5064 | SpellEvent::SpellEvent(Spell* spell) : BasicEvent() |
---|
5065 | { |
---|
5066 | m_Spell = spell; |
---|
5067 | } |
---|
5068 | |
---|
5069 | SpellEvent::~SpellEvent() |
---|
5070 | { |
---|
5071 | if (m_Spell->getState() != SPELL_STATE_FINISHED) |
---|
5072 | m_Spell->cancel(); |
---|
5073 | |
---|
5074 | if (m_Spell->IsDeletable()) |
---|
5075 | { |
---|
5076 | delete m_Spell; |
---|
5077 | } |
---|
5078 | else |
---|
5079 | { |
---|
5080 | sLog.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.", |
---|
5081 | (m_Spell->GetCaster()->GetTypeId()==TYPEID_PLAYER?"Player":"Creature"), m_Spell->GetCaster()->GetGUIDLow(),m_Spell->m_spellInfo->Id); |
---|
5082 | } |
---|
5083 | } |
---|
5084 | |
---|
5085 | bool SpellEvent::Execute(uint64 e_time, uint32 p_time) |
---|
5086 | { |
---|
5087 | // update spell if it is not finished |
---|
5088 | if (m_Spell->getState() != SPELL_STATE_FINISHED) |
---|
5089 | m_Spell->update(p_time); |
---|
5090 | |
---|
5091 | // check spell state to process |
---|
5092 | switch (m_Spell->getState()) |
---|
5093 | { |
---|
5094 | case SPELL_STATE_FINISHED: |
---|
5095 | { |
---|
5096 | // spell was finished, check deletable state |
---|
5097 | if (m_Spell->IsDeletable()) |
---|
5098 | { |
---|
5099 | // check, if we do have unfinished triggered spells |
---|
5100 | |
---|
5101 | return(true); // spell is deletable, finish event |
---|
5102 | } |
---|
5103 | // event will be re-added automatically at the end of routine) |
---|
5104 | } break; |
---|
5105 | |
---|
5106 | case SPELL_STATE_CASTING: |
---|
5107 | { |
---|
5108 | // this spell is in channeled state, process it on the next update |
---|
5109 | // event will be re-added automatically at the end of routine) |
---|
5110 | } break; |
---|
5111 | |
---|
5112 | case SPELL_STATE_DELAYED: |
---|
5113 | { |
---|
5114 | // first, check, if we have just started |
---|
5115 | if (m_Spell->GetDelayStart() != 0) |
---|
5116 | { |
---|
5117 | // no, we aren't, do the typical update |
---|
5118 | // check, if we have channeled spell on our hands |
---|
5119 | if (IsChanneledSpell(m_Spell->m_spellInfo)) |
---|
5120 | { |
---|
5121 | // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish |
---|
5122 | // check, if we have casting anything else except this channeled spell and autorepeat |
---|
5123 | if (m_Spell->GetCaster()->IsNonMeleeSpellCasted(false, true, true)) |
---|
5124 | { |
---|
5125 | // another non-melee non-delayed spell is casted now, abort |
---|
5126 | m_Spell->cancel(); |
---|
5127 | } |
---|
5128 | else |
---|
5129 | { |
---|
5130 | // do the action (pass spell to channeling state) |
---|
5131 | m_Spell->handle_immediate(); |
---|
5132 | } |
---|
5133 | // event will be re-added automatically at the end of routine) |
---|
5134 | } |
---|
5135 | else |
---|
5136 | { |
---|
5137 | // run the spell handler and think about what we can do next |
---|
5138 | uint64 t_offset = e_time - m_Spell->GetDelayStart(); |
---|
5139 | uint64 n_offset = m_Spell->handle_delayed(t_offset); |
---|
5140 | if (n_offset) |
---|
5141 | { |
---|
5142 | // re-add us to the queue |
---|
5143 | m_Spell->GetCaster()->m_Events.AddEvent(this, m_Spell->GetDelayStart() + n_offset, false); |
---|
5144 | return(false); // event not complete |
---|
5145 | } |
---|
5146 | // event complete |
---|
5147 | // finish update event will be re-added automatically at the end of routine) |
---|
5148 | } |
---|
5149 | } |
---|
5150 | else |
---|
5151 | { |
---|
5152 | // delaying had just started, record the moment |
---|
5153 | m_Spell->SetDelayStart(e_time); |
---|
5154 | // re-plan the event for the delay moment |
---|
5155 | m_Spell->GetCaster()->m_Events.AddEvent(this, e_time + m_Spell->GetDelayMoment(), false); |
---|
5156 | return(false); // event not complete |
---|
5157 | } |
---|
5158 | } break; |
---|
5159 | |
---|
5160 | default: |
---|
5161 | { |
---|
5162 | // all other states |
---|
5163 | // event will be re-added automatically at the end of routine) |
---|
5164 | } break; |
---|
5165 | } |
---|
5166 | |
---|
5167 | // spell processing not complete, plan event on the next update interval |
---|
5168 | m_Spell->GetCaster()->m_Events.AddEvent(this, e_time + 1, false); |
---|
5169 | return(false); // event not complete |
---|
5170 | } |
---|
5171 | |
---|
5172 | void SpellEvent::Abort(uint64 /*e_time*/) |
---|
5173 | { |
---|
5174 | // oops, the spell we try to do is aborted |
---|
5175 | if (m_Spell->getState() != SPELL_STATE_FINISHED) |
---|
5176 | m_Spell->cancel(); |
---|
5177 | } |
---|