[9496] HomeBind fixes.
[getmangos.git] / src / game / Spell.h
blob7612ff0842157992935aa9e650308c5751e7082f
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef __SPELL_H
20 #define __SPELL_H
22 #include "GridDefines.h"
23 #include "SharedDefines.h"
24 #include "DBCEnums.h"
26 class WorldSession;
27 class Unit;
28 class DynamicObj;
29 class Player;
30 class GameObject;
31 class Group;
32 class Aura;
34 enum SpellCastTargetFlags
36 TARGET_FLAG_SELF = 0x00000000,
37 TARGET_FLAG_UNUSED1 = 0x00000001, // not used in any spells as of 3.0.3 (can be set dynamically)
38 TARGET_FLAG_UNIT = 0x00000002, // pguid
39 TARGET_FLAG_UNUSED2 = 0x00000004, // not used in any spells as of 3.0.3 (can be set dynamically)
40 TARGET_FLAG_UNUSED3 = 0x00000008, // not used in any spells as of 3.0.3 (can be set dynamically)
41 TARGET_FLAG_ITEM = 0x00000010, // pguid
42 TARGET_FLAG_SOURCE_LOCATION = 0x00000020, // 3 float
43 TARGET_FLAG_DEST_LOCATION = 0x00000040, // 3 float
44 TARGET_FLAG_OBJECT_UNK = 0x00000080, // used in 7 spells only
45 TARGET_FLAG_UNIT_UNK = 0x00000100, // looks like self target (480 spells)
46 TARGET_FLAG_PVP_CORPSE = 0x00000200, // pguid
47 TARGET_FLAG_UNIT_CORPSE = 0x00000400, // 10 spells (gathering professions)
48 TARGET_FLAG_OBJECT = 0x00000800, // pguid, 2 spells
49 TARGET_FLAG_TRADE_ITEM = 0x00001000, // pguid, 0 spells
50 TARGET_FLAG_STRING = 0x00002000, // string, 0 spells
51 TARGET_FLAG_UNK1 = 0x00004000, // 199 spells, opening object/lock
52 TARGET_FLAG_CORPSE = 0x00008000, // pguid, resurrection spells
53 TARGET_FLAG_UNK2 = 0x00010000, // pguid, not used in any spells as of 3.0.3 (can be set dynamically)
54 TARGET_FLAG_GLYPH = 0x00020000 // used in glyph spells
57 enum SpellCastFlags
59 CAST_FLAG_NONE = 0x00000000,
60 CAST_FLAG_UNKNOWN0 = 0x00000001, // may be pending spell cast
61 CAST_FLAG_UNKNOWN1 = 0x00000002,
62 CAST_FLAG_UNKNOWN11 = 0x00000004,
63 CAST_FLAG_UNKNOWN12 = 0x00000008,
64 CAST_FLAG_UNKNOWN2 = 0x00000010,
65 CAST_FLAG_AMMO = 0x00000020, // Projectiles visual
66 CAST_FLAG_UNKNOWN8 = 0x00000040,
67 CAST_FLAG_UNKNOWN9 = 0x00000080,
68 CAST_FLAG_UNKNOWN3 = 0x00000100,
69 CAST_FLAG_UNKNOWN13 = 0x00000200,
70 CAST_FLAG_UNKNOWN14 = 0x00000400,
71 CAST_FLAG_UNKNOWN6 = 0x00000800, // wotlk, trigger rune cooldown
72 CAST_FLAG_UNKNOWN15 = 0x00001000,
73 CAST_FLAG_UNKNOWN16 = 0x00002000,
74 CAST_FLAG_UNKNOWN17 = 0x00004000,
75 CAST_FLAG_UNKNOWN18 = 0x00008000,
76 CAST_FLAG_UNKNOWN19 = 0x00010000,
77 CAST_FLAG_UNKNOWN4 = 0x00020000, // wotlk
78 CAST_FLAG_UNKNOWN10 = 0x00040000,
79 CAST_FLAG_UNKNOWN5 = 0x00080000, // wotlk
80 CAST_FLAG_UNKNOWN20 = 0x00100000,
81 CAST_FLAG_UNKNOWN7 = 0x00200000, // wotlk, rune cooldown list
82 CAST_FLAG_UNKNOWN21 = 0x04000000
85 enum SpellNotifyPushType
87 PUSH_IN_FRONT,
88 PUSH_IN_FRONT_90,
89 PUSH_IN_FRONT_30,
90 PUSH_IN_FRONT_15,
91 PUSH_IN_BACK,
92 PUSH_SELF_CENTER,
93 PUSH_DEST_CENTER,
94 PUSH_TARGET_CENTER
97 bool IsQuestTameSpell(uint32 spellId);
99 namespace MaNGOS
101 struct SpellNotifierPlayer;
102 struct SpellNotifierCreatureAndPlayer;
105 class SpellCastTargets
107 public:
108 SpellCastTargets();
109 ~SpellCastTargets();
111 bool read ( WorldPacket * data, Unit *caster );
112 void write ( WorldPacket * data );
114 SpellCastTargets& operator=(const SpellCastTargets &target)
116 m_unitTarget = target.m_unitTarget;
117 m_itemTarget = target.m_itemTarget;
118 m_GOTarget = target.m_GOTarget;
120 m_unitTargetGUID = target.m_unitTargetGUID;
121 m_GOTargetGUID = target.m_GOTargetGUID;
122 m_CorpseTargetGUID = target.m_CorpseTargetGUID;
123 m_itemTargetGUID = target.m_itemTargetGUID;
125 m_itemTargetEntry = target.m_itemTargetEntry;
127 m_srcX = target.m_srcX;
128 m_srcY = target.m_srcY;
129 m_srcZ = target.m_srcZ;
131 m_destX = target.m_destX;
132 m_destY = target.m_destY;
133 m_destZ = target.m_destZ;
135 m_strTarget = target.m_strTarget;
137 m_targetMask = target.m_targetMask;
139 return *this;
142 uint64 getUnitTargetGUID() const { return m_unitTargetGUID; }
143 Unit *getUnitTarget() const { return m_unitTarget; }
144 void setUnitTarget(Unit *target);
145 void setDestination(float x, float y, float z);
146 void setSource(float x, float y, float z);
148 uint64 getGOTargetGUID() const { return m_GOTargetGUID; }
149 GameObject *getGOTarget() const { return m_GOTarget; }
150 void setGOTarget(GameObject *target);
152 uint64 getCorpseTargetGUID() const { return m_CorpseTargetGUID; }
153 void setCorpseTarget(Corpse* corpse);
154 uint64 getItemTargetGUID() const { return m_itemTargetGUID; }
155 Item* getItemTarget() const { return m_itemTarget; }
156 uint32 getItemTargetEntry() const { return m_itemTargetEntry; }
157 void setItemTarget(Item* item);
158 void updateTradeSlotItem()
160 if(m_itemTarget && (m_targetMask & TARGET_FLAG_TRADE_ITEM))
162 m_itemTargetGUID = m_itemTarget->GetGUID();
163 m_itemTargetEntry = m_itemTarget->GetEntry();
167 bool IsEmpty() const { return m_GOTargetGUID==0 && m_unitTargetGUID==0 && m_itemTarget==0 && m_CorpseTargetGUID==0; }
169 void Update(Unit* caster);
171 float m_srcX, m_srcY, m_srcZ;
172 float m_destX, m_destY, m_destZ;
173 std::string m_strTarget;
175 uint32 m_targetMask;
176 private:
177 // objects (can be used at spell creating and after Update at casting
178 Unit *m_unitTarget;
179 GameObject *m_GOTarget;
180 Item *m_itemTarget;
182 // object GUID/etc, can be used always
183 uint64 m_unitTargetGUID;
184 uint64 m_GOTargetGUID;
185 uint64 m_CorpseTargetGUID;
186 uint64 m_itemTargetGUID;
187 uint32 m_itemTargetEntry;
190 enum SpellState
192 SPELL_STATE_NULL = 0,
193 SPELL_STATE_PREPARING = 1,
194 SPELL_STATE_CASTING = 2,
195 SPELL_STATE_FINISHED = 3,
196 SPELL_STATE_IDLE = 4,
197 SPELL_STATE_DELAYED = 5
200 enum SpellTargets
202 SPELL_TARGETS_HOSTILE,
203 SPELL_TARGETS_NOT_FRIENDLY,
204 SPELL_TARGETS_NOT_HOSTILE,
205 SPELL_TARGETS_FRIENDLY,
206 SPELL_TARGETS_AOE_DAMAGE
209 #define SPELL_SPELL_CHANNEL_UPDATE_INTERVAL (1*IN_MILISECONDS)
211 typedef std::multimap<uint64, uint64> SpellTargetTimeMap;
213 class Spell
215 friend struct MaNGOS::SpellNotifierPlayer;
216 friend struct MaNGOS::SpellNotifierCreatureAndPlayer;
217 friend void Unit::SetCurrentCastedSpell( Spell * pSpell );
218 public:
220 void EffectEmpty(SpellEffectIndex eff_idx);
221 void EffectNULL(SpellEffectIndex eff_idx);
222 void EffectUnused(SpellEffectIndex eff_idx);
223 void EffectDistract(SpellEffectIndex eff_idx);
224 void EffectPull(SpellEffectIndex eff_idx);
225 void EffectSchoolDMG(SpellEffectIndex eff_idx);
226 void EffectEnvironmentalDMG(SpellEffectIndex eff_idx);
227 void EffectInstaKill(SpellEffectIndex eff_idx);
228 void EffectDummy(SpellEffectIndex eff_idx);
229 void EffectTeleportUnits(SpellEffectIndex eff_idx);
230 void EffectApplyAura(SpellEffectIndex eff_idx);
231 void EffectSendEvent(SpellEffectIndex eff_idx);
232 void EffectPowerBurn(SpellEffectIndex eff_idx);
233 void EffectPowerDrain(SpellEffectIndex eff_idx);
234 void EffectHeal(SpellEffectIndex eff_idx);
235 void EffectBind(SpellEffectIndex eff_idx);
236 void EffectHealthLeech(SpellEffectIndex eff_idx);
237 void EffectQuestComplete(SpellEffectIndex eff_idx);
238 void EffectCreateItem(SpellEffectIndex eff_idx);
239 void EffectCreateItem2(SpellEffectIndex eff_idx);
240 void EffectCreateRandomItem(SpellEffectIndex eff_idx);
241 void EffectPersistentAA(SpellEffectIndex eff_idx);
242 void EffectEnergize(SpellEffectIndex eff_idx);
243 void EffectOpenLock(SpellEffectIndex eff_idx);
244 void EffectSummonChangeItem(SpellEffectIndex eff_idx);
245 void EffectProficiency(SpellEffectIndex eff_idx);
246 void EffectApplyAreaAura(SpellEffectIndex eff_idx);
247 void EffectSummonType(SpellEffectIndex eff_idx);
248 void EffectLearnSpell(SpellEffectIndex eff_idx);
249 void EffectDispel(SpellEffectIndex eff_idx);
250 void EffectDualWield(SpellEffectIndex eff_idx);
251 void EffectPickPocket(SpellEffectIndex eff_idx);
252 void EffectAddFarsight(SpellEffectIndex eff_idx);
253 void EffectHealMechanical(SpellEffectIndex eff_idx);
254 void EffectJump(SpellEffectIndex eff_idx);
255 void EffectTeleUnitsFaceCaster(SpellEffectIndex eff_idx);
256 void EffectLearnSkill(SpellEffectIndex eff_idx);
257 void EffectAddHonor(SpellEffectIndex eff_idx);
258 void EffectTradeSkill(SpellEffectIndex eff_idx);
259 void EffectEnchantItemPerm(SpellEffectIndex eff_idx);
260 void EffectEnchantItemTmp(SpellEffectIndex eff_idx);
261 void EffectTameCreature(SpellEffectIndex eff_idx);
262 void EffectSummonPet(SpellEffectIndex eff_idx);
263 void EffectLearnPetSpell(SpellEffectIndex eff_idx);
264 void EffectWeaponDmg(SpellEffectIndex eff_idx);
265 void EffectForceCast(SpellEffectIndex eff_idx);
266 void EffectTriggerSpell(SpellEffectIndex eff_idx);
267 void EffectTriggerMissileSpell(SpellEffectIndex eff_idx);
268 void EffectThreat(SpellEffectIndex eff_idx);
269 void EffectHealMaxHealth(SpellEffectIndex eff_idx);
270 void EffectInterruptCast(SpellEffectIndex eff_idx);
271 void EffectSummonObjectWild(SpellEffectIndex eff_idx);
272 void EffectScriptEffect(SpellEffectIndex eff_idx);
273 void EffectSanctuary(SpellEffectIndex eff_idx);
274 void EffectAddComboPoints(SpellEffectIndex eff_idx);
275 void EffectDuel(SpellEffectIndex eff_idx);
276 void EffectStuck(SpellEffectIndex eff_idx);
277 void EffectSummonPlayer(SpellEffectIndex eff_idx);
278 void EffectActivateObject(SpellEffectIndex eff_idx);
279 void EffectApplyGlyph(SpellEffectIndex eff_idx);
280 void EffectEnchantHeldItem(SpellEffectIndex eff_idx);
281 void EffectSummonObject(SpellEffectIndex eff_idx);
282 void EffectResurrect(SpellEffectIndex eff_idx);
283 void EffectParry(SpellEffectIndex eff_idx);
284 void EffectBlock(SpellEffectIndex eff_idx);
285 void EffectLeapForward(SpellEffectIndex eff_idx);
286 void EffectLeapBack(SpellEffectIndex eff_idx);
287 void EffectTransmitted(SpellEffectIndex eff_idx);
288 void EffectDisEnchant(SpellEffectIndex eff_idx);
289 void EffectInebriate(SpellEffectIndex eff_idx);
290 void EffectFeedPet(SpellEffectIndex eff_idx);
291 void EffectDismissPet(SpellEffectIndex eff_idx);
292 void EffectReputation(SpellEffectIndex eff_idx);
293 void EffectSelfResurrect(SpellEffectIndex eff_idx);
294 void EffectSkinning(SpellEffectIndex eff_idx);
295 void EffectCharge(SpellEffectIndex eff_idx);
296 void EffectCharge2(SpellEffectIndex eff_idx);
297 void EffectProspecting(SpellEffectIndex eff_idx);
298 void EffectMilling(SpellEffectIndex eff_idx);
299 void EffectRenamePet(SpellEffectIndex eff_idx);
300 void EffectSendTaxi(SpellEffectIndex eff_idx);
301 void EffectKnockBack(SpellEffectIndex eff_idx);
302 void EffectPlayerPull(SpellEffectIndex eff_idx);
303 void EffectDispelMechanic(SpellEffectIndex eff_idx);
304 void EffectSummonDeadPet(SpellEffectIndex eff_idx);
305 void EffectSummonAllTotems(SpellEffectIndex eff_idx);
306 void EffectDestroyAllTotems(SpellEffectIndex eff_idx);
307 void EffectDurabilityDamage(SpellEffectIndex eff_idx);
308 void EffectSkill(SpellEffectIndex eff_idx);
309 void EffectTaunt(SpellEffectIndex eff_idx);
310 void EffectDurabilityDamagePCT(SpellEffectIndex eff_idx);
311 void EffectModifyThreatPercent(SpellEffectIndex eff_idx);
312 void EffectResurrectNew(SpellEffectIndex eff_idx);
313 void EffectAddExtraAttacks(SpellEffectIndex eff_idx);
314 void EffectSpiritHeal(SpellEffectIndex eff_idx);
315 void EffectSkinPlayerCorpse(SpellEffectIndex eff_idx);
316 void EffectStealBeneficialBuff(SpellEffectIndex eff_idx);
317 void EffectUnlearnSpecialization(SpellEffectIndex eff_idx);
318 void EffectHealPct(SpellEffectIndex eff_idx);
319 void EffectEnergisePct(SpellEffectIndex eff_idx);
320 void EffectTriggerSpellWithValue(SpellEffectIndex eff_idx);
321 void EffectTriggerRitualOfSummoning(SpellEffectIndex eff_idx);
322 void EffectKillCreditPersonal(SpellEffectIndex eff_idx);
323 void EffectKillCredit(SpellEffectIndex eff_idx);
324 void EffectQuestFail(SpellEffectIndex eff_idx);
325 void EffectActivateRune(SpellEffectIndex eff_idx);
326 void EffectTitanGrip(SpellEffectIndex eff_idx);
327 void EffectEnchantItemPrismatic(SpellEffectIndex eff_idx);
328 void EffectPlayMusic(SpellEffectIndex eff_idx);
329 void EffectSpecCount(SpellEffectIndex eff_idx);
330 void EffectActivateSpec(SpellEffectIndex eff_idx);
332 Spell( Unit* Caster, SpellEntry const *info, bool triggered, uint64 originalCasterGUID = 0, Spell** triggeringContainer = NULL );
333 ~Spell();
335 void prepare(SpellCastTargets const* targets, Aura* triggeredByAura = NULL);
336 void cancel();
337 void update(uint32 difftime);
338 void cast(bool skipCheck = false);
339 void finish(bool ok = true);
340 void TakePower();
341 void TakeReagents();
342 void TakeCastItem();
344 SpellCastResult CheckCast(bool strict);
345 SpellCastResult CheckPetCast(Unit* target);
347 // handlers
348 void handle_immediate();
349 uint64 handle_delayed(uint64 t_offset);
350 // handler helpers
351 void _handle_immediate_phase();
352 void _handle_finish_phase();
354 SpellCastResult CheckItems();
355 SpellCastResult CheckRange(bool strict);
356 SpellCastResult CheckPower();
357 SpellCastResult CheckOrTakeRunePower(bool take);
358 SpellCastResult CheckCasterAuras() const;
360 int32 CalculateDamage(SpellEffectIndex i, Unit* target) { return m_caster->CalculateSpellDamage(m_spellInfo,i,m_currentBasePoints[i],target); }
361 int32 CalculatePowerCost();
363 bool HaveTargetsForEffect(SpellEffectIndex effect) const;
364 void Delayed();
365 void DelayedChannel();
366 uint32 getState() const { return m_spellState; }
367 void setState(uint32 state) { m_spellState = state; }
369 void DoCreateItem(SpellEffectIndex eff_idx, uint32 itemtype);
370 void DoSummon(SpellEffectIndex eff_idx);
371 void DoSummonWild(SpellEffectIndex eff_idx, uint32 forceFaction = 0);
372 void DoSummonGuardian(SpellEffectIndex eff_idx, uint32 forceFaction = 0);
373 void DoSummonTotem(SpellEffectIndex eff_idx, uint8 slot_dbc = 0);
374 void DoSummonCritter(SpellEffectIndex eff_idx, uint32 forceFaction = 0);
376 void WriteSpellGoTargets( WorldPacket * data );
377 void WriteAmmoToPacket( WorldPacket * data );
379 typedef std::list<Unit*> UnitList;
380 void FillTargetMap();
381 void SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList &targetUnitMap);
383 void FillAreaTargets(UnitList &targetUnitMap, float x, float y, float radius, SpellNotifyPushType pushType, SpellTargets spellTargets);
384 void FillRaidOrPartyTargets(UnitList &targetUnitMap, Unit* member, Unit* center, float radius, bool raid, bool withPets, bool withcaster);
385 void FillRaidOrPartyManaPriorityTargets(UnitList &targetUnitMap, Unit* member, Unit* center, float radius, uint32 count, bool raid, bool withPets, bool withcaster);
386 void FillRaidOrPartyHealthPriorityTargets(UnitList &targetUnitMap, Unit* member, Unit* center, float radius, uint32 count, bool raid, bool withPets, bool withcaster);
388 template<typename T> WorldObject* FindCorpseUsing();
390 bool CheckTarget( Unit* target, SpellEffectIndex eff );
391 bool CanAutoCast(Unit* target);
393 static void MANGOS_DLL_SPEC SendCastResult(Player* caster, SpellEntry const* spellInfo, uint8 cast_count, SpellCastResult result);
394 void SendCastResult(SpellCastResult result);
395 void SendSpellStart();
396 void SendSpellGo();
397 void SendSpellCooldown();
398 void SendLogExecute();
399 void SendInterrupted(uint8 result);
400 void SendChannelUpdate(uint32 time);
401 void SendChannelStart(uint32 duration);
402 void SendResurrectRequest(Player* target);
403 void SendPlaySpellVisual(uint32 SpellID);
405 void HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,SpellEffectIndex i, float DamageMultiplier = 1.0);
406 void HandleThreatSpells(uint32 spellId);
407 //void HandleAddAura(Unit* Target);
409 SpellEntry const* m_spellInfo;
410 int32 m_currentBasePoints[3]; // cache SpellEntry::EffectBasePoints and use for set custom base points
411 Item* m_CastItem;
412 uint8 m_cast_count;
413 uint32 m_glyphIndex;
414 SpellCastTargets m_targets;
416 int32 GetCastTime() const { return m_casttime; }
417 uint32 GetCastedTime() { return m_timer; }
418 bool IsAutoRepeat() const { return m_autoRepeat; }
419 void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
420 void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
421 bool IsNextMeleeSwingSpell() const
423 return m_spellInfo->Attributes & (SPELL_ATTR_ON_NEXT_SWING_1|SPELL_ATTR_ON_NEXT_SWING_2);
425 bool IsRangedSpell() const
427 return m_spellInfo->Attributes & SPELL_ATTR_RANGED;
429 bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
430 bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
431 bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
433 bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
434 void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
435 void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; }
436 uint64 GetDelayStart() const { return m_delayStart; }
437 void SetDelayStart(uint64 m_time) { m_delayStart = m_time; }
438 uint64 GetDelayMoment() const { return m_delayMoment; }
440 bool IsNeedSendToClient() const; // use for hide spell cast for client in case when cast not have client side affect (animation or log entries)
441 bool IsTriggeredSpellWithRedundentData() const; // use for ignore some spell data for triggered spells like cast time, some triggered spells have redundent copy data from main spell for client use purpose
443 CurrentSpellTypes GetCurrentContainer();
445 // caster types:
446 // formal spell caster, in game source of spell affects cast
447 Unit* GetCaster() const { return m_caster; }
448 // real source of cast affects, explcit caster, or DoT/HoT applier, or GO owner, etc. Can be NULL
449 Unit* GetAffectiveCaster() const { return m_originalCasterGUID ? m_originalCaster : m_caster; }
450 // m_originalCasterGUID can store GO guid, and in this case this is visual caster
451 WorldObject* GetCastingObject() const;
453 int32 GetPowerCost() const { return m_powerCost; }
455 void UpdatePointers(); // must be used at call Spell code after time delay (non triggered spell cast/update spell call/etc)
457 bool IsAffectedByAura(Aura *aura) const;
459 bool CheckTargetCreatureType(Unit* target) const;
461 void AddTriggeredSpell(SpellEntry const* spellInfo) { m_TriggerSpells.push_back(spellInfo); }
462 void AddPrecastSpell(SpellEntry const* spellInfo) { m_preCastSpells.push_back(spellInfo); }
463 void AddTriggeredSpell(uint32 spellId);
464 void AddPrecastSpell(uint32 spellId);
465 void CastPreCastSpells(Unit* target);
466 void CastTriggerSpells();
468 void CleanupTargetList();
469 protected:
471 void SendLoot(uint64 guid, LootType loottype);
472 bool IgnoreItemRequirements() const; // some item use spells have unexpected reagent data
473 void UpdateOriginalCasterPointer();
475 Unit* m_caster;
477 uint64 m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection
478 // e.g. damage around area spell trigered by victim aura and da,age emeies of aura caster
479 Unit* m_originalCaster; // cached pointer for m_originalCaster, updated at Spell::UpdatePointers()
481 Spell** m_selfContainer; // pointer to our spell container (if applicable)
482 Spell** m_triggeringContainer; // pointer to container with spell that has triggered us
484 //Spell data
485 SpellSchoolMask m_spellSchoolMask; // Spell school (can be overwrite for some spells (wand shoot for example)
486 WeaponAttackType m_attackType; // For weapon based attack
487 int32 m_powerCost; // Calculated spell cost initialized only in Spell::prepare
488 int32 m_casttime; // Calculated spell cast time initialized only in Spell::prepare
489 bool m_canReflect; // can reflect this spell?
490 bool m_autoRepeat;
491 uint8 m_runesState;
493 uint8 m_delayAtDamageCount;
494 bool isDelayableNoMore()
496 if(m_delayAtDamageCount >= 2)
497 return true;
499 m_delayAtDamageCount++;
500 return false;
503 // Delayed spells system
504 uint64 m_delayStart; // time of spell delay start, filled by event handler, zero = just started
505 uint64 m_delayMoment; // moment of next delay call, used internally
506 bool m_immediateHandled; // were immediate actions handled? (used by delayed spells only)
508 // These vars are used in both delayed spell system and modified immediate spell system
509 bool m_referencedFromCurrentSpell; // mark as references to prevent deleted and access by dead pointers
510 bool m_executedCurrently; // mark as executed to prevent deleted and access by dead pointers
511 bool m_needSpellLog; // need to send spell log?
512 uint8 m_applyMultiplierMask; // by effect: damage multiplier needed?
513 float m_damageMultipliers[3]; // by effect: damage multiplier
515 // Current targets, to be used in SpellEffects (MUST BE USED ONLY IN SPELL EFFECTS)
516 Unit* unitTarget;
517 Item* itemTarget;
518 GameObject* gameObjTarget;
519 int32 damage;
521 // this is set in Spell Hit, but used in Apply Aura handler
522 DiminishingLevels m_diminishLevel;
523 DiminishingGroup m_diminishGroup;
525 // -------------------------------------------
526 GameObject* focusObject;
528 // Damage and healing in effects need just calculate
529 int32 m_damage; // Damge in effects count here
530 int32 m_healing; // Healing in effects count here
531 int32 m_healthLeech; // Health leech in effects for all targets count here
533 //******************************************
534 // Spell trigger system
535 //******************************************
536 bool m_canTrigger; // Can start trigger (m_IsTriggeredSpell can`t use for this)
537 uint32 m_procAttacker; // Attacker trigger flags
538 uint32 m_procVictim; // Victim trigger flags
539 void prepareDataForTriggerSystem();
541 //*****************************************
542 // Spell target subsystem
543 //*****************************************
544 // Targets store structures and data
545 struct TargetInfo
547 uint64 targetGUID;
548 uint64 timeDelay;
549 SpellMissInfo missCondition:8;
550 SpellMissInfo reflectResult:8;
551 uint8 effectMask:8;
552 bool processed:1;
554 std::list<TargetInfo> m_UniqueTargetInfo;
555 uint8 m_needAliveTargetMask; // Mask req. alive targets
557 struct GOTargetInfo
559 uint64 targetGUID;
560 uint64 timeDelay;
561 uint8 effectMask:8;
562 bool processed:1;
564 std::list<GOTargetInfo> m_UniqueGOTargetInfo;
566 struct ItemTargetInfo
568 Item *item;
569 uint8 effectMask;
571 std::list<ItemTargetInfo> m_UniqueItemInfo;
573 void AddUnitTarget(Unit* target, SpellEffectIndex effIndex);
574 void AddUnitTarget(uint64 unitGUID, SpellEffectIndex effIndex);
575 void AddGOTarget(GameObject* target, SpellEffectIndex effIndex);
576 void AddGOTarget(uint64 goGUID, SpellEffectIndex effIndex);
577 void AddItemTarget(Item* target, SpellEffectIndex effIndex);
578 void DoAllEffectOnTarget(TargetInfo *target);
579 void DoSpellHitOnUnit(Unit *unit, uint32 effectMask);
580 void DoAllEffectOnTarget(GOTargetInfo *target);
581 void DoAllEffectOnTarget(ItemTargetInfo *target);
582 bool IsAliveUnitPresentInTargetList();
583 SpellCastResult CanOpenLock(SpellEffectIndex effIndex, uint32 lockid, SkillType& skillid, int32& reqSkillValue, int32& skillValue);
584 // -------------------------------------------
586 //List For Triggered Spells
587 typedef std::list<SpellEntry const*> SpellInfoList;
588 SpellInfoList m_TriggerSpells; // casted by caster to same targets settings in m_targets at success finish of current spell
589 SpellInfoList m_preCastSpells; // casted by caster to each target at spell hit before spell effects apply
591 uint32 m_spellState;
592 uint32 m_timer;
594 float m_castPositionX;
595 float m_castPositionY;
596 float m_castPositionZ;
597 float m_castOrientation;
598 bool m_IsTriggeredSpell;
600 // if need this can be replaced by Aura copy
601 // we can't store original aura link to prevent access to deleted auras
602 // and in same time need aura data and after aura deleting.
603 SpellEntry const* m_triggeredByAuraSpell;
606 enum ReplenishType
608 REPLENISH_UNDEFINED = 0,
609 REPLENISH_HEALTH = 20,
610 REPLENISH_MANA = 21,
611 REPLENISH_RAGE = 22
614 namespace MaNGOS
616 struct MANGOS_DLL_DECL SpellNotifierPlayer
618 std::list<Unit*> &i_data;
619 Spell &i_spell;
620 const uint32& i_index;
621 float i_radius;
622 Unit* i_originalCaster;
624 SpellNotifierPlayer(Spell &spell, std::list<Unit*> &data, const uint32 &i, float radius)
625 : i_data(data), i_spell(spell), i_index(i), i_radius(radius)
627 i_originalCaster = i_spell.GetAffectiveCaster();
630 void Visit(PlayerMapType &m)
632 if(!i_originalCaster)
633 return;
635 for(PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
637 Player * pPlayer = itr->getSource();
638 if( !pPlayer->isAlive() || pPlayer->isInFlight())
639 continue;
641 if( i_originalCaster->IsFriendlyTo(pPlayer) )
642 continue;
644 if( pPlayer->IsWithinDist3d(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ,i_radius))
645 i_data.push_back(pPlayer);
648 template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
651 struct MANGOS_DLL_DECL SpellNotifierCreatureAndPlayer
653 std::list<Unit*> *i_data;
654 Spell &i_spell;
655 SpellNotifyPushType i_push_type;
656 float i_radius;
657 SpellTargets i_TargetType;
658 Unit* i_originalCaster;
660 SpellNotifierCreatureAndPlayer(Spell &spell, std::list<Unit*> &data, float radius, SpellNotifyPushType type,
661 SpellTargets TargetType = SPELL_TARGETS_NOT_FRIENDLY)
662 : i_data(&data), i_spell(spell), i_push_type(type), i_radius(radius), i_TargetType(TargetType)
664 i_originalCaster = spell.GetAffectiveCaster();
667 template<class T> inline void Visit(GridRefManager<T> &m)
669 assert(i_data);
671 if(!i_originalCaster)
672 return;
674 for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
676 // there are still more spells which can be casted on dead, but
677 // they are no AOE and don't have such a nice SPELL_ATTR flag
678 if ( !itr->getSource()->isTargetableForAttack(i_spell.m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_CAST_ON_DEAD)
679 // mostly phase check
680 || !itr->getSource()->IsInMap(i_originalCaster))
681 continue;
683 switch (i_TargetType)
685 case SPELL_TARGETS_HOSTILE:
686 if (!i_originalCaster->IsHostileTo( itr->getSource() ))
687 continue;
688 break;
689 case SPELL_TARGETS_NOT_FRIENDLY:
690 if (i_originalCaster->IsFriendlyTo( itr->getSource() ))
691 continue;
692 break;
693 case SPELL_TARGETS_NOT_HOSTILE:
694 if (i_originalCaster->IsHostileTo( itr->getSource() ))
695 continue;
696 break;
697 case SPELL_TARGETS_FRIENDLY:
698 if (!i_originalCaster->IsFriendlyTo( itr->getSource() ))
699 continue;
700 break;
701 case SPELL_TARGETS_AOE_DAMAGE:
703 if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
704 continue;
706 Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();
708 if( check->GetTypeId()==TYPEID_PLAYER )
710 if (check->IsFriendlyTo( itr->getSource() ))
711 continue;
713 else
715 if (!check->IsHostileTo( itr->getSource() ))
716 continue;
719 break;
720 default: continue;
723 // we don't need to check InMap here, it's already done some lines above
724 switch(i_push_type)
726 case PUSH_IN_FRONT:
727 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, 2*M_PI_F/3 ))
728 i_data->push_back(itr->getSource());
729 break;
730 case PUSH_IN_FRONT_90:
731 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, M_PI_F/2 ))
732 i_data->push_back(itr->getSource());
733 break;
734 case PUSH_IN_FRONT_30:
735 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, M_PI_F/6 ))
736 i_data->push_back(itr->getSource());
737 break;
738 case PUSH_IN_FRONT_15:
739 if(i_spell.GetCaster()->isInFront((Unit*)(itr->getSource()), i_radius, M_PI_F/12 ))
740 i_data->push_back(itr->getSource());
741 break;
742 case PUSH_IN_BACK:
743 if(i_spell.GetCaster()->isInBack((Unit*)(itr->getSource()), i_radius, 2*M_PI_F/3 ))
744 i_data->push_back(itr->getSource());
745 break;
746 case PUSH_SELF_CENTER:
747 if(i_spell.GetCaster()->IsWithinDist((Unit*)(itr->getSource()), i_radius))
748 i_data->push_back(itr->getSource());
749 break;
750 case PUSH_DEST_CENTER:
751 if(itr->getSource()->IsWithinDist3d(i_spell.m_targets.m_destX, i_spell.m_targets.m_destY, i_spell.m_targets.m_destZ,i_radius))
752 i_data->push_back(itr->getSource());
753 break;
754 case PUSH_TARGET_CENTER:
755 if(i_spell.m_targets.getUnitTarget()->IsWithinDist((Unit*)(itr->getSource()), i_radius))
756 i_data->push_back(itr->getSource());
757 break;
762 #ifdef WIN32
763 template<> inline void Visit(CorpseMapType & ) {}
764 template<> inline void Visit(GameObjectMapType & ) {}
765 template<> inline void Visit(DynamicObjectMapType & ) {}
766 #endif
769 #ifndef WIN32
770 template<> inline void SpellNotifierCreatureAndPlayer::Visit(CorpseMapType& ) {}
771 template<> inline void SpellNotifierCreatureAndPlayer::Visit(GameObjectMapType& ) {}
772 template<> inline void SpellNotifierCreatureAndPlayer::Visit(DynamicObjectMapType& ) {}
773 #endif
776 typedef void(Spell::*pEffect)(SpellEffectIndex eff_idx);
778 class SpellEvent : public BasicEvent
780 public:
781 SpellEvent(Spell* spell);
782 virtual ~SpellEvent();
784 virtual bool Execute(uint64 e_time, uint32 p_time);
785 virtual void Abort(uint64 e_time);
786 virtual bool IsDeletable() const;
787 protected:
788 Spell* m_Spell;
790 #endif