[9130] Implement spell 48603 script effect.
[getmangos.git] / src / game / SpellEffects.cpp
blobe29eaccde15906196472e04659100251704ed1da
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #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::EffectEnvironmentalDMG, // 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::EffectEnvironmentalDMG(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 46167: // Planning for the Future: Create Snowfall Glade Pup Cover
1179 case 50926: // Gluttonous Lurkers: Create Zul'Drak Rat Cover
1180 case 51026: // Create Drakkari Medallion Cover
1181 case 51592: // Pickup Primordial Hatchling
1182 case 51961: // Captured Chicken Cover
1184 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || m_caster->GetTypeId() != TYPEID_PLAYER)
1185 return;
1187 uint32 spellId = 0;
1189 switch(m_spellInfo->Id)
1191 case 46167: spellId = 46773; break;
1192 case 50926: spellId = 50927; break;
1193 case 51026: spellId = 50737; break;
1194 case 51592: spellId = 51593; break;
1195 case 51961: spellId = 51037; break;
1198 if (const SpellEntry *pSpell = sSpellStore.LookupEntry(spellId))
1200 unitTarget->CastSpell(m_caster, spellId, true);
1202 Creature* creatureTarget = (Creature*)unitTarget;
1204 if (const SpellCastTimesEntry *pCastTime = sSpellCastTimesStore.LookupEntry(pSpell->CastingTimeIndex))
1205 creatureTarget->ForcedDespawn(pCastTime->CastTime + 1);
1207 return;
1209 case 51582: //Rocket Boots Engaged (Rocket Boots Xtreme and Rocket Boots Xtreme Lite)
1211 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1212 return;
1214 if (BattleGround* bg = ((Player*)m_caster)->GetBattleGround())
1215 bg->EventPlayerDroppedFlag((Player*)m_caster);
1217 m_caster->CastSpell(m_caster, 30452, true, NULL);
1218 return;
1220 case 52308: // Take Sputum Sample
1222 switch(i)
1224 case 0:
1226 uint32 spellID = m_spellInfo->CalculateSimpleValue(0);
1227 uint32 reqAuraID = m_spellInfo->CalculateSimpleValue(1);
1229 if (m_caster->HasAura(reqAuraID,0))
1230 m_caster->CastSpell(m_caster, spellID, true, NULL);
1231 return;
1233 case 1:
1234 return; // additional data for dummy[0]
1236 return;
1238 case 52759: // Ancestral Awakening
1239 if (!unitTarget)
1240 return;
1241 m_caster->CastCustomSpell(unitTarget, 52752, &damage, NULL, NULL, true);
1242 return;
1243 case 52845: // Brewfest Mount Transformation (Faction Swap)
1244 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1245 return;
1247 if (!m_caster->HasAuraType(SPELL_AURA_MOUNTED))
1248 return;
1250 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1252 // Ram for Horde, Kodo for Alliance
1253 if (((Player *)m_caster)->GetTeam() == HORDE)
1255 if (m_caster->GetSpeedRate(MOVE_RUN) >= 2.0f)
1256 // Swift Brewfest Ram, 100% Ram
1257 m_caster->CastSpell(m_caster, 43900, true);
1258 else
1259 // Brewfest Ram, 60% Ram
1260 m_caster->CastSpell(m_caster, 43899, true);
1262 else
1264 if (((Player *)m_caster)->GetSpeedRate(MOVE_RUN) >= 2.0f)
1265 // Great Brewfest Kodo, 100% Kodo
1266 m_caster->CastSpell(m_caster, 49379, true);
1267 else
1268 // Brewfest Riding Kodo, 60% Kodo
1269 m_caster->CastSpell(m_caster, 49378, true);
1271 return;
1272 case 53341: // Rune of Cinderglacier
1273 case 53343: // Rune of Razorice
1275 // Runeforging Credit
1276 m_caster->CastSpell(m_caster, 54586, true);
1277 return;
1279 case 55004: // Nitro Boosts
1280 if (!m_CastItem)
1281 return;
1282 if (roll_chance_i(95)) // Nitro Boosts - success
1283 m_caster->CastSpell(m_caster, 54861, true, m_CastItem);
1284 else // Knocked Up - backfire 5%
1285 m_caster->CastSpell(m_caster, 46014, true, m_CastItem);
1286 return;
1287 case 58418: // Portal to Orgrimmar
1288 case 58420: // Portal to Stormwind
1289 return; // implemented in EffectScript[0]
1290 case 59640: // Underbelly Elixir
1292 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1293 return;
1295 uint32 spell_id = 0;
1296 switch(urand(1,3))
1298 case 1: spell_id = 59645; break;
1299 case 2: spell_id = 59831; break;
1300 case 3: spell_id = 59843; break;
1302 m_caster->CastSpell(m_caster,spell_id,true,NULL);
1303 return;
1305 case 60932: // Disengage (one from creature versions)
1306 if (!unitTarget)
1307 return;
1308 m_caster->CastSpell(unitTarget,60934,true,NULL);
1309 return;
1310 case 67019: // Flask of the North
1312 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1313 return;
1315 uint32 spell_id = 0;
1316 switch(m_caster->getClass())
1318 case CLASS_WARRIOR:
1319 case CLASS_DEATH_KNIGHT:
1320 spell_id = 67018; // STR for Warriors, Death Knights
1321 break;
1322 case CLASS_ROGUE:
1323 case CLASS_HUNTER:
1324 spell_id = 67017; // AP for Rogues, Hunters
1325 break;
1326 case CLASS_PRIEST:
1327 case CLASS_MAGE:
1328 case CLASS_WARLOCK:
1329 spell_id = 67016; // SPD for Priests, Mages, Warlocks
1330 break;
1331 case CLASS_SHAMAN:
1332 // random (SPD, AP)
1333 spell_id = roll_chance_i(50) ? 67016 : 67017;
1334 break;
1335 case CLASS_PALADIN:
1336 case CLASS_DRUID:
1337 default:
1338 // random (SPD, STR)
1339 spell_id = roll_chance_i(50) ? 67016 : 67018;
1340 break;
1342 m_caster->CastSpell(m_caster, spell_id, true);
1343 return;
1346 break;
1348 case SPELLFAMILY_MAGE:
1349 switch(m_spellInfo->Id )
1351 case 11958: // Cold Snap
1353 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1354 return;
1356 // immediately finishes the cooldown on Frost spells
1357 const SpellCooldowns& cm = ((Player *)m_caster)->GetSpellCooldownMap();
1358 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1360 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1362 if (spellInfo->SpellFamilyName == SPELLFAMILY_MAGE &&
1363 (GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_FROST) &&
1364 spellInfo->Id != 11958 && GetSpellRecoveryTime(spellInfo) > 0)
1366 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first, true);
1368 else
1369 ++itr;
1371 return;
1373 case 32826: // Polymorph Cast Visual
1375 if (unitTarget && unitTarget->GetTypeId() == TYPEID_UNIT)
1377 //Polymorph Cast Visual Rank 1
1378 const uint32 spell_list[6] = {
1379 32813, // Squirrel Form
1380 32816, // Giraffe Form
1381 32817, // Serpent Form
1382 32818, // Dragonhawk Form
1383 32819, // Worgen Form
1384 32820 // Sheep Form
1386 unitTarget->CastSpell( unitTarget, spell_list[urand(0, 5)], true);
1388 return;
1391 break;
1392 case SPELLFAMILY_WARRIOR:
1393 // Charge
1394 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x1)) && m_spellInfo->SpellVisual[0] == 867)
1396 int32 chargeBasePoints0 = damage;
1397 m_caster->CastCustomSpell(m_caster, 34846, &chargeBasePoints0, NULL, NULL, true);
1398 return;
1400 // Execute
1401 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x20000000))
1403 if(!unitTarget)
1404 return;
1406 uint32 rage = m_caster->GetPower(POWER_RAGE);
1408 // up to max 30 rage cost
1409 if(rage > 300)
1410 rage = 300;
1412 // Glyph of Execution bonus
1413 uint32 rage_modified = rage;
1415 if (Aura *aura = m_caster->GetDummyAura(58367))
1416 rage_modified += aura->GetModifier()->m_amount*10;
1418 int32 basePoints0 = damage+int32(rage_modified * m_spellInfo->DmgMultiplier[i] +
1419 m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.2f);
1421 m_caster->CastCustomSpell(unitTarget, 20647, &basePoints0, NULL, NULL, true, 0);
1423 // Sudden Death
1424 if(m_caster->HasAura(52437))
1426 Unit::AuraList const& auras = m_caster->GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL);
1427 for (Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
1429 // Only Sudden Death have this SpellIconID with SPELL_AURA_PROC_TRIGGER_SPELL
1430 if ((*itr)->GetSpellProto()->SpellIconID == 1989)
1432 // saved rage top stored in next affect
1433 uint32 lastrage = (*itr)->GetSpellProto()->CalculateSimpleValue(1)*10;
1434 if(lastrage < rage)
1435 rage -= lastrage;
1436 break;
1441 m_caster->SetPower(POWER_RAGE,m_caster->GetPower(POWER_RAGE)-rage);
1442 return;
1444 // Slam
1445 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000200000))
1447 if(!unitTarget)
1448 return;
1449 m_damage+=m_caster->CalculateDamage(m_attackType, false);
1450 m_damage+=damage;
1451 return;
1453 // Concussion Blow
1454 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000004000000))
1456 m_damage+= uint32(damage * m_caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
1457 return;
1460 switch(m_spellInfo->Id)
1462 // Warrior's Wrath
1463 case 21977:
1465 if (!unitTarget)
1466 return;
1467 m_caster->CastSpell(unitTarget, 21887, true);// spell mod
1468 return;
1470 // Last Stand
1471 case 12975:
1473 int32 healthModSpellBasePoints0 = int32(m_caster->GetMaxHealth()*0.3);
1474 m_caster->CastCustomSpell(m_caster, 12976, &healthModSpellBasePoints0, NULL, NULL, true, NULL);
1475 return;
1477 // Bloodthirst
1478 case 23881:
1480 m_caster->CastCustomSpell(unitTarget, 23885, &damage, NULL, NULL, true, NULL);
1481 return;
1484 break;
1485 case SPELLFAMILY_WARLOCK:
1486 // Life Tap
1487 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000040000))
1489 // In 303 exist spirit depend
1490 uint32 spirit = uint32(m_caster->GetStat(STAT_SPIRIT));
1491 switch (m_spellInfo->Id)
1493 case 1454: damage+=spirit; break;
1494 case 1455: damage+=spirit*15/10; break;
1495 case 1456: damage+=spirit*2; break;
1496 case 11687: damage+=spirit*25/10; break;
1497 case 11688:
1498 case 11689:
1499 case 27222:
1500 case 57946: damage+=spirit*3; break;
1501 default:
1502 sLog.outError("Spell::EffectDummy: %u Life Tap need set spirit multipler", m_spellInfo->Id);
1503 return;
1505 // Think its not need (also need remove Life Tap from SpellDamageBonus or add new value)
1506 // damage = m_caster->SpellDamageBonus(m_caster, m_spellInfo,uint32(damage > 0 ? damage : 0), SPELL_DIRECT_DAMAGE);
1507 if (unitTarget && (int32(unitTarget->GetHealth()) > damage))
1509 // Shouldn't Appear in Combat Log
1510 unitTarget->ModifyHealth(-damage);
1512 int32 mana = damage;
1513 // Improved Life Tap mod
1514 Unit::AuraList const& auraDummy = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
1515 for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr != auraDummy.end(); ++itr)
1517 if((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (*itr)->GetSpellProto()->SpellIconID == 208)
1518 mana = ((*itr)->GetModifier()->m_amount + 100)* mana / 100;
1520 m_caster->CastCustomSpell(unitTarget, 31818, &mana, NULL, NULL, true);
1522 // Mana Feed
1523 int32 manaFeedVal = 0;
1524 Unit::AuraList const& mod = m_caster->GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER);
1525 for(Unit::AuraList::const_iterator itr = mod.begin(); itr != mod.end(); ++itr)
1527 if((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (*itr)->GetSpellProto()->SpellIconID == 1982)
1528 manaFeedVal+= (*itr)->GetModifier()->m_amount;
1530 if (manaFeedVal > 0)
1532 manaFeedVal = manaFeedVal * mana / 100;
1533 m_caster->CastCustomSpell(m_caster, 32553, &manaFeedVal, NULL, NULL, true, NULL);
1536 else
1537 SendCastResult(SPELL_FAILED_FIZZLE);
1538 return;
1540 break;
1541 case SPELLFAMILY_PRIEST:
1542 // Penance
1543 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0080000000000000))
1545 if (!unitTarget)
1546 return;
1548 int hurt = 0;
1549 int heal = 0;
1550 switch(m_spellInfo->Id)
1552 case 47540: hurt = 47758; heal = 47757; break;
1553 case 53005: hurt = 53001; heal = 52986; break;
1554 case 53006: hurt = 53002; heal = 52987; break;
1555 case 53007: hurt = 53003; heal = 52988; break;
1556 default:
1557 sLog.outError("Spell::EffectDummy: Spell %u Penance need set correct heal/damage spell", m_spellInfo->Id);
1558 return;
1560 if (m_caster->IsFriendlyTo(unitTarget))
1561 m_caster->CastSpell(unitTarget, heal, true, 0);
1562 else
1563 m_caster->CastSpell(unitTarget, hurt, true, 0);
1564 return;
1566 break;
1567 case SPELLFAMILY_DRUID:
1568 // Starfall
1569 if (m_spellInfo->SpellFamilyFlags2 & 0x00000100)
1571 //Shapeshifting into an animal form or mounting cancels the effect.
1572 if(m_caster->GetCreatureType() == CREATURE_TYPE_BEAST || m_caster->IsMounted())
1574 if(m_triggeredByAuraSpell)
1575 m_caster->RemoveAurasDueToSpell(m_triggeredByAuraSpell->Id);
1576 return;
1579 //Any effect which causes you to lose control of your character will supress the starfall effect.
1580 if (m_caster->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_FLEEING | UNIT_STAT_ROOT | UNIT_STAT_CONFUSED))
1581 return;
1583 switch(m_spellInfo->Id)
1585 case 50286: m_caster->CastSpell(unitTarget, 50288, true); return;
1586 case 53196: m_caster->CastSpell(unitTarget, 53191, true); return;
1587 case 53197: m_caster->CastSpell(unitTarget, 53194, true); return;
1588 case 53198: m_caster->CastSpell(unitTarget, 53195, true); return;
1589 default:
1590 sLog.outError("Spell::EffectDummy: Unhandeled Starfall spell rank %u",m_spellInfo->Id);
1591 return;
1594 break;
1595 case SPELLFAMILY_ROGUE:
1596 switch(m_spellInfo->Id )
1598 case 5938: // Shiv
1600 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1601 return;
1603 Player *pCaster = ((Player*)m_caster);
1605 Item *item = pCaster->GetWeaponForAttack(OFF_ATTACK);
1606 if (!item)
1607 return;
1609 // all poison enchantments is temporary
1610 uint32 enchant_id = item->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT);
1611 if (!enchant_id)
1612 return;
1614 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
1615 if (!pEnchant)
1616 return;
1618 for (int s=0;s<3;s++)
1620 if (pEnchant->type[s]!=ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL)
1621 continue;
1623 SpellEntry const* combatEntry = sSpellStore.LookupEntry(pEnchant->spellid[s]);
1624 if (!combatEntry || combatEntry->Dispel != DISPEL_POISON)
1625 continue;
1627 m_caster->CastSpell(unitTarget, combatEntry, true, item);
1630 m_caster->CastSpell(unitTarget, 5940, true);
1631 return;
1633 case 14185: // Preparation
1635 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1636 return;
1638 //immediately finishes the cooldown on certain Rogue abilities
1639 const SpellCooldowns& cm = ((Player *)m_caster)->GetSpellCooldownMap();
1640 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1642 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1644 if (spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && (spellInfo->SpellFamilyFlags & UI64LIT(0x0000024000000860)))
1645 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first,true);
1646 else
1647 ++itr;
1649 return;
1651 case 31231: // Cheat Death
1653 m_caster->CastSpell(m_caster, 45182, true);
1654 return;
1657 break;
1658 case SPELLFAMILY_HUNTER:
1659 // Steady Shot
1660 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x100000000))
1662 if (!unitTarget || !unitTarget->isAlive())
1663 return;
1665 bool found = false;
1667 // check dazed affect
1668 Unit::AuraList const& decSpeedList = unitTarget->GetAurasByType(SPELL_AURA_MOD_DECREASE_SPEED);
1669 for(Unit::AuraList::const_iterator iter = decSpeedList.begin(); iter != decSpeedList.end(); ++iter)
1671 if ((*iter)->GetSpellProto()->SpellIconID==15 && (*iter)->GetSpellProto()->Dispel==0)
1673 found = true;
1674 break;
1678 if (found)
1679 m_damage+= damage;
1680 return;
1683 // Disengage
1684 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000400000000000))
1686 Unit* target = unitTarget;
1687 uint32 spellid;
1688 switch(m_spellInfo->Id)
1690 case 57635: spellid = 57636; break; // one from creature cases
1691 case 61507: spellid = 61508; break; // one from creature cases
1692 default:
1693 sLog.outError("Spell %u not handled propertly in EffectDummy(Disengage)",m_spellInfo->Id);
1694 return;
1696 if (!target || !target->isAlive())
1697 return;
1698 m_caster->CastSpell(target,spellid,true,NULL);
1701 switch(m_spellInfo->Id)
1703 case 23989: // Readiness talent
1705 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1706 return;
1708 //immediately finishes the cooldown for hunter abilities
1709 const SpellCooldowns& cm = ((Player*)m_caster)->GetSpellCooldownMap();
1710 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1712 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1714 if (spellInfo->SpellFamilyName == SPELLFAMILY_HUNTER && spellInfo->Id != 23989 && GetSpellRecoveryTime(spellInfo) > 0 )
1715 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first,true);
1716 else
1717 ++itr;
1719 return;
1721 case 37506: // Scatter Shot
1723 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1724 return;
1726 // break Auto Shot and autohit
1727 m_caster->InterruptSpell(CURRENT_AUTOREPEAT_SPELL);
1728 m_caster->AttackStop();
1729 ((Player*)m_caster)->SendAttackSwingCancelAttack();
1730 return;
1732 // Last Stand
1733 case 53478:
1735 if (!unitTarget)
1736 return;
1737 int32 healthModSpellBasePoints0 = int32(unitTarget->GetMaxHealth() * 0.3);
1738 unitTarget->CastCustomSpell(unitTarget, 53479, &healthModSpellBasePoints0, NULL, NULL, true, NULL);
1739 return;
1741 // Master's Call
1742 case 53271:
1744 Pet* pet = m_caster->GetPet();
1745 if (!pet || !unitTarget)
1746 return;
1748 pet->CastSpell(unitTarget, m_spellInfo->CalculateSimpleValue(i), true);
1749 return;
1752 break;
1753 case SPELLFAMILY_PALADIN:
1754 switch(m_spellInfo->SpellIconID)
1756 case 156: // Holy Shock
1758 if (!unitTarget)
1759 return;
1761 int hurt = 0;
1762 int heal = 0;
1764 switch(m_spellInfo->Id)
1766 case 20473: hurt = 25912; heal = 25914; break;
1767 case 20929: hurt = 25911; heal = 25913; break;
1768 case 20930: hurt = 25902; heal = 25903; break;
1769 case 27174: hurt = 27176; heal = 27175; break;
1770 case 33072: hurt = 33073; heal = 33074; break;
1771 case 48824: hurt = 48822; heal = 48820; break;
1772 case 48825: hurt = 48823; heal = 48821; break;
1773 default:
1774 sLog.outError("Spell::EffectDummy: Spell %u not handled in HS",m_spellInfo->Id);
1775 return;
1778 if (m_caster->IsFriendlyTo(unitTarget))
1779 m_caster->CastSpell(unitTarget, heal, true, 0);
1780 else
1781 m_caster->CastSpell(unitTarget, hurt, true, 0);
1783 return;
1785 case 561: // Judgement of command
1787 if (!unitTarget)
1788 return;
1790 uint32 spell_id = m_currentBasePoints[i]+1;
1791 SpellEntry const* spell_proto = sSpellStore.LookupEntry(spell_id);
1792 if (!spell_proto)
1793 return;
1795 m_caster->CastSpell(unitTarget, spell_proto, true, NULL);
1796 return;
1800 switch(m_spellInfo->Id)
1802 // Judgement of Righteousness (0.2*$AP+0.32*$SPH) holy added in spellDamagBonus
1803 case 20187:
1805 if (!unitTarget)
1806 return;
1807 m_damage+=int32(0.2f*m_caster->GetTotalAttackPowerValue(BASE_ATTACK));
1808 return;
1810 case 31789: // Righteous Defense (step 1)
1812 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1814 SendCastResult(SPELL_FAILED_TARGET_AFFECTING_COMBAT);
1815 return;
1818 // 31989 -> dummy effect (step 1) + dummy effect (step 2) -> 31709 (taunt like spell for each target)
1819 Unit* friendTarget = !unitTarget || unitTarget->IsFriendlyTo(m_caster) ? unitTarget : unitTarget->getVictim();
1820 if (friendTarget)
1822 Player* player = friendTarget->GetCharmerOrOwnerPlayerOrPlayerItself();
1823 if (!player || !player->IsInSameRaidWith((Player*)m_caster))
1824 friendTarget = NULL;
1827 // non-standard cast requirement check
1828 if (!friendTarget || friendTarget->getAttackers().empty())
1830 ((Player*)m_caster)->RemoveSpellCooldown(m_spellInfo->Id,true);
1831 SendCastResult(SPELL_FAILED_TARGET_AFFECTING_COMBAT);
1832 return;
1835 // Righteous Defense (step 2) (in old version 31980 dummy effect)
1836 // Clear targets for eff 1
1837 for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit)
1838 ihit->effectMask &= ~(1<<1);
1840 // not empty (checked), copy
1841 Unit::AttackerSet attackers = friendTarget->getAttackers();
1843 // selected from list 3
1844 for(int i = 0; i < std::min(size_t(3),attackers.size()); ++i)
1846 Unit::AttackerSet::iterator aItr = attackers.begin();
1847 std::advance(aItr, rand() % attackers.size());
1848 AddUnitTarget((*aItr), 1);
1849 attackers.erase(aItr);
1852 // now let next effect cast spell at each target.
1853 return;
1855 case 37877: // Blessing of Faith
1857 if (!unitTarget)
1858 return;
1860 uint32 spell_id = 0;
1861 switch(unitTarget->getClass())
1863 case CLASS_DRUID: spell_id = 37878; break;
1864 case CLASS_PALADIN: spell_id = 37879; break;
1865 case CLASS_PRIEST: spell_id = 37880; break;
1866 case CLASS_SHAMAN: spell_id = 37881; break;
1867 default: return; // ignore for not healing classes
1870 m_caster->CastSpell(m_caster, spell_id, true);
1871 return;
1874 break;
1875 case SPELLFAMILY_SHAMAN:
1876 // Cleansing Totem
1877 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000004000000)) && m_spellInfo->SpellIconID==1673)
1879 if (unitTarget)
1880 m_caster->CastSpell(unitTarget, 52025, true);
1881 return;
1883 // Healing Stream Totem
1884 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000002000))
1886 if (unitTarget)
1887 m_caster->CastCustomSpell(unitTarget, 52042, &damage, 0, 0, true, 0, 0, m_originalCasterGUID);
1888 return;
1890 // Mana Spring Totem
1891 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000004000))
1893 if (!unitTarget || unitTarget->getPowerType()!=POWER_MANA)
1894 return;
1895 m_caster->CastCustomSpell(unitTarget, 52032, &damage, 0, 0, true, 0, 0, m_originalCasterGUID);
1896 return;
1898 if (m_spellInfo->Id == 39610) // Mana Tide Totem effect
1900 if (!unitTarget || unitTarget->getPowerType() != POWER_MANA)
1901 return;
1902 // Glyph of Mana Tide
1903 if (Unit *owner = m_caster->GetOwner())
1904 if (Aura *dummy = owner->GetDummyAura(55441))
1905 damage+=dummy->GetModifier()->m_amount;
1906 // Regenerate 6% of Total Mana Every 3 secs
1907 int32 EffectBasePoints0 = unitTarget->GetMaxPower(POWER_MANA) * damage / 100;
1908 m_caster->CastCustomSpell(unitTarget, 39609, &EffectBasePoints0, NULL, NULL, true, NULL, NULL, m_originalCasterGUID);
1909 return;
1911 // Lava Lash
1912 if (m_spellInfo->SpellFamilyFlags2 & 0x00000004)
1914 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1915 return;
1916 Item *item = ((Player*)m_caster)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND);
1917 if (item)
1919 // Damage is increased if your off-hand weapon is enchanted with Flametongue.
1920 Unit::AuraList const& auraDummy = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
1921 for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr != auraDummy.end(); ++itr)
1923 if ((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_SHAMAN &&
1924 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000200000)) &&
1925 (*itr)->GetCastItemGUID() == item->GetGUID())
1927 m_damage += m_damage * damage / 100;
1928 return;
1932 return;
1934 break;
1935 case SPELLFAMILY_DEATHKNIGHT:
1936 // Death Coil
1937 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x002000))
1939 if (m_caster->IsFriendlyTo(unitTarget))
1941 if (unitTarget->GetCreatureType() != CREATURE_TYPE_UNDEAD)
1942 return;
1944 int32 bp = damage * 1.5f;
1945 m_caster->CastCustomSpell(unitTarget, 47633, &bp, NULL, NULL, true);
1947 else
1949 int32 bp = damage;
1950 m_caster->CastCustomSpell(unitTarget, 47632, &bp, NULL, NULL, true);
1952 return;
1954 // Hungering Cold
1955 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000100000000000))
1957 m_caster->CastSpell(m_caster, 51209, true);
1958 return;
1960 // Death Strike
1961 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000010))
1963 uint32 count = 0;
1964 Unit::AuraMap const& auras = unitTarget->GetAuras();
1965 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
1967 if (itr->second->GetSpellProto()->Dispel == DISPEL_DISEASE &&
1968 itr->second->GetCasterGUID() == m_caster->GetGUID() &&
1969 IsSpellLastAuraEffect(itr->second->GetSpellProto(), itr->second->GetEffIndex()))
1971 ++count;
1972 // max. 15%
1973 if (count == 3)
1974 break;
1978 int32 bp = count * m_caster->GetMaxHealth() * m_spellInfo->DmgMultiplier[0] / 100;
1979 m_caster->CastCustomSpell(m_caster, 45470, &bp, NULL, NULL, true);
1980 return;
1982 break;
1985 // pet auras
1986 if (PetAura const* petSpell = sSpellMgr.GetPetAura(m_spellInfo->Id, i))
1988 m_caster->AddPetAura(petSpell);
1989 return;
1992 // Script based implementation. Must be used only for not good for implementation in core spell effects
1993 // So called only for not proccessed cases
1994 if (gameObjTarget)
1995 Script->EffectDummyGameObj(m_caster, m_spellInfo->Id, i, gameObjTarget);
1996 else if (unitTarget && unitTarget->GetTypeId()==TYPEID_UNIT)
1997 Script->EffectDummyCreature(m_caster, m_spellInfo->Id, i, (Creature*)unitTarget);
1998 else if (itemTarget)
1999 Script->EffectDummyItem(m_caster, m_spellInfo->Id, i, itemTarget);
2002 void Spell::EffectTriggerSpellWithValue(uint32 i)
2004 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2006 // normal case
2007 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2009 if(!spellInfo)
2011 sLog.outError("EffectTriggerSpellWithValue of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2012 return;
2015 int32 bp = damage;
2016 m_caster->CastCustomSpell(unitTarget,triggered_spell_id,&bp,&bp,&bp,true,NULL,NULL,m_originalCasterGUID);
2019 void Spell::EffectTriggerRitualOfSummoning(uint32 i)
2021 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2022 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2024 if(!spellInfo)
2026 sLog.outError("EffectTriggerRitualOfSummoning of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2027 return;
2030 finish();
2032 m_caster->CastSpell(unitTarget,spellInfo,false);
2035 void Spell::EffectForceCast(uint32 i)
2037 if( !unitTarget )
2038 return;
2040 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2042 // normal case
2043 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2045 if(!spellInfo)
2047 sLog.outError("EffectForceCast of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2048 return;
2051 unitTarget->CastSpell(unitTarget, spellInfo, true, NULL, NULL, m_originalCasterGUID);
2054 void Spell::EffectTriggerSpell(uint32 effIndex)
2056 // only unit case known
2057 if (!unitTarget)
2059 if(gameObjTarget || itemTarget)
2060 sLog.outError("Spell::EffectTriggerSpell (Spell: %u): Unsupported non-unit case!",m_spellInfo->Id);
2061 return;
2064 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[effIndex];
2066 // special cases
2067 switch(triggered_spell_id)
2069 // Vanish (not exist)
2070 case 18461:
2072 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2073 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
2074 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STALKED);
2076 // if this spell is given to NPC it must handle rest by it's own AI
2077 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
2078 return;
2080 // get highest rank of the Stealth spell
2081 uint32 spellId = 0;
2082 const PlayerSpellMap& sp_list = ((Player*)unitTarget)->GetSpellMap();
2083 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2085 // only highest rank is shown in spell book, so simply check if shown in spell book
2086 if (!itr->second->active || itr->second->disabled || itr->second->state == PLAYERSPELL_REMOVED)
2087 continue;
2089 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2090 if (!spellInfo)
2091 continue;
2093 if (spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE_STEALTH)
2095 spellId = spellInfo->Id;
2096 break;
2100 // no Stealth spell found
2101 if (!spellId)
2102 return;
2104 // reset cooldown on it if needed
2105 if (((Player*)unitTarget)->HasSpellCooldown(spellId))
2106 ((Player*)unitTarget)->RemoveSpellCooldown(spellId);
2108 m_caster->CastSpell(unitTarget, spellId, true);
2109 return;
2111 // just skip
2112 case 23770: // Sayge's Dark Fortune of *
2113 // not exist, common cooldown can be implemented in scripts if need.
2114 return;
2115 // Brittle Armor - (need add max stack of 24575 Brittle Armor)
2116 case 29284:
2118 // Brittle Armor
2119 SpellEntry const* spell = sSpellStore.LookupEntry(24575);
2120 if (!spell)
2121 return;
2123 for (int j=0; j < spell->StackAmount; ++j)
2124 m_caster->CastSpell(unitTarget, spell->Id, true, m_CastItem, NULL, m_originalCasterGUID);
2125 return;
2127 // Mercurial Shield - (need add max stack of 26464 Mercurial Shield)
2128 case 29286:
2130 // Mercurial Shield
2131 SpellEntry const* spell = sSpellStore.LookupEntry(26464);
2132 if (!spell)
2133 return;
2135 for (int j=0; j < spell->StackAmount; ++j)
2136 m_caster->CastSpell(unitTarget, spell->Id, true, m_CastItem, NULL, m_originalCasterGUID);
2137 return;
2139 // Righteous Defense
2140 case 31980:
2142 m_caster->CastSpell(unitTarget, 31790, true, m_CastItem, NULL, m_originalCasterGUID);
2143 return;
2145 // Cloak of Shadows
2146 case 35729:
2148 Unit::AuraMap& Auras = unitTarget->GetAuras();
2149 for(Unit::AuraMap::iterator iter = Auras.begin(); iter != Auras.end(); ++iter)
2151 // remove all harmful spells on you...
2152 if( // ignore positive and passive auras
2153 !iter->second->IsPositive() && !iter->second->IsPassive() &&
2154 // ignore physical auras
2155 (GetSpellSchoolMask(iter->second->GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)==0 )
2157 m_caster->RemoveAurasDueToSpell(iter->second->GetSpellProto()->Id);
2158 iter = Auras.begin();
2161 return;
2163 // Priest Shadowfiend (34433) need apply mana gain trigger aura on pet
2164 case 41967:
2166 if (Unit *pet = unitTarget->GetPet())
2167 pet->CastSpell(pet, 28305, true);
2168 return;
2172 // normal case
2173 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2174 if (!spellInfo)
2176 sLog.outError("EffectTriggerSpell of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2177 return;
2180 // select formal caster for triggered spell
2181 Unit* caster = m_caster;
2183 // some triggered spells require specific equipment
2184 if (spellInfo->EquippedItemClass >=0 && m_caster->GetTypeId()==TYPEID_PLAYER)
2186 // main hand weapon required
2187 if (spellInfo->AttributesEx3 & SPELL_ATTR_EX3_MAIN_HAND)
2189 Item* item = ((Player*)m_caster)->GetWeaponForAttack(BASE_ATTACK, true, false);
2191 // skip spell if no weapon in slot or broken
2192 if (!item)
2193 return;
2195 // skip spell if weapon not fit to triggered spell
2196 if (!item->IsFitToSpellRequirements(spellInfo))
2197 return;
2200 // offhand hand weapon required
2201 if (spellInfo->AttributesEx3 & SPELL_ATTR_EX3_REQ_OFFHAND)
2203 Item* item = ((Player*)m_caster)->GetWeaponForAttack(OFF_ATTACK, true, false);
2205 // skip spell if no weapon in slot or broken
2206 if (!item)
2207 return;
2209 // skip spell if weapon not fit to triggered spell
2210 if (!item->IsFitToSpellRequirements(spellInfo))
2211 return;
2214 else
2216 // Note: not exist spells with weapon req. and IsSpellHaveCasterSourceTargets == true
2217 // so this just for speedup places in else
2218 caster = IsSpellWithCasterSourceTargetsOnly(spellInfo) ? unitTarget : m_caster;
2221 caster->CastSpell(unitTarget,spellInfo,true,NULL,NULL,m_originalCasterGUID);
2224 void Spell::EffectTriggerMissileSpell(uint32 effect_idx)
2226 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[effect_idx];
2228 // normal case
2229 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2231 if(!spellInfo)
2233 sLog.outError("EffectTriggerMissileSpell of spell %u (eff: %u): triggering unknown spell id %u",
2234 m_spellInfo->Id,effect_idx,triggered_spell_id);
2235 return;
2238 if (m_CastItem)
2239 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id);
2241 m_caster->CastSpell(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, spellInfo, true, m_CastItem, 0, m_originalCasterGUID);
2244 void Spell::EffectJump(uint32 i)
2246 if(m_caster->isInFlight())
2247 return;
2249 // Init dest coordinates
2250 float x,y,z,o;
2251 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
2253 x = m_targets.m_destX;
2254 y = m_targets.m_destY;
2255 z = m_targets.m_destZ;
2257 if(m_spellInfo->EffectImplicitTargetA[i] == TARGET_BEHIND_VICTIM)
2259 // explicit cast data from client or server-side cast
2260 // some spell at client send caster
2261 Unit* pTarget = NULL;
2262 if(m_targets.getUnitTarget() && m_targets.getUnitTarget()!=m_caster)
2263 pTarget = m_targets.getUnitTarget();
2264 else if(unitTarget->getVictim())
2265 pTarget = m_caster->getVictim();
2266 else if(m_caster->GetTypeId() == TYPEID_PLAYER)
2267 pTarget = ObjectAccessor::GetUnit(*m_caster, ((Player*)m_caster)->GetSelection());
2269 o = pTarget ? pTarget->GetOrientation() : m_caster->GetOrientation();
2271 else
2272 o = m_caster->GetOrientation();
2274 else if(unitTarget)
2276 unitTarget->GetContactPoint(m_caster,x,y,z,CONTACT_DISTANCE);
2277 o = m_caster->GetOrientation();
2279 else if(gameObjTarget)
2281 gameObjTarget->GetContactPoint(m_caster,x,y,z,CONTACT_DISTANCE);
2282 o = m_caster->GetOrientation();
2284 else
2286 sLog.outError( "Spell::EffectJump - unsupported target mode for spell ID %u", m_spellInfo->Id );
2287 return;
2290 m_caster->NearTeleportTo(x, y, z, o, true);
2293 void Spell::EffectTeleportUnits(uint32 i)
2295 if(!unitTarget || unitTarget->isInFlight())
2296 return;
2298 switch (m_spellInfo->EffectImplicitTargetB[i])
2300 case TARGET_INNKEEPER_COORDINATES:
2302 // Only players can teleport to innkeeper
2303 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
2304 return;
2306 ((Player*)unitTarget)->TeleportToHomebind(unitTarget==m_caster ? TELE_TO_SPELL : 0);
2307 return;
2309 case TARGET_AREAEFFECT_INSTANT: // in all cases first TARGET_TABLE_X_Y_Z_COORDINATES
2310 case TARGET_TABLE_X_Y_Z_COORDINATES:
2312 SpellTargetPosition const* st = sSpellMgr.GetSpellTargetPosition(m_spellInfo->Id);
2313 if(!st)
2315 sLog.outError( "Spell::EffectTeleportUnits - unknown Teleport coordinates for spell ID %u", m_spellInfo->Id );
2316 return;
2319 if(st->target_mapId==unitTarget->GetMapId())
2320 unitTarget->NearTeleportTo(st->target_X,st->target_Y,st->target_Z,st->target_Orientation,unitTarget==m_caster);
2321 else if(unitTarget->GetTypeId()==TYPEID_PLAYER)
2322 ((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);
2323 break;
2325 case TARGET_BEHIND_VICTIM:
2327 Unit *pTarget = NULL;
2329 // explicit cast data from client or server-side cast
2330 // some spell at client send caster
2331 if(m_targets.getUnitTarget() && m_targets.getUnitTarget()!=unitTarget)
2332 pTarget = m_targets.getUnitTarget();
2333 else if(unitTarget->getVictim())
2334 pTarget = unitTarget->getVictim();
2335 else if(unitTarget->GetTypeId() == TYPEID_PLAYER)
2336 pTarget = ObjectAccessor::GetUnit(*unitTarget, ((Player*)unitTarget)->GetSelection());
2338 // Init dest coordinates
2339 float x = m_targets.m_destX;
2340 float y = m_targets.m_destY;
2341 float z = m_targets.m_destZ;
2342 float orientation = pTarget ? pTarget->GetOrientation() : unitTarget->GetOrientation();
2343 unitTarget->NearTeleportTo(x,y,z,orientation,unitTarget==m_caster);
2344 return;
2346 default:
2348 // If not exist data for dest location - return
2349 if(!(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION))
2351 sLog.outError( "Spell::EffectTeleportUnits - unknown EffectImplicitTargetB[%u] = %u for spell ID %u", i, m_spellInfo->EffectImplicitTargetB[i], m_spellInfo->Id );
2352 return;
2354 // Init dest coordinates
2355 float x = m_targets.m_destX;
2356 float y = m_targets.m_destY;
2357 float z = m_targets.m_destZ;
2358 float orientation = unitTarget->GetOrientation();
2359 // Teleport
2360 unitTarget->NearTeleportTo(x,y,z,orientation,unitTarget==m_caster);
2361 return;
2365 // post effects for TARGET_TABLE_X_Y_Z_COORDINATES
2366 switch ( m_spellInfo->Id )
2368 // Dimensional Ripper - Everlook
2369 case 23442:
2371 int32 r = irand(0, 119);
2372 if ( r >= 70 ) // 7/12 success
2374 if ( r < 100 ) // 4/12 evil twin
2375 m_caster->CastSpell(m_caster, 23445, true);
2376 else // 1/12 fire
2377 m_caster->CastSpell(m_caster, 23449, true);
2379 return;
2381 // Ultrasafe Transporter: Toshley's Station
2382 case 36941:
2384 if ( roll_chance_i(50) ) // 50% success
2386 int32 rand_eff = urand(1, 7);
2387 switch ( rand_eff )
2389 case 1:
2390 // soul split - evil
2391 m_caster->CastSpell(m_caster, 36900, true);
2392 break;
2393 case 2:
2394 // soul split - good
2395 m_caster->CastSpell(m_caster, 36901, true);
2396 break;
2397 case 3:
2398 // Increase the size
2399 m_caster->CastSpell(m_caster, 36895, true);
2400 break;
2401 case 4:
2402 // Decrease the size
2403 m_caster->CastSpell(m_caster, 36893, true);
2404 break;
2405 case 5:
2406 // Transform
2408 if (((Player*)m_caster)->GetTeam() == ALLIANCE )
2409 m_caster->CastSpell(m_caster, 36897, true);
2410 else
2411 m_caster->CastSpell(m_caster, 36899, true);
2412 break;
2414 case 6:
2415 // chicken
2416 m_caster->CastSpell(m_caster, 36940, true);
2417 break;
2418 case 7:
2419 // evil twin
2420 m_caster->CastSpell(m_caster, 23445, true);
2421 break;
2424 return;
2426 // Dimensional Ripper - Area 52
2427 case 36890:
2429 if ( roll_chance_i(50) ) // 50% success
2431 int32 rand_eff = urand(1, 4);
2432 switch ( rand_eff )
2434 case 1:
2435 // soul split - evil
2436 m_caster->CastSpell(m_caster, 36900, true);
2437 break;
2438 case 2:
2439 // soul split - good
2440 m_caster->CastSpell(m_caster, 36901, true);
2441 break;
2442 case 3:
2443 // Increase the size
2444 m_caster->CastSpell(m_caster, 36895, true);
2445 break;
2446 case 4:
2447 // Transform
2449 if (((Player*)m_caster)->GetTeam() == ALLIANCE )
2450 m_caster->CastSpell(m_caster, 36897, true);
2451 else
2452 m_caster->CastSpell(m_caster, 36899, true);
2453 break;
2457 return;
2462 void Spell::EffectApplyAura(uint32 i)
2464 if(!unitTarget)
2465 return;
2467 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
2468 if ( (!unitTarget->isAlive() && !(IsDeathOnlySpell(m_spellInfo) || IsDeathPersistentSpell(m_spellInfo))) &&
2469 (unitTarget->GetTypeId() != TYPEID_PLAYER || !((Player*)unitTarget)->GetSession()->PlayerLoading()) )
2470 return;
2472 Unit* caster = m_originalCaster ? m_originalCaster : m_caster;
2473 if(!caster)
2474 return;
2476 sLog.outDebug("Spell: Aura is: %u", m_spellInfo->EffectApplyAuraName[i]);
2478 Aura* Aur = CreateAura(m_spellInfo, i, &m_currentBasePoints[i], unitTarget, caster, m_CastItem);
2480 // Now Reduce spell duration using data received at spell hit
2481 int32 duration = Aur->GetAuraMaxDuration();
2482 int32 limitduration = GetDiminishingReturnsLimitDuration(m_diminishGroup,m_spellInfo);
2483 unitTarget->ApplyDiminishingToDuration(m_diminishGroup, duration, m_caster, m_diminishLevel,limitduration);
2484 Aur->setDiminishGroup(m_diminishGroup);
2486 // if Aura removed and deleted, do not continue.
2487 if(duration== 0 && !(Aur->IsPermanent()))
2489 delete Aur;
2490 return;
2493 if(duration != Aur->GetAuraMaxDuration())
2495 Aur->SetAuraMaxDuration(duration);
2496 Aur->SetAuraDuration(duration);
2499 unitTarget->AddAura(Aur);
2502 void Spell::EffectUnlearnSpecialization( uint32 i )
2504 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
2505 return;
2507 Player *_player = (Player*)unitTarget;
2508 uint32 spellToUnlearn = m_spellInfo->EffectTriggerSpell[i];
2510 _player->removeSpell(spellToUnlearn);
2512 sLog.outDebug( "Spell: Player %u has unlearned spell %u from NpcGUID: %u", _player->GetGUIDLow(), spellToUnlearn, m_caster->GetGUIDLow() );
2515 void Spell::EffectPowerDrain(uint32 i)
2517 if(m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2518 return;
2520 Powers drain_power = Powers(m_spellInfo->EffectMiscValue[i]);
2522 if(!unitTarget)
2523 return;
2524 if(!unitTarget->isAlive())
2525 return;
2526 if(unitTarget->getPowerType() != drain_power)
2527 return;
2528 if(damage < 0)
2529 return;
2531 uint32 curPower = unitTarget->GetPower(drain_power);
2533 //add spell damage bonus
2534 damage=m_caster->SpellDamageBonus(unitTarget,m_spellInfo,uint32(damage),SPELL_DIRECT_DAMAGE);
2536 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
2537 uint32 power = damage;
2538 if (drain_power == POWER_MANA)
2539 power -= unitTarget->GetSpellCritDamageReduction(power);
2541 int32 new_damage;
2542 if(curPower < power)
2543 new_damage = curPower;
2544 else
2545 new_damage = power;
2547 unitTarget->ModifyPower(drain_power,-new_damage);
2549 // Don`t restore from self drain
2550 if(drain_power == POWER_MANA && m_caster != unitTarget)
2552 float manaMultiplier = m_spellInfo->EffectMultipleValue[i];
2553 if(manaMultiplier==0)
2554 manaMultiplier = 1;
2556 if(Player *modOwner = m_caster->GetSpellModOwner())
2557 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, manaMultiplier);
2559 int32 gain = int32(new_damage * manaMultiplier);
2561 m_caster->EnergizeBySpell(m_caster, m_spellInfo->Id, gain, POWER_MANA);
2565 void Spell::EffectSendEvent(uint32 EffectIndex)
2568 we do not handle a flag dropping or clicking on flag in battleground by sendevent system
2570 sLog.outDebug("Spell ScriptStart %u for spellid %u in EffectSendEvent ", m_spellInfo->EffectMiscValue[EffectIndex], m_spellInfo->Id);
2571 m_caster->GetMap()->ScriptsStart(sEventScripts, m_spellInfo->EffectMiscValue[EffectIndex], m_caster, focusObject);
2574 void Spell::EffectPowerBurn(uint32 i)
2576 if (m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2577 return;
2579 Powers powertype = Powers(m_spellInfo->EffectMiscValue[i]);
2581 if (!unitTarget)
2582 return;
2583 if (!unitTarget->isAlive())
2584 return;
2585 if (unitTarget->getPowerType()!=powertype)
2586 return;
2587 if (damage < 0)
2588 return;
2590 // burn x% of target's mana, up to maximum of 2x% of caster's mana (Mana Burn)
2591 if (m_spellInfo->ManaCostPercentage)
2593 uint32 maxdamage = m_caster->GetMaxPower(powertype) * damage * 2 / 100;
2594 damage = unitTarget->GetMaxPower(powertype) * damage / 100;
2595 if(damage > maxdamage) damage = maxdamage;
2598 int32 curPower = int32(unitTarget->GetPower(powertype));
2600 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
2601 uint32 power = damage;
2602 if (powertype == POWER_MANA)
2603 power -= unitTarget->GetSpellCritDamageReduction(power);
2605 int32 new_damage = (curPower < power) ? curPower : power;
2607 unitTarget->ModifyPower(powertype, -new_damage);
2608 float multiplier = m_spellInfo->EffectMultipleValue[i];
2610 if (Player *modOwner = m_caster->GetSpellModOwner())
2611 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
2613 new_damage = int32(new_damage * multiplier);
2614 m_damage += new_damage;
2617 void Spell::EffectHeal( uint32 /*i*/ )
2619 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2621 // Try to get original caster
2622 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2624 // Skip if m_originalCaster not available
2625 if (!caster)
2626 return;
2628 int32 addhealth = damage;
2630 // Vessel of the Naaru (Vial of the Sunwell trinket)
2631 if (m_spellInfo->Id == 45064)
2633 // Amount of heal - depends from stacked Holy Energy
2634 int damageAmount = 0;
2635 Unit::AuraList const& mDummyAuras = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
2636 for(Unit::AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i)
2637 if ((*i)->GetId() == 45062)
2638 damageAmount+=(*i)->GetModifier()->m_amount;
2639 if (damageAmount)
2640 m_caster->RemoveAurasDueToSpell(45062);
2642 addhealth += damageAmount;
2644 // Death Pact (percent heal)
2645 else if (m_spellInfo->Id==48743)
2646 addhealth = addhealth * unitTarget->GetMaxHealth() / 100;
2647 // Swiftmend - consumes Regrowth or Rejuvenation
2648 else if (m_spellInfo->TargetAuraState == AURA_STATE_SWIFTMEND && unitTarget->HasAuraState(AURA_STATE_SWIFTMEND))
2650 Unit::AuraList const& RejorRegr = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_HEAL);
2651 // find most short by duration
2652 Aura *targetAura = NULL;
2653 for(Unit::AuraList::const_iterator i = RejorRegr.begin(); i != RejorRegr.end(); ++i)
2655 if ((*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2656 // Regrowth or Rejuvenation 0x40 | 0x10
2657 ((*i)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000050)))
2659 if (!targetAura || (*i)->GetAuraDuration() < targetAura->GetAuraDuration())
2660 targetAura = *i;
2664 if (!targetAura)
2666 sLog.outError("Target (GUID: %u TypeId: %u) has aurastate AURA_STATE_SWIFTMEND but no matching aura.", unitTarget->GetGUIDLow(), unitTarget->GetTypeId());
2667 return;
2669 int idx = 0;
2670 while(idx < 3)
2672 if(targetAura->GetSpellProto()->EffectApplyAuraName[idx] == SPELL_AURA_PERIODIC_HEAL)
2673 break;
2674 idx++;
2677 int32 tickheal = caster->SpellHealingBonus(unitTarget, targetAura->GetSpellProto(), targetAura->GetModifier()->m_amount, DOT);
2678 int32 tickcount = GetSpellDuration(targetAura->GetSpellProto()) / targetAura->GetSpellProto()->EffectAmplitude[idx];
2680 // Glyph of Swiftmend
2681 if (!caster->HasAura(54824))
2682 unitTarget->RemoveAurasDueToSpell(targetAura->GetId());
2684 addhealth += tickheal * tickcount;
2686 else
2687 addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, addhealth, HEAL);
2689 m_healing+=addhealth;
2693 void Spell::EffectHealPct( uint32 /*i*/ )
2695 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2697 // Try to get original caster
2698 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2700 // Skip if m_originalCaster not available
2701 if (!caster)
2702 return;
2704 uint32 addhealth = unitTarget->GetMaxHealth() * damage / 100;
2705 if (Player* modOwner = m_caster->GetSpellModOwner())
2706 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DAMAGE, addhealth, this);
2708 int32 gain = caster->DealHeal(unitTarget, addhealth, m_spellInfo);
2709 unitTarget->getHostileRefManager().threatAssist(m_caster, float(gain) * 0.5f, m_spellInfo);
2713 void Spell::EffectHealMechanical( uint32 /*i*/ )
2715 // Mechanic creature type should be correctly checked by targetCreatureType field
2716 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2718 // Try to get original caster
2719 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2721 // Skip if m_originalCaster not available
2722 if (!caster)
2723 return;
2725 uint32 addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, uint32(damage), HEAL);
2726 caster->DealHeal(unitTarget, addhealth, m_spellInfo);
2730 void Spell::EffectHealthLeech(uint32 i)
2732 if (!unitTarget)
2733 return;
2734 if (!unitTarget->isAlive())
2735 return;
2737 if (damage < 0)
2738 return;
2740 sLog.outDebug("HealthLeech :%i", damage);
2742 uint32 curHealth = unitTarget->GetHealth();
2743 damage = m_caster->SpellNonMeleeDamageLog(unitTarget, m_spellInfo->Id, damage );
2744 if (curHealth < damage)
2745 damage = curHealth;
2747 float multiplier = m_spellInfo->EffectMultipleValue[i];
2749 if (Player *modOwner = m_caster->GetSpellModOwner())
2750 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
2752 uint32 heal = uint32(damage*multiplier);
2753 if (m_caster->isAlive())
2755 heal = m_caster->SpellHealingBonus(m_caster, m_spellInfo, heal, HEAL);
2756 m_caster->DealHeal(m_caster, heal, m_spellInfo);
2760 void Spell::DoCreateItem(uint32 i, uint32 itemtype)
2762 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
2763 return;
2765 Player* player = (Player*)unitTarget;
2767 uint32 newitemid = itemtype;
2768 ItemPrototype const *pProto = ObjectMgr::GetItemPrototype( newitemid );
2769 if(!pProto)
2771 player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
2772 return;
2775 // bg reward have some special in code work
2776 uint32 bgType = 0;
2777 switch(m_spellInfo->Id)
2779 case SPELL_AV_MARK_WINNER:
2780 case SPELL_AV_MARK_LOSER:
2781 bgType = BATTLEGROUND_AV;
2782 break;
2783 case SPELL_WS_MARK_WINNER:
2784 case SPELL_WS_MARK_LOSER:
2785 bgType = BATTLEGROUND_WS;
2786 break;
2787 case SPELL_AB_MARK_WINNER:
2788 case SPELL_AB_MARK_LOSER:
2789 bgType = BATTLEGROUND_AB;
2790 break;
2791 default:
2792 break;
2795 uint32 num_to_add;
2797 // TODO: maybe all this can be replaced by using correct calculated `damage` value
2798 if(pProto->Class != ITEM_CLASS_CONSUMABLE || m_spellInfo->SpellFamilyName != SPELLFAMILY_MAGE)
2800 int32 basePoints = m_currentBasePoints[i];
2801 int32 randomPoints = m_spellInfo->EffectDieSides[i];
2802 if (randomPoints)
2803 num_to_add = basePoints + irand(1, randomPoints);
2804 else
2805 num_to_add = basePoints + 1;
2807 else if (pProto->MaxCount == 1)
2808 num_to_add = 1;
2809 else if(player->getLevel() >= m_spellInfo->spellLevel)
2811 int32 basePoints = m_currentBasePoints[i];
2812 float pointPerLevel = m_spellInfo->EffectRealPointsPerLevel[i];
2813 num_to_add = basePoints + 1 + uint32((player->getLevel() - m_spellInfo->spellLevel)*pointPerLevel);
2815 else
2816 num_to_add = 2;
2818 if (num_to_add < 1)
2819 num_to_add = 1;
2820 if (num_to_add > pProto->GetMaxStackSize())
2821 num_to_add = pProto->GetMaxStackSize();
2823 // init items_count to 1, since 1 item will be created regardless of specialization
2824 int items_count=1;
2825 // the chance to create additional items
2826 float additionalCreateChance=0.0f;
2827 // the maximum number of created additional items
2828 uint8 additionalMaxNum=0;
2829 // get the chance and maximum number for creating extra items
2830 if ( canCreateExtraItems(player, m_spellInfo->Id, additionalCreateChance, additionalMaxNum) )
2832 // roll with this chance till we roll not to create or we create the max num
2833 while ( roll_chance_f(additionalCreateChance) && items_count<=additionalMaxNum )
2834 ++items_count;
2837 // really will be created more items
2838 num_to_add *= items_count;
2840 // can the player store the new item?
2841 ItemPosCountVec dest;
2842 uint32 no_space = 0;
2843 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, newitemid, num_to_add, &no_space );
2844 if( msg != EQUIP_ERR_OK )
2846 // convert to possible store amount
2847 if( msg == EQUIP_ERR_INVENTORY_FULL || msg == EQUIP_ERR_CANT_CARRY_MORE_OF_THIS )
2848 num_to_add -= no_space;
2849 else
2851 // if not created by another reason from full inventory or unique items amount limitation
2852 player->SendEquipError( msg, NULL, NULL );
2853 return;
2857 if(num_to_add)
2859 // create the new item and store it
2860 Item* pItem = player->StoreNewItem( dest, newitemid, true, Item::GenerateItemRandomPropertyId(newitemid));
2862 // was it successful? return error if not
2863 if(!pItem)
2865 player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
2866 return;
2869 // set the "Crafted by ..." property of the item
2870 if( pItem->GetProto()->Class != ITEM_CLASS_CONSUMABLE && pItem->GetProto()->Class != ITEM_CLASS_QUEST)
2871 pItem->SetUInt32Value(ITEM_FIELD_CREATOR, player->GetGUIDLow());
2873 // send info to the client
2874 if(pItem)
2875 player->SendNewItem(pItem, num_to_add, true, bgType == 0);
2877 // we succeeded in creating at least one item, so a levelup is possible
2878 if(bgType == 0)
2879 player->UpdateCraftSkill(m_spellInfo->Id);
2882 // for battleground marks send by mail if not add all expected
2883 if(no_space > 0 && bgType)
2885 if(BattleGround* bg = sBattleGroundMgr.GetBattleGroundTemplate(BattleGroundTypeId(bgType)))
2886 bg->SendRewardMarkByMail(player, newitemid, no_space);
2890 void Spell::EffectCreateItem(uint32 i)
2892 DoCreateItem(i,m_spellInfo->EffectItemType[i]);
2895 void Spell::EffectCreateItem2(uint32 i)
2897 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
2898 return;
2899 Player* player = (Player*)m_caster;
2901 uint32 item_id = m_spellInfo->EffectItemType[i];
2903 DoCreateItem(i, item_id);
2905 // special case: fake item replaced by generate using spell_loot_template
2906 if (IsLootCraftingSpell(m_spellInfo))
2908 if (!player->HasItemCount(item_id, 1))
2909 return;
2911 // remove reagent
2912 uint32 count = 1;
2913 player->DestroyItemCount(item_id, count, true);
2915 // create some random items
2916 player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
2920 void Spell::EffectCreateRandomItem(uint32 i)
2922 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
2923 return;
2924 Player* player = (Player*)m_caster;
2926 // create some random items
2927 player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
2930 void Spell::EffectPersistentAA(uint32 i)
2932 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
2934 if (Player* modOwner = m_caster->GetSpellModOwner())
2935 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RADIUS, radius);
2937 int32 duration = GetSpellDuration(m_spellInfo);
2938 DynamicObject* dynObj = new DynamicObject;
2939 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))
2941 delete dynObj;
2942 return;
2944 dynObj->SetUInt32Value(OBJECT_FIELD_TYPE, 65);
2945 dynObj->SetUInt32Value(GAMEOBJECT_DISPLAYID, 368003);
2946 dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x01eeeeee);
2947 m_caster->AddDynObject(dynObj);
2948 m_caster->GetMap()->Add(dynObj);
2951 void Spell::EffectEnergize(uint32 i)
2953 if(!unitTarget)
2954 return;
2955 if(!unitTarget->isAlive())
2956 return;
2958 if(m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2959 return;
2961 Powers power = Powers(m_spellInfo->EffectMiscValue[i]);
2963 // Some level depends spells
2964 int level_multiplier = 0;
2965 int level_diff = 0;
2966 switch (m_spellInfo->Id)
2968 case 9512: // Restore Energy
2969 level_diff = m_caster->getLevel() - 40;
2970 level_multiplier = 2;
2971 break;
2972 case 24571: // Blood Fury
2973 level_diff = m_caster->getLevel() - 60;
2974 level_multiplier = 10;
2975 break;
2976 case 24532: // Burst of Energy
2977 level_diff = m_caster->getLevel() - 60;
2978 level_multiplier = 4;
2979 break;
2980 case 31930: // Judgements of the Wise
2981 case 48542: // Revitalize (mana restore case)
2982 case 63375: // Improved Stormstrike
2983 damage = damage * unitTarget->GetCreateMana() / 100;
2984 break;
2985 default:
2986 break;
2989 if (level_diff > 0)
2990 damage -= level_multiplier * level_diff;
2992 if(damage < 0)
2993 return;
2995 if(unitTarget->GetMaxPower(power) == 0)
2996 return;
2998 m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, damage, power);
3000 // Mad Alchemist's Potion
3001 if (m_spellInfo->Id == 45051)
3003 // find elixirs on target
3004 uint32 elixir_mask = 0;
3005 Unit::AuraMap& Auras = unitTarget->GetAuras();
3006 for(Unit::AuraMap::iterator itr = Auras.begin(); itr != Auras.end(); ++itr)
3008 uint32 spell_id = itr->second->GetId();
3009 if(uint32 mask = sSpellMgr.GetSpellElixirMask(spell_id))
3010 elixir_mask |= mask;
3013 // get available elixir mask any not active type from battle/guardian (and flask if no any)
3014 elixir_mask = (elixir_mask & ELIXIR_FLASK_MASK) ^ ELIXIR_FLASK_MASK;
3016 // get all available elixirs by mask and spell level
3017 std::vector<uint32> elixirs;
3018 SpellElixirMap const& m_spellElixirs = sSpellMgr.GetSpellElixirMap();
3019 for(SpellElixirMap::const_iterator itr = m_spellElixirs.begin(); itr != m_spellElixirs.end(); ++itr)
3021 if (itr->second & elixir_mask)
3023 if (itr->second & (ELIXIR_UNSTABLE_MASK | ELIXIR_SHATTRATH_MASK))
3024 continue;
3026 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
3027 if (spellInfo && (spellInfo->spellLevel < m_spellInfo->spellLevel || spellInfo->spellLevel > unitTarget->getLevel()))
3028 continue;
3030 elixirs.push_back(itr->first);
3034 if (!elixirs.empty())
3036 // cast random elixir on target
3037 uint32 rand_spell = urand(0,elixirs.size()-1);
3038 m_caster->CastSpell(unitTarget,elixirs[rand_spell],true,m_CastItem);
3043 void Spell::EffectEnergisePct(uint32 i)
3045 if (!unitTarget)
3046 return;
3047 if (!unitTarget->isAlive())
3048 return;
3050 if (m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
3051 return;
3053 Powers power = Powers(m_spellInfo->EffectMiscValue[i]);
3055 uint32 maxPower = unitTarget->GetMaxPower(power);
3056 if (maxPower == 0)
3057 return;
3059 uint32 gain = damage * maxPower / 100;
3060 m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, gain, power);
3063 void Spell::SendLoot(uint64 guid, LootType loottype)
3065 Player* player = (Player*)m_caster;
3066 if (!player)
3067 return;
3069 if (gameObjTarget)
3071 if (Script->GOHello(player, gameObjTarget))
3072 return;
3074 switch (gameObjTarget->GetGoType())
3076 case GAMEOBJECT_TYPE_DOOR:
3077 case GAMEOBJECT_TYPE_BUTTON:
3078 gameObjTarget->UseDoorOrButton();
3079 player->GetMap()->ScriptsStart(sGameObjectScripts, gameObjTarget->GetDBTableGUIDLow(), player, gameObjTarget);
3080 return;
3082 case GAMEOBJECT_TYPE_QUESTGIVER:
3083 // start or end quest
3084 player->PrepareQuestMenu(guid);
3085 player->SendPreparedQuest(guid);
3086 return;
3088 case GAMEOBJECT_TYPE_SPELL_FOCUS:
3089 // triggering linked GO
3090 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->spellFocus.linkedTrapId)
3091 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3092 return;
3094 case GAMEOBJECT_TYPE_GOOBER:
3095 // goober_scripts can be triggered if the player don't have the quest
3096 if (gameObjTarget->GetGOInfo()->goober.eventId)
3098 sLog.outDebug("Goober ScriptStart id %u for GO %u", gameObjTarget->GetGOInfo()->goober.eventId,gameObjTarget->GetDBTableGUIDLow());
3099 player->GetMap()->ScriptsStart(sEventScripts, gameObjTarget->GetGOInfo()->goober.eventId, player, gameObjTarget);
3102 // cast goober spell
3103 if (gameObjTarget->GetGOInfo()->goober.questId)
3104 ///Quest require to be active for GO using
3105 if (player->GetQuestStatus(gameObjTarget->GetGOInfo()->goober.questId) != QUEST_STATUS_INCOMPLETE)
3106 return;
3108 gameObjTarget->AddUniqueUse(player);
3109 gameObjTarget->SetLootState(GO_JUST_DEACTIVATED);
3111 //TODO? Objective counting called without spell check but with quest objective check
3112 // if send spell id then this line will duplicate to spell casting call (double counting)
3113 // So we or have this line and not required in quest_template have reqSpellIdN
3114 // or must remove this line and required in DB have data in quest_template have reqSpellIdN for all quest using cases.
3115 player->CastedCreatureOrGO(gameObjTarget->GetEntry(), gameObjTarget->GetGUID(), 0);
3117 // triggering linked GO
3118 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->goober.linkedTrapId)
3119 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3121 return;
3123 case GAMEOBJECT_TYPE_CHEST:
3124 // TODO: possible must be moved to loot release (in different from linked triggering)
3125 if (gameObjTarget->GetGOInfo()->chest.eventId)
3127 sLog.outDebug("Chest ScriptStart id %u for GO %u", gameObjTarget->GetGOInfo()->chest.eventId,gameObjTarget->GetDBTableGUIDLow());
3128 player->GetMap()->ScriptsStart(sEventScripts, gameObjTarget->GetGOInfo()->chest.eventId, player, gameObjTarget);
3131 // triggering linked GO
3132 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->chest.linkedTrapId)
3133 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3135 // Don't return, let loots been taken
3136 default:
3137 break;
3141 // Send loot
3142 player->SendLoot(guid, loottype);
3145 void Spell::EffectOpenLock(uint32 effIndex)
3147 if (!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER)
3149 sLog.outDebug( "WORLD: Open Lock - No Player Caster!");
3150 return;
3153 Player* player = (Player*)m_caster;
3155 uint32 lockId = 0;
3156 uint64 guid = 0;
3158 // Get lockId
3159 if (gameObjTarget)
3161 GameObjectInfo const* goInfo = gameObjTarget->GetGOInfo();
3162 // Arathi Basin banner opening !
3163 if (goInfo->type == GAMEOBJECT_TYPE_BUTTON && goInfo->button.noDamageImmune ||
3164 goInfo->type == GAMEOBJECT_TYPE_GOOBER && goInfo->goober.losOK)
3166 //CanUseBattleGroundObject() already called in CheckCast()
3167 // in battleground check
3168 if (BattleGround *bg = player->GetBattleGround())
3170 // check if it's correct bg
3171 if (bg->GetTypeID() == BATTLEGROUND_AB || bg->GetTypeID() == BATTLEGROUND_AV)
3172 bg->EventPlayerClickedOnFlag(player, gameObjTarget);
3173 return;
3176 else if (goInfo->type == GAMEOBJECT_TYPE_FLAGSTAND)
3178 //CanUseBattleGroundObject() already called in CheckCast()
3179 // in battleground check
3180 if (BattleGround *bg = player->GetBattleGround())
3182 if (bg->GetTypeID() == BATTLEGROUND_EY)
3183 bg->EventPlayerClickedOnFlag(player, gameObjTarget);
3184 return;
3187 lockId = goInfo->GetLockId();
3188 guid = gameObjTarget->GetGUID();
3190 else if (itemTarget)
3192 lockId = itemTarget->GetProto()->LockID;
3193 guid = itemTarget->GetGUID();
3195 else
3197 sLog.outDebug( "WORLD: Open Lock - No GameObject/Item Target!");
3198 return;
3201 SkillType skillId = SKILL_NONE;
3202 int32 reqSkillValue = 0;
3203 int32 skillValue;
3205 SpellCastResult res = CanOpenLock(effIndex, lockId, skillId, reqSkillValue, skillValue);
3206 if (res != SPELL_CAST_OK)
3208 SendCastResult(res);
3209 return;
3212 SendLoot(guid, LOOT_SKINNING);
3214 // not allow use skill grow at item base open
3215 if (!m_CastItem && skillId != SKILL_NONE)
3217 // update skill if really known
3218 if (uint32 pureSkillValue = player->GetPureSkillValue(skillId))
3220 if (gameObjTarget)
3222 // Allow one skill-up until respawned
3223 if (!gameObjTarget->IsInSkillupList(player->GetGUIDLow()) &&
3224 player->UpdateGatherSkill(skillId, pureSkillValue, reqSkillValue))
3225 gameObjTarget->AddToSkillupList(player->GetGUIDLow());
3227 else if (itemTarget)
3229 // Do one skill-up
3230 player->UpdateGatherSkill(skillId, pureSkillValue, reqSkillValue);
3236 void Spell::EffectSummonChangeItem(uint32 i)
3238 if (m_caster->GetTypeId() != TYPEID_PLAYER)
3239 return;
3241 Player *player = (Player*)m_caster;
3243 // applied only to using item
3244 if (!m_CastItem)
3245 return;
3247 // ... only to item in own inventory/bank/equip_slot
3248 if (m_CastItem->GetOwnerGUID()!=player->GetGUID())
3249 return;
3251 uint32 newitemid = m_spellInfo->EffectItemType[i];
3252 if (!newitemid)
3253 return;
3255 uint16 pos = m_CastItem->GetPos();
3257 Item *pNewItem = Item::CreateItem( newitemid, 1, player);
3258 if (!pNewItem)
3259 return;
3261 for(uint8 j= PERM_ENCHANTMENT_SLOT; j<=TEMP_ENCHANTMENT_SLOT; ++j)
3263 if (m_CastItem->GetEnchantmentId(EnchantmentSlot(j)))
3264 pNewItem->SetEnchantment(EnchantmentSlot(j), m_CastItem->GetEnchantmentId(EnchantmentSlot(j)), m_CastItem->GetEnchantmentDuration(EnchantmentSlot(j)), m_CastItem->GetEnchantmentCharges(EnchantmentSlot(j)));
3267 if (m_CastItem->GetUInt32Value(ITEM_FIELD_DURABILITY) < m_CastItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY))
3269 double loosePercent = 1 - m_CastItem->GetUInt32Value(ITEM_FIELD_DURABILITY) / double(m_CastItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY));
3270 player->DurabilityLoss(pNewItem, loosePercent);
3273 if (player->IsInventoryPos(pos))
3275 ItemPosCountVec dest;
3276 uint8 msg = player->CanStoreItem( m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), dest, pNewItem, true );
3277 if (msg == EQUIP_ERR_OK)
3279 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3281 // prevent crash at access and unexpected charges counting with item update queue corrupt
3282 if (m_CastItem==m_targets.getItemTarget())
3283 m_targets.setItemTarget(NULL);
3285 m_CastItem = NULL;
3287 player->StoreItem( dest, pNewItem, true);
3288 return;
3291 else if (player->IsBankPos (pos))
3293 ItemPosCountVec dest;
3294 uint8 msg = player->CanBankItem( m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), dest, pNewItem, true );
3295 if (msg == EQUIP_ERR_OK)
3297 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3299 // prevent crash at access and unexpected charges counting with item update queue corrupt
3300 if (m_CastItem==m_targets.getItemTarget())
3301 m_targets.setItemTarget(NULL);
3303 m_CastItem = NULL;
3305 player->BankItem( dest, pNewItem, true);
3306 return;
3309 else if (player->IsEquipmentPos (pos))
3311 uint16 dest;
3312 uint8 msg = player->CanEquipItem( m_CastItem->GetSlot(), dest, pNewItem, true );
3313 if (msg == EQUIP_ERR_OK)
3315 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3317 // prevent crash at access and unexpected charges counting with item update queue corrupt
3318 if (m_CastItem==m_targets.getItemTarget())
3319 m_targets.setItemTarget(NULL);
3321 m_CastItem = NULL;
3323 player->EquipItem( dest, pNewItem, true);
3324 player->AutoUnequipOffhandIfNeed();
3325 return;
3329 // fail
3330 delete pNewItem;
3333 void Spell::EffectProficiency(uint32 /*i*/)
3335 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
3336 return;
3337 Player *p_target = (Player*)unitTarget;
3339 uint32 subClassMask = m_spellInfo->EquippedItemSubClassMask;
3340 if (m_spellInfo->EquippedItemClass == ITEM_CLASS_WEAPON && !(p_target->GetWeaponProficiency() & subClassMask))
3342 p_target->AddWeaponProficiency(subClassMask);
3343 p_target->SendProficiency(ITEM_CLASS_WEAPON, p_target->GetWeaponProficiency());
3345 if (m_spellInfo->EquippedItemClass == ITEM_CLASS_ARMOR && !(p_target->GetArmorProficiency() & subClassMask))
3347 p_target->AddArmorProficiency(subClassMask);
3348 p_target->SendProficiency(ITEM_CLASS_ARMOR, p_target->GetArmorProficiency());
3352 void Spell::EffectApplyAreaAura(uint32 i)
3354 if (!unitTarget)
3355 return;
3356 if (!unitTarget->isAlive())
3357 return;
3359 AreaAura* Aur = new AreaAura(m_spellInfo, i, &m_currentBasePoints[i], unitTarget, m_caster, m_CastItem);
3360 unitTarget->AddAura(Aur);
3363 void Spell::EffectSummonType(uint32 i)
3365 uint32 prop_id = m_spellInfo->EffectMiscValueB[i];
3366 SummonPropertiesEntry const *summon_prop = sSummonPropertiesStore.LookupEntry(prop_id);
3367 if(!summon_prop)
3369 sLog.outError("EffectSummonType: Unhandled summon type %u", prop_id);
3370 return;
3373 switch(summon_prop->Group)
3375 // faction handled later on, or loaded from template
3376 case SUMMON_PROP_GROUP_WILD:
3377 case SUMMON_PROP_GROUP_FRIENDLY:
3379 switch(summon_prop->Type)
3381 case SUMMON_PROP_TYPE_OTHER:
3383 // those are classical totems - effectbasepoints is their hp and not summon ammount!
3384 //SUMMON_TYPE_TOTEM = 121: 23035, battlestands
3385 //SUMMON_TYPE_TOTEM2 = 647: 52893, Anti-Magic Zone (npc used)
3386 if(prop_id == 121 || prop_id == 647)
3387 EffectSummonTotem(i);
3388 else
3389 EffectSummonWild(i, summon_prop->FactionId);
3390 break;
3392 case SUMMON_PROP_TYPE_SUMMON:
3393 case SUMMON_PROP_TYPE_GUARDIAN:
3394 case SUMMON_PROP_TYPE_ARMY:
3395 case SUMMON_PROP_TYPE_DK:
3396 case SUMMON_PROP_TYPE_CONSTRUCT:
3398 // JC golems - 32804, etc -- fits much better totem AI
3399 if(m_spellInfo->SpellIconID == 2056)
3400 EffectSummonTotem(i);
3401 if(prop_id == 832) // scrapbot
3402 EffectSummonWild(i, summon_prop->FactionId);
3403 else
3404 EffectSummonGuardian(i, summon_prop->FactionId);
3405 break;
3407 case SUMMON_PROP_TYPE_TOTEM:
3408 EffectSummonTotem(i, summon_prop->Slot);
3409 break;
3410 case SUMMON_PROP_TYPE_CRITTER:
3411 EffectSummonCritter(i, summon_prop->FactionId);
3412 break;
3413 case SUMMON_PROP_TYPE_PHASING:
3414 case SUMMON_PROP_TYPE_LIGHTWELL:
3415 case SUMMON_PROP_TYPE_REPAIR_BOT:
3416 EffectSummonWild(i, summon_prop->FactionId);
3417 break;
3418 case SUMMON_PROP_TYPE_SIEGE_VEH:
3419 case SUMMON_PROP_TYPE_DRAKE_VEH:
3420 // TODO
3421 // EffectSummonVehicle(i);
3422 break;
3423 default:
3424 sLog.outError("EffectSummonType: Unhandled summon type %u", summon_prop->Type);
3425 break;
3427 break;
3429 case SUMMON_PROP_GROUP_PETS:
3431 // FIXME : multiple summons - not yet supported as pet
3432 //1562 - force of nature - sid 33831
3433 //1161 - feral spirit - sid 51533
3434 if(prop_id == 1562) // 3 uncontrolable instead of one controllable :/
3435 EffectSummonGuardian(i, summon_prop->FactionId);
3436 else
3437 EffectSummon(i);
3438 break;
3440 case SUMMON_PROP_GROUP_CONTROLLABLE:
3442 // no type here
3443 // maybe wrong - but thats the handler currently used for those
3444 EffectSummonGuardian(i, summon_prop->FactionId);
3445 break;
3447 case SUMMON_PROP_GROUP_VEHICLE:
3449 // TODO
3450 // EffectSummonVehicle(i);
3451 break;
3453 default:
3454 sLog.outError("EffectSummonType: Unhandled summon group type %u", summon_prop->Group);
3455 break;
3459 void Spell::EffectSummon(uint32 i)
3461 if (m_caster->GetPetGUID())
3462 return;
3464 if (!unitTarget)
3465 return;
3466 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
3467 if (!pet_entry)
3468 return;
3469 uint32 level = m_caster->getLevel();
3470 Pet* spawnCreature = new Pet(SUMMON_PET);
3472 int32 duration = GetSpellDuration(m_spellInfo);
3473 if(Player* modOwner = m_caster->GetSpellModOwner())
3474 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
3476 if (m_caster->GetTypeId()==TYPEID_PLAYER && spawnCreature->LoadPetFromDB((Player*)m_caster,pet_entry))
3478 // Summon in dest location
3479 float x, y, z;
3480 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3482 x = m_targets.m_destX;
3483 y = m_targets.m_destY;
3484 z = m_targets.m_destZ;
3485 spawnCreature->Relocate(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, -m_caster->GetOrientation());
3488 // set timer for unsummon
3489 if (duration > 0)
3490 spawnCreature->SetDuration(duration);
3492 return;
3495 Map *map = m_caster->GetMap();
3496 uint32 pet_number = sObjectMgr.GeneratePetNumber();
3497 if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
3498 m_spellInfo->EffectMiscValue[i], pet_number))
3500 sLog.outErrorDb("Spell::EffectSummon: no such creature entry %u",m_spellInfo->EffectMiscValue[i]);
3501 delete spawnCreature;
3502 return;
3505 // Summon in dest location
3506 float x, y, z;
3507 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3509 x = m_targets.m_destX;
3510 y = m_targets.m_destY;
3511 z = m_targets.m_destZ;
3513 else
3514 m_caster->GetClosePoint(x, y, z, spawnCreature->GetObjectSize());
3516 spawnCreature->Relocate(x, y, z, -m_caster->GetOrientation());
3518 if (!spawnCreature->IsPositionValid())
3520 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
3521 spawnCreature->GetGUIDLow(), spawnCreature->GetEntry(), spawnCreature->GetPositionX(), spawnCreature->GetPositionY());
3522 delete spawnCreature;
3523 return;
3526 // set timer for unsummon
3527 if (duration > 0)
3528 spawnCreature->SetDuration(duration);
3530 spawnCreature->SetOwnerGUID(m_caster->GetGUID());
3531 spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
3532 spawnCreature->setPowerType(POWER_MANA);
3533 spawnCreature->setFaction(m_caster->getFaction());
3534 spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS, 0);
3535 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
3536 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
3537 spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
3538 spawnCreature->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
3539 spawnCreature->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
3540 spawnCreature->SetCreatorGUID(m_caster->GetGUID());
3541 spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3543 spawnCreature->InitStatsForLevel(level, m_caster);
3545 spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
3547 spawnCreature->AIM_Initialize();
3548 spawnCreature->InitPetCreateSpells();
3549 spawnCreature->InitLevelupSpellsForLevel();
3550 spawnCreature->SetHealth(spawnCreature->GetMaxHealth());
3551 spawnCreature->SetPower(POWER_MANA, spawnCreature->GetMaxPower(POWER_MANA));
3553 std::string name = m_caster->GetName();
3554 name.append(petTypeSuffix[spawnCreature->getPetType()]);
3555 spawnCreature->SetName( name );
3557 map->Add((Creature*)spawnCreature);
3559 m_caster->SetPet(spawnCreature);
3561 if (m_caster->GetTypeId() == TYPEID_PLAYER)
3563 spawnCreature->GetCharmInfo()->SetReactState( REACT_DEFENSIVE );
3564 spawnCreature->SavePetToDB(PET_SAVE_AS_CURRENT);
3565 ((Player*)m_caster)->PetSpellInitialize();
3569 void Spell::EffectLearnSpell(uint32 i)
3571 if (!unitTarget)
3572 return;
3574 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
3576 if (m_caster->GetTypeId() == TYPEID_PLAYER)
3577 EffectLearnPetSpell(i);
3579 return;
3582 Player *player = (Player*)unitTarget;
3584 uint32 spellToLearn = ((m_spellInfo->Id==SPELL_ID_GENERIC_LEARN) || (m_spellInfo->Id==SPELL_ID_GENERIC_LEARN_PET)) ? damage : m_spellInfo->EffectTriggerSpell[i];
3585 player->learnSpell(spellToLearn,false);
3587 sLog.outDebug( "Spell: Player %u has learned spell %u from NpcGUID=%u", player->GetGUIDLow(), spellToLearn, m_caster->GetGUIDLow() );
3590 void Spell::EffectDispel(uint32 i)
3592 if (!unitTarget)
3593 return;
3595 // Fill possible dispell list
3596 std::vector <Aura *> dispel_list;
3598 // Create dispel mask by dispel type
3599 uint32 dispel_type = m_spellInfo->EffectMiscValue[i];
3600 uint32 dispelMask = GetDispellMask( DispelType(dispel_type) );
3601 Unit::AuraMap const& auras = unitTarget->GetAuras();
3602 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3604 Aura *aur = (*itr).second;
3605 if (aur && (1<<aur->GetSpellProto()->Dispel) & dispelMask)
3607 if(aur->GetSpellProto()->Dispel == DISPEL_MAGIC)
3609 bool positive = true;
3610 if (!aur->IsPositive())
3611 positive = false;
3612 else
3613 positive = (aur->GetSpellProto()->AttributesEx & SPELL_ATTR_EX_NEGATIVE)==0;
3615 // do not remove positive auras if friendly target
3616 // negative auras if non-friendly target
3617 if (positive == unitTarget->IsFriendlyTo(m_caster))
3618 continue;
3620 // Add aura to dispel list (all stack cases)
3621 for(int k = 0; k < aur->GetStackAmount(); ++k)
3622 dispel_list.push_back(aur);
3625 // Ok if exist some buffs for dispel try dispel it
3626 if (!dispel_list.empty())
3628 std::list < std::pair<uint32,uint64> > success_list;// (spell_id,casterGuid)
3629 std::list < uint32 > fail_list; // spell_id
3631 // some spells have effect value = 0 and all from its by meaning expect 1
3632 if(!damage)
3633 damage = 1;
3635 // Dispell N = damage buffs (or while exist buffs for dispel)
3636 for (int32 count=0; count < damage && !dispel_list.empty(); ++count)
3638 // Random select buff for dispel
3639 std::vector<Aura*>::iterator dispel_itr = dispel_list.begin();
3640 std::advance(dispel_itr,urand(0, dispel_list.size()-1));
3642 Aura *aur = *dispel_itr;
3644 // remove entry from dispel_list
3645 dispel_list.erase(dispel_itr);
3647 SpellEntry const* spellInfo = aur->GetSpellProto();
3648 // Base dispel chance
3649 // TODO: possible chance depend from spell level??
3650 int32 miss_chance = 0;
3651 // Apply dispel mod from aura caster
3652 if (Unit *caster = aur->GetCaster())
3654 if ( Player* modOwner = caster->GetSpellModOwner() )
3655 modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_RESIST_DISPEL_CHANCE, miss_chance, this);
3657 // Try dispel
3658 if (roll_chance_i(miss_chance))
3659 fail_list.push_back(spellInfo->Id);
3660 else
3661 success_list.push_back(std::pair<uint32,uint64>(aur->GetId(),aur->GetCasterGUID()));
3663 // Send success log and really remove auras
3664 if (!success_list.empty())
3666 int32 count = success_list.size();
3667 WorldPacket data(SMSG_SPELLDISPELLOG, 8+8+4+1+4+count*5);
3668 data.append(unitTarget->GetPackGUID()); // Victim GUID
3669 data.append(m_caster->GetPackGUID()); // Caster GUID
3670 data << uint32(m_spellInfo->Id); // Dispel spell id
3671 data << uint8(0); // not used
3672 data << uint32(count); // count
3673 for (std::list<std::pair<uint32,uint64> >::iterator j = success_list.begin(); j != success_list.end(); ++j)
3675 SpellEntry const* spellInfo = sSpellStore.LookupEntry(j->first);
3676 data << uint32(spellInfo->Id); // Spell Id
3677 data << uint8(0); // 0 - dispeled !=0 cleansed
3678 unitTarget->RemoveSingleAuraDueToSpellByDispel(spellInfo->Id, j->second, m_caster);
3680 m_caster->SendMessageToSet(&data, true);
3682 // On success dispel
3683 // Devour Magic
3684 if (m_spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK && m_spellInfo->Category == SPELLCATEGORY_DEVOUR_MAGIC)
3686 int32 heal_amount = m_spellInfo->CalculateSimpleValue(1);
3687 m_caster->CastCustomSpell(m_caster, 19658, &heal_amount, NULL, NULL, true);
3690 // Send fail log to client
3691 if (!fail_list.empty())
3693 // Failed to dispell
3694 WorldPacket data(SMSG_DISPEL_FAILED, 8+8+4+4*fail_list.size());
3695 data << uint64(m_caster->GetGUID()); // Caster GUID
3696 data << uint64(unitTarget->GetGUID()); // Victim GUID
3697 data << uint32(m_spellInfo->Id); // Dispell spell id
3698 for (std::list< uint32 >::iterator j = fail_list.begin(); j != fail_list.end(); ++j)
3699 data << uint32(*j); // Spell Id
3700 m_caster->SendMessageToSet(&data, true);
3705 void Spell::EffectDualWield(uint32 /*i*/)
3707 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
3708 ((Player*)unitTarget)->SetCanDualWield(true);
3711 void Spell::EffectPull(uint32 /*i*/)
3713 // TODO: create a proper pull towards distract spell center for distract
3714 sLog.outDebug("WORLD: Spell Effect DUMMY");
3717 void Spell::EffectDistract(uint32 /*i*/)
3719 // Check for possible target
3720 if (!unitTarget || unitTarget->isInCombat())
3721 return;
3723 // target must be OK to do this
3724 if( unitTarget->hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_STUNNED | UNIT_STAT_FLEEING ) )
3725 return;
3727 float angle = unitTarget->GetAngle(m_targets.m_destX, m_targets.m_destY);
3729 if ( unitTarget->GetTypeId() == TYPEID_PLAYER )
3731 // For players just turn them
3732 WorldPacket data;
3733 ((Player*)unitTarget)->BuildTeleportAckMsg(&data, unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), angle);
3734 ((Player*)unitTarget)->GetSession()->SendPacket( &data );
3735 ((Player*)unitTarget)->SetPosition(unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), angle, false);
3737 else
3739 // Set creature Distracted, Stop it, And turn it
3740 unitTarget->SetOrientation(angle);
3741 unitTarget->StopMoving();
3742 unitTarget->GetMotionMaster()->MoveDistract(damage * IN_MILISECONDS);
3746 void Spell::EffectPickPocket(uint32 /*i*/)
3748 if (m_caster->GetTypeId() != TYPEID_PLAYER)
3749 return;
3751 // victim must be creature and attackable
3752 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || m_caster->IsFriendlyTo(unitTarget))
3753 return;
3755 // victim have to be alive and humanoid or undead
3756 if (unitTarget->isAlive() && (unitTarget->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD) != 0)
3758 int32 chance = 10 + int32(m_caster->getLevel()) - int32(unitTarget->getLevel());
3760 if (chance > irand(0, 19))
3762 // Stealing successful
3763 //sLog.outDebug("Sending loot from pickpocket");
3764 ((Player*)m_caster)->SendLoot(unitTarget->GetGUID(),LOOT_PICKPOCKETING);
3766 else
3768 // Reveal action + get attack
3769 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
3770 if (((Creature*)unitTarget)->AI())
3771 ((Creature*)unitTarget)->AI()->AttackedBy(m_caster);
3776 void Spell::EffectAddFarsight(uint32 i)
3778 if(m_caster->GetTypeId() != TYPEID_PLAYER)
3779 return;
3781 int32 duration = GetSpellDuration(m_spellInfo);
3782 DynamicObject* dynObj = new DynamicObject;
3784 // set radius to 0: spell not expected to work as persistent aura
3785 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))
3787 delete dynObj;
3788 return;
3790 dynObj->SetUInt32Value(OBJECT_FIELD_TYPE, 65);
3791 dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x80000002);
3792 m_caster->AddDynObject(dynObj);
3793 m_caster->GetMap()->Add(dynObj);
3794 ((Player*)m_caster)->SetFarSightGUID(dynObj->GetGUID());
3797 void Spell::EffectSummonWild(uint32 i, uint32 forceFaction)
3799 uint32 creature_entry = m_spellInfo->EffectMiscValue[i];
3800 if (!creature_entry)
3801 return;
3803 uint32 level = m_caster->getLevel();
3805 // level of creature summoned using engineering item based at engineering skill level
3806 if (m_caster->GetTypeId()==TYPEID_PLAYER && m_CastItem)
3808 ItemPrototype const *proto = m_CastItem->GetProto();
3809 if (proto && proto->RequiredSkill == SKILL_ENGINERING)
3811 uint16 skill202 = ((Player*)m_caster)->GetSkillValue(SKILL_ENGINERING);
3812 if (skill202)
3813 level = skill202/5;
3817 // select center of summon position
3818 float center_x = m_targets.m_destX;
3819 float center_y = m_targets.m_destY;
3820 float center_z = m_targets.m_destZ;
3822 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3823 int32 duration = GetSpellDuration(m_spellInfo);
3824 TempSummonType summonType = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_OR_DEAD_DESPAWN;
3826 int32 amount = damage > 0 ? damage : 1;
3828 for(int32 count = 0; count < amount; ++count)
3830 float px, py, pz;
3831 // If dest location if present
3832 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3834 // Summon 1 unit in dest location
3835 if (count == 0)
3837 px = m_targets.m_destX;
3838 py = m_targets.m_destY;
3839 pz = m_targets.m_destZ;
3841 // Summon in random point all other units if location present
3842 else
3843 m_caster->GetRandomPoint(center_x, center_y, center_z, radius, px, py, pz);
3845 // Summon if dest location not present near caster
3846 else
3847 m_caster->GetClosePoint(px, py, pz, 3.0f);
3849 if(Creature *summon = m_caster->SummonCreature(creature_entry, px, py, pz, m_caster->GetOrientation(), summonType, duration))
3851 summon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3852 summon->SetCreatorGUID(m_caster->GetGUID());
3854 if(forceFaction)
3855 summon->setFaction(forceFaction);
3860 void Spell::EffectSummonGuardian(uint32 i, uint32 forceFaction)
3862 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
3863 if (!pet_entry)
3864 return;
3866 // in another case summon new
3867 uint32 level = m_caster->getLevel();
3869 // level of pet summoned using engineering item based at engineering skill level
3870 if (m_caster->GetTypeId() == TYPEID_PLAYER && m_CastItem)
3872 ItemPrototype const *proto = m_CastItem->GetProto();
3873 if (proto && proto->RequiredSkill == SKILL_ENGINERING)
3875 uint16 skill202 = ((Player*)m_caster)->GetSkillValue(SKILL_ENGINERING);
3876 if (skill202)
3878 level = skill202 / 5;
3883 // select center of summon position
3884 float center_x = m_targets.m_destX;
3885 float center_y = m_targets.m_destY;
3886 float center_z = m_targets.m_destZ;
3888 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3889 int32 duration = GetSpellDuration(m_spellInfo);
3890 if(Player* modOwner = m_caster->GetSpellModOwner())
3891 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
3893 int32 amount = damage > 0 ? damage : 1;
3895 for(int32 count = 0; count < amount; ++count)
3897 Pet* spawnCreature = new Pet(GUARDIAN_PET);
3899 Map *map = m_caster->GetMap();
3900 uint32 pet_number = sObjectMgr.GeneratePetNumber();
3901 if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map,m_caster->GetPhaseMask(),
3902 m_spellInfo->EffectMiscValue[i], pet_number))
3904 sLog.outError("no such creature entry %u", m_spellInfo->EffectMiscValue[i]);
3905 delete spawnCreature;
3906 return;
3909 float px, py, pz;
3910 // If dest location if present
3911 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3913 // Summon 1 unit in dest location
3914 if (count == 0)
3916 px = m_targets.m_destX;
3917 py = m_targets.m_destY;
3918 pz = m_targets.m_destZ;
3920 // Summon in random point all other units if location present
3921 else
3922 m_caster->GetRandomPoint(center_x, center_y, center_z, radius, px, py, pz);
3924 // Summon if dest location not present near caster
3925 else
3926 m_caster->GetClosePoint(px, py, pz,spawnCreature->GetObjectSize());
3928 spawnCreature->Relocate(px, py, pz, m_caster->GetOrientation());
3930 if (!spawnCreature->IsPositionValid())
3932 sLog.outError("Pet (guidlow %d, entry %d) not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)",
3933 spawnCreature->GetGUIDLow(), spawnCreature->GetEntry(), spawnCreature->GetPositionX(), spawnCreature->GetPositionY());
3934 delete spawnCreature;
3935 return;
3938 if (duration > 0)
3939 spawnCreature->SetDuration(duration);
3941 spawnCreature->SetOwnerGUID(m_caster->GetGUID());
3942 spawnCreature->setPowerType(POWER_MANA);
3943 spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, spawnCreature->GetCreatureInfo()->npcflag);
3944 spawnCreature->setFaction(forceFaction ? forceFaction : m_caster->getFaction());
3945 spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS, 0);
3946 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
3947 spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
3948 spawnCreature->SetCreatorGUID(m_caster->GetGUID());
3949 spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3951 spawnCreature->InitStatsForLevel(level, m_caster);
3952 spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
3954 spawnCreature->AIM_Initialize();
3956 m_caster->AddGuardian(spawnCreature);
3958 map->Add((Creature*)spawnCreature);
3962 void Spell::EffectTeleUnitsFaceCaster(uint32 i)
3964 if (!unitTarget)
3965 return;
3967 if (unitTarget->isInFlight())
3968 return;
3970 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3972 float fx, fy, fz;
3973 m_caster->GetClosePoint(fx, fy, fz, unitTarget->GetObjectSize(), dis);
3975 unitTarget->NearTeleportTo(fx, fy, fz, -m_caster->GetOrientation(), unitTarget==m_caster);
3978 void Spell::EffectLearnSkill(uint32 i)
3980 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
3981 return;
3983 if (damage < 0)
3984 return;
3986 uint32 skillid = m_spellInfo->EffectMiscValue[i];
3987 uint16 skillval = ((Player*)unitTarget)->GetPureSkillValue(skillid);
3988 ((Player*)unitTarget)->SetSkill(skillid, skillval ? skillval : 1, damage * 75);
3991 void Spell::EffectAddHonor(uint32 /*i*/)
3993 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
3994 return;
3996 // not scale value for item based reward (/10 value expected)
3997 if (m_CastItem)
3999 ((Player*)unitTarget)->RewardHonor(NULL, 1, damage / 10);
4000 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());
4001 return;
4004 // do not allow to add too many honor for player (50 * 21) = 1040 at level 70, or (50 * 31) = 1550 at level 80
4005 if (damage <= 50)
4007 uint32 honor_reward = MaNGOS::Honor::hk_honor_at_level(unitTarget->getLevel(), damage);
4008 ((Player*)unitTarget)->RewardHonor(NULL, 1, honor_reward);
4009 sLog.outDebug("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (scale) to player: %u", m_spellInfo->Id, honor_reward, ((Player*)unitTarget)->GetGUIDLow());
4011 else
4013 //maybe we have correct honor_gain in damage already
4014 ((Player*)unitTarget)->RewardHonor(NULL, 1, damage);
4015 sLog.outError("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (non scale) for player: %u", m_spellInfo->Id, damage, ((Player*)unitTarget)->GetGUIDLow());
4019 void Spell::EffectTradeSkill(uint32 /*i*/)
4021 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4022 return;
4023 // uint32 skillid = m_spellInfo->EffectMiscValue[i];
4024 // uint16 skillmax = ((Player*)unitTarget)->(skillid);
4025 // ((Player*)unitTarget)->SetSkill(skillid,skillval?skillval:1,skillmax+75);
4028 void Spell::EffectEnchantItemPerm(uint32 effect_idx)
4030 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4031 return;
4032 if (!itemTarget)
4033 return;
4035 Player* p_caster = (Player*)m_caster;
4037 // not grow at item use at item case
4038 p_caster->UpdateCraftSkill(m_spellInfo->Id);
4040 uint32 enchant_id = m_spellInfo->EffectMiscValue[effect_idx];
4041 if (!enchant_id)
4042 return;
4044 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4045 if (!pEnchant)
4046 return;
4048 // item can be in trade slot and have owner diff. from caster
4049 Player* item_owner = itemTarget->GetOwner();
4050 if (!item_owner)
4051 return;
4053 if (item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4055 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(perm): %s (Entry: %d) for player: %s (Account: %u)",
4056 p_caster->GetName(),p_caster->GetSession()->GetAccountId(),
4057 itemTarget->GetProto()->Name1,itemTarget->GetEntry(),
4058 item_owner->GetName(),item_owner->GetSession()->GetAccountId());
4061 // remove old enchanting before applying new if equipped
4062 item_owner->ApplyEnchantment(itemTarget,PERM_ENCHANTMENT_SLOT,false);
4064 itemTarget->SetEnchantment(PERM_ENCHANTMENT_SLOT, enchant_id, 0, 0);
4066 // add new enchanting if equipped
4067 item_owner->ApplyEnchantment(itemTarget,PERM_ENCHANTMENT_SLOT,true);
4070 void Spell::EffectEnchantItemPrismatic(uint32 effect_idx)
4072 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4073 return;
4074 if (!itemTarget)
4075 return;
4077 Player* p_caster = (Player*)m_caster;
4079 uint32 enchant_id = m_spellInfo->EffectMiscValue[effect_idx];
4080 if (!enchant_id)
4081 return;
4083 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4084 if (!pEnchant)
4085 return;
4087 // support only enchantings with add socket in this slot
4089 bool add_socket = false;
4090 for(int i = 0; i < 3; ++i)
4092 if (pEnchant->type[i]==ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET)
4094 add_socket = true;
4095 break;
4098 if (!add_socket)
4100 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.",
4101 m_spellInfo->Id,SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC,ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET);
4102 return;
4106 // item can be in trade slot and have owner diff. from caster
4107 Player* item_owner = itemTarget->GetOwner();
4108 if (!item_owner)
4109 return;
4111 if (item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4113 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(perm): %s (Entry: %d) for player: %s (Account: %u)",
4114 p_caster->GetName(),p_caster->GetSession()->GetAccountId(),
4115 itemTarget->GetProto()->Name1,itemTarget->GetEntry(),
4116 item_owner->GetName(),item_owner->GetSession()->GetAccountId());
4119 // remove old enchanting before applying new if equipped
4120 item_owner->ApplyEnchantment(itemTarget,PRISMATIC_ENCHANTMENT_SLOT,false);
4122 itemTarget->SetEnchantment(PRISMATIC_ENCHANTMENT_SLOT, enchant_id, 0, 0);
4124 // add new enchanting if equipped
4125 item_owner->ApplyEnchantment(itemTarget,PRISMATIC_ENCHANTMENT_SLOT,true);
4128 void Spell::EffectEnchantItemTmp(uint32 i)
4130 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4131 return;
4133 Player* p_caster = (Player*)m_caster;
4135 // Rockbiter Weapon apply to both weapon
4136 if (m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN && m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000400000))
4138 uint32 spell_id = 0;
4140 // enchanting spell selected by calculated damage-per-sec stored in Effect[1] base value
4141 // Note: damage calculated (correctly) with rounding int32(float(v)) but
4142 // RW enchantments applied damage int32(float(v)+0.5), this create 0..1 difference sometime
4143 switch(damage)
4145 // Rank 1
4146 case 2: spell_id = 36744; break; // 0% [ 7% == 2, 14% == 2, 20% == 2]
4147 // Rank 2
4148 case 4: spell_id = 36753; break; // 0% [ 7% == 4, 14% == 4]
4149 case 5: spell_id = 36751; break; // 20%
4150 // Rank 3
4151 case 6: spell_id = 36754; break; // 0% [ 7% == 6, 14% == 6]
4152 case 7: spell_id = 36755; break; // 20%
4153 // Rank 4
4154 case 9: spell_id = 36761; break; // 0% [ 7% == 6]
4155 case 10: spell_id = 36758; break; // 14%
4156 case 11: spell_id = 36760; break; // 20%
4157 default:
4158 sLog.outError("Spell::EffectEnchantItemTmp: Damage %u not handled in S'RW",damage);
4159 return;
4163 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id);
4164 if (!spellInfo)
4166 sLog.outError("Spell::EffectEnchantItemTmp: unknown spell id %i", spell_id);
4167 return;
4170 for(int j = BASE_ATTACK; j <= OFF_ATTACK; ++j)
4172 if (Item* item = p_caster->GetWeaponForAttack(WeaponAttackType(j)))
4174 if (item->IsFitToSpellRequirements(m_spellInfo))
4176 Spell *spell = new Spell(m_caster, spellInfo, true);
4177 SpellCastTargets targets;
4178 targets.setItemTarget( item );
4179 spell->prepare(&targets);
4183 return;
4186 if (!itemTarget)
4187 return;
4189 uint32 enchant_id = m_spellInfo->EffectMiscValue[i];
4191 if (!enchant_id)
4193 sLog.outError("Spell %u Effect %u (SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY) have 0 as enchanting id",m_spellInfo->Id,i);
4194 return;
4197 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4198 if(!pEnchant)
4200 sLog.outError("Spell %u Effect %u (SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY) have not existed enchanting id %u ",m_spellInfo->Id,i,enchant_id);
4201 return;
4204 // select enchantment duration
4205 uint32 duration;
4207 // rogue family enchantments exception by duration
4208 if(m_spellInfo->Id == 38615)
4209 duration = 1800; // 30 mins
4210 // other rogue family enchantments always 1 hour (some have spell damage=0, but some have wrong data in EffBasePoints)
4211 else if(m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE)
4212 duration = 3600; // 1 hour
4213 // shaman family enchantments
4214 else if(m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN)
4215 duration = 1800; // 30 mins
4216 // other cases with this SpellVisual already selected
4217 else if(m_spellInfo->SpellVisual[0] == 215)
4218 duration = 1800; // 30 mins
4219 // some fishing pole bonuses
4220 else if(m_spellInfo->SpellVisual[0] == 563)
4221 duration = 600; // 10 mins
4222 // shaman rockbiter enchantments
4223 else if(m_spellInfo->SpellVisual[0] == 0)
4224 duration = 1800; // 30 mins
4225 else if(m_spellInfo->Id == 29702)
4226 duration = 300; // 5 mins
4227 else if(m_spellInfo->Id == 37360)
4228 duration = 300; // 5 mins
4229 // default case
4230 else
4231 duration = 3600; // 1 hour
4233 // item can be in trade slot and have owner diff. from caster
4234 Player* item_owner = itemTarget->GetOwner();
4235 if(!item_owner)
4236 return;
4238 if(item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4240 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(temp): %s (Entry: %d) for player: %s (Account: %u)",
4241 p_caster->GetName(), p_caster->GetSession()->GetAccountId(),
4242 itemTarget->GetProto()->Name1, itemTarget->GetEntry(),
4243 item_owner->GetName(), item_owner->GetSession()->GetAccountId());
4246 // remove old enchanting before applying new if equipped
4247 item_owner->ApplyEnchantment(itemTarget,TEMP_ENCHANTMENT_SLOT, false);
4249 itemTarget->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, duration * 1000, 0);
4251 // add new enchanting if equipped
4252 item_owner->ApplyEnchantment(itemTarget, TEMP_ENCHANTMENT_SLOT, true);
4255 void Spell::EffectTameCreature(uint32 /*i*/)
4257 // Caster must be player, checked in Spell::CheckCast
4258 // Spell can be triggered, we need to check original caster prior to caster
4259 Player* plr = (Player*)(m_originalCaster ? m_originalCaster : m_caster);
4261 Creature* creatureTarget = (Creature*)unitTarget;
4263 // cast finish successfully
4264 //SendChannelUpdate(0);
4265 finish();
4267 Pet* pet = plr->CreateTamedPetFrom(creatureTarget, m_spellInfo->Id);
4268 if(!pet) // in versy specific state like near world end/etc.
4269 return;
4271 // "kill" original creature
4272 creatureTarget->ForcedDespawn();
4274 uint32 level = (creatureTarget->getLevel() < (plr->getLevel() - 5)) ? (plr->getLevel() - 5) : creatureTarget->getLevel();
4276 // prepare visual effect for levelup
4277 pet->SetUInt32Value(UNIT_FIELD_LEVEL, level - 1);
4279 // add to world
4280 pet->GetMap()->Add((Creature*)pet);
4282 // visual effect for levelup
4283 pet->SetUInt32Value(UNIT_FIELD_LEVEL, level);
4285 // caster have pet now
4286 plr->SetPet(pet);
4288 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
4289 plr->PetSpellInitialize();
4292 void Spell::EffectSummonPet(uint32 i)
4294 uint32 petentry = m_spellInfo->EffectMiscValue[i];
4296 Pet *OldSummon = m_caster->GetPet();
4298 // if pet requested type already exist
4299 if( OldSummon )
4301 if(petentry == 0 || OldSummon->GetEntry() == petentry)
4303 // pet in corpse state can't be summoned
4304 if( OldSummon->isDead() )
4305 return;
4307 OldSummon->GetMap()->Remove((Creature*)OldSummon,false);
4309 float px, py, pz;
4310 m_caster->GetClosePoint(px, py, pz, OldSummon->GetObjectSize());
4312 OldSummon->Relocate(px, py, pz, OldSummon->GetOrientation());
4313 m_caster->GetMap()->Add((Creature*)OldSummon);
4315 if(m_caster->GetTypeId() == TYPEID_PLAYER && OldSummon->isControlled() )
4317 ((Player*)m_caster)->PetSpellInitialize();
4319 return;
4322 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4323 ((Player*)m_caster)->RemovePet(OldSummon,(OldSummon->getPetType()==HUNTER_PET ? PET_SAVE_AS_DELETED : PET_SAVE_NOT_IN_SLOT),false);
4324 else
4325 return;
4328 Pet* NewSummon = new Pet;
4330 // petentry==0 for hunter "call pet" (current pet summoned if any)
4331 if(m_caster->GetTypeId() == TYPEID_PLAYER && NewSummon->LoadPetFromDB((Player*)m_caster,petentry))
4333 if(NewSummon->getPetType()==SUMMON_PET)
4335 // Remove Demonic Sacrifice auras (known pet)
4336 Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4337 for(Unit::AuraList::const_iterator itr = auraClassScripts.begin();itr!=auraClassScripts.end();)
4339 if((*itr)->GetModifier()->m_miscvalue == 2228)
4341 m_caster->RemoveAurasDueToSpell((*itr)->GetId());
4342 itr = auraClassScripts.begin();
4344 else
4345 ++itr;
4349 return;
4352 // not error in case fail hunter call pet
4353 if(!petentry)
4355 delete NewSummon;
4356 return;
4359 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(petentry);
4361 if(!cInfo)
4363 sLog.outError("EffectSummonPet: creature entry %u not found.",petentry);
4364 delete NewSummon;
4365 return;
4368 Map *map = m_caster->GetMap();
4369 uint32 pet_number = sObjectMgr.GeneratePetNumber();
4370 if(!NewSummon->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
4371 petentry, pet_number))
4373 delete NewSummon;
4374 return;
4377 float px, py, pz;
4378 m_caster->GetClosePoint(px, py, pz, NewSummon->GetObjectSize());
4380 NewSummon->Relocate(px, py, pz, m_caster->GetOrientation());
4382 if(!NewSummon->IsPositionValid())
4384 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
4385 NewSummon->GetGUIDLow(), NewSummon->GetEntry(), NewSummon->GetPositionX(), NewSummon->GetPositionY());
4386 delete NewSummon;
4387 return;
4390 uint32 petlevel = m_caster->getLevel();
4391 NewSummon->setPetType(SUMMON_PET);
4393 uint32 faction = m_caster->getFaction();
4394 if(m_caster->GetTypeId() == TYPEID_UNIT)
4396 if ( ((Creature*)m_caster)->isTotem() )
4397 NewSummon->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE);
4398 else
4399 NewSummon->GetCharmInfo()->SetReactState(REACT_DEFENSIVE);
4402 NewSummon->SetOwnerGUID(m_caster->GetGUID());
4403 NewSummon->SetCreatorGUID(m_caster->GetGUID());
4404 NewSummon->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
4405 NewSummon->setFaction(faction);
4406 NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
4407 NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
4408 NewSummon->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
4409 NewSummon->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
4410 NewSummon->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
4411 NewSummon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
4413 NewSummon->GetCharmInfo()->SetPetNumber(pet_number, true);
4414 // this enables pet details window (Shift+P)
4416 // this enables popup window (pet dismiss, cancel), hunter pet additional flags set later
4417 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4418 NewSummon->SetUInt32Value(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE);
4420 if(m_caster->IsPvP())
4421 NewSummon->SetPvP(true);
4423 NewSummon->InitStatsForLevel(petlevel, m_caster);
4424 NewSummon->InitPetCreateSpells();
4425 NewSummon->InitLevelupSpellsForLevel();
4426 NewSummon->InitTalentForLevel();
4428 if(NewSummon->getPetType()==SUMMON_PET)
4430 // Remove Demonic Sacrifice auras (new pet)
4431 Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4432 for(Unit::AuraList::const_iterator itr = auraClassScripts.begin();itr!=auraClassScripts.end();)
4434 if((*itr)->GetModifier()->m_miscvalue==2228)
4436 m_caster->RemoveAurasDueToSpell((*itr)->GetId());
4437 itr = auraClassScripts.begin();
4439 else
4440 ++itr;
4443 // generate new name for summon pet
4444 std::string new_name=sObjectMgr.GeneratePetName(petentry);
4445 if(!new_name.empty())
4446 NewSummon->SetName(new_name);
4448 else if(NewSummon->getPetType()==HUNTER_PET)
4449 NewSummon->SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_NOT_ALLOWED);
4451 NewSummon->AIM_Initialize();
4452 NewSummon->SetHealth(NewSummon->GetMaxHealth());
4453 NewSummon->SetPower(POWER_MANA, NewSummon->GetMaxPower(POWER_MANA));
4455 map->Add((Creature*)NewSummon);
4457 m_caster->SetPet(NewSummon);
4458 sLog.outDebug("New Pet has guid %u", NewSummon->GetGUIDLow());
4460 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4462 NewSummon->SavePetToDB(PET_SAVE_AS_CURRENT);
4463 ((Player*)m_caster)->PetSpellInitialize();
4467 void Spell::EffectLearnPetSpell(uint32 i)
4469 if(m_caster->GetTypeId() != TYPEID_PLAYER)
4470 return;
4472 Player *_player = (Player*)m_caster;
4474 Pet *pet = _player->GetPet();
4475 if(!pet)
4476 return;
4477 if(!pet->isAlive())
4478 return;
4480 SpellEntry const *learn_spellproto = sSpellStore.LookupEntry(m_spellInfo->EffectTriggerSpell[i]);
4481 if(!learn_spellproto)
4482 return;
4484 pet->learnSpell(learn_spellproto->Id);
4486 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
4487 _player->PetSpellInitialize();
4490 void Spell::EffectTaunt(uint32 /*i*/)
4492 if (!unitTarget)
4493 return;
4495 // this effect use before aura Taunt apply for prevent taunt already attacking target
4496 // for spell as marked "non effective at already attacking target"
4497 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4499 if (unitTarget->getVictim()==m_caster)
4501 SendCastResult(SPELL_FAILED_DONT_REPORT);
4502 return;
4506 // Also use this effect to set the taunter's threat to the taunted creature's highest value
4507 if (unitTarget->CanHaveThreatList() && unitTarget->getThreatManager().getCurrentVictim())
4508 unitTarget->getThreatManager().addThreat(m_caster,unitTarget->getThreatManager().getCurrentVictim()->getThreat());
4511 void Spell::EffectWeaponDmg(uint32 i)
4513 if(!unitTarget)
4514 return;
4515 if(!unitTarget->isAlive())
4516 return;
4518 // multiple weapon dmg effect workaround
4519 // execute only the last weapon damage
4520 // and handle all effects at once
4521 for (int j = 0; j < 3; ++j)
4523 switch(m_spellInfo->Effect[j])
4525 case SPELL_EFFECT_WEAPON_DAMAGE:
4526 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
4527 case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
4528 case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
4529 if (j < i) // we must calculate only at last weapon effect
4530 return;
4531 break;
4535 // some spell specific modifiers
4536 bool spellBonusNeedWeaponDamagePercentMod = false; // if set applied weapon damage percent mode to spell bonus
4538 float weaponDamagePercentMod = 1.0f; // applied to weapon damage and to fixed effect damage bonus
4539 float totalDamagePercentMod = 1.0f; // applied to final bonus+weapon damage
4540 bool normalized = false;
4542 int32 spell_bonus = 0; // bonus specific for spell
4543 switch(m_spellInfo->SpellFamilyName)
4545 case SPELLFAMILY_WARRIOR:
4547 // Devastate bonus and sunder armor refresh
4548 if(m_spellInfo->SpellVisual[0] == 12295 && m_spellInfo->SpellIconID == 1508)
4550 uint32 stack = 0;
4551 // Need refresh all Sunder Armor auras from this caster
4552 Unit::AuraMap& suAuras = unitTarget->GetAuras();
4553 SpellEntry const *spellInfo;
4554 for(Unit::AuraMap::iterator itr = suAuras.begin(); itr != suAuras.end(); ++itr)
4556 spellInfo = (*itr).second->GetSpellProto();
4557 if( spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR &&
4558 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000004000)) &&
4559 (*itr).second->GetCasterGUID() == m_caster->GetGUID())
4561 (*itr).second->RefreshAura();
4562 stack = (*itr).second->GetStackAmount();
4563 break;
4566 if (stack)
4567 spell_bonus += stack * CalculateDamage(2, unitTarget);
4568 if (!stack || stack < spellInfo->StackAmount)
4569 // Devastate causing Sunder Armor Effect
4570 // and no need to cast over max stack amount
4571 m_caster->CastSpell(unitTarget, 58567, true);
4573 break;
4575 case SPELLFAMILY_ROGUE:
4577 // Mutilate (for each hand)
4578 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x600000000))
4580 bool found = false;
4581 // fast check
4582 if(unitTarget->HasAuraState(AURA_STATE_DEADLY_POISON))
4583 found = true;
4584 // full aura scan
4585 else
4587 Unit::AuraMap const& auras = unitTarget->GetAuras();
4588 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
4590 if(itr->second->GetSpellProto()->Dispel == DISPEL_POISON)
4592 found = true;
4593 break;
4598 if(found)
4599 totalDamagePercentMod *= 1.2f; // 120% if poisoned
4601 // Fan of Knives
4602 else if (m_caster->GetTypeId()==TYPEID_PLAYER && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0004000000000000)))
4604 Item* weapon = ((Player*)m_caster)->GetWeaponForAttack(m_attackType,true,true);
4605 if (weapon && weapon->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER)
4606 totalDamagePercentMod *= 1.5f; // 150% to daggers
4608 break;
4610 case SPELLFAMILY_PALADIN:
4612 // Seal of Command - receive benefit from Spell Damage and Healing
4613 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x00000002000000))
4615 spellBonusNeedWeaponDamagePercentMod = true;// apply weaponDamagePercentMod to spell_bonus (and then to all bonus, fixes and weapon already have applied)
4616 spell_bonus += int32(0.23f*m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo)));
4617 spell_bonus += int32(0.29f*m_caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellInfo), unitTarget));
4619 break;
4621 case SPELLFAMILY_SHAMAN:
4623 // Skyshatter Harness item set bonus
4624 // Stormstrike
4625 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x001000000000))
4627 Unit::AuraList const& m_OverrideClassScript = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4628 for(Unit::AuraList::const_iterator citr = m_OverrideClassScript.begin(); citr != m_OverrideClassScript.end(); ++citr)
4630 // Stormstrike AP Buff
4631 if ( (*citr)->GetModifier()->m_miscvalue == 5634 )
4633 m_caster->CastSpell(m_caster, 38430, true, NULL, *citr);
4634 break;
4638 break;
4640 case SPELLFAMILY_DEATHKNIGHT:
4642 // Blood Strike, Heart Strike, Obliterate
4643 // Blood-Caked Strike, Scourge Strike
4644 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0002000001400000) ||
4645 m_spellInfo->SpellIconID == 1736 || m_spellInfo->SpellIconID == 3143)
4647 uint32 count = 0;
4648 Unit::AuraMap const& auras = unitTarget->GetAuras();
4649 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
4651 if(itr->second->GetSpellProto()->Dispel == DISPEL_DISEASE &&
4652 itr->second->GetCasterGUID() == m_caster->GetGUID() &&
4653 IsSpellLastAuraEffect(itr->second->GetSpellProto(), itr->second->GetEffIndex()))
4654 ++count;
4657 if (count)
4659 // Effect 1(for Blood-Caked Strike)/3(other) damage is bonus
4660 float bonus = count * CalculateDamage(m_spellInfo->SpellIconID == 1736 ? 0 : 2, unitTarget) / 100.0f;
4661 // Blood Strike, Blood-Caked Strike and Obliterate store bonus*2
4662 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0002000000400000) ||
4663 m_spellInfo->SpellIconID == 1736)
4664 bonus /= 2.0f;
4666 totalDamagePercentMod *= 1.0f + bonus;
4669 // Glyph of Blood Strike
4670 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000400000) &&
4671 m_caster->HasAura(59332) &&
4672 unitTarget->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED))
4674 totalDamagePercentMod *= 1.2f; // 120% if snared
4676 // Glyph of Death Strike
4677 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000010) &&
4678 m_caster->HasAura(59336))
4680 int32 rp = m_caster->GetPower(POWER_RUNIC_POWER) / 10;
4681 if(rp > 25)
4682 rp = 25;
4683 totalDamagePercentMod *= 1.0f + rp / 100.0f;
4685 // Glyph of Plague Strike
4686 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000001) &&
4687 m_caster->HasAura(58657) )
4689 totalDamagePercentMod *= 1.2f;
4691 break;
4695 int32 fixed_bonus = 0;
4696 for (int j = 0; j < 3; ++j)
4698 switch(m_spellInfo->Effect[j])
4700 case SPELL_EFFECT_WEAPON_DAMAGE:
4701 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
4702 fixed_bonus += CalculateDamage(j, unitTarget);
4703 break;
4704 case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
4705 fixed_bonus += CalculateDamage(j, unitTarget);
4706 normalized = true;
4707 break;
4708 case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
4709 weaponDamagePercentMod *= float(CalculateDamage(j, unitTarget)) / 100.0f;
4711 // applied only to prev.effects fixed damage
4712 fixed_bonus = int32(fixed_bonus*weaponDamagePercentMod);
4713 break;
4714 default:
4715 break; // not weapon damage effect, just skip
4719 // apply weaponDamagePercentMod to spell bonus also
4720 if(spellBonusNeedWeaponDamagePercentMod)
4721 spell_bonus = int32(spell_bonus*weaponDamagePercentMod);
4723 // non-weapon damage
4724 int32 bonus = spell_bonus + fixed_bonus;
4726 // apply to non-weapon bonus weapon total pct effect, weapon total flat effect included in weapon damage
4727 if(bonus)
4729 UnitMods unitMod;
4730 switch(m_attackType)
4732 default:
4733 case BASE_ATTACK: unitMod = UNIT_MOD_DAMAGE_MAINHAND; break;
4734 case OFF_ATTACK: unitMod = UNIT_MOD_DAMAGE_OFFHAND; break;
4735 case RANGED_ATTACK: unitMod = UNIT_MOD_DAMAGE_RANGED; break;
4738 float weapon_total_pct = m_caster->GetModifierValue(unitMod, TOTAL_PCT);
4739 bonus = int32(bonus*weapon_total_pct);
4742 // + weapon damage with applied weapon% dmg to base weapon damage in call
4743 bonus += int32(m_caster->CalculateDamage(m_attackType, normalized)*weaponDamagePercentMod);
4745 // total damage
4746 bonus = int32(bonus*totalDamagePercentMod);
4748 // prevent negative damage
4749 m_damage+= uint32(bonus > 0 ? bonus : 0);
4751 // Hemorrhage
4752 if (m_spellInfo->SpellFamilyName==SPELLFAMILY_ROGUE && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x2000000)))
4754 if(m_caster->GetTypeId()==TYPEID_PLAYER)
4755 ((Player*)m_caster)->AddComboPoints(unitTarget, 1);
4757 // Mangle (Cat): CP
4758 else if (m_spellInfo->SpellFamilyName==SPELLFAMILY_DRUID && (m_spellInfo->SpellFamilyFlags==UI64LIT(0x0000040000000000)))
4760 if(m_caster->GetTypeId()==TYPEID_PLAYER)
4761 ((Player*)m_caster)->AddComboPoints(unitTarget, 1);
4763 else if(m_spellInfo->SpellFamilyName==SPELLFAMILY_PALADIN)
4765 // Judgement of Blood/of the Martyr backlash damage (33%)
4766 if(m_spellInfo->SpellFamilyFlags & 0x0000000800000000LL && m_spellInfo->SpellIconID==153)
4768 int32 damagePoint = m_damage * 33 / 100;
4769 if(m_spellInfo->Id == 31898)
4770 m_caster->CastCustomSpell(m_caster, 32220, &damagePoint, NULL, NULL, true);
4771 else
4772 m_caster->CastCustomSpell(m_caster, 53725, &damagePoint, NULL, NULL, true);
4776 // take ammo
4777 if(m_attackType == RANGED_ATTACK && m_caster->GetTypeId() == TYPEID_PLAYER)
4779 Item *pItem = ((Player*)m_caster)->GetWeaponForAttack(RANGED_ATTACK, true, false);
4781 // wands don't have ammo
4782 if (!pItem || pItem->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_WAND)
4783 return;
4785 if (pItem->GetProto()->InventoryType == INVTYPE_THROWN)
4787 if(pItem->GetMaxStackCount()==1)
4789 // decrease durability for non-stackable throw weapon
4790 ((Player*)m_caster)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_RANGED);
4792 else
4794 // decrease items amount for stackable throw weapon
4795 uint32 count = 1;
4796 ((Player*)m_caster)->DestroyItemCount( pItem, count, true);
4799 else if(uint32 ammo = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID))
4800 ((Player*)m_caster)->DestroyItemCount(ammo, 1, true);
4804 void Spell::EffectThreat(uint32 /*i*/)
4806 if(!unitTarget || !unitTarget->isAlive() || !m_caster->isAlive())
4807 return;
4809 if(!unitTarget->CanHaveThreatList())
4810 return;
4812 unitTarget->AddThreat(m_caster, float(damage), false, GetSpellSchoolMask(m_spellInfo), m_spellInfo);
4815 void Spell::EffectHealMaxHealth(uint32 /*i*/)
4817 if(!unitTarget)
4818 return;
4819 if(!unitTarget->isAlive())
4820 return;
4822 uint32 heal = m_caster->GetMaxHealth();
4824 m_healing += heal;
4827 void Spell::EffectInterruptCast(uint32 /*i*/)
4829 if(!unitTarget)
4830 return;
4831 if(!unitTarget->isAlive())
4832 return;
4834 // TODO: not all spells that used this effect apply cooldown at school spells
4835 // also exist case: apply cooldown to interrupted cast only and to all spells
4836 for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
4838 if (Spell* spell = unitTarget->GetCurrentSpell(CurrentSpellTypes(i)))
4840 SpellEntry const* curSpellInfo = spell->m_spellInfo;
4841 // check if we can interrupt spell
4842 if ((curSpellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_INTERRUPT) && curSpellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE )
4844 unitTarget->ProhibitSpellScholl(GetSpellSchoolMask(curSpellInfo), GetSpellDuration(m_spellInfo));
4845 unitTarget->InterruptSpell(CurrentSpellTypes(i),false);
4851 void Spell::EffectSummonObjectWild(uint32 i)
4853 uint32 gameobject_id = m_spellInfo->EffectMiscValue[i];
4855 GameObject* pGameObj = new GameObject;
4857 WorldObject* target = focusObject;
4858 if( !target )
4859 target = m_caster;
4861 float x, y, z;
4862 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
4864 x = m_targets.m_destX;
4865 y = m_targets.m_destY;
4866 z = m_targets.m_destZ;
4868 else
4869 m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE);
4871 Map *map = target->GetMap();
4873 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id, map,
4874 m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
4876 delete pGameObj;
4877 return;
4880 int32 duration = GetSpellDuration(m_spellInfo);
4882 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
4883 pGameObj->SetSpellId(m_spellInfo->Id);
4885 // Wild object not have owner and check clickable by players
4886 map->Add(pGameObj);
4888 if(pGameObj->GetGoType() == GAMEOBJECT_TYPE_FLAGDROP && m_caster->GetTypeId() == TYPEID_PLAYER)
4890 Player *pl = (Player*)m_caster;
4891 BattleGround* bg = ((Player *)m_caster)->GetBattleGround();
4893 switch(pGameObj->GetMapId())
4895 case 489: //WS
4897 if(bg && bg->GetTypeID()==BATTLEGROUND_WS && bg->GetStatus() == STATUS_IN_PROGRESS)
4899 uint32 team = ALLIANCE;
4901 if(pl->GetTeam() == team)
4902 team = HORDE;
4904 ((BattleGroundWS*)bg)->SetDroppedFlagGUID(pGameObj->GetGUID(),team);
4906 break;
4908 case 566: //EY
4910 if(bg && bg->GetTypeID()==BATTLEGROUND_EY && bg->GetStatus() == STATUS_IN_PROGRESS)
4912 ((BattleGroundEY*)bg)->SetDroppedFlagGUID(pGameObj->GetGUID());
4914 break;
4919 if(uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry())
4921 GameObject* linkedGO = new GameObject;
4922 if(linkedGO->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, map,
4923 m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
4925 linkedGO->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
4926 linkedGO->SetSpellId(m_spellInfo->Id);
4928 // Wild object not have owner and check clickable by players
4929 map->Add(linkedGO);
4931 else
4933 delete linkedGO;
4934 linkedGO = NULL;
4935 return;
4940 void Spell::EffectScriptEffect(uint32 effIndex)
4942 // TODO: we must implement hunter pet summon at login there (spell 6962)
4944 switch(m_spellInfo->SpellFamilyName)
4946 case SPELLFAMILY_GENERIC:
4948 switch(m_spellInfo->Id)
4950 // Bending Shinbone
4951 case 8856:
4953 if(!itemTarget && m_caster->GetTypeId()!=TYPEID_PLAYER)
4954 return;
4956 uint32 spell_id = 0;
4957 switch(urand(1, 5))
4959 case 1: spell_id = 8854; break;
4960 default: spell_id = 8855; break;
4963 m_caster->CastSpell(m_caster,spell_id,true,NULL);
4964 return;
4966 // Piccolo of the Flaming Fire
4967 case 17512:
4969 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
4970 return;
4971 unitTarget->HandleEmoteCommand(EMOTE_STATE_DANCE);
4972 return;
4974 // Escape artist
4975 case 20589:
4977 if(!unitTarget)
4978 return;
4980 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
4981 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
4982 return;
4984 // Brittle Armor - need remove one 24575 Brittle Armor aura
4985 case 24590:
4986 unitTarget->RemoveSingleSpellAurasFromStack(24575);
4987 return;
4988 // PX-238 Winter Wondervolt TRAP
4989 case 26275:
4991 uint32 spells[4] = { 26272, 26157, 26273, 26274 };
4993 // check presence
4994 for(int j = 0; j < 4; ++j)
4995 if(unitTarget->HasAura(spells[j],0))
4996 return;
4998 // select spell
4999 uint32 iTmpSpellId = spells[urand(0,3)];
5001 // cast
5002 unitTarget->CastSpell(unitTarget, iTmpSpellId, true);
5003 return;
5005 // Mercurial Shield - need remove one 26464 Mercurial Shield aura
5006 case 26465:
5007 unitTarget->RemoveSingleSpellAurasFromStack(26464);
5008 return;
5009 // Orb teleport spells
5010 case 25140:
5011 case 25143:
5012 case 25650:
5013 case 25652:
5014 case 29128:
5015 case 29129:
5016 case 35376:
5017 case 35727:
5019 if(!unitTarget)
5020 return;
5022 uint32 spellid;
5023 switch(m_spellInfo->Id)
5025 case 25140: spellid = 32571; break;
5026 case 25143: spellid = 32572; break;
5027 case 25650: spellid = 30140; break;
5028 case 25652: spellid = 30141; break;
5029 case 29128: spellid = 32568; break;
5030 case 29129: spellid = 32569; break;
5031 case 35376: spellid = 25649; break;
5032 case 35727: spellid = 35730; break;
5033 default:
5034 return;
5037 unitTarget->CastSpell(unitTarget,spellid,false);
5038 return;
5040 // Shadow Flame (All script effects, not just end ones to prevent player from dodging the last triggered spell)
5041 case 22539:
5042 case 22972:
5043 case 22975:
5044 case 22976:
5045 case 22977:
5046 case 22978:
5047 case 22979:
5048 case 22980:
5049 case 22981:
5050 case 22982:
5051 case 22983:
5052 case 22984:
5053 case 22985:
5055 if(!unitTarget || !unitTarget->isAlive())
5056 return;
5058 // Onyxia Scale Cloak
5059 if(unitTarget->GetDummyAura(22683))
5060 return;
5062 // Shadow Flame
5063 m_caster->CastSpell(unitTarget, 22682, true);
5064 return;
5066 // Summon Black Qiraji Battle Tank
5067 case 26656:
5069 if(!unitTarget)
5070 return;
5072 // Prevent stacking of mounts
5073 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
5075 // Two separate mounts depending on area id (allows use both in and out of specific instance)
5076 if (unitTarget->GetAreaId() == 3428)
5077 unitTarget->CastSpell(unitTarget, 25863, false);
5078 else
5079 unitTarget->CastSpell(unitTarget, 26655, false);
5080 return;
5082 // Mirren's Drinking Hat
5083 case 29830:
5085 uint32 item = 0;
5086 switch ( urand(1, 6) )
5088 case 1:
5089 case 2:
5090 case 3:
5091 item = 23584; break; // Loch Modan Lager
5092 case 4:
5093 case 5:
5094 item = 23585; break; // Stouthammer Lite
5095 case 6:
5096 item = 23586; break; // Aerie Peak Pale Ale
5098 if (item)
5099 DoCreateItem(effIndex,item);
5100 break;
5102 // Improved Sprint
5103 case 30918:
5105 if(!unitTarget)
5106 return;
5107 // Removes snares and roots.
5108 unitTarget->RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK,30918,true);
5109 break;
5111 // Flame Crash
5112 case 41126:
5114 if(!unitTarget)
5115 return;
5117 unitTarget->CastSpell(unitTarget, 41131, true);
5118 break;
5120 // Force Cast - Portal Effect: Sunwell Isle
5121 case 44876:
5123 if(!unitTarget)
5124 return;
5126 unitTarget->CastSpell(unitTarget, 44870, true);
5127 break;
5129 // Goblin Weather Machine
5130 case 46203:
5132 if(!unitTarget)
5133 return;
5135 uint32 spellId = 0;
5136 switch(rand() % 4)
5138 case 0: spellId = 46740; break;
5139 case 1: spellId = 46739; break;
5140 case 2: spellId = 46738; break;
5141 case 3: spellId = 46736; break;
5143 unitTarget->CastSpell(unitTarget, spellId, true);
5144 break;
5146 //5,000 Gold
5147 case 46642:
5149 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5150 return;
5152 ((Player*)unitTarget)->ModifyMoney(50000000);
5154 break;
5156 // Surge Needle Teleporter
5157 case 47097:
5159 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5160 return;
5162 if (unitTarget->GetAreaId() == 4156)
5163 unitTarget->CastSpell(unitTarget, 47324, true);
5164 else if (unitTarget->GetAreaId() == 4157)
5165 unitTarget->CastSpell(unitTarget, 47325, true);
5167 break;
5169 // High Executor's Branding Iron
5170 case 48603:
5171 // Torture the Torturer: High Executor's Branding Iron Impact
5172 unitTarget->CastSpell(unitTarget, 48614, true);
5173 return;
5174 // Emblazon Runeblade
5175 case 51770:
5177 if(!m_originalCaster)
5178 return;
5180 m_originalCaster->CastSpell(m_originalCaster, damage, false);
5181 break;
5183 // Death Gate
5184 case 52751:
5186 if(!unitTarget || unitTarget->getClass() != CLASS_DEATH_KNIGHT)
5187 return;
5188 // triggered spell is stored in m_spellInfo->EffectBasePoints[0]
5189 unitTarget->CastSpell(unitTarget, damage, false);
5190 break;
5192 // Winged Steed of the Ebon Blade
5193 case 54729:
5195 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5196 return;
5198 // Prevent stacking of mounts
5199 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
5201 // Triggered spell id dependent of riding skill
5202 if(uint16 skillval = ((Player*)unitTarget)->GetSkillValue(SKILL_RIDING))
5204 if (skillval >= 300)
5205 unitTarget->CastSpell(unitTarget, 54727, true);
5206 else
5207 unitTarget->CastSpell(unitTarget, 54726, true);
5209 return;
5211 // Demonic Empowerment (succubus Vanish effect)
5212 case 54436:
5214 if(!unitTarget)
5215 return;
5217 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
5218 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
5219 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STALKED);
5220 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STUN);
5221 return;
5223 case 55693: // Remove Collapsing Cave Aura
5224 if(!unitTarget)
5225 return;
5226 unitTarget->RemoveAurasDueToSpell(m_spellInfo->CalculateSimpleValue(effIndex));
5227 break;
5228 case 58418: // Portal to Orgrimmar
5229 case 58420: // Portal to Stormwind
5231 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER || effIndex!=0)
5232 return;
5234 uint32 spellID = m_spellInfo->CalculateSimpleValue(0);
5235 uint32 questID = m_spellInfo->CalculateSimpleValue(1);
5237 if (((Player*)unitTarget)->GetQuestStatus(questID) == QUEST_STATUS_COMPLETE && !((Player*)unitTarget)->GetQuestRewardStatus (questID))
5238 unitTarget->CastSpell(unitTarget, spellID, true);
5240 return;
5242 case 59317: // Teleporting
5243 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5244 return;
5246 // return from top
5247 if (((Player*)unitTarget)->GetAreaId() == 4637)
5248 unitTarget->CastSpell(unitTarget, 59316, true);
5249 // teleport atop
5250 else
5251 unitTarget->CastSpell(unitTarget, 59314, true);
5253 return;
5254 // random spell learn instead placeholder
5255 case 60893: // Northrend Alchemy Research
5256 case 61177: // Northrend Inscription Research
5257 case 61288: // Minor Inscription Research
5258 case 61756: // Northrend Inscription Research (FAST QA VERSION)
5259 case 64323: // Book of Glyph Mastery
5261 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5262 return;
5264 // learn random explicit discovery recipe (if any)
5265 if(uint32 discoveredSpell = GetExplicitDiscoverySpell(m_spellInfo->Id, (Player*)m_caster))
5266 ((Player*)m_caster)->learnSpell(discoveredSpell, false);
5267 return;
5270 break;
5272 case SPELLFAMILY_WARLOCK:
5274 switch(m_spellInfo->Id)
5276 // Healthstone creating spells
5277 case 6201:
5278 case 6202:
5279 case 5699:
5280 case 11729:
5281 case 11730:
5282 case 27230:
5283 case 47871:
5284 case 47878:
5286 if(!unitTarget)
5287 return;
5288 uint32 itemtype;
5289 uint32 rank = 0;
5290 Unit::AuraList const& mDummyAuras = unitTarget->GetAurasByType(SPELL_AURA_DUMMY);
5291 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
5293 if((*i)->GetId() == 18692)
5295 rank = 1;
5296 break;
5298 else if((*i)->GetId() == 18693)
5300 rank = 2;
5301 break;
5305 static uint32 const itypes[8][3] = {
5306 { 5512, 19004, 19005}, // Minor Healthstone
5307 { 5511, 19006, 19007}, // Lesser Healthstone
5308 { 5509, 19008, 19009}, // Healthstone
5309 { 5510, 19010, 19011}, // Greater Healthstone
5310 { 9421, 19012, 19013}, // Major Healthstone
5311 {22103, 22104, 22105}, // Master Healthstone
5312 {36889, 36890, 36891}, // Demonic Healthstone
5313 {36892, 36893, 36894} // Fel Healthstone
5316 switch(m_spellInfo->Id)
5318 case 6201:
5319 itemtype=itypes[0][rank];break; // Minor Healthstone
5320 case 6202:
5321 itemtype=itypes[1][rank];break; // Lesser Healthstone
5322 case 5699:
5323 itemtype=itypes[2][rank];break; // Healthstone
5324 case 11729:
5325 itemtype=itypes[3][rank];break; // Greater Healthstone
5326 case 11730:
5327 itemtype=itypes[4][rank];break; // Major Healthstone
5328 case 27230:
5329 itemtype=itypes[5][rank];break; // Master Healthstone
5330 case 47871:
5331 itemtype=itypes[6][rank];break; // Demonic Healthstone
5332 case 47878:
5333 itemtype=itypes[7][rank];break; // Fel Healthstone
5334 default:
5335 return;
5337 DoCreateItem( effIndex, itemtype );
5338 return;
5340 // Demonic Empowerment
5341 case 47193:
5343 if(!unitTarget)
5344 return;
5345 uint32 entry = unitTarget->GetEntry();
5346 uint32 spellID;
5347 switch(entry)
5349 case 416: spellID = 54444; break; //imp
5350 case 417: spellID = 54509; break; //fellhunter
5351 case 1860: spellID = 54443; break; //void
5352 case 1863: spellID = 54435; break; //succubus
5353 case 17252: spellID = 54508; break; //fellguard
5354 default:
5355 return;
5357 unitTarget->CastSpell(unitTarget,spellID,true);
5358 return;
5360 // Everlasting Affliction
5361 case 47422:
5363 // Need refresh caster corruption auras on target
5364 Unit::AuraMap& suAuras = unitTarget->GetAuras();
5365 for(Unit::AuraMap::iterator itr = suAuras.begin(); itr != suAuras.end(); ++itr)
5367 SpellEntry const *spellInfo = (*itr).second->GetSpellProto();
5368 if(spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK &&
5369 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000002)) &&
5370 (*itr).second->GetCasterGUID()==m_caster->GetGUID())
5371 (*itr).second->RefreshAura();
5373 return;
5375 // Guarded by The Light (Paladin spell with SPELLFAMILY_WARLOCK)
5376 case 63521:
5378 // Divine Plea, refresh on target (3 aura slots)
5379 if (Aura* aura = unitTarget->GetAura(54428,0))
5380 aura->RefreshAura();
5381 return;
5384 break;
5386 case SPELLFAMILY_PRIEST:
5388 switch(m_spellInfo->Id)
5390 // Pain and Suffering
5391 case 47948:
5393 if (!unitTarget)
5394 return;
5395 // Refresh Shadow Word: Pain on target
5396 Unit::AuraMap& auras = unitTarget->GetAuras();
5397 for(Unit::AuraMap::iterator itr = auras.begin(); itr != auras.end(); ++itr)
5399 SpellEntry const *spellInfo = (*itr).second->GetSpellProto();
5400 if (spellInfo->SpellFamilyName == SPELLFAMILY_PRIEST &&
5401 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000008000)) &&
5402 (*itr).second->GetCasterGUID() == m_caster->GetGUID())
5404 (*itr).second->RefreshAura();
5405 return;
5408 return;
5410 default:
5411 break;
5413 break;
5415 case SPELLFAMILY_HUNTER:
5417 switch(m_spellInfo->Id)
5419 // Chimera Shot
5420 case 53209:
5422 if(!unitTarget)
5423 return;
5424 uint32 spellId = 0;
5425 int32 basePoint = 0;
5426 Unit* target = unitTarget;
5427 Unit::AuraMap& Auras = unitTarget->GetAuras();
5428 for(Unit::AuraMap::iterator i = Auras.begin(); i != Auras.end(); ++i)
5430 Aura *aura = (*i).second;
5431 if (aura->GetCasterGUID() != m_caster->GetGUID())
5432 continue;
5433 // Search only Serpent Sting, Viper Sting, Scorpid Sting auras
5434 uint64 familyFlag = aura->GetSpellProto()->SpellFamilyFlags;
5435 if (!(familyFlag & UI64LIT(0x000000800000C000)))
5436 continue;
5437 // Refresh aura duration
5438 aura->RefreshAura();
5440 // Serpent Sting - Instantly deals 40% of the damage done by your Serpent Sting.
5441 if ((familyFlag & UI64LIT(0x0000000000004000)) && aura->GetEffIndex() == 0)
5443 // m_amount already include RAP bonus
5444 basePoint = aura->GetModifier()->m_amount * 5 * 40 / 100;
5445 spellId = 53353; // Chimera Shot - Serpent
5447 // Viper Sting - Instantly restores mana to you equal to 60% of the total amount drained by your Viper Sting.
5448 if ((familyFlag & UI64LIT(0x0000008000000000)) && aura->GetEffIndex() == 0)
5450 uint32 target_max_mana = unitTarget->GetMaxPower(POWER_MANA);
5451 if (!target_max_mana)
5452 continue;
5454 // ignore non positive values (can be result apply spellmods to aura damage
5455 uint32 pdamage = aura->GetModifier()->m_amount > 0 ? aura->GetModifier()->m_amount : 0;
5457 // Special case: draining x% of mana (up to a maximum of 2*x% of the caster's maximum mana)
5458 uint32 maxmana = m_caster->GetMaxPower(POWER_MANA) * pdamage * 2 / 100;
5460 pdamage = target_max_mana * pdamage / 100;
5461 if (pdamage > maxmana)
5462 pdamage = maxmana;
5464 pdamage *= 4; // total aura damage
5465 basePoint = pdamage * 60 / 100;
5466 spellId = 53358; // Chimera Shot - Viper
5467 target = m_caster;
5469 // Scorpid Sting - Attempts to Disarm the target for 10 sec. This effect cannot occur more than once per 1 minute.
5470 if (familyFlag & UI64LIT(0x0000000000008000))
5471 spellId = 53359; // Chimera Shot - Scorpid
5472 // ?? nothing say in spell desc (possibly need addition check)
5473 //if ((familyFlag & UI64LIT(0x0000010000000000)) || // dot
5474 // (familyFlag & UI64LIT(0x0000100000000000))) // stun
5476 // spellId = 53366; // 53366 Chimera Shot - Wyvern
5479 if (spellId)
5480 m_caster->CastCustomSpell(target, spellId, &basePoint, 0, 0, false);
5481 return;
5483 case 53412: // Invigoration (pet triggered script, master targeted)
5485 if (!unitTarget)
5486 return;
5488 Unit::AuraList const& auras = unitTarget->GetAurasByType(SPELL_AURA_DUMMY);
5489 for(Unit::AuraList::const_iterator i = auras.begin();i != auras.end(); ++i)
5491 // Invigoration (master talent)
5492 if ((*i)->GetModifier()->m_miscvalue == 8 && (*i)->GetSpellProto()->SpellIconID == 3487)
5494 if (roll_chance_i((*i)->GetModifier()->m_amount))
5496 unitTarget->CastSpell(unitTarget, 53398, true, NULL, (*i), m_caster->GetGUID());
5497 break;
5501 return;
5503 // Master's Call
5504 case 53271:
5506 if (!unitTarget)
5507 return;
5509 // script effect have in value, but this outdated removed part
5510 unitTarget->CastSpell(unitTarget, 62305, true);
5511 return;
5513 default:
5514 break;
5516 break;
5518 case SPELLFAMILY_PALADIN:
5520 // Judgement (seal trigger)
5521 if (m_spellInfo->Category == SPELLCATEGORY_JUDGEMENT)
5523 if(!unitTarget || !unitTarget->isAlive())
5524 return;
5525 uint32 spellId1 = 0;
5526 uint32 spellId2 = 0;
5528 // Judgement self add switch
5529 switch (m_spellInfo->Id)
5531 case 53407: spellId1 = 20184; break; // Judgement of Justice
5532 case 20271: // Judgement of Light
5533 case 57774: spellId1 = 20185; break; // Judgement of Light
5534 case 53408: spellId1 = 20186; break; // Judgement of Wisdom
5535 default:
5536 sLog.outError("Unsupported Judgement (seal trigger) spell (Id: %u) in Spell::EffectScriptEffect",m_spellInfo->Id);
5537 return;
5539 // offensive seals have aura dummy in 2 effect
5540 Unit::AuraList const& m_dummyAuras = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
5541 for(Unit::AuraList::const_iterator itr = m_dummyAuras.begin(); itr != m_dummyAuras.end(); ++itr)
5543 // search seal (offensive seals have judgement's aura dummy spell id in 2 effect
5544 if ((*itr)->GetEffIndex() != 2 || !IsSealSpell((*itr)->GetSpellProto()))
5545 continue;
5546 spellId2 = (*itr)->GetModifier()->m_amount;
5547 SpellEntry const *judge = sSpellStore.LookupEntry(spellId2);
5548 if (!judge)
5549 continue;
5550 break;
5552 // if there were no offensive seals than there is seal with proc trigger aura
5553 if (!spellId2)
5555 Unit::AuraList const& procTriggerAuras = m_caster->GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL);
5556 for(Unit::AuraList::const_iterator itr = procTriggerAuras.begin(); itr != procTriggerAuras.end(); ++itr)
5558 if ((*itr)->GetEffIndex() != 0 || !IsSealSpell((*itr)->GetSpellProto()))
5559 continue;
5560 spellId2 = 54158;
5561 break;
5564 if (spellId1)
5565 m_caster->CastSpell(unitTarget, spellId1, true);
5566 if (spellId2)
5567 m_caster->CastSpell(unitTarget, spellId2, true);
5568 return;
5571 case SPELLFAMILY_POTION:
5573 switch(m_spellInfo->Id)
5575 // Dreaming Glory
5576 case 28698:
5578 if(!unitTarget)
5579 return;
5580 unitTarget->CastSpell(unitTarget, 28694, true);
5581 break;
5583 // Netherbloom
5584 case 28702:
5586 if(!unitTarget)
5587 return;
5588 // 25% chance of casting a random buff
5589 if(roll_chance_i(75))
5590 return;
5592 // triggered spells are 28703 to 28707
5593 // Note: some sources say, that there was the possibility of
5594 // receiving a debuff. However, this seems to be removed by a patch.
5595 const uint32 spellid = 28703;
5597 // don't overwrite an existing aura
5598 for(uint8 i = 0; i < 5; ++i)
5599 if(unitTarget->HasAura(spellid + i, 0))
5600 return;
5601 unitTarget->CastSpell(unitTarget, spellid+urand(0, 4), true);
5602 break;
5605 // Nightmare Vine
5606 case 28720:
5608 if(!unitTarget)
5609 return;
5610 // 25% chance of casting Nightmare Pollen
5611 if(roll_chance_i(75))
5612 return;
5613 unitTarget->CastSpell(unitTarget, 28721, true);
5614 break;
5617 break;
5619 case SPELLFAMILY_DEATHKNIGHT:
5621 switch(m_spellInfo->Id)
5623 // Pestilence
5624 case 50842:
5626 if(!unitTarget)
5627 return;
5629 Unit* mainTarget = m_targets.getUnitTarget();
5630 if(!mainTarget)
5631 return;
5633 // do only refresh diseases on main target if caster has Glyph of Disease
5634 if(mainTarget == unitTarget && !m_caster->HasAura(63334))
5635 return;
5637 // Blood Plague
5638 if(mainTarget->HasAura(55078))
5639 m_caster->CastSpell(unitTarget, 55078, true);
5641 // Frost Fever
5642 if(mainTarget->HasAura(55095))
5643 m_caster->CastSpell(unitTarget, 55095, true);
5645 break;
5648 break;
5652 // normal DB scripted effect
5653 if(!unitTarget)
5654 return;
5656 sLog.outDebug("Spell ScriptStart spellid %u in EffectScriptEffect ", m_spellInfo->Id);
5657 m_caster->GetMap()->ScriptsStart(sSpellScripts, m_spellInfo->Id, m_caster, unitTarget);
5660 void Spell::EffectSanctuary(uint32 /*i*/)
5662 if(!unitTarget)
5663 return;
5664 //unitTarget->CombatStop();
5666 unitTarget->CombatStop();
5667 unitTarget->getHostileRefManager().deleteReferences(); // stop all fighting
5668 // Vanish allows to remove all threat and cast regular stealth so other spells can be used
5669 if(m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && (m_spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE_VANISH))
5671 ((Player *)m_caster)->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
5675 void Spell::EffectAddComboPoints(uint32 /*i*/)
5677 if(!unitTarget)
5678 return;
5680 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5681 return;
5683 if(damage <= 0)
5684 return;
5686 ((Player*)m_caster)->AddComboPoints(unitTarget, damage);
5689 void Spell::EffectDuel(uint32 i)
5691 if(!m_caster || !unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER || unitTarget->GetTypeId() != TYPEID_PLAYER)
5692 return;
5694 Player *caster = (Player*)m_caster;
5695 Player *target = (Player*)unitTarget;
5697 // caster or target already have requested duel
5698 if( caster->duel || target->duel || !target->GetSocial() || target->GetSocial()->HasIgnore(caster->GetGUIDLow()) )
5699 return;
5701 // Players can only fight a duel with each other outside (=not inside dungeons and not in capital cities)
5702 // Don't have to check the target's map since you cannot challenge someone across maps
5703 uint32 mapid = caster->GetMapId();
5704 if( mapid != 0 && mapid != 1 && mapid != 530 && mapid != 571 && mapid != 609)
5706 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5707 return;
5710 AreaTableEntry const* casterAreaEntry = GetAreaEntryByAreaID(caster->GetZoneId());
5711 if(casterAreaEntry && (casterAreaEntry->flags & AREA_FLAG_CAPITAL) )
5713 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5714 return;
5717 AreaTableEntry const* targetAreaEntry = GetAreaEntryByAreaID(target->GetZoneId());
5718 if(targetAreaEntry && (targetAreaEntry->flags & AREA_FLAG_CAPITAL) )
5720 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5721 return;
5724 //CREATE DUEL FLAG OBJECT
5725 GameObject* pGameObj = new GameObject;
5727 uint32 gameobject_id = m_spellInfo->EffectMiscValue[i];
5729 Map *map = m_caster->GetMap();
5730 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id,
5731 map, m_caster->GetPhaseMask(),
5732 m_caster->GetPositionX()+(unitTarget->GetPositionX()-m_caster->GetPositionX())/2 ,
5733 m_caster->GetPositionY()+(unitTarget->GetPositionY()-m_caster->GetPositionY())/2 ,
5734 m_caster->GetPositionZ(),
5735 m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
5737 delete pGameObj;
5738 return;
5741 pGameObj->SetUInt32Value(GAMEOBJECT_FACTION, m_caster->getFaction() );
5742 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()+1 );
5743 int32 duration = GetSpellDuration(m_spellInfo);
5744 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
5745 pGameObj->SetSpellId(m_spellInfo->Id);
5747 m_caster->AddGameObject(pGameObj);
5748 map->Add(pGameObj);
5749 //END
5751 // Send request
5752 WorldPacket data(SMSG_DUEL_REQUESTED, 8 + 8);
5753 data << uint64(pGameObj->GetGUID());
5754 data << uint64(caster->GetGUID());
5755 caster->GetSession()->SendPacket(&data);
5756 target->GetSession()->SendPacket(&data);
5758 // create duel-info
5759 DuelInfo *duel = new DuelInfo;
5760 duel->initiator = caster;
5761 duel->opponent = target;
5762 duel->startTime = 0;
5763 duel->startTimer = 0;
5764 caster->duel = duel;
5766 DuelInfo *duel2 = new DuelInfo;
5767 duel2->initiator = caster;
5768 duel2->opponent = caster;
5769 duel2->startTime = 0;
5770 duel2->startTimer = 0;
5771 target->duel = duel2;
5773 caster->SetUInt64Value(PLAYER_DUEL_ARBITER, pGameObj->GetGUID());
5774 target->SetUInt64Value(PLAYER_DUEL_ARBITER, pGameObj->GetGUID());
5777 void Spell::EffectStuck(uint32 /*i*/)
5779 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5780 return;
5782 if(!sWorld.getConfig(CONFIG_CAST_UNSTUCK))
5783 return;
5785 Player* pTarget = (Player*)unitTarget;
5787 sLog.outDebug("Spell Effect: Stuck");
5788 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());
5790 if(pTarget->isInFlight())
5791 return;
5793 // homebind location is loaded always
5794 pTarget->TeleportToHomebind(unitTarget==m_caster ? TELE_TO_SPELL : 0);
5796 // Stuck spell trigger Hearthstone cooldown
5797 SpellEntry const *spellInfo = sSpellStore.LookupEntry(8690);
5798 if(!spellInfo)
5799 return;
5800 Spell spell(pTarget, spellInfo, true, 0);
5801 spell.SendSpellCooldown();
5804 void Spell::EffectSummonPlayer(uint32 /*i*/)
5806 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5807 return;
5809 // Evil Twin (ignore player summon, but hide this for summoner)
5810 if(unitTarget->GetDummyAura(23445))
5811 return;
5813 float x, y, z;
5814 m_caster->GetClosePoint(x, y, z, unitTarget->GetObjectSize());
5816 ((Player*)unitTarget)->SetSummonPoint(m_caster->GetMapId(),x,y,z);
5818 WorldPacket data(SMSG_SUMMON_REQUEST, 8+4+4);
5819 data << uint64(m_caster->GetGUID()); // summoner guid
5820 data << uint32(m_caster->GetZoneId()); // summoner zone
5821 data << uint32(MAX_PLAYER_SUMMON_DELAY*IN_MILISECONDS); // auto decline after msecs
5822 ((Player*)unitTarget)->GetSession()->SendPacket(&data);
5825 static ScriptInfo generateActivateCommand()
5827 ScriptInfo si;
5828 si.command = SCRIPT_COMMAND_ACTIVATE_OBJECT;
5829 return si;
5832 void Spell::EffectActivateObject(uint32 effect_idx)
5834 if(!gameObjTarget)
5835 return;
5837 static ScriptInfo activateCommand = generateActivateCommand();
5839 int32 delay_secs = m_spellInfo->EffectMiscValue[effect_idx];
5841 gameObjTarget->GetMap()->ScriptCommandStart(activateCommand, delay_secs, m_caster, gameObjTarget);
5844 void Spell::EffectApplyGlyph(uint32 i)
5846 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5847 return;
5849 Player *player = (Player*)m_caster;
5851 // apply new one
5852 if(uint32 glyph = m_spellInfo->EffectMiscValue[i])
5854 if(GlyphPropertiesEntry const *gp = sGlyphPropertiesStore.LookupEntry(glyph))
5856 if(GlyphSlotEntry const *gs = sGlyphSlotStore.LookupEntry(player->GetGlyphSlot(m_glyphIndex)))
5858 if(gp->TypeFlags != gs->TypeFlags)
5860 SendCastResult(SPELL_FAILED_INVALID_GLYPH);
5861 return; // glyph slot mismatch
5865 // remove old glyph
5866 if(uint32 oldglyph = player->GetGlyph(m_glyphIndex))
5868 if(GlyphPropertiesEntry const *old_gp = sGlyphPropertiesStore.LookupEntry(oldglyph))
5870 player->RemoveAurasDueToSpell(old_gp->SpellId);
5871 player->SetGlyph(m_glyphIndex, 0);
5875 player->CastSpell(m_caster, gp->SpellId, true);
5876 player->SetGlyph(m_glyphIndex, glyph);
5877 player->SendTalentsInfoData(false);
5882 void Spell::EffectSummonTotem(uint32 i, uint8 slot)
5884 slot = slot ? (slot - 1): 255;
5886 if(slot < MAX_TOTEM)
5888 uint64 guid = m_caster->m_TotemSlot[slot];
5889 if(guid != 0)
5891 Creature *OldTotem = m_caster->GetMap()->GetCreature(guid);
5892 if(OldTotem && OldTotem->isTotem())
5893 ((Totem*)OldTotem)->UnSummon();
5897 uint32 team = 0;
5898 if (m_caster->GetTypeId()==TYPEID_PLAYER)
5899 team = ((Player*)m_caster)->GetTeam();
5901 Totem* pTotem = new Totem;
5903 if(!pTotem->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), m_caster->GetMap(), m_caster->GetPhaseMask(),
5904 m_spellInfo->EffectMiscValue[i], team ))
5906 delete pTotem;
5907 return;
5910 float angle = slot < MAX_TOTEM ? M_PI/MAX_TOTEM - (slot*2*M_PI/MAX_TOTEM) : 0;
5912 float x, y, z;
5913 m_caster->GetClosePoint(x, y, z, pTotem->GetObjectSize(), 2.0f, angle);
5915 // totem must be at same Z in case swimming caster and etc.
5916 if( fabs( z - m_caster->GetPositionZ() ) > 5 )
5917 z = m_caster->GetPositionZ();
5919 pTotem->Relocate(x, y, z, m_caster->GetOrientation());
5921 if(slot < MAX_TOTEM)
5922 m_caster->m_TotemSlot[slot] = pTotem->GetGUID();
5924 pTotem->SetOwner(m_caster->GetGUID());
5925 pTotem->SetTypeBySummonSpell(m_spellInfo); // must be after Create call where m_spells initilized
5927 int32 duration=GetSpellDuration(m_spellInfo);
5928 if(Player* modOwner = m_caster->GetSpellModOwner())
5929 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
5930 pTotem->SetDuration(duration);
5932 if (damage) // if not spell info, DB values used
5934 pTotem->SetMaxHealth(damage);
5935 pTotem->SetHealth(damage);
5938 pTotem->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
5940 if(m_caster->GetTypeId() == TYPEID_PLAYER)
5941 pTotem->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
5943 if(m_caster->IsPvP())
5944 pTotem->SetPvP(true);
5946 pTotem->Summon(m_caster);
5948 if(slot < MAX_TOTEM && m_caster->GetTypeId() == TYPEID_PLAYER)
5950 WorldPacket data(SMSG_TOTEM_CREATED, 1 + 8 + 4 + 4);
5951 data << uint8(slot);
5952 data << uint64(pTotem->GetGUID());
5953 data << uint32(duration);
5954 data << uint32(m_spellInfo->Id);
5955 ((Player*)m_caster)->SendDirectMessage(&data);
5959 void Spell::EffectEnchantHeldItem(uint32 i)
5961 // this is only item spell effect applied to main-hand weapon of target player (players in area)
5962 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5963 return;
5965 Player* item_owner = (Player*)unitTarget;
5966 Item* item = item_owner->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
5968 if(!item )
5969 return;
5971 // must be equipped
5972 if(!item ->IsEquipped())
5973 return;
5975 if (m_spellInfo->EffectMiscValue[i])
5977 uint32 enchant_id = m_spellInfo->EffectMiscValue[i];
5978 int32 duration = GetSpellDuration(m_spellInfo); //Try duration index first ..
5979 if(!duration)
5980 duration = m_currentBasePoints[i]+1; //Base points after ..
5981 if(!duration)
5982 duration = 10; //10 seconds for enchants which don't have listed duration
5984 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
5985 if(!pEnchant)
5986 return;
5988 // Always go to temp enchantment slot
5989 EnchantmentSlot slot = TEMP_ENCHANTMENT_SLOT;
5991 // Enchantment will not be applied if a different one already exists
5992 if(item->GetEnchantmentId(slot) && item->GetEnchantmentId(slot) != enchant_id)
5993 return;
5995 // Apply the temporary enchantment
5996 item->SetEnchantment(slot, enchant_id, duration*IN_MILISECONDS, 0);
5997 item_owner->ApplyEnchantment(item, slot, true);
6001 void Spell::EffectDisEnchant(uint32 /*i*/)
6003 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6004 return;
6006 Player* p_caster = (Player*)m_caster;
6007 if(!itemTarget || !itemTarget->GetProto()->DisenchantID)
6008 return;
6010 p_caster->UpdateCraftSkill(m_spellInfo->Id);
6012 ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(),LOOT_DISENCHANTING);
6014 // item will be removed at disenchanting end
6017 void Spell::EffectInebriate(uint32 /*i*/)
6019 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6020 return;
6022 Player *player = (Player*)unitTarget;
6023 uint16 currentDrunk = player->GetDrunkValue();
6024 uint16 drunkMod = damage * 256;
6025 if (currentDrunk + drunkMod > 0xFFFF)
6026 currentDrunk = 0xFFFF;
6027 else
6028 currentDrunk += drunkMod;
6029 player->SetDrunkValue(currentDrunk, m_CastItem ? m_CastItem->GetEntry() : 0);
6032 void Spell::EffectFeedPet(uint32 i)
6034 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6035 return;
6037 Player *_player = (Player*)m_caster;
6039 Item* foodItem = m_targets.getItemTarget();
6040 if(!foodItem)
6041 return;
6043 Pet *pet = _player->GetPet();
6044 if(!pet)
6045 return;
6047 if(!pet->isAlive())
6048 return;
6050 int32 benefit = pet->GetCurrentFoodBenefitLevel(foodItem->GetProto()->ItemLevel);
6051 if(benefit <= 0)
6052 return;
6054 uint32 count = 1;
6055 _player->DestroyItemCount(foodItem,count,true);
6056 // TODO: fix crash when a spell has two effects, both pointed at the same item target
6058 m_caster->CastCustomSpell(pet, m_spellInfo->EffectTriggerSpell[i], &benefit, NULL, NULL, true);
6061 void Spell::EffectDismissPet(uint32 /*i*/)
6063 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6064 return;
6066 Pet* pet = m_caster->GetPet();
6068 // not let dismiss dead pet
6069 if(!pet||!pet->isAlive())
6070 return;
6072 ((Player*)m_caster)->RemovePet(pet, PET_SAVE_NOT_IN_SLOT);
6075 void Spell::EffectSummonObject(uint32 i)
6077 uint32 go_id = m_spellInfo->EffectMiscValue[i];
6079 uint8 slot = 0;
6080 switch(m_spellInfo->Effect[i])
6082 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1: slot = 0; break;
6083 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2: slot = 1; break;
6084 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3: slot = 2; break;
6085 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4: slot = 3; break;
6086 default: return;
6089 if(uint64 guid = m_caster->m_ObjectSlot[slot])
6091 if(GameObject* obj = m_caster ? m_caster->GetMap()->GetGameObject(guid) : NULL)
6092 obj->SetLootState(GO_JUST_DEACTIVATED);
6093 m_caster->m_ObjectSlot[slot] = 0;
6096 GameObject* pGameObj = new GameObject;
6098 float x, y, z;
6099 // If dest location if present
6100 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6102 x = m_targets.m_destX;
6103 y = m_targets.m_destY;
6104 z = m_targets.m_destZ;
6106 // Summon in random point all other units if location present
6107 else
6108 m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE);
6110 Map *map = m_caster->GetMap();
6111 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), go_id, map,
6112 m_caster->GetPhaseMask(), x, y, z, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
6114 delete pGameObj;
6115 return;
6118 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL,m_caster->getLevel());
6119 int32 duration = GetSpellDuration(m_spellInfo);
6120 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
6121 pGameObj->SetSpellId(m_spellInfo->Id);
6122 m_caster->AddGameObject(pGameObj);
6124 map->Add(pGameObj);
6126 m_caster->m_ObjectSlot[slot] = pGameObj->GetGUID();
6129 void Spell::EffectResurrect(uint32 /*effIndex*/)
6131 if(!unitTarget)
6132 return;
6133 if(unitTarget->GetTypeId() != TYPEID_PLAYER)
6134 return;
6136 if(unitTarget->isAlive())
6137 return;
6138 if(!unitTarget->IsInWorld())
6139 return;
6141 switch (m_spellInfo->Id)
6143 // Defibrillate (Goblin Jumper Cables) have 33% chance on success
6144 case 8342:
6145 if (roll_chance_i(67))
6147 m_caster->CastSpell(m_caster, 8338, true, m_CastItem);
6148 return;
6150 break;
6151 // Defibrillate (Goblin Jumper Cables XL) have 50% chance on success
6152 case 22999:
6153 if (roll_chance_i(50))
6155 m_caster->CastSpell(m_caster, 23055, true, m_CastItem);
6156 return;
6158 break;
6159 default:
6160 break;
6163 Player* pTarget = ((Player*)unitTarget);
6165 if(pTarget->isRessurectRequested()) // already have one active request
6166 return;
6168 uint32 health = pTarget->GetMaxHealth() * damage / 100;
6169 uint32 mana = pTarget->GetMaxPower(POWER_MANA) * damage / 100;
6171 pTarget->setResurrectRequestData(m_caster->GetGUID(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), health, mana);
6172 SendResurrectRequest(pTarget);
6175 void Spell::EffectAddExtraAttacks(uint32 /*i*/)
6177 if(!unitTarget || !unitTarget->isAlive())
6178 return;
6180 if( unitTarget->m_extraAttacks )
6181 return;
6183 unitTarget->m_extraAttacks = damage;
6186 void Spell::EffectParry(uint32 /*i*/)
6188 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6189 ((Player*)unitTarget)->SetCanParry(true);
6192 void Spell::EffectBlock(uint32 /*i*/)
6194 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6195 ((Player*)unitTarget)->SetCanBlock(true);
6198 void Spell::EffectLeapForward(uint32 i)
6200 if(unitTarget->isInFlight())
6201 return;
6203 if( m_spellInfo->rangeIndex == 1) //self range
6205 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
6207 // before caster
6208 float fx, fy, fz;
6209 unitTarget->GetClosePoint(fx, fy, fz, unitTarget->GetObjectSize(), dis);
6210 float ox, oy, oz;
6211 unitTarget->GetPosition(ox, oy, oz);
6213 float fx2, fy2, fz2; // getObjectHitPos overwrite last args in any result case
6214 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(unitTarget->GetMapId(), ox,oy,oz+0.5, fx,fy,oz+0.5,fx2,fy2,fz2, -0.5))
6216 fx = fx2;
6217 fy = fy2;
6218 fz = fz2;
6219 unitTarget->UpdateGroundPositionZ(fx, fy, fz);
6222 unitTarget->NearTeleportTo(fx, fy, fz, unitTarget->GetOrientation(), unitTarget == m_caster);
6226 void Spell::EffectLeapBack(uint32 i)
6228 if(unitTarget->isInFlight())
6229 return;
6231 m_caster->KnockBackFrom(unitTarget,float(m_spellInfo->EffectMiscValue[i])/10,float(damage)/10);
6234 void Spell::EffectReputation(uint32 i)
6236 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6237 return;
6239 Player *_player = (Player*)unitTarget;
6241 int32 rep_change = m_currentBasePoints[i]+1; // field store reputation change -1
6243 uint32 faction_id = m_spellInfo->EffectMiscValue[i];
6245 FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id);
6247 if(!factionEntry)
6248 return;
6250 _player->GetReputationMgr().ModifyReputation(factionEntry, rep_change);
6253 void Spell::EffectQuestComplete(uint32 i)
6255 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6256 return;
6258 Player *_player = (Player*)m_caster;
6260 uint32 quest_id = m_spellInfo->EffectMiscValue[i];
6261 _player->AreaExploredOrEventHappens(quest_id);
6264 void Spell::EffectSelfResurrect(uint32 i)
6266 if(!unitTarget || unitTarget->isAlive())
6267 return;
6268 if(unitTarget->GetTypeId() != TYPEID_PLAYER)
6269 return;
6270 if(!unitTarget->IsInWorld())
6271 return;
6273 uint32 health = 0;
6274 uint32 mana = 0;
6276 // flat case
6277 if(damage < 0)
6279 health = uint32(-damage);
6280 mana = m_spellInfo->EffectMiscValue[i];
6282 // percent case
6283 else
6285 health = uint32(damage/100.0f*unitTarget->GetMaxHealth());
6286 if(unitTarget->GetMaxPower(POWER_MANA) > 0)
6287 mana = uint32(damage/100.0f*unitTarget->GetMaxPower(POWER_MANA));
6290 Player *plr = ((Player*)unitTarget);
6291 plr->ResurrectPlayer(0.0f);
6293 plr->SetHealth( health );
6294 plr->SetPower(POWER_MANA, mana );
6295 plr->SetPower(POWER_RAGE, 0 );
6296 plr->SetPower(POWER_ENERGY, plr->GetMaxPower(POWER_ENERGY) );
6298 plr->SpawnCorpseBones();
6301 void Spell::EffectSkinning(uint32 /*i*/)
6303 if(unitTarget->GetTypeId() != TYPEID_UNIT )
6304 return;
6305 if(!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER)
6306 return;
6308 Creature* creature = (Creature*) unitTarget;
6309 int32 targetLevel = creature->getLevel();
6311 uint32 skill = creature->GetCreatureInfo()->GetRequiredLootSkill();
6313 ((Player*)m_caster)->SendLoot(creature->GetGUID(),LOOT_SKINNING);
6314 creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
6316 int32 reqValue = targetLevel < 10 ? 0 : targetLevel < 20 ? (targetLevel-10)*10 : targetLevel*5;
6318 int32 skillValue = ((Player*)m_caster)->GetPureSkillValue(skill);
6320 // Double chances for elites
6321 ((Player*)m_caster)->UpdateGatherSkill(skill, skillValue, reqValue, creature->isElite() ? 2 : 1 );
6324 void Spell::EffectCharge(uint32 /*i*/)
6326 if (!unitTarget)
6327 return;
6329 //TODO: research more ContactPoint/attack distance.
6330 //3.666666 instead of ATTACK_DISTANCE(5.0f) in below seem to give more accurate result.
6331 float x, y, z;
6332 unitTarget->GetContactPoint(m_caster, x, y, z, 3.666666f);
6334 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6335 ((Creature *)unitTarget)->StopMoving();
6337 // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
6338 m_caster->SendMonsterMove(x, y, z, 0, m_caster->GetTypeId()==TYPEID_PLAYER ? MONSTER_MOVE_WALK : ((Creature*)m_caster)->GetMonsterMoveFlags(), 1);
6340 if (m_caster->GetTypeId() != TYPEID_PLAYER)
6341 m_caster->GetMap()->CreatureRelocation((Creature*)m_caster,x,y,z,m_caster->GetOrientation());
6343 // not all charge effects used in negative spells
6344 if (unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
6345 m_caster->Attack(unitTarget,true);
6348 void Spell::EffectCharge2(uint32 /*i*/)
6350 float x, y, z;
6351 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6353 x = m_targets.m_destX;
6354 y = m_targets.m_destY;
6355 z = m_targets.m_destZ;
6357 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6358 ((Creature *)unitTarget)->StopMoving();
6360 else if (unitTarget && unitTarget != m_caster)
6361 unitTarget->GetContactPoint(m_caster, x, y, z, 3.666666f);
6362 else
6363 return;
6365 // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
6366 m_caster->SendMonsterMove(x, y, z, 0, m_caster->GetTypeId()==TYPEID_PLAYER ? MONSTER_MOVE_WALK : ((Creature*)m_caster)->GetMonsterMoveFlags(), 1);
6368 if (m_caster->GetTypeId() != TYPEID_PLAYER)
6369 m_caster->GetMap()->CreatureRelocation((Creature*)m_caster,x,y,z,m_caster->GetOrientation());
6371 // not all charge effects used in negative spells
6372 if (unitTarget && unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
6373 m_caster->Attack(unitTarget,true);
6376 void Spell::EffectSummonCritter(uint32 i, uint32 forceFaction)
6378 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6379 return;
6380 Player* player = (Player*)m_caster;
6382 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
6383 if(!pet_entry)
6384 return;
6386 Pet* old_critter = player->GetMiniPet();
6388 // for same pet just despawn
6389 if(old_critter && old_critter->GetEntry() == pet_entry)
6391 player->RemoveMiniPet();
6392 return;
6395 // despawn old pet before summon new
6396 if(old_critter)
6397 player->RemoveMiniPet();
6399 // summon new pet
6400 Pet* critter = new Pet(MINI_PET);
6402 Map *map = m_caster->GetMap();
6403 uint32 pet_number = sObjectMgr.GeneratePetNumber();
6404 if(!critter->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
6405 pet_entry, pet_number))
6407 sLog.outError("Spell::EffectSummonCritter, spellid %u: no such creature entry %u", m_spellInfo->Id, pet_entry);
6408 delete critter;
6409 return;
6412 float x, y, z;
6413 // If dest location if present
6414 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6416 x = m_targets.m_destX;
6417 y = m_targets.m_destY;
6418 z = m_targets.m_destZ;
6420 // Summon if dest location not present near caster
6421 else
6422 m_caster->GetClosePoint(x, y, z, critter->GetObjectSize());
6424 critter->Relocate(x, y, z, m_caster->GetOrientation());
6426 if(!critter->IsPositionValid())
6428 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
6429 critter->GetGUIDLow(), critter->GetEntry(), critter->GetPositionX(), critter->GetPositionY());
6430 delete critter;
6431 return;
6434 critter->SetOwnerGUID(m_caster->GetGUID());
6435 critter->SetCreatorGUID(m_caster->GetGUID());
6437 critter->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
6438 critter->setFaction(forceFaction ? forceFaction : m_caster->getFaction());
6439 critter->AIM_Initialize();
6440 critter->InitPetCreateSpells(); // e.g. disgusting oozeling has a create spell as critter...
6441 //critter->InitLevelupSpellsForLevel(); // none?
6442 critter->SelectLevel(critter->GetCreatureInfo()); // some summoned creaters have different from 1 DB data for level/hp
6443 critter->SetUInt32Value(UNIT_NPC_FLAGS, critter->GetCreatureInfo()->npcflag);
6444 // some mini-pets have quests
6446 // set timer for unsummon
6447 int32 duration = GetSpellDuration(m_spellInfo);
6448 if(duration > 0)
6449 critter->SetDuration(duration);
6451 std::string name = player->GetName();
6452 name.append(petTypeSuffix[critter->getPetType()]);
6453 critter->SetName( name );
6454 player->SetMiniPet(critter);
6456 map->Add((Creature*)critter);
6459 void Spell::EffectKnockBack(uint32 i)
6461 if(!unitTarget)
6462 return;
6464 unitTarget->KnockBackFrom(m_caster,float(m_spellInfo->EffectMiscValue[i])/10,float(damage)/10);
6467 void Spell::EffectSendTaxi(uint32 i)
6469 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6470 return;
6472 ((Player*)unitTarget)->ActivateTaxiPathTo(m_spellInfo->EffectMiscValue[i],m_spellInfo->Id);
6475 void Spell::EffectPlayerPull(uint32 i)
6477 if(!unitTarget)
6478 return;
6480 float dist = unitTarget->GetDistance2d(m_caster);
6481 if (damage && dist > damage)
6482 dist = damage;
6484 unitTarget->KnockBackFrom(m_caster,-dist,float(m_spellInfo->EffectMiscValue[i])/10);
6487 void Spell::EffectDispelMechanic(uint32 i)
6489 if(!unitTarget)
6490 return;
6492 uint32 mechanic = m_spellInfo->EffectMiscValue[i];
6494 Unit::AuraMap& Auras = unitTarget->GetAuras();
6495 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
6497 next = iter;
6498 ++next;
6499 SpellEntry const *spell = sSpellStore.LookupEntry(iter->second->GetSpellProto()->Id);
6500 if(spell->Mechanic == mechanic || spell->EffectMechanic[iter->second->GetEffIndex()] == mechanic)
6502 unitTarget->RemoveAurasDueToSpell(spell->Id);
6503 if(Auras.empty())
6504 break;
6505 else
6506 next = Auras.begin();
6509 return;
6512 void Spell::EffectSummonDeadPet(uint32 /*i*/)
6514 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6515 return;
6516 Player *_player = (Player*)m_caster;
6517 Pet *pet = _player->GetPet();
6518 if(!pet)
6519 return;
6520 if(pet->isAlive())
6521 return;
6522 if(damage < 0)
6523 return;
6524 pet->SetUInt32Value(UNIT_DYNAMIC_FLAGS, 0);
6525 pet->RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
6526 pet->setDeathState( ALIVE );
6527 pet->clearUnitState(UNIT_STAT_ALL_STATE);
6528 pet->SetHealth( uint32(pet->GetMaxHealth()*(float(damage)/100)));
6530 pet->AIM_Initialize();
6532 // _player->PetSpellInitialize(); -- action bar not removed at death and not required send at revive
6533 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
6536 void Spell::EffectDestroyAllTotems(uint32 /*i*/)
6538 int32 mana = 0;
6539 for(int slot = 0; slot < MAX_TOTEM; ++slot)
6541 if(!m_caster->m_TotemSlot[slot])
6542 continue;
6544 Creature* totem = m_caster->GetMap()->GetCreature(m_caster->m_TotemSlot[slot]);
6545 if(totem && totem->isTotem())
6547 uint32 spell_id = totem->GetUInt32Value(UNIT_CREATED_BY_SPELL);
6548 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
6549 if(spellInfo)
6551 uint32 manacost = m_caster->GetCreateMana() * spellInfo->ManaCostPercentage / 100;
6552 mana += manacost * damage / 100;
6554 ((Totem*)totem)->UnSummon();
6558 if (mana)
6559 m_caster->CastCustomSpell(m_caster, 39104, &mana, NULL, NULL, true);
6562 void Spell::EffectDurabilityDamage(uint32 i)
6564 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6565 return;
6567 int32 slot = m_spellInfo->EffectMiscValue[i];
6569 // FIXME: some spells effects have value -1/-2
6570 // Possibly its mean -1 all player equipped items and -2 all items
6571 if(slot < 0)
6573 ((Player*)unitTarget)->DurabilityPointsLossAll(damage, (slot < -1));
6574 return;
6577 // invalid slot value
6578 if(slot >= INVENTORY_SLOT_BAG_END)
6579 return;
6581 if(Item* item = ((Player*)unitTarget)->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
6582 ((Player*)unitTarget)->DurabilityPointsLoss(item, damage);
6585 void Spell::EffectDurabilityDamagePCT(uint32 i)
6587 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6588 return;
6590 int32 slot = m_spellInfo->EffectMiscValue[i];
6592 // FIXME: some spells effects have value -1/-2
6593 // Possibly its mean -1 all player equipped items and -2 all items
6594 if(slot < 0)
6596 ((Player*)unitTarget)->DurabilityLossAll(double(damage)/100.0f, (slot < -1));
6597 return;
6600 // invalid slot value
6601 if(slot >= INVENTORY_SLOT_BAG_END)
6602 return;
6604 if(damage <= 0)
6605 return;
6607 if(Item* item = ((Player*)unitTarget)->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
6608 ((Player*)unitTarget)->DurabilityLoss(item, double(damage)/100.0f);
6611 void Spell::EffectModifyThreatPercent(uint32 /*effIndex*/)
6613 if(!unitTarget)
6614 return;
6616 unitTarget->getThreatManager().modifyThreatPercent(m_caster, damage);
6619 void Spell::EffectTransmitted(uint32 effIndex)
6621 uint32 name_id = m_spellInfo->EffectMiscValue[effIndex];
6623 GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(name_id);
6625 if (!goinfo)
6627 sLog.outErrorDb("Gameobject (Entry: %u) not exist and not created at spell (ID: %u) cast",name_id, m_spellInfo->Id);
6628 return;
6631 float fx, fy, fz;
6633 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6635 fx = m_targets.m_destX;
6636 fy = m_targets.m_destY;
6637 fz = m_targets.m_destZ;
6639 //FIXME: this can be better check for most objects but still hack
6640 else if(m_spellInfo->EffectRadiusIndex[effIndex] && m_spellInfo->speed==0)
6642 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[effIndex]));
6643 m_caster->GetClosePoint(fx, fy, fz, DEFAULT_WORLD_OBJECT_SIZE, dis);
6645 else
6647 float min_dis = GetSpellMinRange(sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex));
6648 float max_dis = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex));
6649 float dis = rand_norm() * (max_dis - min_dis) + min_dis;
6651 m_caster->GetClosePoint(fx, fy, fz, DEFAULT_WORLD_OBJECT_SIZE, dis);
6654 Map *cMap = m_caster->GetMap();
6656 if(goinfo->type==GAMEOBJECT_TYPE_FISHINGNODE)
6658 if ( !cMap->IsInWater(fx, fy, fz-0.5f)) // Hack to prevent fishing bobber from failing to land on fishing hole
6659 { // but this is not proper, we really need to ignore not materialized objects
6660 SendCastResult(SPELL_FAILED_NOT_HERE);
6661 SendChannelUpdate(0);
6662 return;
6665 // replace by water level in this case
6666 fz = cMap->GetWaterLevel(fx, fy);
6668 // if gameobject is summoning object, it should be spawned right on caster's position
6669 else if(goinfo->type==GAMEOBJECT_TYPE_SUMMONING_RITUAL)
6671 m_caster->GetPosition(fx, fy, fz);
6674 GameObject* pGameObj = new GameObject;
6676 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), name_id, cMap,
6677 m_caster->GetPhaseMask(), fx, fy, fz, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
6679 delete pGameObj;
6680 return;
6683 int32 duration = GetSpellDuration(m_spellInfo);
6685 switch(goinfo->type)
6687 case GAMEOBJECT_TYPE_FISHINGNODE:
6689 m_caster->SetChannelObjectGUID(pGameObj->GetGUID());
6690 m_caster->AddGameObject(pGameObj); // will removed at spell cancel
6692 // end time of range when possible catch fish (FISHING_BOBBER_READY_TIME..GetDuration(m_spellInfo))
6693 // start time == fish-FISHING_BOBBER_READY_TIME (0..GetDuration(m_spellInfo)-FISHING_BOBBER_READY_TIME)
6694 int32 lastSec = 0;
6695 switch(urand(0, 3))
6697 case 0: lastSec = 3; break;
6698 case 1: lastSec = 7; break;
6699 case 2: lastSec = 13; break;
6700 case 3: lastSec = 17; break;
6703 duration = duration - lastSec*IN_MILISECONDS + FISHING_BOBBER_READY_TIME*IN_MILISECONDS;
6704 break;
6706 case GAMEOBJECT_TYPE_SUMMONING_RITUAL:
6708 if(m_caster->GetTypeId() == TYPEID_PLAYER)
6710 pGameObj->AddUniqueUse((Player*)m_caster);
6711 m_caster->AddGameObject(pGameObj); // will removed at spell cancel
6713 break;
6715 case GAMEOBJECT_TYPE_FISHINGHOLE:
6716 case GAMEOBJECT_TYPE_CHEST:
6717 default:
6718 break;
6721 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
6723 pGameObj->SetOwnerGUID(m_caster->GetGUID());
6725 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel());
6726 pGameObj->SetSpellId(m_spellInfo->Id);
6728 DEBUG_LOG("AddObject at SpellEfects.cpp EffectTransmitted");
6729 //m_caster->AddGameObject(pGameObj);
6730 //m_ObjToDel.push_back(pGameObj);
6732 cMap->Add(pGameObj);
6734 if(uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry())
6736 GameObject* linkedGO = new GameObject;
6737 if(linkedGO->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, cMap,
6738 m_caster->GetPhaseMask(), fx, fy, fz, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
6740 linkedGO->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
6741 linkedGO->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel());
6742 linkedGO->SetSpellId(m_spellInfo->Id);
6743 linkedGO->SetOwnerGUID(m_caster->GetGUID());
6745 linkedGO->GetMap()->Add(linkedGO);
6747 else
6749 delete linkedGO;
6750 linkedGO = NULL;
6751 return;
6756 void Spell::EffectProspecting(uint32 /*i*/)
6758 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6759 return;
6761 Player* p_caster = (Player*)m_caster;
6762 if(!itemTarget || !(itemTarget->GetProto()->BagFamily & BAG_FAMILY_MASK_MINING_SUPP))
6763 return;
6765 if(itemTarget->GetCount() < 5)
6766 return;
6768 if( sWorld.getConfig(CONFIG_SKILL_PROSPECTING))
6770 uint32 SkillValue = p_caster->GetPureSkillValue(SKILL_JEWELCRAFTING);
6771 uint32 reqSkillValue = itemTarget->GetProto()->RequiredSkillRank;
6772 p_caster->UpdateGatherSkill(SKILL_JEWELCRAFTING, SkillValue, reqSkillValue);
6775 ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(), LOOT_PROSPECTING);
6778 void Spell::EffectMilling(uint32 /*i*/)
6780 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6781 return;
6783 Player* p_caster = (Player*)m_caster;
6784 if(!itemTarget || !(itemTarget->GetProto()->BagFamily & BAG_FAMILY_MASK_HERBS))
6785 return;
6787 if(itemTarget->GetCount() < 5)
6788 return;
6790 if( sWorld.getConfig(CONFIG_SKILL_MILLING))
6792 uint32 SkillValue = p_caster->GetPureSkillValue(SKILL_INSCRIPTION);
6793 uint32 reqSkillValue = itemTarget->GetProto()->RequiredSkillRank;
6794 p_caster->UpdateGatherSkill(SKILL_INSCRIPTION, SkillValue, reqSkillValue);
6797 ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(), LOOT_MILLING);
6800 void Spell::EffectSkill(uint32 /*i*/)
6802 sLog.outDebug("WORLD: SkillEFFECT");
6805 void Spell::EffectSpiritHeal(uint32 /*i*/)
6807 // TODO player can't see the heal-animation - he should respawn some ticks later
6808 if (!unitTarget || unitTarget->isAlive())
6809 return;
6810 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6811 return;
6812 if (!unitTarget->IsInWorld())
6813 return;
6814 if (m_spellInfo->Id == 22012 && !unitTarget->HasAura(2584))
6815 return;
6817 ((Player*)unitTarget)->ResurrectPlayer(1.0f);
6818 ((Player*)unitTarget)->SpawnCorpseBones();
6821 // remove insignia spell effect
6822 void Spell::EffectSkinPlayerCorpse(uint32 /*i*/)
6824 sLog.outDebug("Effect: SkinPlayerCorpse");
6825 if ( (m_caster->GetTypeId() != TYPEID_PLAYER) || (unitTarget->GetTypeId() != TYPEID_PLAYER) || (unitTarget->isAlive()) )
6826 return;
6828 ((Player*)unitTarget)->RemovedInsignia( (Player*)m_caster );
6831 void Spell::EffectStealBeneficialBuff(uint32 i)
6833 sLog.outDebug("Effect: StealBeneficialBuff");
6835 if(!unitTarget || unitTarget==m_caster) // can't steal from self
6836 return;
6838 std::vector <Aura *> steal_list;
6839 // Create dispel mask by dispel type
6840 uint32 dispelMask = GetDispellMask( DispelType(m_spellInfo->EffectMiscValue[i]) );
6841 Unit::AuraMap const& auras = unitTarget->GetAuras();
6842 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
6844 Aura *aur = (*itr).second;
6845 if (aur && (1<<aur->GetSpellProto()->Dispel) & dispelMask)
6847 // Need check for passive? this
6848 if (aur->IsPositive() && !aur->IsPassive() && !(aur->GetSpellProto()->AttributesEx4 & SPELL_ATTR_EX4_NOT_STEALABLE))
6849 steal_list.push_back(aur);
6852 // Ok if exist some buffs for dispel try dispel it
6853 if (!steal_list.empty())
6855 std::list < std::pair<uint32,uint64> > success_list;
6856 int32 list_size = steal_list.size();
6857 // Dispell N = damage buffs (or while exist buffs for dispel)
6858 for (int32 count=0; count < damage && list_size > 0; ++count)
6860 // Random select buff for dispel
6861 Aura *aur = steal_list[urand(0, list_size-1)];
6862 // Not use chance for steal
6863 // TODO possible need do it
6864 success_list.push_back( std::pair<uint32,uint64>(aur->GetId(),aur->GetCasterGUID()));
6866 // Remove buff from list for prevent doubles
6867 for (std::vector<Aura *>::iterator j = steal_list.begin(); j != steal_list.end(); )
6869 Aura *stealed = *j;
6870 if (stealed->GetId() == aur->GetId() && stealed->GetCasterGUID() == aur->GetCasterGUID())
6872 j = steal_list.erase(j);
6873 --list_size;
6875 else
6876 ++j;
6879 // Really try steal and send log
6880 if (!success_list.empty())
6882 int32 count = success_list.size();
6883 WorldPacket data(SMSG_SPELLSTEALLOG, 8+8+4+1+4+count*5);
6884 data.append(unitTarget->GetPackGUID()); // Victim GUID
6885 data.append(m_caster->GetPackGUID()); // Caster GUID
6886 data << uint32(m_spellInfo->Id); // Dispell spell id
6887 data << uint8(0); // not used
6888 data << uint32(count); // count
6889 for (std::list<std::pair<uint32,uint64> >::iterator j = success_list.begin(); j != success_list.end(); ++j)
6891 SpellEntry const* spellInfo = sSpellStore.LookupEntry(j->first);
6892 data << uint32(spellInfo->Id); // Spell Id
6893 data << uint8(0); // 0 - steals !=0 transfers
6894 unitTarget->RemoveAurasDueToSpellBySteal(spellInfo->Id, j->second, m_caster);
6896 m_caster->SendMessageToSet(&data, true);
6901 void Spell::EffectKillCreditPersonal(uint32 i)
6903 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6904 return;
6906 ((Player*)unitTarget)->KilledMonsterCredit(m_spellInfo->EffectMiscValue[i], 0);
6909 void Spell::EffectKillCredit(uint32 i)
6911 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6912 return;
6914 ((Player*)unitTarget)->RewardPlayerAndGroupAtEvent(m_spellInfo->EffectMiscValue[i], unitTarget);
6917 void Spell::EffectQuestFail(uint32 i)
6919 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6920 return;
6922 ((Player*)unitTarget)->FailQuest(m_spellInfo->EffectMiscValue[i]);
6925 void Spell::EffectActivateRune(uint32 eff_idx)
6927 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6928 return;
6930 Player *plr = (Player*)m_caster;
6932 if(plr->getClass() != CLASS_DEATH_KNIGHT)
6933 return;
6935 for(uint32 j = 0; j < MAX_RUNES; ++j)
6937 if(plr->GetRuneCooldown(j) && plr->GetCurrentRune(j) == RuneType(m_spellInfo->EffectMiscValue[eff_idx]))
6939 plr->SetRuneCooldown(j, 0);
6944 void Spell::EffectTitanGrip(uint32 /*eff_idx*/)
6946 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6947 ((Player*)unitTarget)->SetCanTitanGrip(true);
6950 void Spell::EffectRenamePet(uint32 /*eff_idx*/)
6952 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT ||
6953 !((Creature*)unitTarget)->isPet() || ((Pet*)unitTarget)->getPetType() != HUNTER_PET)
6954 return;
6956 unitTarget->SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED);
6959 void Spell::EffectPlayMusic(uint32 i)
6961 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6962 return;
6964 uint32 soundid = m_spellInfo->EffectMiscValue[i];
6966 if (!sSoundEntriesStore.LookupEntry(soundid))
6968 sLog.outError("EffectPlayMusic: Sound (Id: %u) not exist in spell %u.",soundid,m_spellInfo->Id);
6969 return;
6972 WorldPacket data(SMSG_PLAY_MUSIC, 4);
6973 data << uint32(soundid);
6974 ((Player*)unitTarget)->GetSession()->SendPacket(&data);