[9149] Drop code and DB data for removed 31892/53720 and related spells.
[getmangos.git] / src / game / SpellEffects.cpp
blobc5488d0101d49839e8f2ad565781ed7b294e7dd8
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 // Avenger's Shield ($m1+0.07*$SPH+0.07*$AP) - ranged sdb for future
672 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000004000))
674 float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
675 int32 holy = m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo)) +
676 m_caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellInfo), unitTarget);
677 damage += int32(ap * 0.07f) + int32(holy * 7 / 100);
679 // Hammer of Wrath ($m1+0.15*$SPH+0.15*$AP) - ranged type sdb future fix
680 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000008000000000))
682 float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
683 int32 holy = m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo)) +
684 m_caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellInfo), unitTarget);
685 damage += int32(ap * 0.15f) + int32(holy * 15 / 100);
687 // Hammer of the Righteous
688 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0004000000000000))
690 // Add main hand dps * effect[2] amount
691 float average = (m_caster->GetFloatValue(UNIT_FIELD_MINDAMAGE) + m_caster->GetFloatValue(UNIT_FIELD_MAXDAMAGE)) / 2;
692 int32 count = m_caster->CalculateSpellDamage(m_spellInfo, 2, m_spellInfo->EffectBasePoints[2], unitTarget);
693 damage += count * int32(average * IN_MILISECONDS) / m_caster->GetAttackTime(BASE_ATTACK);
695 // Shield of Righteousness
696 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0010000000000000))
698 damage+=int32(m_caster->GetShieldBlockValue());
700 // Judgement
701 else if (m_spellInfo->Id == 54158)
703 // [1 + 0.25 * SPH + 0.16 * AP]
704 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 0.16f);
706 break;
710 if(damage >= 0)
711 m_damage += damage;
715 void Spell::EffectDummy(uint32 i)
717 if (!unitTarget && !gameObjTarget && !itemTarget)
718 return;
720 // selection by spell family
721 switch(m_spellInfo->SpellFamilyName)
723 case SPELLFAMILY_GENERIC:
725 switch(m_spellInfo->Id )
727 case 8063: // Deviate Fish
729 if (m_caster->GetTypeId() != TYPEID_PLAYER)
730 return;
732 uint32 spell_id = 0;
733 switch(urand(1,5))
735 case 1: spell_id = 8064; break; // Sleepy
736 case 2: spell_id = 8065; break; // Invigorate
737 case 3: spell_id = 8066; break; // Shrink
738 case 4: spell_id = 8067; break; // Party Time!
739 case 5: spell_id = 8068; break; // Healthy Spirit
741 m_caster->CastSpell(m_caster, spell_id, true, NULL);
742 return;
744 case 8213: // Savory Deviate Delight
746 if (m_caster->GetTypeId() != TYPEID_PLAYER)
747 return;
749 uint32 spell_id = 0;
750 switch(urand(1,2))
752 // Flip Out - ninja
753 case 1: spell_id = (m_caster->getGender() == GENDER_MALE ? 8219 : 8220); break;
754 // Yaaarrrr - pirate
755 case 2: spell_id = (m_caster->getGender() == GENDER_MALE ? 8221 : 8222); break;
757 m_caster->CastSpell(m_caster,spell_id,true,NULL);
758 return;
760 case 8593: // Symbol of life (restore creature to life)
761 case 31225: // Shimmering Vessel (restore creature to life)
763 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
764 return;
765 ((Creature*)unitTarget)->setDeathState(JUST_ALIVED);
766 return;
768 case 13120: // net-o-matic
770 if (!unitTarget)
771 return;
773 uint32 spell_id = 0;
775 uint32 roll = urand(0, 99);
777 if (roll < 2) // 2% for 30 sec self root (off-like chance unknown)
778 spell_id = 16566;
779 else if (roll < 4) // 2% for 20 sec root, charge to target (off-like chance unknown)
780 spell_id = 13119;
781 else // normal root
782 spell_id = 13099;
784 m_caster->CastSpell(unitTarget,spell_id,true,NULL);
785 return;
787 case 13567: // Dummy Trigger
789 // can be used for different aura triggering, so select by aura
790 if (!m_triggeredByAuraSpell || !unitTarget)
791 return;
793 switch(m_triggeredByAuraSpell->Id)
795 case 26467: // Persistent Shield
796 m_caster->CastCustomSpell(unitTarget, 26470, &damage, NULL, NULL, true);
797 break;
798 default:
799 sLog.outError("EffectDummy: Non-handled case for spell 13567 for triggered aura %u",m_triggeredByAuraSpell->Id);
800 break;
802 return;
804 case 15998: // Capture Worg Pup
805 case 29435: // Capture Female Kaliri Hatchling
807 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
808 return;
810 Creature* creatureTarget = (Creature*)unitTarget;
812 creatureTarget->ForcedDespawn();
813 return;
815 case 16589: // Noggenfogger Elixir
817 if (m_caster->GetTypeId() != TYPEID_PLAYER)
818 return;
820 uint32 spell_id = 0;
821 switch(urand(1, 3))
823 case 1: spell_id = 16595; break;
824 case 2: spell_id = 16593; break;
825 default:spell_id = 16591; break;
828 m_caster->CastSpell(m_caster, spell_id, true, NULL);
829 return;
831 case 17251: // Spirit Healer Res
833 if (!unitTarget || !m_originalCaster)
834 return;
836 if (m_originalCaster->GetTypeId() == TYPEID_PLAYER)
838 WorldPacket data(SMSG_SPIRIT_HEALER_CONFIRM, 8);
839 data << uint64(unitTarget->GetGUID());
840 ((Player*)m_originalCaster)->GetSession()->SendPacket( &data );
842 return;
844 case 17271: // Test Fetid Skull
846 if (!itemTarget && m_caster->GetTypeId()!=TYPEID_PLAYER)
847 return;
849 uint32 spell_id = roll_chance_i(50)
850 ? 17269 // Create Resonating Skull
851 : 17270; // Create Bone Dust
853 m_caster->CastSpell(m_caster, spell_id, true, NULL);
854 return;
856 case 20577: // Cannibalize
857 if (unitTarget)
858 m_caster->CastSpell(m_caster, 20578, false, NULL);
859 return;
860 case 23019: // Crystal Prison Dummy DND
862 if (!unitTarget || !unitTarget->isAlive() || unitTarget->GetTypeId() != TYPEID_UNIT || ((Creature*)unitTarget)->isPet())
863 return;
865 Creature* creatureTarget = (Creature*)unitTarget;
866 if (creatureTarget->isPet())
867 return;
869 GameObject* pGameObj = new GameObject;
871 Map *map = creatureTarget->GetMap();
873 // create before death for get proper coordinates
874 if (!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), 179644, map, m_caster->GetPhaseMask(),
875 creatureTarget->GetPositionX(), creatureTarget->GetPositionY(), creatureTarget->GetPositionZ(),
876 creatureTarget->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY) )
878 delete pGameObj;
879 return;
882 pGameObj->SetRespawnTime(creatureTarget->GetRespawnTime()-time(NULL));
883 pGameObj->SetOwnerGUID(m_caster->GetGUID() );
884 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel() );
885 pGameObj->SetSpellId(m_spellInfo->Id);
887 creatureTarget->ForcedDespawn();
889 DEBUG_LOG("AddObject at SpellEfects.cpp EffectDummy");
890 map->Add(pGameObj);
892 return;
894 case 23074: // Arcanite Dragonling
895 if (!m_CastItem)
896 return;
897 m_caster->CastSpell(m_caster, 19804, true, m_CastItem);
898 return;
899 case 23075: // Mithril Mechanical Dragonling
900 if (!m_CastItem)
901 return;
902 m_caster->CastSpell(m_caster, 12749, true, m_CastItem);
903 return;
904 case 23076: // Mechanical Dragonling
905 if (!m_CastItem)
906 return;
907 m_caster->CastSpell(m_caster, 4073, true, m_CastItem);
908 return;
909 case 23133: // Gnomish Battle Chicken
910 if (!m_CastItem)
911 return;
912 m_caster->CastSpell(m_caster, 13166, true, m_CastItem);
913 return;
914 case 23448: // Transporter Arrival - Ultrasafe Transporter: Gadgetzan - backfires
916 int32 r = irand(0, 119);
917 if (r < 20) // Transporter Malfunction - 1/6 polymorph
918 m_caster->CastSpell(m_caster, 23444, true);
919 else if (r < 100) // Evil Twin - 4/6 evil twin
920 m_caster->CastSpell(m_caster, 23445, true);
921 else // Transporter Malfunction - 1/6 miss the target
922 m_caster->CastSpell(m_caster, 36902, true);
923 return;
925 case 23453: // Gnomish Transporter - Ultrasafe Transporter: Gadgetzan
926 if (roll_chance_i(50)) // Gadgetzan Transporter - success
927 m_caster->CastSpell(m_caster, 23441, true);
928 else // Gadgetzan Transporter Failure - failure
929 m_caster->CastSpell(m_caster, 23446, true);
930 return;
931 case 23645: // Hourglass Sand
932 m_caster->RemoveAurasDueToSpell(23170); // Brood Affliction: Bronze
933 return;
934 case 23725: // Gift of Life (warrior bwl trinket)
935 m_caster->CastSpell(m_caster, 23782, true);
936 m_caster->CastSpell(m_caster, 23783, true);
937 return;
938 case 25860: // Reindeer Transformation
940 if (!m_caster->HasAuraType(SPELL_AURA_MOUNTED))
941 return;
943 float flyspeed = m_caster->GetSpeedRate(MOVE_FLIGHT);
944 float speed = m_caster->GetSpeedRate(MOVE_RUN);
946 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
948 //5 different spells used depending on mounted speed and if mount can fly or not
949 if (flyspeed >= 4.1f)
950 // Flying Reindeer
951 m_caster->CastSpell(m_caster, 44827, true); //310% flying Reindeer
952 else if (flyspeed >= 3.8f)
953 // Flying Reindeer
954 m_caster->CastSpell(m_caster, 44825, true); //280% flying Reindeer
955 else if (flyspeed >= 1.6f)
956 // Flying Reindeer
957 m_caster->CastSpell(m_caster, 44824, true); //60% flying Reindeer
958 else if (speed >= 2.0f)
959 // Reindeer
960 m_caster->CastSpell(m_caster, 25859, true); //100% ground Reindeer
961 else
962 // Reindeer
963 m_caster->CastSpell(m_caster, 25858, true); //60% ground Reindeer
965 return;
967 case 26074: // Holiday Cheer
968 // implemented at client side
969 return;
970 case 28006: // Arcane Cloaking
972 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER )
973 // Naxxramas Entry Flag Effect DND
974 m_caster->CastSpell(unitTarget, 29294, true);
975 return;
977 case 29200: // Purify Helboar Meat
979 if (m_caster->GetTypeId() != TYPEID_PLAYER)
980 return;
982 uint32 spell_id = roll_chance_i(50)
983 ? 29277 // Summon Purified Helboar Meat
984 : 29278; // Summon Toxic Helboar Meat
986 m_caster->CastSpell(m_caster,spell_id,true,NULL);
987 return;
989 case 29858: // Soulshatter
990 if (unitTarget && unitTarget->GetTypeId() == TYPEID_UNIT && unitTarget->IsHostileTo(m_caster))
991 m_caster->CastSpell(unitTarget,32835,true);
992 return;
993 case 30458: // Nigh Invulnerability
994 if (!m_CastItem)
995 return;
996 if (roll_chance_i(86)) // Nigh-Invulnerability - success
997 m_caster->CastSpell(m_caster, 30456, true, m_CastItem);
998 else // Complete Vulnerability - backfire in 14% casts
999 m_caster->CastSpell(m_caster, 30457, true, m_CastItem);
1000 return;
1001 case 30507: // Poultryizer
1002 if(!m_CastItem)
1003 return;
1004 if (roll_chance_i(80)) // Poultryized! - success
1005 m_caster->CastSpell(unitTarget, 30501, true, m_CastItem);
1006 else // Poultryized! - backfire 20%
1007 m_caster->CastSpell(unitTarget, 30504, true, m_CastItem);
1008 return;
1009 case 33060: // Make a Wish
1011 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1012 return;
1014 uint32 spell_id = 0;
1016 switch(urand(1,5))
1018 case 1: spell_id = 33053; break; // Mr Pinchy's Blessing
1019 case 2: spell_id = 33057; break; // Summon Mighty Mr. Pinchy
1020 case 3: spell_id = 33059; break; // Summon Furious Mr. Pinchy
1021 case 4: spell_id = 33062; break; // Tiny Magical Crawdad
1022 case 5: spell_id = 33064; break; // Mr. Pinchy's Gift
1025 m_caster->CastSpell(m_caster, spell_id, true, NULL);
1026 return;
1028 case 34665: //Administer Antidote
1030 if (!unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER )
1031 return;
1032 // Spell has scriptable target but for sure.
1033 if (unitTarget->GetTypeId() != TYPEID_UNIT)
1034 return;
1036 uint32 health = unitTarget->GetHealth();
1037 float x, y, z, o;
1039 unitTarget->GetPosition(x, y, z);
1040 o = unitTarget->GetOrientation();
1041 ((Creature*)unitTarget)->ForcedDespawn();
1043 if (Creature* summon = m_caster->SummonCreature(16992, x, y, z, o,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,180000))
1045 summon->SetHealth(health);
1046 ((Player*)m_caster)->RewardPlayerAndGroupAtEvent(16992, summon);
1048 if (summon->AI())
1049 summon->AI()->AttackStart(m_caster);
1051 return;
1053 case 35745: // Socrethar's Stone
1055 uint32 spell_id;
1056 switch(m_caster->GetAreaId())
1058 case 3900: spell_id = 35743; break; // Socrethar Portal
1059 case 3742: spell_id = 35744; break; // Socrethar Portal
1060 default: return;
1063 m_caster->CastSpell(m_caster, spell_id, true);
1064 return;
1066 case 37674: // Chaos Blast
1068 if (!unitTarget)
1069 return;
1071 int32 basepoints0 = 100;
1072 m_caster->CastCustomSpell(unitTarget, 37675, &basepoints0, NULL, NULL, true);
1073 return;
1075 case 40802: // Mingo's Fortune Generator (Mingo's Fortune Giblets)
1077 // selecting one from Bloodstained Fortune item
1078 uint32 newitemid;
1079 switch(urand(1, 20))
1081 case 1: newitemid = 32688; break;
1082 case 2: newitemid = 32689; break;
1083 case 3: newitemid = 32690; break;
1084 case 4: newitemid = 32691; break;
1085 case 5: newitemid = 32692; break;
1086 case 6: newitemid = 32693; break;
1087 case 7: newitemid = 32700; break;
1088 case 8: newitemid = 32701; break;
1089 case 9: newitemid = 32702; break;
1090 case 10: newitemid = 32703; break;
1091 case 11: newitemid = 32704; break;
1092 case 12: newitemid = 32705; break;
1093 case 13: newitemid = 32706; break;
1094 case 14: newitemid = 32707; break;
1095 case 15: newitemid = 32708; break;
1096 case 16: newitemid = 32709; break;
1097 case 17: newitemid = 32710; break;
1098 case 18: newitemid = 32711; break;
1099 case 19: newitemid = 32712; break;
1100 case 20: newitemid = 32713; break;
1101 default:
1102 return;
1105 DoCreateItem(i, newitemid);
1106 return;
1108 // Demon Broiled Surprise
1109 /* FIX ME: Required for correct work implementing implicit target 7 (in pair (22,7))
1110 case 43723:
1112 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1113 return;
1115 ((Player*)m_caster)->CastSpell(unitTarget, 43753, true);
1116 return;
1119 case 44875: // Complete Raptor Capture
1121 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
1122 return;
1124 Creature* creatureTarget = (Creature*)unitTarget;
1126 creatureTarget->ForcedDespawn();
1128 //cast spell Raptor Capture Credit
1129 m_caster->CastSpell(m_caster, 42337, true, NULL);
1130 return;
1132 case 44997: // Converting Sentry
1134 //Converted Sentry Credit
1135 m_caster->CastSpell(m_caster, 45009, true);
1136 return;
1138 case 45030: // Impale Emissary
1140 // Emissary of Hate Credit
1141 m_caster->CastSpell(m_caster, 45088, true);
1142 return;
1144 case 49357: // Brewfest Mount Transformation
1145 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1146 return;
1148 if (!m_caster->HasAuraType(SPELL_AURA_MOUNTED))
1149 return;
1151 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1153 // Ram for Alliance, Kodo for Horde
1154 if (((Player *)m_caster)->GetTeam() == ALLIANCE)
1156 if (m_caster->GetSpeedRate(MOVE_RUN) >= 2.0f)
1157 // 100% Ram
1158 m_caster->CastSpell(m_caster, 43900, true);
1159 else
1160 // 60% Ram
1161 m_caster->CastSpell(m_caster, 43899, true);
1163 else
1165 if (((Player *)m_caster)->GetSpeedRate(MOVE_RUN) >= 2.0f)
1166 // 100% Kodo
1167 m_caster->CastSpell(m_caster, 49379, true);
1168 else
1169 // 60% Kodo
1170 m_caster->CastSpell(m_caster, 49378, true);
1172 return;
1173 case 50243: // Teach Language
1175 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1176 return;
1178 // spell has a 1/3 chance to trigger one of the below
1179 if (roll_chance_i(66))
1180 return;
1181 if (((Player*)m_caster)->GetTeam() == ALLIANCE)
1183 // 1000001 - gnomish binary
1184 m_caster->CastSpell(m_caster, 50242, true);
1186 else
1188 // 01001000 - goblin binary
1189 m_caster->CastSpell(m_caster, 50246, true);
1192 return;
1194 case 46167: // Planning for the Future: Create Snowfall Glade Pup Cover
1195 case 50926: // Gluttonous Lurkers: Create Zul'Drak Rat Cover
1196 case 51026: // Create Drakkari Medallion Cover
1197 case 51592: // Pickup Primordial Hatchling
1198 case 51961: // Captured Chicken Cover
1200 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || m_caster->GetTypeId() != TYPEID_PLAYER)
1201 return;
1203 uint32 spellId = 0;
1205 switch(m_spellInfo->Id)
1207 case 46167: spellId = 46773; break;
1208 case 50926: spellId = 50927; break;
1209 case 51026: spellId = 50737; break;
1210 case 51592: spellId = 51593; break;
1211 case 51961: spellId = 51037; break;
1214 if (const SpellEntry *pSpell = sSpellStore.LookupEntry(spellId))
1216 unitTarget->CastSpell(m_caster, spellId, true);
1218 Creature* creatureTarget = (Creature*)unitTarget;
1220 if (const SpellCastTimesEntry *pCastTime = sSpellCastTimesStore.LookupEntry(pSpell->CastingTimeIndex))
1221 creatureTarget->ForcedDespawn(pCastTime->CastTime + 1);
1223 return;
1225 case 51582: //Rocket Boots Engaged (Rocket Boots Xtreme and Rocket Boots Xtreme Lite)
1227 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1228 return;
1230 if (BattleGround* bg = ((Player*)m_caster)->GetBattleGround())
1231 bg->EventPlayerDroppedFlag((Player*)m_caster);
1233 m_caster->CastSpell(m_caster, 30452, true, NULL);
1234 return;
1236 case 52308: // Take Sputum Sample
1238 switch(i)
1240 case 0:
1242 uint32 spellID = m_spellInfo->CalculateSimpleValue(0);
1243 uint32 reqAuraID = m_spellInfo->CalculateSimpleValue(1);
1245 if (m_caster->HasAura(reqAuraID,0))
1246 m_caster->CastSpell(m_caster, spellID, true, NULL);
1247 return;
1249 case 1:
1250 return; // additional data for dummy[0]
1252 return;
1254 case 52759: // Ancestral Awakening
1255 if (!unitTarget)
1256 return;
1257 m_caster->CastCustomSpell(unitTarget, 52752, &damage, NULL, NULL, true);
1258 return;
1259 case 52845: // Brewfest Mount Transformation (Faction Swap)
1260 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1261 return;
1263 if (!m_caster->HasAuraType(SPELL_AURA_MOUNTED))
1264 return;
1266 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1268 // Ram for Horde, Kodo for Alliance
1269 if (((Player *)m_caster)->GetTeam() == HORDE)
1271 if (m_caster->GetSpeedRate(MOVE_RUN) >= 2.0f)
1272 // Swift Brewfest Ram, 100% Ram
1273 m_caster->CastSpell(m_caster, 43900, true);
1274 else
1275 // Brewfest Ram, 60% Ram
1276 m_caster->CastSpell(m_caster, 43899, true);
1278 else
1280 if (((Player *)m_caster)->GetSpeedRate(MOVE_RUN) >= 2.0f)
1281 // Great Brewfest Kodo, 100% Kodo
1282 m_caster->CastSpell(m_caster, 49379, true);
1283 else
1284 // Brewfest Riding Kodo, 60% Kodo
1285 m_caster->CastSpell(m_caster, 49378, true);
1287 return;
1288 case 53341: // Rune of Cinderglacier
1289 case 53343: // Rune of Razorice
1291 // Runeforging Credit
1292 m_caster->CastSpell(m_caster, 54586, true);
1293 return;
1295 case 55004: // Nitro Boosts
1296 if (!m_CastItem)
1297 return;
1298 if (roll_chance_i(95)) // Nitro Boosts - success
1299 m_caster->CastSpell(m_caster, 54861, true, m_CastItem);
1300 else // Knocked Up - backfire 5%
1301 m_caster->CastSpell(m_caster, 46014, true, m_CastItem);
1302 return;
1303 case 58418: // Portal to Orgrimmar
1304 case 58420: // Portal to Stormwind
1305 return; // implemented in EffectScript[0]
1306 case 59640: // Underbelly Elixir
1308 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1309 return;
1311 uint32 spell_id = 0;
1312 switch(urand(1,3))
1314 case 1: spell_id = 59645; break;
1315 case 2: spell_id = 59831; break;
1316 case 3: spell_id = 59843; break;
1318 m_caster->CastSpell(m_caster,spell_id,true,NULL);
1319 return;
1321 case 60932: // Disengage (one from creature versions)
1322 if (!unitTarget)
1323 return;
1324 m_caster->CastSpell(unitTarget,60934,true,NULL);
1325 return;
1326 case 67019: // Flask of the North
1328 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1329 return;
1331 uint32 spell_id = 0;
1332 switch(m_caster->getClass())
1334 case CLASS_WARRIOR:
1335 case CLASS_DEATH_KNIGHT:
1336 spell_id = 67018; // STR for Warriors, Death Knights
1337 break;
1338 case CLASS_ROGUE:
1339 case CLASS_HUNTER:
1340 spell_id = 67017; // AP for Rogues, Hunters
1341 break;
1342 case CLASS_PRIEST:
1343 case CLASS_MAGE:
1344 case CLASS_WARLOCK:
1345 spell_id = 67016; // SPD for Priests, Mages, Warlocks
1346 break;
1347 case CLASS_SHAMAN:
1348 // random (SPD, AP)
1349 spell_id = roll_chance_i(50) ? 67016 : 67017;
1350 break;
1351 case CLASS_PALADIN:
1352 case CLASS_DRUID:
1353 default:
1354 // random (SPD, STR)
1355 spell_id = roll_chance_i(50) ? 67016 : 67018;
1356 break;
1358 m_caster->CastSpell(m_caster, spell_id, true);
1359 return;
1362 break;
1364 case SPELLFAMILY_MAGE:
1365 switch(m_spellInfo->Id )
1367 case 11958: // Cold Snap
1369 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1370 return;
1372 // immediately finishes the cooldown on Frost spells
1373 const SpellCooldowns& cm = ((Player *)m_caster)->GetSpellCooldownMap();
1374 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1376 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1378 if (spellInfo->SpellFamilyName == SPELLFAMILY_MAGE &&
1379 (GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_FROST) &&
1380 spellInfo->Id != 11958 && GetSpellRecoveryTime(spellInfo) > 0)
1382 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first, true);
1384 else
1385 ++itr;
1387 return;
1389 case 32826: // Polymorph Cast Visual
1391 if (unitTarget && unitTarget->GetTypeId() == TYPEID_UNIT)
1393 //Polymorph Cast Visual Rank 1
1394 const uint32 spell_list[6] = {
1395 32813, // Squirrel Form
1396 32816, // Giraffe Form
1397 32817, // Serpent Form
1398 32818, // Dragonhawk Form
1399 32819, // Worgen Form
1400 32820 // Sheep Form
1402 unitTarget->CastSpell( unitTarget, spell_list[urand(0, 5)], true);
1404 return;
1407 break;
1408 case SPELLFAMILY_WARRIOR:
1409 // Charge
1410 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x1)) && m_spellInfo->SpellVisual[0] == 867)
1412 int32 chargeBasePoints0 = damage;
1413 m_caster->CastCustomSpell(m_caster, 34846, &chargeBasePoints0, NULL, NULL, true);
1414 return;
1416 // Execute
1417 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x20000000))
1419 if(!unitTarget)
1420 return;
1422 uint32 rage = m_caster->GetPower(POWER_RAGE);
1424 // up to max 30 rage cost
1425 if(rage > 300)
1426 rage = 300;
1428 // Glyph of Execution bonus
1429 uint32 rage_modified = rage;
1431 if (Aura *aura = m_caster->GetDummyAura(58367))
1432 rage_modified += aura->GetModifier()->m_amount*10;
1434 int32 basePoints0 = damage+int32(rage_modified * m_spellInfo->DmgMultiplier[i] +
1435 m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.2f);
1437 m_caster->CastCustomSpell(unitTarget, 20647, &basePoints0, NULL, NULL, true, 0);
1439 // Sudden Death
1440 if(m_caster->HasAura(52437))
1442 Unit::AuraList const& auras = m_caster->GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL);
1443 for (Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
1445 // Only Sudden Death have this SpellIconID with SPELL_AURA_PROC_TRIGGER_SPELL
1446 if ((*itr)->GetSpellProto()->SpellIconID == 1989)
1448 // saved rage top stored in next affect
1449 uint32 lastrage = (*itr)->GetSpellProto()->CalculateSimpleValue(1)*10;
1450 if(lastrage < rage)
1451 rage -= lastrage;
1452 break;
1457 m_caster->SetPower(POWER_RAGE,m_caster->GetPower(POWER_RAGE)-rage);
1458 return;
1460 // Slam
1461 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000200000))
1463 if(!unitTarget)
1464 return;
1465 m_damage+=m_caster->CalculateDamage(m_attackType, false);
1466 m_damage+=damage;
1467 return;
1469 // Concussion Blow
1470 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000004000000))
1472 m_damage+= uint32(damage * m_caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
1473 return;
1476 switch(m_spellInfo->Id)
1478 // Warrior's Wrath
1479 case 21977:
1481 if (!unitTarget)
1482 return;
1483 m_caster->CastSpell(unitTarget, 21887, true);// spell mod
1484 return;
1486 // Last Stand
1487 case 12975:
1489 int32 healthModSpellBasePoints0 = int32(m_caster->GetMaxHealth()*0.3);
1490 m_caster->CastCustomSpell(m_caster, 12976, &healthModSpellBasePoints0, NULL, NULL, true, NULL);
1491 return;
1493 // Bloodthirst
1494 case 23881:
1496 m_caster->CastCustomSpell(unitTarget, 23885, &damage, NULL, NULL, true, NULL);
1497 return;
1500 break;
1501 case SPELLFAMILY_WARLOCK:
1502 // Life Tap
1503 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000040000))
1505 // In 303 exist spirit depend
1506 uint32 spirit = uint32(m_caster->GetStat(STAT_SPIRIT));
1507 switch (m_spellInfo->Id)
1509 case 1454: damage+=spirit; break;
1510 case 1455: damage+=spirit*15/10; break;
1511 case 1456: damage+=spirit*2; break;
1512 case 11687: damage+=spirit*25/10; break;
1513 case 11688:
1514 case 11689:
1515 case 27222:
1516 case 57946: damage+=spirit*3; break;
1517 default:
1518 sLog.outError("Spell::EffectDummy: %u Life Tap need set spirit multipler", m_spellInfo->Id);
1519 return;
1521 // Think its not need (also need remove Life Tap from SpellDamageBonus or add new value)
1522 // damage = m_caster->SpellDamageBonus(m_caster, m_spellInfo,uint32(damage > 0 ? damage : 0), SPELL_DIRECT_DAMAGE);
1523 if (unitTarget && (int32(unitTarget->GetHealth()) > damage))
1525 // Shouldn't Appear in Combat Log
1526 unitTarget->ModifyHealth(-damage);
1528 int32 mana = damage;
1529 // Improved Life Tap mod
1530 Unit::AuraList const& auraDummy = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
1531 for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr != auraDummy.end(); ++itr)
1533 if((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (*itr)->GetSpellProto()->SpellIconID == 208)
1534 mana = ((*itr)->GetModifier()->m_amount + 100)* mana / 100;
1536 m_caster->CastCustomSpell(unitTarget, 31818, &mana, NULL, NULL, true);
1538 // Mana Feed
1539 int32 manaFeedVal = 0;
1540 Unit::AuraList const& mod = m_caster->GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER);
1541 for(Unit::AuraList::const_iterator itr = mod.begin(); itr != mod.end(); ++itr)
1543 if((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (*itr)->GetSpellProto()->SpellIconID == 1982)
1544 manaFeedVal+= (*itr)->GetModifier()->m_amount;
1546 if (manaFeedVal > 0)
1548 manaFeedVal = manaFeedVal * mana / 100;
1549 m_caster->CastCustomSpell(m_caster, 32553, &manaFeedVal, NULL, NULL, true, NULL);
1552 else
1553 SendCastResult(SPELL_FAILED_FIZZLE);
1554 return;
1556 break;
1557 case SPELLFAMILY_PRIEST:
1558 // Penance
1559 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0080000000000000))
1561 if (!unitTarget)
1562 return;
1564 int hurt = 0;
1565 int heal = 0;
1566 switch(m_spellInfo->Id)
1568 case 47540: hurt = 47758; heal = 47757; break;
1569 case 53005: hurt = 53001; heal = 52986; break;
1570 case 53006: hurt = 53002; heal = 52987; break;
1571 case 53007: hurt = 53003; heal = 52988; break;
1572 default:
1573 sLog.outError("Spell::EffectDummy: Spell %u Penance need set correct heal/damage spell", m_spellInfo->Id);
1574 return;
1576 if (m_caster->IsFriendlyTo(unitTarget))
1577 m_caster->CastSpell(unitTarget, heal, true, 0);
1578 else
1579 m_caster->CastSpell(unitTarget, hurt, true, 0);
1580 return;
1582 break;
1583 case SPELLFAMILY_DRUID:
1584 // Starfall
1585 if (m_spellInfo->SpellFamilyFlags2 & 0x00000100)
1587 //Shapeshifting into an animal form or mounting cancels the effect.
1588 if(m_caster->GetCreatureType() == CREATURE_TYPE_BEAST || m_caster->IsMounted())
1590 if(m_triggeredByAuraSpell)
1591 m_caster->RemoveAurasDueToSpell(m_triggeredByAuraSpell->Id);
1592 return;
1595 //Any effect which causes you to lose control of your character will supress the starfall effect.
1596 if (m_caster->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_FLEEING | UNIT_STAT_ROOT | UNIT_STAT_CONFUSED))
1597 return;
1599 switch(m_spellInfo->Id)
1601 case 50286: m_caster->CastSpell(unitTarget, 50288, true); return;
1602 case 53196: m_caster->CastSpell(unitTarget, 53191, true); return;
1603 case 53197: m_caster->CastSpell(unitTarget, 53194, true); return;
1604 case 53198: m_caster->CastSpell(unitTarget, 53195, true); return;
1605 default:
1606 sLog.outError("Spell::EffectDummy: Unhandeled Starfall spell rank %u",m_spellInfo->Id);
1607 return;
1610 break;
1611 case SPELLFAMILY_ROGUE:
1612 switch(m_spellInfo->Id )
1614 case 5938: // Shiv
1616 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1617 return;
1619 Player *pCaster = ((Player*)m_caster);
1621 Item *item = pCaster->GetWeaponForAttack(OFF_ATTACK);
1622 if (!item)
1623 return;
1625 // all poison enchantments is temporary
1626 uint32 enchant_id = item->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT);
1627 if (!enchant_id)
1628 return;
1630 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
1631 if (!pEnchant)
1632 return;
1634 for (int s=0;s<3;s++)
1636 if (pEnchant->type[s]!=ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL)
1637 continue;
1639 SpellEntry const* combatEntry = sSpellStore.LookupEntry(pEnchant->spellid[s]);
1640 if (!combatEntry || combatEntry->Dispel != DISPEL_POISON)
1641 continue;
1643 m_caster->CastSpell(unitTarget, combatEntry, true, item);
1646 m_caster->CastSpell(unitTarget, 5940, true);
1647 return;
1649 case 14185: // Preparation
1651 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1652 return;
1654 //immediately finishes the cooldown on certain Rogue abilities
1655 const SpellCooldowns& cm = ((Player *)m_caster)->GetSpellCooldownMap();
1656 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1658 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1660 if (spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && (spellInfo->SpellFamilyFlags & UI64LIT(0x0000024000000860)))
1661 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first,true);
1662 else
1663 ++itr;
1665 return;
1667 case 31231: // Cheat Death
1669 m_caster->CastSpell(m_caster, 45182, true);
1670 return;
1673 break;
1674 case SPELLFAMILY_HUNTER:
1675 // Steady Shot
1676 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x100000000))
1678 if (!unitTarget || !unitTarget->isAlive())
1679 return;
1681 bool found = false;
1683 // check dazed affect
1684 Unit::AuraList const& decSpeedList = unitTarget->GetAurasByType(SPELL_AURA_MOD_DECREASE_SPEED);
1685 for(Unit::AuraList::const_iterator iter = decSpeedList.begin(); iter != decSpeedList.end(); ++iter)
1687 if ((*iter)->GetSpellProto()->SpellIconID==15 && (*iter)->GetSpellProto()->Dispel==0)
1689 found = true;
1690 break;
1694 if (found)
1695 m_damage+= damage;
1696 return;
1699 // Disengage
1700 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000400000000000))
1702 Unit* target = unitTarget;
1703 uint32 spellid;
1704 switch(m_spellInfo->Id)
1706 case 57635: spellid = 57636; break; // one from creature cases
1707 case 61507: spellid = 61508; break; // one from creature cases
1708 default:
1709 sLog.outError("Spell %u not handled propertly in EffectDummy(Disengage)",m_spellInfo->Id);
1710 return;
1712 if (!target || !target->isAlive())
1713 return;
1714 m_caster->CastSpell(target,spellid,true,NULL);
1717 switch(m_spellInfo->Id)
1719 case 23989: // Readiness talent
1721 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1722 return;
1724 //immediately finishes the cooldown for hunter abilities
1725 const SpellCooldowns& cm = ((Player*)m_caster)->GetSpellCooldownMap();
1726 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1728 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1730 if (spellInfo->SpellFamilyName == SPELLFAMILY_HUNTER && spellInfo->Id != 23989 && GetSpellRecoveryTime(spellInfo) > 0 )
1731 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first,true);
1732 else
1733 ++itr;
1735 return;
1737 case 37506: // Scatter Shot
1739 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1740 return;
1742 // break Auto Shot and autohit
1743 m_caster->InterruptSpell(CURRENT_AUTOREPEAT_SPELL);
1744 m_caster->AttackStop();
1745 ((Player*)m_caster)->SendAttackSwingCancelAttack();
1746 return;
1748 // Last Stand
1749 case 53478:
1751 if (!unitTarget)
1752 return;
1753 int32 healthModSpellBasePoints0 = int32(unitTarget->GetMaxHealth() * 0.3);
1754 unitTarget->CastCustomSpell(unitTarget, 53479, &healthModSpellBasePoints0, NULL, NULL, true, NULL);
1755 return;
1757 // Master's Call
1758 case 53271:
1760 Pet* pet = m_caster->GetPet();
1761 if (!pet || !unitTarget)
1762 return;
1764 pet->CastSpell(unitTarget, m_spellInfo->CalculateSimpleValue(i), true);
1765 return;
1768 break;
1769 case SPELLFAMILY_PALADIN:
1770 switch(m_spellInfo->SpellIconID)
1772 case 156: // Holy Shock
1774 if (!unitTarget)
1775 return;
1777 int hurt = 0;
1778 int heal = 0;
1780 switch(m_spellInfo->Id)
1782 case 20473: hurt = 25912; heal = 25914; break;
1783 case 20929: hurt = 25911; heal = 25913; break;
1784 case 20930: hurt = 25902; heal = 25903; break;
1785 case 27174: hurt = 27176; heal = 27175; break;
1786 case 33072: hurt = 33073; heal = 33074; break;
1787 case 48824: hurt = 48822; heal = 48820; break;
1788 case 48825: hurt = 48823; heal = 48821; break;
1789 default:
1790 sLog.outError("Spell::EffectDummy: Spell %u not handled in HS",m_spellInfo->Id);
1791 return;
1794 if (m_caster->IsFriendlyTo(unitTarget))
1795 m_caster->CastSpell(unitTarget, heal, true, 0);
1796 else
1797 m_caster->CastSpell(unitTarget, hurt, true, 0);
1799 return;
1801 case 561: // Judgement of command
1803 if (!unitTarget)
1804 return;
1806 uint32 spell_id = m_currentBasePoints[i]+1;
1807 SpellEntry const* spell_proto = sSpellStore.LookupEntry(spell_id);
1808 if (!spell_proto)
1809 return;
1811 m_caster->CastSpell(unitTarget, spell_proto, true, NULL);
1812 return;
1816 switch(m_spellInfo->Id)
1818 // Judgement of Righteousness (0.2*$AP+0.32*$SPH) holy added in spellDamagBonus
1819 case 20187:
1821 if (!unitTarget)
1822 return;
1823 m_damage+=int32(0.2f*m_caster->GetTotalAttackPowerValue(BASE_ATTACK));
1824 return;
1826 case 31789: // Righteous Defense (step 1)
1828 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1830 SendCastResult(SPELL_FAILED_TARGET_AFFECTING_COMBAT);
1831 return;
1834 // 31989 -> dummy effect (step 1) + dummy effect (step 2) -> 31709 (taunt like spell for each target)
1835 Unit* friendTarget = !unitTarget || unitTarget->IsFriendlyTo(m_caster) ? unitTarget : unitTarget->getVictim();
1836 if (friendTarget)
1838 Player* player = friendTarget->GetCharmerOrOwnerPlayerOrPlayerItself();
1839 if (!player || !player->IsInSameRaidWith((Player*)m_caster))
1840 friendTarget = NULL;
1843 // non-standard cast requirement check
1844 if (!friendTarget || friendTarget->getAttackers().empty())
1846 ((Player*)m_caster)->RemoveSpellCooldown(m_spellInfo->Id,true);
1847 SendCastResult(SPELL_FAILED_TARGET_AFFECTING_COMBAT);
1848 return;
1851 // Righteous Defense (step 2) (in old version 31980 dummy effect)
1852 // Clear targets for eff 1
1853 for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit)
1854 ihit->effectMask &= ~(1<<1);
1856 // not empty (checked), copy
1857 Unit::AttackerSet attackers = friendTarget->getAttackers();
1859 // selected from list 3
1860 for(int i = 0; i < std::min(size_t(3),attackers.size()); ++i)
1862 Unit::AttackerSet::iterator aItr = attackers.begin();
1863 std::advance(aItr, rand() % attackers.size());
1864 AddUnitTarget((*aItr), 1);
1865 attackers.erase(aItr);
1868 // now let next effect cast spell at each target.
1869 return;
1871 case 37877: // Blessing of Faith
1873 if (!unitTarget)
1874 return;
1876 uint32 spell_id = 0;
1877 switch(unitTarget->getClass())
1879 case CLASS_DRUID: spell_id = 37878; break;
1880 case CLASS_PALADIN: spell_id = 37879; break;
1881 case CLASS_PRIEST: spell_id = 37880; break;
1882 case CLASS_SHAMAN: spell_id = 37881; break;
1883 default: return; // ignore for not healing classes
1886 m_caster->CastSpell(m_caster, spell_id, true);
1887 return;
1890 break;
1891 case SPELLFAMILY_SHAMAN:
1892 // Cleansing Totem
1893 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000004000000)) && m_spellInfo->SpellIconID==1673)
1895 if (unitTarget)
1896 m_caster->CastSpell(unitTarget, 52025, true);
1897 return;
1899 // Healing Stream Totem
1900 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000002000))
1902 if (unitTarget)
1903 m_caster->CastCustomSpell(unitTarget, 52042, &damage, 0, 0, true, 0, 0, m_originalCasterGUID);
1904 return;
1906 // Mana Spring Totem
1907 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000004000))
1909 if (!unitTarget || unitTarget->getPowerType()!=POWER_MANA)
1910 return;
1911 m_caster->CastCustomSpell(unitTarget, 52032, &damage, 0, 0, true, 0, 0, m_originalCasterGUID);
1912 return;
1914 if (m_spellInfo->Id == 39610) // Mana Tide Totem effect
1916 if (!unitTarget || unitTarget->getPowerType() != POWER_MANA)
1917 return;
1918 // Glyph of Mana Tide
1919 if (Unit *owner = m_caster->GetOwner())
1920 if (Aura *dummy = owner->GetDummyAura(55441))
1921 damage+=dummy->GetModifier()->m_amount;
1922 // Regenerate 6% of Total Mana Every 3 secs
1923 int32 EffectBasePoints0 = unitTarget->GetMaxPower(POWER_MANA) * damage / 100;
1924 m_caster->CastCustomSpell(unitTarget, 39609, &EffectBasePoints0, NULL, NULL, true, NULL, NULL, m_originalCasterGUID);
1925 return;
1927 // Lava Lash
1928 if (m_spellInfo->SpellFamilyFlags2 & 0x00000004)
1930 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1931 return;
1932 Item *item = ((Player*)m_caster)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND);
1933 if (item)
1935 // Damage is increased if your off-hand weapon is enchanted with Flametongue.
1936 Unit::AuraList const& auraDummy = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
1937 for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr != auraDummy.end(); ++itr)
1939 if ((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_SHAMAN &&
1940 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000200000)) &&
1941 (*itr)->GetCastItemGUID() == item->GetGUID())
1943 m_damage += m_damage * damage / 100;
1944 return;
1948 return;
1950 break;
1951 case SPELLFAMILY_DEATHKNIGHT:
1952 // Death Coil
1953 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x002000))
1955 if (m_caster->IsFriendlyTo(unitTarget))
1957 if (unitTarget->GetCreatureType() != CREATURE_TYPE_UNDEAD)
1958 return;
1960 int32 bp = damage * 1.5f;
1961 m_caster->CastCustomSpell(unitTarget, 47633, &bp, NULL, NULL, true);
1963 else
1965 int32 bp = damage;
1966 m_caster->CastCustomSpell(unitTarget, 47632, &bp, NULL, NULL, true);
1968 return;
1970 // Hungering Cold
1971 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000100000000000))
1973 m_caster->CastSpell(m_caster, 51209, true);
1974 return;
1976 // Death Strike
1977 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000010))
1979 uint32 count = 0;
1980 Unit::AuraMap const& auras = unitTarget->GetAuras();
1981 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
1983 if (itr->second->GetSpellProto()->Dispel == DISPEL_DISEASE &&
1984 itr->second->GetCasterGUID() == m_caster->GetGUID() &&
1985 IsSpellLastAuraEffect(itr->second->GetSpellProto(), itr->second->GetEffIndex()))
1987 ++count;
1988 // max. 15%
1989 if (count == 3)
1990 break;
1994 int32 bp = count * m_caster->GetMaxHealth() * m_spellInfo->DmgMultiplier[0] / 100;
1995 m_caster->CastCustomSpell(m_caster, 45470, &bp, NULL, NULL, true);
1996 return;
1998 break;
2001 // pet auras
2002 if (PetAura const* petSpell = sSpellMgr.GetPetAura(m_spellInfo->Id, i))
2004 m_caster->AddPetAura(petSpell);
2005 return;
2008 // Script based implementation. Must be used only for not good for implementation in core spell effects
2009 // So called only for not proccessed cases
2010 if (gameObjTarget)
2011 Script->EffectDummyGameObj(m_caster, m_spellInfo->Id, i, gameObjTarget);
2012 else if (unitTarget && unitTarget->GetTypeId()==TYPEID_UNIT)
2013 Script->EffectDummyCreature(m_caster, m_spellInfo->Id, i, (Creature*)unitTarget);
2014 else if (itemTarget)
2015 Script->EffectDummyItem(m_caster, m_spellInfo->Id, i, itemTarget);
2018 void Spell::EffectTriggerSpellWithValue(uint32 i)
2020 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2022 // normal case
2023 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2025 if(!spellInfo)
2027 sLog.outError("EffectTriggerSpellWithValue of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2028 return;
2031 int32 bp = damage;
2032 m_caster->CastCustomSpell(unitTarget,triggered_spell_id,&bp,&bp,&bp,true,NULL,NULL,m_originalCasterGUID);
2035 void Spell::EffectTriggerRitualOfSummoning(uint32 i)
2037 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2038 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2040 if(!spellInfo)
2042 sLog.outError("EffectTriggerRitualOfSummoning of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2043 return;
2046 finish();
2048 m_caster->CastSpell(unitTarget,spellInfo,false);
2051 void Spell::EffectForceCast(uint32 i)
2053 if( !unitTarget )
2054 return;
2056 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2058 // normal case
2059 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2061 if(!spellInfo)
2063 sLog.outError("EffectForceCast of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2064 return;
2067 unitTarget->CastSpell(unitTarget, spellInfo, true, NULL, NULL, m_originalCasterGUID);
2070 void Spell::EffectTriggerSpell(uint32 effIndex)
2072 // only unit case known
2073 if (!unitTarget)
2075 if(gameObjTarget || itemTarget)
2076 sLog.outError("Spell::EffectTriggerSpell (Spell: %u): Unsupported non-unit case!",m_spellInfo->Id);
2077 return;
2080 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[effIndex];
2082 // special cases
2083 switch(triggered_spell_id)
2085 // Vanish (not exist)
2086 case 18461:
2088 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2089 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
2090 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STALKED);
2092 // if this spell is given to NPC it must handle rest by it's own AI
2093 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
2094 return;
2096 // get highest rank of the Stealth spell
2097 uint32 spellId = 0;
2098 const PlayerSpellMap& sp_list = ((Player*)unitTarget)->GetSpellMap();
2099 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2101 // only highest rank is shown in spell book, so simply check if shown in spell book
2102 if (!itr->second->active || itr->second->disabled || itr->second->state == PLAYERSPELL_REMOVED)
2103 continue;
2105 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2106 if (!spellInfo)
2107 continue;
2109 if (spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE_STEALTH)
2111 spellId = spellInfo->Id;
2112 break;
2116 // no Stealth spell found
2117 if (!spellId)
2118 return;
2120 // reset cooldown on it if needed
2121 if (((Player*)unitTarget)->HasSpellCooldown(spellId))
2122 ((Player*)unitTarget)->RemoveSpellCooldown(spellId);
2124 m_caster->CastSpell(unitTarget, spellId, true);
2125 return;
2127 // just skip
2128 case 23770: // Sayge's Dark Fortune of *
2129 // not exist, common cooldown can be implemented in scripts if need.
2130 return;
2131 // Brittle Armor - (need add max stack of 24575 Brittle Armor)
2132 case 29284:
2134 // Brittle Armor
2135 SpellEntry const* spell = sSpellStore.LookupEntry(24575);
2136 if (!spell)
2137 return;
2139 for (int j=0; j < spell->StackAmount; ++j)
2140 m_caster->CastSpell(unitTarget, spell->Id, true, m_CastItem, NULL, m_originalCasterGUID);
2141 return;
2143 // Mercurial Shield - (need add max stack of 26464 Mercurial Shield)
2144 case 29286:
2146 // Mercurial Shield
2147 SpellEntry const* spell = sSpellStore.LookupEntry(26464);
2148 if (!spell)
2149 return;
2151 for (int j=0; j < spell->StackAmount; ++j)
2152 m_caster->CastSpell(unitTarget, spell->Id, true, m_CastItem, NULL, m_originalCasterGUID);
2153 return;
2155 // Righteous Defense
2156 case 31980:
2158 m_caster->CastSpell(unitTarget, 31790, true, m_CastItem, NULL, m_originalCasterGUID);
2159 return;
2161 // Cloak of Shadows
2162 case 35729:
2164 Unit::AuraMap& Auras = unitTarget->GetAuras();
2165 for(Unit::AuraMap::iterator iter = Auras.begin(); iter != Auras.end(); ++iter)
2167 // remove all harmful spells on you...
2168 if( // ignore positive and passive auras
2169 !iter->second->IsPositive() && !iter->second->IsPassive() &&
2170 // ignore physical auras
2171 (GetSpellSchoolMask(iter->second->GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)==0 )
2173 m_caster->RemoveAurasDueToSpell(iter->second->GetSpellProto()->Id);
2174 iter = Auras.begin();
2177 return;
2179 // Priest Shadowfiend (34433) need apply mana gain trigger aura on pet
2180 case 41967:
2182 if (Unit *pet = unitTarget->GetPet())
2183 pet->CastSpell(pet, 28305, true);
2184 return;
2188 // normal case
2189 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2190 if (!spellInfo)
2192 sLog.outError("EffectTriggerSpell of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2193 return;
2196 // select formal caster for triggered spell
2197 Unit* caster = m_caster;
2199 // some triggered spells require specific equipment
2200 if (spellInfo->EquippedItemClass >=0 && m_caster->GetTypeId()==TYPEID_PLAYER)
2202 // main hand weapon required
2203 if (spellInfo->AttributesEx3 & SPELL_ATTR_EX3_MAIN_HAND)
2205 Item* item = ((Player*)m_caster)->GetWeaponForAttack(BASE_ATTACK, true, false);
2207 // skip spell if no weapon in slot or broken
2208 if (!item)
2209 return;
2211 // skip spell if weapon not fit to triggered spell
2212 if (!item->IsFitToSpellRequirements(spellInfo))
2213 return;
2216 // offhand hand weapon required
2217 if (spellInfo->AttributesEx3 & SPELL_ATTR_EX3_REQ_OFFHAND)
2219 Item* item = ((Player*)m_caster)->GetWeaponForAttack(OFF_ATTACK, true, false);
2221 // skip spell if no weapon in slot or broken
2222 if (!item)
2223 return;
2225 // skip spell if weapon not fit to triggered spell
2226 if (!item->IsFitToSpellRequirements(spellInfo))
2227 return;
2230 else
2232 // Note: not exist spells with weapon req. and IsSpellHaveCasterSourceTargets == true
2233 // so this just for speedup places in else
2234 caster = IsSpellWithCasterSourceTargetsOnly(spellInfo) ? unitTarget : m_caster;
2237 caster->CastSpell(unitTarget,spellInfo,true,NULL,NULL,m_originalCasterGUID);
2240 void Spell::EffectTriggerMissileSpell(uint32 effect_idx)
2242 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[effect_idx];
2244 // normal case
2245 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2247 if(!spellInfo)
2249 sLog.outError("EffectTriggerMissileSpell of spell %u (eff: %u): triggering unknown spell id %u",
2250 m_spellInfo->Id,effect_idx,triggered_spell_id);
2251 return;
2254 if (m_CastItem)
2255 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id);
2257 m_caster->CastSpell(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, spellInfo, true, m_CastItem, 0, m_originalCasterGUID);
2260 void Spell::EffectJump(uint32 i)
2262 if(m_caster->isInFlight())
2263 return;
2265 // Init dest coordinates
2266 float x,y,z,o;
2267 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
2269 x = m_targets.m_destX;
2270 y = m_targets.m_destY;
2271 z = m_targets.m_destZ;
2273 if(m_spellInfo->EffectImplicitTargetA[i] == TARGET_BEHIND_VICTIM)
2275 // explicit cast data from client or server-side cast
2276 // some spell at client send caster
2277 Unit* pTarget = NULL;
2278 if(m_targets.getUnitTarget() && m_targets.getUnitTarget()!=m_caster)
2279 pTarget = m_targets.getUnitTarget();
2280 else if(unitTarget->getVictim())
2281 pTarget = m_caster->getVictim();
2282 else if(m_caster->GetTypeId() == TYPEID_PLAYER)
2283 pTarget = ObjectAccessor::GetUnit(*m_caster, ((Player*)m_caster)->GetSelection());
2285 o = pTarget ? pTarget->GetOrientation() : m_caster->GetOrientation();
2287 else
2288 o = m_caster->GetOrientation();
2290 else if(unitTarget)
2292 unitTarget->GetContactPoint(m_caster,x,y,z,CONTACT_DISTANCE);
2293 o = m_caster->GetOrientation();
2295 else if(gameObjTarget)
2297 gameObjTarget->GetContactPoint(m_caster,x,y,z,CONTACT_DISTANCE);
2298 o = m_caster->GetOrientation();
2300 else
2302 sLog.outError( "Spell::EffectJump - unsupported target mode for spell ID %u", m_spellInfo->Id );
2303 return;
2306 m_caster->NearTeleportTo(x, y, z, o, true);
2309 void Spell::EffectTeleportUnits(uint32 i)
2311 if(!unitTarget || unitTarget->isInFlight())
2312 return;
2314 switch (m_spellInfo->EffectImplicitTargetB[i])
2316 case TARGET_INNKEEPER_COORDINATES:
2318 // Only players can teleport to innkeeper
2319 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
2320 return;
2322 ((Player*)unitTarget)->TeleportToHomebind(unitTarget==m_caster ? TELE_TO_SPELL : 0);
2323 return;
2325 case TARGET_AREAEFFECT_INSTANT: // in all cases first TARGET_TABLE_X_Y_Z_COORDINATES
2326 case TARGET_TABLE_X_Y_Z_COORDINATES:
2328 SpellTargetPosition const* st = sSpellMgr.GetSpellTargetPosition(m_spellInfo->Id);
2329 if(!st)
2331 sLog.outError( "Spell::EffectTeleportUnits - unknown Teleport coordinates for spell ID %u", m_spellInfo->Id );
2332 return;
2335 if(st->target_mapId==unitTarget->GetMapId())
2336 unitTarget->NearTeleportTo(st->target_X,st->target_Y,st->target_Z,st->target_Orientation,unitTarget==m_caster);
2337 else if(unitTarget->GetTypeId()==TYPEID_PLAYER)
2338 ((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);
2339 break;
2341 case TARGET_BEHIND_VICTIM:
2343 Unit *pTarget = NULL;
2345 // explicit cast data from client or server-side cast
2346 // some spell at client send caster
2347 if(m_targets.getUnitTarget() && m_targets.getUnitTarget()!=unitTarget)
2348 pTarget = m_targets.getUnitTarget();
2349 else if(unitTarget->getVictim())
2350 pTarget = unitTarget->getVictim();
2351 else if(unitTarget->GetTypeId() == TYPEID_PLAYER)
2352 pTarget = ObjectAccessor::GetUnit(*unitTarget, ((Player*)unitTarget)->GetSelection());
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 = pTarget ? pTarget->GetOrientation() : unitTarget->GetOrientation();
2359 unitTarget->NearTeleportTo(x,y,z,orientation,unitTarget==m_caster);
2360 return;
2362 default:
2364 // If not exist data for dest location - return
2365 if(!(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION))
2367 sLog.outError( "Spell::EffectTeleportUnits - unknown EffectImplicitTargetB[%u] = %u for spell ID %u", i, m_spellInfo->EffectImplicitTargetB[i], m_spellInfo->Id );
2368 return;
2370 // Init dest coordinates
2371 float x = m_targets.m_destX;
2372 float y = m_targets.m_destY;
2373 float z = m_targets.m_destZ;
2374 float orientation = unitTarget->GetOrientation();
2375 // Teleport
2376 unitTarget->NearTeleportTo(x,y,z,orientation,unitTarget==m_caster);
2377 return;
2381 // post effects for TARGET_TABLE_X_Y_Z_COORDINATES
2382 switch ( m_spellInfo->Id )
2384 // Dimensional Ripper - Everlook
2385 case 23442:
2387 int32 r = irand(0, 119);
2388 if ( r >= 70 ) // 7/12 success
2390 if ( r < 100 ) // 4/12 evil twin
2391 m_caster->CastSpell(m_caster, 23445, true);
2392 else // 1/12 fire
2393 m_caster->CastSpell(m_caster, 23449, true);
2395 return;
2397 // Ultrasafe Transporter: Toshley's Station
2398 case 36941:
2400 if ( roll_chance_i(50) ) // 50% success
2402 int32 rand_eff = urand(1, 7);
2403 switch ( rand_eff )
2405 case 1:
2406 // soul split - evil
2407 m_caster->CastSpell(m_caster, 36900, true);
2408 break;
2409 case 2:
2410 // soul split - good
2411 m_caster->CastSpell(m_caster, 36901, true);
2412 break;
2413 case 3:
2414 // Increase the size
2415 m_caster->CastSpell(m_caster, 36895, true);
2416 break;
2417 case 4:
2418 // Decrease the size
2419 m_caster->CastSpell(m_caster, 36893, true);
2420 break;
2421 case 5:
2422 // Transform
2424 if (((Player*)m_caster)->GetTeam() == ALLIANCE )
2425 m_caster->CastSpell(m_caster, 36897, true);
2426 else
2427 m_caster->CastSpell(m_caster, 36899, true);
2428 break;
2430 case 6:
2431 // chicken
2432 m_caster->CastSpell(m_caster, 36940, true);
2433 break;
2434 case 7:
2435 // evil twin
2436 m_caster->CastSpell(m_caster, 23445, true);
2437 break;
2440 return;
2442 // Dimensional Ripper - Area 52
2443 case 36890:
2445 if ( roll_chance_i(50) ) // 50% success
2447 int32 rand_eff = urand(1, 4);
2448 switch ( rand_eff )
2450 case 1:
2451 // soul split - evil
2452 m_caster->CastSpell(m_caster, 36900, true);
2453 break;
2454 case 2:
2455 // soul split - good
2456 m_caster->CastSpell(m_caster, 36901, true);
2457 break;
2458 case 3:
2459 // Increase the size
2460 m_caster->CastSpell(m_caster, 36895, true);
2461 break;
2462 case 4:
2463 // Transform
2465 if (((Player*)m_caster)->GetTeam() == ALLIANCE )
2466 m_caster->CastSpell(m_caster, 36897, true);
2467 else
2468 m_caster->CastSpell(m_caster, 36899, true);
2469 break;
2473 return;
2478 void Spell::EffectApplyAura(uint32 i)
2480 if(!unitTarget)
2481 return;
2483 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
2484 if ( (!unitTarget->isAlive() && !(IsDeathOnlySpell(m_spellInfo) || IsDeathPersistentSpell(m_spellInfo))) &&
2485 (unitTarget->GetTypeId() != TYPEID_PLAYER || !((Player*)unitTarget)->GetSession()->PlayerLoading()) )
2486 return;
2488 Unit* caster = m_originalCaster ? m_originalCaster : m_caster;
2489 if(!caster)
2490 return;
2492 sLog.outDebug("Spell: Aura is: %u", m_spellInfo->EffectApplyAuraName[i]);
2494 Aura* Aur = CreateAura(m_spellInfo, i, &m_currentBasePoints[i], unitTarget, caster, m_CastItem);
2496 // Now Reduce spell duration using data received at spell hit
2497 int32 duration = Aur->GetAuraMaxDuration();
2498 int32 limitduration = GetDiminishingReturnsLimitDuration(m_diminishGroup,m_spellInfo);
2499 unitTarget->ApplyDiminishingToDuration(m_diminishGroup, duration, m_caster, m_diminishLevel,limitduration);
2500 Aur->setDiminishGroup(m_diminishGroup);
2502 // if Aura removed and deleted, do not continue.
2503 if(duration== 0 && !(Aur->IsPermanent()))
2505 delete Aur;
2506 return;
2509 if(duration != Aur->GetAuraMaxDuration())
2511 Aur->SetAuraMaxDuration(duration);
2512 Aur->SetAuraDuration(duration);
2515 unitTarget->AddAura(Aur);
2518 void Spell::EffectUnlearnSpecialization( uint32 i )
2520 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
2521 return;
2523 Player *_player = (Player*)unitTarget;
2524 uint32 spellToUnlearn = m_spellInfo->EffectTriggerSpell[i];
2526 _player->removeSpell(spellToUnlearn);
2528 sLog.outDebug( "Spell: Player %u has unlearned spell %u from NpcGUID: %u", _player->GetGUIDLow(), spellToUnlearn, m_caster->GetGUIDLow() );
2531 void Spell::EffectPowerDrain(uint32 i)
2533 if(m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2534 return;
2536 Powers drain_power = Powers(m_spellInfo->EffectMiscValue[i]);
2538 if(!unitTarget)
2539 return;
2540 if(!unitTarget->isAlive())
2541 return;
2542 if(unitTarget->getPowerType() != drain_power)
2543 return;
2544 if(damage < 0)
2545 return;
2547 uint32 curPower = unitTarget->GetPower(drain_power);
2549 //add spell damage bonus
2550 damage=m_caster->SpellDamageBonus(unitTarget,m_spellInfo,uint32(damage),SPELL_DIRECT_DAMAGE);
2552 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
2553 uint32 power = damage;
2554 if (drain_power == POWER_MANA)
2555 power -= unitTarget->GetSpellCritDamageReduction(power);
2557 int32 new_damage;
2558 if(curPower < power)
2559 new_damage = curPower;
2560 else
2561 new_damage = power;
2563 unitTarget->ModifyPower(drain_power,-new_damage);
2565 // Don`t restore from self drain
2566 if(drain_power == POWER_MANA && m_caster != unitTarget)
2568 float manaMultiplier = m_spellInfo->EffectMultipleValue[i];
2569 if(manaMultiplier==0)
2570 manaMultiplier = 1;
2572 if(Player *modOwner = m_caster->GetSpellModOwner())
2573 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, manaMultiplier);
2575 int32 gain = int32(new_damage * manaMultiplier);
2577 m_caster->EnergizeBySpell(m_caster, m_spellInfo->Id, gain, POWER_MANA);
2581 void Spell::EffectSendEvent(uint32 EffectIndex)
2584 we do not handle a flag dropping or clicking on flag in battleground by sendevent system
2586 sLog.outDebug("Spell ScriptStart %u for spellid %u in EffectSendEvent ", m_spellInfo->EffectMiscValue[EffectIndex], m_spellInfo->Id);
2587 m_caster->GetMap()->ScriptsStart(sEventScripts, m_spellInfo->EffectMiscValue[EffectIndex], m_caster, focusObject);
2590 void Spell::EffectPowerBurn(uint32 i)
2592 if (m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2593 return;
2595 Powers powertype = Powers(m_spellInfo->EffectMiscValue[i]);
2597 if (!unitTarget)
2598 return;
2599 if (!unitTarget->isAlive())
2600 return;
2601 if (unitTarget->getPowerType()!=powertype)
2602 return;
2603 if (damage < 0)
2604 return;
2606 // burn x% of target's mana, up to maximum of 2x% of caster's mana (Mana Burn)
2607 if (m_spellInfo->ManaCostPercentage)
2609 uint32 maxdamage = m_caster->GetMaxPower(powertype) * damage * 2 / 100;
2610 damage = unitTarget->GetMaxPower(powertype) * damage / 100;
2611 if(damage > maxdamage) damage = maxdamage;
2614 int32 curPower = int32(unitTarget->GetPower(powertype));
2616 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
2617 uint32 power = damage;
2618 if (powertype == POWER_MANA)
2619 power -= unitTarget->GetSpellCritDamageReduction(power);
2621 int32 new_damage = (curPower < power) ? curPower : power;
2623 unitTarget->ModifyPower(powertype, -new_damage);
2624 float multiplier = m_spellInfo->EffectMultipleValue[i];
2626 if (Player *modOwner = m_caster->GetSpellModOwner())
2627 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
2629 new_damage = int32(new_damage * multiplier);
2630 m_damage += new_damage;
2633 void Spell::EffectHeal( uint32 /*i*/ )
2635 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2637 // Try to get original caster
2638 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2640 // Skip if m_originalCaster not available
2641 if (!caster)
2642 return;
2644 int32 addhealth = damage;
2646 // Vessel of the Naaru (Vial of the Sunwell trinket)
2647 if (m_spellInfo->Id == 45064)
2649 // Amount of heal - depends from stacked Holy Energy
2650 int damageAmount = 0;
2651 Unit::AuraList const& mDummyAuras = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
2652 for(Unit::AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i)
2653 if ((*i)->GetId() == 45062)
2654 damageAmount+=(*i)->GetModifier()->m_amount;
2655 if (damageAmount)
2656 m_caster->RemoveAurasDueToSpell(45062);
2658 addhealth += damageAmount;
2660 // Death Pact (percent heal)
2661 else if (m_spellInfo->Id==48743)
2662 addhealth = addhealth * unitTarget->GetMaxHealth() / 100;
2663 // Swiftmend - consumes Regrowth or Rejuvenation
2664 else if (m_spellInfo->TargetAuraState == AURA_STATE_SWIFTMEND && unitTarget->HasAuraState(AURA_STATE_SWIFTMEND))
2666 Unit::AuraList const& RejorRegr = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_HEAL);
2667 // find most short by duration
2668 Aura *targetAura = NULL;
2669 for(Unit::AuraList::const_iterator i = RejorRegr.begin(); i != RejorRegr.end(); ++i)
2671 if ((*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2672 // Regrowth or Rejuvenation 0x40 | 0x10
2673 ((*i)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000050)))
2675 if (!targetAura || (*i)->GetAuraDuration() < targetAura->GetAuraDuration())
2676 targetAura = *i;
2680 if (!targetAura)
2682 sLog.outError("Target (GUID: %u TypeId: %u) has aurastate AURA_STATE_SWIFTMEND but no matching aura.", unitTarget->GetGUIDLow(), unitTarget->GetTypeId());
2683 return;
2685 int idx = 0;
2686 while(idx < 3)
2688 if(targetAura->GetSpellProto()->EffectApplyAuraName[idx] == SPELL_AURA_PERIODIC_HEAL)
2689 break;
2690 idx++;
2693 int32 tickheal = caster->SpellHealingBonus(unitTarget, targetAura->GetSpellProto(), targetAura->GetModifier()->m_amount, DOT);
2694 int32 tickcount = GetSpellDuration(targetAura->GetSpellProto()) / targetAura->GetSpellProto()->EffectAmplitude[idx];
2696 // Glyph of Swiftmend
2697 if (!caster->HasAura(54824))
2698 unitTarget->RemoveAurasDueToSpell(targetAura->GetId());
2700 addhealth += tickheal * tickcount;
2702 else
2703 addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, addhealth, HEAL);
2705 m_healing+=addhealth;
2709 void Spell::EffectHealPct( uint32 /*i*/ )
2711 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2713 // Try to get original caster
2714 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2716 // Skip if m_originalCaster not available
2717 if (!caster)
2718 return;
2720 uint32 addhealth = unitTarget->GetMaxHealth() * damage / 100;
2721 if (Player* modOwner = m_caster->GetSpellModOwner())
2722 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DAMAGE, addhealth, this);
2724 int32 gain = caster->DealHeal(unitTarget, addhealth, m_spellInfo);
2725 unitTarget->getHostileRefManager().threatAssist(m_caster, float(gain) * 0.5f, m_spellInfo);
2729 void Spell::EffectHealMechanical( uint32 /*i*/ )
2731 // Mechanic creature type should be correctly checked by targetCreatureType field
2732 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2734 // Try to get original caster
2735 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2737 // Skip if m_originalCaster not available
2738 if (!caster)
2739 return;
2741 uint32 addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, uint32(damage), HEAL);
2742 caster->DealHeal(unitTarget, addhealth, m_spellInfo);
2746 void Spell::EffectHealthLeech(uint32 i)
2748 if (!unitTarget)
2749 return;
2750 if (!unitTarget->isAlive())
2751 return;
2753 if (damage < 0)
2754 return;
2756 sLog.outDebug("HealthLeech :%i", damage);
2758 uint32 curHealth = unitTarget->GetHealth();
2759 damage = m_caster->SpellNonMeleeDamageLog(unitTarget, m_spellInfo->Id, damage );
2760 if (curHealth < damage)
2761 damage = curHealth;
2763 float multiplier = m_spellInfo->EffectMultipleValue[i];
2765 if (Player *modOwner = m_caster->GetSpellModOwner())
2766 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
2768 uint32 heal = uint32(damage*multiplier);
2769 if (m_caster->isAlive())
2771 heal = m_caster->SpellHealingBonus(m_caster, m_spellInfo, heal, HEAL);
2772 m_caster->DealHeal(m_caster, heal, m_spellInfo);
2776 void Spell::DoCreateItem(uint32 i, uint32 itemtype)
2778 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
2779 return;
2781 Player* player = (Player*)unitTarget;
2783 uint32 newitemid = itemtype;
2784 ItemPrototype const *pProto = ObjectMgr::GetItemPrototype( newitemid );
2785 if(!pProto)
2787 player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
2788 return;
2791 // bg reward have some special in code work
2792 uint32 bgType = 0;
2793 switch(m_spellInfo->Id)
2795 case SPELL_AV_MARK_WINNER:
2796 case SPELL_AV_MARK_LOSER:
2797 bgType = BATTLEGROUND_AV;
2798 break;
2799 case SPELL_WS_MARK_WINNER:
2800 case SPELL_WS_MARK_LOSER:
2801 bgType = BATTLEGROUND_WS;
2802 break;
2803 case SPELL_AB_MARK_WINNER:
2804 case SPELL_AB_MARK_LOSER:
2805 bgType = BATTLEGROUND_AB;
2806 break;
2807 default:
2808 break;
2811 uint32 num_to_add;
2813 // TODO: maybe all this can be replaced by using correct calculated `damage` value
2814 if(pProto->Class != ITEM_CLASS_CONSUMABLE || m_spellInfo->SpellFamilyName != SPELLFAMILY_MAGE)
2816 int32 basePoints = m_currentBasePoints[i];
2817 int32 randomPoints = m_spellInfo->EffectDieSides[i];
2818 if (randomPoints)
2819 num_to_add = basePoints + irand(1, randomPoints);
2820 else
2821 num_to_add = basePoints + 1;
2823 else if (pProto->MaxCount == 1)
2824 num_to_add = 1;
2825 else if(player->getLevel() >= m_spellInfo->spellLevel)
2827 int32 basePoints = m_currentBasePoints[i];
2828 float pointPerLevel = m_spellInfo->EffectRealPointsPerLevel[i];
2829 num_to_add = basePoints + 1 + uint32((player->getLevel() - m_spellInfo->spellLevel)*pointPerLevel);
2831 else
2832 num_to_add = 2;
2834 if (num_to_add < 1)
2835 num_to_add = 1;
2836 if (num_to_add > pProto->GetMaxStackSize())
2837 num_to_add = pProto->GetMaxStackSize();
2839 // init items_count to 1, since 1 item will be created regardless of specialization
2840 int items_count=1;
2841 // the chance to create additional items
2842 float additionalCreateChance=0.0f;
2843 // the maximum number of created additional items
2844 uint8 additionalMaxNum=0;
2845 // get the chance and maximum number for creating extra items
2846 if ( canCreateExtraItems(player, m_spellInfo->Id, additionalCreateChance, additionalMaxNum) )
2848 // roll with this chance till we roll not to create or we create the max num
2849 while ( roll_chance_f(additionalCreateChance) && items_count<=additionalMaxNum )
2850 ++items_count;
2853 // really will be created more items
2854 num_to_add *= items_count;
2856 // can the player store the new item?
2857 ItemPosCountVec dest;
2858 uint32 no_space = 0;
2859 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, newitemid, num_to_add, &no_space );
2860 if( msg != EQUIP_ERR_OK )
2862 // convert to possible store amount
2863 if( msg == EQUIP_ERR_INVENTORY_FULL || msg == EQUIP_ERR_CANT_CARRY_MORE_OF_THIS )
2864 num_to_add -= no_space;
2865 else
2867 // if not created by another reason from full inventory or unique items amount limitation
2868 player->SendEquipError( msg, NULL, NULL );
2869 return;
2873 if(num_to_add)
2875 // create the new item and store it
2876 Item* pItem = player->StoreNewItem( dest, newitemid, true, Item::GenerateItemRandomPropertyId(newitemid));
2878 // was it successful? return error if not
2879 if(!pItem)
2881 player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
2882 return;
2885 // set the "Crafted by ..." property of the item
2886 if( pItem->GetProto()->Class != ITEM_CLASS_CONSUMABLE && pItem->GetProto()->Class != ITEM_CLASS_QUEST)
2887 pItem->SetUInt32Value(ITEM_FIELD_CREATOR, player->GetGUIDLow());
2889 // send info to the client
2890 if(pItem)
2891 player->SendNewItem(pItem, num_to_add, true, bgType == 0);
2893 // we succeeded in creating at least one item, so a levelup is possible
2894 if(bgType == 0)
2895 player->UpdateCraftSkill(m_spellInfo->Id);
2898 // for battleground marks send by mail if not add all expected
2899 if(no_space > 0 && bgType)
2901 if(BattleGround* bg = sBattleGroundMgr.GetBattleGroundTemplate(BattleGroundTypeId(bgType)))
2902 bg->SendRewardMarkByMail(player, newitemid, no_space);
2906 void Spell::EffectCreateItem(uint32 i)
2908 DoCreateItem(i,m_spellInfo->EffectItemType[i]);
2911 void Spell::EffectCreateItem2(uint32 i)
2913 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
2914 return;
2915 Player* player = (Player*)m_caster;
2917 uint32 item_id = m_spellInfo->EffectItemType[i];
2919 DoCreateItem(i, item_id);
2921 // special case: fake item replaced by generate using spell_loot_template
2922 if (IsLootCraftingSpell(m_spellInfo))
2924 if (!player->HasItemCount(item_id, 1))
2925 return;
2927 // remove reagent
2928 uint32 count = 1;
2929 player->DestroyItemCount(item_id, count, true);
2931 // create some random items
2932 player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
2936 void Spell::EffectCreateRandomItem(uint32 i)
2938 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
2939 return;
2940 Player* player = (Player*)m_caster;
2942 // create some random items
2943 player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
2946 void Spell::EffectPersistentAA(uint32 i)
2948 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
2950 if (Player* modOwner = m_caster->GetSpellModOwner())
2951 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RADIUS, radius);
2953 int32 duration = GetSpellDuration(m_spellInfo);
2954 DynamicObject* dynObj = new DynamicObject;
2955 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))
2957 delete dynObj;
2958 return;
2960 dynObj->SetUInt32Value(OBJECT_FIELD_TYPE, 65);
2961 dynObj->SetUInt32Value(GAMEOBJECT_DISPLAYID, 368003);
2962 dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x01eeeeee);
2963 m_caster->AddDynObject(dynObj);
2964 m_caster->GetMap()->Add(dynObj);
2967 void Spell::EffectEnergize(uint32 i)
2969 if(!unitTarget)
2970 return;
2971 if(!unitTarget->isAlive())
2972 return;
2974 if(m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2975 return;
2977 Powers power = Powers(m_spellInfo->EffectMiscValue[i]);
2979 // Some level depends spells
2980 int level_multiplier = 0;
2981 int level_diff = 0;
2982 switch (m_spellInfo->Id)
2984 case 9512: // Restore Energy
2985 level_diff = m_caster->getLevel() - 40;
2986 level_multiplier = 2;
2987 break;
2988 case 24571: // Blood Fury
2989 level_diff = m_caster->getLevel() - 60;
2990 level_multiplier = 10;
2991 break;
2992 case 24532: // Burst of Energy
2993 level_diff = m_caster->getLevel() - 60;
2994 level_multiplier = 4;
2995 break;
2996 case 31930: // Judgements of the Wise
2997 case 48542: // Revitalize (mana restore case)
2998 case 63375: // Improved Stormstrike
2999 damage = damage * unitTarget->GetCreateMana() / 100;
3000 break;
3001 default:
3002 break;
3005 if (level_diff > 0)
3006 damage -= level_multiplier * level_diff;
3008 if(damage < 0)
3009 return;
3011 if(unitTarget->GetMaxPower(power) == 0)
3012 return;
3014 m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, damage, power);
3016 // Mad Alchemist's Potion
3017 if (m_spellInfo->Id == 45051)
3019 // find elixirs on target
3020 uint32 elixir_mask = 0;
3021 Unit::AuraMap& Auras = unitTarget->GetAuras();
3022 for(Unit::AuraMap::iterator itr = Auras.begin(); itr != Auras.end(); ++itr)
3024 uint32 spell_id = itr->second->GetId();
3025 if(uint32 mask = sSpellMgr.GetSpellElixirMask(spell_id))
3026 elixir_mask |= mask;
3029 // get available elixir mask any not active type from battle/guardian (and flask if no any)
3030 elixir_mask = (elixir_mask & ELIXIR_FLASK_MASK) ^ ELIXIR_FLASK_MASK;
3032 // get all available elixirs by mask and spell level
3033 std::vector<uint32> elixirs;
3034 SpellElixirMap const& m_spellElixirs = sSpellMgr.GetSpellElixirMap();
3035 for(SpellElixirMap::const_iterator itr = m_spellElixirs.begin(); itr != m_spellElixirs.end(); ++itr)
3037 if (itr->second & elixir_mask)
3039 if (itr->second & (ELIXIR_UNSTABLE_MASK | ELIXIR_SHATTRATH_MASK))
3040 continue;
3042 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
3043 if (spellInfo && (spellInfo->spellLevel < m_spellInfo->spellLevel || spellInfo->spellLevel > unitTarget->getLevel()))
3044 continue;
3046 elixirs.push_back(itr->first);
3050 if (!elixirs.empty())
3052 // cast random elixir on target
3053 uint32 rand_spell = urand(0,elixirs.size()-1);
3054 m_caster->CastSpell(unitTarget,elixirs[rand_spell],true,m_CastItem);
3059 void Spell::EffectEnergisePct(uint32 i)
3061 if (!unitTarget)
3062 return;
3063 if (!unitTarget->isAlive())
3064 return;
3066 if (m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
3067 return;
3069 Powers power = Powers(m_spellInfo->EffectMiscValue[i]);
3071 uint32 maxPower = unitTarget->GetMaxPower(power);
3072 if (maxPower == 0)
3073 return;
3075 uint32 gain = damage * maxPower / 100;
3076 m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, gain, power);
3079 void Spell::SendLoot(uint64 guid, LootType loottype)
3081 Player* player = (Player*)m_caster;
3082 if (!player)
3083 return;
3085 if (gameObjTarget)
3087 if (Script->GOHello(player, gameObjTarget))
3088 return;
3090 switch (gameObjTarget->GetGoType())
3092 case GAMEOBJECT_TYPE_DOOR:
3093 case GAMEOBJECT_TYPE_BUTTON:
3094 gameObjTarget->UseDoorOrButton();
3095 player->GetMap()->ScriptsStart(sGameObjectScripts, gameObjTarget->GetDBTableGUIDLow(), player, gameObjTarget);
3096 return;
3098 case GAMEOBJECT_TYPE_QUESTGIVER:
3099 // start or end quest
3100 player->PrepareQuestMenu(guid);
3101 player->SendPreparedQuest(guid);
3102 return;
3104 case GAMEOBJECT_TYPE_SPELL_FOCUS:
3105 // triggering linked GO
3106 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->spellFocus.linkedTrapId)
3107 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3108 return;
3110 case GAMEOBJECT_TYPE_GOOBER:
3111 // goober_scripts can be triggered if the player don't have the quest
3112 if (gameObjTarget->GetGOInfo()->goober.eventId)
3114 sLog.outDebug("Goober ScriptStart id %u for GO %u", gameObjTarget->GetGOInfo()->goober.eventId,gameObjTarget->GetDBTableGUIDLow());
3115 player->GetMap()->ScriptsStart(sEventScripts, gameObjTarget->GetGOInfo()->goober.eventId, player, gameObjTarget);
3118 // cast goober spell
3119 if (gameObjTarget->GetGOInfo()->goober.questId)
3120 ///Quest require to be active for GO using
3121 if (player->GetQuestStatus(gameObjTarget->GetGOInfo()->goober.questId) != QUEST_STATUS_INCOMPLETE)
3122 return;
3124 gameObjTarget->AddUniqueUse(player);
3125 gameObjTarget->SetLootState(GO_JUST_DEACTIVATED);
3127 //TODO? Objective counting called without spell check but with quest objective check
3128 // if send spell id then this line will duplicate to spell casting call (double counting)
3129 // So we or have this line and not required in quest_template have reqSpellIdN
3130 // or must remove this line and required in DB have data in quest_template have reqSpellIdN for all quest using cases.
3131 player->CastedCreatureOrGO(gameObjTarget->GetEntry(), gameObjTarget->GetGUID(), 0);
3133 // triggering linked GO
3134 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->goober.linkedTrapId)
3135 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3137 return;
3139 case GAMEOBJECT_TYPE_CHEST:
3140 // TODO: possible must be moved to loot release (in different from linked triggering)
3141 if (gameObjTarget->GetGOInfo()->chest.eventId)
3143 sLog.outDebug("Chest ScriptStart id %u for GO %u", gameObjTarget->GetGOInfo()->chest.eventId,gameObjTarget->GetDBTableGUIDLow());
3144 player->GetMap()->ScriptsStart(sEventScripts, gameObjTarget->GetGOInfo()->chest.eventId, player, gameObjTarget);
3147 // triggering linked GO
3148 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->chest.linkedTrapId)
3149 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3151 // Don't return, let loots been taken
3152 default:
3153 break;
3157 // Send loot
3158 player->SendLoot(guid, loottype);
3161 void Spell::EffectOpenLock(uint32 effIndex)
3163 if (!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER)
3165 sLog.outDebug( "WORLD: Open Lock - No Player Caster!");
3166 return;
3169 Player* player = (Player*)m_caster;
3171 uint32 lockId = 0;
3172 uint64 guid = 0;
3174 // Get lockId
3175 if (gameObjTarget)
3177 GameObjectInfo const* goInfo = gameObjTarget->GetGOInfo();
3178 // Arathi Basin banner opening !
3179 if (goInfo->type == GAMEOBJECT_TYPE_BUTTON && goInfo->button.noDamageImmune ||
3180 goInfo->type == GAMEOBJECT_TYPE_GOOBER && goInfo->goober.losOK)
3182 //CanUseBattleGroundObject() already called in CheckCast()
3183 // in battleground check
3184 if (BattleGround *bg = player->GetBattleGround())
3186 // check if it's correct bg
3187 if (bg->GetTypeID() == BATTLEGROUND_AB || bg->GetTypeID() == BATTLEGROUND_AV)
3188 bg->EventPlayerClickedOnFlag(player, gameObjTarget);
3189 return;
3192 else if (goInfo->type == GAMEOBJECT_TYPE_FLAGSTAND)
3194 //CanUseBattleGroundObject() already called in CheckCast()
3195 // in battleground check
3196 if (BattleGround *bg = player->GetBattleGround())
3198 if (bg->GetTypeID() == BATTLEGROUND_EY)
3199 bg->EventPlayerClickedOnFlag(player, gameObjTarget);
3200 return;
3203 lockId = goInfo->GetLockId();
3204 guid = gameObjTarget->GetGUID();
3206 else if (itemTarget)
3208 lockId = itemTarget->GetProto()->LockID;
3209 guid = itemTarget->GetGUID();
3211 else
3213 sLog.outDebug( "WORLD: Open Lock - No GameObject/Item Target!");
3214 return;
3217 SkillType skillId = SKILL_NONE;
3218 int32 reqSkillValue = 0;
3219 int32 skillValue;
3221 SpellCastResult res = CanOpenLock(effIndex, lockId, skillId, reqSkillValue, skillValue);
3222 if (res != SPELL_CAST_OK)
3224 SendCastResult(res);
3225 return;
3228 SendLoot(guid, LOOT_SKINNING);
3230 // not allow use skill grow at item base open
3231 if (!m_CastItem && skillId != SKILL_NONE)
3233 // update skill if really known
3234 if (uint32 pureSkillValue = player->GetPureSkillValue(skillId))
3236 if (gameObjTarget)
3238 // Allow one skill-up until respawned
3239 if (!gameObjTarget->IsInSkillupList(player->GetGUIDLow()) &&
3240 player->UpdateGatherSkill(skillId, pureSkillValue, reqSkillValue))
3241 gameObjTarget->AddToSkillupList(player->GetGUIDLow());
3243 else if (itemTarget)
3245 // Do one skill-up
3246 player->UpdateGatherSkill(skillId, pureSkillValue, reqSkillValue);
3252 void Spell::EffectSummonChangeItem(uint32 i)
3254 if (m_caster->GetTypeId() != TYPEID_PLAYER)
3255 return;
3257 Player *player = (Player*)m_caster;
3259 // applied only to using item
3260 if (!m_CastItem)
3261 return;
3263 // ... only to item in own inventory/bank/equip_slot
3264 if (m_CastItem->GetOwnerGUID()!=player->GetGUID())
3265 return;
3267 uint32 newitemid = m_spellInfo->EffectItemType[i];
3268 if (!newitemid)
3269 return;
3271 uint16 pos = m_CastItem->GetPos();
3273 Item *pNewItem = Item::CreateItem( newitemid, 1, player);
3274 if (!pNewItem)
3275 return;
3277 for(uint8 j= PERM_ENCHANTMENT_SLOT; j<=TEMP_ENCHANTMENT_SLOT; ++j)
3279 if (m_CastItem->GetEnchantmentId(EnchantmentSlot(j)))
3280 pNewItem->SetEnchantment(EnchantmentSlot(j), m_CastItem->GetEnchantmentId(EnchantmentSlot(j)), m_CastItem->GetEnchantmentDuration(EnchantmentSlot(j)), m_CastItem->GetEnchantmentCharges(EnchantmentSlot(j)));
3283 if (m_CastItem->GetUInt32Value(ITEM_FIELD_DURABILITY) < m_CastItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY))
3285 double loosePercent = 1 - m_CastItem->GetUInt32Value(ITEM_FIELD_DURABILITY) / double(m_CastItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY));
3286 player->DurabilityLoss(pNewItem, loosePercent);
3289 if (player->IsInventoryPos(pos))
3291 ItemPosCountVec dest;
3292 uint8 msg = player->CanStoreItem( m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), dest, pNewItem, true );
3293 if (msg == EQUIP_ERR_OK)
3295 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3297 // prevent crash at access and unexpected charges counting with item update queue corrupt
3298 if (m_CastItem==m_targets.getItemTarget())
3299 m_targets.setItemTarget(NULL);
3301 m_CastItem = NULL;
3303 player->StoreItem( dest, pNewItem, true);
3304 return;
3307 else if (player->IsBankPos (pos))
3309 ItemPosCountVec dest;
3310 uint8 msg = player->CanBankItem( m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), dest, pNewItem, true );
3311 if (msg == EQUIP_ERR_OK)
3313 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3315 // prevent crash at access and unexpected charges counting with item update queue corrupt
3316 if (m_CastItem==m_targets.getItemTarget())
3317 m_targets.setItemTarget(NULL);
3319 m_CastItem = NULL;
3321 player->BankItem( dest, pNewItem, true);
3322 return;
3325 else if (player->IsEquipmentPos (pos))
3327 uint16 dest;
3328 uint8 msg = player->CanEquipItem( m_CastItem->GetSlot(), dest, pNewItem, true );
3329 if (msg == EQUIP_ERR_OK)
3331 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3333 // prevent crash at access and unexpected charges counting with item update queue corrupt
3334 if (m_CastItem==m_targets.getItemTarget())
3335 m_targets.setItemTarget(NULL);
3337 m_CastItem = NULL;
3339 player->EquipItem( dest, pNewItem, true);
3340 player->AutoUnequipOffhandIfNeed();
3341 return;
3345 // fail
3346 delete pNewItem;
3349 void Spell::EffectProficiency(uint32 /*i*/)
3351 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
3352 return;
3353 Player *p_target = (Player*)unitTarget;
3355 uint32 subClassMask = m_spellInfo->EquippedItemSubClassMask;
3356 if (m_spellInfo->EquippedItemClass == ITEM_CLASS_WEAPON && !(p_target->GetWeaponProficiency() & subClassMask))
3358 p_target->AddWeaponProficiency(subClassMask);
3359 p_target->SendProficiency(ITEM_CLASS_WEAPON, p_target->GetWeaponProficiency());
3361 if (m_spellInfo->EquippedItemClass == ITEM_CLASS_ARMOR && !(p_target->GetArmorProficiency() & subClassMask))
3363 p_target->AddArmorProficiency(subClassMask);
3364 p_target->SendProficiency(ITEM_CLASS_ARMOR, p_target->GetArmorProficiency());
3368 void Spell::EffectApplyAreaAura(uint32 i)
3370 if (!unitTarget)
3371 return;
3372 if (!unitTarget->isAlive())
3373 return;
3375 AreaAura* Aur = new AreaAura(m_spellInfo, i, &m_currentBasePoints[i], unitTarget, m_caster, m_CastItem);
3376 unitTarget->AddAura(Aur);
3379 void Spell::EffectSummonType(uint32 i)
3381 uint32 prop_id = m_spellInfo->EffectMiscValueB[i];
3382 SummonPropertiesEntry const *summon_prop = sSummonPropertiesStore.LookupEntry(prop_id);
3383 if(!summon_prop)
3385 sLog.outError("EffectSummonType: Unhandled summon type %u", prop_id);
3386 return;
3389 switch(summon_prop->Group)
3391 // faction handled later on, or loaded from template
3392 case SUMMON_PROP_GROUP_WILD:
3393 case SUMMON_PROP_GROUP_FRIENDLY:
3395 switch(summon_prop->Type)
3397 case SUMMON_PROP_TYPE_OTHER:
3399 // those are classical totems - effectbasepoints is their hp and not summon ammount!
3400 //SUMMON_TYPE_TOTEM = 121: 23035, battlestands
3401 //SUMMON_TYPE_TOTEM2 = 647: 52893, Anti-Magic Zone (npc used)
3402 if(prop_id == 121 || prop_id == 647)
3403 EffectSummonTotem(i);
3404 else
3405 EffectSummonWild(i, summon_prop->FactionId);
3406 break;
3408 case SUMMON_PROP_TYPE_SUMMON:
3409 case SUMMON_PROP_TYPE_GUARDIAN:
3410 case SUMMON_PROP_TYPE_ARMY:
3411 case SUMMON_PROP_TYPE_DK:
3412 case SUMMON_PROP_TYPE_CONSTRUCT:
3414 // JC golems - 32804, etc -- fits much better totem AI
3415 if(m_spellInfo->SpellIconID == 2056)
3416 EffectSummonTotem(i);
3417 if(prop_id == 832) // scrapbot
3418 EffectSummonWild(i, summon_prop->FactionId);
3419 else
3420 EffectSummonGuardian(i, summon_prop->FactionId);
3421 break;
3423 case SUMMON_PROP_TYPE_TOTEM:
3424 EffectSummonTotem(i, summon_prop->Slot);
3425 break;
3426 case SUMMON_PROP_TYPE_CRITTER:
3427 EffectSummonCritter(i, summon_prop->FactionId);
3428 break;
3429 case SUMMON_PROP_TYPE_PHASING:
3430 case SUMMON_PROP_TYPE_LIGHTWELL:
3431 case SUMMON_PROP_TYPE_REPAIR_BOT:
3432 EffectSummonWild(i, summon_prop->FactionId);
3433 break;
3434 case SUMMON_PROP_TYPE_SIEGE_VEH:
3435 case SUMMON_PROP_TYPE_DRAKE_VEH:
3436 // TODO
3437 // EffectSummonVehicle(i);
3438 break;
3439 default:
3440 sLog.outError("EffectSummonType: Unhandled summon type %u", summon_prop->Type);
3441 break;
3443 break;
3445 case SUMMON_PROP_GROUP_PETS:
3447 // FIXME : multiple summons - not yet supported as pet
3448 //1562 - force of nature - sid 33831
3449 //1161 - feral spirit - sid 51533
3450 if(prop_id == 1562) // 3 uncontrolable instead of one controllable :/
3451 EffectSummonGuardian(i, summon_prop->FactionId);
3452 else
3453 EffectSummon(i);
3454 break;
3456 case SUMMON_PROP_GROUP_CONTROLLABLE:
3458 // no type here
3459 // maybe wrong - but thats the handler currently used for those
3460 EffectSummonGuardian(i, summon_prop->FactionId);
3461 break;
3463 case SUMMON_PROP_GROUP_VEHICLE:
3465 // TODO
3466 // EffectSummonVehicle(i);
3467 break;
3469 default:
3470 sLog.outError("EffectSummonType: Unhandled summon group type %u", summon_prop->Group);
3471 break;
3475 void Spell::EffectSummon(uint32 i)
3477 if (m_caster->GetPetGUID())
3478 return;
3480 if (!unitTarget)
3481 return;
3482 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
3483 if (!pet_entry)
3484 return;
3485 uint32 level = m_caster->getLevel();
3486 Pet* spawnCreature = new Pet(SUMMON_PET);
3488 int32 duration = GetSpellDuration(m_spellInfo);
3489 if(Player* modOwner = m_caster->GetSpellModOwner())
3490 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
3492 if (m_caster->GetTypeId()==TYPEID_PLAYER && spawnCreature->LoadPetFromDB((Player*)m_caster,pet_entry))
3494 // Summon in dest location
3495 float x, y, z;
3496 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3498 x = m_targets.m_destX;
3499 y = m_targets.m_destY;
3500 z = m_targets.m_destZ;
3501 spawnCreature->Relocate(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, -m_caster->GetOrientation());
3504 // set timer for unsummon
3505 if (duration > 0)
3506 spawnCreature->SetDuration(duration);
3508 return;
3511 Map *map = m_caster->GetMap();
3512 uint32 pet_number = sObjectMgr.GeneratePetNumber();
3513 if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
3514 m_spellInfo->EffectMiscValue[i], pet_number))
3516 sLog.outErrorDb("Spell::EffectSummon: no such creature entry %u",m_spellInfo->EffectMiscValue[i]);
3517 delete spawnCreature;
3518 return;
3521 // Summon in dest location
3522 float x, y, z;
3523 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3525 x = m_targets.m_destX;
3526 y = m_targets.m_destY;
3527 z = m_targets.m_destZ;
3529 else
3530 m_caster->GetClosePoint(x, y, z, spawnCreature->GetObjectSize());
3532 spawnCreature->Relocate(x, y, z, -m_caster->GetOrientation());
3534 if (!spawnCreature->IsPositionValid())
3536 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
3537 spawnCreature->GetGUIDLow(), spawnCreature->GetEntry(), spawnCreature->GetPositionX(), spawnCreature->GetPositionY());
3538 delete spawnCreature;
3539 return;
3542 // set timer for unsummon
3543 if (duration > 0)
3544 spawnCreature->SetDuration(duration);
3546 spawnCreature->SetOwnerGUID(m_caster->GetGUID());
3547 spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
3548 spawnCreature->setPowerType(POWER_MANA);
3549 spawnCreature->setFaction(m_caster->getFaction());
3550 spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS, 0);
3551 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
3552 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
3553 spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
3554 spawnCreature->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
3555 spawnCreature->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
3556 spawnCreature->SetCreatorGUID(m_caster->GetGUID());
3557 spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3559 spawnCreature->InitStatsForLevel(level, m_caster);
3561 spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
3563 spawnCreature->AIM_Initialize();
3564 spawnCreature->InitPetCreateSpells();
3565 spawnCreature->InitLevelupSpellsForLevel();
3566 spawnCreature->SetHealth(spawnCreature->GetMaxHealth());
3567 spawnCreature->SetPower(POWER_MANA, spawnCreature->GetMaxPower(POWER_MANA));
3569 std::string name = m_caster->GetName();
3570 name.append(petTypeSuffix[spawnCreature->getPetType()]);
3571 spawnCreature->SetName( name );
3573 map->Add((Creature*)spawnCreature);
3575 m_caster->SetPet(spawnCreature);
3577 if (m_caster->GetTypeId() == TYPEID_PLAYER)
3579 spawnCreature->GetCharmInfo()->SetReactState( REACT_DEFENSIVE );
3580 spawnCreature->SavePetToDB(PET_SAVE_AS_CURRENT);
3581 ((Player*)m_caster)->PetSpellInitialize();
3585 void Spell::EffectLearnSpell(uint32 i)
3587 if (!unitTarget)
3588 return;
3590 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
3592 if (m_caster->GetTypeId() == TYPEID_PLAYER)
3593 EffectLearnPetSpell(i);
3595 return;
3598 Player *player = (Player*)unitTarget;
3600 uint32 spellToLearn = ((m_spellInfo->Id==SPELL_ID_GENERIC_LEARN) || (m_spellInfo->Id==SPELL_ID_GENERIC_LEARN_PET)) ? damage : m_spellInfo->EffectTriggerSpell[i];
3601 player->learnSpell(spellToLearn,false);
3603 sLog.outDebug( "Spell: Player %u has learned spell %u from NpcGUID=%u", player->GetGUIDLow(), spellToLearn, m_caster->GetGUIDLow() );
3606 void Spell::EffectDispel(uint32 i)
3608 if (!unitTarget)
3609 return;
3611 // Fill possible dispell list
3612 std::vector <Aura *> dispel_list;
3614 // Create dispel mask by dispel type
3615 uint32 dispel_type = m_spellInfo->EffectMiscValue[i];
3616 uint32 dispelMask = GetDispellMask( DispelType(dispel_type) );
3617 Unit::AuraMap const& auras = unitTarget->GetAuras();
3618 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3620 Aura *aur = (*itr).second;
3621 if (aur && (1<<aur->GetSpellProto()->Dispel) & dispelMask)
3623 if(aur->GetSpellProto()->Dispel == DISPEL_MAGIC)
3625 bool positive = true;
3626 if (!aur->IsPositive())
3627 positive = false;
3628 else
3629 positive = (aur->GetSpellProto()->AttributesEx & SPELL_ATTR_EX_NEGATIVE)==0;
3631 // do not remove positive auras if friendly target
3632 // negative auras if non-friendly target
3633 if (positive == unitTarget->IsFriendlyTo(m_caster))
3634 continue;
3636 // Add aura to dispel list (all stack cases)
3637 for(int k = 0; k < aur->GetStackAmount(); ++k)
3638 dispel_list.push_back(aur);
3641 // Ok if exist some buffs for dispel try dispel it
3642 if (!dispel_list.empty())
3644 std::list < std::pair<uint32,uint64> > success_list;// (spell_id,casterGuid)
3645 std::list < uint32 > fail_list; // spell_id
3647 // some spells have effect value = 0 and all from its by meaning expect 1
3648 if(!damage)
3649 damage = 1;
3651 // Dispell N = damage buffs (or while exist buffs for dispel)
3652 for (int32 count=0; count < damage && !dispel_list.empty(); ++count)
3654 // Random select buff for dispel
3655 std::vector<Aura*>::iterator dispel_itr = dispel_list.begin();
3656 std::advance(dispel_itr,urand(0, dispel_list.size()-1));
3658 Aura *aur = *dispel_itr;
3660 // remove entry from dispel_list
3661 dispel_list.erase(dispel_itr);
3663 SpellEntry const* spellInfo = aur->GetSpellProto();
3664 // Base dispel chance
3665 // TODO: possible chance depend from spell level??
3666 int32 miss_chance = 0;
3667 // Apply dispel mod from aura caster
3668 if (Unit *caster = aur->GetCaster())
3670 if ( Player* modOwner = caster->GetSpellModOwner() )
3671 modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_RESIST_DISPEL_CHANCE, miss_chance, this);
3673 // Try dispel
3674 if (roll_chance_i(miss_chance))
3675 fail_list.push_back(spellInfo->Id);
3676 else
3677 success_list.push_back(std::pair<uint32,uint64>(aur->GetId(),aur->GetCasterGUID()));
3679 // Send success log and really remove auras
3680 if (!success_list.empty())
3682 int32 count = success_list.size();
3683 WorldPacket data(SMSG_SPELLDISPELLOG, 8+8+4+1+4+count*5);
3684 data.append(unitTarget->GetPackGUID()); // Victim GUID
3685 data.append(m_caster->GetPackGUID()); // Caster GUID
3686 data << uint32(m_spellInfo->Id); // Dispel spell id
3687 data << uint8(0); // not used
3688 data << uint32(count); // count
3689 for (std::list<std::pair<uint32,uint64> >::iterator j = success_list.begin(); j != success_list.end(); ++j)
3691 SpellEntry const* spellInfo = sSpellStore.LookupEntry(j->first);
3692 data << uint32(spellInfo->Id); // Spell Id
3693 data << uint8(0); // 0 - dispeled !=0 cleansed
3694 unitTarget->RemoveSingleAuraDueToSpellByDispel(spellInfo->Id, j->second, m_caster);
3696 m_caster->SendMessageToSet(&data, true);
3698 // On success dispel
3699 // Devour Magic
3700 if (m_spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK && m_spellInfo->Category == SPELLCATEGORY_DEVOUR_MAGIC)
3702 int32 heal_amount = m_spellInfo->CalculateSimpleValue(1);
3703 m_caster->CastCustomSpell(m_caster, 19658, &heal_amount, NULL, NULL, true);
3706 // Send fail log to client
3707 if (!fail_list.empty())
3709 // Failed to dispell
3710 WorldPacket data(SMSG_DISPEL_FAILED, 8+8+4+4*fail_list.size());
3711 data << uint64(m_caster->GetGUID()); // Caster GUID
3712 data << uint64(unitTarget->GetGUID()); // Victim GUID
3713 data << uint32(m_spellInfo->Id); // Dispell spell id
3714 for (std::list< uint32 >::iterator j = fail_list.begin(); j != fail_list.end(); ++j)
3715 data << uint32(*j); // Spell Id
3716 m_caster->SendMessageToSet(&data, true);
3721 void Spell::EffectDualWield(uint32 /*i*/)
3723 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
3724 ((Player*)unitTarget)->SetCanDualWield(true);
3727 void Spell::EffectPull(uint32 /*i*/)
3729 // TODO: create a proper pull towards distract spell center for distract
3730 sLog.outDebug("WORLD: Spell Effect DUMMY");
3733 void Spell::EffectDistract(uint32 /*i*/)
3735 // Check for possible target
3736 if (!unitTarget || unitTarget->isInCombat())
3737 return;
3739 // target must be OK to do this
3740 if( unitTarget->hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_STUNNED | UNIT_STAT_FLEEING ) )
3741 return;
3743 float angle = unitTarget->GetAngle(m_targets.m_destX, m_targets.m_destY);
3745 if ( unitTarget->GetTypeId() == TYPEID_PLAYER )
3747 // For players just turn them
3748 WorldPacket data;
3749 ((Player*)unitTarget)->BuildTeleportAckMsg(&data, unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), angle);
3750 ((Player*)unitTarget)->GetSession()->SendPacket( &data );
3751 ((Player*)unitTarget)->SetPosition(unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), angle, false);
3753 else
3755 // Set creature Distracted, Stop it, And turn it
3756 unitTarget->SetOrientation(angle);
3757 unitTarget->StopMoving();
3758 unitTarget->GetMotionMaster()->MoveDistract(damage * IN_MILISECONDS);
3762 void Spell::EffectPickPocket(uint32 /*i*/)
3764 if (m_caster->GetTypeId() != TYPEID_PLAYER)
3765 return;
3767 // victim must be creature and attackable
3768 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || m_caster->IsFriendlyTo(unitTarget))
3769 return;
3771 // victim have to be alive and humanoid or undead
3772 if (unitTarget->isAlive() && (unitTarget->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD) != 0)
3774 int32 chance = 10 + int32(m_caster->getLevel()) - int32(unitTarget->getLevel());
3776 if (chance > irand(0, 19))
3778 // Stealing successful
3779 //sLog.outDebug("Sending loot from pickpocket");
3780 ((Player*)m_caster)->SendLoot(unitTarget->GetGUID(),LOOT_PICKPOCKETING);
3782 else
3784 // Reveal action + get attack
3785 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
3786 if (((Creature*)unitTarget)->AI())
3787 ((Creature*)unitTarget)->AI()->AttackedBy(m_caster);
3792 void Spell::EffectAddFarsight(uint32 i)
3794 if(m_caster->GetTypeId() != TYPEID_PLAYER)
3795 return;
3797 int32 duration = GetSpellDuration(m_spellInfo);
3798 DynamicObject* dynObj = new DynamicObject;
3800 // set radius to 0: spell not expected to work as persistent aura
3801 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))
3803 delete dynObj;
3804 return;
3806 dynObj->SetUInt32Value(OBJECT_FIELD_TYPE, 65);
3807 dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x80000002);
3808 m_caster->AddDynObject(dynObj);
3809 m_caster->GetMap()->Add(dynObj);
3810 ((Player*)m_caster)->SetFarSightGUID(dynObj->GetGUID());
3813 void Spell::EffectSummonWild(uint32 i, uint32 forceFaction)
3815 uint32 creature_entry = m_spellInfo->EffectMiscValue[i];
3816 if (!creature_entry)
3817 return;
3819 uint32 level = m_caster->getLevel();
3821 // level of creature summoned using engineering item based at engineering skill level
3822 if (m_caster->GetTypeId()==TYPEID_PLAYER && m_CastItem)
3824 ItemPrototype const *proto = m_CastItem->GetProto();
3825 if (proto && proto->RequiredSkill == SKILL_ENGINERING)
3827 uint16 skill202 = ((Player*)m_caster)->GetSkillValue(SKILL_ENGINERING);
3828 if (skill202)
3829 level = skill202/5;
3833 // select center of summon position
3834 float center_x = m_targets.m_destX;
3835 float center_y = m_targets.m_destY;
3836 float center_z = m_targets.m_destZ;
3838 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3839 int32 duration = GetSpellDuration(m_spellInfo);
3840 TempSummonType summonType = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_OR_DEAD_DESPAWN;
3842 int32 amount = damage > 0 ? damage : 1;
3844 for(int32 count = 0; count < amount; ++count)
3846 float px, py, pz;
3847 // If dest location if present
3848 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3850 // Summon 1 unit in dest location
3851 if (count == 0)
3853 px = m_targets.m_destX;
3854 py = m_targets.m_destY;
3855 pz = m_targets.m_destZ;
3857 // Summon in random point all other units if location present
3858 else
3859 m_caster->GetRandomPoint(center_x, center_y, center_z, radius, px, py, pz);
3861 // Summon if dest location not present near caster
3862 else
3863 m_caster->GetClosePoint(px, py, pz, 3.0f);
3865 if(Creature *summon = m_caster->SummonCreature(creature_entry, px, py, pz, m_caster->GetOrientation(), summonType, duration))
3867 summon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3868 summon->SetCreatorGUID(m_caster->GetGUID());
3870 if(forceFaction)
3871 summon->setFaction(forceFaction);
3876 void Spell::EffectSummonGuardian(uint32 i, uint32 forceFaction)
3878 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
3879 if (!pet_entry)
3880 return;
3882 // in another case summon new
3883 uint32 level = m_caster->getLevel();
3885 // level of pet summoned using engineering item based at engineering skill level
3886 if (m_caster->GetTypeId() == TYPEID_PLAYER && m_CastItem)
3888 ItemPrototype const *proto = m_CastItem->GetProto();
3889 if (proto && proto->RequiredSkill == SKILL_ENGINERING)
3891 uint16 skill202 = ((Player*)m_caster)->GetSkillValue(SKILL_ENGINERING);
3892 if (skill202)
3894 level = skill202 / 5;
3899 // select center of summon position
3900 float center_x = m_targets.m_destX;
3901 float center_y = m_targets.m_destY;
3902 float center_z = m_targets.m_destZ;
3904 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3905 int32 duration = GetSpellDuration(m_spellInfo);
3906 if(Player* modOwner = m_caster->GetSpellModOwner())
3907 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
3909 int32 amount = damage > 0 ? damage : 1;
3911 for(int32 count = 0; count < amount; ++count)
3913 Pet* spawnCreature = new Pet(GUARDIAN_PET);
3915 Map *map = m_caster->GetMap();
3916 uint32 pet_number = sObjectMgr.GeneratePetNumber();
3917 if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map,m_caster->GetPhaseMask(),
3918 m_spellInfo->EffectMiscValue[i], pet_number))
3920 sLog.outError("no such creature entry %u", m_spellInfo->EffectMiscValue[i]);
3921 delete spawnCreature;
3922 return;
3925 float px, py, pz;
3926 // If dest location if present
3927 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3929 // Summon 1 unit in dest location
3930 if (count == 0)
3932 px = m_targets.m_destX;
3933 py = m_targets.m_destY;
3934 pz = m_targets.m_destZ;
3936 // Summon in random point all other units if location present
3937 else
3938 m_caster->GetRandomPoint(center_x, center_y, center_z, radius, px, py, pz);
3940 // Summon if dest location not present near caster
3941 else
3942 m_caster->GetClosePoint(px, py, pz,spawnCreature->GetObjectSize());
3944 spawnCreature->Relocate(px, py, pz, m_caster->GetOrientation());
3946 if (!spawnCreature->IsPositionValid())
3948 sLog.outError("Pet (guidlow %d, entry %d) not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)",
3949 spawnCreature->GetGUIDLow(), spawnCreature->GetEntry(), spawnCreature->GetPositionX(), spawnCreature->GetPositionY());
3950 delete spawnCreature;
3951 return;
3954 if (duration > 0)
3955 spawnCreature->SetDuration(duration);
3957 spawnCreature->SetOwnerGUID(m_caster->GetGUID());
3958 spawnCreature->setPowerType(POWER_MANA);
3959 spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, spawnCreature->GetCreatureInfo()->npcflag);
3960 spawnCreature->setFaction(forceFaction ? forceFaction : m_caster->getFaction());
3961 spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS, 0);
3962 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
3963 spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
3964 spawnCreature->SetCreatorGUID(m_caster->GetGUID());
3965 spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3967 spawnCreature->InitStatsForLevel(level, m_caster);
3968 spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
3970 spawnCreature->AIM_Initialize();
3972 m_caster->AddGuardian(spawnCreature);
3974 map->Add((Creature*)spawnCreature);
3978 void Spell::EffectTeleUnitsFaceCaster(uint32 i)
3980 if (!unitTarget)
3981 return;
3983 if (unitTarget->isInFlight())
3984 return;
3986 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3988 float fx, fy, fz;
3989 m_caster->GetClosePoint(fx, fy, fz, unitTarget->GetObjectSize(), dis);
3991 unitTarget->NearTeleportTo(fx, fy, fz, -m_caster->GetOrientation(), unitTarget==m_caster);
3994 void Spell::EffectLearnSkill(uint32 i)
3996 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
3997 return;
3999 if (damage < 0)
4000 return;
4002 uint32 skillid = m_spellInfo->EffectMiscValue[i];
4003 uint16 skillval = ((Player*)unitTarget)->GetPureSkillValue(skillid);
4004 ((Player*)unitTarget)->SetSkill(skillid, skillval ? skillval : 1, damage * 75);
4007 void Spell::EffectAddHonor(uint32 /*i*/)
4009 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4010 return;
4012 // not scale value for item based reward (/10 value expected)
4013 if (m_CastItem)
4015 ((Player*)unitTarget)->RewardHonor(NULL, 1, damage / 10);
4016 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());
4017 return;
4020 // do not allow to add too many honor for player (50 * 21) = 1040 at level 70, or (50 * 31) = 1550 at level 80
4021 if (damage <= 50)
4023 uint32 honor_reward = MaNGOS::Honor::hk_honor_at_level(unitTarget->getLevel(), damage);
4024 ((Player*)unitTarget)->RewardHonor(NULL, 1, honor_reward);
4025 sLog.outDebug("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (scale) to player: %u", m_spellInfo->Id, honor_reward, ((Player*)unitTarget)->GetGUIDLow());
4027 else
4029 //maybe we have correct honor_gain in damage already
4030 ((Player*)unitTarget)->RewardHonor(NULL, 1, damage);
4031 sLog.outError("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (non scale) for player: %u", m_spellInfo->Id, damage, ((Player*)unitTarget)->GetGUIDLow());
4035 void Spell::EffectTradeSkill(uint32 /*i*/)
4037 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4038 return;
4039 // uint32 skillid = m_spellInfo->EffectMiscValue[i];
4040 // uint16 skillmax = ((Player*)unitTarget)->(skillid);
4041 // ((Player*)unitTarget)->SetSkill(skillid,skillval?skillval:1,skillmax+75);
4044 void Spell::EffectEnchantItemPerm(uint32 effect_idx)
4046 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4047 return;
4048 if (!itemTarget)
4049 return;
4051 Player* p_caster = (Player*)m_caster;
4053 // not grow at item use at item case
4054 p_caster->UpdateCraftSkill(m_spellInfo->Id);
4056 uint32 enchant_id = m_spellInfo->EffectMiscValue[effect_idx];
4057 if (!enchant_id)
4058 return;
4060 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4061 if (!pEnchant)
4062 return;
4064 // item can be in trade slot and have owner diff. from caster
4065 Player* item_owner = itemTarget->GetOwner();
4066 if (!item_owner)
4067 return;
4069 if (item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4071 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(perm): %s (Entry: %d) for player: %s (Account: %u)",
4072 p_caster->GetName(),p_caster->GetSession()->GetAccountId(),
4073 itemTarget->GetProto()->Name1,itemTarget->GetEntry(),
4074 item_owner->GetName(),item_owner->GetSession()->GetAccountId());
4077 // remove old enchanting before applying new if equipped
4078 item_owner->ApplyEnchantment(itemTarget,PERM_ENCHANTMENT_SLOT,false);
4080 itemTarget->SetEnchantment(PERM_ENCHANTMENT_SLOT, enchant_id, 0, 0);
4082 // add new enchanting if equipped
4083 item_owner->ApplyEnchantment(itemTarget,PERM_ENCHANTMENT_SLOT,true);
4086 void Spell::EffectEnchantItemPrismatic(uint32 effect_idx)
4088 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4089 return;
4090 if (!itemTarget)
4091 return;
4093 Player* p_caster = (Player*)m_caster;
4095 uint32 enchant_id = m_spellInfo->EffectMiscValue[effect_idx];
4096 if (!enchant_id)
4097 return;
4099 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4100 if (!pEnchant)
4101 return;
4103 // support only enchantings with add socket in this slot
4105 bool add_socket = false;
4106 for(int i = 0; i < 3; ++i)
4108 if (pEnchant->type[i]==ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET)
4110 add_socket = true;
4111 break;
4114 if (!add_socket)
4116 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.",
4117 m_spellInfo->Id,SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC,ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET);
4118 return;
4122 // item can be in trade slot and have owner diff. from caster
4123 Player* item_owner = itemTarget->GetOwner();
4124 if (!item_owner)
4125 return;
4127 if (item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4129 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(perm): %s (Entry: %d) for player: %s (Account: %u)",
4130 p_caster->GetName(),p_caster->GetSession()->GetAccountId(),
4131 itemTarget->GetProto()->Name1,itemTarget->GetEntry(),
4132 item_owner->GetName(),item_owner->GetSession()->GetAccountId());
4135 // remove old enchanting before applying new if equipped
4136 item_owner->ApplyEnchantment(itemTarget,PRISMATIC_ENCHANTMENT_SLOT,false);
4138 itemTarget->SetEnchantment(PRISMATIC_ENCHANTMENT_SLOT, enchant_id, 0, 0);
4140 // add new enchanting if equipped
4141 item_owner->ApplyEnchantment(itemTarget,PRISMATIC_ENCHANTMENT_SLOT,true);
4144 void Spell::EffectEnchantItemTmp(uint32 i)
4146 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4147 return;
4149 Player* p_caster = (Player*)m_caster;
4151 // Rockbiter Weapon apply to both weapon
4152 if (m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN && m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000400000))
4154 uint32 spell_id = 0;
4156 // enchanting spell selected by calculated damage-per-sec stored in Effect[1] base value
4157 // Note: damage calculated (correctly) with rounding int32(float(v)) but
4158 // RW enchantments applied damage int32(float(v)+0.5), this create 0..1 difference sometime
4159 switch(damage)
4161 // Rank 1
4162 case 2: spell_id = 36744; break; // 0% [ 7% == 2, 14% == 2, 20% == 2]
4163 // Rank 2
4164 case 4: spell_id = 36753; break; // 0% [ 7% == 4, 14% == 4]
4165 case 5: spell_id = 36751; break; // 20%
4166 // Rank 3
4167 case 6: spell_id = 36754; break; // 0% [ 7% == 6, 14% == 6]
4168 case 7: spell_id = 36755; break; // 20%
4169 // Rank 4
4170 case 9: spell_id = 36761; break; // 0% [ 7% == 6]
4171 case 10: spell_id = 36758; break; // 14%
4172 case 11: spell_id = 36760; break; // 20%
4173 default:
4174 sLog.outError("Spell::EffectEnchantItemTmp: Damage %u not handled in S'RW",damage);
4175 return;
4179 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id);
4180 if (!spellInfo)
4182 sLog.outError("Spell::EffectEnchantItemTmp: unknown spell id %i", spell_id);
4183 return;
4186 for(int j = BASE_ATTACK; j <= OFF_ATTACK; ++j)
4188 if (Item* item = p_caster->GetWeaponForAttack(WeaponAttackType(j)))
4190 if (item->IsFitToSpellRequirements(m_spellInfo))
4192 Spell *spell = new Spell(m_caster, spellInfo, true);
4193 SpellCastTargets targets;
4194 targets.setItemTarget( item );
4195 spell->prepare(&targets);
4199 return;
4202 if (!itemTarget)
4203 return;
4205 uint32 enchant_id = m_spellInfo->EffectMiscValue[i];
4207 if (!enchant_id)
4209 sLog.outError("Spell %u Effect %u (SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY) have 0 as enchanting id",m_spellInfo->Id,i);
4210 return;
4213 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4214 if(!pEnchant)
4216 sLog.outError("Spell %u Effect %u (SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY) have not existed enchanting id %u ",m_spellInfo->Id,i,enchant_id);
4217 return;
4220 // select enchantment duration
4221 uint32 duration;
4223 // rogue family enchantments exception by duration
4224 if(m_spellInfo->Id == 38615)
4225 duration = 1800; // 30 mins
4226 // other rogue family enchantments always 1 hour (some have spell damage=0, but some have wrong data in EffBasePoints)
4227 else if(m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE)
4228 duration = 3600; // 1 hour
4229 // shaman family enchantments
4230 else if(m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN)
4231 duration = 1800; // 30 mins
4232 // other cases with this SpellVisual already selected
4233 else if(m_spellInfo->SpellVisual[0] == 215)
4234 duration = 1800; // 30 mins
4235 // some fishing pole bonuses
4236 else if(m_spellInfo->SpellVisual[0] == 563)
4237 duration = 600; // 10 mins
4238 // shaman rockbiter enchantments
4239 else if(m_spellInfo->SpellVisual[0] == 0)
4240 duration = 1800; // 30 mins
4241 else if(m_spellInfo->Id == 29702)
4242 duration = 300; // 5 mins
4243 else if(m_spellInfo->Id == 37360)
4244 duration = 300; // 5 mins
4245 // default case
4246 else
4247 duration = 3600; // 1 hour
4249 // item can be in trade slot and have owner diff. from caster
4250 Player* item_owner = itemTarget->GetOwner();
4251 if(!item_owner)
4252 return;
4254 if(item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4256 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(temp): %s (Entry: %d) for player: %s (Account: %u)",
4257 p_caster->GetName(), p_caster->GetSession()->GetAccountId(),
4258 itemTarget->GetProto()->Name1, itemTarget->GetEntry(),
4259 item_owner->GetName(), item_owner->GetSession()->GetAccountId());
4262 // remove old enchanting before applying new if equipped
4263 item_owner->ApplyEnchantment(itemTarget,TEMP_ENCHANTMENT_SLOT, false);
4265 itemTarget->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, duration * 1000, 0);
4267 // add new enchanting if equipped
4268 item_owner->ApplyEnchantment(itemTarget, TEMP_ENCHANTMENT_SLOT, true);
4271 void Spell::EffectTameCreature(uint32 /*i*/)
4273 // Caster must be player, checked in Spell::CheckCast
4274 // Spell can be triggered, we need to check original caster prior to caster
4275 Player* plr = (Player*)(m_originalCaster ? m_originalCaster : m_caster);
4277 Creature* creatureTarget = (Creature*)unitTarget;
4279 // cast finish successfully
4280 //SendChannelUpdate(0);
4281 finish();
4283 Pet* pet = plr->CreateTamedPetFrom(creatureTarget, m_spellInfo->Id);
4284 if(!pet) // in versy specific state like near world end/etc.
4285 return;
4287 // "kill" original creature
4288 creatureTarget->ForcedDespawn();
4290 uint32 level = (creatureTarget->getLevel() < (plr->getLevel() - 5)) ? (plr->getLevel() - 5) : creatureTarget->getLevel();
4292 // prepare visual effect for levelup
4293 pet->SetUInt32Value(UNIT_FIELD_LEVEL, level - 1);
4295 // add to world
4296 pet->GetMap()->Add((Creature*)pet);
4298 // visual effect for levelup
4299 pet->SetUInt32Value(UNIT_FIELD_LEVEL, level);
4301 // caster have pet now
4302 plr->SetPet(pet);
4304 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
4305 plr->PetSpellInitialize();
4308 void Spell::EffectSummonPet(uint32 i)
4310 uint32 petentry = m_spellInfo->EffectMiscValue[i];
4312 Pet *OldSummon = m_caster->GetPet();
4314 // if pet requested type already exist
4315 if( OldSummon )
4317 if(petentry == 0 || OldSummon->GetEntry() == petentry)
4319 // pet in corpse state can't be summoned
4320 if( OldSummon->isDead() )
4321 return;
4323 OldSummon->GetMap()->Remove((Creature*)OldSummon,false);
4325 float px, py, pz;
4326 m_caster->GetClosePoint(px, py, pz, OldSummon->GetObjectSize());
4328 OldSummon->Relocate(px, py, pz, OldSummon->GetOrientation());
4329 m_caster->GetMap()->Add((Creature*)OldSummon);
4331 if(m_caster->GetTypeId() == TYPEID_PLAYER && OldSummon->isControlled() )
4333 ((Player*)m_caster)->PetSpellInitialize();
4335 return;
4338 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4339 ((Player*)m_caster)->RemovePet(OldSummon,(OldSummon->getPetType()==HUNTER_PET ? PET_SAVE_AS_DELETED : PET_SAVE_NOT_IN_SLOT),false);
4340 else
4341 return;
4344 Pet* NewSummon = new Pet;
4346 // petentry==0 for hunter "call pet" (current pet summoned if any)
4347 if(m_caster->GetTypeId() == TYPEID_PLAYER && NewSummon->LoadPetFromDB((Player*)m_caster, petentry))
4349 if(NewSummon->getPetType() == SUMMON_PET)
4351 // Remove Demonic Sacrifice auras (known pet)
4352 Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4353 for(Unit::AuraList::const_iterator itr = auraClassScripts.begin(); itr != auraClassScripts.end();)
4355 if((*itr)->GetModifier()->m_miscvalue == 2228)
4357 m_caster->RemoveAurasDueToSpell((*itr)->GetId());
4358 itr = auraClassScripts.begin();
4360 else
4361 ++itr;
4365 return;
4368 // not error in case fail hunter call pet
4369 if(!petentry)
4371 delete NewSummon;
4372 return;
4375 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(petentry);
4377 if(!cInfo)
4379 sLog.outError("EffectSummonPet: creature entry %u not found.", petentry);
4380 delete NewSummon;
4381 return;
4384 Map *map = m_caster->GetMap();
4385 uint32 pet_number = sObjectMgr.GeneratePetNumber();
4386 if(!NewSummon->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
4387 petentry, pet_number))
4389 delete NewSummon;
4390 return;
4393 float px, py, pz;
4394 m_caster->GetClosePoint(px, py, pz, NewSummon->GetObjectSize());
4396 NewSummon->Relocate(px, py, pz, m_caster->GetOrientation());
4398 if(!NewSummon->IsPositionValid())
4400 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
4401 NewSummon->GetGUIDLow(), NewSummon->GetEntry(), NewSummon->GetPositionX(), NewSummon->GetPositionY());
4402 delete NewSummon;
4403 return;
4406 uint32 petlevel = m_caster->getLevel();
4407 NewSummon->setPetType(SUMMON_PET);
4409 uint32 faction = m_caster->getFaction();
4410 if(m_caster->GetTypeId() == TYPEID_UNIT)
4412 if ( ((Creature*)m_caster)->isTotem() )
4413 NewSummon->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE);
4414 else
4415 NewSummon->GetCharmInfo()->SetReactState(REACT_DEFENSIVE);
4418 NewSummon->SetOwnerGUID(m_caster->GetGUID());
4419 NewSummon->SetCreatorGUID(m_caster->GetGUID());
4420 NewSummon->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
4421 NewSummon->setFaction(faction);
4422 NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
4423 NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
4424 NewSummon->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
4425 NewSummon->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
4426 NewSummon->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
4427 NewSummon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
4429 NewSummon->GetCharmInfo()->SetPetNumber(pet_number, true);
4430 // this enables pet details window (Shift+P)
4432 // this enables popup window (pet dismiss, cancel), hunter pet additional flags set later
4433 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4434 NewSummon->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4436 if(m_caster->IsPvP())
4437 NewSummon->SetPvP(true);
4439 NewSummon->InitStatsForLevel(petlevel, m_caster);
4440 NewSummon->InitPetCreateSpells();
4441 NewSummon->InitLevelupSpellsForLevel();
4442 NewSummon->InitTalentForLevel();
4444 if(NewSummon->getPetType() == SUMMON_PET)
4446 // Remove Demonic Sacrifice auras (new pet)
4447 Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4448 for(Unit::AuraList::const_iterator itr = auraClassScripts.begin(); itr != auraClassScripts.end();)
4450 if((*itr)->GetModifier()->m_miscvalue == 2228)
4452 m_caster->RemoveAurasDueToSpell((*itr)->GetId());
4453 itr = auraClassScripts.begin();
4455 else
4456 ++itr;
4459 // generate new name for summon pet
4460 std::string new_name = sObjectMgr.GeneratePetName(petentry);
4461 if(!new_name.empty())
4462 NewSummon->SetName(new_name);
4464 else if(NewSummon->getPetType() == HUNTER_PET)
4466 NewSummon->RemoveByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED);
4467 NewSummon->SetByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_ABANDONED);
4470 NewSummon->AIM_Initialize();
4471 NewSummon->SetHealth(NewSummon->GetMaxHealth());
4472 NewSummon->SetPower(POWER_MANA, NewSummon->GetMaxPower(POWER_MANA));
4474 map->Add((Creature*)NewSummon);
4476 m_caster->SetPet(NewSummon);
4477 sLog.outDebug("New Pet has guid %u", NewSummon->GetGUIDLow());
4479 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4481 NewSummon->SavePetToDB(PET_SAVE_AS_CURRENT);
4482 ((Player*)m_caster)->PetSpellInitialize();
4486 void Spell::EffectLearnPetSpell(uint32 i)
4488 if(m_caster->GetTypeId() != TYPEID_PLAYER)
4489 return;
4491 Player *_player = (Player*)m_caster;
4493 Pet *pet = _player->GetPet();
4494 if(!pet)
4495 return;
4496 if(!pet->isAlive())
4497 return;
4499 SpellEntry const *learn_spellproto = sSpellStore.LookupEntry(m_spellInfo->EffectTriggerSpell[i]);
4500 if(!learn_spellproto)
4501 return;
4503 pet->learnSpell(learn_spellproto->Id);
4505 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
4506 _player->PetSpellInitialize();
4509 void Spell::EffectTaunt(uint32 /*i*/)
4511 if (!unitTarget)
4512 return;
4514 // this effect use before aura Taunt apply for prevent taunt already attacking target
4515 // for spell as marked "non effective at already attacking target"
4516 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4518 if (unitTarget->getVictim()==m_caster)
4520 SendCastResult(SPELL_FAILED_DONT_REPORT);
4521 return;
4525 // Also use this effect to set the taunter's threat to the taunted creature's highest value
4526 if (unitTarget->CanHaveThreatList() && unitTarget->getThreatManager().getCurrentVictim())
4527 unitTarget->getThreatManager().addThreat(m_caster,unitTarget->getThreatManager().getCurrentVictim()->getThreat());
4530 void Spell::EffectWeaponDmg(uint32 i)
4532 if(!unitTarget)
4533 return;
4534 if(!unitTarget->isAlive())
4535 return;
4537 // multiple weapon dmg effect workaround
4538 // execute only the last weapon damage
4539 // and handle all effects at once
4540 for (int j = 0; j < 3; ++j)
4542 switch(m_spellInfo->Effect[j])
4544 case SPELL_EFFECT_WEAPON_DAMAGE:
4545 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
4546 case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
4547 case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
4548 if (j < i) // we must calculate only at last weapon effect
4549 return;
4550 break;
4554 // some spell specific modifiers
4555 bool spellBonusNeedWeaponDamagePercentMod = false; // if set applied weapon damage percent mode to spell bonus
4557 float weaponDamagePercentMod = 1.0f; // applied to weapon damage and to fixed effect damage bonus
4558 float totalDamagePercentMod = 1.0f; // applied to final bonus+weapon damage
4559 bool normalized = false;
4561 int32 spell_bonus = 0; // bonus specific for spell
4562 switch(m_spellInfo->SpellFamilyName)
4564 case SPELLFAMILY_WARRIOR:
4566 // Devastate bonus and sunder armor refresh
4567 if(m_spellInfo->SpellVisual[0] == 12295 && m_spellInfo->SpellIconID == 1508)
4569 uint32 stack = 0;
4570 // Need refresh all Sunder Armor auras from this caster
4571 Unit::AuraMap& suAuras = unitTarget->GetAuras();
4572 SpellEntry const *spellInfo;
4573 for(Unit::AuraMap::iterator itr = suAuras.begin(); itr != suAuras.end(); ++itr)
4575 spellInfo = (*itr).second->GetSpellProto();
4576 if( spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR &&
4577 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000004000)) &&
4578 (*itr).second->GetCasterGUID() == m_caster->GetGUID())
4580 (*itr).second->RefreshAura();
4581 stack = (*itr).second->GetStackAmount();
4582 break;
4585 if (stack)
4586 spell_bonus += stack * CalculateDamage(2, unitTarget);
4587 if (!stack || stack < spellInfo->StackAmount)
4588 // Devastate causing Sunder Armor Effect
4589 // and no need to cast over max stack amount
4590 m_caster->CastSpell(unitTarget, 58567, true);
4592 break;
4594 case SPELLFAMILY_ROGUE:
4596 // Mutilate (for each hand)
4597 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x600000000))
4599 bool found = false;
4600 // fast check
4601 if(unitTarget->HasAuraState(AURA_STATE_DEADLY_POISON))
4602 found = true;
4603 // full aura scan
4604 else
4606 Unit::AuraMap const& auras = unitTarget->GetAuras();
4607 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
4609 if(itr->second->GetSpellProto()->Dispel == DISPEL_POISON)
4611 found = true;
4612 break;
4617 if(found)
4618 totalDamagePercentMod *= 1.2f; // 120% if poisoned
4620 // Fan of Knives
4621 else if (m_caster->GetTypeId()==TYPEID_PLAYER && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0004000000000000)))
4623 Item* weapon = ((Player*)m_caster)->GetWeaponForAttack(m_attackType,true,true);
4624 if (weapon && weapon->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER)
4625 totalDamagePercentMod *= 1.5f; // 150% to daggers
4627 break;
4629 case SPELLFAMILY_PALADIN:
4631 // Seal of Command - receive benefit from Spell Damage and Healing
4632 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x00000002000000))
4634 spellBonusNeedWeaponDamagePercentMod = true;// apply weaponDamagePercentMod to spell_bonus (and then to all bonus, fixes and weapon already have applied)
4635 spell_bonus += int32(0.23f*m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo)));
4636 spell_bonus += int32(0.29f*m_caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellInfo), unitTarget));
4638 break;
4640 case SPELLFAMILY_SHAMAN:
4642 // Skyshatter Harness item set bonus
4643 // Stormstrike
4644 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x001000000000))
4646 Unit::AuraList const& m_OverrideClassScript = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4647 for(Unit::AuraList::const_iterator citr = m_OverrideClassScript.begin(); citr != m_OverrideClassScript.end(); ++citr)
4649 // Stormstrike AP Buff
4650 if ( (*citr)->GetModifier()->m_miscvalue == 5634 )
4652 m_caster->CastSpell(m_caster, 38430, true, NULL, *citr);
4653 break;
4657 break;
4659 case SPELLFAMILY_DEATHKNIGHT:
4661 // Blood Strike, Heart Strike, Obliterate
4662 // Blood-Caked Strike, Scourge Strike
4663 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0002000001400000) ||
4664 m_spellInfo->SpellIconID == 1736 || m_spellInfo->SpellIconID == 3143)
4666 uint32 count = 0;
4667 Unit::AuraMap const& auras = unitTarget->GetAuras();
4668 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
4670 if(itr->second->GetSpellProto()->Dispel == DISPEL_DISEASE &&
4671 itr->second->GetCasterGUID() == m_caster->GetGUID() &&
4672 IsSpellLastAuraEffect(itr->second->GetSpellProto(), itr->second->GetEffIndex()))
4673 ++count;
4676 if (count)
4678 // Effect 1(for Blood-Caked Strike)/3(other) damage is bonus
4679 float bonus = count * CalculateDamage(m_spellInfo->SpellIconID == 1736 ? 0 : 2, unitTarget) / 100.0f;
4680 // Blood Strike, Blood-Caked Strike and Obliterate store bonus*2
4681 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0002000000400000) ||
4682 m_spellInfo->SpellIconID == 1736)
4683 bonus /= 2.0f;
4685 totalDamagePercentMod *= 1.0f + bonus;
4688 // Glyph of Blood Strike
4689 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000400000) &&
4690 m_caster->HasAura(59332) &&
4691 unitTarget->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED))
4693 totalDamagePercentMod *= 1.2f; // 120% if snared
4695 // Glyph of Death Strike
4696 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000010) &&
4697 m_caster->HasAura(59336))
4699 int32 rp = m_caster->GetPower(POWER_RUNIC_POWER) / 10;
4700 if(rp > 25)
4701 rp = 25;
4702 totalDamagePercentMod *= 1.0f + rp / 100.0f;
4704 // Glyph of Plague Strike
4705 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000001) &&
4706 m_caster->HasAura(58657) )
4708 totalDamagePercentMod *= 1.2f;
4710 break;
4714 int32 fixed_bonus = 0;
4715 for (int j = 0; j < 3; ++j)
4717 switch(m_spellInfo->Effect[j])
4719 case SPELL_EFFECT_WEAPON_DAMAGE:
4720 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
4721 fixed_bonus += CalculateDamage(j, unitTarget);
4722 break;
4723 case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
4724 fixed_bonus += CalculateDamage(j, unitTarget);
4725 normalized = true;
4726 break;
4727 case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
4728 weaponDamagePercentMod *= float(CalculateDamage(j, unitTarget)) / 100.0f;
4730 // applied only to prev.effects fixed damage
4731 fixed_bonus = int32(fixed_bonus*weaponDamagePercentMod);
4732 break;
4733 default:
4734 break; // not weapon damage effect, just skip
4738 // apply weaponDamagePercentMod to spell bonus also
4739 if(spellBonusNeedWeaponDamagePercentMod)
4740 spell_bonus = int32(spell_bonus*weaponDamagePercentMod);
4742 // non-weapon damage
4743 int32 bonus = spell_bonus + fixed_bonus;
4745 // apply to non-weapon bonus weapon total pct effect, weapon total flat effect included in weapon damage
4746 if(bonus)
4748 UnitMods unitMod;
4749 switch(m_attackType)
4751 default:
4752 case BASE_ATTACK: unitMod = UNIT_MOD_DAMAGE_MAINHAND; break;
4753 case OFF_ATTACK: unitMod = UNIT_MOD_DAMAGE_OFFHAND; break;
4754 case RANGED_ATTACK: unitMod = UNIT_MOD_DAMAGE_RANGED; break;
4757 float weapon_total_pct = m_caster->GetModifierValue(unitMod, TOTAL_PCT);
4758 bonus = int32(bonus*weapon_total_pct);
4761 // + weapon damage with applied weapon% dmg to base weapon damage in call
4762 bonus += int32(m_caster->CalculateDamage(m_attackType, normalized)*weaponDamagePercentMod);
4764 // total damage
4765 bonus = int32(bonus*totalDamagePercentMod);
4767 // prevent negative damage
4768 m_damage+= uint32(bonus > 0 ? bonus : 0);
4770 // Hemorrhage
4771 if (m_spellInfo->SpellFamilyName==SPELLFAMILY_ROGUE && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x2000000)))
4773 if(m_caster->GetTypeId()==TYPEID_PLAYER)
4774 ((Player*)m_caster)->AddComboPoints(unitTarget, 1);
4776 // Mangle (Cat): CP
4777 else if (m_spellInfo->SpellFamilyName==SPELLFAMILY_DRUID && (m_spellInfo->SpellFamilyFlags==UI64LIT(0x0000040000000000)))
4779 if(m_caster->GetTypeId()==TYPEID_PLAYER)
4780 ((Player*)m_caster)->AddComboPoints(unitTarget, 1);
4783 // take ammo
4784 if(m_attackType == RANGED_ATTACK && m_caster->GetTypeId() == TYPEID_PLAYER)
4786 Item *pItem = ((Player*)m_caster)->GetWeaponForAttack(RANGED_ATTACK, true, false);
4788 // wands don't have ammo
4789 if (!pItem || pItem->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_WAND)
4790 return;
4792 if (pItem->GetProto()->InventoryType == INVTYPE_THROWN)
4794 if(pItem->GetMaxStackCount()==1)
4796 // decrease durability for non-stackable throw weapon
4797 ((Player*)m_caster)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_RANGED);
4799 else
4801 // decrease items amount for stackable throw weapon
4802 uint32 count = 1;
4803 ((Player*)m_caster)->DestroyItemCount( pItem, count, true);
4806 else if(uint32 ammo = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID))
4807 ((Player*)m_caster)->DestroyItemCount(ammo, 1, true);
4811 void Spell::EffectThreat(uint32 /*i*/)
4813 if(!unitTarget || !unitTarget->isAlive() || !m_caster->isAlive())
4814 return;
4816 if(!unitTarget->CanHaveThreatList())
4817 return;
4819 unitTarget->AddThreat(m_caster, float(damage), false, GetSpellSchoolMask(m_spellInfo), m_spellInfo);
4822 void Spell::EffectHealMaxHealth(uint32 /*i*/)
4824 if(!unitTarget)
4825 return;
4826 if(!unitTarget->isAlive())
4827 return;
4829 uint32 heal = m_caster->GetMaxHealth();
4831 m_healing += heal;
4834 void Spell::EffectInterruptCast(uint32 /*i*/)
4836 if(!unitTarget)
4837 return;
4838 if(!unitTarget->isAlive())
4839 return;
4841 // TODO: not all spells that used this effect apply cooldown at school spells
4842 // also exist case: apply cooldown to interrupted cast only and to all spells
4843 for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
4845 if (Spell* spell = unitTarget->GetCurrentSpell(CurrentSpellTypes(i)))
4847 SpellEntry const* curSpellInfo = spell->m_spellInfo;
4848 // check if we can interrupt spell
4849 if ((curSpellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_INTERRUPT) && curSpellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE )
4851 unitTarget->ProhibitSpellScholl(GetSpellSchoolMask(curSpellInfo), GetSpellDuration(m_spellInfo));
4852 unitTarget->InterruptSpell(CurrentSpellTypes(i),false);
4858 void Spell::EffectSummonObjectWild(uint32 i)
4860 uint32 gameobject_id = m_spellInfo->EffectMiscValue[i];
4862 GameObject* pGameObj = new GameObject;
4864 WorldObject* target = focusObject;
4865 if( !target )
4866 target = m_caster;
4868 float x, y, z;
4869 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
4871 x = m_targets.m_destX;
4872 y = m_targets.m_destY;
4873 z = m_targets.m_destZ;
4875 else
4876 m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE);
4878 Map *map = target->GetMap();
4880 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id, map,
4881 m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
4883 delete pGameObj;
4884 return;
4887 int32 duration = GetSpellDuration(m_spellInfo);
4889 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
4890 pGameObj->SetSpellId(m_spellInfo->Id);
4892 // Wild object not have owner and check clickable by players
4893 map->Add(pGameObj);
4895 if(pGameObj->GetGoType() == GAMEOBJECT_TYPE_FLAGDROP && m_caster->GetTypeId() == TYPEID_PLAYER)
4897 Player *pl = (Player*)m_caster;
4898 BattleGround* bg = ((Player *)m_caster)->GetBattleGround();
4900 switch(pGameObj->GetMapId())
4902 case 489: //WS
4904 if(bg && bg->GetTypeID()==BATTLEGROUND_WS && bg->GetStatus() == STATUS_IN_PROGRESS)
4906 uint32 team = ALLIANCE;
4908 if(pl->GetTeam() == team)
4909 team = HORDE;
4911 ((BattleGroundWS*)bg)->SetDroppedFlagGUID(pGameObj->GetGUID(),team);
4913 break;
4915 case 566: //EY
4917 if(bg && bg->GetTypeID()==BATTLEGROUND_EY && bg->GetStatus() == STATUS_IN_PROGRESS)
4919 ((BattleGroundEY*)bg)->SetDroppedFlagGUID(pGameObj->GetGUID());
4921 break;
4926 if(uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry())
4928 GameObject* linkedGO = new GameObject;
4929 if(linkedGO->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, map,
4930 m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
4932 linkedGO->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
4933 linkedGO->SetSpellId(m_spellInfo->Id);
4935 // Wild object not have owner and check clickable by players
4936 map->Add(linkedGO);
4938 else
4940 delete linkedGO;
4941 linkedGO = NULL;
4942 return;
4947 void Spell::EffectScriptEffect(uint32 effIndex)
4949 // TODO: we must implement hunter pet summon at login there (spell 6962)
4951 switch(m_spellInfo->SpellFamilyName)
4953 case SPELLFAMILY_GENERIC:
4955 switch(m_spellInfo->Id)
4957 // Bending Shinbone
4958 case 8856:
4960 if(!itemTarget && m_caster->GetTypeId()!=TYPEID_PLAYER)
4961 return;
4963 uint32 spell_id = 0;
4964 switch(urand(1, 5))
4966 case 1: spell_id = 8854; break;
4967 default: spell_id = 8855; break;
4970 m_caster->CastSpell(m_caster,spell_id,true,NULL);
4971 return;
4973 // Piccolo of the Flaming Fire
4974 case 17512:
4976 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
4977 return;
4978 unitTarget->HandleEmoteCommand(EMOTE_STATE_DANCE);
4979 return;
4981 // Escape artist
4982 case 20589:
4984 if(!unitTarget)
4985 return;
4987 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
4988 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
4989 return;
4991 // Brittle Armor - need remove one 24575 Brittle Armor aura
4992 case 24590:
4993 unitTarget->RemoveSingleSpellAurasFromStack(24575);
4994 return;
4995 // PX-238 Winter Wondervolt TRAP
4996 case 26275:
4998 uint32 spells[4] = { 26272, 26157, 26273, 26274 };
5000 // check presence
5001 for(int j = 0; j < 4; ++j)
5002 if(unitTarget->HasAura(spells[j],0))
5003 return;
5005 // select spell
5006 uint32 iTmpSpellId = spells[urand(0,3)];
5008 // cast
5009 unitTarget->CastSpell(unitTarget, iTmpSpellId, true);
5010 return;
5012 // Mercurial Shield - need remove one 26464 Mercurial Shield aura
5013 case 26465:
5014 unitTarget->RemoveSingleSpellAurasFromStack(26464);
5015 return;
5016 // Orb teleport spells
5017 case 25140:
5018 case 25143:
5019 case 25650:
5020 case 25652:
5021 case 29128:
5022 case 29129:
5023 case 35376:
5024 case 35727:
5026 if(!unitTarget)
5027 return;
5029 uint32 spellid;
5030 switch(m_spellInfo->Id)
5032 case 25140: spellid = 32571; break;
5033 case 25143: spellid = 32572; break;
5034 case 25650: spellid = 30140; break;
5035 case 25652: spellid = 30141; break;
5036 case 29128: spellid = 32568; break;
5037 case 29129: spellid = 32569; break;
5038 case 35376: spellid = 25649; break;
5039 case 35727: spellid = 35730; break;
5040 default:
5041 return;
5044 unitTarget->CastSpell(unitTarget,spellid,false);
5045 return;
5047 // Shadow Flame (All script effects, not just end ones to prevent player from dodging the last triggered spell)
5048 case 22539:
5049 case 22972:
5050 case 22975:
5051 case 22976:
5052 case 22977:
5053 case 22978:
5054 case 22979:
5055 case 22980:
5056 case 22981:
5057 case 22982:
5058 case 22983:
5059 case 22984:
5060 case 22985:
5062 if(!unitTarget || !unitTarget->isAlive())
5063 return;
5065 // Onyxia Scale Cloak
5066 if(unitTarget->GetDummyAura(22683))
5067 return;
5069 // Shadow Flame
5070 m_caster->CastSpell(unitTarget, 22682, true);
5071 return;
5073 // Summon Black Qiraji Battle Tank
5074 case 26656:
5076 if(!unitTarget)
5077 return;
5079 // Prevent stacking of mounts
5080 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
5082 // Two separate mounts depending on area id (allows use both in and out of specific instance)
5083 if (unitTarget->GetAreaId() == 3428)
5084 unitTarget->CastSpell(unitTarget, 25863, false);
5085 else
5086 unitTarget->CastSpell(unitTarget, 26655, false);
5087 return;
5089 // Mirren's Drinking Hat
5090 case 29830:
5092 uint32 item = 0;
5093 switch ( urand(1, 6) )
5095 case 1:
5096 case 2:
5097 case 3:
5098 item = 23584; break; // Loch Modan Lager
5099 case 4:
5100 case 5:
5101 item = 23585; break; // Stouthammer Lite
5102 case 6:
5103 item = 23586; break; // Aerie Peak Pale Ale
5105 if (item)
5106 DoCreateItem(effIndex,item);
5107 break;
5109 // Improved Sprint
5110 case 30918:
5112 if(!unitTarget)
5113 return;
5114 // Removes snares and roots.
5115 unitTarget->RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK,30918,true);
5116 break;
5118 // Flame Crash
5119 case 41126:
5121 if(!unitTarget)
5122 return;
5124 unitTarget->CastSpell(unitTarget, 41131, true);
5125 break;
5127 // Force Cast - Portal Effect: Sunwell Isle
5128 case 44876:
5130 if(!unitTarget)
5131 return;
5133 unitTarget->CastSpell(unitTarget, 44870, true);
5134 break;
5136 // Goblin Weather Machine
5137 case 46203:
5139 if(!unitTarget)
5140 return;
5142 uint32 spellId = 0;
5143 switch(rand() % 4)
5145 case 0: spellId = 46740; break;
5146 case 1: spellId = 46739; break;
5147 case 2: spellId = 46738; break;
5148 case 3: spellId = 46736; break;
5150 unitTarget->CastSpell(unitTarget, spellId, true);
5151 break;
5153 //5,000 Gold
5154 case 46642:
5156 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5157 return;
5159 ((Player*)unitTarget)->ModifyMoney(50000000);
5161 break;
5163 // Surge Needle Teleporter
5164 case 47097:
5166 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5167 return;
5169 if (unitTarget->GetAreaId() == 4156)
5170 unitTarget->CastSpell(unitTarget, 47324, true);
5171 else if (unitTarget->GetAreaId() == 4157)
5172 unitTarget->CastSpell(unitTarget, 47325, true);
5174 break;
5176 // High Executor's Branding Iron
5177 case 48603:
5178 // Torture the Torturer: High Executor's Branding Iron Impact
5179 unitTarget->CastSpell(unitTarget, 48614, true);
5180 return;
5181 // Emblazon Runeblade
5182 case 51770:
5184 if(!m_originalCaster)
5185 return;
5187 m_originalCaster->CastSpell(m_originalCaster, damage, false);
5188 break;
5190 // Death Gate
5191 case 52751:
5193 if(!unitTarget || unitTarget->getClass() != CLASS_DEATH_KNIGHT)
5194 return;
5195 // triggered spell is stored in m_spellInfo->EffectBasePoints[0]
5196 unitTarget->CastSpell(unitTarget, damage, false);
5197 break;
5199 // Winged Steed of the Ebon Blade
5200 case 54729:
5202 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5203 return;
5205 // Prevent stacking of mounts
5206 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
5208 // Triggered spell id dependent of riding skill
5209 if(uint16 skillval = ((Player*)unitTarget)->GetSkillValue(SKILL_RIDING))
5211 if (skillval >= 300)
5212 unitTarget->CastSpell(unitTarget, 54727, true);
5213 else
5214 unitTarget->CastSpell(unitTarget, 54726, true);
5216 return;
5218 // Demonic Empowerment (succubus Vanish effect)
5219 case 54436:
5221 if(!unitTarget)
5222 return;
5224 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
5225 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
5226 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STALKED);
5227 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STUN);
5228 return;
5230 case 55693: // Remove Collapsing Cave Aura
5231 if(!unitTarget)
5232 return;
5233 unitTarget->RemoveAurasDueToSpell(m_spellInfo->CalculateSimpleValue(effIndex));
5234 break;
5235 case 58418: // Portal to Orgrimmar
5236 case 58420: // Portal to Stormwind
5238 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER || effIndex!=0)
5239 return;
5241 uint32 spellID = m_spellInfo->CalculateSimpleValue(0);
5242 uint32 questID = m_spellInfo->CalculateSimpleValue(1);
5244 if (((Player*)unitTarget)->GetQuestStatus(questID) == QUEST_STATUS_COMPLETE && !((Player*)unitTarget)->GetQuestRewardStatus (questID))
5245 unitTarget->CastSpell(unitTarget, spellID, true);
5247 return;
5249 case 59317: // Teleporting
5250 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5251 return;
5253 // return from top
5254 if (((Player*)unitTarget)->GetAreaId() == 4637)
5255 unitTarget->CastSpell(unitTarget, 59316, true);
5256 // teleport atop
5257 else
5258 unitTarget->CastSpell(unitTarget, 59314, true);
5260 return;
5261 // random spell learn instead placeholder
5262 case 60893: // Northrend Alchemy Research
5263 case 61177: // Northrend Inscription Research
5264 case 61288: // Minor Inscription Research
5265 case 61756: // Northrend Inscription Research (FAST QA VERSION)
5266 case 64323: // Book of Glyph Mastery
5268 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5269 return;
5271 // learn random explicit discovery recipe (if any)
5272 if(uint32 discoveredSpell = GetExplicitDiscoverySpell(m_spellInfo->Id, (Player*)m_caster))
5273 ((Player*)m_caster)->learnSpell(discoveredSpell, false);
5274 return;
5277 break;
5279 case SPELLFAMILY_WARLOCK:
5281 switch(m_spellInfo->Id)
5283 // Healthstone creating spells
5284 case 6201:
5285 case 6202:
5286 case 5699:
5287 case 11729:
5288 case 11730:
5289 case 27230:
5290 case 47871:
5291 case 47878:
5293 if(!unitTarget)
5294 return;
5295 uint32 itemtype;
5296 uint32 rank = 0;
5297 Unit::AuraList const& mDummyAuras = unitTarget->GetAurasByType(SPELL_AURA_DUMMY);
5298 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
5300 if((*i)->GetId() == 18692)
5302 rank = 1;
5303 break;
5305 else if((*i)->GetId() == 18693)
5307 rank = 2;
5308 break;
5312 static uint32 const itypes[8][3] = {
5313 { 5512, 19004, 19005}, // Minor Healthstone
5314 { 5511, 19006, 19007}, // Lesser Healthstone
5315 { 5509, 19008, 19009}, // Healthstone
5316 { 5510, 19010, 19011}, // Greater Healthstone
5317 { 9421, 19012, 19013}, // Major Healthstone
5318 {22103, 22104, 22105}, // Master Healthstone
5319 {36889, 36890, 36891}, // Demonic Healthstone
5320 {36892, 36893, 36894} // Fel Healthstone
5323 switch(m_spellInfo->Id)
5325 case 6201:
5326 itemtype=itypes[0][rank];break; // Minor Healthstone
5327 case 6202:
5328 itemtype=itypes[1][rank];break; // Lesser Healthstone
5329 case 5699:
5330 itemtype=itypes[2][rank];break; // Healthstone
5331 case 11729:
5332 itemtype=itypes[3][rank];break; // Greater Healthstone
5333 case 11730:
5334 itemtype=itypes[4][rank];break; // Major Healthstone
5335 case 27230:
5336 itemtype=itypes[5][rank];break; // Master Healthstone
5337 case 47871:
5338 itemtype=itypes[6][rank];break; // Demonic Healthstone
5339 case 47878:
5340 itemtype=itypes[7][rank];break; // Fel Healthstone
5341 default:
5342 return;
5344 DoCreateItem( effIndex, itemtype );
5345 return;
5347 // Demonic Empowerment
5348 case 47193:
5350 if(!unitTarget)
5351 return;
5352 uint32 entry = unitTarget->GetEntry();
5353 uint32 spellID;
5354 switch(entry)
5356 case 416: spellID = 54444; break; //imp
5357 case 417: spellID = 54509; break; //fellhunter
5358 case 1860: spellID = 54443; break; //void
5359 case 1863: spellID = 54435; break; //succubus
5360 case 17252: spellID = 54508; break; //fellguard
5361 default:
5362 return;
5364 unitTarget->CastSpell(unitTarget,spellID,true);
5365 return;
5367 // Everlasting Affliction
5368 case 47422:
5370 // Need refresh caster corruption auras on target
5371 Unit::AuraMap& suAuras = unitTarget->GetAuras();
5372 for(Unit::AuraMap::iterator itr = suAuras.begin(); itr != suAuras.end(); ++itr)
5374 SpellEntry const *spellInfo = (*itr).second->GetSpellProto();
5375 if(spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK &&
5376 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000002)) &&
5377 (*itr).second->GetCasterGUID()==m_caster->GetGUID())
5378 (*itr).second->RefreshAura();
5380 return;
5382 // Guarded by The Light (Paladin spell with SPELLFAMILY_WARLOCK)
5383 case 63521:
5385 // Divine Plea, refresh on target (3 aura slots)
5386 if (Aura* aura = unitTarget->GetAura(54428,0))
5387 aura->RefreshAura();
5388 return;
5391 break;
5393 case SPELLFAMILY_PRIEST:
5395 switch(m_spellInfo->Id)
5397 // Pain and Suffering
5398 case 47948:
5400 if (!unitTarget)
5401 return;
5402 // Refresh Shadow Word: Pain on target
5403 Unit::AuraMap& auras = unitTarget->GetAuras();
5404 for(Unit::AuraMap::iterator itr = auras.begin(); itr != auras.end(); ++itr)
5406 SpellEntry const *spellInfo = (*itr).second->GetSpellProto();
5407 if (spellInfo->SpellFamilyName == SPELLFAMILY_PRIEST &&
5408 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000008000)) &&
5409 (*itr).second->GetCasterGUID() == m_caster->GetGUID())
5411 (*itr).second->RefreshAura();
5412 return;
5415 return;
5417 default:
5418 break;
5420 break;
5422 case SPELLFAMILY_HUNTER:
5424 switch(m_spellInfo->Id)
5426 // Chimera Shot
5427 case 53209:
5429 if(!unitTarget)
5430 return;
5431 uint32 spellId = 0;
5432 int32 basePoint = 0;
5433 Unit* target = unitTarget;
5434 Unit::AuraMap& Auras = unitTarget->GetAuras();
5435 for(Unit::AuraMap::iterator i = Auras.begin(); i != Auras.end(); ++i)
5437 Aura *aura = (*i).second;
5438 if (aura->GetCasterGUID() != m_caster->GetGUID())
5439 continue;
5440 // Search only Serpent Sting, Viper Sting, Scorpid Sting auras
5441 uint64 familyFlag = aura->GetSpellProto()->SpellFamilyFlags;
5442 if (!(familyFlag & UI64LIT(0x000000800000C000)))
5443 continue;
5444 // Refresh aura duration
5445 aura->RefreshAura();
5447 // Serpent Sting - Instantly deals 40% of the damage done by your Serpent Sting.
5448 if ((familyFlag & UI64LIT(0x0000000000004000)) && aura->GetEffIndex() == 0)
5450 // m_amount already include RAP bonus
5451 basePoint = aura->GetModifier()->m_amount * 5 * 40 / 100;
5452 spellId = 53353; // Chimera Shot - Serpent
5454 // Viper Sting - Instantly restores mana to you equal to 60% of the total amount drained by your Viper Sting.
5455 if ((familyFlag & UI64LIT(0x0000008000000000)) && aura->GetEffIndex() == 0)
5457 uint32 target_max_mana = unitTarget->GetMaxPower(POWER_MANA);
5458 if (!target_max_mana)
5459 continue;
5461 // ignore non positive values (can be result apply spellmods to aura damage
5462 uint32 pdamage = aura->GetModifier()->m_amount > 0 ? aura->GetModifier()->m_amount : 0;
5464 // Special case: draining x% of mana (up to a maximum of 2*x% of the caster's maximum mana)
5465 uint32 maxmana = m_caster->GetMaxPower(POWER_MANA) * pdamage * 2 / 100;
5467 pdamage = target_max_mana * pdamage / 100;
5468 if (pdamage > maxmana)
5469 pdamage = maxmana;
5471 pdamage *= 4; // total aura damage
5472 basePoint = pdamage * 60 / 100;
5473 spellId = 53358; // Chimera Shot - Viper
5474 target = m_caster;
5476 // Scorpid Sting - Attempts to Disarm the target for 10 sec. This effect cannot occur more than once per 1 minute.
5477 if (familyFlag & UI64LIT(0x0000000000008000))
5478 spellId = 53359; // Chimera Shot - Scorpid
5479 // ?? nothing say in spell desc (possibly need addition check)
5480 //if ((familyFlag & UI64LIT(0x0000010000000000)) || // dot
5481 // (familyFlag & UI64LIT(0x0000100000000000))) // stun
5483 // spellId = 53366; // 53366 Chimera Shot - Wyvern
5486 if (spellId)
5487 m_caster->CastCustomSpell(target, spellId, &basePoint, 0, 0, false);
5488 return;
5490 case 53412: // Invigoration (pet triggered script, master targeted)
5492 if (!unitTarget)
5493 return;
5495 Unit::AuraList const& auras = unitTarget->GetAurasByType(SPELL_AURA_DUMMY);
5496 for(Unit::AuraList::const_iterator i = auras.begin();i != auras.end(); ++i)
5498 // Invigoration (master talent)
5499 if ((*i)->GetModifier()->m_miscvalue == 8 && (*i)->GetSpellProto()->SpellIconID == 3487)
5501 if (roll_chance_i((*i)->GetModifier()->m_amount))
5503 unitTarget->CastSpell(unitTarget, 53398, true, NULL, (*i), m_caster->GetGUID());
5504 break;
5508 return;
5510 // Master's Call
5511 case 53271:
5513 if (!unitTarget)
5514 return;
5516 // script effect have in value, but this outdated removed part
5517 unitTarget->CastSpell(unitTarget, 62305, true);
5518 return;
5520 default:
5521 break;
5523 break;
5525 case SPELLFAMILY_PALADIN:
5527 // Judgement (seal trigger)
5528 if (m_spellInfo->Category == SPELLCATEGORY_JUDGEMENT)
5530 if(!unitTarget || !unitTarget->isAlive())
5531 return;
5532 uint32 spellId1 = 0;
5533 uint32 spellId2 = 0;
5535 // Judgement self add switch
5536 switch (m_spellInfo->Id)
5538 case 53407: spellId1 = 20184; break; // Judgement of Justice
5539 case 20271: // Judgement of Light
5540 case 57774: spellId1 = 20185; break; // Judgement of Light
5541 case 53408: spellId1 = 20186; break; // Judgement of Wisdom
5542 default:
5543 sLog.outError("Unsupported Judgement (seal trigger) spell (Id: %u) in Spell::EffectScriptEffect",m_spellInfo->Id);
5544 return;
5546 // offensive seals have aura dummy in 2 effect
5547 Unit::AuraList const& m_dummyAuras = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
5548 for(Unit::AuraList::const_iterator itr = m_dummyAuras.begin(); itr != m_dummyAuras.end(); ++itr)
5550 // search seal (offensive seals have judgement's aura dummy spell id in 2 effect
5551 if ((*itr)->GetEffIndex() != 2 || !IsSealSpell((*itr)->GetSpellProto()))
5552 continue;
5553 spellId2 = (*itr)->GetModifier()->m_amount;
5554 SpellEntry const *judge = sSpellStore.LookupEntry(spellId2);
5555 if (!judge)
5556 continue;
5557 break;
5559 // if there were no offensive seals than there is seal with proc trigger aura
5560 if (!spellId2)
5562 Unit::AuraList const& procTriggerAuras = m_caster->GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL);
5563 for(Unit::AuraList::const_iterator itr = procTriggerAuras.begin(); itr != procTriggerAuras.end(); ++itr)
5565 if ((*itr)->GetEffIndex() != 0 || !IsSealSpell((*itr)->GetSpellProto()))
5566 continue;
5567 spellId2 = 54158;
5568 break;
5571 if (spellId1)
5572 m_caster->CastSpell(unitTarget, spellId1, true);
5573 if (spellId2)
5574 m_caster->CastSpell(unitTarget, spellId2, true);
5575 return;
5578 case SPELLFAMILY_POTION:
5580 switch(m_spellInfo->Id)
5582 // Dreaming Glory
5583 case 28698:
5585 if(!unitTarget)
5586 return;
5587 unitTarget->CastSpell(unitTarget, 28694, true);
5588 break;
5590 // Netherbloom
5591 case 28702:
5593 if(!unitTarget)
5594 return;
5595 // 25% chance of casting a random buff
5596 if(roll_chance_i(75))
5597 return;
5599 // triggered spells are 28703 to 28707
5600 // Note: some sources say, that there was the possibility of
5601 // receiving a debuff. However, this seems to be removed by a patch.
5602 const uint32 spellid = 28703;
5604 // don't overwrite an existing aura
5605 for(uint8 i = 0; i < 5; ++i)
5606 if(unitTarget->HasAura(spellid + i, 0))
5607 return;
5608 unitTarget->CastSpell(unitTarget, spellid+urand(0, 4), true);
5609 break;
5612 // Nightmare Vine
5613 case 28720:
5615 if(!unitTarget)
5616 return;
5617 // 25% chance of casting Nightmare Pollen
5618 if(roll_chance_i(75))
5619 return;
5620 unitTarget->CastSpell(unitTarget, 28721, true);
5621 break;
5624 break;
5626 case SPELLFAMILY_DEATHKNIGHT:
5628 switch(m_spellInfo->Id)
5630 // Pestilence
5631 case 50842:
5633 if(!unitTarget)
5634 return;
5636 Unit* mainTarget = m_targets.getUnitTarget();
5637 if(!mainTarget)
5638 return;
5640 // do only refresh diseases on main target if caster has Glyph of Disease
5641 if(mainTarget == unitTarget && !m_caster->HasAura(63334))
5642 return;
5644 // Blood Plague
5645 if(mainTarget->HasAura(55078))
5646 m_caster->CastSpell(unitTarget, 55078, true);
5648 // Frost Fever
5649 if(mainTarget->HasAura(55095))
5650 m_caster->CastSpell(unitTarget, 55095, true);
5652 break;
5655 break;
5659 // normal DB scripted effect
5660 if(!unitTarget)
5661 return;
5663 sLog.outDebug("Spell ScriptStart spellid %u in EffectScriptEffect ", m_spellInfo->Id);
5664 m_caster->GetMap()->ScriptsStart(sSpellScripts, m_spellInfo->Id, m_caster, unitTarget);
5667 void Spell::EffectSanctuary(uint32 /*i*/)
5669 if(!unitTarget)
5670 return;
5671 //unitTarget->CombatStop();
5673 unitTarget->CombatStop();
5674 unitTarget->getHostileRefManager().deleteReferences(); // stop all fighting
5675 // Vanish allows to remove all threat and cast regular stealth so other spells can be used
5676 if(m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && (m_spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE_VANISH))
5678 ((Player *)m_caster)->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
5682 void Spell::EffectAddComboPoints(uint32 /*i*/)
5684 if(!unitTarget)
5685 return;
5687 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5688 return;
5690 if(damage <= 0)
5691 return;
5693 ((Player*)m_caster)->AddComboPoints(unitTarget, damage);
5696 void Spell::EffectDuel(uint32 i)
5698 if(!m_caster || !unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER || unitTarget->GetTypeId() != TYPEID_PLAYER)
5699 return;
5701 Player *caster = (Player*)m_caster;
5702 Player *target = (Player*)unitTarget;
5704 // caster or target already have requested duel
5705 if( caster->duel || target->duel || !target->GetSocial() || target->GetSocial()->HasIgnore(caster->GetGUIDLow()) )
5706 return;
5708 // Players can only fight a duel with each other outside (=not inside dungeons and not in capital cities)
5709 // Don't have to check the target's map since you cannot challenge someone across maps
5710 uint32 mapid = caster->GetMapId();
5711 if( mapid != 0 && mapid != 1 && mapid != 530 && mapid != 571 && mapid != 609)
5713 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5714 return;
5717 AreaTableEntry const* casterAreaEntry = GetAreaEntryByAreaID(caster->GetZoneId());
5718 if(casterAreaEntry && (casterAreaEntry->flags & AREA_FLAG_CAPITAL) )
5720 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5721 return;
5724 AreaTableEntry const* targetAreaEntry = GetAreaEntryByAreaID(target->GetZoneId());
5725 if(targetAreaEntry && (targetAreaEntry->flags & AREA_FLAG_CAPITAL) )
5727 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5728 return;
5731 //CREATE DUEL FLAG OBJECT
5732 GameObject* pGameObj = new GameObject;
5734 uint32 gameobject_id = m_spellInfo->EffectMiscValue[i];
5736 Map *map = m_caster->GetMap();
5737 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id,
5738 map, m_caster->GetPhaseMask(),
5739 m_caster->GetPositionX()+(unitTarget->GetPositionX()-m_caster->GetPositionX())/2 ,
5740 m_caster->GetPositionY()+(unitTarget->GetPositionY()-m_caster->GetPositionY())/2 ,
5741 m_caster->GetPositionZ(),
5742 m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
5744 delete pGameObj;
5745 return;
5748 pGameObj->SetUInt32Value(GAMEOBJECT_FACTION, m_caster->getFaction() );
5749 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()+1 );
5750 int32 duration = GetSpellDuration(m_spellInfo);
5751 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
5752 pGameObj->SetSpellId(m_spellInfo->Id);
5754 m_caster->AddGameObject(pGameObj);
5755 map->Add(pGameObj);
5756 //END
5758 // Send request
5759 WorldPacket data(SMSG_DUEL_REQUESTED, 8 + 8);
5760 data << uint64(pGameObj->GetGUID());
5761 data << uint64(caster->GetGUID());
5762 caster->GetSession()->SendPacket(&data);
5763 target->GetSession()->SendPacket(&data);
5765 // create duel-info
5766 DuelInfo *duel = new DuelInfo;
5767 duel->initiator = caster;
5768 duel->opponent = target;
5769 duel->startTime = 0;
5770 duel->startTimer = 0;
5771 caster->duel = duel;
5773 DuelInfo *duel2 = new DuelInfo;
5774 duel2->initiator = caster;
5775 duel2->opponent = caster;
5776 duel2->startTime = 0;
5777 duel2->startTimer = 0;
5778 target->duel = duel2;
5780 caster->SetUInt64Value(PLAYER_DUEL_ARBITER, pGameObj->GetGUID());
5781 target->SetUInt64Value(PLAYER_DUEL_ARBITER, pGameObj->GetGUID());
5784 void Spell::EffectStuck(uint32 /*i*/)
5786 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5787 return;
5789 if(!sWorld.getConfig(CONFIG_CAST_UNSTUCK))
5790 return;
5792 Player* pTarget = (Player*)unitTarget;
5794 sLog.outDebug("Spell Effect: Stuck");
5795 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());
5797 if(pTarget->isInFlight())
5798 return;
5800 // homebind location is loaded always
5801 pTarget->TeleportToHomebind(unitTarget==m_caster ? TELE_TO_SPELL : 0);
5803 // Stuck spell trigger Hearthstone cooldown
5804 SpellEntry const *spellInfo = sSpellStore.LookupEntry(8690);
5805 if(!spellInfo)
5806 return;
5807 Spell spell(pTarget, spellInfo, true, 0);
5808 spell.SendSpellCooldown();
5811 void Spell::EffectSummonPlayer(uint32 /*i*/)
5813 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5814 return;
5816 // Evil Twin (ignore player summon, but hide this for summoner)
5817 if(unitTarget->GetDummyAura(23445))
5818 return;
5820 float x, y, z;
5821 m_caster->GetClosePoint(x, y, z, unitTarget->GetObjectSize());
5823 ((Player*)unitTarget)->SetSummonPoint(m_caster->GetMapId(),x,y,z);
5825 WorldPacket data(SMSG_SUMMON_REQUEST, 8+4+4);
5826 data << uint64(m_caster->GetGUID()); // summoner guid
5827 data << uint32(m_caster->GetZoneId()); // summoner zone
5828 data << uint32(MAX_PLAYER_SUMMON_DELAY*IN_MILISECONDS); // auto decline after msecs
5829 ((Player*)unitTarget)->GetSession()->SendPacket(&data);
5832 static ScriptInfo generateActivateCommand()
5834 ScriptInfo si;
5835 si.command = SCRIPT_COMMAND_ACTIVATE_OBJECT;
5836 return si;
5839 void Spell::EffectActivateObject(uint32 effect_idx)
5841 if(!gameObjTarget)
5842 return;
5844 static ScriptInfo activateCommand = generateActivateCommand();
5846 int32 delay_secs = m_spellInfo->EffectMiscValue[effect_idx];
5848 gameObjTarget->GetMap()->ScriptCommandStart(activateCommand, delay_secs, m_caster, gameObjTarget);
5851 void Spell::EffectApplyGlyph(uint32 i)
5853 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5854 return;
5856 Player *player = (Player*)m_caster;
5858 // apply new one
5859 if(uint32 glyph = m_spellInfo->EffectMiscValue[i])
5861 if(GlyphPropertiesEntry const *gp = sGlyphPropertiesStore.LookupEntry(glyph))
5863 if(GlyphSlotEntry const *gs = sGlyphSlotStore.LookupEntry(player->GetGlyphSlot(m_glyphIndex)))
5865 if(gp->TypeFlags != gs->TypeFlags)
5867 SendCastResult(SPELL_FAILED_INVALID_GLYPH);
5868 return; // glyph slot mismatch
5872 // remove old glyph
5873 if(uint32 oldglyph = player->GetGlyph(m_glyphIndex))
5875 if(GlyphPropertiesEntry const *old_gp = sGlyphPropertiesStore.LookupEntry(oldglyph))
5877 player->RemoveAurasDueToSpell(old_gp->SpellId);
5878 player->SetGlyph(m_glyphIndex, 0);
5882 player->CastSpell(m_caster, gp->SpellId, true);
5883 player->SetGlyph(m_glyphIndex, glyph);
5884 player->SendTalentsInfoData(false);
5889 void Spell::EffectSummonTotem(uint32 i, uint8 slot)
5891 slot = slot ? (slot - 1): 255;
5893 if(slot < MAX_TOTEM)
5895 uint64 guid = m_caster->m_TotemSlot[slot];
5896 if(guid != 0)
5898 Creature *OldTotem = m_caster->GetMap()->GetCreature(guid);
5899 if(OldTotem && OldTotem->isTotem())
5900 ((Totem*)OldTotem)->UnSummon();
5904 uint32 team = 0;
5905 if (m_caster->GetTypeId()==TYPEID_PLAYER)
5906 team = ((Player*)m_caster)->GetTeam();
5908 Totem* pTotem = new Totem;
5910 if(!pTotem->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), m_caster->GetMap(), m_caster->GetPhaseMask(),
5911 m_spellInfo->EffectMiscValue[i], team ))
5913 delete pTotem;
5914 return;
5917 float angle = slot < MAX_TOTEM ? M_PI/MAX_TOTEM - (slot*2*M_PI/MAX_TOTEM) : 0;
5919 float x, y, z;
5920 m_caster->GetClosePoint(x, y, z, pTotem->GetObjectSize(), 2.0f, angle);
5922 // totem must be at same Z in case swimming caster and etc.
5923 if( fabs( z - m_caster->GetPositionZ() ) > 5 )
5924 z = m_caster->GetPositionZ();
5926 pTotem->Relocate(x, y, z, m_caster->GetOrientation());
5928 if(slot < MAX_TOTEM)
5929 m_caster->m_TotemSlot[slot] = pTotem->GetGUID();
5931 pTotem->SetOwner(m_caster->GetGUID());
5932 pTotem->SetTypeBySummonSpell(m_spellInfo); // must be after Create call where m_spells initilized
5934 int32 duration=GetSpellDuration(m_spellInfo);
5935 if(Player* modOwner = m_caster->GetSpellModOwner())
5936 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
5937 pTotem->SetDuration(duration);
5939 if (damage) // if not spell info, DB values used
5941 pTotem->SetMaxHealth(damage);
5942 pTotem->SetHealth(damage);
5945 pTotem->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
5947 if(m_caster->GetTypeId() == TYPEID_PLAYER)
5948 pTotem->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
5950 if(m_caster->IsPvP())
5951 pTotem->SetPvP(true);
5953 pTotem->Summon(m_caster);
5955 if(slot < MAX_TOTEM && m_caster->GetTypeId() == TYPEID_PLAYER)
5957 WorldPacket data(SMSG_TOTEM_CREATED, 1 + 8 + 4 + 4);
5958 data << uint8(slot);
5959 data << uint64(pTotem->GetGUID());
5960 data << uint32(duration);
5961 data << uint32(m_spellInfo->Id);
5962 ((Player*)m_caster)->SendDirectMessage(&data);
5966 void Spell::EffectEnchantHeldItem(uint32 i)
5968 // this is only item spell effect applied to main-hand weapon of target player (players in area)
5969 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5970 return;
5972 Player* item_owner = (Player*)unitTarget;
5973 Item* item = item_owner->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
5975 if(!item )
5976 return;
5978 // must be equipped
5979 if(!item ->IsEquipped())
5980 return;
5982 if (m_spellInfo->EffectMiscValue[i])
5984 uint32 enchant_id = m_spellInfo->EffectMiscValue[i];
5985 int32 duration = GetSpellDuration(m_spellInfo); //Try duration index first ..
5986 if(!duration)
5987 duration = m_currentBasePoints[i]+1; //Base points after ..
5988 if(!duration)
5989 duration = 10; //10 seconds for enchants which don't have listed duration
5991 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
5992 if(!pEnchant)
5993 return;
5995 // Always go to temp enchantment slot
5996 EnchantmentSlot slot = TEMP_ENCHANTMENT_SLOT;
5998 // Enchantment will not be applied if a different one already exists
5999 if(item->GetEnchantmentId(slot) && item->GetEnchantmentId(slot) != enchant_id)
6000 return;
6002 // Apply the temporary enchantment
6003 item->SetEnchantment(slot, enchant_id, duration*IN_MILISECONDS, 0);
6004 item_owner->ApplyEnchantment(item, slot, true);
6008 void Spell::EffectDisEnchant(uint32 /*i*/)
6010 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6011 return;
6013 Player* p_caster = (Player*)m_caster;
6014 if(!itemTarget || !itemTarget->GetProto()->DisenchantID)
6015 return;
6017 p_caster->UpdateCraftSkill(m_spellInfo->Id);
6019 ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(),LOOT_DISENCHANTING);
6021 // item will be removed at disenchanting end
6024 void Spell::EffectInebriate(uint32 /*i*/)
6026 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6027 return;
6029 Player *player = (Player*)unitTarget;
6030 uint16 currentDrunk = player->GetDrunkValue();
6031 uint16 drunkMod = damage * 256;
6032 if (currentDrunk + drunkMod > 0xFFFF)
6033 currentDrunk = 0xFFFF;
6034 else
6035 currentDrunk += drunkMod;
6036 player->SetDrunkValue(currentDrunk, m_CastItem ? m_CastItem->GetEntry() : 0);
6039 void Spell::EffectFeedPet(uint32 i)
6041 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6042 return;
6044 Player *_player = (Player*)m_caster;
6046 Item* foodItem = m_targets.getItemTarget();
6047 if(!foodItem)
6048 return;
6050 Pet *pet = _player->GetPet();
6051 if(!pet)
6052 return;
6054 if(!pet->isAlive())
6055 return;
6057 int32 benefit = pet->GetCurrentFoodBenefitLevel(foodItem->GetProto()->ItemLevel);
6058 if(benefit <= 0)
6059 return;
6061 uint32 count = 1;
6062 _player->DestroyItemCount(foodItem,count,true);
6063 // TODO: fix crash when a spell has two effects, both pointed at the same item target
6065 m_caster->CastCustomSpell(pet, m_spellInfo->EffectTriggerSpell[i], &benefit, NULL, NULL, true);
6068 void Spell::EffectDismissPet(uint32 /*i*/)
6070 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6071 return;
6073 Pet* pet = m_caster->GetPet();
6075 // not let dismiss dead pet
6076 if(!pet||!pet->isAlive())
6077 return;
6079 ((Player*)m_caster)->RemovePet(pet, PET_SAVE_NOT_IN_SLOT);
6082 void Spell::EffectSummonObject(uint32 i)
6084 uint32 go_id = m_spellInfo->EffectMiscValue[i];
6086 uint8 slot = 0;
6087 switch(m_spellInfo->Effect[i])
6089 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1: slot = 0; break;
6090 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2: slot = 1; break;
6091 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3: slot = 2; break;
6092 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4: slot = 3; break;
6093 default: return;
6096 if(uint64 guid = m_caster->m_ObjectSlot[slot])
6098 if(GameObject* obj = m_caster ? m_caster->GetMap()->GetGameObject(guid) : NULL)
6099 obj->SetLootState(GO_JUST_DEACTIVATED);
6100 m_caster->m_ObjectSlot[slot] = 0;
6103 GameObject* pGameObj = new GameObject;
6105 float x, y, z;
6106 // If dest location if present
6107 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6109 x = m_targets.m_destX;
6110 y = m_targets.m_destY;
6111 z = m_targets.m_destZ;
6113 // Summon in random point all other units if location present
6114 else
6115 m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE);
6117 Map *map = m_caster->GetMap();
6118 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), go_id, map,
6119 m_caster->GetPhaseMask(), x, y, z, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
6121 delete pGameObj;
6122 return;
6125 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL,m_caster->getLevel());
6126 int32 duration = GetSpellDuration(m_spellInfo);
6127 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
6128 pGameObj->SetSpellId(m_spellInfo->Id);
6129 m_caster->AddGameObject(pGameObj);
6131 map->Add(pGameObj);
6133 m_caster->m_ObjectSlot[slot] = pGameObj->GetGUID();
6136 void Spell::EffectResurrect(uint32 /*effIndex*/)
6138 if(!unitTarget)
6139 return;
6140 if(unitTarget->GetTypeId() != TYPEID_PLAYER)
6141 return;
6143 if(unitTarget->isAlive())
6144 return;
6145 if(!unitTarget->IsInWorld())
6146 return;
6148 switch (m_spellInfo->Id)
6150 // Defibrillate (Goblin Jumper Cables) have 33% chance on success
6151 case 8342:
6152 if (roll_chance_i(67))
6154 m_caster->CastSpell(m_caster, 8338, true, m_CastItem);
6155 return;
6157 break;
6158 // Defibrillate (Goblin Jumper Cables XL) have 50% chance on success
6159 case 22999:
6160 if (roll_chance_i(50))
6162 m_caster->CastSpell(m_caster, 23055, true, m_CastItem);
6163 return;
6165 break;
6166 default:
6167 break;
6170 Player* pTarget = ((Player*)unitTarget);
6172 if(pTarget->isRessurectRequested()) // already have one active request
6173 return;
6175 uint32 health = pTarget->GetMaxHealth() * damage / 100;
6176 uint32 mana = pTarget->GetMaxPower(POWER_MANA) * damage / 100;
6178 pTarget->setResurrectRequestData(m_caster->GetGUID(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), health, mana);
6179 SendResurrectRequest(pTarget);
6182 void Spell::EffectAddExtraAttacks(uint32 /*i*/)
6184 if(!unitTarget || !unitTarget->isAlive())
6185 return;
6187 if( unitTarget->m_extraAttacks )
6188 return;
6190 unitTarget->m_extraAttacks = damage;
6193 void Spell::EffectParry(uint32 /*i*/)
6195 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6196 ((Player*)unitTarget)->SetCanParry(true);
6199 void Spell::EffectBlock(uint32 /*i*/)
6201 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6202 ((Player*)unitTarget)->SetCanBlock(true);
6205 void Spell::EffectLeapForward(uint32 i)
6207 if(unitTarget->isInFlight())
6208 return;
6210 if( m_spellInfo->rangeIndex == 1) //self range
6212 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
6214 // before caster
6215 float fx, fy, fz;
6216 unitTarget->GetClosePoint(fx, fy, fz, unitTarget->GetObjectSize(), dis);
6217 float ox, oy, oz;
6218 unitTarget->GetPosition(ox, oy, oz);
6220 float fx2, fy2, fz2; // getObjectHitPos overwrite last args in any result case
6221 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(unitTarget->GetMapId(), ox,oy,oz+0.5, fx,fy,oz+0.5,fx2,fy2,fz2, -0.5))
6223 fx = fx2;
6224 fy = fy2;
6225 fz = fz2;
6226 unitTarget->UpdateGroundPositionZ(fx, fy, fz);
6229 unitTarget->NearTeleportTo(fx, fy, fz, unitTarget->GetOrientation(), unitTarget == m_caster);
6233 void Spell::EffectLeapBack(uint32 i)
6235 if(unitTarget->isInFlight())
6236 return;
6238 m_caster->KnockBackFrom(unitTarget,float(m_spellInfo->EffectMiscValue[i])/10,float(damage)/10);
6241 void Spell::EffectReputation(uint32 i)
6243 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6244 return;
6246 Player *_player = (Player*)unitTarget;
6248 int32 rep_change = m_currentBasePoints[i]+1; // field store reputation change -1
6250 uint32 faction_id = m_spellInfo->EffectMiscValue[i];
6252 FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id);
6254 if(!factionEntry)
6255 return;
6257 _player->GetReputationMgr().ModifyReputation(factionEntry, rep_change);
6260 void Spell::EffectQuestComplete(uint32 i)
6262 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6263 return;
6265 Player *_player = (Player*)m_caster;
6267 uint32 quest_id = m_spellInfo->EffectMiscValue[i];
6268 _player->AreaExploredOrEventHappens(quest_id);
6271 void Spell::EffectSelfResurrect(uint32 i)
6273 if(!unitTarget || unitTarget->isAlive())
6274 return;
6275 if(unitTarget->GetTypeId() != TYPEID_PLAYER)
6276 return;
6277 if(!unitTarget->IsInWorld())
6278 return;
6280 uint32 health = 0;
6281 uint32 mana = 0;
6283 // flat case
6284 if(damage < 0)
6286 health = uint32(-damage);
6287 mana = m_spellInfo->EffectMiscValue[i];
6289 // percent case
6290 else
6292 health = uint32(damage/100.0f*unitTarget->GetMaxHealth());
6293 if(unitTarget->GetMaxPower(POWER_MANA) > 0)
6294 mana = uint32(damage/100.0f*unitTarget->GetMaxPower(POWER_MANA));
6297 Player *plr = ((Player*)unitTarget);
6298 plr->ResurrectPlayer(0.0f);
6300 plr->SetHealth( health );
6301 plr->SetPower(POWER_MANA, mana );
6302 plr->SetPower(POWER_RAGE, 0 );
6303 plr->SetPower(POWER_ENERGY, plr->GetMaxPower(POWER_ENERGY) );
6305 plr->SpawnCorpseBones();
6308 void Spell::EffectSkinning(uint32 /*i*/)
6310 if(unitTarget->GetTypeId() != TYPEID_UNIT )
6311 return;
6312 if(!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER)
6313 return;
6315 Creature* creature = (Creature*) unitTarget;
6316 int32 targetLevel = creature->getLevel();
6318 uint32 skill = creature->GetCreatureInfo()->GetRequiredLootSkill();
6320 ((Player*)m_caster)->SendLoot(creature->GetGUID(),LOOT_SKINNING);
6321 creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
6323 int32 reqValue = targetLevel < 10 ? 0 : targetLevel < 20 ? (targetLevel-10)*10 : targetLevel*5;
6325 int32 skillValue = ((Player*)m_caster)->GetPureSkillValue(skill);
6327 // Double chances for elites
6328 ((Player*)m_caster)->UpdateGatherSkill(skill, skillValue, reqValue, creature->isElite() ? 2 : 1 );
6331 void Spell::EffectCharge(uint32 /*i*/)
6333 if (!unitTarget)
6334 return;
6336 //TODO: research more ContactPoint/attack distance.
6337 //3.666666 instead of ATTACK_DISTANCE(5.0f) in below seem to give more accurate result.
6338 float x, y, z;
6339 unitTarget->GetContactPoint(m_caster, x, y, z, 3.666666f);
6341 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6342 ((Creature *)unitTarget)->StopMoving();
6344 // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
6345 m_caster->SendMonsterMove(x, y, z, 0, m_caster->GetTypeId()==TYPEID_PLAYER ? MONSTER_MOVE_WALK : ((Creature*)m_caster)->GetMonsterMoveFlags(), 1);
6347 if (m_caster->GetTypeId() != TYPEID_PLAYER)
6348 m_caster->GetMap()->CreatureRelocation((Creature*)m_caster,x,y,z,m_caster->GetOrientation());
6350 // not all charge effects used in negative spells
6351 if (unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
6352 m_caster->Attack(unitTarget,true);
6355 void Spell::EffectCharge2(uint32 /*i*/)
6357 float x, y, z;
6358 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6360 x = m_targets.m_destX;
6361 y = m_targets.m_destY;
6362 z = m_targets.m_destZ;
6364 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6365 ((Creature *)unitTarget)->StopMoving();
6367 else if (unitTarget && unitTarget != m_caster)
6368 unitTarget->GetContactPoint(m_caster, x, y, z, 3.666666f);
6369 else
6370 return;
6372 // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
6373 m_caster->SendMonsterMove(x, y, z, 0, m_caster->GetTypeId()==TYPEID_PLAYER ? MONSTER_MOVE_WALK : ((Creature*)m_caster)->GetMonsterMoveFlags(), 1);
6375 if (m_caster->GetTypeId() != TYPEID_PLAYER)
6376 m_caster->GetMap()->CreatureRelocation((Creature*)m_caster,x,y,z,m_caster->GetOrientation());
6378 // not all charge effects used in negative spells
6379 if (unitTarget && unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
6380 m_caster->Attack(unitTarget,true);
6383 void Spell::EffectSummonCritter(uint32 i, uint32 forceFaction)
6385 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6386 return;
6387 Player* player = (Player*)m_caster;
6389 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
6390 if(!pet_entry)
6391 return;
6393 Pet* old_critter = player->GetMiniPet();
6395 // for same pet just despawn
6396 if(old_critter && old_critter->GetEntry() == pet_entry)
6398 player->RemoveMiniPet();
6399 return;
6402 // despawn old pet before summon new
6403 if(old_critter)
6404 player->RemoveMiniPet();
6406 // summon new pet
6407 Pet* critter = new Pet(MINI_PET);
6409 Map *map = m_caster->GetMap();
6410 uint32 pet_number = sObjectMgr.GeneratePetNumber();
6411 if(!critter->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
6412 pet_entry, pet_number))
6414 sLog.outError("Spell::EffectSummonCritter, spellid %u: no such creature entry %u", m_spellInfo->Id, pet_entry);
6415 delete critter;
6416 return;
6419 float x, y, z;
6420 // If dest location if present
6421 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6423 x = m_targets.m_destX;
6424 y = m_targets.m_destY;
6425 z = m_targets.m_destZ;
6427 // Summon if dest location not present near caster
6428 else
6429 m_caster->GetClosePoint(x, y, z, critter->GetObjectSize());
6431 critter->Relocate(x, y, z, m_caster->GetOrientation());
6433 if(!critter->IsPositionValid())
6435 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
6436 critter->GetGUIDLow(), critter->GetEntry(), critter->GetPositionX(), critter->GetPositionY());
6437 delete critter;
6438 return;
6441 critter->SetOwnerGUID(m_caster->GetGUID());
6442 critter->SetCreatorGUID(m_caster->GetGUID());
6444 critter->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
6445 critter->setFaction(forceFaction ? forceFaction : m_caster->getFaction());
6446 critter->AIM_Initialize();
6447 critter->InitPetCreateSpells(); // e.g. disgusting oozeling has a create spell as critter...
6448 //critter->InitLevelupSpellsForLevel(); // none?
6449 critter->SelectLevel(critter->GetCreatureInfo()); // some summoned creaters have different from 1 DB data for level/hp
6450 critter->SetUInt32Value(UNIT_NPC_FLAGS, critter->GetCreatureInfo()->npcflag);
6451 // some mini-pets have quests
6453 // set timer for unsummon
6454 int32 duration = GetSpellDuration(m_spellInfo);
6455 if(duration > 0)
6456 critter->SetDuration(duration);
6458 std::string name = player->GetName();
6459 name.append(petTypeSuffix[critter->getPetType()]);
6460 critter->SetName( name );
6461 player->SetMiniPet(critter);
6463 map->Add((Creature*)critter);
6466 void Spell::EffectKnockBack(uint32 i)
6468 if(!unitTarget)
6469 return;
6471 unitTarget->KnockBackFrom(m_caster,float(m_spellInfo->EffectMiscValue[i])/10,float(damage)/10);
6474 void Spell::EffectSendTaxi(uint32 i)
6476 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6477 return;
6479 ((Player*)unitTarget)->ActivateTaxiPathTo(m_spellInfo->EffectMiscValue[i],m_spellInfo->Id);
6482 void Spell::EffectPlayerPull(uint32 i)
6484 if(!unitTarget)
6485 return;
6487 float dist = unitTarget->GetDistance2d(m_caster);
6488 if (damage && dist > damage)
6489 dist = damage;
6491 unitTarget->KnockBackFrom(m_caster,-dist,float(m_spellInfo->EffectMiscValue[i])/10);
6494 void Spell::EffectDispelMechanic(uint32 i)
6496 if(!unitTarget)
6497 return;
6499 uint32 mechanic = m_spellInfo->EffectMiscValue[i];
6501 Unit::AuraMap& Auras = unitTarget->GetAuras();
6502 for(Unit::AuraMap::iterator iter = Auras.begin(), next; iter != Auras.end(); iter = next)
6504 next = iter;
6505 ++next;
6506 SpellEntry const *spell = sSpellStore.LookupEntry(iter->second->GetSpellProto()->Id);
6507 if(spell->Mechanic == mechanic || spell->EffectMechanic[iter->second->GetEffIndex()] == mechanic)
6509 unitTarget->RemoveAurasDueToSpell(spell->Id);
6510 if(Auras.empty())
6511 break;
6512 else
6513 next = Auras.begin();
6516 return;
6519 void Spell::EffectSummonDeadPet(uint32 /*i*/)
6521 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6522 return;
6523 Player *_player = (Player*)m_caster;
6524 Pet *pet = _player->GetPet();
6525 if(!pet)
6526 return;
6527 if(pet->isAlive())
6528 return;
6529 if(damage < 0)
6530 return;
6531 pet->SetUInt32Value(UNIT_DYNAMIC_FLAGS, 0);
6532 pet->RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
6533 pet->setDeathState( ALIVE );
6534 pet->clearUnitState(UNIT_STAT_ALL_STATE);
6535 pet->SetHealth( uint32(pet->GetMaxHealth()*(float(damage)/100)));
6537 pet->AIM_Initialize();
6539 // _player->PetSpellInitialize(); -- action bar not removed at death and not required send at revive
6540 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
6543 void Spell::EffectDestroyAllTotems(uint32 /*i*/)
6545 int32 mana = 0;
6546 for(int slot = 0; slot < MAX_TOTEM; ++slot)
6548 if(!m_caster->m_TotemSlot[slot])
6549 continue;
6551 Creature* totem = m_caster->GetMap()->GetCreature(m_caster->m_TotemSlot[slot]);
6552 if(totem && totem->isTotem())
6554 uint32 spell_id = totem->GetUInt32Value(UNIT_CREATED_BY_SPELL);
6555 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell_id);
6556 if(spellInfo)
6558 uint32 manacost = m_caster->GetCreateMana() * spellInfo->ManaCostPercentage / 100;
6559 mana += manacost * damage / 100;
6561 ((Totem*)totem)->UnSummon();
6565 if (mana)
6566 m_caster->CastCustomSpell(m_caster, 39104, &mana, NULL, NULL, true);
6569 void Spell::EffectDurabilityDamage(uint32 i)
6571 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6572 return;
6574 int32 slot = m_spellInfo->EffectMiscValue[i];
6576 // FIXME: some spells effects have value -1/-2
6577 // Possibly its mean -1 all player equipped items and -2 all items
6578 if(slot < 0)
6580 ((Player*)unitTarget)->DurabilityPointsLossAll(damage, (slot < -1));
6581 return;
6584 // invalid slot value
6585 if(slot >= INVENTORY_SLOT_BAG_END)
6586 return;
6588 if(Item* item = ((Player*)unitTarget)->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
6589 ((Player*)unitTarget)->DurabilityPointsLoss(item, damage);
6592 void Spell::EffectDurabilityDamagePCT(uint32 i)
6594 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6595 return;
6597 int32 slot = m_spellInfo->EffectMiscValue[i];
6599 // FIXME: some spells effects have value -1/-2
6600 // Possibly its mean -1 all player equipped items and -2 all items
6601 if(slot < 0)
6603 ((Player*)unitTarget)->DurabilityLossAll(double(damage)/100.0f, (slot < -1));
6604 return;
6607 // invalid slot value
6608 if(slot >= INVENTORY_SLOT_BAG_END)
6609 return;
6611 if(damage <= 0)
6612 return;
6614 if(Item* item = ((Player*)unitTarget)->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
6615 ((Player*)unitTarget)->DurabilityLoss(item, double(damage)/100.0f);
6618 void Spell::EffectModifyThreatPercent(uint32 /*effIndex*/)
6620 if(!unitTarget)
6621 return;
6623 unitTarget->getThreatManager().modifyThreatPercent(m_caster, damage);
6626 void Spell::EffectTransmitted(uint32 effIndex)
6628 uint32 name_id = m_spellInfo->EffectMiscValue[effIndex];
6630 GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(name_id);
6632 if (!goinfo)
6634 sLog.outErrorDb("Gameobject (Entry: %u) not exist and not created at spell (ID: %u) cast",name_id, m_spellInfo->Id);
6635 return;
6638 float fx, fy, fz;
6640 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6642 fx = m_targets.m_destX;
6643 fy = m_targets.m_destY;
6644 fz = m_targets.m_destZ;
6646 //FIXME: this can be better check for most objects but still hack
6647 else if(m_spellInfo->EffectRadiusIndex[effIndex] && m_spellInfo->speed==0)
6649 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[effIndex]));
6650 m_caster->GetClosePoint(fx, fy, fz, DEFAULT_WORLD_OBJECT_SIZE, dis);
6652 else
6654 float min_dis = GetSpellMinRange(sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex));
6655 float max_dis = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex));
6656 float dis = rand_norm() * (max_dis - min_dis) + min_dis;
6658 m_caster->GetClosePoint(fx, fy, fz, DEFAULT_WORLD_OBJECT_SIZE, dis);
6661 Map *cMap = m_caster->GetMap();
6663 if(goinfo->type==GAMEOBJECT_TYPE_FISHINGNODE)
6665 if ( !cMap->IsInWater(fx, fy, fz-0.5f)) // Hack to prevent fishing bobber from failing to land on fishing hole
6666 { // but this is not proper, we really need to ignore not materialized objects
6667 SendCastResult(SPELL_FAILED_NOT_HERE);
6668 SendChannelUpdate(0);
6669 return;
6672 // replace by water level in this case
6673 fz = cMap->GetWaterLevel(fx, fy);
6675 // if gameobject is summoning object, it should be spawned right on caster's position
6676 else if(goinfo->type==GAMEOBJECT_TYPE_SUMMONING_RITUAL)
6678 m_caster->GetPosition(fx, fy, fz);
6681 GameObject* pGameObj = new GameObject;
6683 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), name_id, cMap,
6684 m_caster->GetPhaseMask(), fx, fy, fz, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
6686 delete pGameObj;
6687 return;
6690 int32 duration = GetSpellDuration(m_spellInfo);
6692 switch(goinfo->type)
6694 case GAMEOBJECT_TYPE_FISHINGNODE:
6696 m_caster->SetChannelObjectGUID(pGameObj->GetGUID());
6697 m_caster->AddGameObject(pGameObj); // will removed at spell cancel
6699 // end time of range when possible catch fish (FISHING_BOBBER_READY_TIME..GetDuration(m_spellInfo))
6700 // start time == fish-FISHING_BOBBER_READY_TIME (0..GetDuration(m_spellInfo)-FISHING_BOBBER_READY_TIME)
6701 int32 lastSec = 0;
6702 switch(urand(0, 3))
6704 case 0: lastSec = 3; break;
6705 case 1: lastSec = 7; break;
6706 case 2: lastSec = 13; break;
6707 case 3: lastSec = 17; break;
6710 duration = duration - lastSec*IN_MILISECONDS + FISHING_BOBBER_READY_TIME*IN_MILISECONDS;
6711 break;
6713 case GAMEOBJECT_TYPE_SUMMONING_RITUAL:
6715 if(m_caster->GetTypeId() == TYPEID_PLAYER)
6717 pGameObj->AddUniqueUse((Player*)m_caster);
6718 m_caster->AddGameObject(pGameObj); // will removed at spell cancel
6720 break;
6722 case GAMEOBJECT_TYPE_FISHINGHOLE:
6723 case GAMEOBJECT_TYPE_CHEST:
6724 default:
6725 break;
6728 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
6730 pGameObj->SetOwnerGUID(m_caster->GetGUID());
6732 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel());
6733 pGameObj->SetSpellId(m_spellInfo->Id);
6735 DEBUG_LOG("AddObject at SpellEfects.cpp EffectTransmitted");
6736 //m_caster->AddGameObject(pGameObj);
6737 //m_ObjToDel.push_back(pGameObj);
6739 cMap->Add(pGameObj);
6741 if(uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry())
6743 GameObject* linkedGO = new GameObject;
6744 if(linkedGO->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, cMap,
6745 m_caster->GetPhaseMask(), fx, fy, fz, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
6747 linkedGO->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
6748 linkedGO->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel());
6749 linkedGO->SetSpellId(m_spellInfo->Id);
6750 linkedGO->SetOwnerGUID(m_caster->GetGUID());
6752 linkedGO->GetMap()->Add(linkedGO);
6754 else
6756 delete linkedGO;
6757 linkedGO = NULL;
6758 return;
6763 void Spell::EffectProspecting(uint32 /*i*/)
6765 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6766 return;
6768 Player* p_caster = (Player*)m_caster;
6769 if(!itemTarget || !(itemTarget->GetProto()->BagFamily & BAG_FAMILY_MASK_MINING_SUPP))
6770 return;
6772 if(itemTarget->GetCount() < 5)
6773 return;
6775 if( sWorld.getConfig(CONFIG_SKILL_PROSPECTING))
6777 uint32 SkillValue = p_caster->GetPureSkillValue(SKILL_JEWELCRAFTING);
6778 uint32 reqSkillValue = itemTarget->GetProto()->RequiredSkillRank;
6779 p_caster->UpdateGatherSkill(SKILL_JEWELCRAFTING, SkillValue, reqSkillValue);
6782 ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(), LOOT_PROSPECTING);
6785 void Spell::EffectMilling(uint32 /*i*/)
6787 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6788 return;
6790 Player* p_caster = (Player*)m_caster;
6791 if(!itemTarget || !(itemTarget->GetProto()->BagFamily & BAG_FAMILY_MASK_HERBS))
6792 return;
6794 if(itemTarget->GetCount() < 5)
6795 return;
6797 if( sWorld.getConfig(CONFIG_SKILL_MILLING))
6799 uint32 SkillValue = p_caster->GetPureSkillValue(SKILL_INSCRIPTION);
6800 uint32 reqSkillValue = itemTarget->GetProto()->RequiredSkillRank;
6801 p_caster->UpdateGatherSkill(SKILL_INSCRIPTION, SkillValue, reqSkillValue);
6804 ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(), LOOT_MILLING);
6807 void Spell::EffectSkill(uint32 /*i*/)
6809 sLog.outDebug("WORLD: SkillEFFECT");
6812 void Spell::EffectSpiritHeal(uint32 /*i*/)
6814 // TODO player can't see the heal-animation - he should respawn some ticks later
6815 if (!unitTarget || unitTarget->isAlive())
6816 return;
6817 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6818 return;
6819 if (!unitTarget->IsInWorld())
6820 return;
6821 if (m_spellInfo->Id == 22012 && !unitTarget->HasAura(2584))
6822 return;
6824 ((Player*)unitTarget)->ResurrectPlayer(1.0f);
6825 ((Player*)unitTarget)->SpawnCorpseBones();
6828 // remove insignia spell effect
6829 void Spell::EffectSkinPlayerCorpse(uint32 /*i*/)
6831 sLog.outDebug("Effect: SkinPlayerCorpse");
6832 if ( (m_caster->GetTypeId() != TYPEID_PLAYER) || (unitTarget->GetTypeId() != TYPEID_PLAYER) || (unitTarget->isAlive()) )
6833 return;
6835 ((Player*)unitTarget)->RemovedInsignia( (Player*)m_caster );
6838 void Spell::EffectStealBeneficialBuff(uint32 i)
6840 sLog.outDebug("Effect: StealBeneficialBuff");
6842 if(!unitTarget || unitTarget==m_caster) // can't steal from self
6843 return;
6845 std::vector <Aura *> steal_list;
6846 // Create dispel mask by dispel type
6847 uint32 dispelMask = GetDispellMask( DispelType(m_spellInfo->EffectMiscValue[i]) );
6848 Unit::AuraMap const& auras = unitTarget->GetAuras();
6849 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
6851 Aura *aur = (*itr).second;
6852 if (aur && (1<<aur->GetSpellProto()->Dispel) & dispelMask)
6854 // Need check for passive? this
6855 if (aur->IsPositive() && !aur->IsPassive() && !(aur->GetSpellProto()->AttributesEx4 & SPELL_ATTR_EX4_NOT_STEALABLE))
6856 steal_list.push_back(aur);
6859 // Ok if exist some buffs for dispel try dispel it
6860 if (!steal_list.empty())
6862 std::list < std::pair<uint32,uint64> > success_list;
6863 int32 list_size = steal_list.size();
6864 // Dispell N = damage buffs (or while exist buffs for dispel)
6865 for (int32 count=0; count < damage && list_size > 0; ++count)
6867 // Random select buff for dispel
6868 Aura *aur = steal_list[urand(0, list_size-1)];
6869 // Not use chance for steal
6870 // TODO possible need do it
6871 success_list.push_back( std::pair<uint32,uint64>(aur->GetId(),aur->GetCasterGUID()));
6873 // Remove buff from list for prevent doubles
6874 for (std::vector<Aura *>::iterator j = steal_list.begin(); j != steal_list.end(); )
6876 Aura *stealed = *j;
6877 if (stealed->GetId() == aur->GetId() && stealed->GetCasterGUID() == aur->GetCasterGUID())
6879 j = steal_list.erase(j);
6880 --list_size;
6882 else
6883 ++j;
6886 // Really try steal and send log
6887 if (!success_list.empty())
6889 int32 count = success_list.size();
6890 WorldPacket data(SMSG_SPELLSTEALLOG, 8+8+4+1+4+count*5);
6891 data.append(unitTarget->GetPackGUID()); // Victim GUID
6892 data.append(m_caster->GetPackGUID()); // Caster GUID
6893 data << uint32(m_spellInfo->Id); // Dispell spell id
6894 data << uint8(0); // not used
6895 data << uint32(count); // count
6896 for (std::list<std::pair<uint32,uint64> >::iterator j = success_list.begin(); j != success_list.end(); ++j)
6898 SpellEntry const* spellInfo = sSpellStore.LookupEntry(j->first);
6899 data << uint32(spellInfo->Id); // Spell Id
6900 data << uint8(0); // 0 - steals !=0 transfers
6901 unitTarget->RemoveAurasDueToSpellBySteal(spellInfo->Id, j->second, m_caster);
6903 m_caster->SendMessageToSet(&data, true);
6908 void Spell::EffectKillCreditPersonal(uint32 i)
6910 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6911 return;
6913 ((Player*)unitTarget)->KilledMonsterCredit(m_spellInfo->EffectMiscValue[i], 0);
6916 void Spell::EffectKillCredit(uint32 i)
6918 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6919 return;
6921 ((Player*)unitTarget)->RewardPlayerAndGroupAtEvent(m_spellInfo->EffectMiscValue[i], unitTarget);
6924 void Spell::EffectQuestFail(uint32 i)
6926 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6927 return;
6929 ((Player*)unitTarget)->FailQuest(m_spellInfo->EffectMiscValue[i]);
6932 void Spell::EffectActivateRune(uint32 eff_idx)
6934 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6935 return;
6937 Player *plr = (Player*)m_caster;
6939 if(plr->getClass() != CLASS_DEATH_KNIGHT)
6940 return;
6942 for(uint32 j = 0; j < MAX_RUNES; ++j)
6944 if(plr->GetRuneCooldown(j) && plr->GetCurrentRune(j) == RuneType(m_spellInfo->EffectMiscValue[eff_idx]))
6946 plr->SetRuneCooldown(j, 0);
6951 void Spell::EffectTitanGrip(uint32 /*eff_idx*/)
6953 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6954 ((Player*)unitTarget)->SetCanTitanGrip(true);
6957 void Spell::EffectRenamePet(uint32 /*eff_idx*/)
6959 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT ||
6960 !((Creature*)unitTarget)->isPet() || ((Pet*)unitTarget)->getPetType() != HUNTER_PET)
6961 return;
6963 unitTarget->RemoveByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED);
6966 void Spell::EffectPlayMusic(uint32 i)
6968 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6969 return;
6971 uint32 soundid = m_spellInfo->EffectMiscValue[i];
6973 if (!sSoundEntriesStore.LookupEntry(soundid))
6975 sLog.outError("EffectPlayMusic: Sound (Id: %u) not exist in spell %u.",soundid,m_spellInfo->Id);
6976 return;
6979 WorldPacket data(SMSG_PLAY_MUSIC, 4);
6980 data << uint32(soundid);
6981 ((Player*)unitTarget)->GetSession()->SendPacket(&data);