[9076] Another SPELL_EFFECT_PLAYER_PULL problem fix.
[getmangos.git] / src / game / SpellEffects.cpp
blob4a28ebf479617c93ae8fac8c9ec6fc4003d871f7
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "Opcodes.h"
23 #include "Log.h"
24 #include "UpdateMask.h"
25 #include "World.h"
26 #include "ObjectMgr.h"
27 #include "SpellMgr.h"
28 #include "Player.h"
29 #include "SkillExtraItems.h"
30 #include "Unit.h"
31 #include "Spell.h"
32 #include "DynamicObject.h"
33 #include "SpellAuras.h"
34 #include "Group.h"
35 #include "UpdateData.h"
36 #include "MapManager.h"
37 #include "ObjectAccessor.h"
38 #include "SharedDefines.h"
39 #include "Pet.h"
40 #include "GameObject.h"
41 #include "GossipDef.h"
42 #include "Creature.h"
43 #include "Totem.h"
44 #include "CreatureAI.h"
45 #include "BattleGroundMgr.h"
46 #include "BattleGround.h"
47 #include "BattleGroundEY.h"
48 #include "BattleGroundWS.h"
49 #include "VMapFactory.h"
50 #include "Language.h"
51 #include "SocialMgr.h"
52 #include "Util.h"
53 #include "TemporarySummon.h"
54 #include "ScriptCalls.h"
55 #include "SkillDiscovery.h"
56 #include "Formulas.h"
58 pEffect SpellEffects[TOTAL_SPELL_EFFECTS]=
60 &Spell::EffectNULL, // 0
61 &Spell::EffectInstaKill, // 1 SPELL_EFFECT_INSTAKILL
62 &Spell::EffectSchoolDMG, // 2 SPELL_EFFECT_SCHOOL_DAMAGE
63 &Spell::EffectDummy, // 3 SPELL_EFFECT_DUMMY
64 &Spell::EffectUnused, // 4 SPELL_EFFECT_PORTAL_TELEPORT unused
65 &Spell::EffectTeleportUnits, // 5 SPELL_EFFECT_TELEPORT_UNITS
66 &Spell::EffectApplyAura, // 6 SPELL_EFFECT_APPLY_AURA
67 &Spell::EffectEnvirinmentalDMG, // 7 SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
68 &Spell::EffectPowerDrain, // 8 SPELL_EFFECT_POWER_DRAIN
69 &Spell::EffectHealthLeech, // 9 SPELL_EFFECT_HEALTH_LEECH
70 &Spell::EffectHeal, // 10 SPELL_EFFECT_HEAL
71 &Spell::EffectUnused, // 11 SPELL_EFFECT_BIND
72 &Spell::EffectNULL, // 12 SPELL_EFFECT_PORTAL
73 &Spell::EffectUnused, // 13 SPELL_EFFECT_RITUAL_BASE unused
74 &Spell::EffectUnused, // 14 SPELL_EFFECT_RITUAL_SPECIALIZE unused
75 &Spell::EffectUnused, // 15 SPELL_EFFECT_RITUAL_ACTIVATE_PORTAL unused
76 &Spell::EffectQuestComplete, // 16 SPELL_EFFECT_QUEST_COMPLETE
77 &Spell::EffectWeaponDmg, // 17 SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
78 &Spell::EffectResurrect, // 18 SPELL_EFFECT_RESURRECT
79 &Spell::EffectAddExtraAttacks, // 19 SPELL_EFFECT_ADD_EXTRA_ATTACKS
80 &Spell::EffectUnused, // 20 SPELL_EFFECT_DODGE one spell: Dodge
81 &Spell::EffectUnused, // 21 SPELL_EFFECT_EVADE one spell: Evade (DND)
82 &Spell::EffectParry, // 22 SPELL_EFFECT_PARRY
83 &Spell::EffectBlock, // 23 SPELL_EFFECT_BLOCK one spell: Block
84 &Spell::EffectCreateItem, // 24 SPELL_EFFECT_CREATE_ITEM
85 &Spell::EffectUnused, // 25 SPELL_EFFECT_WEAPON
86 &Spell::EffectUnused, // 26 SPELL_EFFECT_DEFENSE one spell: Defense
87 &Spell::EffectPersistentAA, // 27 SPELL_EFFECT_PERSISTENT_AREA_AURA
88 &Spell::EffectSummonType, // 28 SPELL_EFFECT_SUMMON
89 &Spell::EffectLeapForward, // 29 SPELL_EFFECT_LEAP
90 &Spell::EffectEnergize, // 30 SPELL_EFFECT_ENERGIZE
91 &Spell::EffectWeaponDmg, // 31 SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
92 &Spell::EffectTriggerMissileSpell, // 32 SPELL_EFFECT_TRIGGER_MISSILE
93 &Spell::EffectOpenLock, // 33 SPELL_EFFECT_OPEN_LOCK
94 &Spell::EffectSummonChangeItem, // 34 SPELL_EFFECT_SUMMON_CHANGE_ITEM
95 &Spell::EffectApplyAreaAura, // 35 SPELL_EFFECT_APPLY_AREA_AURA_PARTY
96 &Spell::EffectLearnSpell, // 36 SPELL_EFFECT_LEARN_SPELL
97 &Spell::EffectUnused, // 37 SPELL_EFFECT_SPELL_DEFENSE one spell: SPELLDEFENSE (DND)
98 &Spell::EffectDispel, // 38 SPELL_EFFECT_DISPEL
99 &Spell::EffectUnused, // 39 SPELL_EFFECT_LANGUAGE
100 &Spell::EffectDualWield, // 40 SPELL_EFFECT_DUAL_WIELD
101 &Spell::EffectUnused, // 41 SPELL_EFFECT_JUMP
102 &Spell::EffectJump, // 42 SPELL_EFFECT_JUMP2
103 &Spell::EffectTeleUnitsFaceCaster, // 43 SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
104 &Spell::EffectLearnSkill, // 44 SPELL_EFFECT_SKILL_STEP
105 &Spell::EffectAddHonor, // 45 SPELL_EFFECT_ADD_HONOR honor/pvp related
106 &Spell::EffectNULL, // 46 SPELL_EFFECT_SPAWN we must spawn pet there
107 &Spell::EffectTradeSkill, // 47 SPELL_EFFECT_TRADE_SKILL
108 &Spell::EffectUnused, // 48 SPELL_EFFECT_STEALTH one spell: Base Stealth
109 &Spell::EffectUnused, // 49 SPELL_EFFECT_DETECT one spell: Detect
110 &Spell::EffectTransmitted, // 50 SPELL_EFFECT_TRANS_DOOR
111 &Spell::EffectUnused, // 51 SPELL_EFFECT_FORCE_CRITICAL_HIT unused
112 &Spell::EffectUnused, // 52 SPELL_EFFECT_GUARANTEE_HIT one spell: zzOLDCritical Shot
113 &Spell::EffectEnchantItemPerm, // 53 SPELL_EFFECT_ENCHANT_ITEM
114 &Spell::EffectEnchantItemTmp, // 54 SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
115 &Spell::EffectTameCreature, // 55 SPELL_EFFECT_TAMECREATURE
116 &Spell::EffectSummonPet, // 56 SPELL_EFFECT_SUMMON_PET
117 &Spell::EffectLearnPetSpell, // 57 SPELL_EFFECT_LEARN_PET_SPELL
118 &Spell::EffectWeaponDmg, // 58 SPELL_EFFECT_WEAPON_DAMAGE
119 &Spell::EffectCreateRandomItem, // 59 SPELL_EFFECT_CREATE_RANDOM_ITEM create item base at spell specific loot
120 &Spell::EffectProficiency, // 60 SPELL_EFFECT_PROFICIENCY
121 &Spell::EffectSendEvent, // 61 SPELL_EFFECT_SEND_EVENT
122 &Spell::EffectPowerBurn, // 62 SPELL_EFFECT_POWER_BURN
123 &Spell::EffectThreat, // 63 SPELL_EFFECT_THREAT
124 &Spell::EffectTriggerSpell, // 64 SPELL_EFFECT_TRIGGER_SPELL
125 &Spell::EffectApplyAreaAura, // 65 SPELL_EFFECT_APPLY_AREA_AURA_RAID
126 &Spell::EffectUnused, // 66 SPELL_EFFECT_CREATE_MANA_GEM (possibly recharge it, misc - is item ID)
127 &Spell::EffectHealMaxHealth, // 67 SPELL_EFFECT_HEAL_MAX_HEALTH
128 &Spell::EffectInterruptCast, // 68 SPELL_EFFECT_INTERRUPT_CAST
129 &Spell::EffectDistract, // 69 SPELL_EFFECT_DISTRACT
130 &Spell::EffectPull, // 70 SPELL_EFFECT_PULL one spell: Distract Move
131 &Spell::EffectPickPocket, // 71 SPELL_EFFECT_PICKPOCKET
132 &Spell::EffectAddFarsight, // 72 SPELL_EFFECT_ADD_FARSIGHT
133 &Spell::EffectUnused, // 73 SPELL_EFFECT_UNTRAIN_TALENTS
134 &Spell::EffectApplyGlyph, // 74 SPELL_EFFECT_APPLY_GLYPH
135 &Spell::EffectHealMechanical, // 75 SPELL_EFFECT_HEAL_MECHANICAL one spell: Mechanical Patch Kit
136 &Spell::EffectSummonObjectWild, // 76 SPELL_EFFECT_SUMMON_OBJECT_WILD
137 &Spell::EffectScriptEffect, // 77 SPELL_EFFECT_SCRIPT_EFFECT
138 &Spell::EffectUnused, // 78 SPELL_EFFECT_ATTACK
139 &Spell::EffectSanctuary, // 79 SPELL_EFFECT_SANCTUARY
140 &Spell::EffectAddComboPoints, // 80 SPELL_EFFECT_ADD_COMBO_POINTS
141 &Spell::EffectUnused, // 81 SPELL_EFFECT_CREATE_HOUSE one spell: Create House (TEST)
142 &Spell::EffectNULL, // 82 SPELL_EFFECT_BIND_SIGHT
143 &Spell::EffectDuel, // 83 SPELL_EFFECT_DUEL
144 &Spell::EffectStuck, // 84 SPELL_EFFECT_STUCK
145 &Spell::EffectSummonPlayer, // 85 SPELL_EFFECT_SUMMON_PLAYER
146 &Spell::EffectActivateObject, // 86 SPELL_EFFECT_ACTIVATE_OBJECT
147 &Spell::EffectUnused, // 87 SPELL_EFFECT_WMO_DAMAGE
148 &Spell::EffectUnused, // 88 SPELL_EFFECT_WMO_REPAIR
149 &Spell::EffectUnused, // 89 SPELL_EFFECT_WMO_CHANGE
150 &Spell::EffectKillCreditPersonal, // 90 SPELL_EFFECT_KILL_CREDIT Kill credit but only for single person
151 &Spell::EffectUnused, // 91 SPELL_EFFECT_THREAT_ALL one spell: zzOLDBrainwash
152 &Spell::EffectEnchantHeldItem, // 92 SPELL_EFFECT_ENCHANT_HELD_ITEM
153 &Spell::EffectUnused, // 93 SPELL_EFFECT_SUMMON_PHANTASM
154 &Spell::EffectSelfResurrect, // 94 SPELL_EFFECT_SELF_RESURRECT
155 &Spell::EffectSkinning, // 95 SPELL_EFFECT_SKINNING
156 &Spell::EffectCharge, // 96 SPELL_EFFECT_CHARGE
157 &Spell::EffectUnused, // 97 SPELL_EFFECT_97
158 &Spell::EffectKnockBack, // 98 SPELL_EFFECT_KNOCK_BACK
159 &Spell::EffectDisEnchant, // 99 SPELL_EFFECT_DISENCHANT
160 &Spell::EffectInebriate, //100 SPELL_EFFECT_INEBRIATE
161 &Spell::EffectFeedPet, //101 SPELL_EFFECT_FEED_PET
162 &Spell::EffectDismissPet, //102 SPELL_EFFECT_DISMISS_PET
163 &Spell::EffectReputation, //103 SPELL_EFFECT_REPUTATION
164 &Spell::EffectSummonObject, //104 SPELL_EFFECT_SUMMON_OBJECT_SLOT1
165 &Spell::EffectSummonObject, //105 SPELL_EFFECT_SUMMON_OBJECT_SLOT2
166 &Spell::EffectSummonObject, //106 SPELL_EFFECT_SUMMON_OBJECT_SLOT3
167 &Spell::EffectSummonObject, //107 SPELL_EFFECT_SUMMON_OBJECT_SLOT4
168 &Spell::EffectDispelMechanic, //108 SPELL_EFFECT_DISPEL_MECHANIC
169 &Spell::EffectSummonDeadPet, //109 SPELL_EFFECT_SUMMON_DEAD_PET
170 &Spell::EffectDestroyAllTotems, //110 SPELL_EFFECT_DESTROY_ALL_TOTEMS
171 &Spell::EffectDurabilityDamage, //111 SPELL_EFFECT_DURABILITY_DAMAGE
172 &Spell::EffectUnused, //112 SPELL_EFFECT_112
173 &Spell::EffectResurrectNew, //113 SPELL_EFFECT_RESURRECT_NEW
174 &Spell::EffectTaunt, //114 SPELL_EFFECT_ATTACK_ME
175 &Spell::EffectDurabilityDamagePCT, //115 SPELL_EFFECT_DURABILITY_DAMAGE_PCT
176 &Spell::EffectSkinPlayerCorpse, //116 SPELL_EFFECT_SKIN_PLAYER_CORPSE one spell: Remove Insignia, bg usage, required special corpse flags...
177 &Spell::EffectSpiritHeal, //117 SPELL_EFFECT_SPIRIT_HEAL one spell: Spirit Heal
178 &Spell::EffectSkill, //118 SPELL_EFFECT_SKILL professions and more
179 &Spell::EffectApplyAreaAura, //119 SPELL_EFFECT_APPLY_AREA_AURA_PET
180 &Spell::EffectUnused, //120 SPELL_EFFECT_TELEPORT_GRAVEYARD one spell: Graveyard Teleport Test
181 &Spell::EffectWeaponDmg, //121 SPELL_EFFECT_NORMALIZED_WEAPON_DMG
182 &Spell::EffectUnused, //122 SPELL_EFFECT_122 unused
183 &Spell::EffectSendTaxi, //123 SPELL_EFFECT_SEND_TAXI taxi/flight related (misc value is taxi path id)
184 &Spell::EffectPlayerPull, //124 SPELL_EFFECT_PLAYER_PULL opposite of knockback effect (pulls player twoard caster)
185 &Spell::EffectModifyThreatPercent, //125 SPELL_EFFECT_MODIFY_THREAT_PERCENT
186 &Spell::EffectStealBeneficialBuff, //126 SPELL_EFFECT_STEAL_BENEFICIAL_BUFF spell steal effect?
187 &Spell::EffectProspecting, //127 SPELL_EFFECT_PROSPECTING Prospecting spell
188 &Spell::EffectApplyAreaAura, //128 SPELL_EFFECT_APPLY_AREA_AURA_FRIEND
189 &Spell::EffectApplyAreaAura, //129 SPELL_EFFECT_APPLY_AREA_AURA_ENEMY
190 &Spell::EffectNULL, //130 SPELL_EFFECT_REDIRECT_THREAT
191 &Spell::EffectUnused, //131 SPELL_EFFECT_131 used in some test spells
192 &Spell::EffectPlayMusic, //132 SPELL_EFFECT_PLAY_MUSIC sound id in misc value (SoundEntries.dbc)
193 &Spell::EffectUnlearnSpecialization, //133 SPELL_EFFECT_UNLEARN_SPECIALIZATION unlearn profession specialization
194 &Spell::EffectKillCredit, //134 SPELL_EFFECT_KILL_CREDIT misc value is creature entry
195 &Spell::EffectNULL, //135 SPELL_EFFECT_CALL_PET
196 &Spell::EffectHealPct, //136 SPELL_EFFECT_HEAL_PCT
197 &Spell::EffectEnergisePct, //137 SPELL_EFFECT_ENERGIZE_PCT
198 &Spell::EffectLeapBack, //138 SPELL_EFFECT_LEAP_BACK Leap back
199 &Spell::EffectUnused, //139 SPELL_EFFECT_CLEAR_QUEST (misc - is quest ID)
200 &Spell::EffectForceCast, //140 SPELL_EFFECT_FORCE_CAST
201 &Spell::EffectNULL, //141 SPELL_EFFECT_141 damage and reduce speed?
202 &Spell::EffectTriggerSpellWithValue, //142 SPELL_EFFECT_TRIGGER_SPELL_WITH_VALUE
203 &Spell::EffectApplyAreaAura, //143 SPELL_EFFECT_APPLY_AREA_AURA_OWNER
204 &Spell::EffectNULL, //144 SPELL_EFFECT_144 Spectral Blast
205 &Spell::EffectNULL, //145 SPELL_EFFECT_145 Black Hole Effect
206 &Spell::EffectActivateRune, //146 SPELL_EFFECT_ACTIVATE_RUNE
207 &Spell::EffectQuestFail, //147 SPELL_EFFECT_QUEST_FAIL quest fail
208 &Spell::EffectUnused, //148 SPELL_EFFECT_148 unused
209 &Spell::EffectCharge2, //149 SPELL_EFFECT_CHARGE2 swoop
210 &Spell::EffectUnused, //150 SPELL_EFFECT_150 unused
211 &Spell::EffectTriggerRitualOfSummoning, //151 SPELL_EFFECT_TRIGGER_SPELL_2
212 &Spell::EffectNULL, //152 SPELL_EFFECT_152 summon Refer-a-Friend
213 &Spell::EffectNULL, //153 SPELL_EFFECT_CREATE_PET misc value is creature entry
214 &Spell::EffectNULL, //154 unused
215 &Spell::EffectTitanGrip, //155 SPELL_EFFECT_TITAN_GRIP Allows you to equip two-handed axes, maces and swords in one hand, but you attack $49152s1% slower than normal.
216 &Spell::EffectEnchantItemPrismatic, //156 SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
217 &Spell::EffectCreateItem2, //157 SPELL_EFFECT_CREATE_ITEM_2 create item or create item template and replace by some randon spell loot item
218 &Spell::EffectMilling, //158 SPELL_EFFECT_MILLING milling
219 &Spell::EffectRenamePet, //159 SPELL_EFFECT_ALLOW_RENAME_PET allow rename pet once again
220 &Spell::EffectNULL, //160 SPELL_EFFECT_160 unused
221 &Spell::EffectNULL, //161 SPELL_EFFECT_TALENT_SPEC_COUNT second talent spec (learn/revert)
222 &Spell::EffectNULL, //162 SPELL_EFFECT_TALENT_SPEC_SELECT activate primary/secondary spec
225 void Spell::EffectNULL(uint32 /*i*/)
227 sLog.outDebug("WORLD: Spell Effect DUMMY");
230 void Spell::EffectUnused(uint32 /*i*/)
232 // NOT USED BY ANY SPELL OR USELESS OR IMPLEMENTED IN DIFFERENT WAY IN MANGOS
235 void Spell::EffectResurrectNew(uint32 i)
237 if(!unitTarget || unitTarget->isAlive())
238 return;
240 if(unitTarget->GetTypeId() != TYPEID_PLAYER)
241 return;
243 if(!unitTarget->IsInWorld())
244 return;
246 Player* pTarget = ((Player*)unitTarget);
248 if(pTarget->isRessurectRequested()) // already have one active request
249 return;
251 uint32 health = damage;
252 uint32 mana = m_spellInfo->EffectMiscValue[i];
253 pTarget->setResurrectRequestData(m_caster->GetGUID(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), health, mana);
254 SendResurrectRequest(pTarget);
257 void Spell::EffectInstaKill(uint32 /*i*/)
259 if( !unitTarget || !unitTarget->isAlive() )
260 return;
262 // Demonic Sacrifice
263 if(m_spellInfo->Id==18788 && unitTarget->GetTypeId()==TYPEID_UNIT)
265 uint32 entry = unitTarget->GetEntry();
266 uint32 spellID;
267 switch(entry)
269 case 416: spellID=18789; break; //imp
270 case 417: spellID=18792; break; //fellhunter
271 case 1860: spellID=18790; break; //void
272 case 1863: spellID=18791; break; //succubus
273 case 17252: spellID=35701; break; //fellguard
274 default:
275 sLog.outError("EffectInstaKill: Unhandled creature entry (%u) case.", entry);
276 return;
279 m_caster->CastSpell(m_caster, spellID, true);
282 if(m_caster == unitTarget) // prevent interrupt message
283 finish();
285 m_caster->DealDamage(unitTarget, unitTarget->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
288 void Spell::EffectEnvirinmentalDMG(uint32 i)
290 uint32 absorb = 0;
291 uint32 resist = 0;
293 // Note: this hack with damage replace required until GO casting not implemented
294 // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support
295 // currently each enemy selected explicitly and self cast damage, we prevent apply self casted spell bonuses/etc
296 damage = m_spellInfo->CalculateSimpleValue(i);
298 m_caster->CalcAbsorbResist(m_caster, GetSpellSchoolMask(m_spellInfo), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
300 m_caster->SendSpellNonMeleeDamageLog(m_caster, m_spellInfo->Id, damage, GetSpellSchoolMask(m_spellInfo), absorb, resist, false, 0, false);
301 if(m_caster->GetTypeId() == TYPEID_PLAYER)
302 ((Player*)m_caster)->EnvironmentalDamage(DAMAGE_FIRE, damage);
305 void Spell::EffectSchoolDMG(uint32 effect_idx)
307 if( unitTarget && unitTarget->isAlive())
309 switch(m_spellInfo->SpellFamilyName)
311 case SPELLFAMILY_GENERIC:
313 switch(m_spellInfo->Id) // better way to check unknown
315 // Meteor like spells (divided damage to targets)
316 case 24340: case 26558: case 28884: // Meteor
317 case 36837: case 38903: case 41276: // Meteor
318 case 26789: // Shard of the Fallen Star
319 case 31436: // Malevolent Cleave
320 case 35181: // Dive Bomb
321 case 40810: case 43267: case 43268: // Saber Lash
322 case 42384: // Brutal Swipe
323 case 45150: // Meteor Slash
324 case 64422: case 64688: // Sonic Screech
326 uint32 count = 0;
327 for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit)
328 if(ihit->effectMask & (1<<effect_idx))
329 ++count;
331 damage /= count; // divide to all targets
332 break;
334 // percent from health with min
335 case 25599: // Thundercrash
337 damage = unitTarget->GetHealth() / 2;
338 if(damage < 200)
339 damage = 200;
340 break;
342 // Intercept (warrior spell trigger)
343 case 20253:
344 case 61491:
346 damage+= uint32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 0.12f);
347 break;
349 // Cataclysmic Bolt
350 case 38441:
352 damage = unitTarget->GetMaxHealth() / 2;
353 break;
355 // Tympanic Tantrum
356 case 62775:
358 damage = unitTarget->GetMaxHealth() / 10;
359 break;
361 // Hand of Rekoning (name not have typos ;) )
362 case 67485:
363 damage += uint32(0.5f * m_caster->GetTotalAttackPowerValue(BASE_ATTACK));
364 break;
366 break;
368 case SPELLFAMILY_MAGE:
369 // remove Arcane Blast buffs at any non-Arcane Blast arcane damage spell.
370 // NOTE: it removed at hit instead cast because currently spell done-damage calculated at hit instead cast
371 if ((m_spellInfo->SchoolMask & SPELL_SCHOOL_MASK_ARCANE) && !(m_spellInfo->SpellFamilyFlags & UI64LIT(0x20000000)))
372 m_caster->RemoveAurasDueToSpell(36032); // Arcane Blast buff
373 break;
374 case SPELLFAMILY_WARRIOR:
376 // Bloodthirst
377 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x40000000000))
379 damage = uint32(damage * (m_caster->GetTotalAttackPowerValue(BASE_ATTACK)) / 100);
381 // Shield Slam
382 else if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000020000000000)) && m_spellInfo->Category==1209)
383 damage += int32(m_caster->GetShieldBlockValue());
384 // Victory Rush
385 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x10000000000))
387 damage = uint32(damage * m_caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
388 m_caster->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, false);
390 // Revenge ${$m1+$AP*0.207} to ${$M1+$AP*0.207}
391 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000400))
392 damage+= uint32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 0.207f);
393 // Heroic Throw ${$m1+$AP*.50}
394 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000100000000))
395 damage+= uint32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 0.5f);
396 // Shockwave ${$m3/100*$AP}
397 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000800000000000))
399 int32 pct = m_caster->CalculateSpellDamage(m_spellInfo, 2, m_spellInfo->EffectBasePoints[2], unitTarget);
400 if (pct > 0)
401 damage+= int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * pct / 100);
402 break;
404 // Thunder Clap
405 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000080))
407 damage+=int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 12 / 100);
409 break;
411 case SPELLFAMILY_WARLOCK:
413 // Incinerate Rank 1 & 2
414 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x00004000000000)) && m_spellInfo->SpellIconID==2128)
416 // Incinerate does more dmg (dmg*0.25) if the target have Immolate debuff.
417 // Check aura state for speed but aura state set not only for Immolate spell
418 if(unitTarget->HasAuraState(AURA_STATE_CONFLAGRATE))
420 Unit::AuraList const& RejorRegr = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
421 for(Unit::AuraList::const_iterator i = RejorRegr.begin(); i != RejorRegr.end(); ++i)
423 // Immolate
424 if((*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK &&
425 ((*i)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x00000000000004)))
427 damage += damage/4;
428 break;
433 // Shadowflame
434 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0001000000000000))
436 // Apply DOT part
437 switch(m_spellInfo->Id)
439 case 47897: m_caster->CastSpell(unitTarget, 47960, true); break;
440 case 61290: m_caster->CastSpell(unitTarget, 61291, true); break;
441 default:
442 sLog.outError("Spell::EffectDummy: Unhandeled Shadowflame spell rank %u",m_spellInfo->Id);
443 break;
446 // Conflagrate - consumes Immolate or Shadowflame
447 else if (m_spellInfo->TargetAuraState == AURA_STATE_CONFLAGRATE)
449 Aura const* aura = NULL; // found req. aura for damage calculation
451 Unit::AuraList const &mPeriodic = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
452 for(Unit::AuraList::const_iterator i = mPeriodic.begin(); i != mPeriodic.end(); ++i)
454 // for caster applied auras only
455 if ((*i)->GetSpellProto()->SpellFamilyName != SPELLFAMILY_WARLOCK ||
456 (*i)->GetCasterGUID()!=m_caster->GetGUID())
457 continue;
459 // Immolate
460 if ((*i)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000004))
462 aura = *i; // it selected always if exist
463 break;
466 // Shadowflame
467 if ((*i)->GetSpellProto()->SpellFamilyFlags2 & 0x00000002)
468 aura = *i; // remember but wait possible Immolate as primary priority
471 // found Immolate or Shadowflame
472 if (aura)
474 // DoT not have applied spell bonuses in m_amount
475 int32 damagetick = m_caster->SpellDamageBonus(unitTarget, aura->GetSpellProto(), aura->GetModifier()->m_amount, DOT);
476 damage += damagetick * 4;
478 // Glyph of Conflagrate
479 if (!m_caster->HasAura(56235))
480 unitTarget->RemoveAurasByCasterSpell(aura->GetId(), m_caster->GetGUID());
481 break;
484 break;
486 case SPELLFAMILY_PRIEST:
488 // Shadow Word: Death - deals damage equal to damage done to caster
489 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000200000000))
490 m_caster->CastCustomSpell(m_caster, 32409, &damage, 0, 0, true);
491 // Improved Mind Blast (Mind Blast in shadow form bonus)
492 else if (m_caster->m_form == FORM_SHADOW && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x00002000)))
494 Unit::AuraList const& ImprMindBlast = m_caster->GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER);
495 for(Unit::AuraList::const_iterator i = ImprMindBlast.begin(); i != ImprMindBlast.end(); ++i)
497 if ((*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_PRIEST &&
498 ((*i)->GetSpellProto()->SpellIconID == 95))
500 int chance = (*i)->GetSpellProto()->CalculateSimpleValue(1);
501 if (roll_chance_i(chance))
502 // Mind Trauma
503 m_caster->CastSpell(unitTarget, 48301, true, 0);
504 break;
508 break;
510 case SPELLFAMILY_DRUID:
512 // Ferocious Bite
513 if (m_caster->GetTypeId()==TYPEID_PLAYER && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x000800000)) && m_spellInfo->SpellVisual[0]==6587)
515 // converts up to 30 points of energy into ($f1+$AP/410) additional damage
516 float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
517 float multiple = ap / 410 + m_spellInfo->DmgMultiplier[effect_idx];
518 damage += int32(((Player*)m_caster)->GetComboPoints() * ap * 7 / 100);
519 uint32 energy = m_caster->GetPower(POWER_ENERGY);
520 uint32 used_energy = energy > 30 ? 30 : energy;
521 damage += int32(used_energy * multiple);
522 m_caster->SetPower(POWER_ENERGY,energy-used_energy);
524 // Rake
525 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000001000) && m_spellInfo->Effect[2]==SPELL_EFFECT_ADD_COMBO_POINTS)
527 // $AP*0.01 bonus
528 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
530 // Swipe
531 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0010000000000000))
533 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.08f);
535 break;
537 case SPELLFAMILY_ROGUE:
539 // Envenom
540 if (m_caster->GetTypeId()==TYPEID_PLAYER && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x800000000)))
542 // consume from stack dozes not more that have combo-points
543 if(uint32 combo = ((Player*)m_caster)->GetComboPoints())
545 Aura *poison = 0;
546 // Lookup for Deadly poison (only attacker applied)
547 Unit::AuraList const& auras = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
548 for(Unit::AuraList::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
549 if( (*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_ROGUE &&
550 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x10000)) &&
551 (*itr)->GetCasterGUID()==m_caster->GetGUID() )
553 poison = *itr;
554 break;
556 // count consumed deadly poison doses at target
557 if (poison)
559 uint32 spellId = poison->GetId();
560 uint32 doses = poison->GetStackAmount();
561 if (doses > combo)
562 doses = combo;
563 for (int i=0; i< doses; i++)
564 unitTarget->RemoveSingleSpellAurasFromStack(spellId);
565 damage *= doses;
566 damage += int32(((Player*)m_caster)->GetTotalAttackPowerValue(BASE_ATTACK) * 0.09f * doses);
568 // Eviscerate and Envenom Bonus Damage (item set effect)
569 if(m_caster->GetDummyAura(37169))
570 damage += ((Player*)m_caster)->GetComboPoints()*40;
573 // Eviscerate
574 else if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x00020000)) && m_caster->GetTypeId()==TYPEID_PLAYER)
576 if(uint32 combo = ((Player*)m_caster)->GetComboPoints())
578 float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
579 damage += irand(int32(ap * combo * 0.03f), int32(ap * combo * 0.07f));
581 // Eviscerate and Envenom Bonus Damage (item set effect)
582 if(m_caster->GetDummyAura(37169))
583 damage += combo*40;
586 // Gouge
587 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000008))
589 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.21f);
591 // Instant Poison
592 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000002000))
594 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.10f);
596 // Wound Poison
597 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000010000000))
599 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.04f);
601 break;
603 case SPELLFAMILY_HUNTER:
605 //Gore
606 if (m_spellInfo->SpellIconID == 1578)
608 if (m_caster->HasAura(57627)) // Charge 6 sec post-affect
609 damage *= 2;
611 // Mongoose Bite
612 else if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x000000002)) && m_spellInfo->SpellVisual[0]==342)
614 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.2f);
616 // Counterattack
617 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0008000000000000))
619 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.2f);
621 // Arcane Shot
622 else if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x00000800)) && m_spellInfo->maxLevel > 0)
624 damage += int32(m_caster->GetTotalAttackPowerValue(RANGED_ATTACK)*0.15f);
626 // Steady Shot
627 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x100000000))
629 int32 base = irand((int32)m_caster->GetWeaponDamageRange(RANGED_ATTACK, MINDAMAGE),(int32)m_caster->GetWeaponDamageRange(RANGED_ATTACK, MAXDAMAGE));
630 damage += int32(float(base)/m_caster->GetAttackTime(RANGED_ATTACK)*2800 + m_caster->GetTotalAttackPowerValue(RANGED_ATTACK)*0.1f);
632 // Explosive Trap Effect
633 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x00000004))
635 damage += int32(m_caster->GetTotalAttackPowerValue(RANGED_ATTACK)*0.1f);
637 break;
639 case SPELLFAMILY_PALADIN:
641 // Judgement of Vengeance/Corruption ${1+0.22*$SPH+0.14*$AP} + 10% for each application of Holy Vengeance/Blood Corruption on the target
642 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x800000000)) && m_spellInfo->SpellIconID==2292)
644 uint32 debuf_id;
645 switch(m_spellInfo->Id)
647 case 53733: debuf_id = 53742; break;// Judgement of Corruption -> Blood Corruption
648 case 31804: debuf_id = 31803; break;// Judgement of Vengeance -> Holy Vengeance
649 default: return;
652 float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
653 int32 holy = m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo)) +
654 m_caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellInfo), unitTarget);
655 damage+=int32(ap * 0.14f) + int32(holy * 22 / 100);
656 // Get stack of Holy Vengeance on the target added by caster
657 uint32 stacks = 0;
658 Unit::AuraList const& auras = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
659 for(Unit::AuraList::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
661 if( ((*itr)->GetId() == debuf_id) && (*itr)->GetCasterGUID()==m_caster->GetGUID())
663 stacks = (*itr)->GetStackAmount();
664 break;
667 // + 10% for each application of Holy Vengeance on the target
668 if(stacks)
669 damage += damage * stacks * 10 /100;
671 // Hammer of the Righteous
672 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0004000000000000))
674 // Add main hand dps * effect[2] amount
675 float average = (m_caster->GetFloatValue(UNIT_FIELD_MINDAMAGE) + m_caster->GetFloatValue(UNIT_FIELD_MAXDAMAGE)) / 2;
676 int32 count = m_caster->CalculateSpellDamage(m_spellInfo, 2, m_spellInfo->EffectBasePoints[2], unitTarget);
677 damage += count * int32(average * IN_MILISECONDS) / m_caster->GetAttackTime(BASE_ATTACK);
679 // Shield of Righteousness
680 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0010000000000000))
682 damage+=int32(m_caster->GetShieldBlockValue());
684 // Judgement
685 else if (m_spellInfo->Id == 54158)
687 // [1 + 0.25 * SPH + 0.16 * AP]
688 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 0.16f);
690 break;
694 if(damage >= 0)
695 m_damage += damage;
699 void Spell::EffectDummy(uint32 i)
701 if (!unitTarget && !gameObjTarget && !itemTarget)
702 return;
704 // selection by spell family
705 switch(m_spellInfo->SpellFamilyName)
707 case SPELLFAMILY_GENERIC:
709 switch(m_spellInfo->Id )
711 case 8063: // Deviate Fish
713 if (m_caster->GetTypeId() != TYPEID_PLAYER)
714 return;
716 uint32 spell_id = 0;
717 switch(urand(1,5))
719 case 1: spell_id = 8064; break; // Sleepy
720 case 2: spell_id = 8065; break; // Invigorate
721 case 3: spell_id = 8066; break; // Shrink
722 case 4: spell_id = 8067; break; // Party Time!
723 case 5: spell_id = 8068; break; // Healthy Spirit
725 m_caster->CastSpell(m_caster, spell_id, true, NULL);
726 return;
728 case 8213: // Savory Deviate Delight
730 if (m_caster->GetTypeId() != TYPEID_PLAYER)
731 return;
733 uint32 spell_id = 0;
734 switch(urand(1,2))
736 // Flip Out - ninja
737 case 1: spell_id = (m_caster->getGender() == GENDER_MALE ? 8219 : 8220); break;
738 // Yaaarrrr - pirate
739 case 2: spell_id = (m_caster->getGender() == GENDER_MALE ? 8221 : 8222); break;
741 m_caster->CastSpell(m_caster,spell_id,true,NULL);
742 return;
744 case 8593: // Symbol of life (restore creature to life)
745 case 31225: // Shimmering Vessel (restore creature to life)
747 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
748 return;
749 ((Creature*)unitTarget)->setDeathState(JUST_ALIVED);
750 return;
752 case 13120: // net-o-matic
754 if (!unitTarget)
755 return;
757 uint32 spell_id = 0;
759 uint32 roll = urand(0, 99);
761 if (roll < 2) // 2% for 30 sec self root (off-like chance unknown)
762 spell_id = 16566;
763 else if (roll < 4) // 2% for 20 sec root, charge to target (off-like chance unknown)
764 spell_id = 13119;
765 else // normal root
766 spell_id = 13099;
768 m_caster->CastSpell(unitTarget,spell_id,true,NULL);
769 return;
771 case 13567: // Dummy Trigger
773 // can be used for different aura triggering, so select by aura
774 if (!m_triggeredByAuraSpell || !unitTarget)
775 return;
777 switch(m_triggeredByAuraSpell->Id)
779 case 26467: // Persistent Shield
780 m_caster->CastCustomSpell(unitTarget, 26470, &damage, NULL, NULL, true);
781 break;
782 default:
783 sLog.outError("EffectDummy: Non-handled case for spell 13567 for triggered aura %u",m_triggeredByAuraSpell->Id);
784 break;
786 return;
788 case 15998: // Capture Worg Pup
789 case 29435: // Capture Female Kaliri Hatchling
791 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
792 return;
794 Creature* creatureTarget = (Creature*)unitTarget;
796 creatureTarget->ForcedDespawn();
797 return;
799 case 16589: // Noggenfogger Elixir
801 if (m_caster->GetTypeId() != TYPEID_PLAYER)
802 return;
804 uint32 spell_id = 0;
805 switch(urand(1, 3))
807 case 1: spell_id = 16595; break;
808 case 2: spell_id = 16593; break;
809 default:spell_id = 16591; break;
812 m_caster->CastSpell(m_caster, spell_id, true, NULL);
813 return;
815 case 17251: // Spirit Healer Res
817 if (!unitTarget || !m_originalCaster)
818 return;
820 if (m_originalCaster->GetTypeId() == TYPEID_PLAYER)
822 WorldPacket data(SMSG_SPIRIT_HEALER_CONFIRM, 8);
823 data << uint64(unitTarget->GetGUID());
824 ((Player*)m_originalCaster)->GetSession()->SendPacket( &data );
826 return;
828 case 17271: // Test Fetid Skull
830 if (!itemTarget && m_caster->GetTypeId()!=TYPEID_PLAYER)
831 return;
833 uint32 spell_id = roll_chance_i(50)
834 ? 17269 // Create Resonating Skull
835 : 17270; // Create Bone Dust
837 m_caster->CastSpell(m_caster, spell_id, true, NULL);
838 return;
840 case 20577: // Cannibalize
841 if (unitTarget)
842 m_caster->CastSpell(m_caster, 20578, false, NULL);
843 return;
844 case 23019: // Crystal Prison Dummy DND
846 if (!unitTarget || !unitTarget->isAlive() || unitTarget->GetTypeId() != TYPEID_UNIT || ((Creature*)unitTarget)->isPet())
847 return;
849 Creature* creatureTarget = (Creature*)unitTarget;
850 if (creatureTarget->isPet())
851 return;
853 GameObject* pGameObj = new GameObject;
855 Map *map = creatureTarget->GetMap();
857 // create before death for get proper coordinates
858 if (!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), 179644, map, m_caster->GetPhaseMask(),
859 creatureTarget->GetPositionX(), creatureTarget->GetPositionY(), creatureTarget->GetPositionZ(),
860 creatureTarget->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY) )
862 delete pGameObj;
863 return;
866 pGameObj->SetRespawnTime(creatureTarget->GetRespawnTime()-time(NULL));
867 pGameObj->SetOwnerGUID(m_caster->GetGUID() );
868 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel() );
869 pGameObj->SetSpellId(m_spellInfo->Id);
871 creatureTarget->ForcedDespawn();
873 DEBUG_LOG("AddObject at SpellEfects.cpp EffectDummy");
874 map->Add(pGameObj);
876 return;
878 case 23074: // Arcanite Dragonling
879 if (!m_CastItem)
880 return;
881 m_caster->CastSpell(m_caster, 19804, true, m_CastItem);
882 return;
883 case 23075: // Mithril Mechanical Dragonling
884 if (!m_CastItem)
885 return;
886 m_caster->CastSpell(m_caster, 12749, true, m_CastItem);
887 return;
888 case 23076: // Mechanical Dragonling
889 if (!m_CastItem)
890 return;
891 m_caster->CastSpell(m_caster, 4073, true, m_CastItem);
892 return;
893 case 23133: // Gnomish Battle Chicken
894 if (!m_CastItem)
895 return;
896 m_caster->CastSpell(m_caster, 13166, true, m_CastItem);
897 return;
898 case 23448: // Transporter Arrival - Ultrasafe Transporter: Gadgetzan - backfires
900 int32 r = irand(0, 119);
901 if (r < 20) // Transporter Malfunction - 1/6 polymorph
902 m_caster->CastSpell(m_caster, 23444, true);
903 else if (r < 100) // Evil Twin - 4/6 evil twin
904 m_caster->CastSpell(m_caster, 23445, true);
905 else // Transporter Malfunction - 1/6 miss the target
906 m_caster->CastSpell(m_caster, 36902, true);
907 return;
909 case 23453: // Gnomish Transporter - Ultrasafe Transporter: Gadgetzan
910 if (roll_chance_i(50)) // Gadgetzan Transporter - success
911 m_caster->CastSpell(m_caster, 23441, true);
912 else // Gadgetzan Transporter Failure - failure
913 m_caster->CastSpell(m_caster, 23446, true);
914 return;
915 case 23645: // Hourglass Sand
916 m_caster->RemoveAurasDueToSpell(23170); // Brood Affliction: Bronze
917 return;
918 case 23725: // Gift of Life (warrior bwl trinket)
919 m_caster->CastSpell(m_caster, 23782, true);
920 m_caster->CastSpell(m_caster, 23783, true);
921 return;
922 case 25860: // Reindeer Transformation
924 if (!m_caster->HasAuraType(SPELL_AURA_MOUNTED))
925 return;
927 float flyspeed = m_caster->GetSpeedRate(MOVE_FLIGHT);
928 float speed = m_caster->GetSpeedRate(MOVE_RUN);
930 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
932 //5 different spells used depending on mounted speed and if mount can fly or not
933 if (flyspeed >= 4.1f)
934 // Flying Reindeer
935 m_caster->CastSpell(m_caster, 44827, true); //310% flying Reindeer
936 else if (flyspeed >= 3.8f)
937 // Flying Reindeer
938 m_caster->CastSpell(m_caster, 44825, true); //280% flying Reindeer
939 else if (flyspeed >= 1.6f)
940 // Flying Reindeer
941 m_caster->CastSpell(m_caster, 44824, true); //60% flying Reindeer
942 else if (speed >= 2.0f)
943 // Reindeer
944 m_caster->CastSpell(m_caster, 25859, true); //100% ground Reindeer
945 else
946 // Reindeer
947 m_caster->CastSpell(m_caster, 25858, true); //60% ground Reindeer
949 return;
951 case 26074: // Holiday Cheer
952 // implemented at client side
953 return;
954 case 28006: // Arcane Cloaking
956 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER )
957 // Naxxramas Entry Flag Effect DND
958 m_caster->CastSpell(unitTarget, 29294, true);
959 return;
961 case 29200: // Purify Helboar Meat
963 if (m_caster->GetTypeId() != TYPEID_PLAYER)
964 return;
966 uint32 spell_id = roll_chance_i(50)
967 ? 29277 // Summon Purified Helboar Meat
968 : 29278; // Summon Toxic Helboar Meat
970 m_caster->CastSpell(m_caster,spell_id,true,NULL);
971 return;
973 case 29858: // Soulshatter
974 if (unitTarget && unitTarget->GetTypeId() == TYPEID_UNIT && unitTarget->IsHostileTo(m_caster))
975 m_caster->CastSpell(unitTarget,32835,true);
976 return;
977 case 30458: // Nigh Invulnerability
978 if (!m_CastItem)
979 return;
980 if (roll_chance_i(86)) // Nigh-Invulnerability - success
981 m_caster->CastSpell(m_caster, 30456, true, m_CastItem);
982 else // Complete Vulnerability - backfire in 14% casts
983 m_caster->CastSpell(m_caster, 30457, true, m_CastItem);
984 return;
985 case 30507: // Poultryizer
986 if(!m_CastItem)
987 return;
988 if (roll_chance_i(80)) // Poultryized! - success
989 m_caster->CastSpell(unitTarget, 30501, true, m_CastItem);
990 else // Poultryized! - backfire 20%
991 m_caster->CastSpell(unitTarget, 30504, true, m_CastItem);
992 return;
993 case 33060: // Make a Wish
995 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
996 return;
998 uint32 spell_id = 0;
1000 switch(urand(1,5))
1002 case 1: spell_id = 33053; break; // Mr Pinchy's Blessing
1003 case 2: spell_id = 33057; break; // Summon Mighty Mr. Pinchy
1004 case 3: spell_id = 33059; break; // Summon Furious Mr. Pinchy
1005 case 4: spell_id = 33062; break; // Tiny Magical Crawdad
1006 case 5: spell_id = 33064; break; // Mr. Pinchy's Gift
1009 m_caster->CastSpell(m_caster, spell_id, true, NULL);
1010 return;
1012 case 34665: //Administer Antidote
1014 if (!unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER )
1015 return;
1016 // Spell has scriptable target but for sure.
1017 if (unitTarget->GetTypeId() != TYPEID_UNIT)
1018 return;
1020 uint32 health = unitTarget->GetHealth();
1021 float x, y, z, o;
1023 unitTarget->GetPosition(x, y, z);
1024 o = unitTarget->GetOrientation();
1025 ((Creature*)unitTarget)->ForcedDespawn();
1027 if (Creature* summon = m_caster->SummonCreature(16992, x, y, z, o,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,180000))
1029 summon->SetHealth(health);
1030 ((Player*)m_caster)->RewardPlayerAndGroupAtEvent(16992, summon);
1032 if (summon->AI())
1033 summon->AI()->AttackStart(m_caster);
1035 return;
1037 case 35745: // Socrethar's Stone
1039 uint32 spell_id;
1040 switch(m_caster->GetAreaId())
1042 case 3900: spell_id = 35743; break; // Socrethar Portal
1043 case 3742: spell_id = 35744; break; // Socrethar Portal
1044 default: return;
1047 m_caster->CastSpell(m_caster, spell_id, true);
1048 return;
1050 case 37674: // Chaos Blast
1052 if (!unitTarget)
1053 return;
1055 int32 basepoints0 = 100;
1056 m_caster->CastCustomSpell(unitTarget, 37675, &basepoints0, NULL, NULL, true);
1057 return;
1059 case 40802: // Mingo's Fortune Generator (Mingo's Fortune Giblets)
1061 // selecting one from Bloodstained Fortune item
1062 uint32 newitemid;
1063 switch(urand(1, 20))
1065 case 1: newitemid = 32688; break;
1066 case 2: newitemid = 32689; break;
1067 case 3: newitemid = 32690; break;
1068 case 4: newitemid = 32691; break;
1069 case 5: newitemid = 32692; break;
1070 case 6: newitemid = 32693; break;
1071 case 7: newitemid = 32700; break;
1072 case 8: newitemid = 32701; break;
1073 case 9: newitemid = 32702; break;
1074 case 10: newitemid = 32703; break;
1075 case 11: newitemid = 32704; break;
1076 case 12: newitemid = 32705; break;
1077 case 13: newitemid = 32706; break;
1078 case 14: newitemid = 32707; break;
1079 case 15: newitemid = 32708; break;
1080 case 16: newitemid = 32709; break;
1081 case 17: newitemid = 32710; break;
1082 case 18: newitemid = 32711; break;
1083 case 19: newitemid = 32712; break;
1084 case 20: newitemid = 32713; break;
1085 default:
1086 return;
1089 DoCreateItem(i, newitemid);
1090 return;
1092 // Demon Broiled Surprise
1093 /* FIX ME: Required for correct work implementing implicit target 7 (in pair (22,7))
1094 case 43723:
1096 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1097 return;
1099 ((Player*)m_caster)->CastSpell(unitTarget, 43753, true);
1100 return;
1103 case 44875: // Complete Raptor Capture
1105 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
1106 return;
1108 Creature* creatureTarget = (Creature*)unitTarget;
1110 creatureTarget->ForcedDespawn();
1112 //cast spell Raptor Capture Credit
1113 m_caster->CastSpell(m_caster, 42337, true, NULL);
1114 return;
1116 case 44997: // Converting Sentry
1118 //Converted Sentry Credit
1119 m_caster->CastSpell(m_caster, 45009, true);
1120 return;
1122 case 45030: // Impale Emissary
1124 // Emissary of Hate Credit
1125 m_caster->CastSpell(m_caster, 45088, true);
1126 return;
1128 case 49357: // Brewfest Mount Transformation
1129 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1130 return;
1132 if (!m_caster->HasAuraType(SPELL_AURA_MOUNTED))
1133 return;
1135 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1137 // Ram for Alliance, Kodo for Horde
1138 if (((Player *)m_caster)->GetTeam() == ALLIANCE)
1140 if (m_caster->GetSpeedRate(MOVE_RUN) >= 2.0f)
1141 // 100% Ram
1142 m_caster->CastSpell(m_caster, 43900, true);
1143 else
1144 // 60% Ram
1145 m_caster->CastSpell(m_caster, 43899, true);
1147 else
1149 if (((Player *)m_caster)->GetSpeedRate(MOVE_RUN) >= 2.0f)
1150 // 100% Kodo
1151 m_caster->CastSpell(m_caster, 49379, true);
1152 else
1153 // 60% Kodo
1154 m_caster->CastSpell(m_caster, 49378, true);
1156 return;
1157 case 50243: // Teach Language
1159 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1160 return;
1162 // spell has a 1/3 chance to trigger one of the below
1163 if (roll_chance_i(66))
1164 return;
1165 if (((Player*)m_caster)->GetTeam() == ALLIANCE)
1167 // 1000001 - gnomish binary
1168 m_caster->CastSpell(m_caster, 50242, true);
1170 else
1172 // 01001000 - goblin binary
1173 m_caster->CastSpell(m_caster, 50246, true);
1176 return;
1178 case 51582: //Rocket Boots Engaged (Rocket Boots Xtreme and Rocket Boots Xtreme Lite)
1180 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1181 return;
1183 if (BattleGround* bg = ((Player*)m_caster)->GetBattleGround())
1184 bg->EventPlayerDroppedFlag((Player*)m_caster);
1186 m_caster->CastSpell(m_caster, 30452, true, NULL);
1187 return;
1189 case 51592: // Pickup Primordial Hatchling
1191 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
1192 return;
1194 Creature* creatureTarget = (Creature*)unitTarget;
1196 creatureTarget->ForcedDespawn();
1197 return;
1200 case 52308: // Take Sputum Sample
1202 switch(i)
1204 case 0:
1206 uint32 spellID = m_spellInfo->CalculateSimpleValue(0);
1207 uint32 reqAuraID = m_spellInfo->CalculateSimpleValue(1);
1209 if (m_caster->HasAura(reqAuraID,0))
1210 m_caster->CastSpell(m_caster, spellID, true, NULL);
1211 return;
1213 case 1:
1214 return; // additional data for dummy[0]
1216 return;
1218 case 52759: // Ancestral Awakening
1219 if (!unitTarget)
1220 return;
1221 m_caster->CastCustomSpell(unitTarget, 52752, &damage, NULL, NULL, true);
1222 return;
1223 case 52845: // Brewfest Mount Transformation (Faction Swap)
1224 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1225 return;
1227 if (!m_caster->HasAuraType(SPELL_AURA_MOUNTED))
1228 return;
1230 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1232 // Ram for Horde, Kodo for Alliance
1233 if (((Player *)m_caster)->GetTeam() == HORDE)
1235 if (m_caster->GetSpeedRate(MOVE_RUN) >= 2.0f)
1236 // Swift Brewfest Ram, 100% Ram
1237 m_caster->CastSpell(m_caster, 43900, true);
1238 else
1239 // Brewfest Ram, 60% Ram
1240 m_caster->CastSpell(m_caster, 43899, true);
1242 else
1244 if (((Player *)m_caster)->GetSpeedRate(MOVE_RUN) >= 2.0f)
1245 // Great Brewfest Kodo, 100% Kodo
1246 m_caster->CastSpell(m_caster, 49379, true);
1247 else
1248 // Brewfest Riding Kodo, 60% Kodo
1249 m_caster->CastSpell(m_caster, 49378, true);
1251 return;
1252 case 53341: // Rune of Cinderglacier
1253 case 53343: // Rune of Razorice
1255 // Runeforging Credit
1256 m_caster->CastSpell(m_caster, 54586, true);
1257 return;
1259 case 55004: // Nitro Boosts
1260 if (!m_CastItem)
1261 return;
1262 if (roll_chance_i(95)) // Nitro Boosts - success
1263 m_caster->CastSpell(m_caster, 54861, true, m_CastItem);
1264 else // Knocked Up - backfire 5%
1265 m_caster->CastSpell(m_caster, 46014, true, m_CastItem);
1266 return;
1267 case 58418: // Portal to Orgrimmar
1268 case 58420: // Portal to Stormwind
1269 return; // implemented in EffectScript[0]
1270 case 59640: // Underbelly Elixir
1272 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1273 return;
1275 uint32 spell_id = 0;
1276 switch(urand(1,3))
1278 case 1: spell_id = 59645; break;
1279 case 2: spell_id = 59831; break;
1280 case 3: spell_id = 59843; break;
1282 m_caster->CastSpell(m_caster,spell_id,true,NULL);
1283 return;
1285 case 60932: // Disengage (one from creature versions)
1286 if (!unitTarget)
1287 return;
1288 m_caster->CastSpell(unitTarget,60934,true,NULL);
1289 return;
1290 case 67019: // Flask of the North
1292 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1293 return;
1295 uint32 spell_id = 0;
1296 switch(m_caster->getClass())
1298 case CLASS_WARRIOR:
1299 case CLASS_DEATH_KNIGHT:
1300 spell_id = 67018; // STR for Warriors, Death Knights
1301 break;
1302 case CLASS_ROGUE:
1303 case CLASS_HUNTER:
1304 spell_id = 67017; // AP for Rogues, Hunters
1305 break;
1306 case CLASS_PRIEST:
1307 case CLASS_MAGE:
1308 case CLASS_WARLOCK:
1309 spell_id = 67016; // SPD for Priests, Mages, Warlocks
1310 break;
1311 case CLASS_SHAMAN:
1312 // random (SPD, AP)
1313 spell_id = roll_chance_i(50) ? 67016 : 67017;
1314 break;
1315 case CLASS_PALADIN:
1316 case CLASS_DRUID:
1317 default:
1318 // random (SPD, STR)
1319 spell_id = roll_chance_i(50) ? 67016 : 67018;
1320 break;
1322 m_caster->CastSpell(m_caster, spell_id, true);
1323 return;
1326 break;
1328 case SPELLFAMILY_MAGE:
1329 switch(m_spellInfo->Id )
1331 case 11958: // Cold Snap
1333 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1334 return;
1336 // immediately finishes the cooldown on Frost spells
1337 const SpellCooldowns& cm = ((Player *)m_caster)->GetSpellCooldownMap();
1338 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1340 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1342 if (spellInfo->SpellFamilyName == SPELLFAMILY_MAGE &&
1343 (GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_FROST) &&
1344 spellInfo->Id != 11958 && GetSpellRecoveryTime(spellInfo) > 0)
1346 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first, true);
1348 else
1349 ++itr;
1351 return;
1353 case 32826: // Polymorph Cast Visual
1355 if (unitTarget && unitTarget->GetTypeId() == TYPEID_UNIT)
1357 //Polymorph Cast Visual Rank 1
1358 const uint32 spell_list[6] = {
1359 32813, // Squirrel Form
1360 32816, // Giraffe Form
1361 32817, // Serpent Form
1362 32818, // Dragonhawk Form
1363 32819, // Worgen Form
1364 32820 // Sheep Form
1366 unitTarget->CastSpell( unitTarget, spell_list[urand(0, 5)], true);
1368 return;
1371 break;
1372 case SPELLFAMILY_WARRIOR:
1373 // Charge
1374 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x1)) && m_spellInfo->SpellVisual[0] == 867)
1376 int32 chargeBasePoints0 = damage;
1377 m_caster->CastCustomSpell(m_caster, 34846, &chargeBasePoints0, NULL, NULL, true);
1378 return;
1380 // Execute
1381 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x20000000))
1383 if(!unitTarget)
1384 return;
1386 uint32 rage = m_caster->GetPower(POWER_RAGE);
1388 // up to max 30 rage cost
1389 if(rage > 300)
1390 rage = 300;
1392 // Glyph of Execution bonus
1393 uint32 rage_modified = rage;
1395 if (Aura *aura = m_caster->GetDummyAura(58367))
1396 rage_modified += aura->GetModifier()->m_amount*10;
1398 int32 basePoints0 = damage+int32(rage_modified * m_spellInfo->DmgMultiplier[i] +
1399 m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.2f);
1401 m_caster->CastCustomSpell(unitTarget, 20647, &basePoints0, NULL, NULL, true, 0);
1403 // Sudden Death
1404 if(m_caster->HasAura(52437))
1406 Unit::AuraList const& auras = m_caster->GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL);
1407 for (Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
1409 // Only Sudden Death have this SpellIconID with SPELL_AURA_PROC_TRIGGER_SPELL
1410 if ((*itr)->GetSpellProto()->SpellIconID == 1989)
1412 // saved rage top stored in next affect
1413 uint32 lastrage = (*itr)->GetSpellProto()->CalculateSimpleValue(1)*10;
1414 if(lastrage < rage)
1415 rage -= lastrage;
1416 break;
1421 m_caster->SetPower(POWER_RAGE,m_caster->GetPower(POWER_RAGE)-rage);
1422 return;
1424 // Slam
1425 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000200000))
1427 if(!unitTarget)
1428 return;
1429 m_damage+=m_caster->CalculateDamage(m_attackType, false);
1430 m_damage+=damage;
1431 return;
1433 // Concussion Blow
1434 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000004000000))
1436 m_damage+= uint32(damage * m_caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
1437 return;
1440 switch(m_spellInfo->Id)
1442 // Warrior's Wrath
1443 case 21977:
1445 if (!unitTarget)
1446 return;
1447 m_caster->CastSpell(unitTarget, 21887, true);// spell mod
1448 return;
1450 // Last Stand
1451 case 12975:
1453 int32 healthModSpellBasePoints0 = int32(m_caster->GetMaxHealth()*0.3);
1454 m_caster->CastCustomSpell(m_caster, 12976, &healthModSpellBasePoints0, NULL, NULL, true, NULL);
1455 return;
1457 // Bloodthirst
1458 case 23881:
1460 m_caster->CastCustomSpell(unitTarget, 23885, &damage, NULL, NULL, true, NULL);
1461 return;
1464 break;
1465 case SPELLFAMILY_WARLOCK:
1466 // Life Tap
1467 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000040000))
1469 // In 303 exist spirit depend
1470 uint32 spirit = uint32(m_caster->GetStat(STAT_SPIRIT));
1471 switch (m_spellInfo->Id)
1473 case 1454: damage+=spirit; break;
1474 case 1455: damage+=spirit*15/10; break;
1475 case 1456: damage+=spirit*2; break;
1476 case 11687: damage+=spirit*25/10; break;
1477 case 11688:
1478 case 11689:
1479 case 27222:
1480 case 57946: damage+=spirit*3; break;
1481 default:
1482 sLog.outError("Spell::EffectDummy: %u Life Tap need set spirit multipler", m_spellInfo->Id);
1483 return;
1485 // Think its not need (also need remove Life Tap from SpellDamageBonus or add new value)
1486 // damage = m_caster->SpellDamageBonus(m_caster, m_spellInfo,uint32(damage > 0 ? damage : 0), SPELL_DIRECT_DAMAGE);
1487 if (unitTarget && (int32(unitTarget->GetHealth()) > damage))
1489 // Shouldn't Appear in Combat Log
1490 unitTarget->ModifyHealth(-damage);
1492 int32 mana = damage;
1493 // Improved Life Tap mod
1494 Unit::AuraList const& auraDummy = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
1495 for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr != auraDummy.end(); ++itr)
1497 if((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (*itr)->GetSpellProto()->SpellIconID == 208)
1498 mana = ((*itr)->GetModifier()->m_amount + 100)* mana / 100;
1500 m_caster->CastCustomSpell(unitTarget, 31818, &mana, NULL, NULL, true);
1502 // Mana Feed
1503 int32 manaFeedVal = 0;
1504 Unit::AuraList const& mod = m_caster->GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER);
1505 for(Unit::AuraList::const_iterator itr = mod.begin(); itr != mod.end(); ++itr)
1507 if((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (*itr)->GetSpellProto()->SpellIconID == 1982)
1508 manaFeedVal+= (*itr)->GetModifier()->m_amount;
1510 if (manaFeedVal > 0)
1512 manaFeedVal = manaFeedVal * mana / 100;
1513 m_caster->CastCustomSpell(m_caster, 32553, &manaFeedVal, NULL, NULL, true, NULL);
1516 else
1517 SendCastResult(SPELL_FAILED_FIZZLE);
1518 return;
1520 break;
1521 case SPELLFAMILY_PRIEST:
1522 // Penance
1523 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0080000000000000))
1525 if (!unitTarget)
1526 return;
1528 int hurt = 0;
1529 int heal = 0;
1530 switch(m_spellInfo->Id)
1532 case 47540: hurt = 47758; heal = 47757; break;
1533 case 53005: hurt = 53001; heal = 52986; break;
1534 case 53006: hurt = 53002; heal = 52987; break;
1535 case 53007: hurt = 53003; heal = 52988; break;
1536 default:
1537 sLog.outError("Spell::EffectDummy: Spell %u Penance need set correct heal/damage spell", m_spellInfo->Id);
1538 return;
1540 if (m_caster->IsFriendlyTo(unitTarget))
1541 m_caster->CastSpell(unitTarget, heal, true, 0);
1542 else
1543 m_caster->CastSpell(unitTarget, hurt, true, 0);
1544 return;
1546 break;
1547 case SPELLFAMILY_DRUID:
1548 // Starfall
1549 if (m_spellInfo->SpellFamilyFlags2 & UI64LIT(0x00000100))
1551 //Shapeshifting into an animal form or mounting cancels the effect.
1552 if(m_caster->GetCreatureType() == CREATURE_TYPE_BEAST || m_caster->IsMounted())
1554 if(m_triggeredByAuraSpell)
1555 m_caster->RemoveAurasDueToSpell(m_triggeredByAuraSpell->Id);
1556 return;
1559 //Any effect which causes you to lose control of your character will supress the starfall effect.
1560 if (m_caster->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_FLEEING | UNIT_STAT_ROOT | UNIT_STAT_CONFUSED))
1561 return;
1563 switch(m_spellInfo->Id)
1565 case 50286: m_caster->CastSpell(unitTarget, 50288, true); return;
1566 case 53196: m_caster->CastSpell(unitTarget, 53191, true); return;
1567 case 53197: m_caster->CastSpell(unitTarget, 53194, true); return;
1568 case 53198: m_caster->CastSpell(unitTarget, 53195, true); return;
1569 default:
1570 sLog.outError("Spell::EffectDummy: Unhandeled Starfall spell rank %u",m_spellInfo->Id);
1571 return;
1574 break;
1575 case SPELLFAMILY_ROGUE:
1576 switch(m_spellInfo->Id )
1578 case 5938: // Shiv
1580 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1581 return;
1583 Player *pCaster = ((Player*)m_caster);
1585 Item *item = pCaster->GetWeaponForAttack(OFF_ATTACK);
1586 if (!item)
1587 return;
1589 // all poison enchantments is temporary
1590 uint32 enchant_id = item->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT);
1591 if (!enchant_id)
1592 return;
1594 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
1595 if (!pEnchant)
1596 return;
1598 for (int s=0;s<3;s++)
1600 if (pEnchant->type[s]!=ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL)
1601 continue;
1603 SpellEntry const* combatEntry = sSpellStore.LookupEntry(pEnchant->spellid[s]);
1604 if (!combatEntry || combatEntry->Dispel != DISPEL_POISON)
1605 continue;
1607 m_caster->CastSpell(unitTarget, combatEntry, true, item);
1610 m_caster->CastSpell(unitTarget, 5940, true);
1611 return;
1613 case 14185: // Preparation
1615 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1616 return;
1618 //immediately finishes the cooldown on certain Rogue abilities
1619 const SpellCooldowns& cm = ((Player *)m_caster)->GetSpellCooldownMap();
1620 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1622 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1624 if (spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && (spellInfo->SpellFamilyFlags & UI64LIT(0x0000024000000860)))
1625 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first,true);
1626 else
1627 ++itr;
1629 return;
1631 case 31231: // Cheat Death
1633 m_caster->CastSpell(m_caster, 45182, true);
1634 return;
1637 break;
1638 case SPELLFAMILY_HUNTER:
1639 // Steady Shot
1640 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x100000000))
1642 if (!unitTarget || !unitTarget->isAlive())
1643 return;
1645 bool found = false;
1647 // check dazed affect
1648 Unit::AuraList const& decSpeedList = unitTarget->GetAurasByType(SPELL_AURA_MOD_DECREASE_SPEED);
1649 for(Unit::AuraList::const_iterator iter = decSpeedList.begin(); iter != decSpeedList.end(); ++iter)
1651 if ((*iter)->GetSpellProto()->SpellIconID==15 && (*iter)->GetSpellProto()->Dispel==0)
1653 found = true;
1654 break;
1658 if (found)
1659 m_damage+= damage;
1660 return;
1663 // Disengage
1664 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000400000000000))
1666 Unit* target = unitTarget;
1667 uint32 spellid;
1668 switch(m_spellInfo->Id)
1670 case 57635: spellid = 57636; break; // one from creature cases
1671 case 61507: spellid = 61508; break; // one from creature cases
1672 default:
1673 sLog.outError("Spell %u not handled propertly in EffectDummy(Disengage)",m_spellInfo->Id);
1674 return;
1676 if (!target || !target->isAlive())
1677 return;
1678 m_caster->CastSpell(target,spellid,true,NULL);
1681 switch(m_spellInfo->Id)
1683 case 23989: // Readiness talent
1685 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1686 return;
1688 //immediately finishes the cooldown for hunter abilities
1689 const SpellCooldowns& cm = ((Player*)m_caster)->GetSpellCooldownMap();
1690 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1692 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1694 if (spellInfo->SpellFamilyName == SPELLFAMILY_HUNTER && spellInfo->Id != 23989 && GetSpellRecoveryTime(spellInfo) > 0 )
1695 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first,true);
1696 else
1697 ++itr;
1699 return;
1701 case 37506: // Scatter Shot
1703 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1704 return;
1706 // break Auto Shot and autohit
1707 m_caster->InterruptSpell(CURRENT_AUTOREPEAT_SPELL);
1708 m_caster->AttackStop();
1709 ((Player*)m_caster)->SendAttackSwingCancelAttack();
1710 return;
1712 // Last Stand
1713 case 53478:
1715 if (!unitTarget)
1716 return;
1717 int32 healthModSpellBasePoints0 = int32(unitTarget->GetMaxHealth() * 0.3);
1718 unitTarget->CastCustomSpell(unitTarget, 53479, &healthModSpellBasePoints0, NULL, NULL, true, NULL);
1719 return;
1721 // Master's Call
1722 case 53271:
1724 Pet* pet = m_caster->GetPet();
1725 if (!pet || !unitTarget)
1726 return;
1728 pet->CastSpell(unitTarget, m_spellInfo->CalculateSimpleValue(i), true);
1729 return;
1732 break;
1733 case SPELLFAMILY_PALADIN:
1734 switch(m_spellInfo->SpellIconID)
1736 case 156: // Holy Shock
1738 if (!unitTarget)
1739 return;
1741 int hurt = 0;
1742 int heal = 0;
1744 switch(m_spellInfo->Id)
1746 case 20473: hurt = 25912; heal = 25914; break;
1747 case 20929: hurt = 25911; heal = 25913; break;
1748 case 20930: hurt = 25902; heal = 25903; break;
1749 case 27174: hurt = 27176; heal = 27175; break;
1750 case 33072: hurt = 33073; heal = 33074; break;
1751 case 48824: hurt = 48822; heal = 48820; break;
1752 case 48825: hurt = 48823; heal = 48821; break;
1753 default:
1754 sLog.outError("Spell::EffectDummy: Spell %u not handled in HS",m_spellInfo->Id);
1755 return;
1758 if (m_caster->IsFriendlyTo(unitTarget))
1759 m_caster->CastSpell(unitTarget, heal, true, 0);
1760 else
1761 m_caster->CastSpell(unitTarget, hurt, true, 0);
1763 return;
1765 case 561: // Judgement of command
1767 if (!unitTarget)
1768 return;
1770 uint32 spell_id = m_currentBasePoints[i]+1;
1771 SpellEntry const* spell_proto = sSpellStore.LookupEntry(spell_id);
1772 if (!spell_proto)
1773 return;
1775 m_caster->CastSpell(unitTarget, spell_proto, true, NULL);
1776 return;
1780 switch(m_spellInfo->Id)
1782 // Judgement of Righteousness (0.2*$AP+0.32*$SPH) holy added in spellDamagBonus
1783 case 20187:
1785 if (!unitTarget)
1786 return;
1787 m_damage+=int32(0.2f*m_caster->GetTotalAttackPowerValue(BASE_ATTACK));
1788 return;
1790 case 31789: // Righteous Defense (step 1)
1792 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1794 SendCastResult(SPELL_FAILED_TARGET_AFFECTING_COMBAT);
1795 return;
1798 // 31989 -> dummy effect (step 1) + dummy effect (step 2) -> 31709 (taunt like spell for each target)
1799 Unit* friendTarget = !unitTarget || unitTarget->IsFriendlyTo(m_caster) ? unitTarget : unitTarget->getVictim();
1800 if (friendTarget)
1802 Player* player = friendTarget->GetCharmerOrOwnerPlayerOrPlayerItself();
1803 if (!player || !player->IsInSameRaidWith((Player*)m_caster))
1804 friendTarget = NULL;
1807 // non-standard cast requirement check
1808 if (!friendTarget || friendTarget->getAttackers().empty())
1810 ((Player*)m_caster)->RemoveSpellCooldown(m_spellInfo->Id,true);
1811 SendCastResult(SPELL_FAILED_TARGET_AFFECTING_COMBAT);
1812 return;
1815 // Righteous Defense (step 2) (in old version 31980 dummy effect)
1816 // Clear targets for eff 1
1817 for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit)
1818 ihit->effectMask &= ~(1<<1);
1820 // not empty (checked), copy
1821 Unit::AttackerSet attackers = friendTarget->getAttackers();
1823 // selected from list 3
1824 for(int i = 0; i < std::min(size_t(3),attackers.size()); ++i)
1826 Unit::AttackerSet::iterator aItr = attackers.begin();
1827 std::advance(aItr, rand() % attackers.size());
1828 AddUnitTarget((*aItr), 1);
1829 attackers.erase(aItr);
1832 // now let next effect cast spell at each target.
1833 return;
1835 case 37877: // Blessing of Faith
1837 if (!unitTarget)
1838 return;
1840 uint32 spell_id = 0;
1841 switch(unitTarget->getClass())
1843 case CLASS_DRUID: spell_id = 37878; break;
1844 case CLASS_PALADIN: spell_id = 37879; break;
1845 case CLASS_PRIEST: spell_id = 37880; break;
1846 case CLASS_SHAMAN: spell_id = 37881; break;
1847 default: return; // ignore for not healing classes
1850 m_caster->CastSpell(m_caster, spell_id, true);
1851 return;
1854 break;
1855 case SPELLFAMILY_SHAMAN:
1856 // Cleansing Totem
1857 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000004000000)) && m_spellInfo->SpellIconID==1673)
1859 if (unitTarget)
1860 m_caster->CastSpell(unitTarget, 52025, true);
1861 return;
1863 // Healing Stream Totem
1864 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000002000))
1866 if (unitTarget)
1867 m_caster->CastCustomSpell(unitTarget, 52042, &damage, 0, 0, true, 0, 0, m_originalCasterGUID);
1868 return;
1870 // Mana Spring Totem
1871 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000004000))
1873 if (!unitTarget || unitTarget->getPowerType()!=POWER_MANA)
1874 return;
1875 m_caster->CastCustomSpell(unitTarget, 52032, &damage, 0, 0, true, 0, 0, m_originalCasterGUID);
1876 return;
1878 if (m_spellInfo->Id == 39610) // Mana Tide Totem effect
1880 if (!unitTarget || unitTarget->getPowerType() != POWER_MANA)
1881 return;
1882 // Glyph of Mana Tide
1883 if (Unit *owner = m_caster->GetOwner())
1884 if (Aura *dummy = owner->GetDummyAura(55441))
1885 damage+=dummy->GetModifier()->m_amount;
1886 // Regenerate 6% of Total Mana Every 3 secs
1887 int32 EffectBasePoints0 = unitTarget->GetMaxPower(POWER_MANA) * damage / 100;
1888 m_caster->CastCustomSpell(unitTarget, 39609, &EffectBasePoints0, NULL, NULL, true, NULL, NULL, m_originalCasterGUID);
1889 return;
1891 // Lava Lash
1892 if (m_spellInfo->SpellFamilyFlags2 & 0x00000004)
1894 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1895 return;
1896 Item *item = ((Player*)m_caster)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND);
1897 if (item)
1899 // Damage is increased if your off-hand weapon is enchanted with Flametongue.
1900 Unit::AuraList const& auraDummy = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
1901 for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr != auraDummy.end(); ++itr)
1903 if ((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_SHAMAN &&
1904 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000200000)) &&
1905 (*itr)->GetCastItemGUID() == item->GetGUID())
1907 m_damage += m_damage * damage / 100;
1908 return;
1912 return;
1914 break;
1915 case SPELLFAMILY_DEATHKNIGHT:
1916 // Death Coil
1917 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x002000))
1919 if (m_caster->IsFriendlyTo(unitTarget))
1921 if (unitTarget->GetCreatureType() != CREATURE_TYPE_UNDEAD)
1922 return;
1924 int32 bp = damage * 1.5f;
1925 m_caster->CastCustomSpell(unitTarget, 47633, &bp, NULL, NULL, true);
1927 else
1929 int32 bp = damage;
1930 m_caster->CastCustomSpell(unitTarget, 47632, &bp, NULL, NULL, true);
1932 return;
1934 // Hungering Cold
1935 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000100000000000))
1937 m_caster->CastSpell(m_caster, 51209, true);
1938 return;
1940 // Death Strike
1941 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000010))
1943 uint32 count = 0;
1944 Unit::AuraMap const& auras = unitTarget->GetAuras();
1945 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
1947 if (itr->second->GetSpellProto()->Dispel == DISPEL_DISEASE &&
1948 itr->second->GetCasterGUID() == m_caster->GetGUID() &&
1949 IsSpellLastAuraEffect(itr->second->GetSpellProto(), itr->second->GetEffIndex()))
1951 ++count;
1952 // max. 15%
1953 if (count == 3)
1954 break;
1958 int32 bp = count * m_caster->GetMaxHealth() * m_spellInfo->DmgMultiplier[0] / 100;
1959 m_caster->CastCustomSpell(m_caster, 45470, &bp, NULL, NULL, true);
1960 return;
1962 break;
1965 // pet auras
1966 if (PetAura const* petSpell = sSpellMgr.GetPetAura(m_spellInfo->Id, i))
1968 m_caster->AddPetAura(petSpell);
1969 return;
1972 // Script based implementation. Must be used only for not good for implementation in core spell effects
1973 // So called only for not proccessed cases
1974 if (gameObjTarget)
1975 Script->EffectDummyGameObj(m_caster, m_spellInfo->Id, i, gameObjTarget);
1976 else if (unitTarget && unitTarget->GetTypeId()==TYPEID_UNIT)
1977 Script->EffectDummyCreature(m_caster, m_spellInfo->Id, i, (Creature*)unitTarget);
1978 else if (itemTarget)
1979 Script->EffectDummyItem(m_caster, m_spellInfo->Id, i, itemTarget);
1982 void Spell::EffectTriggerSpellWithValue(uint32 i)
1984 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
1986 // normal case
1987 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
1989 if(!spellInfo)
1991 sLog.outError("EffectTriggerSpellWithValue of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
1992 return;
1995 int32 bp = damage;
1996 m_caster->CastCustomSpell(unitTarget,triggered_spell_id,&bp,&bp,&bp,true,NULL,NULL,m_originalCasterGUID);
1999 void Spell::EffectTriggerRitualOfSummoning(uint32 i)
2001 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2002 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2004 if(!spellInfo)
2006 sLog.outError("EffectTriggerRitualOfSummoning of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2007 return;
2010 finish();
2012 m_caster->CastSpell(unitTarget,spellInfo,false);
2015 void Spell::EffectForceCast(uint32 i)
2017 if( !unitTarget )
2018 return;
2020 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2022 // normal case
2023 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2025 if(!spellInfo)
2027 sLog.outError("EffectForceCast of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2028 return;
2031 unitTarget->CastSpell(unitTarget, spellInfo, true, NULL, NULL, m_originalCasterGUID);
2034 void Spell::EffectTriggerSpell(uint32 effIndex)
2036 // only unit case known
2037 if (!unitTarget)
2039 if(gameObjTarget || itemTarget)
2040 sLog.outError("Spell::EffectTriggerSpell (Spell: %u): Unsupported non-unit case!",m_spellInfo->Id);
2041 return;
2044 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[effIndex];
2046 // special cases
2047 switch(triggered_spell_id)
2049 // Vanish (not exist)
2050 case 18461:
2052 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2053 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
2054 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STALKED);
2056 // if this spell is given to NPC it must handle rest by it's own AI
2057 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
2058 return;
2060 // get highest rank of the Stealth spell
2061 uint32 spellId = 0;
2062 const PlayerSpellMap& sp_list = ((Player*)unitTarget)->GetSpellMap();
2063 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2065 // only highest rank is shown in spell book, so simply check if shown in spell book
2066 if (!itr->second->active || itr->second->disabled || itr->second->state == PLAYERSPELL_REMOVED)
2067 continue;
2069 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2070 if (!spellInfo)
2071 continue;
2073 if (spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE_STEALTH)
2075 spellId = spellInfo->Id;
2076 break;
2080 // no Stealth spell found
2081 if (!spellId)
2082 return;
2084 // reset cooldown on it if needed
2085 if (((Player*)unitTarget)->HasSpellCooldown(spellId))
2086 ((Player*)unitTarget)->RemoveSpellCooldown(spellId);
2088 m_caster->CastSpell(unitTarget, spellId, true);
2089 return;
2091 // just skip
2092 case 23770: // Sayge's Dark Fortune of *
2093 // not exist, common cooldown can be implemented in scripts if need.
2094 return;
2095 // Brittle Armor - (need add max stack of 24575 Brittle Armor)
2096 case 29284:
2098 // Brittle Armor
2099 SpellEntry const* spell = sSpellStore.LookupEntry(24575);
2100 if (!spell)
2101 return;
2103 for (int j=0; j < spell->StackAmount; ++j)
2104 m_caster->CastSpell(unitTarget, spell->Id, true, m_CastItem, NULL, m_originalCasterGUID);
2105 return;
2107 // Mercurial Shield - (need add max stack of 26464 Mercurial Shield)
2108 case 29286:
2110 // Mercurial Shield
2111 SpellEntry const* spell = sSpellStore.LookupEntry(26464);
2112 if (!spell)
2113 return;
2115 for (int j=0; j < spell->StackAmount; ++j)
2116 m_caster->CastSpell(unitTarget, spell->Id, true, m_CastItem, NULL, m_originalCasterGUID);
2117 return;
2119 // Righteous Defense
2120 case 31980:
2122 m_caster->CastSpell(unitTarget, 31790, true, m_CastItem, NULL, m_originalCasterGUID);
2123 return;
2125 // Cloak of Shadows
2126 case 35729:
2128 Unit::AuraMap& Auras = unitTarget->GetAuras();
2129 for(Unit::AuraMap::iterator iter = Auras.begin(); iter != Auras.end(); ++iter)
2131 // remove all harmful spells on you...
2132 if( // ignore positive and passive auras
2133 !iter->second->IsPositive() && !iter->second->IsPassive() &&
2134 // ignore physical auras
2135 (GetSpellSchoolMask(iter->second->GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)==0 )
2137 m_caster->RemoveAurasDueToSpell(iter->second->GetSpellProto()->Id);
2138 iter = Auras.begin();
2141 return;
2143 // Priest Shadowfiend (34433) need apply mana gain trigger aura on pet
2144 case 41967:
2146 if (Unit *pet = unitTarget->GetPet())
2147 pet->CastSpell(pet, 28305, true);
2148 return;
2152 // normal case
2153 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2154 if (!spellInfo)
2156 sLog.outError("EffectTriggerSpell of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2157 return;
2160 // select formal caster for triggered spell
2161 Unit* caster = m_caster;
2163 // some triggered spells require specific equipment
2164 if (spellInfo->EquippedItemClass >=0 && m_caster->GetTypeId()==TYPEID_PLAYER)
2166 // main hand weapon required
2167 if (spellInfo->AttributesEx3 & SPELL_ATTR_EX3_MAIN_HAND)
2169 Item* item = ((Player*)m_caster)->GetWeaponForAttack(BASE_ATTACK, true, false);
2171 // skip spell if no weapon in slot or broken
2172 if (!item)
2173 return;
2175 // skip spell if weapon not fit to triggered spell
2176 if (!item->IsFitToSpellRequirements(spellInfo))
2177 return;
2180 // offhand hand weapon required
2181 if (spellInfo->AttributesEx3 & SPELL_ATTR_EX3_REQ_OFFHAND)
2183 Item* item = ((Player*)m_caster)->GetWeaponForAttack(OFF_ATTACK, true, false);
2185 // skip spell if no weapon in slot or broken
2186 if (!item)
2187 return;
2189 // skip spell if weapon not fit to triggered spell
2190 if (!item->IsFitToSpellRequirements(spellInfo))
2191 return;
2194 else
2196 // Note: not exist spells with weapon req. and IsSpellHaveCasterSourceTargets == true
2197 // so this just for speedup places in else
2198 caster = IsSpellWithCasterSourceTargetsOnly(spellInfo) ? unitTarget : m_caster;
2201 caster->CastSpell(unitTarget,spellInfo,true,NULL,NULL,m_originalCasterGUID);
2204 void Spell::EffectTriggerMissileSpell(uint32 effect_idx)
2206 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[effect_idx];
2208 // normal case
2209 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2211 if(!spellInfo)
2213 sLog.outError("EffectTriggerMissileSpell of spell %u (eff: %u): triggering unknown spell id %u",
2214 m_spellInfo->Id,effect_idx,triggered_spell_id);
2215 return;
2218 if (m_CastItem)
2219 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id);
2221 m_caster->CastSpell(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, spellInfo, true, m_CastItem, 0, m_originalCasterGUID);
2224 void Spell::EffectJump(uint32 i)
2226 if(m_caster->isInFlight())
2227 return;
2229 // Init dest coordinates
2230 float x,y,z,o;
2231 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
2233 x = m_targets.m_destX;
2234 y = m_targets.m_destY;
2235 z = m_targets.m_destZ;
2237 if(m_spellInfo->EffectImplicitTargetA[i] == TARGET_BEHIND_VICTIM)
2239 // explicit cast data from client or server-side cast
2240 // some spell at client send caster
2241 Unit* pTarget = NULL;
2242 if(m_targets.getUnitTarget() && m_targets.getUnitTarget()!=m_caster)
2243 pTarget = m_targets.getUnitTarget();
2244 else if(unitTarget->getVictim())
2245 pTarget = m_caster->getVictim();
2246 else if(m_caster->GetTypeId() == TYPEID_PLAYER)
2247 pTarget = ObjectAccessor::GetUnit(*m_caster, ((Player*)m_caster)->GetSelection());
2249 o = pTarget ? pTarget->GetOrientation() : m_caster->GetOrientation();
2251 else
2252 o = m_caster->GetOrientation();
2254 else if(unitTarget)
2256 unitTarget->GetContactPoint(m_caster,x,y,z,CONTACT_DISTANCE);
2257 o = m_caster->GetOrientation();
2259 else if(gameObjTarget)
2261 gameObjTarget->GetContactPoint(m_caster,x,y,z,CONTACT_DISTANCE);
2262 o = m_caster->GetOrientation();
2264 else
2266 sLog.outError( "Spell::EffectJump - unsupported target mode for spell ID %u", m_spellInfo->Id );
2267 return;
2270 m_caster->NearTeleportTo(x, y, z, o, true);
2273 void Spell::EffectTeleportUnits(uint32 i)
2275 if(!unitTarget || unitTarget->isInFlight())
2276 return;
2278 switch (m_spellInfo->EffectImplicitTargetB[i])
2280 case TARGET_INNKEEPER_COORDINATES:
2282 // Only players can teleport to innkeeper
2283 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
2284 return;
2286 ((Player*)unitTarget)->TeleportToHomebind(unitTarget==m_caster ? TELE_TO_SPELL : 0);
2287 return;
2289 case TARGET_AREAEFFECT_INSTANT: // in all cases first TARGET_TABLE_X_Y_Z_COORDINATES
2290 case TARGET_TABLE_X_Y_Z_COORDINATES:
2292 SpellTargetPosition const* st = sSpellMgr.GetSpellTargetPosition(m_spellInfo->Id);
2293 if(!st)
2295 sLog.outError( "Spell::EffectTeleportUnits - unknown Teleport coordinates for spell ID %u", m_spellInfo->Id );
2296 return;
2299 if(st->target_mapId==unitTarget->GetMapId())
2300 unitTarget->NearTeleportTo(st->target_X,st->target_Y,st->target_Z,st->target_Orientation,unitTarget==m_caster);
2301 else if(unitTarget->GetTypeId()==TYPEID_PLAYER)
2302 ((Player*)unitTarget)->TeleportTo(st->target_mapId,st->target_X,st->target_Y,st->target_Z,st->target_Orientation,unitTarget==m_caster ? TELE_TO_SPELL : 0);
2303 break;
2305 case TARGET_BEHIND_VICTIM:
2307 Unit *pTarget = NULL;
2309 // explicit cast data from client or server-side cast
2310 // some spell at client send caster
2311 if(m_targets.getUnitTarget() && m_targets.getUnitTarget()!=unitTarget)
2312 pTarget = m_targets.getUnitTarget();
2313 else if(unitTarget->getVictim())
2314 pTarget = unitTarget->getVictim();
2315 else if(unitTarget->GetTypeId() == TYPEID_PLAYER)
2316 pTarget = ObjectAccessor::GetUnit(*unitTarget, ((Player*)unitTarget)->GetSelection());
2318 // Init dest coordinates
2319 float x = m_targets.m_destX;
2320 float y = m_targets.m_destY;
2321 float z = m_targets.m_destZ;
2322 float orientation = pTarget ? pTarget->GetOrientation() : unitTarget->GetOrientation();
2323 unitTarget->NearTeleportTo(x,y,z,orientation,unitTarget==m_caster);
2324 return;
2326 default:
2328 // If not exist data for dest location - return
2329 if(!(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION))
2331 sLog.outError( "Spell::EffectTeleportUnits - unknown EffectImplicitTargetB[%u] = %u for spell ID %u", i, m_spellInfo->EffectImplicitTargetB[i], m_spellInfo->Id );
2332 return;
2334 // Init dest coordinates
2335 float x = m_targets.m_destX;
2336 float y = m_targets.m_destY;
2337 float z = m_targets.m_destZ;
2338 float orientation = unitTarget->GetOrientation();
2339 // Teleport
2340 unitTarget->NearTeleportTo(x,y,z,orientation,unitTarget==m_caster);
2341 return;
2345 // post effects for TARGET_TABLE_X_Y_Z_COORDINATES
2346 switch ( m_spellInfo->Id )
2348 // Dimensional Ripper - Everlook
2349 case 23442:
2351 int32 r = irand(0, 119);
2352 if ( r >= 70 ) // 7/12 success
2354 if ( r < 100 ) // 4/12 evil twin
2355 m_caster->CastSpell(m_caster, 23445, true);
2356 else // 1/12 fire
2357 m_caster->CastSpell(m_caster, 23449, true);
2359 return;
2361 // Ultrasafe Transporter: Toshley's Station
2362 case 36941:
2364 if ( roll_chance_i(50) ) // 50% success
2366 int32 rand_eff = urand(1, 7);
2367 switch ( rand_eff )
2369 case 1:
2370 // soul split - evil
2371 m_caster->CastSpell(m_caster, 36900, true);
2372 break;
2373 case 2:
2374 // soul split - good
2375 m_caster->CastSpell(m_caster, 36901, true);
2376 break;
2377 case 3:
2378 // Increase the size
2379 m_caster->CastSpell(m_caster, 36895, true);
2380 break;
2381 case 4:
2382 // Decrease the size
2383 m_caster->CastSpell(m_caster, 36893, true);
2384 break;
2385 case 5:
2386 // Transform
2388 if (((Player*)m_caster)->GetTeam() == ALLIANCE )
2389 m_caster->CastSpell(m_caster, 36897, true);
2390 else
2391 m_caster->CastSpell(m_caster, 36899, true);
2392 break;
2394 case 6:
2395 // chicken
2396 m_caster->CastSpell(m_caster, 36940, true);
2397 break;
2398 case 7:
2399 // evil twin
2400 m_caster->CastSpell(m_caster, 23445, true);
2401 break;
2404 return;
2406 // Dimensional Ripper - Area 52
2407 case 36890:
2409 if ( roll_chance_i(50) ) // 50% success
2411 int32 rand_eff = urand(1, 4);
2412 switch ( rand_eff )
2414 case 1:
2415 // soul split - evil
2416 m_caster->CastSpell(m_caster, 36900, true);
2417 break;
2418 case 2:
2419 // soul split - good
2420 m_caster->CastSpell(m_caster, 36901, true);
2421 break;
2422 case 3:
2423 // Increase the size
2424 m_caster->CastSpell(m_caster, 36895, true);
2425 break;
2426 case 4:
2427 // Transform
2429 if (((Player*)m_caster)->GetTeam() == ALLIANCE )
2430 m_caster->CastSpell(m_caster, 36897, true);
2431 else
2432 m_caster->CastSpell(m_caster, 36899, true);
2433 break;
2437 return;
2442 void Spell::EffectApplyAura(uint32 i)
2444 if(!unitTarget)
2445 return;
2447 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
2448 if ( (!unitTarget->isAlive() && !(IsDeathOnlySpell(m_spellInfo) || IsDeathPersistentSpell(m_spellInfo))) &&
2449 (unitTarget->GetTypeId() != TYPEID_PLAYER || !((Player*)unitTarget)->GetSession()->PlayerLoading()) )
2450 return;
2452 Unit* caster = m_originalCaster ? m_originalCaster : m_caster;
2453 if(!caster)
2454 return;
2456 sLog.outDebug("Spell: Aura is: %u", m_spellInfo->EffectApplyAuraName[i]);
2458 Aura* Aur = CreateAura(m_spellInfo, i, &m_currentBasePoints[i], unitTarget, caster, m_CastItem);
2460 // Now Reduce spell duration using data received at spell hit
2461 int32 duration = Aur->GetAuraMaxDuration();
2462 int32 limitduration = GetDiminishingReturnsLimitDuration(m_diminishGroup,m_spellInfo);
2463 unitTarget->ApplyDiminishingToDuration(m_diminishGroup, duration, m_caster, m_diminishLevel,limitduration);
2464 Aur->setDiminishGroup(m_diminishGroup);
2466 // if Aura removed and deleted, do not continue.
2467 if(duration== 0 && !(Aur->IsPermanent()))
2469 delete Aur;
2470 return;
2473 if(duration != Aur->GetAuraMaxDuration())
2475 Aur->SetAuraMaxDuration(duration);
2476 Aur->SetAuraDuration(duration);
2479 unitTarget->AddAura(Aur);
2482 void Spell::EffectUnlearnSpecialization( uint32 i )
2484 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
2485 return;
2487 Player *_player = (Player*)unitTarget;
2488 uint32 spellToUnlearn = m_spellInfo->EffectTriggerSpell[i];
2490 _player->removeSpell(spellToUnlearn);
2492 sLog.outDebug( "Spell: Player %u has unlearned spell %u from NpcGUID: %u", _player->GetGUIDLow(), spellToUnlearn, m_caster->GetGUIDLow() );
2495 void Spell::EffectPowerDrain(uint32 i)
2497 if(m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2498 return;
2500 Powers drain_power = Powers(m_spellInfo->EffectMiscValue[i]);
2502 if(!unitTarget)
2503 return;
2504 if(!unitTarget->isAlive())
2505 return;
2506 if(unitTarget->getPowerType() != drain_power)
2507 return;
2508 if(damage < 0)
2509 return;
2511 uint32 curPower = unitTarget->GetPower(drain_power);
2513 //add spell damage bonus
2514 damage=m_caster->SpellDamageBonus(unitTarget,m_spellInfo,uint32(damage),SPELL_DIRECT_DAMAGE);
2516 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
2517 uint32 power = damage;
2518 if (drain_power == POWER_MANA)
2519 power -= unitTarget->GetSpellCritDamageReduction(power);
2521 int32 new_damage;
2522 if(curPower < power)
2523 new_damage = curPower;
2524 else
2525 new_damage = power;
2527 unitTarget->ModifyPower(drain_power,-new_damage);
2529 // Don`t restore from self drain
2530 if(drain_power == POWER_MANA && m_caster != unitTarget)
2532 float manaMultiplier = m_spellInfo->EffectMultipleValue[i];
2533 if(manaMultiplier==0)
2534 manaMultiplier = 1;
2536 if(Player *modOwner = m_caster->GetSpellModOwner())
2537 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, manaMultiplier);
2539 int32 gain = int32(new_damage * manaMultiplier);
2541 m_caster->EnergizeBySpell(m_caster, m_spellInfo->Id, gain, POWER_MANA);
2545 void Spell::EffectSendEvent(uint32 EffectIndex)
2548 we do not handle a flag dropping or clicking on flag in battleground by sendevent system
2550 sLog.outDebug("Spell ScriptStart %u for spellid %u in EffectSendEvent ", m_spellInfo->EffectMiscValue[EffectIndex], m_spellInfo->Id);
2551 m_caster->GetMap()->ScriptsStart(sEventScripts, m_spellInfo->EffectMiscValue[EffectIndex], m_caster, focusObject);
2554 void Spell::EffectPowerBurn(uint32 i)
2556 if (m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2557 return;
2559 Powers powertype = Powers(m_spellInfo->EffectMiscValue[i]);
2561 if (!unitTarget)
2562 return;
2563 if (!unitTarget->isAlive())
2564 return;
2565 if (unitTarget->getPowerType()!=powertype)
2566 return;
2567 if (damage < 0)
2568 return;
2570 // burn x% of target's mana, up to maximum of 2x% of caster's mana (Mana Burn)
2571 if (m_spellInfo->ManaCostPercentage)
2573 uint32 maxdamage = m_caster->GetMaxPower(powertype) * damage * 2 / 100;
2574 damage = unitTarget->GetMaxPower(powertype) * damage / 100;
2575 if(damage > maxdamage) damage = maxdamage;
2578 int32 curPower = int32(unitTarget->GetPower(powertype));
2580 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
2581 uint32 power = damage;
2582 if (powertype == POWER_MANA)
2583 power -= unitTarget->GetSpellCritDamageReduction(power);
2585 int32 new_damage = (curPower < power) ? curPower : power;
2587 unitTarget->ModifyPower(powertype, -new_damage);
2588 float multiplier = m_spellInfo->EffectMultipleValue[i];
2590 if (Player *modOwner = m_caster->GetSpellModOwner())
2591 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
2593 new_damage = int32(new_damage * multiplier);
2594 m_damage += new_damage;
2597 void Spell::EffectHeal( uint32 /*i*/ )
2599 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2601 // Try to get original caster
2602 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2604 // Skip if m_originalCaster not available
2605 if (!caster)
2606 return;
2608 int32 addhealth = damage;
2610 // Vessel of the Naaru (Vial of the Sunwell trinket)
2611 if (m_spellInfo->Id == 45064)
2613 // Amount of heal - depends from stacked Holy Energy
2614 int damageAmount = 0;
2615 Unit::AuraList const& mDummyAuras = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
2616 for(Unit::AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i)
2617 if ((*i)->GetId() == 45062)
2618 damageAmount+=(*i)->GetModifier()->m_amount;
2619 if (damageAmount)
2620 m_caster->RemoveAurasDueToSpell(45062);
2622 addhealth += damageAmount;
2624 // Death Pact (percent heal)
2625 else if (m_spellInfo->Id==48743)
2626 addhealth = addhealth * unitTarget->GetMaxHealth() / 100;
2627 // Swiftmend - consumes Regrowth or Rejuvenation
2628 else if (m_spellInfo->TargetAuraState == AURA_STATE_SWIFTMEND && unitTarget->HasAuraState(AURA_STATE_SWIFTMEND))
2630 Unit::AuraList const& RejorRegr = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_HEAL);
2631 // find most short by duration
2632 Aura *targetAura = NULL;
2633 for(Unit::AuraList::const_iterator i = RejorRegr.begin(); i != RejorRegr.end(); ++i)
2635 if ((*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2636 // Regrowth or Rejuvenation 0x40 | 0x10
2637 ((*i)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000050)))
2639 if (!targetAura || (*i)->GetAuraDuration() < targetAura->GetAuraDuration())
2640 targetAura = *i;
2644 if (!targetAura)
2646 sLog.outError("Target (GUID: %u TypeId: %u) has aurastate AURA_STATE_SWIFTMEND but no matching aura.", unitTarget->GetGUIDLow(), unitTarget->GetTypeId());
2647 return;
2649 int idx = 0;
2650 while(idx < 3)
2652 if(targetAura->GetSpellProto()->EffectApplyAuraName[idx] == SPELL_AURA_PERIODIC_HEAL)
2653 break;
2654 idx++;
2657 int32 tickheal = caster->SpellHealingBonus(unitTarget, targetAura->GetSpellProto(), targetAura->GetModifier()->m_amount, DOT);
2658 int32 tickcount = GetSpellDuration(targetAura->GetSpellProto()) / targetAura->GetSpellProto()->EffectAmplitude[idx];
2660 // Glyph of Swiftmend
2661 if (!caster->HasAura(54824))
2662 unitTarget->RemoveAurasDueToSpell(targetAura->GetId());
2664 addhealth += tickheal * tickcount;
2666 else
2667 addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, addhealth, HEAL);
2669 m_healing+=addhealth;
2673 void Spell::EffectHealPct( uint32 /*i*/ )
2675 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2677 // Try to get original caster
2678 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2680 // Skip if m_originalCaster not available
2681 if (!caster)
2682 return;
2684 uint32 addhealth = unitTarget->GetMaxHealth() * damage / 100;
2685 if (Player* modOwner = m_caster->GetSpellModOwner())
2686 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DAMAGE, addhealth, this);
2688 int32 gain = caster->DealHeal(unitTarget, addhealth, m_spellInfo);
2689 unitTarget->getHostileRefManager().threatAssist(m_caster, float(gain) * 0.5f, m_spellInfo);
2693 void Spell::EffectHealMechanical( uint32 /*i*/ )
2695 // Mechanic creature type should be correctly checked by targetCreatureType field
2696 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2698 // Try to get original caster
2699 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2701 // Skip if m_originalCaster not available
2702 if (!caster)
2703 return;
2705 uint32 addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, uint32(damage), HEAL);
2706 caster->DealHeal(unitTarget, addhealth, m_spellInfo);
2710 void Spell::EffectHealthLeech(uint32 i)
2712 if (!unitTarget)
2713 return;
2714 if (!unitTarget->isAlive())
2715 return;
2717 if (damage < 0)
2718 return;
2720 sLog.outDebug("HealthLeech :%i", damage);
2722 uint32 curHealth = unitTarget->GetHealth();
2723 damage = m_caster->SpellNonMeleeDamageLog(unitTarget, m_spellInfo->Id, damage );
2724 if (curHealth < damage)
2725 damage = curHealth;
2727 float multiplier = m_spellInfo->EffectMultipleValue[i];
2729 if (Player *modOwner = m_caster->GetSpellModOwner())
2730 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
2732 uint32 heal = uint32(damage*multiplier);
2733 if (m_caster->isAlive())
2735 heal = m_caster->SpellHealingBonus(m_caster, m_spellInfo, heal, HEAL);
2736 m_caster->DealHeal(m_caster, heal, m_spellInfo);
2740 void Spell::DoCreateItem(uint32 i, uint32 itemtype)
2742 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
2743 return;
2745 Player* player = (Player*)unitTarget;
2747 uint32 newitemid = itemtype;
2748 ItemPrototype const *pProto = ObjectMgr::GetItemPrototype( newitemid );
2749 if(!pProto)
2751 player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
2752 return;
2755 // bg reward have some special in code work
2756 uint32 bgType = 0;
2757 switch(m_spellInfo->Id)
2759 case SPELL_AV_MARK_WINNER:
2760 case SPELL_AV_MARK_LOSER:
2761 bgType = BATTLEGROUND_AV;
2762 break;
2763 case SPELL_WS_MARK_WINNER:
2764 case SPELL_WS_MARK_LOSER:
2765 bgType = BATTLEGROUND_WS;
2766 break;
2767 case SPELL_AB_MARK_WINNER:
2768 case SPELL_AB_MARK_LOSER:
2769 bgType = BATTLEGROUND_AB;
2770 break;
2771 default:
2772 break;
2775 uint32 num_to_add;
2777 // TODO: maybe all this can be replaced by using correct calculated `damage` value
2778 if(pProto->Class != ITEM_CLASS_CONSUMABLE || m_spellInfo->SpellFamilyName != SPELLFAMILY_MAGE)
2780 int32 basePoints = m_currentBasePoints[i];
2781 int32 randomPoints = m_spellInfo->EffectDieSides[i];
2782 if (randomPoints)
2783 num_to_add = basePoints + irand(1, randomPoints);
2784 else
2785 num_to_add = basePoints + 1;
2787 else if (pProto->MaxCount == 1)
2788 num_to_add = 1;
2789 else if(player->getLevel() >= m_spellInfo->spellLevel)
2791 int32 basePoints = m_currentBasePoints[i];
2792 float pointPerLevel = m_spellInfo->EffectRealPointsPerLevel[i];
2793 num_to_add = basePoints + 1 + uint32((player->getLevel() - m_spellInfo->spellLevel)*pointPerLevel);
2795 else
2796 num_to_add = 2;
2798 if (num_to_add < 1)
2799 num_to_add = 1;
2800 if (num_to_add > pProto->GetMaxStackSize())
2801 num_to_add = pProto->GetMaxStackSize();
2803 // init items_count to 1, since 1 item will be created regardless of specialization
2804 int items_count=1;
2805 // the chance to create additional items
2806 float additionalCreateChance=0.0f;
2807 // the maximum number of created additional items
2808 uint8 additionalMaxNum=0;
2809 // get the chance and maximum number for creating extra items
2810 if ( canCreateExtraItems(player, m_spellInfo->Id, additionalCreateChance, additionalMaxNum) )
2812 // roll with this chance till we roll not to create or we create the max num
2813 while ( roll_chance_f(additionalCreateChance) && items_count<=additionalMaxNum )
2814 ++items_count;
2817 // really will be created more items
2818 num_to_add *= items_count;
2820 // can the player store the new item?
2821 ItemPosCountVec dest;
2822 uint32 no_space = 0;
2823 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, newitemid, num_to_add, &no_space );
2824 if( msg != EQUIP_ERR_OK )
2826 // convert to possible store amount
2827 if( msg == EQUIP_ERR_INVENTORY_FULL || msg == EQUIP_ERR_CANT_CARRY_MORE_OF_THIS )
2828 num_to_add -= no_space;
2829 else
2831 // if not created by another reason from full inventory or unique items amount limitation
2832 player->SendEquipError( msg, NULL, NULL );
2833 return;
2837 if(num_to_add)
2839 // create the new item and store it
2840 Item* pItem = player->StoreNewItem( dest, newitemid, true, Item::GenerateItemRandomPropertyId(newitemid));
2842 // was it successful? return error if not
2843 if(!pItem)
2845 player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
2846 return;
2849 // set the "Crafted by ..." property of the item
2850 if( pItem->GetProto()->Class != ITEM_CLASS_CONSUMABLE && pItem->GetProto()->Class != ITEM_CLASS_QUEST)
2851 pItem->SetUInt32Value(ITEM_FIELD_CREATOR, player->GetGUIDLow());
2853 // send info to the client
2854 if(pItem)
2855 player->SendNewItem(pItem, num_to_add, true, bgType == 0);
2857 // we succeeded in creating at least one item, so a levelup is possible
2858 if(bgType == 0)
2859 player->UpdateCraftSkill(m_spellInfo->Id);
2862 // for battleground marks send by mail if not add all expected
2863 if(no_space > 0 && bgType)
2865 if(BattleGround* bg = sBattleGroundMgr.GetBattleGroundTemplate(BattleGroundTypeId(bgType)))
2866 bg->SendRewardMarkByMail(player, newitemid, no_space);
2870 void Spell::EffectCreateItem(uint32 i)
2872 DoCreateItem(i,m_spellInfo->EffectItemType[i]);
2875 void Spell::EffectCreateItem2(uint32 i)
2877 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
2878 return;
2879 Player* player = (Player*)m_caster;
2881 uint32 item_id = m_spellInfo->EffectItemType[i];
2883 DoCreateItem(i, item_id);
2885 // special case: fake item replaced by generate using spell_loot_template
2886 if (IsLootCraftingSpell(m_spellInfo))
2888 if (!player->HasItemCount(item_id, 1))
2889 return;
2891 // remove reagent
2892 uint32 count = 1;
2893 player->DestroyItemCount(item_id, count, true);
2895 // create some random items
2896 player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
2900 void Spell::EffectCreateRandomItem(uint32 i)
2902 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
2903 return;
2904 Player* player = (Player*)m_caster;
2906 // create some random items
2907 player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
2910 void Spell::EffectPersistentAA(uint32 i)
2912 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
2914 if (Player* modOwner = m_caster->GetSpellModOwner())
2915 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RADIUS, radius);
2917 int32 duration = GetSpellDuration(m_spellInfo);
2918 DynamicObject* dynObj = new DynamicObject;
2919 if (!dynObj->Create(m_caster->GetMap()->GenerateLocalLowGuid(HIGHGUID_DYNAMICOBJECT), m_caster, m_spellInfo->Id, i, m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, duration, radius))
2921 delete dynObj;
2922 return;
2924 dynObj->SetUInt32Value(OBJECT_FIELD_TYPE, 65);
2925 dynObj->SetUInt32Value(GAMEOBJECT_DISPLAYID, 368003);
2926 dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x01eeeeee);
2927 m_caster->AddDynObject(dynObj);
2928 m_caster->GetMap()->Add(dynObj);
2931 void Spell::EffectEnergize(uint32 i)
2933 if(!unitTarget)
2934 return;
2935 if(!unitTarget->isAlive())
2936 return;
2938 if(m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2939 return;
2941 Powers power = Powers(m_spellInfo->EffectMiscValue[i]);
2943 // Some level depends spells
2944 int level_multiplier = 0;
2945 int level_diff = 0;
2946 switch (m_spellInfo->Id)
2948 case 9512: // Restore Energy
2949 level_diff = m_caster->getLevel() - 40;
2950 level_multiplier = 2;
2951 break;
2952 case 24571: // Blood Fury
2953 level_diff = m_caster->getLevel() - 60;
2954 level_multiplier = 10;
2955 break;
2956 case 24532: // Burst of Energy
2957 level_diff = m_caster->getLevel() - 60;
2958 level_multiplier = 4;
2959 break;
2960 case 31930: // Judgements of the Wise
2961 case 48542: // Revitalize (mana restore case)
2962 case 63375: // Improved Stormstrike
2963 damage = damage * unitTarget->GetCreateMana() / 100;
2964 break;
2965 default:
2966 break;
2969 if (level_diff > 0)
2970 damage -= level_multiplier * level_diff;
2972 if(damage < 0)
2973 return;
2975 if(unitTarget->GetMaxPower(power) == 0)
2976 return;
2978 m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, damage, power);
2980 // Mad Alchemist's Potion
2981 if (m_spellInfo->Id == 45051)
2983 // find elixirs on target
2984 uint32 elixir_mask = 0;
2985 Unit::AuraMap& Auras = unitTarget->GetAuras();
2986 for(Unit::AuraMap::iterator itr = Auras.begin(); itr != Auras.end(); ++itr)
2988 uint32 spell_id = itr->second->GetId();
2989 if(uint32 mask = sSpellMgr.GetSpellElixirMask(spell_id))
2990 elixir_mask |= mask;
2993 // get available elixir mask any not active type from battle/guardian (and flask if no any)
2994 elixir_mask = (elixir_mask & ELIXIR_FLASK_MASK) ^ ELIXIR_FLASK_MASK;
2996 // get all available elixirs by mask and spell level
2997 std::vector<uint32> elixirs;
2998 SpellElixirMap const& m_spellElixirs = sSpellMgr.GetSpellElixirMap();
2999 for(SpellElixirMap::const_iterator itr = m_spellElixirs.begin(); itr != m_spellElixirs.end(); ++itr)
3001 if (itr->second & elixir_mask)
3003 if (itr->second & (ELIXIR_UNSTABLE_MASK | ELIXIR_SHATTRATH_MASK))
3004 continue;
3006 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
3007 if (spellInfo && (spellInfo->spellLevel < m_spellInfo->spellLevel || spellInfo->spellLevel > unitTarget->getLevel()))
3008 continue;
3010 elixirs.push_back(itr->first);
3014 if (!elixirs.empty())
3016 // cast random elixir on target
3017 uint32 rand_spell = urand(0,elixirs.size()-1);
3018 m_caster->CastSpell(unitTarget,elixirs[rand_spell],true,m_CastItem);
3023 void Spell::EffectEnergisePct(uint32 i)
3025 if (!unitTarget)
3026 return;
3027 if (!unitTarget->isAlive())
3028 return;
3030 if (m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
3031 return;
3033 Powers power = Powers(m_spellInfo->EffectMiscValue[i]);
3035 uint32 maxPower = unitTarget->GetMaxPower(power);
3036 if (maxPower == 0)
3037 return;
3039 uint32 gain = damage * maxPower / 100;
3040 m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, gain, power);
3043 void Spell::SendLoot(uint64 guid, LootType loottype)
3045 Player* player = (Player*)m_caster;
3046 if (!player)
3047 return;
3049 if (gameObjTarget)
3051 if (Script->GOHello(player, gameObjTarget))
3052 return;
3054 switch (gameObjTarget->GetGoType())
3056 case GAMEOBJECT_TYPE_DOOR:
3057 case GAMEOBJECT_TYPE_BUTTON:
3058 gameObjTarget->UseDoorOrButton();
3059 player->GetMap()->ScriptsStart(sGameObjectScripts, gameObjTarget->GetDBTableGUIDLow(), player, gameObjTarget);
3060 return;
3062 case GAMEOBJECT_TYPE_QUESTGIVER:
3063 // start or end quest
3064 player->PrepareQuestMenu(guid);
3065 player->SendPreparedQuest(guid);
3066 return;
3068 case GAMEOBJECT_TYPE_SPELL_FOCUS:
3069 // triggering linked GO
3070 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->spellFocus.linkedTrapId)
3071 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3072 return;
3074 case GAMEOBJECT_TYPE_GOOBER:
3075 // goober_scripts can be triggered if the player don't have the quest
3076 if (gameObjTarget->GetGOInfo()->goober.eventId)
3078 sLog.outDebug("Goober ScriptStart id %u for GO %u", gameObjTarget->GetGOInfo()->goober.eventId,gameObjTarget->GetDBTableGUIDLow());
3079 player->GetMap()->ScriptsStart(sEventScripts, gameObjTarget->GetGOInfo()->goober.eventId, player, gameObjTarget);
3082 // cast goober spell
3083 if (gameObjTarget->GetGOInfo()->goober.questId)
3084 ///Quest require to be active for GO using
3085 if (player->GetQuestStatus(gameObjTarget->GetGOInfo()->goober.questId) != QUEST_STATUS_INCOMPLETE)
3086 return;
3088 gameObjTarget->AddUniqueUse(player);
3089 gameObjTarget->SetLootState(GO_JUST_DEACTIVATED);
3091 //TODO? Objective counting called without spell check but with quest objective check
3092 // if send spell id then this line will duplicate to spell casting call (double counting)
3093 // So we or have this line and not required in quest_template have reqSpellIdN
3094 // or must remove this line and required in DB have data in quest_template have reqSpellIdN for all quest using cases.
3095 player->CastedCreatureOrGO(gameObjTarget->GetEntry(), gameObjTarget->GetGUID(), 0);
3097 // triggering linked GO
3098 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->goober.linkedTrapId)
3099 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3101 return;
3103 case GAMEOBJECT_TYPE_CHEST:
3104 // TODO: possible must be moved to loot release (in different from linked triggering)
3105 if (gameObjTarget->GetGOInfo()->chest.eventId)
3107 sLog.outDebug("Chest ScriptStart id %u for GO %u", gameObjTarget->GetGOInfo()->chest.eventId,gameObjTarget->GetDBTableGUIDLow());
3108 player->GetMap()->ScriptsStart(sEventScripts, gameObjTarget->GetGOInfo()->chest.eventId, player, gameObjTarget);
3111 // triggering linked GO
3112 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->chest.linkedTrapId)
3113 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3115 // Don't return, let loots been taken
3116 default:
3117 break;
3121 // Send loot
3122 player->SendLoot(guid, loottype);
3125 void Spell::EffectOpenLock(uint32 effIndex)
3127 if (!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER)
3129 sLog.outDebug( "WORLD: Open Lock - No Player Caster!");
3130 return;
3133 Player* player = (Player*)m_caster;
3135 uint32 lockId = 0;
3136 uint64 guid = 0;
3138 // Get lockId
3139 if (gameObjTarget)
3141 GameObjectInfo const* goInfo = gameObjTarget->GetGOInfo();
3142 // Arathi Basin banner opening !
3143 if (goInfo->type == GAMEOBJECT_TYPE_BUTTON && goInfo->button.noDamageImmune ||
3144 goInfo->type == GAMEOBJECT_TYPE_GOOBER && goInfo->goober.losOK)
3146 //CanUseBattleGroundObject() already called in CheckCast()
3147 // in battleground check
3148 if (BattleGround *bg = player->GetBattleGround())
3150 // check if it's correct bg
3151 if (bg->GetTypeID() == BATTLEGROUND_AB || bg->GetTypeID() == BATTLEGROUND_AV)
3152 bg->EventPlayerClickedOnFlag(player, gameObjTarget);
3153 return;
3156 else if (goInfo->type == GAMEOBJECT_TYPE_FLAGSTAND)
3158 //CanUseBattleGroundObject() already called in CheckCast()
3159 // in battleground check
3160 if (BattleGround *bg = player->GetBattleGround())
3162 if (bg->GetTypeID() == BATTLEGROUND_EY)
3163 bg->EventPlayerClickedOnFlag(player, gameObjTarget);
3164 return;
3167 lockId = goInfo->GetLockId();
3168 guid = gameObjTarget->GetGUID();
3170 else if (itemTarget)
3172 lockId = itemTarget->GetProto()->LockID;
3173 guid = itemTarget->GetGUID();
3175 else
3177 sLog.outDebug( "WORLD: Open Lock - No GameObject/Item Target!");
3178 return;
3181 SkillType skillId = SKILL_NONE;
3182 int32 reqSkillValue = 0;
3183 int32 skillValue;
3185 SpellCastResult res = CanOpenLock(effIndex, lockId, skillId, reqSkillValue, skillValue);
3186 if (res != SPELL_CAST_OK)
3188 SendCastResult(res);
3189 return;
3192 SendLoot(guid, LOOT_SKINNING);
3194 // not allow use skill grow at item base open
3195 if (!m_CastItem && skillId != SKILL_NONE)
3197 // update skill if really known
3198 if (uint32 pureSkillValue = player->GetPureSkillValue(skillId))
3200 if (gameObjTarget)
3202 // Allow one skill-up until respawned
3203 if (!gameObjTarget->IsInSkillupList(player->GetGUIDLow()) &&
3204 player->UpdateGatherSkill(skillId, pureSkillValue, reqSkillValue))
3205 gameObjTarget->AddToSkillupList(player->GetGUIDLow());
3207 else if (itemTarget)
3209 // Do one skill-up
3210 player->UpdateGatherSkill(skillId, pureSkillValue, reqSkillValue);
3216 void Spell::EffectSummonChangeItem(uint32 i)
3218 if (m_caster->GetTypeId() != TYPEID_PLAYER)
3219 return;
3221 Player *player = (Player*)m_caster;
3223 // applied only to using item
3224 if (!m_CastItem)
3225 return;
3227 // ... only to item in own inventory/bank/equip_slot
3228 if (m_CastItem->GetOwnerGUID()!=player->GetGUID())
3229 return;
3231 uint32 newitemid = m_spellInfo->EffectItemType[i];
3232 if (!newitemid)
3233 return;
3235 uint16 pos = m_CastItem->GetPos();
3237 Item *pNewItem = Item::CreateItem( newitemid, 1, player);
3238 if (!pNewItem)
3239 return;
3241 for(uint8 j= PERM_ENCHANTMENT_SLOT; j<=TEMP_ENCHANTMENT_SLOT; ++j)
3243 if (m_CastItem->GetEnchantmentId(EnchantmentSlot(j)))
3244 pNewItem->SetEnchantment(EnchantmentSlot(j), m_CastItem->GetEnchantmentId(EnchantmentSlot(j)), m_CastItem->GetEnchantmentDuration(EnchantmentSlot(j)), m_CastItem->GetEnchantmentCharges(EnchantmentSlot(j)));
3247 if (m_CastItem->GetUInt32Value(ITEM_FIELD_DURABILITY) < m_CastItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY))
3249 double loosePercent = 1 - m_CastItem->GetUInt32Value(ITEM_FIELD_DURABILITY) / double(m_CastItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY));
3250 player->DurabilityLoss(pNewItem, loosePercent);
3253 if (player->IsInventoryPos(pos))
3255 ItemPosCountVec dest;
3256 uint8 msg = player->CanStoreItem( m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), dest, pNewItem, true );
3257 if (msg == EQUIP_ERR_OK)
3259 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3261 // prevent crash at access and unexpected charges counting with item update queue corrupt
3262 if (m_CastItem==m_targets.getItemTarget())
3263 m_targets.setItemTarget(NULL);
3265 m_CastItem = NULL;
3267 player->StoreItem( dest, pNewItem, true);
3268 return;
3271 else if (player->IsBankPos (pos))
3273 ItemPosCountVec dest;
3274 uint8 msg = player->CanBankItem( m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), dest, pNewItem, true );
3275 if (msg == EQUIP_ERR_OK)
3277 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3279 // prevent crash at access and unexpected charges counting with item update queue corrupt
3280 if (m_CastItem==m_targets.getItemTarget())
3281 m_targets.setItemTarget(NULL);
3283 m_CastItem = NULL;
3285 player->BankItem( dest, pNewItem, true);
3286 return;
3289 else if (player->IsEquipmentPos (pos))
3291 uint16 dest;
3292 uint8 msg = player->CanEquipItem( m_CastItem->GetSlot(), dest, pNewItem, true );
3293 if (msg == EQUIP_ERR_OK)
3295 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3297 // prevent crash at access and unexpected charges counting with item update queue corrupt
3298 if (m_CastItem==m_targets.getItemTarget())
3299 m_targets.setItemTarget(NULL);
3301 m_CastItem = NULL;
3303 player->EquipItem( dest, pNewItem, true);
3304 player->AutoUnequipOffhandIfNeed();
3305 return;
3309 // fail
3310 delete pNewItem;
3313 void Spell::EffectProficiency(uint32 /*i*/)
3315 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
3316 return;
3317 Player *p_target = (Player*)unitTarget;
3319 uint32 subClassMask = m_spellInfo->EquippedItemSubClassMask;
3320 if (m_spellInfo->EquippedItemClass == ITEM_CLASS_WEAPON && !(p_target->GetWeaponProficiency() & subClassMask))
3322 p_target->AddWeaponProficiency(subClassMask);
3323 p_target->SendProficiency(ITEM_CLASS_WEAPON, p_target->GetWeaponProficiency());
3325 if (m_spellInfo->EquippedItemClass == ITEM_CLASS_ARMOR && !(p_target->GetArmorProficiency() & subClassMask))
3327 p_target->AddArmorProficiency(subClassMask);
3328 p_target->SendProficiency(ITEM_CLASS_ARMOR, p_target->GetArmorProficiency());
3332 void Spell::EffectApplyAreaAura(uint32 i)
3334 if (!unitTarget)
3335 return;
3336 if (!unitTarget->isAlive())
3337 return;
3339 AreaAura* Aur = new AreaAura(m_spellInfo, i, &m_currentBasePoints[i], unitTarget, m_caster, m_CastItem);
3340 unitTarget->AddAura(Aur);
3343 void Spell::EffectSummonType(uint32 i)
3345 uint32 prop_id = m_spellInfo->EffectMiscValueB[i];
3346 SummonPropertiesEntry const *summon_prop = sSummonPropertiesStore.LookupEntry(prop_id);
3347 if(!summon_prop)
3349 sLog.outError("EffectSummonType: Unhandled summon type %u", prop_id);
3350 return;
3353 switch(summon_prop->Group)
3355 // faction handled later on, or loaded from template
3356 case SUMMON_PROP_GROUP_WILD:
3357 case SUMMON_PROP_GROUP_FRIENDLY:
3359 switch(summon_prop->Type)
3361 case SUMMON_PROP_TYPE_OTHER:
3363 // those are classical totems - effectbasepoints is their hp and not summon ammount!
3364 //SUMMON_TYPE_TOTEM = 121: 23035, battlestands
3365 //SUMMON_TYPE_TOTEM2 = 647: 52893, Anti-Magic Zone (npc used)
3366 if(prop_id == 121 || prop_id == 647)
3367 EffectSummonTotem(i);
3368 else
3369 EffectSummonWild(i, summon_prop->FactionId);
3370 break;
3372 case SUMMON_PROP_TYPE_SUMMON:
3373 case SUMMON_PROP_TYPE_GUARDIAN:
3374 case SUMMON_PROP_TYPE_ARMY:
3375 case SUMMON_PROP_TYPE_DK:
3376 case SUMMON_PROP_TYPE_CONSTRUCT:
3378 // JC golems - 32804, etc -- fits much better totem AI
3379 if(m_spellInfo->SpellIconID == 2056)
3380 EffectSummonTotem(i);
3381 if(prop_id == 832) // scrapbot
3382 EffectSummonWild(i, summon_prop->FactionId);
3383 else
3384 EffectSummonGuardian(i, summon_prop->FactionId);
3385 break;
3387 case SUMMON_PROP_TYPE_TOTEM:
3388 EffectSummonTotem(i, summon_prop->Slot);
3389 break;
3390 case SUMMON_PROP_TYPE_CRITTER:
3391 EffectSummonCritter(i, summon_prop->FactionId);
3392 break;
3393 case SUMMON_PROP_TYPE_PHASING:
3394 case SUMMON_PROP_TYPE_LIGHTWELL:
3395 case SUMMON_PROP_TYPE_REPAIR_BOT:
3396 EffectSummonWild(i, summon_prop->FactionId);
3397 break;
3398 case SUMMON_PROP_TYPE_SIEGE_VEH:
3399 case SUMMON_PROP_TYPE_DRAKE_VEH:
3400 // TODO
3401 // EffectSummonVehicle(i);
3402 break;
3403 default:
3404 sLog.outError("EffectSummonType: Unhandled summon type %u", summon_prop->Type);
3405 break;
3407 break;
3409 case SUMMON_PROP_GROUP_PETS:
3411 // FIXME : multiple summons - not yet supported as pet
3412 //1562 - force of nature - sid 33831
3413 //1161 - feral spirit - sid 51533
3414 if(prop_id == 1562) // 3 uncontrolable instead of one controllable :/
3415 EffectSummonGuardian(i, summon_prop->FactionId);
3416 else
3417 EffectSummon(i);
3418 break;
3420 case SUMMON_PROP_GROUP_CONTROLLABLE:
3422 // no type here
3423 // maybe wrong - but thats the handler currently used for those
3424 EffectSummonGuardian(i, summon_prop->FactionId);
3425 break;
3427 case SUMMON_PROP_GROUP_VEHICLE:
3429 // TODO
3430 // EffectSummonVehicle(i);
3431 break;
3433 default:
3434 sLog.outError("EffectSummonType: Unhandled summon group type %u", summon_prop->Group);
3435 break;
3439 void Spell::EffectSummon(uint32 i)
3441 if (m_caster->GetPetGUID())
3442 return;
3444 if (!unitTarget)
3445 return;
3446 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
3447 if (!pet_entry)
3448 return;
3449 uint32 level = m_caster->getLevel();
3450 Pet* spawnCreature = new Pet(SUMMON_PET);
3452 int32 duration = GetSpellDuration(m_spellInfo);
3453 if(Player* modOwner = m_caster->GetSpellModOwner())
3454 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
3456 if (m_caster->GetTypeId()==TYPEID_PLAYER && spawnCreature->LoadPetFromDB((Player*)m_caster,pet_entry))
3458 // Summon in dest location
3459 float x, y, z;
3460 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3462 x = m_targets.m_destX;
3463 y = m_targets.m_destY;
3464 z = m_targets.m_destZ;
3465 spawnCreature->Relocate(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, -m_caster->GetOrientation());
3468 // set timer for unsummon
3469 if (duration > 0)
3470 spawnCreature->SetDuration(duration);
3472 return;
3475 Map *map = m_caster->GetMap();
3476 uint32 pet_number = sObjectMgr.GeneratePetNumber();
3477 if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
3478 m_spellInfo->EffectMiscValue[i], pet_number))
3480 sLog.outErrorDb("Spell::EffectSummon: no such creature entry %u",m_spellInfo->EffectMiscValue[i]);
3481 delete spawnCreature;
3482 return;
3485 // Summon in dest location
3486 float x, y, z;
3487 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3489 x = m_targets.m_destX;
3490 y = m_targets.m_destY;
3491 z = m_targets.m_destZ;
3493 else
3494 m_caster->GetClosePoint(x, y, z, spawnCreature->GetObjectSize());
3496 spawnCreature->Relocate(x, y, z, -m_caster->GetOrientation());
3498 if (!spawnCreature->IsPositionValid())
3500 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
3501 spawnCreature->GetGUIDLow(), spawnCreature->GetEntry(), spawnCreature->GetPositionX(), spawnCreature->GetPositionY());
3502 delete spawnCreature;
3503 return;
3506 // set timer for unsummon
3507 if (duration > 0)
3508 spawnCreature->SetDuration(duration);
3510 spawnCreature->SetOwnerGUID(m_caster->GetGUID());
3511 spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
3512 spawnCreature->setPowerType(POWER_MANA);
3513 spawnCreature->setFaction(m_caster->getFaction());
3514 spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS, 0);
3515 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
3516 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
3517 spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
3518 spawnCreature->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
3519 spawnCreature->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
3520 spawnCreature->SetCreatorGUID(m_caster->GetGUID());
3521 spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3523 spawnCreature->InitStatsForLevel(level, m_caster);
3525 spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
3527 spawnCreature->AIM_Initialize();
3528 spawnCreature->InitPetCreateSpells();
3529 spawnCreature->InitLevelupSpellsForLevel();
3530 spawnCreature->SetHealth(spawnCreature->GetMaxHealth());
3531 spawnCreature->SetPower(POWER_MANA, spawnCreature->GetMaxPower(POWER_MANA));
3533 std::string name = m_caster->GetName();
3534 name.append(petTypeSuffix[spawnCreature->getPetType()]);
3535 spawnCreature->SetName( name );
3537 map->Add((Creature*)spawnCreature);
3539 m_caster->SetPet(spawnCreature);
3541 if (m_caster->GetTypeId() == TYPEID_PLAYER)
3543 spawnCreature->GetCharmInfo()->SetReactState( REACT_DEFENSIVE );
3544 spawnCreature->SavePetToDB(PET_SAVE_AS_CURRENT);
3545 ((Player*)m_caster)->PetSpellInitialize();
3549 void Spell::EffectLearnSpell(uint32 i)
3551 if (!unitTarget)
3552 return;
3554 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
3556 if (m_caster->GetTypeId() == TYPEID_PLAYER)
3557 EffectLearnPetSpell(i);
3559 return;
3562 Player *player = (Player*)unitTarget;
3564 uint32 spellToLearn = ((m_spellInfo->Id==SPELL_ID_GENERIC_LEARN) || (m_spellInfo->Id==SPELL_ID_GENERIC_LEARN_PET)) ? damage : m_spellInfo->EffectTriggerSpell[i];
3565 player->learnSpell(spellToLearn,false);
3567 sLog.outDebug( "Spell: Player %u has learned spell %u from NpcGUID=%u", player->GetGUIDLow(), spellToLearn, m_caster->GetGUIDLow() );
3570 void Spell::EffectDispel(uint32 i)
3572 if (!unitTarget)
3573 return;
3575 // Fill possible dispell list
3576 std::vector <Aura *> dispel_list;
3578 // Create dispel mask by dispel type
3579 uint32 dispel_type = m_spellInfo->EffectMiscValue[i];
3580 uint32 dispelMask = GetDispellMask( DispelType(dispel_type) );
3581 Unit::AuraMap const& auras = unitTarget->GetAuras();
3582 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3584 Aura *aur = (*itr).second;
3585 if (aur && (1<<aur->GetSpellProto()->Dispel) & dispelMask)
3587 if(aur->GetSpellProto()->Dispel == DISPEL_MAGIC)
3589 bool positive = true;
3590 if (!aur->IsPositive())
3591 positive = false;
3592 else
3593 positive = (aur->GetSpellProto()->AttributesEx & SPELL_ATTR_EX_NEGATIVE)==0;
3595 // do not remove positive auras if friendly target
3596 // negative auras if non-friendly target
3597 if (positive == unitTarget->IsFriendlyTo(m_caster))
3598 continue;
3600 // Add aura to dispel list (all stack cases)
3601 for(int k = 0; k < aur->GetStackAmount(); ++k)
3602 dispel_list.push_back(aur);
3605 // Ok if exist some buffs for dispel try dispel it
3606 if (!dispel_list.empty())
3608 std::list < std::pair<uint32,uint64> > success_list;// (spell_id,casterGuid)
3609 std::list < uint32 > fail_list; // spell_id
3611 // some spells have effect value = 0 and all from its by meaning expect 1
3612 if(!damage)
3613 damage = 1;
3615 // Dispell N = damage buffs (or while exist buffs for dispel)
3616 for (int32 count=0; count < damage && !dispel_list.empty(); ++count)
3618 // Random select buff for dispel
3619 std::vector<Aura*>::iterator dispel_itr = dispel_list.begin();
3620 std::advance(dispel_itr,urand(0, dispel_list.size()-1));
3622 Aura *aur = *dispel_itr;
3624 // remove entry from dispel_list
3625 dispel_list.erase(dispel_itr);
3627 SpellEntry const* spellInfo = aur->GetSpellProto();
3628 // Base dispel chance
3629 // TODO: possible chance depend from spell level??
3630 int32 miss_chance = 0;
3631 // Apply dispel mod from aura caster
3632 if (Unit *caster = aur->GetCaster())
3634 if ( Player* modOwner = caster->GetSpellModOwner() )
3635 modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_RESIST_DISPEL_CHANCE, miss_chance, this);
3637 // Try dispel
3638 if (roll_chance_i(miss_chance))
3639 fail_list.push_back(spellInfo->Id);
3640 else
3641 success_list.push_back(std::pair<uint32,uint64>(aur->GetId(),aur->GetCasterGUID()));
3643 // Send success log and really remove auras
3644 if (!success_list.empty())
3646 int32 count = success_list.size();
3647 WorldPacket data(SMSG_SPELLDISPELLOG, 8+8+4+1+4+count*5);
3648 data.append(unitTarget->GetPackGUID()); // Victim GUID
3649 data.append(m_caster->GetPackGUID()); // Caster GUID
3650 data << uint32(m_spellInfo->Id); // Dispel spell id
3651 data << uint8(0); // not used
3652 data << uint32(count); // count
3653 for (std::list<std::pair<uint32,uint64> >::iterator j = success_list.begin(); j != success_list.end(); ++j)
3655 SpellEntry const* spellInfo = sSpellStore.LookupEntry(j->first);
3656 data << uint32(spellInfo->Id); // Spell Id
3657 data << uint8(0); // 0 - dispeled !=0 cleansed
3658 unitTarget->RemoveSingleAuraDueToSpellByDispel(spellInfo->Id, j->second, m_caster);
3660 m_caster->SendMessageToSet(&data, true);
3662 // On success dispel
3663 // Devour Magic
3664 if (m_spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK && m_spellInfo->Category == SPELLCATEGORY_DEVOUR_MAGIC)
3666 int32 heal_amount = m_spellInfo->CalculateSimpleValue(1);
3667 m_caster->CastCustomSpell(m_caster, 19658, &heal_amount, NULL, NULL, true);
3670 // Send fail log to client
3671 if (!fail_list.empty())
3673 // Failed to dispell
3674 WorldPacket data(SMSG_DISPEL_FAILED, 8+8+4+4*fail_list.size());
3675 data << uint64(m_caster->GetGUID()); // Caster GUID
3676 data << uint64(unitTarget->GetGUID()); // Victim GUID
3677 data << uint32(m_spellInfo->Id); // Dispell spell id
3678 for (std::list< uint32 >::iterator j = fail_list.begin(); j != fail_list.end(); ++j)
3679 data << uint32(*j); // Spell Id
3680 m_caster->SendMessageToSet(&data, true);
3685 void Spell::EffectDualWield(uint32 /*i*/)
3687 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
3688 ((Player*)unitTarget)->SetCanDualWield(true);
3691 void Spell::EffectPull(uint32 /*i*/)
3693 // TODO: create a proper pull towards distract spell center for distract
3694 sLog.outDebug("WORLD: Spell Effect DUMMY");
3697 void Spell::EffectDistract(uint32 /*i*/)
3699 // Check for possible target
3700 if (!unitTarget || unitTarget->isInCombat())
3701 return;
3703 // target must be OK to do this
3704 if( unitTarget->hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_STUNNED | UNIT_STAT_FLEEING ) )
3705 return;
3707 float angle = unitTarget->GetAngle(m_targets.m_destX, m_targets.m_destY);
3709 if ( unitTarget->GetTypeId() == TYPEID_PLAYER )
3711 // For players just turn them
3712 WorldPacket data;
3713 ((Player*)unitTarget)->BuildTeleportAckMsg(&data, unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), angle);
3714 ((Player*)unitTarget)->GetSession()->SendPacket( &data );
3715 ((Player*)unitTarget)->SetPosition(unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), angle, false);
3717 else
3719 // Set creature Distracted, Stop it, And turn it
3720 unitTarget->SetOrientation(angle);
3721 unitTarget->StopMoving();
3722 unitTarget->GetMotionMaster()->MoveDistract(damage * IN_MILISECONDS);
3726 void Spell::EffectPickPocket(uint32 /*i*/)
3728 if (m_caster->GetTypeId() != TYPEID_PLAYER)
3729 return;
3731 // victim must be creature and attackable
3732 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || m_caster->IsFriendlyTo(unitTarget))
3733 return;
3735 // victim have to be alive and humanoid or undead
3736 if (unitTarget->isAlive() && (unitTarget->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD) != 0)
3738 int32 chance = 10 + int32(m_caster->getLevel()) - int32(unitTarget->getLevel());
3740 if (chance > irand(0, 19))
3742 // Stealing successful
3743 //sLog.outDebug("Sending loot from pickpocket");
3744 ((Player*)m_caster)->SendLoot(unitTarget->GetGUID(),LOOT_PICKPOCKETING);
3746 else
3748 // Reveal action + get attack
3749 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
3750 if (((Creature*)unitTarget)->AI())
3751 ((Creature*)unitTarget)->AI()->AttackedBy(m_caster);
3756 void Spell::EffectAddFarsight(uint32 i)
3758 if(m_caster->GetTypeId() != TYPEID_PLAYER)
3759 return;
3761 int32 duration = GetSpellDuration(m_spellInfo);
3762 DynamicObject* dynObj = new DynamicObject;
3764 // set radius to 0: spell not expected to work as persistent aura
3765 if(!dynObj->Create(m_caster->GetMap()->GenerateLocalLowGuid(HIGHGUID_DYNAMICOBJECT), m_caster, m_spellInfo->Id, i, m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, duration, 0))
3767 delete dynObj;
3768 return;
3770 dynObj->SetUInt32Value(OBJECT_FIELD_TYPE, 65);
3771 dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x80000002);
3772 m_caster->AddDynObject(dynObj);
3773 m_caster->GetMap()->Add(dynObj);
3774 ((Player*)m_caster)->SetFarSightGUID(dynObj->GetGUID());
3777 void Spell::EffectSummonWild(uint32 i, uint32 forceFaction)
3779 uint32 creature_entry = m_spellInfo->EffectMiscValue[i];
3780 if (!creature_entry)
3781 return;
3783 uint32 level = m_caster->getLevel();
3785 // level of creature summoned using engineering item based at engineering skill level
3786 if (m_caster->GetTypeId()==TYPEID_PLAYER && m_CastItem)
3788 ItemPrototype const *proto = m_CastItem->GetProto();
3789 if (proto && proto->RequiredSkill == SKILL_ENGINERING)
3791 uint16 skill202 = ((Player*)m_caster)->GetSkillValue(SKILL_ENGINERING);
3792 if (skill202)
3793 level = skill202/5;
3797 // select center of summon position
3798 float center_x = m_targets.m_destX;
3799 float center_y = m_targets.m_destY;
3800 float center_z = m_targets.m_destZ;
3802 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3803 int32 duration = GetSpellDuration(m_spellInfo);
3804 TempSummonType summonType = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_OR_DEAD_DESPAWN;
3806 int32 amount = damage > 0 ? damage : 1;
3808 for(int32 count = 0; count < amount; ++count)
3810 float px, py, pz;
3811 // If dest location if present
3812 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3814 // Summon 1 unit in dest location
3815 if (count == 0)
3817 px = m_targets.m_destX;
3818 py = m_targets.m_destY;
3819 pz = m_targets.m_destZ;
3821 // Summon in random point all other units if location present
3822 else
3823 m_caster->GetRandomPoint(center_x, center_y, center_z, radius, px, py, pz);
3825 // Summon if dest location not present near caster
3826 else
3827 m_caster->GetClosePoint(px, py, pz, 3.0f);
3829 if(Creature *summon = m_caster->SummonCreature(creature_entry, px, py, pz, m_caster->GetOrientation(), summonType, duration))
3831 summon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3832 summon->SetCreatorGUID(m_caster->GetGUID());
3834 if(forceFaction)
3835 summon->setFaction(forceFaction);
3840 void Spell::EffectSummonGuardian(uint32 i, uint32 forceFaction)
3842 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
3843 if (!pet_entry)
3844 return;
3846 // in another case summon new
3847 uint32 level = m_caster->getLevel();
3849 // level of pet summoned using engineering item based at engineering skill level
3850 if (m_caster->GetTypeId() == TYPEID_PLAYER && m_CastItem)
3852 ItemPrototype const *proto = m_CastItem->GetProto();
3853 if (proto && proto->RequiredSkill == SKILL_ENGINERING)
3855 uint16 skill202 = ((Player*)m_caster)->GetSkillValue(SKILL_ENGINERING);
3856 if (skill202)
3858 level = skill202 / 5;
3863 // select center of summon position
3864 float center_x = m_targets.m_destX;
3865 float center_y = m_targets.m_destY;
3866 float center_z = m_targets.m_destZ;
3868 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3869 int32 duration = GetSpellDuration(m_spellInfo);
3870 if(Player* modOwner = m_caster->GetSpellModOwner())
3871 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
3873 int32 amount = damage > 0 ? damage : 1;
3875 for(int32 count = 0; count < amount; ++count)
3877 Pet* spawnCreature = new Pet(GUARDIAN_PET);
3879 Map *map = m_caster->GetMap();
3880 uint32 pet_number = sObjectMgr.GeneratePetNumber();
3881 if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map,m_caster->GetPhaseMask(),
3882 m_spellInfo->EffectMiscValue[i], pet_number))
3884 sLog.outError("no such creature entry %u", m_spellInfo->EffectMiscValue[i]);
3885 delete spawnCreature;
3886 return;
3889 float px, py, pz;
3890 // If dest location if present
3891 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3893 // Summon 1 unit in dest location
3894 if (count == 0)
3896 px = m_targets.m_destX;
3897 py = m_targets.m_destY;
3898 pz = m_targets.m_destZ;
3900 // Summon in random point all other units if location present
3901 else
3902 m_caster->GetRandomPoint(center_x, center_y, center_z, radius, px, py, pz);
3904 // Summon if dest location not present near caster
3905 else
3906 m_caster->GetClosePoint(px, py, pz,spawnCreature->GetObjectSize());
3908 spawnCreature->Relocate(px, py, pz, m_caster->GetOrientation());
3910 if (!spawnCreature->IsPositionValid())
3912 sLog.outError("Pet (guidlow %d, entry %d) not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)",
3913 spawnCreature->GetGUIDLow(), spawnCreature->GetEntry(), spawnCreature->GetPositionX(), spawnCreature->GetPositionY());
3914 delete spawnCreature;
3915 return;
3918 if (duration > 0)
3919 spawnCreature->SetDuration(duration);
3921 spawnCreature->SetOwnerGUID(m_caster->GetGUID());
3922 spawnCreature->setPowerType(POWER_MANA);
3923 spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, spawnCreature->GetCreatureInfo()->npcflag);
3924 spawnCreature->setFaction(forceFaction ? forceFaction : m_caster->getFaction());
3925 spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS, 0);
3926 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
3927 spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
3928 spawnCreature->SetCreatorGUID(m_caster->GetGUID());
3929 spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3931 spawnCreature->InitStatsForLevel(level, m_caster);
3932 spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
3934 spawnCreature->AIM_Initialize();
3936 m_caster->AddGuardian(spawnCreature);
3938 map->Add((Creature*)spawnCreature);
3942 void Spell::EffectTeleUnitsFaceCaster(uint32 i)
3944 if (!unitTarget)
3945 return;
3947 if (unitTarget->isInFlight())
3948 return;
3950 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3952 float fx, fy, fz;
3953 m_caster->GetClosePoint(fx, fy, fz, unitTarget->GetObjectSize(), dis);
3955 unitTarget->NearTeleportTo(fx, fy, fz, -m_caster->GetOrientation(), unitTarget==m_caster);
3958 void Spell::EffectLearnSkill(uint32 i)
3960 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
3961 return;
3963 if (damage < 0)
3964 return;
3966 uint32 skillid = m_spellInfo->EffectMiscValue[i];
3967 uint16 skillval = ((Player*)unitTarget)->GetPureSkillValue(skillid);
3968 ((Player*)unitTarget)->SetSkill(skillid, skillval ? skillval : 1, damage * 75);
3971 void Spell::EffectAddHonor(uint32 /*i*/)
3973 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
3974 return;
3976 // not scale value for item based reward (/10 value expected)
3977 if (m_CastItem)
3979 ((Player*)unitTarget)->RewardHonor(NULL, 1, damage / 10);
3980 sLog.outDebug("SpellEffect::AddHonor (spell_id %u) rewards %d honor points (item %u) for player: %u", m_spellInfo->Id, damage/10, m_CastItem->GetEntry(),((Player*)unitTarget)->GetGUIDLow());
3981 return;
3984 // do not allow to add too many honor for player (50 * 21) = 1040 at level 70, or (50 * 31) = 1550 at level 80
3985 if (damage <= 50)
3987 uint32 honor_reward = MaNGOS::Honor::hk_honor_at_level(unitTarget->getLevel(), damage);
3988 ((Player*)unitTarget)->RewardHonor(NULL, 1, honor_reward);
3989 sLog.outDebug("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (scale) to player: %u", m_spellInfo->Id, honor_reward, ((Player*)unitTarget)->GetGUIDLow());
3991 else
3993 //maybe we have correct honor_gain in damage already
3994 ((Player*)unitTarget)->RewardHonor(NULL, 1, damage);
3995 sLog.outError("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (non scale) for player: %u", m_spellInfo->Id, damage, ((Player*)unitTarget)->GetGUIDLow());
3999 void Spell::EffectTradeSkill(uint32 /*i*/)
4001 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4002 return;
4003 // uint32 skillid = m_spellInfo->EffectMiscValue[i];
4004 // uint16 skillmax = ((Player*)unitTarget)->(skillid);
4005 // ((Player*)unitTarget)->SetSkill(skillid,skillval?skillval:1,skillmax+75);
4008 void Spell::EffectEnchantItemPerm(uint32 effect_idx)
4010 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4011 return;
4012 if (!itemTarget)
4013 return;
4015 Player* p_caster = (Player*)m_caster;
4017 // not grow at item use at item case
4018 p_caster->UpdateCraftSkill(m_spellInfo->Id);
4020 uint32 enchant_id = m_spellInfo->EffectMiscValue[effect_idx];
4021 if (!enchant_id)
4022 return;
4024 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4025 if (!pEnchant)
4026 return;
4028 // item can be in trade slot and have owner diff. from caster
4029 Player* item_owner = itemTarget->GetOwner();
4030 if (!item_owner)
4031 return;
4033 if (item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4035 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(perm): %s (Entry: %d) for player: %s (Account: %u)",
4036 p_caster->GetName(),p_caster->GetSession()->GetAccountId(),
4037 itemTarget->GetProto()->Name1,itemTarget->GetEntry(),
4038 item_owner->GetName(),item_owner->GetSession()->GetAccountId());
4041 // remove old enchanting before applying new if equipped
4042 item_owner->ApplyEnchantment(itemTarget,PERM_ENCHANTMENT_SLOT,false);
4044 itemTarget->SetEnchantment(PERM_ENCHANTMENT_SLOT, enchant_id, 0, 0);
4046 // add new enchanting if equipped
4047 item_owner->ApplyEnchantment(itemTarget,PERM_ENCHANTMENT_SLOT,true);
4050 void Spell::EffectEnchantItemPrismatic(uint32 effect_idx)
4052 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4053 return;
4054 if (!itemTarget)
4055 return;
4057 Player* p_caster = (Player*)m_caster;
4059 uint32 enchant_id = m_spellInfo->EffectMiscValue[effect_idx];
4060 if (!enchant_id)
4061 return;
4063 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4064 if (!pEnchant)
4065 return;
4067 // support only enchantings with add socket in this slot
4069 bool add_socket = false;
4070 for(int i = 0; i < 3; ++i)
4072 if (pEnchant->type[i]==ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET)
4074 add_socket = true;
4075 break;
4078 if (!add_socket)
4080 sLog.outError("Spell::EffectEnchantItemPrismatic: attempt apply enchant spell %u with SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC (%u) but without ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET (%u), not suppoted yet.",
4081 m_spellInfo->Id,SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC,ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET);
4082 return;
4086 // item can be in trade slot and have owner diff. from caster
4087 Player* item_owner = itemTarget->GetOwner();
4088 if (!item_owner)
4089 return;
4091 if (item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4093 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(perm): %s (Entry: %d) for player: %s (Account: %u)",
4094 p_caster->GetName(),p_caster->GetSession()->GetAccountId(),
4095 itemTarget->GetProto()->Name1,itemTarget->GetEntry(),
4096 item_owner->GetName(),item_owner->GetSession()->GetAccountId());
4099 // remove old enchanting before applying new if equipped
4100 item_owner->ApplyEnchantment(itemTarget,PRISMATIC_ENCHANTMENT_SLOT,false);
4102 itemTarget->SetEnchantment(PRISMATIC_ENCHANTMENT_SLOT, enchant_id, 0, 0);
4104 // add new enchanting if equipped
4105 item_owner->ApplyEnchantment(itemTarget,PRISMATIC_ENCHANTMENT_SLOT,true);
4108 void Spell::EffectEnchantItemTmp(uint32 i)
4110 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4111 return;
4113 Player* p_caster = (Player*)m_caster;
4115 // Rockbiter Weapon apply to both weapon
4116 if (m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN && m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000400000))
4118 uint32 spell_id = 0;
4120 // enchanting spell selected by calculated damage-per-sec stored in Effect[1] base value
4121 // Note: damage calculated (correctly) with rounding int32(float(v)) but
4122 // RW enchantments applied damage int32(float(v)+0.5), this create 0..1 difference sometime
4123 switch(damage)
4125 // Rank 1
4126 case 2: spell_id = 36744; break; // 0% [ 7% == 2, 14% == 2, 20% == 2]
4127 // Rank 2
4128 case 4: spell_id = 36753; break; // 0% [ 7% == 4, 14% == 4]
4129 case 5: spell_id = 36751; break; // 20%
4130 // Rank 3
4131 case 6: spell_id = 36754; break; // 0% [ 7% == 6, 14% == 6]
4132 case 7: spell_id = 36755; break; // 20%
4133 // Rank 4
4134 case 9: spell_id = 36761; break; // 0% [ 7% == 6]
4135 case 10: spell_id = 36758; break; // 14%
4136 case 11: spell_id = 36760; break; // 20%
4137 default:
4138 sLog.outError("Spell::EffectEnchantItemTmp: Damage %u not handled in S'RW",damage);
4139 return;
4143 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id);
4144 if (!spellInfo)
4146 sLog.outError("Spell::EffectEnchantItemTmp: unknown spell id %i", spell_id);
4147 return;
4150 for(int j = BASE_ATTACK; j <= OFF_ATTACK; ++j)
4152 if (Item* item = p_caster->GetWeaponForAttack(WeaponAttackType(j)))
4154 if (item->IsFitToSpellRequirements(m_spellInfo))
4156 Spell *spell = new Spell(m_caster, spellInfo, true);
4157 SpellCastTargets targets;
4158 targets.setItemTarget( item );
4159 spell->prepare(&targets);
4163 return;
4166 if (!itemTarget)
4167 return;
4169 uint32 enchant_id = m_spellInfo->EffectMiscValue[i];
4171 if (!enchant_id)
4173 sLog.outError("Spell %u Effect %u (SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY) have 0 as enchanting id",m_spellInfo->Id,i);
4174 return;
4177 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4178 if(!pEnchant)
4180 sLog.outError("Spell %u Effect %u (SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY) have not existed enchanting id %u ",m_spellInfo->Id,i,enchant_id);
4181 return;
4184 // select enchantment duration
4185 uint32 duration;
4187 // rogue family enchantments exception by duration
4188 if(m_spellInfo->Id == 38615)
4189 duration = 1800; // 30 mins
4190 // other rogue family enchantments always 1 hour (some have spell damage=0, but some have wrong data in EffBasePoints)
4191 else if(m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE)
4192 duration = 3600; // 1 hour
4193 // shaman family enchantments
4194 else if(m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN)
4195 duration = 1800; // 30 mins
4196 // other cases with this SpellVisual already selected
4197 else if(m_spellInfo->SpellVisual[0] == 215)
4198 duration = 1800; // 30 mins
4199 // some fishing pole bonuses
4200 else if(m_spellInfo->SpellVisual[0] == 563)
4201 duration = 600; // 10 mins
4202 // shaman rockbiter enchantments
4203 else if(m_spellInfo->SpellVisual[0] == 0)
4204 duration = 1800; // 30 mins
4205 else if(m_spellInfo->Id == 29702)
4206 duration = 300; // 5 mins
4207 else if(m_spellInfo->Id == 37360)
4208 duration = 300; // 5 mins
4209 // default case
4210 else
4211 duration = 3600; // 1 hour
4213 // item can be in trade slot and have owner diff. from caster
4214 Player* item_owner = itemTarget->GetOwner();
4215 if(!item_owner)
4216 return;
4218 if(item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4220 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(temp): %s (Entry: %d) for player: %s (Account: %u)",
4221 p_caster->GetName(), p_caster->GetSession()->GetAccountId(),
4222 itemTarget->GetProto()->Name1, itemTarget->GetEntry(),
4223 item_owner->GetName(), item_owner->GetSession()->GetAccountId());
4226 // remove old enchanting before applying new if equipped
4227 item_owner->ApplyEnchantment(itemTarget,TEMP_ENCHANTMENT_SLOT, false);
4229 itemTarget->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, duration * 1000, 0);
4231 // add new enchanting if equipped
4232 item_owner->ApplyEnchantment(itemTarget, TEMP_ENCHANTMENT_SLOT, true);
4235 void Spell::EffectTameCreature(uint32 /*i*/)
4237 // Caster must be player, checked in Spell::CheckCast
4238 // Spell can be triggered, we need to check original caster prior to caster
4239 Player* plr = (Player*)(m_originalCaster ? m_originalCaster : m_caster);
4241 Creature* creatureTarget = (Creature*)unitTarget;
4243 // cast finish successfully
4244 //SendChannelUpdate(0);
4245 finish();
4247 Pet* pet = plr->CreateTamedPetFrom(creatureTarget, m_spellInfo->Id);
4248 if(!pet) // in versy specific state like near world end/etc.
4249 return;
4251 // "kill" original creature
4252 creatureTarget->ForcedDespawn();
4254 uint32 level = (creatureTarget->getLevel() < (plr->getLevel() - 5)) ? (plr->getLevel() - 5) : creatureTarget->getLevel();
4256 // prepare visual effect for levelup
4257 pet->SetUInt32Value(UNIT_FIELD_LEVEL, level - 1);
4259 // add to world
4260 pet->GetMap()->Add((Creature*)pet);
4262 // visual effect for levelup
4263 pet->SetUInt32Value(UNIT_FIELD_LEVEL, level);
4265 // caster have pet now
4266 plr->SetPet(pet);
4268 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
4269 plr->PetSpellInitialize();
4272 void Spell::EffectSummonPet(uint32 i)
4274 uint32 petentry = m_spellInfo->EffectMiscValue[i];
4276 Pet *OldSummon = m_caster->GetPet();
4278 // if pet requested type already exist
4279 if( OldSummon )
4281 if(petentry == 0 || OldSummon->GetEntry() == petentry)
4283 // pet in corpse state can't be summoned
4284 if( OldSummon->isDead() )
4285 return;
4287 OldSummon->GetMap()->Remove((Creature*)OldSummon,false);
4289 float px, py, pz;
4290 m_caster->GetClosePoint(px, py, pz, OldSummon->GetObjectSize());
4292 OldSummon->Relocate(px, py, pz, OldSummon->GetOrientation());
4293 m_caster->GetMap()->Add((Creature*)OldSummon);
4295 if(m_caster->GetTypeId() == TYPEID_PLAYER && OldSummon->isControlled() )
4297 ((Player*)m_caster)->PetSpellInitialize();
4299 return;
4302 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4303 ((Player*)m_caster)->RemovePet(OldSummon,(OldSummon->getPetType()==HUNTER_PET ? PET_SAVE_AS_DELETED : PET_SAVE_NOT_IN_SLOT),false);
4304 else
4305 return;
4308 Pet* NewSummon = new Pet;
4310 // petentry==0 for hunter "call pet" (current pet summoned if any)
4311 if(m_caster->GetTypeId() == TYPEID_PLAYER && NewSummon->LoadPetFromDB((Player*)m_caster,petentry))
4313 if(NewSummon->getPetType()==SUMMON_PET)
4315 // Remove Demonic Sacrifice auras (known pet)
4316 Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4317 for(Unit::AuraList::const_iterator itr = auraClassScripts.begin();itr!=auraClassScripts.end();)
4319 if((*itr)->GetModifier()->m_miscvalue == 2228)
4321 m_caster->RemoveAurasDueToSpell((*itr)->GetId());
4322 itr = auraClassScripts.begin();
4324 else
4325 ++itr;
4329 return;
4332 // not error in case fail hunter call pet
4333 if(!petentry)
4335 delete NewSummon;
4336 return;
4339 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(petentry);
4341 if(!cInfo)
4343 sLog.outError("EffectSummonPet: creature entry %u not found.",petentry);
4344 delete NewSummon;
4345 return;
4348 Map *map = m_caster->GetMap();
4349 uint32 pet_number = sObjectMgr.GeneratePetNumber();
4350 if(!NewSummon->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
4351 petentry, pet_number))
4353 delete NewSummon;
4354 return;
4357 float px, py, pz;
4358 m_caster->GetClosePoint(px, py, pz, NewSummon->GetObjectSize());
4360 NewSummon->Relocate(px, py, pz, m_caster->GetOrientation());
4362 if(!NewSummon->IsPositionValid())
4364 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
4365 NewSummon->GetGUIDLow(), NewSummon->GetEntry(), NewSummon->GetPositionX(), NewSummon->GetPositionY());
4366 delete NewSummon;
4367 return;
4370 uint32 petlevel = m_caster->getLevel();
4371 NewSummon->setPetType(SUMMON_PET);
4373 uint32 faction = m_caster->getFaction();
4374 if(m_caster->GetTypeId() == TYPEID_UNIT)
4376 if ( ((Creature*)m_caster)->isTotem() )
4377 NewSummon->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE);
4378 else
4379 NewSummon->GetCharmInfo()->SetReactState(REACT_DEFENSIVE);
4382 NewSummon->SetOwnerGUID(m_caster->GetGUID());
4383 NewSummon->SetCreatorGUID(m_caster->GetGUID());
4384 NewSummon->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
4385 NewSummon->setFaction(faction);
4386 NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
4387 NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
4388 NewSummon->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
4389 NewSummon->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
4390 NewSummon->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
4391 NewSummon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
4393 NewSummon->GetCharmInfo()->SetPetNumber(pet_number, true);
4394 // this enables pet details window (Shift+P)
4396 // this enables popup window (pet dismiss, cancel), hunter pet additional flags set later
4397 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4398 NewSummon->SetUInt32Value(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE);
4400 if(m_caster->IsPvP())
4401 NewSummon->SetPvP(true);
4403 NewSummon->InitStatsForLevel(petlevel, m_caster);
4404 NewSummon->InitPetCreateSpells();
4405 NewSummon->InitLevelupSpellsForLevel();
4406 NewSummon->InitTalentForLevel();
4408 if(NewSummon->getPetType()==SUMMON_PET)
4410 // Remove Demonic Sacrifice auras (new pet)
4411 Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4412 for(Unit::AuraList::const_iterator itr = auraClassScripts.begin();itr!=auraClassScripts.end();)
4414 if((*itr)->GetModifier()->m_miscvalue==2228)
4416 m_caster->RemoveAurasDueToSpell((*itr)->GetId());
4417 itr = auraClassScripts.begin();
4419 else
4420 ++itr;
4423 // generate new name for summon pet
4424 std::string new_name=sObjectMgr.GeneratePetName(petentry);
4425 if(!new_name.empty())
4426 NewSummon->SetName(new_name);
4428 else if(NewSummon->getPetType()==HUNTER_PET)
4429 NewSummon->SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_NOT_ALLOWED);
4431 NewSummon->AIM_Initialize();
4432 NewSummon->SetHealth(NewSummon->GetMaxHealth());
4433 NewSummon->SetPower(POWER_MANA, NewSummon->GetMaxPower(POWER_MANA));
4435 map->Add((Creature*)NewSummon);
4437 m_caster->SetPet(NewSummon);
4438 sLog.outDebug("New Pet has guid %u", NewSummon->GetGUIDLow());
4440 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4442 NewSummon->SavePetToDB(PET_SAVE_AS_CURRENT);
4443 ((Player*)m_caster)->PetSpellInitialize();
4447 void Spell::EffectLearnPetSpell(uint32 i)
4449 if(m_caster->GetTypeId() != TYPEID_PLAYER)
4450 return;
4452 Player *_player = (Player*)m_caster;
4454 Pet *pet = _player->GetPet();
4455 if(!pet)
4456 return;
4457 if(!pet->isAlive())
4458 return;
4460 SpellEntry const *learn_spellproto = sSpellStore.LookupEntry(m_spellInfo->EffectTriggerSpell[i]);
4461 if(!learn_spellproto)
4462 return;
4464 pet->learnSpell(learn_spellproto->Id);
4466 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
4467 _player->PetSpellInitialize();
4470 void Spell::EffectTaunt(uint32 /*i*/)
4472 if (!unitTarget)
4473 return;
4475 // this effect use before aura Taunt apply for prevent taunt already attacking target
4476 // for spell as marked "non effective at already attacking target"
4477 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4479 if (unitTarget->getVictim()==m_caster)
4481 SendCastResult(SPELL_FAILED_DONT_REPORT);
4482 return;
4486 // Also use this effect to set the taunter's threat to the taunted creature's highest value
4487 if (unitTarget->CanHaveThreatList() && unitTarget->getThreatManager().getCurrentVictim())
4488 unitTarget->getThreatManager().addThreat(m_caster,unitTarget->getThreatManager().getCurrentVictim()->getThreat());
4491 void Spell::EffectWeaponDmg(uint32 i)
4493 if(!unitTarget)
4494 return;
4495 if(!unitTarget->isAlive())
4496 return;
4498 // multiple weapon dmg effect workaround
4499 // execute only the last weapon damage
4500 // and handle all effects at once
4501 for (int j = 0; j < 3; ++j)
4503 switch(m_spellInfo->Effect[j])
4505 case SPELL_EFFECT_WEAPON_DAMAGE:
4506 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
4507 case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
4508 case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
4509 if (j < i) // we must calculate only at last weapon effect
4510 return;
4511 break;
4515 // some spell specific modifiers
4516 bool spellBonusNeedWeaponDamagePercentMod = false; // if set applied weapon damage percent mode to spell bonus
4518 float weaponDamagePercentMod = 1.0f; // applied to weapon damage and to fixed effect damage bonus
4519 float totalDamagePercentMod = 1.0f; // applied to final bonus+weapon damage
4520 bool normalized = false;
4522 int32 spell_bonus = 0; // bonus specific for spell
4523 switch(m_spellInfo->SpellFamilyName)
4525 case SPELLFAMILY_WARRIOR:
4527 // Devastate bonus and sunder armor refresh
4528 if(m_spellInfo->SpellVisual[0] == 12295 && m_spellInfo->SpellIconID == 1508)
4530 uint32 stack = 0;
4531 // Need refresh all Sunder Armor auras from this caster
4532 Unit::AuraMap& suAuras = unitTarget->GetAuras();
4533 SpellEntry const *spellInfo;
4534 for(Unit::AuraMap::iterator itr = suAuras.begin(); itr != suAuras.end(); ++itr)
4536 spellInfo = (*itr).second->GetSpellProto();
4537 if( spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR &&
4538 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000004000)) &&
4539 (*itr).second->GetCasterGUID() == m_caster->GetGUID())
4541 (*itr).second->RefreshAura();
4542 stack = (*itr).second->GetStackAmount();
4543 break;
4546 if (stack)
4547 spell_bonus += stack * CalculateDamage(2, unitTarget);
4548 if (!stack || stack < spellInfo->StackAmount)
4549 // Devastate causing Sunder Armor Effect
4550 // and no need to cast over max stack amount
4551 m_caster->CastSpell(unitTarget, 58567, true);
4553 break;
4555 case SPELLFAMILY_ROGUE:
4557 // Mutilate (for each hand)
4558 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x600000000))
4560 bool found = false;
4561 // fast check
4562 if(unitTarget->HasAuraState(AURA_STATE_DEADLY_POISON))
4563 found = true;
4564 // full aura scan
4565 else
4567 Unit::AuraMap const& auras = unitTarget->GetAuras();
4568 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
4570 if(itr->second->GetSpellProto()->Dispel == DISPEL_POISON)
4572 found = true;
4573 break;
4578 if(found)
4579 totalDamagePercentMod *= 1.2f; // 120% if poisoned
4581 // Fan of Knives
4582 else if (m_caster->GetTypeId()==TYPEID_PLAYER && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0004000000000000)))
4584 Item* weapon = ((Player*)m_caster)->GetWeaponForAttack(m_attackType,true,true);
4585 if (weapon && weapon->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER)
4586 totalDamagePercentMod *= 1.5f; // 150% to daggers
4588 break;
4590 case SPELLFAMILY_PALADIN:
4592 // Seal of Command - receive benefit from Spell Damage and Healing
4593 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x00000002000000))
4595 spellBonusNeedWeaponDamagePercentMod = true;// apply weaponDamagePercentMod to spell_bonus (and then to all bonus, fixes and weapon already have applied)
4596 spell_bonus += int32(0.23f*m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo)));
4597 spell_bonus += int32(0.29f*m_caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellInfo), unitTarget));
4599 break;
4601 case SPELLFAMILY_SHAMAN:
4603 // Skyshatter Harness item set bonus
4604 // Stormstrike
4605 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x001000000000))
4607 Unit::AuraList const& m_OverrideClassScript = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4608 for(Unit::AuraList::const_iterator citr = m_OverrideClassScript.begin(); citr != m_OverrideClassScript.end(); ++citr)
4610 // Stormstrike AP Buff
4611 if ( (*citr)->GetModifier()->m_miscvalue == 5634 )
4613 m_caster->CastSpell(m_caster, 38430, true, NULL, *citr);
4614 break;
4618 break;
4620 case SPELLFAMILY_DEATHKNIGHT:
4622 // Blood Strike, Heart Strike, Obliterate
4623 // Blood-Caked Strike, Scourge Strike
4624 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0002000001400000) ||
4625 m_spellInfo->SpellIconID == 1736 || m_spellInfo->SpellIconID == 3143)
4627 uint32 count = 0;
4628 Unit::AuraMap const& auras = unitTarget->GetAuras();
4629 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
4631 if(itr->second->GetSpellProto()->Dispel == DISPEL_DISEASE &&
4632 itr->second->GetCasterGUID() == m_caster->GetGUID() &&
4633 IsSpellLastAuraEffect(itr->second->GetSpellProto(), itr->second->GetEffIndex()))
4634 ++count;
4637 if (count)
4639 // Effect 1(for Blood-Caked Strike)/3(other) damage is bonus
4640 float bonus = count * CalculateDamage(m_spellInfo->SpellIconID == 1736 ? 0 : 2, unitTarget) / 100.0f;
4641 // Blood Strike, Blood-Caked Strike and Obliterate store bonus*2
4642 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0002000000400000) ||
4643 m_spellInfo->SpellIconID == 1736)
4644 bonus /= 2.0f;
4646 totalDamagePercentMod *= 1.0f + bonus;
4649 // Glyph of Blood Strike
4650 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000400000) &&
4651 m_caster->HasAura(59332) &&
4652 unitTarget->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED))
4654 totalDamagePercentMod *= 1.2f; // 120% if snared
4656 // Glyph of Death Strike
4657 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000010) &&
4658 m_caster->HasAura(59336))
4660 int32 rp = m_caster->GetPower(POWER_RUNIC_POWER) / 10;
4661 if(rp > 25)
4662 rp = 25;
4663 totalDamagePercentMod *= 1.0f + rp / 100.0f;
4665 // Glyph of Plague Strike
4666 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000001) &&
4667 m_caster->HasAura(58657) )
4669 totalDamagePercentMod *= 1.2f;
4671 break;
4675 int32 fixed_bonus = 0;
4676 for (int j = 0; j < 3; ++j)
4678 switch(m_spellInfo->Effect[j])
4680 case SPELL_EFFECT_WEAPON_DAMAGE:
4681 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
4682 fixed_bonus += CalculateDamage(j, unitTarget);
4683 break;
4684 case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
4685 fixed_bonus += CalculateDamage(j, unitTarget);
4686 normalized = true;
4687 break;
4688 case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
4689 weaponDamagePercentMod *= float(CalculateDamage(j, unitTarget)) / 100.0f;
4691 // applied only to prev.effects fixed damage
4692 fixed_bonus = int32(fixed_bonus*weaponDamagePercentMod);
4693 break;
4694 default:
4695 break; // not weapon damage effect, just skip
4699 // apply weaponDamagePercentMod to spell bonus also
4700 if(spellBonusNeedWeaponDamagePercentMod)
4701 spell_bonus = int32(spell_bonus*weaponDamagePercentMod);
4703 // non-weapon damage
4704 int32 bonus = spell_bonus + fixed_bonus;
4706 // apply to non-weapon bonus weapon total pct effect, weapon total flat effect included in weapon damage
4707 if(bonus)
4709 UnitMods unitMod;
4710 switch(m_attackType)
4712 default:
4713 case BASE_ATTACK: unitMod = UNIT_MOD_DAMAGE_MAINHAND; break;
4714 case OFF_ATTACK: unitMod = UNIT_MOD_DAMAGE_OFFHAND; break;
4715 case RANGED_ATTACK: unitMod = UNIT_MOD_DAMAGE_RANGED; break;
4718 float weapon_total_pct = m_caster->GetModifierValue(unitMod, TOTAL_PCT);
4719 bonus = int32(bonus*weapon_total_pct);
4722 // + weapon damage with applied weapon% dmg to base weapon damage in call
4723 bonus += int32(m_caster->CalculateDamage(m_attackType, normalized)*weaponDamagePercentMod);
4725 // total damage
4726 bonus = int32(bonus*totalDamagePercentMod);
4728 // prevent negative damage
4729 m_damage+= uint32(bonus > 0 ? bonus : 0);
4731 // Hemorrhage
4732 if (m_spellInfo->SpellFamilyName==SPELLFAMILY_ROGUE && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x2000000)))
4734 if(m_caster->GetTypeId()==TYPEID_PLAYER)
4735 ((Player*)m_caster)->AddComboPoints(unitTarget, 1);
4737 // Mangle (Cat): CP
4738 else if (m_spellInfo->SpellFamilyName==SPELLFAMILY_DRUID && (m_spellInfo->SpellFamilyFlags==UI64LIT(0x0000040000000000)))
4740 if(m_caster->GetTypeId()==TYPEID_PLAYER)
4741 ((Player*)m_caster)->AddComboPoints(unitTarget, 1);
4743 else if(m_spellInfo->SpellFamilyName==SPELLFAMILY_PALADIN)
4745 // Judgement of Blood/of the Martyr backlash damage (33%)
4746 if(m_spellInfo->SpellFamilyFlags & 0x0000000800000000LL && m_spellInfo->SpellIconID==153)
4748 int32 damagePoint = m_damage * 33 / 100;
4749 if(m_spellInfo->Id == 31898)
4750 m_caster->CastCustomSpell(m_caster, 32220, &damagePoint, NULL, NULL, true);
4751 else
4752 m_caster->CastCustomSpell(m_caster, 53725, &damagePoint, NULL, NULL, true);
4756 // take ammo
4757 if(m_attackType == RANGED_ATTACK && m_caster->GetTypeId() == TYPEID_PLAYER)
4759 Item *pItem = ((Player*)m_caster)->GetWeaponForAttack(RANGED_ATTACK, true, false);
4761 // wands don't have ammo
4762 if (!pItem || pItem->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_WAND)
4763 return;
4765 if (pItem->GetProto()->InventoryType == INVTYPE_THROWN)
4767 if(pItem->GetMaxStackCount()==1)
4769 // decrease durability for non-stackable throw weapon
4770 ((Player*)m_caster)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_RANGED);
4772 else
4774 // decrease items amount for stackable throw weapon
4775 uint32 count = 1;
4776 ((Player*)m_caster)->DestroyItemCount( pItem, count, true);
4779 else if(uint32 ammo = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID))
4780 ((Player*)m_caster)->DestroyItemCount(ammo, 1, true);
4784 void Spell::EffectThreat(uint32 /*i*/)
4786 if(!unitTarget || !unitTarget->isAlive() || !m_caster->isAlive())
4787 return;
4789 if(!unitTarget->CanHaveThreatList())
4790 return;
4792 unitTarget->AddThreat(m_caster, float(damage), false, GetSpellSchoolMask(m_spellInfo), m_spellInfo);
4795 void Spell::EffectHealMaxHealth(uint32 /*i*/)
4797 if(!unitTarget)
4798 return;
4799 if(!unitTarget->isAlive())
4800 return;
4802 uint32 heal = m_caster->GetMaxHealth();
4804 m_healing += heal;
4807 void Spell::EffectInterruptCast(uint32 /*i*/)
4809 if(!unitTarget)
4810 return;
4811 if(!unitTarget->isAlive())
4812 return;
4814 // TODO: not all spells that used this effect apply cooldown at school spells
4815 // also exist case: apply cooldown to interrupted cast only and to all spells
4816 for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
4818 if (Spell* spell = unitTarget->GetCurrentSpell(CurrentSpellTypes(i)))
4820 SpellEntry const* curSpellInfo = spell->m_spellInfo;
4821 // check if we can interrupt spell
4822 if ((curSpellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_INTERRUPT) && curSpellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE )
4824 unitTarget->ProhibitSpellScholl(GetSpellSchoolMask(curSpellInfo), GetSpellDuration(m_spellInfo));
4825 unitTarget->InterruptSpell(CurrentSpellTypes(i),false);
4831 void Spell::EffectSummonObjectWild(uint32 i)
4833 uint32 gameobject_id = m_spellInfo->EffectMiscValue[i];
4835 GameObject* pGameObj = new GameObject;
4837 WorldObject* target = focusObject;
4838 if( !target )
4839 target = m_caster;
4841 float x, y, z;
4842 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
4844 x = m_targets.m_destX;
4845 y = m_targets.m_destY;
4846 z = m_targets.m_destZ;
4848 else
4849 m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE);
4851 Map *map = target->GetMap();
4853 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id, map,
4854 m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
4856 delete pGameObj;
4857 return;
4860 int32 duration = GetSpellDuration(m_spellInfo);
4862 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
4863 pGameObj->SetSpellId(m_spellInfo->Id);
4865 // Wild object not have owner and check clickable by players
4866 map->Add(pGameObj);
4868 if(pGameObj->GetGoType() == GAMEOBJECT_TYPE_FLAGDROP && m_caster->GetTypeId() == TYPEID_PLAYER)
4870 Player *pl = (Player*)m_caster;
4871 BattleGround* bg = ((Player *)m_caster)->GetBattleGround();
4873 switch(pGameObj->GetMapId())
4875 case 489: //WS
4877 if(bg && bg->GetTypeID()==BATTLEGROUND_WS && bg->GetStatus() == STATUS_IN_PROGRESS)
4879 uint32 team = ALLIANCE;
4881 if(pl->GetTeam() == team)
4882 team = HORDE;
4884 ((BattleGroundWS*)bg)->SetDroppedFlagGUID(pGameObj->GetGUID(),team);
4886 break;
4888 case 566: //EY
4890 if(bg && bg->GetTypeID()==BATTLEGROUND_EY && bg->GetStatus() == STATUS_IN_PROGRESS)
4892 ((BattleGroundEY*)bg)->SetDroppedFlagGUID(pGameObj->GetGUID());
4894 break;
4899 if(uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry())
4901 GameObject* linkedGO = new GameObject;
4902 if(linkedGO->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, map,
4903 m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
4905 linkedGO->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
4906 linkedGO->SetSpellId(m_spellInfo->Id);
4908 // Wild object not have owner and check clickable by players
4909 map->Add(linkedGO);
4911 else
4913 delete linkedGO;
4914 linkedGO = NULL;
4915 return;
4920 void Spell::EffectScriptEffect(uint32 effIndex)
4922 // TODO: we must implement hunter pet summon at login there (spell 6962)
4924 switch(m_spellInfo->SpellFamilyName)
4926 case SPELLFAMILY_GENERIC:
4928 switch(m_spellInfo->Id)
4930 // PX-238 Winter Wondervolt TRAP
4931 case 26275:
4933 uint32 spells[4] = { 26272, 26157, 26273, 26274 };
4935 // check presence
4936 for(int j = 0; j < 4; ++j)
4937 if(unitTarget->HasAura(spells[j],0))
4938 return;
4940 // select spell
4941 uint32 iTmpSpellId = spells[urand(0,3)];
4943 // cast
4944 unitTarget->CastSpell(unitTarget, iTmpSpellId, true);
4945 return;
4947 // Bending Shinbone
4948 case 8856:
4950 if(!itemTarget && m_caster->GetTypeId()!=TYPEID_PLAYER)
4951 return;
4953 uint32 spell_id = 0;
4954 switch(urand(1, 5))
4956 case 1: spell_id = 8854; break;
4957 default: spell_id = 8855; break;
4960 m_caster->CastSpell(m_caster,spell_id,true,NULL);
4961 return;
4963 // Brittle Armor - need remove one 24575 Brittle Armor aura
4964 case 24590:
4965 unitTarget->RemoveSingleSpellAurasFromStack(24575);
4966 return;
4967 // Mercurial Shield - need remove one 26464 Mercurial Shield aura
4968 case 26465:
4969 unitTarget->RemoveSingleSpellAurasFromStack(26464);
4970 return;
4971 // Orb teleport spells
4972 case 25140:
4973 case 25143:
4974 case 25650:
4975 case 25652:
4976 case 29128:
4977 case 29129:
4978 case 35376:
4979 case 35727:
4981 if(!unitTarget)
4982 return;
4984 uint32 spellid;
4985 switch(m_spellInfo->Id)
4987 case 25140: spellid = 32571; break;
4988 case 25143: spellid = 32572; break;
4989 case 25650: spellid = 30140; break;
4990 case 25652: spellid = 30141; break;
4991 case 29128: spellid = 32568; break;
4992 case 29129: spellid = 32569; break;
4993 case 35376: spellid = 25649; break;
4994 case 35727: spellid = 35730; break;
4995 default:
4996 return;
4999 unitTarget->CastSpell(unitTarget,spellid,false);
5000 return;
5002 // Shadow Flame (All script effects, not just end ones to prevent player from dodging the last triggered spell)
5003 case 22539:
5004 case 22972:
5005 case 22975:
5006 case 22976:
5007 case 22977:
5008 case 22978:
5009 case 22979:
5010 case 22980:
5011 case 22981:
5012 case 22982:
5013 case 22983:
5014 case 22984:
5015 case 22985:
5017 if(!unitTarget || !unitTarget->isAlive())
5018 return;
5020 // Onyxia Scale Cloak
5021 if(unitTarget->GetDummyAura(22683))
5022 return;
5024 // Shadow Flame
5025 m_caster->CastSpell(unitTarget, 22682, true);
5026 return;
5028 // Summon Black Qiraji Battle Tank
5029 case 26656:
5031 if(!unitTarget)
5032 return;
5034 // Prevent stacking of mounts
5035 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
5037 // Two separate mounts depending on area id (allows use both in and out of specific instance)
5038 if (unitTarget->GetAreaId() == 3428)
5039 unitTarget->CastSpell(unitTarget, 25863, false);
5040 else
5041 unitTarget->CastSpell(unitTarget, 26655, false);
5042 return;
5044 // Piccolo of the Flaming Fire
5045 case 17512:
5047 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5048 return;
5049 unitTarget->HandleEmoteCommand(EMOTE_STATE_DANCE);
5050 return;
5052 // Demonic Empowerment (succubus Vanish effect)
5053 case 54436:
5055 if(!unitTarget)
5056 return;
5058 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
5059 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
5060 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STALKED);
5061 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STUN);
5062 return;
5064 // Escape artist
5065 case 20589:
5067 if(!unitTarget)
5068 return;
5070 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
5071 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
5072 return;
5074 // Mirren's Drinking Hat
5075 case 29830:
5077 uint32 item = 0;
5078 switch ( urand(1, 6) )
5080 case 1:
5081 case 2:
5082 case 3:
5083 item = 23584; break; // Loch Modan Lager
5084 case 4:
5085 case 5:
5086 item = 23585; break; // Stouthammer Lite
5087 case 6:
5088 item = 23586; break; // Aerie Peak Pale Ale
5090 if (item)
5091 DoCreateItem(effIndex,item);
5092 break;
5094 // Improved Sprint
5095 case 30918:
5097 if(!unitTarget)
5098 return;
5099 // Removes snares and roots.
5100 unitTarget->RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK,30918,true);
5101 break;
5103 // Flame Crash
5104 case 41126:
5106 if(!unitTarget)
5107 return;
5109 unitTarget->CastSpell(unitTarget, 41131, true);
5110 break;
5112 // Force Cast - Portal Effect: Sunwell Isle
5113 case 44876:
5115 if(!unitTarget)
5116 return;
5118 unitTarget->CastSpell(unitTarget, 44870, true);
5119 break;
5121 // Goblin Weather Machine
5122 case 46203:
5124 if(!unitTarget)
5125 return;
5127 uint32 spellId = 0;
5128 switch(rand() % 4)
5130 case 0: spellId = 46740; break;
5131 case 1: spellId = 46739; break;
5132 case 2: spellId = 46738; break;
5133 case 3: spellId = 46736; break;
5135 unitTarget->CastSpell(unitTarget, spellId, true);
5136 break;
5138 //5,000 Gold
5139 case 46642:
5141 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5142 return;
5144 ((Player*)unitTarget)->ModifyMoney(50000000);
5146 break;
5148 // Emblazon Runeblade
5149 case 51770:
5151 if(!m_originalCaster)
5152 return;
5154 m_originalCaster->CastSpell(m_originalCaster, damage, false);
5155 break;
5157 // Death Gate
5158 case 52751:
5160 if(!unitTarget || unitTarget->getClass() != CLASS_DEATH_KNIGHT)
5161 return;
5162 // triggered spell is stored in m_spellInfo->EffectBasePoints[0]
5163 unitTarget->CastSpell(unitTarget, damage, false);
5164 break;
5166 // Winged Steed of the Ebon Blade
5167 case 54729:
5169 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5170 return;
5172 // Prevent stacking of mounts
5173 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
5175 // Triggered spell id dependent of riding skill
5176 if(uint16 skillval = ((Player*)unitTarget)->GetSkillValue(SKILL_RIDING))
5178 if (skillval >= 300)
5179 unitTarget->CastSpell(unitTarget, 54727, true);
5180 else
5181 unitTarget->CastSpell(unitTarget, 54726, true);
5183 return;
5185 case 55693: // Remove Collapsing Cave Aura
5186 if(!unitTarget)
5187 return;
5188 unitTarget->RemoveAurasDueToSpell(m_spellInfo->CalculateSimpleValue(effIndex));
5189 break;
5190 case 58418: // Portal to Orgrimmar
5191 case 58420: // Portal to Stormwind
5193 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER || effIndex!=0)
5194 return;
5196 uint32 spellID = m_spellInfo->CalculateSimpleValue(0);
5197 uint32 questID = m_spellInfo->CalculateSimpleValue(1);
5199 if (((Player*)unitTarget)->GetQuestStatus(questID) == QUEST_STATUS_COMPLETE && !((Player*)unitTarget)->GetQuestRewardStatus (questID))
5200 unitTarget->CastSpell(unitTarget, spellID, true);
5202 return;
5204 case 59317: // Teleporting
5205 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5206 return;
5208 // return from top
5209 if (((Player*)unitTarget)->GetAreaId() == 4637)
5210 unitTarget->CastSpell(unitTarget, 59316, true);
5211 // teleport atop
5212 else
5213 unitTarget->CastSpell(unitTarget, 59314, true);
5215 return;
5216 // random spell learn instead placeholder
5217 case 60893: // Northrend Alchemy Research
5218 case 61177: // Northrend Inscription Research
5219 case 61288: // Minor Inscription Research
5220 case 61756: // Northrend Inscription Research (FAST QA VERSION)
5221 case 64323: // Book of Glyph Mastery
5223 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5224 return;
5226 // learn random explicit discovery recipe (if any)
5227 if(uint32 discoveredSpell = GetExplicitDiscoverySpell(m_spellInfo->Id, (Player*)m_caster))
5228 ((Player*)m_caster)->learnSpell(discoveredSpell, false);
5229 return;
5232 break;
5234 case SPELLFAMILY_WARLOCK:
5236 switch(m_spellInfo->Id)
5238 // Healthstone creating spells
5239 case 6201:
5240 case 6202:
5241 case 5699:
5242 case 11729:
5243 case 11730:
5244 case 27230:
5245 case 47871:
5246 case 47878:
5248 if(!unitTarget)
5249 return;
5250 uint32 itemtype;
5251 uint32 rank = 0;
5252 Unit::AuraList const& mDummyAuras = unitTarget->GetAurasByType(SPELL_AURA_DUMMY);
5253 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
5255 if((*i)->GetId() == 18692)
5257 rank = 1;
5258 break;
5260 else if((*i)->GetId() == 18693)
5262 rank = 2;
5263 break;
5267 static uint32 const itypes[8][3] = {
5268 { 5512, 19004, 19005}, // Minor Healthstone
5269 { 5511, 19006, 19007}, // Lesser Healthstone
5270 { 5509, 19008, 19009}, // Healthstone
5271 { 5510, 19010, 19011}, // Greater Healthstone
5272 { 9421, 19012, 19013}, // Major Healthstone
5273 {22103, 22104, 22105}, // Master Healthstone
5274 {36889, 36890, 36891}, // Demonic Healthstone
5275 {36892, 36893, 36894} // Fel Healthstone
5278 switch(m_spellInfo->Id)
5280 case 6201:
5281 itemtype=itypes[0][rank];break; // Minor Healthstone
5282 case 6202:
5283 itemtype=itypes[1][rank];break; // Lesser Healthstone
5284 case 5699:
5285 itemtype=itypes[2][rank];break; // Healthstone
5286 case 11729:
5287 itemtype=itypes[3][rank];break; // Greater Healthstone
5288 case 11730:
5289 itemtype=itypes[4][rank];break; // Major Healthstone
5290 case 27230:
5291 itemtype=itypes[5][rank];break; // Master Healthstone
5292 case 47871:
5293 itemtype=itypes[6][rank];break; // Demonic Healthstone
5294 case 47878:
5295 itemtype=itypes[7][rank];break; // Fel Healthstone
5296 default:
5297 return;
5299 DoCreateItem( effIndex, itemtype );
5300 return;
5302 // Demonic Empowerment
5303 case 47193:
5305 if(!unitTarget)
5306 return;
5307 uint32 entry = unitTarget->GetEntry();
5308 uint32 spellID;
5309 switch(entry)
5311 case 416: spellID = 54444; break; //imp
5312 case 417: spellID = 54509; break; //fellhunter
5313 case 1860: spellID = 54443; break; //void
5314 case 1863: spellID = 54435; break; //succubus
5315 case 17252: spellID = 54508; break; //fellguard
5316 default:
5317 return;
5319 unitTarget->CastSpell(unitTarget,spellID,true);
5320 return;
5322 // Everlasting Affliction
5323 case 47422:
5325 // Need refresh caster corruption auras on target
5326 Unit::AuraMap& suAuras = unitTarget->GetAuras();
5327 for(Unit::AuraMap::iterator itr = suAuras.begin(); itr != suAuras.end(); ++itr)
5329 SpellEntry const *spellInfo = (*itr).second->GetSpellProto();
5330 if(spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK &&
5331 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000002)) &&
5332 (*itr).second->GetCasterGUID()==m_caster->GetGUID())
5333 (*itr).second->RefreshAura();
5335 return;
5337 // Guarded by The Light (Paladin spell with SPELLFAMILY_WARLOCK)
5338 case 63521:
5340 // Divine Plea, refresh on target (3 aura slots)
5341 if (Aura* aura = unitTarget->GetAura(54428,0))
5342 aura->RefreshAura();
5343 return;
5346 break;
5348 case SPELLFAMILY_PRIEST:
5350 switch(m_spellInfo->Id)
5352 // Pain and Suffering
5353 case 47948:
5355 if (!unitTarget)
5356 return;
5357 // Refresh Shadow Word: Pain on target
5358 Unit::AuraMap& auras = unitTarget->GetAuras();
5359 for(Unit::AuraMap::iterator itr = auras.begin(); itr != auras.end(); ++itr)
5361 SpellEntry const *spellInfo = (*itr).second->GetSpellProto();
5362 if (spellInfo->SpellFamilyName == SPELLFAMILY_PRIEST &&
5363 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000008000)) &&
5364 (*itr).second->GetCasterGUID() == m_caster->GetGUID())
5366 (*itr).second->RefreshAura();
5367 return;
5370 return;
5372 default:
5373 break;
5375 break;
5377 case SPELLFAMILY_HUNTER:
5379 switch(m_spellInfo->Id)
5381 // Chimera Shot
5382 case 53209:
5384 if(!unitTarget)
5385 return;
5386 uint32 spellId = 0;
5387 int32 basePoint = 0;
5388 Unit* target = unitTarget;
5389 Unit::AuraMap& Auras = unitTarget->GetAuras();
5390 for(Unit::AuraMap::iterator i = Auras.begin(); i != Auras.end(); ++i)
5392 Aura *aura = (*i).second;
5393 if (aura->GetCasterGUID() != m_caster->GetGUID())
5394 continue;
5395 // Search only Serpent Sting, Viper Sting, Scorpid Sting auras
5396 uint64 familyFlag = aura->GetSpellProto()->SpellFamilyFlags;
5397 if (!(familyFlag & UI64LIT(0x000000800000C000)))
5398 continue;
5399 // Refresh aura duration
5400 aura->RefreshAura();
5402 // Serpent Sting - Instantly deals 40% of the damage done by your Serpent Sting.
5403 if ((familyFlag & UI64LIT(0x0000000000004000)) && aura->GetEffIndex() == 0)
5405 // m_amount already include RAP bonus
5406 basePoint = aura->GetModifier()->m_amount * 5 * 40 / 100;
5407 spellId = 53353; // Chimera Shot - Serpent
5409 // Viper Sting - Instantly restores mana to you equal to 60% of the total amount drained by your Viper Sting.
5410 if ((familyFlag & UI64LIT(0x0000008000000000)) && aura->GetEffIndex() == 0)
5412 uint32 target_max_mana = unitTarget->GetMaxPower(POWER_MANA);
5413 if (!target_max_mana)
5414 continue;
5416 // ignore non positive values (can be result apply spellmods to aura damage
5417 uint32 pdamage = aura->GetModifier()->m_amount > 0 ? aura->GetModifier()->m_amount : 0;
5419 // Special case: draining x% of mana (up to a maximum of 2*x% of the caster's maximum mana)
5420 uint32 maxmana = m_caster->GetMaxPower(POWER_MANA) * pdamage * 2 / 100;
5422 pdamage = target_max_mana * pdamage / 100;
5423 if (pdamage > maxmana)
5424 pdamage = maxmana;
5426 pdamage *= 4; // total aura damage
5427 basePoint = pdamage * 60 / 100;
5428 spellId = 53358; // Chimera Shot - Viper
5429 target = m_caster;
5431 // Scorpid Sting - Attempts to Disarm the target for 10 sec. This effect cannot occur more than once per 1 minute.
5432 if (familyFlag & UI64LIT(0x0000000000008000))
5433 spellId = 53359; // Chimera Shot - Scorpid
5434 // ?? nothing say in spell desc (possibly need addition check)
5435 //if ((familyFlag & UI64LIT(0x0000010000000000)) || // dot
5436 // (familyFlag & UI64LIT(0x0000100000000000))) // stun
5438 // spellId = 53366; // 53366 Chimera Shot - Wyvern
5441 if (spellId)
5442 m_caster->CastCustomSpell(target, spellId, &basePoint, 0, 0, false);
5443 return;
5445 case 53412: // Invigoration (pet triggered script, master targeted)
5447 if (!unitTarget)
5448 return;
5450 Unit::AuraList const& auras = unitTarget->GetAurasByType(SPELL_AURA_DUMMY);
5451 for(Unit::AuraList::const_iterator i = auras.begin();i != auras.end(); ++i)
5453 // Invigoration (master talent)
5454 if ((*i)->GetModifier()->m_miscvalue == 8 && (*i)->GetSpellProto()->SpellIconID == 3487)
5456 if (roll_chance_i((*i)->GetModifier()->m_amount))
5458 unitTarget->CastSpell(unitTarget, 53398, true, NULL, (*i), m_caster->GetGUID());
5459 break;
5463 return;
5465 // Master's Call
5466 case 53271:
5468 if (!unitTarget)
5469 return;
5471 // script effect have in value, but this outdated removed part
5472 unitTarget->CastSpell(unitTarget, 62305, true);
5473 return;
5475 default:
5476 break;
5478 break;
5480 case SPELLFAMILY_PALADIN:
5482 // Judgement (seal trigger)
5483 if (m_spellInfo->Category == SPELLCATEGORY_JUDGEMENT)
5485 if(!unitTarget || !unitTarget->isAlive())
5486 return;
5487 uint32 spellId1 = 0;
5488 uint32 spellId2 = 0;
5490 // Judgement self add switch
5491 switch (m_spellInfo->Id)
5493 case 53407: spellId1 = 20184; break; // Judgement of Justice
5494 case 20271: // Judgement of Light
5495 case 57774: spellId1 = 20185; break; // Judgement of Light
5496 case 53408: spellId1 = 20186; break; // Judgement of Wisdom
5497 default:
5498 sLog.outError("Unsupported Judgement (seal trigger) spell (Id: %u) in Spell::EffectScriptEffect",m_spellInfo->Id);
5499 return;
5501 // offensive seals have aura dummy in 2 effect
5502 Unit::AuraList const& m_dummyAuras = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
5503 for(Unit::AuraList::const_iterator itr = m_dummyAuras.begin(); itr != m_dummyAuras.end(); ++itr)
5505 // search seal (offensive seals have judgement's aura dummy spell id in 2 effect
5506 if ((*itr)->GetEffIndex() != 2 || !IsSealSpell((*itr)->GetSpellProto()))
5507 continue;
5508 spellId2 = (*itr)->GetModifier()->m_amount;
5509 SpellEntry const *judge = sSpellStore.LookupEntry(spellId2);
5510 if (!judge)
5511 continue;
5512 break;
5514 // if there were no offensive seals than there is seal with proc trigger aura
5515 if (!spellId2)
5517 Unit::AuraList const& procTriggerAuras = m_caster->GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL);
5518 for(Unit::AuraList::const_iterator itr = procTriggerAuras.begin(); itr != procTriggerAuras.end(); ++itr)
5520 if ((*itr)->GetEffIndex() != 0 || !IsSealSpell((*itr)->GetSpellProto()))
5521 continue;
5522 spellId2 = 54158;
5523 break;
5526 if (spellId1)
5527 m_caster->CastSpell(unitTarget, spellId1, true);
5528 if (spellId2)
5529 m_caster->CastSpell(unitTarget, spellId2, true);
5530 return;
5533 case SPELLFAMILY_POTION:
5535 switch(m_spellInfo->Id)
5537 // Dreaming Glory
5538 case 28698:
5540 if(!unitTarget)
5541 return;
5542 unitTarget->CastSpell(unitTarget, 28694, true);
5543 break;
5545 // Netherbloom
5546 case 28702:
5548 if(!unitTarget)
5549 return;
5550 // 25% chance of casting a random buff
5551 if(roll_chance_i(75))
5552 return;
5554 // triggered spells are 28703 to 28707
5555 // Note: some sources say, that there was the possibility of
5556 // receiving a debuff. However, this seems to be removed by a patch.
5557 const uint32 spellid = 28703;
5559 // don't overwrite an existing aura
5560 for(uint8 i = 0; i < 5; ++i)
5561 if(unitTarget->HasAura(spellid + i, 0))
5562 return;
5563 unitTarget->CastSpell(unitTarget, spellid+urand(0, 4), true);
5564 break;
5567 // Nightmare Vine
5568 case 28720:
5570 if(!unitTarget)
5571 return;
5572 // 25% chance of casting Nightmare Pollen
5573 if(roll_chance_i(75))
5574 return;
5575 unitTarget->CastSpell(unitTarget, 28721, true);
5576 break;
5579 break;
5581 case SPELLFAMILY_DEATHKNIGHT:
5583 switch(m_spellInfo->Id)
5585 // Pestilence
5586 case 50842:
5588 if(!unitTarget)
5589 return;
5591 Unit* mainTarget = m_targets.getUnitTarget();
5592 if(!mainTarget)
5593 return;
5595 // do only refresh diseases on main target if caster has Glyph of Disease
5596 if(mainTarget == unitTarget && !m_caster->HasAura(63334))
5597 return;
5599 // Blood Plague
5600 if(mainTarget->HasAura(55078))
5601 m_caster->CastSpell(unitTarget, 55078, true);
5603 // Frost Fever
5604 if(mainTarget->HasAura(55095))
5605 m_caster->CastSpell(unitTarget, 55095, true);
5607 break;
5610 break;
5614 // normal DB scripted effect
5615 if(!unitTarget)
5616 return;
5618 sLog.outDebug("Spell ScriptStart spellid %u in EffectScriptEffect ", m_spellInfo->Id);
5619 m_caster->GetMap()->ScriptsStart(sSpellScripts, m_spellInfo->Id, m_caster, unitTarget);
5622 void Spell::EffectSanctuary(uint32 /*i*/)
5624 if(!unitTarget)
5625 return;
5626 //unitTarget->CombatStop();
5628 unitTarget->CombatStop();
5629 unitTarget->getHostileRefManager().deleteReferences(); // stop all fighting
5630 // Vanish allows to remove all threat and cast regular stealth so other spells can be used
5631 if(m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && (m_spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE_VANISH))
5633 ((Player *)m_caster)->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
5637 void Spell::EffectAddComboPoints(uint32 /*i*/)
5639 if(!unitTarget)
5640 return;
5642 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5643 return;
5645 if(damage <= 0)
5646 return;
5648 ((Player*)m_caster)->AddComboPoints(unitTarget, damage);
5651 void Spell::EffectDuel(uint32 i)
5653 if(!m_caster || !unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER || unitTarget->GetTypeId() != TYPEID_PLAYER)
5654 return;
5656 Player *caster = (Player*)m_caster;
5657 Player *target = (Player*)unitTarget;
5659 // caster or target already have requested duel
5660 if( caster->duel || target->duel || !target->GetSocial() || target->GetSocial()->HasIgnore(caster->GetGUIDLow()) )
5661 return;
5663 // Players can only fight a duel with each other outside (=not inside dungeons and not in capital cities)
5664 // Don't have to check the target's map since you cannot challenge someone across maps
5665 uint32 mapid = caster->GetMapId();
5666 if( mapid != 0 && mapid != 1 && mapid != 530 && mapid != 571 && mapid != 609)
5668 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5669 return;
5672 AreaTableEntry const* casterAreaEntry = GetAreaEntryByAreaID(caster->GetZoneId());
5673 if(casterAreaEntry && (casterAreaEntry->flags & AREA_FLAG_CAPITAL) )
5675 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5676 return;
5679 AreaTableEntry const* targetAreaEntry = GetAreaEntryByAreaID(target->GetZoneId());
5680 if(targetAreaEntry && (targetAreaEntry->flags & AREA_FLAG_CAPITAL) )
5682 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5683 return;
5686 //CREATE DUEL FLAG OBJECT
5687 GameObject* pGameObj = new GameObject;
5689 uint32 gameobject_id = m_spellInfo->EffectMiscValue[i];
5691 Map *map = m_caster->GetMap();
5692 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id,
5693 map, m_caster->GetPhaseMask(),
5694 m_caster->GetPositionX()+(unitTarget->GetPositionX()-m_caster->GetPositionX())/2 ,
5695 m_caster->GetPositionY()+(unitTarget->GetPositionY()-m_caster->GetPositionY())/2 ,
5696 m_caster->GetPositionZ(),
5697 m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
5699 delete pGameObj;
5700 return;
5703 pGameObj->SetUInt32Value(GAMEOBJECT_FACTION, m_caster->getFaction() );
5704 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()+1 );
5705 int32 duration = GetSpellDuration(m_spellInfo);
5706 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
5707 pGameObj->SetSpellId(m_spellInfo->Id);
5709 m_caster->AddGameObject(pGameObj);
5710 map->Add(pGameObj);
5711 //END
5713 // Send request
5714 WorldPacket data(SMSG_DUEL_REQUESTED, 8 + 8);
5715 data << uint64(pGameObj->GetGUID());
5716 data << uint64(caster->GetGUID());
5717 caster->GetSession()->SendPacket(&data);
5718 target->GetSession()->SendPacket(&data);
5720 // create duel-info
5721 DuelInfo *duel = new DuelInfo;
5722 duel->initiator = caster;
5723 duel->opponent = target;
5724 duel->startTime = 0;
5725 duel->startTimer = 0;
5726 caster->duel = duel;
5728 DuelInfo *duel2 = new DuelInfo;
5729 duel2->initiator = caster;
5730 duel2->opponent = caster;
5731 duel2->startTime = 0;
5732 duel2->startTimer = 0;
5733 target->duel = duel2;
5735 caster->SetUInt64Value(PLAYER_DUEL_ARBITER, pGameObj->GetGUID());
5736 target->SetUInt64Value(PLAYER_DUEL_ARBITER, pGameObj->GetGUID());
5739 void Spell::EffectStuck(uint32 /*i*/)
5741 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5742 return;
5744 if(!sWorld.getConfig(CONFIG_CAST_UNSTUCK))
5745 return;
5747 Player* pTarget = (Player*)unitTarget;
5749 sLog.outDebug("Spell Effect: Stuck");
5750 sLog.outDetail("Player %s (guid %u) used auto-unstuck future at map %u (%f, %f, %f)", pTarget->GetName(), pTarget->GetGUIDLow(), m_caster->GetMapId(), m_caster->GetPositionX(), pTarget->GetPositionY(), pTarget->GetPositionZ());
5752 if(pTarget->isInFlight())
5753 return;
5755 // homebind location is loaded always
5756 pTarget->TeleportToHomebind(unitTarget==m_caster ? TELE_TO_SPELL : 0);
5758 // Stuck spell trigger Hearthstone cooldown
5759 SpellEntry const *spellInfo = sSpellStore.LookupEntry(8690);
5760 if(!spellInfo)
5761 return;
5762 Spell spell(pTarget, spellInfo, true, 0);
5763 spell.SendSpellCooldown();
5766 void Spell::EffectSummonPlayer(uint32 /*i*/)
5768 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5769 return;
5771 // Evil Twin (ignore player summon, but hide this for summoner)
5772 if(unitTarget->GetDummyAura(23445))
5773 return;
5775 float x, y, z;
5776 m_caster->GetClosePoint(x, y, z, unitTarget->GetObjectSize());
5778 ((Player*)unitTarget)->SetSummonPoint(m_caster->GetMapId(),x,y,z);
5780 WorldPacket data(SMSG_SUMMON_REQUEST, 8+4+4);
5781 data << uint64(m_caster->GetGUID()); // summoner guid
5782 data << uint32(m_caster->GetZoneId()); // summoner zone
5783 data << uint32(MAX_PLAYER_SUMMON_DELAY*IN_MILISECONDS); // auto decline after msecs
5784 ((Player*)unitTarget)->GetSession()->SendPacket(&data);
5787 static ScriptInfo generateActivateCommand()
5789 ScriptInfo si;
5790 si.command = SCRIPT_COMMAND_ACTIVATE_OBJECT;
5791 return si;
5794 void Spell::EffectActivateObject(uint32 effect_idx)
5796 if(!gameObjTarget)
5797 return;
5799 static ScriptInfo activateCommand = generateActivateCommand();
5801 int32 delay_secs = m_spellInfo->EffectMiscValue[effect_idx];
5803 gameObjTarget->GetMap()->ScriptCommandStart(activateCommand, delay_secs, m_caster, gameObjTarget);
5806 void Spell::EffectApplyGlyph(uint32 i)
5808 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5809 return;
5811 Player *player = (Player*)m_caster;
5813 // apply new one
5814 if(uint32 glyph = m_spellInfo->EffectMiscValue[i])
5816 if(GlyphPropertiesEntry const *gp = sGlyphPropertiesStore.LookupEntry(glyph))
5818 if(GlyphSlotEntry const *gs = sGlyphSlotStore.LookupEntry(player->GetGlyphSlot(m_glyphIndex)))
5820 if(gp->TypeFlags != gs->TypeFlags)
5822 SendCastResult(SPELL_FAILED_INVALID_GLYPH);
5823 return; // glyph slot mismatch
5827 // remove old glyph
5828 if(uint32 oldglyph = player->GetGlyph(m_glyphIndex))
5830 if(GlyphPropertiesEntry const *old_gp = sGlyphPropertiesStore.LookupEntry(oldglyph))
5832 player->RemoveAurasDueToSpell(old_gp->SpellId);
5833 player->SetGlyph(m_glyphIndex, 0);
5837 player->CastSpell(m_caster, gp->SpellId, true);
5838 player->SetGlyph(m_glyphIndex, glyph);
5839 player->SendTalentsInfoData(false);
5844 void Spell::EffectSummonTotem(uint32 i, uint8 slot)
5846 slot = slot ? (slot - 1): 255;
5848 if(slot < MAX_TOTEM)
5850 uint64 guid = m_caster->m_TotemSlot[slot];
5851 if(guid != 0)
5853 Creature *OldTotem = m_caster->GetMap()->GetCreature(guid);
5854 if(OldTotem && OldTotem->isTotem())
5855 ((Totem*)OldTotem)->UnSummon();
5859 uint32 team = 0;
5860 if (m_caster->GetTypeId()==TYPEID_PLAYER)
5861 team = ((Player*)m_caster)->GetTeam();
5863 Totem* pTotem = new Totem;
5865 if(!pTotem->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), m_caster->GetMap(), m_caster->GetPhaseMask(),
5866 m_spellInfo->EffectMiscValue[i], team ))
5868 delete pTotem;
5869 return;
5872 float angle = slot < MAX_TOTEM ? M_PI/MAX_TOTEM - (slot*2*M_PI/MAX_TOTEM) : 0;
5874 float x, y, z;
5875 m_caster->GetClosePoint(x, y, z, pTotem->GetObjectSize(), 2.0f, angle);
5877 // totem must be at same Z in case swimming caster and etc.
5878 if( fabs( z - m_caster->GetPositionZ() ) > 5 )
5879 z = m_caster->GetPositionZ();
5881 pTotem->Relocate(x, y, z, m_caster->GetOrientation());
5883 if(slot < MAX_TOTEM)
5884 m_caster->m_TotemSlot[slot] = pTotem->GetGUID();
5886 pTotem->SetOwner(m_caster->GetGUID());
5887 pTotem->SetTypeBySummonSpell(m_spellInfo); // must be after Create call where m_spells initilized
5889 int32 duration=GetSpellDuration(m_spellInfo);
5890 if(Player* modOwner = m_caster->GetSpellModOwner())
5891 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
5892 pTotem->SetDuration(duration);
5894 if (damage) // if not spell info, DB values used
5896 pTotem->SetMaxHealth(damage);
5897 pTotem->SetHealth(damage);
5900 pTotem->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
5902 if(m_caster->GetTypeId() == TYPEID_PLAYER)
5903 pTotem->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
5905 if(m_caster->IsPvP())
5906 pTotem->SetPvP(true);
5908 pTotem->Summon(m_caster);
5910 if(slot < MAX_TOTEM && m_caster->GetTypeId() == TYPEID_PLAYER)
5912 WorldPacket data(SMSG_TOTEM_CREATED, 1 + 8 + 4 + 4);
5913 data << uint8(slot);
5914 data << uint64(pTotem->GetGUID());
5915 data << uint32(duration);
5916 data << uint32(m_spellInfo->Id);
5917 ((Player*)m_caster)->SendDirectMessage(&data);
5921 void Spell::EffectEnchantHeldItem(uint32 i)
5923 // this is only item spell effect applied to main-hand weapon of target player (players in area)
5924 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5925 return;
5927 Player* item_owner = (Player*)unitTarget;
5928 Item* item = item_owner->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
5930 if(!item )
5931 return;
5933 // must be equipped
5934 if(!item ->IsEquipped())
5935 return;
5937 if (m_spellInfo->EffectMiscValue[i])
5939 uint32 enchant_id = m_spellInfo->EffectMiscValue[i];
5940 int32 duration = GetSpellDuration(m_spellInfo); //Try duration index first ..
5941 if(!duration)
5942 duration = m_currentBasePoints[i]+1; //Base points after ..
5943 if(!duration)
5944 duration = 10; //10 seconds for enchants which don't have listed duration
5946 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
5947 if(!pEnchant)
5948 return;
5950 // Always go to temp enchantment slot
5951 EnchantmentSlot slot = TEMP_ENCHANTMENT_SLOT;
5953 // Enchantment will not be applied if a different one already exists
5954 if(item->GetEnchantmentId(slot) && item->GetEnchantmentId(slot) != enchant_id)
5955 return;
5957 // Apply the temporary enchantment
5958 item->SetEnchantment(slot, enchant_id, duration*IN_MILISECONDS, 0);
5959 item_owner->ApplyEnchantment(item, slot, true);
5963 void Spell::EffectDisEnchant(uint32 /*i*/)
5965 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5966 return;
5968 Player* p_caster = (Player*)m_caster;
5969 if(!itemTarget || !itemTarget->GetProto()->DisenchantID)
5970 return;
5972 p_caster->UpdateCraftSkill(m_spellInfo->Id);
5974 ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(),LOOT_DISENCHANTING);
5976 // item will be removed at disenchanting end
5979 void Spell::EffectInebriate(uint32 /*i*/)
5981 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5982 return;
5984 Player *player = (Player*)unitTarget;
5985 uint16 currentDrunk = player->GetDrunkValue();
5986 uint16 drunkMod = damage * 256;
5987 if (currentDrunk + drunkMod > 0xFFFF)
5988 currentDrunk = 0xFFFF;
5989 else
5990 currentDrunk += drunkMod;
5991 player->SetDrunkValue(currentDrunk, m_CastItem ? m_CastItem->GetEntry() : 0);
5994 void Spell::EffectFeedPet(uint32 i)
5996 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5997 return;
5999 Player *_player = (Player*)m_caster;
6001 Item* foodItem = m_targets.getItemTarget();
6002 if(!foodItem)
6003 return;
6005 Pet *pet = _player->GetPet();
6006 if(!pet)
6007 return;
6009 if(!pet->isAlive())
6010 return;
6012 int32 benefit = pet->GetCurrentFoodBenefitLevel(foodItem->GetProto()->ItemLevel);
6013 if(benefit <= 0)
6014 return;
6016 uint32 count = 1;
6017 _player->DestroyItemCount(foodItem,count,true);
6018 // TODO: fix crash when a spell has two effects, both pointed at the same item target
6020 m_caster->CastCustomSpell(pet, m_spellInfo->EffectTriggerSpell[i], &benefit, NULL, NULL, true);
6023 void Spell::EffectDismissPet(uint32 /*i*/)
6025 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6026 return;
6028 Pet* pet = m_caster->GetPet();
6030 // not let dismiss dead pet
6031 if(!pet||!pet->isAlive())
6032 return;
6034 ((Player*)m_caster)->RemovePet(pet, PET_SAVE_NOT_IN_SLOT);
6037 void Spell::EffectSummonObject(uint32 i)
6039 uint32 go_id = m_spellInfo->EffectMiscValue[i];
6041 uint8 slot = 0;
6042 switch(m_spellInfo->Effect[i])
6044 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1: slot = 0; break;
6045 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2: slot = 1; break;
6046 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3: slot = 2; break;
6047 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4: slot = 3; break;
6048 default: return;
6051 if(uint64 guid = m_caster->m_ObjectSlot[slot])
6053 if(GameObject* obj = m_caster ? m_caster->GetMap()->GetGameObject(guid) : NULL)
6054 obj->SetLootState(GO_JUST_DEACTIVATED);
6055 m_caster->m_ObjectSlot[slot] = 0;
6058 GameObject* pGameObj = new GameObject;
6060 float x, y, z;
6061 // If dest location if present
6062 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6064 x = m_targets.m_destX;
6065 y = m_targets.m_destY;
6066 z = m_targets.m_destZ;
6068 // Summon in random point all other units if location present
6069 else
6070 m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE);
6072 Map *map = m_caster->GetMap();
6073 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), go_id, map,
6074 m_caster->GetPhaseMask(), x, y, z, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
6076 delete pGameObj;
6077 return;
6080 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL,m_caster->getLevel());
6081 int32 duration = GetSpellDuration(m_spellInfo);
6082 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
6083 pGameObj->SetSpellId(m_spellInfo->Id);
6084 m_caster->AddGameObject(pGameObj);
6086 map->Add(pGameObj);
6088 m_caster->m_ObjectSlot[slot] = pGameObj->GetGUID();
6091 void Spell::EffectResurrect(uint32 /*effIndex*/)
6093 if(!unitTarget)
6094 return;
6095 if(unitTarget->GetTypeId() != TYPEID_PLAYER)
6096 return;
6098 if(unitTarget->isAlive())
6099 return;
6100 if(!unitTarget->IsInWorld())
6101 return;
6103 switch (m_spellInfo->Id)
6105 // Defibrillate (Goblin Jumper Cables) have 33% chance on success
6106 case 8342:
6107 if (roll_chance_i(67))
6109 m_caster->CastSpell(m_caster, 8338, true, m_CastItem);
6110 return;
6112 break;
6113 // Defibrillate (Goblin Jumper Cables XL) have 50% chance on success
6114 case 22999:
6115 if (roll_chance_i(50))
6117 m_caster->CastSpell(m_caster, 23055, true, m_CastItem);
6118 return;
6120 break;
6121 default:
6122 break;
6125 Player* pTarget = ((Player*)unitTarget);
6127 if(pTarget->isRessurectRequested()) // already have one active request
6128 return;
6130 uint32 health = pTarget->GetMaxHealth() * damage / 100;
6131 uint32 mana = pTarget->GetMaxPower(POWER_MANA) * damage / 100;
6133 pTarget->setResurrectRequestData(m_caster->GetGUID(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), health, mana);
6134 SendResurrectRequest(pTarget);
6137 void Spell::EffectAddExtraAttacks(uint32 /*i*/)
6139 if(!unitTarget || !unitTarget->isAlive())
6140 return;
6142 if( unitTarget->m_extraAttacks )
6143 return;
6145 unitTarget->m_extraAttacks = damage;
6148 void Spell::EffectParry(uint32 /*i*/)
6150 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6151 ((Player*)unitTarget)->SetCanParry(true);
6154 void Spell::EffectBlock(uint32 /*i*/)
6156 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6157 ((Player*)unitTarget)->SetCanBlock(true);
6160 void Spell::EffectLeapForward(uint32 i)
6162 if(unitTarget->isInFlight())
6163 return;
6165 if( m_spellInfo->rangeIndex == 1) //self range
6167 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
6169 // before caster
6170 float fx, fy, fz;
6171 unitTarget->GetClosePoint(fx, fy, fz, unitTarget->GetObjectSize(), dis);
6172 float ox, oy, oz;
6173 unitTarget->GetPosition(ox, oy, oz);
6175 float fx2, fy2, fz2; // getObjectHitPos overwrite last args in any result case
6176 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(unitTarget->GetMapId(), ox,oy,oz+0.5, fx,fy,oz+0.5,fx2,fy2,fz2, -0.5))
6178 fx = fx2;
6179 fy = fy2;
6180 fz = fz2;
6181 unitTarget->UpdateGroundPositionZ(fx, fy, fz);
6184 unitTarget->NearTeleportTo(fx, fy, fz, unitTarget->GetOrientation(), unitTarget == m_caster);
6188 void Spell::EffectLeapBack(uint32 i)
6190 if(unitTarget->isInFlight())
6191 return;
6193 m_caster->KnockBackFrom(unitTarget,float(m_spellInfo->EffectMiscValue[i])/10,float(damage)/10);
6196 void Spell::EffectReputation(uint32 i)
6198 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6199 return;
6201 Player *_player = (Player*)unitTarget;
6203 int32 rep_change = m_currentBasePoints[i]+1; // field store reputation change -1
6205 uint32 faction_id = m_spellInfo->EffectMiscValue[i];
6207 FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id);
6209 if(!factionEntry)
6210 return;
6212 _player->GetReputationMgr().ModifyReputation(factionEntry, rep_change);
6215 void Spell::EffectQuestComplete(uint32 i)
6217 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6218 return;
6220 Player *_player = (Player*)m_caster;
6222 uint32 quest_id = m_spellInfo->EffectMiscValue[i];
6223 _player->AreaExploredOrEventHappens(quest_id);
6226 void Spell::EffectSelfResurrect(uint32 i)
6228 if(!unitTarget || unitTarget->isAlive())
6229 return;
6230 if(unitTarget->GetTypeId() != TYPEID_PLAYER)
6231 return;
6232 if(!unitTarget->IsInWorld())
6233 return;
6235 uint32 health = 0;
6236 uint32 mana = 0;
6238 // flat case
6239 if(damage < 0)
6241 health = uint32(-damage);
6242 mana = m_spellInfo->EffectMiscValue[i];
6244 // percent case
6245 else
6247 health = uint32(damage/100.0f*unitTarget->GetMaxHealth());
6248 if(unitTarget->GetMaxPower(POWER_MANA) > 0)
6249 mana = uint32(damage/100.0f*unitTarget->GetMaxPower(POWER_MANA));
6252 Player *plr = ((Player*)unitTarget);
6253 plr->ResurrectPlayer(0.0f);
6255 plr->SetHealth( health );
6256 plr->SetPower(POWER_MANA, mana );
6257 plr->SetPower(POWER_RAGE, 0 );
6258 plr->SetPower(POWER_ENERGY, plr->GetMaxPower(POWER_ENERGY) );
6260 plr->SpawnCorpseBones();
6263 void Spell::EffectSkinning(uint32 /*i*/)
6265 if(unitTarget->GetTypeId() != TYPEID_UNIT )
6266 return;
6267 if(!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER)
6268 return;
6270 Creature* creature = (Creature*) unitTarget;
6271 int32 targetLevel = creature->getLevel();
6273 uint32 skill = creature->GetCreatureInfo()->GetRequiredLootSkill();
6275 ((Player*)m_caster)->SendLoot(creature->GetGUID(),LOOT_SKINNING);
6276 creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
6278 int32 reqValue = targetLevel < 10 ? 0 : targetLevel < 20 ? (targetLevel-10)*10 : targetLevel*5;
6280 int32 skillValue = ((Player*)m_caster)->GetPureSkillValue(skill);
6282 // Double chances for elites
6283 ((Player*)m_caster)->UpdateGatherSkill(skill, skillValue, reqValue, creature->isElite() ? 2 : 1 );
6286 void Spell::EffectCharge(uint32 /*i*/)
6288 if (!unitTarget)
6289 return;
6291 //TODO: research more ContactPoint/attack distance.
6292 //3.666666 instead of ATTACK_DISTANCE(5.0f) in below seem to give more accurate result.
6293 float x, y, z;
6294 unitTarget->GetContactPoint(m_caster, x, y, z, 3.666666f);
6296 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6297 ((Creature *)unitTarget)->StopMoving();
6299 // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
6300 m_caster->SendMonsterMove(x, y, z, 0, m_caster->GetTypeId()==TYPEID_PLAYER ? MONSTER_MOVE_WALK : ((Creature*)m_caster)->GetMonsterMoveFlags(), 1);
6302 if (m_caster->GetTypeId() != TYPEID_PLAYER)
6303 m_caster->GetMap()->CreatureRelocation((Creature*)m_caster,x,y,z,m_caster->GetOrientation());
6305 // not all charge effects used in negative spells
6306 if (unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
6307 m_caster->Attack(unitTarget,true);
6310 void Spell::EffectCharge2(uint32 /*i*/)
6312 float x, y, z;
6313 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6315 x = m_targets.m_destX;
6316 y = m_targets.m_destY;
6317 z = m_targets.m_destZ;
6319 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6320 ((Creature *)unitTarget)->StopMoving();
6322 else if (unitTarget && unitTarget != m_caster)
6323 unitTarget->GetContactPoint(m_caster, x, y, z, 3.666666f);
6324 else
6325 return;
6327 // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
6328 m_caster->SendMonsterMove(x, y, z, 0, m_caster->GetTypeId()==TYPEID_PLAYER ? MONSTER_MOVE_WALK : ((Creature*)m_caster)->GetMonsterMoveFlags(), 1);
6330 if (m_caster->GetTypeId() != TYPEID_PLAYER)
6331 m_caster->GetMap()->CreatureRelocation((Creature*)m_caster,x,y,z,m_caster->GetOrientation());
6333 // not all charge effects used in negative spells
6334 if (unitTarget && unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
6335 m_caster->Attack(unitTarget,true);
6338 void Spell::EffectSummonCritter(uint32 i, uint32 forceFaction)
6340 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6341 return;
6342 Player* player = (Player*)m_caster;
6344 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
6345 if(!pet_entry)
6346 return;
6348 Pet* old_critter = player->GetMiniPet();
6350 // for same pet just despawn
6351 if(old_critter && old_critter->GetEntry() == pet_entry)
6353 player->RemoveMiniPet();
6354 return;
6357 // despawn old pet before summon new
6358 if(old_critter)
6359 player->RemoveMiniPet();
6361 // summon new pet
6362 Pet* critter = new Pet(MINI_PET);
6364 Map *map = m_caster->GetMap();
6365 uint32 pet_number = sObjectMgr.GeneratePetNumber();
6366 if(!critter->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
6367 pet_entry, pet_number))
6369 sLog.outError("Spell::EffectSummonCritter, spellid %u: no such creature entry %u", m_spellInfo->Id, pet_entry);
6370 delete critter;
6371 return;
6374 float x, y, z;
6375 // If dest location if present
6376 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6378 x = m_targets.m_destX;
6379 y = m_targets.m_destY;
6380 z = m_targets.m_destZ;
6382 // Summon if dest location not present near caster
6383 else
6384 m_caster->GetClosePoint(x, y, z, critter->GetObjectSize());
6386 critter->Relocate(x, y, z, m_caster->GetOrientation());
6388 if(!critter->IsPositionValid())
6390 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
6391 critter->GetGUIDLow(), critter->GetEntry(), critter->GetPositionX(), critter->GetPositionY());
6392 delete critter;
6393 return;
6396 critter->SetOwnerGUID(m_caster->GetGUID());
6397 critter->SetCreatorGUID(m_caster->GetGUID());
6399 critter->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
6400 critter->setFaction(forceFaction ? forceFaction : m_caster->getFaction());
6401 critter->AIM_Initialize();
6402 critter->InitPetCreateSpells(); // e.g. disgusting oozeling has a create spell as critter...
6403 //critter->InitLevelupSpellsForLevel(); // none?
6404 critter->SelectLevel(critter->GetCreatureInfo()); // some summoned creaters have different from 1 DB data for level/hp
6405 critter->SetUInt32Value(UNIT_NPC_FLAGS, critter->GetCreatureInfo()->npcflag);
6406 // some mini-pets have quests
6408 // set timer for unsummon
6409 int32 duration = GetSpellDuration(m_spellInfo);
6410 if(duration > 0)
6411 critter->SetDuration(duration);
6413 std::string name = player->GetName();
6414 name.append(petTypeSuffix[critter->getPetType()]);
6415 critter->SetName( name );
6416 player->SetMiniPet(critter);
6418 map->Add((Creature*)critter);
6421 void Spell::EffectKnockBack(uint32 i)
6423 if(!unitTarget)
6424 return;
6426 unitTarget->KnockBackFrom(m_caster,float(m_spellInfo->EffectMiscValue[i])/10,float(damage)/10);
6429 void Spell::EffectSendTaxi(uint32 i)
6431 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6432 return;
6434 ((Player*)unitTarget)->ActivateTaxiPathTo(m_spellInfo->EffectMiscValue[i],m_spellInfo->Id);
6437 void Spell::EffectPlayerPull(uint32 i)
6439 if(!unitTarget)
6440 return;
6442 float dist = unitTarget->GetDistance2d(m_caster);
6443 if (damage && dist > damage)
6444 dist = damage;
6446 unitTarget->KnockBackFrom(m_caster,-dist,float(m_spellInfo->EffectMiscValue[i])/10);
6449 void Spell::EffectDispelMechanic(uint32 i)
6451 if(!unitTarget)
6452 return;
6454 uint32 mechanic = m_spellInfo->EffectMiscValue[i];
6456 Unit::AuraMap& Auras = unitTarget->GetAuras();
6457 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
6459 next = iter;
6460 ++next;
6461 SpellEntry const *spell = sSpellStore.LookupEntry(iter->second->GetSpellProto()->Id);
6462 if(spell->Mechanic == mechanic || spell->EffectMechanic[iter->second->GetEffIndex()] == mechanic)
6464 unitTarget->RemoveAurasDueToSpell(spell->Id);
6465 if(Auras.empty())
6466 break;
6467 else
6468 next = Auras.begin();
6471 return;
6474 void Spell::EffectSummonDeadPet(uint32 /*i*/)
6476 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6477 return;
6478 Player *_player = (Player*)m_caster;
6479 Pet *pet = _player->GetPet();
6480 if(!pet)
6481 return;
6482 if(pet->isAlive())
6483 return;
6484 if(damage < 0)
6485 return;
6486 pet->SetUInt32Value(UNIT_DYNAMIC_FLAGS, 0);
6487 pet->RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
6488 pet->setDeathState( ALIVE );
6489 pet->clearUnitState(UNIT_STAT_ALL_STATE);
6490 pet->SetHealth( uint32(pet->GetMaxHealth()*(float(damage)/100)));
6492 pet->AIM_Initialize();
6494 // _player->PetSpellInitialize(); -- action bar not removed at death and not required send at revive
6495 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
6498 void Spell::EffectDestroyAllTotems(uint32 /*i*/)
6500 int32 mana = 0;
6501 for(int slot = 0; slot < MAX_TOTEM; ++slot)
6503 if(!m_caster->m_TotemSlot[slot])
6504 continue;
6506 Creature* totem = m_caster->GetMap()->GetCreature(m_caster->m_TotemSlot[slot]);
6507 if(totem && totem->isTotem())
6509 uint32 spell_id = totem->GetUInt32Value(UNIT_CREATED_BY_SPELL);
6510 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
6511 if(spellInfo)
6513 uint32 manacost = m_caster->GetCreateMana() * spellInfo->ManaCostPercentage / 100;
6514 mana += manacost * damage / 100;
6516 ((Totem*)totem)->UnSummon();
6520 if (mana)
6521 m_caster->CastCustomSpell(m_caster, 39104, &mana, NULL, NULL, true);
6524 void Spell::EffectDurabilityDamage(uint32 i)
6526 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6527 return;
6529 int32 slot = m_spellInfo->EffectMiscValue[i];
6531 // FIXME: some spells effects have value -1/-2
6532 // Possibly its mean -1 all player equipped items and -2 all items
6533 if(slot < 0)
6535 ((Player*)unitTarget)->DurabilityPointsLossAll(damage, (slot < -1));
6536 return;
6539 // invalid slot value
6540 if(slot >= INVENTORY_SLOT_BAG_END)
6541 return;
6543 if(Item* item = ((Player*)unitTarget)->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
6544 ((Player*)unitTarget)->DurabilityPointsLoss(item, damage);
6547 void Spell::EffectDurabilityDamagePCT(uint32 i)
6549 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6550 return;
6552 int32 slot = m_spellInfo->EffectMiscValue[i];
6554 // FIXME: some spells effects have value -1/-2
6555 // Possibly its mean -1 all player equipped items and -2 all items
6556 if(slot < 0)
6558 ((Player*)unitTarget)->DurabilityLossAll(double(damage)/100.0f, (slot < -1));
6559 return;
6562 // invalid slot value
6563 if(slot >= INVENTORY_SLOT_BAG_END)
6564 return;
6566 if(damage <= 0)
6567 return;
6569 if(Item* item = ((Player*)unitTarget)->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
6570 ((Player*)unitTarget)->DurabilityLoss(item, double(damage)/100.0f);
6573 void Spell::EffectModifyThreatPercent(uint32 /*effIndex*/)
6575 if(!unitTarget)
6576 return;
6578 unitTarget->getThreatManager().modifyThreatPercent(m_caster, damage);
6581 void Spell::EffectTransmitted(uint32 effIndex)
6583 uint32 name_id = m_spellInfo->EffectMiscValue[effIndex];
6585 GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(name_id);
6587 if (!goinfo)
6589 sLog.outErrorDb("Gameobject (Entry: %u) not exist and not created at spell (ID: %u) cast",name_id, m_spellInfo->Id);
6590 return;
6593 float fx, fy, fz;
6595 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6597 fx = m_targets.m_destX;
6598 fy = m_targets.m_destY;
6599 fz = m_targets.m_destZ;
6601 //FIXME: this can be better check for most objects but still hack
6602 else if(m_spellInfo->EffectRadiusIndex[effIndex] && m_spellInfo->speed==0)
6604 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[effIndex]));
6605 m_caster->GetClosePoint(fx, fy, fz, DEFAULT_WORLD_OBJECT_SIZE, dis);
6607 else
6609 float min_dis = GetSpellMinRange(sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex));
6610 float max_dis = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex));
6611 float dis = rand_norm() * (max_dis - min_dis) + min_dis;
6613 m_caster->GetClosePoint(fx, fy, fz, DEFAULT_WORLD_OBJECT_SIZE, dis);
6616 Map *cMap = m_caster->GetMap();
6618 if(goinfo->type==GAMEOBJECT_TYPE_FISHINGNODE)
6620 if ( !cMap->IsInWater(fx, fy, fz-0.5f)) // Hack to prevent fishing bobber from failing to land on fishing hole
6621 { // but this is not proper, we really need to ignore not materialized objects
6622 SendCastResult(SPELL_FAILED_NOT_HERE);
6623 SendChannelUpdate(0);
6624 return;
6627 // replace by water level in this case
6628 fz = cMap->GetWaterLevel(fx, fy);
6630 // if gameobject is summoning object, it should be spawned right on caster's position
6631 else if(goinfo->type==GAMEOBJECT_TYPE_SUMMONING_RITUAL)
6633 m_caster->GetPosition(fx, fy, fz);
6636 GameObject* pGameObj = new GameObject;
6638 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), name_id, cMap,
6639 m_caster->GetPhaseMask(), fx, fy, fz, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
6641 delete pGameObj;
6642 return;
6645 int32 duration = GetSpellDuration(m_spellInfo);
6647 switch(goinfo->type)
6649 case GAMEOBJECT_TYPE_FISHINGNODE:
6651 m_caster->SetChannelObjectGUID(pGameObj->GetGUID());
6652 m_caster->AddGameObject(pGameObj); // will removed at spell cancel
6654 // end time of range when possible catch fish (FISHING_BOBBER_READY_TIME..GetDuration(m_spellInfo))
6655 // start time == fish-FISHING_BOBBER_READY_TIME (0..GetDuration(m_spellInfo)-FISHING_BOBBER_READY_TIME)
6656 int32 lastSec = 0;
6657 switch(urand(0, 3))
6659 case 0: lastSec = 3; break;
6660 case 1: lastSec = 7; break;
6661 case 2: lastSec = 13; break;
6662 case 3: lastSec = 17; break;
6665 duration = duration - lastSec*IN_MILISECONDS + FISHING_BOBBER_READY_TIME*IN_MILISECONDS;
6666 break;
6668 case GAMEOBJECT_TYPE_SUMMONING_RITUAL:
6670 if(m_caster->GetTypeId() == TYPEID_PLAYER)
6672 pGameObj->AddUniqueUse((Player*)m_caster);
6673 m_caster->AddGameObject(pGameObj); // will removed at spell cancel
6675 break;
6677 case GAMEOBJECT_TYPE_FISHINGHOLE:
6678 case GAMEOBJECT_TYPE_CHEST:
6679 default:
6680 break;
6683 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
6685 pGameObj->SetOwnerGUID(m_caster->GetGUID());
6687 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel());
6688 pGameObj->SetSpellId(m_spellInfo->Id);
6690 DEBUG_LOG("AddObject at SpellEfects.cpp EffectTransmitted");
6691 //m_caster->AddGameObject(pGameObj);
6692 //m_ObjToDel.push_back(pGameObj);
6694 cMap->Add(pGameObj);
6696 if(uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry())
6698 GameObject* linkedGO = new GameObject;
6699 if(linkedGO->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, cMap,
6700 m_caster->GetPhaseMask(), fx, fy, fz, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
6702 linkedGO->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
6703 linkedGO->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel());
6704 linkedGO->SetSpellId(m_spellInfo->Id);
6705 linkedGO->SetOwnerGUID(m_caster->GetGUID());
6707 linkedGO->GetMap()->Add(linkedGO);
6709 else
6711 delete linkedGO;
6712 linkedGO = NULL;
6713 return;
6718 void Spell::EffectProspecting(uint32 /*i*/)
6720 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6721 return;
6723 Player* p_caster = (Player*)m_caster;
6724 if(!itemTarget || !(itemTarget->GetProto()->BagFamily & BAG_FAMILY_MASK_MINING_SUPP))
6725 return;
6727 if(itemTarget->GetCount() < 5)
6728 return;
6730 if( sWorld.getConfig(CONFIG_SKILL_PROSPECTING))
6732 uint32 SkillValue = p_caster->GetPureSkillValue(SKILL_JEWELCRAFTING);
6733 uint32 reqSkillValue = itemTarget->GetProto()->RequiredSkillRank;
6734 p_caster->UpdateGatherSkill(SKILL_JEWELCRAFTING, SkillValue, reqSkillValue);
6737 ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(), LOOT_PROSPECTING);
6740 void Spell::EffectMilling(uint32 /*i*/)
6742 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6743 return;
6745 Player* p_caster = (Player*)m_caster;
6746 if(!itemTarget || !(itemTarget->GetProto()->BagFamily & BAG_FAMILY_MASK_HERBS))
6747 return;
6749 if(itemTarget->GetCount() < 5)
6750 return;
6752 if( sWorld.getConfig(CONFIG_SKILL_MILLING))
6754 uint32 SkillValue = p_caster->GetPureSkillValue(SKILL_INSCRIPTION);
6755 uint32 reqSkillValue = itemTarget->GetProto()->RequiredSkillRank;
6756 p_caster->UpdateGatherSkill(SKILL_INSCRIPTION, SkillValue, reqSkillValue);
6759 ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(), LOOT_MILLING);
6762 void Spell::EffectSkill(uint32 /*i*/)
6764 sLog.outDebug("WORLD: SkillEFFECT");
6767 void Spell::EffectSpiritHeal(uint32 /*i*/)
6769 // TODO player can't see the heal-animation - he should respawn some ticks later
6770 if (!unitTarget || unitTarget->isAlive())
6771 return;
6772 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6773 return;
6774 if (!unitTarget->IsInWorld())
6775 return;
6776 if (m_spellInfo->Id == 22012 && !unitTarget->HasAura(2584))
6777 return;
6779 ((Player*)unitTarget)->ResurrectPlayer(1.0f);
6780 ((Player*)unitTarget)->SpawnCorpseBones();
6783 // remove insignia spell effect
6784 void Spell::EffectSkinPlayerCorpse(uint32 /*i*/)
6786 sLog.outDebug("Effect: SkinPlayerCorpse");
6787 if ( (m_caster->GetTypeId() != TYPEID_PLAYER) || (unitTarget->GetTypeId() != TYPEID_PLAYER) || (unitTarget->isAlive()) )
6788 return;
6790 ((Player*)unitTarget)->RemovedInsignia( (Player*)m_caster );
6793 void Spell::EffectStealBeneficialBuff(uint32 i)
6795 sLog.outDebug("Effect: StealBeneficialBuff");
6797 if(!unitTarget || unitTarget==m_caster) // can't steal from self
6798 return;
6800 std::vector <Aura *> steal_list;
6801 // Create dispel mask by dispel type
6802 uint32 dispelMask = GetDispellMask( DispelType(m_spellInfo->EffectMiscValue[i]) );
6803 Unit::AuraMap const& auras = unitTarget->GetAuras();
6804 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
6806 Aura *aur = (*itr).second;
6807 if (aur && (1<<aur->GetSpellProto()->Dispel) & dispelMask)
6809 // Need check for passive? this
6810 if (aur->IsPositive() && !aur->IsPassive() && !(aur->GetSpellProto()->AttributesEx4 & SPELL_ATTR_EX4_NOT_STEALABLE))
6811 steal_list.push_back(aur);
6814 // Ok if exist some buffs for dispel try dispel it
6815 if (!steal_list.empty())
6817 std::list < std::pair<uint32,uint64> > success_list;
6818 int32 list_size = steal_list.size();
6819 // Dispell N = damage buffs (or while exist buffs for dispel)
6820 for (int32 count=0; count < damage && list_size > 0; ++count)
6822 // Random select buff for dispel
6823 Aura *aur = steal_list[urand(0, list_size-1)];
6824 // Not use chance for steal
6825 // TODO possible need do it
6826 success_list.push_back( std::pair<uint32,uint64>(aur->GetId(),aur->GetCasterGUID()));
6828 // Remove buff from list for prevent doubles
6829 for (std::vector<Aura *>::iterator j = steal_list.begin(); j != steal_list.end(); )
6831 Aura *stealed = *j;
6832 if (stealed->GetId() == aur->GetId() && stealed->GetCasterGUID() == aur->GetCasterGUID())
6834 j = steal_list.erase(j);
6835 --list_size;
6837 else
6838 ++j;
6841 // Really try steal and send log
6842 if (!success_list.empty())
6844 int32 count = success_list.size();
6845 WorldPacket data(SMSG_SPELLSTEALLOG, 8+8+4+1+4+count*5);
6846 data.append(unitTarget->GetPackGUID()); // Victim GUID
6847 data.append(m_caster->GetPackGUID()); // Caster GUID
6848 data << uint32(m_spellInfo->Id); // Dispell spell id
6849 data << uint8(0); // not used
6850 data << uint32(count); // count
6851 for (std::list<std::pair<uint32,uint64> >::iterator j = success_list.begin(); j != success_list.end(); ++j)
6853 SpellEntry const* spellInfo = sSpellStore.LookupEntry(j->first);
6854 data << uint32(spellInfo->Id); // Spell Id
6855 data << uint8(0); // 0 - steals !=0 transfers
6856 unitTarget->RemoveAurasDueToSpellBySteal(spellInfo->Id, j->second, m_caster);
6858 m_caster->SendMessageToSet(&data, true);
6863 void Spell::EffectKillCreditPersonal(uint32 i)
6865 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6866 return;
6868 ((Player*)unitTarget)->KilledMonsterCredit(m_spellInfo->EffectMiscValue[i], 0);
6871 void Spell::EffectKillCredit(uint32 i)
6873 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6874 return;
6876 ((Player*)unitTarget)->RewardPlayerAndGroupAtEvent(m_spellInfo->EffectMiscValue[i], unitTarget);
6879 void Spell::EffectQuestFail(uint32 i)
6881 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6882 return;
6884 ((Player*)unitTarget)->FailQuest(m_spellInfo->EffectMiscValue[i]);
6887 void Spell::EffectActivateRune(uint32 eff_idx)
6889 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6890 return;
6892 Player *plr = (Player*)m_caster;
6894 if(plr->getClass() != CLASS_DEATH_KNIGHT)
6895 return;
6897 for(uint32 j = 0; j < MAX_RUNES; ++j)
6899 if(plr->GetRuneCooldown(j) && plr->GetCurrentRune(j) == RuneType(m_spellInfo->EffectMiscValue[eff_idx]))
6901 plr->SetRuneCooldown(j, 0);
6906 void Spell::EffectTitanGrip(uint32 /*eff_idx*/)
6908 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6909 ((Player*)unitTarget)->SetCanTitanGrip(true);
6912 void Spell::EffectRenamePet(uint32 /*eff_idx*/)
6914 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT ||
6915 !((Creature*)unitTarget)->isPet() || ((Pet*)unitTarget)->getPetType() != HUNTER_PET)
6916 return;
6918 unitTarget->SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED);
6921 void Spell::EffectPlayMusic(uint32 i)
6923 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6924 return;
6926 uint32 soundid = m_spellInfo->EffectMiscValue[i];
6928 if (!sSoundEntriesStore.LookupEntry(soundid))
6930 sLog.outError("EffectPlayMusic: Sound (Id: %u) not exist in spell %u.",soundid,m_spellInfo->Id);
6931 return;
6934 WorldPacket data(SMSG_PLAY_MUSIC, 4);
6935 data << uint32(soundid);
6936 ((Player*)unitTarget)->GetSession()->SendPacket(&data);