[9029] Fixed spell 0451 and ranks buff apply.
[getmangos.git] / src / game / SpellEffects.cpp
blob27d08cdb947a403e2642d9d47e1c857f61fee5fd
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "Opcodes.h"
23 #include "Log.h"
24 #include "UpdateMask.h"
25 #include "World.h"
26 #include "ObjectMgr.h"
27 #include "SpellMgr.h"
28 #include "Player.h"
29 #include "SkillExtraItems.h"
30 #include "Unit.h"
31 #include "Spell.h"
32 #include "DynamicObject.h"
33 #include "SpellAuras.h"
34 #include "Group.h"
35 #include "UpdateData.h"
36 #include "MapManager.h"
37 #include "ObjectAccessor.h"
38 #include "SharedDefines.h"
39 #include "Pet.h"
40 #include "GameObject.h"
41 #include "GossipDef.h"
42 #include "Creature.h"
43 #include "Totem.h"
44 #include "CreatureAI.h"
45 #include "BattleGroundMgr.h"
46 #include "BattleGround.h"
47 #include "BattleGroundEY.h"
48 #include "BattleGroundWS.h"
49 #include "VMapFactory.h"
50 #include "Language.h"
51 #include "SocialMgr.h"
52 #include "Util.h"
53 #include "TemporarySummon.h"
54 #include "ScriptCalls.h"
55 #include "SkillDiscovery.h"
56 #include "Formulas.h"
58 pEffect SpellEffects[TOTAL_SPELL_EFFECTS]=
60 &Spell::EffectNULL, // 0
61 &Spell::EffectInstaKill, // 1 SPELL_EFFECT_INSTAKILL
62 &Spell::EffectSchoolDMG, // 2 SPELL_EFFECT_SCHOOL_DAMAGE
63 &Spell::EffectDummy, // 3 SPELL_EFFECT_DUMMY
64 &Spell::EffectUnused, // 4 SPELL_EFFECT_PORTAL_TELEPORT unused
65 &Spell::EffectTeleportUnits, // 5 SPELL_EFFECT_TELEPORT_UNITS
66 &Spell::EffectApplyAura, // 6 SPELL_EFFECT_APPLY_AURA
67 &Spell::EffectEnvirinmentalDMG, // 7 SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
68 &Spell::EffectPowerDrain, // 8 SPELL_EFFECT_POWER_DRAIN
69 &Spell::EffectHealthLeech, // 9 SPELL_EFFECT_HEALTH_LEECH
70 &Spell::EffectHeal, // 10 SPELL_EFFECT_HEAL
71 &Spell::EffectUnused, // 11 SPELL_EFFECT_BIND
72 &Spell::EffectNULL, // 12 SPELL_EFFECT_PORTAL
73 &Spell::EffectUnused, // 13 SPELL_EFFECT_RITUAL_BASE unused
74 &Spell::EffectUnused, // 14 SPELL_EFFECT_RITUAL_SPECIALIZE unused
75 &Spell::EffectUnused, // 15 SPELL_EFFECT_RITUAL_ACTIVATE_PORTAL unused
76 &Spell::EffectQuestComplete, // 16 SPELL_EFFECT_QUEST_COMPLETE
77 &Spell::EffectWeaponDmg, // 17 SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
78 &Spell::EffectResurrect, // 18 SPELL_EFFECT_RESURRECT
79 &Spell::EffectAddExtraAttacks, // 19 SPELL_EFFECT_ADD_EXTRA_ATTACKS
80 &Spell::EffectUnused, // 20 SPELL_EFFECT_DODGE one spell: Dodge
81 &Spell::EffectUnused, // 21 SPELL_EFFECT_EVADE one spell: Evade (DND)
82 &Spell::EffectParry, // 22 SPELL_EFFECT_PARRY
83 &Spell::EffectBlock, // 23 SPELL_EFFECT_BLOCK one spell: Block
84 &Spell::EffectCreateItem, // 24 SPELL_EFFECT_CREATE_ITEM
85 &Spell::EffectUnused, // 25 SPELL_EFFECT_WEAPON
86 &Spell::EffectUnused, // 26 SPELL_EFFECT_DEFENSE one spell: Defense
87 &Spell::EffectPersistentAA, // 27 SPELL_EFFECT_PERSISTENT_AREA_AURA
88 &Spell::EffectSummonType, // 28 SPELL_EFFECT_SUMMON
89 &Spell::EffectLeapForward, // 29 SPELL_EFFECT_LEAP
90 &Spell::EffectEnergize, // 30 SPELL_EFFECT_ENERGIZE
91 &Spell::EffectWeaponDmg, // 31 SPELL_EFFECT_WEAPON_PERCENT_DAMAGE
92 &Spell::EffectTriggerMissileSpell, // 32 SPELL_EFFECT_TRIGGER_MISSILE
93 &Spell::EffectOpenLock, // 33 SPELL_EFFECT_OPEN_LOCK
94 &Spell::EffectSummonChangeItem, // 34 SPELL_EFFECT_SUMMON_CHANGE_ITEM
95 &Spell::EffectApplyAreaAura, // 35 SPELL_EFFECT_APPLY_AREA_AURA_PARTY
96 &Spell::EffectLearnSpell, // 36 SPELL_EFFECT_LEARN_SPELL
97 &Spell::EffectUnused, // 37 SPELL_EFFECT_SPELL_DEFENSE one spell: SPELLDEFENSE (DND)
98 &Spell::EffectDispel, // 38 SPELL_EFFECT_DISPEL
99 &Spell::EffectUnused, // 39 SPELL_EFFECT_LANGUAGE
100 &Spell::EffectDualWield, // 40 SPELL_EFFECT_DUAL_WIELD
101 &Spell::EffectUnused, // 41 SPELL_EFFECT_JUMP
102 &Spell::EffectJump, // 42 SPELL_EFFECT_JUMP2
103 &Spell::EffectTeleUnitsFaceCaster, // 43 SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
104 &Spell::EffectLearnSkill, // 44 SPELL_EFFECT_SKILL_STEP
105 &Spell::EffectAddHonor, // 45 SPELL_EFFECT_ADD_HONOR honor/pvp related
106 &Spell::EffectNULL, // 46 SPELL_EFFECT_SPAWN we must spawn pet there
107 &Spell::EffectTradeSkill, // 47 SPELL_EFFECT_TRADE_SKILL
108 &Spell::EffectUnused, // 48 SPELL_EFFECT_STEALTH one spell: Base Stealth
109 &Spell::EffectUnused, // 49 SPELL_EFFECT_DETECT one spell: Detect
110 &Spell::EffectTransmitted, // 50 SPELL_EFFECT_TRANS_DOOR
111 &Spell::EffectUnused, // 51 SPELL_EFFECT_FORCE_CRITICAL_HIT unused
112 &Spell::EffectUnused, // 52 SPELL_EFFECT_GUARANTEE_HIT one spell: zzOLDCritical Shot
113 &Spell::EffectEnchantItemPerm, // 53 SPELL_EFFECT_ENCHANT_ITEM
114 &Spell::EffectEnchantItemTmp, // 54 SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
115 &Spell::EffectTameCreature, // 55 SPELL_EFFECT_TAMECREATURE
116 &Spell::EffectSummonPet, // 56 SPELL_EFFECT_SUMMON_PET
117 &Spell::EffectLearnPetSpell, // 57 SPELL_EFFECT_LEARN_PET_SPELL
118 &Spell::EffectWeaponDmg, // 58 SPELL_EFFECT_WEAPON_DAMAGE
119 &Spell::EffectCreateRandomItem, // 59 SPELL_EFFECT_CREATE_RANDOM_ITEM create item base at spell specific loot
120 &Spell::EffectProficiency, // 60 SPELL_EFFECT_PROFICIENCY
121 &Spell::EffectSendEvent, // 61 SPELL_EFFECT_SEND_EVENT
122 &Spell::EffectPowerBurn, // 62 SPELL_EFFECT_POWER_BURN
123 &Spell::EffectThreat, // 63 SPELL_EFFECT_THREAT
124 &Spell::EffectTriggerSpell, // 64 SPELL_EFFECT_TRIGGER_SPELL
125 &Spell::EffectApplyAreaAura, // 65 SPELL_EFFECT_APPLY_AREA_AURA_RAID
126 &Spell::EffectUnused, // 66 SPELL_EFFECT_CREATE_MANA_GEM (possibly recharge it, misc - is item ID)
127 &Spell::EffectHealMaxHealth, // 67 SPELL_EFFECT_HEAL_MAX_HEALTH
128 &Spell::EffectInterruptCast, // 68 SPELL_EFFECT_INTERRUPT_CAST
129 &Spell::EffectDistract, // 69 SPELL_EFFECT_DISTRACT
130 &Spell::EffectPull, // 70 SPELL_EFFECT_PULL one spell: Distract Move
131 &Spell::EffectPickPocket, // 71 SPELL_EFFECT_PICKPOCKET
132 &Spell::EffectAddFarsight, // 72 SPELL_EFFECT_ADD_FARSIGHT
133 &Spell::EffectUnused, // 73 SPELL_EFFECT_UNTRAIN_TALENTS
134 &Spell::EffectApplyGlyph, // 74 SPELL_EFFECT_APPLY_GLYPH
135 &Spell::EffectHealMechanical, // 75 SPELL_EFFECT_HEAL_MECHANICAL one spell: Mechanical Patch Kit
136 &Spell::EffectSummonObjectWild, // 76 SPELL_EFFECT_SUMMON_OBJECT_WILD
137 &Spell::EffectScriptEffect, // 77 SPELL_EFFECT_SCRIPT_EFFECT
138 &Spell::EffectUnused, // 78 SPELL_EFFECT_ATTACK
139 &Spell::EffectSanctuary, // 79 SPELL_EFFECT_SANCTUARY
140 &Spell::EffectAddComboPoints, // 80 SPELL_EFFECT_ADD_COMBO_POINTS
141 &Spell::EffectUnused, // 81 SPELL_EFFECT_CREATE_HOUSE one spell: Create House (TEST)
142 &Spell::EffectNULL, // 82 SPELL_EFFECT_BIND_SIGHT
143 &Spell::EffectDuel, // 83 SPELL_EFFECT_DUEL
144 &Spell::EffectStuck, // 84 SPELL_EFFECT_STUCK
145 &Spell::EffectSummonPlayer, // 85 SPELL_EFFECT_SUMMON_PLAYER
146 &Spell::EffectActivateObject, // 86 SPELL_EFFECT_ACTIVATE_OBJECT
147 &Spell::EffectUnused, // 87 SPELL_EFFECT_WMO_DAMAGE
148 &Spell::EffectUnused, // 88 SPELL_EFFECT_WMO_REPAIR
149 &Spell::EffectUnused, // 89 SPELL_EFFECT_WMO_CHANGE
150 &Spell::EffectKillCreditPersonal, // 90 SPELL_EFFECT_KILL_CREDIT Kill credit but only for single person
151 &Spell::EffectUnused, // 91 SPELL_EFFECT_THREAT_ALL one spell: zzOLDBrainwash
152 &Spell::EffectEnchantHeldItem, // 92 SPELL_EFFECT_ENCHANT_HELD_ITEM
153 &Spell::EffectUnused, // 93 SPELL_EFFECT_SUMMON_PHANTASM
154 &Spell::EffectSelfResurrect, // 94 SPELL_EFFECT_SELF_RESURRECT
155 &Spell::EffectSkinning, // 95 SPELL_EFFECT_SKINNING
156 &Spell::EffectCharge, // 96 SPELL_EFFECT_CHARGE
157 &Spell::EffectUnused, // 97 SPELL_EFFECT_97
158 &Spell::EffectKnockBack, // 98 SPELL_EFFECT_KNOCK_BACK
159 &Spell::EffectDisEnchant, // 99 SPELL_EFFECT_DISENCHANT
160 &Spell::EffectInebriate, //100 SPELL_EFFECT_INEBRIATE
161 &Spell::EffectFeedPet, //101 SPELL_EFFECT_FEED_PET
162 &Spell::EffectDismissPet, //102 SPELL_EFFECT_DISMISS_PET
163 &Spell::EffectReputation, //103 SPELL_EFFECT_REPUTATION
164 &Spell::EffectSummonObject, //104 SPELL_EFFECT_SUMMON_OBJECT_SLOT1
165 &Spell::EffectSummonObject, //105 SPELL_EFFECT_SUMMON_OBJECT_SLOT2
166 &Spell::EffectSummonObject, //106 SPELL_EFFECT_SUMMON_OBJECT_SLOT3
167 &Spell::EffectSummonObject, //107 SPELL_EFFECT_SUMMON_OBJECT_SLOT4
168 &Spell::EffectDispelMechanic, //108 SPELL_EFFECT_DISPEL_MECHANIC
169 &Spell::EffectSummonDeadPet, //109 SPELL_EFFECT_SUMMON_DEAD_PET
170 &Spell::EffectDestroyAllTotems, //110 SPELL_EFFECT_DESTROY_ALL_TOTEMS
171 &Spell::EffectDurabilityDamage, //111 SPELL_EFFECT_DURABILITY_DAMAGE
172 &Spell::EffectUnused, //112 SPELL_EFFECT_112
173 &Spell::EffectResurrectNew, //113 SPELL_EFFECT_RESURRECT_NEW
174 &Spell::EffectTaunt, //114 SPELL_EFFECT_ATTACK_ME
175 &Spell::EffectDurabilityDamagePCT, //115 SPELL_EFFECT_DURABILITY_DAMAGE_PCT
176 &Spell::EffectSkinPlayerCorpse, //116 SPELL_EFFECT_SKIN_PLAYER_CORPSE one spell: Remove Insignia, bg usage, required special corpse flags...
177 &Spell::EffectSpiritHeal, //117 SPELL_EFFECT_SPIRIT_HEAL one spell: Spirit Heal
178 &Spell::EffectSkill, //118 SPELL_EFFECT_SKILL professions and more
179 &Spell::EffectApplyAreaAura, //119 SPELL_EFFECT_APPLY_AREA_AURA_PET
180 &Spell::EffectUnused, //120 SPELL_EFFECT_TELEPORT_GRAVEYARD one spell: Graveyard Teleport Test
181 &Spell::EffectWeaponDmg, //121 SPELL_EFFECT_NORMALIZED_WEAPON_DMG
182 &Spell::EffectUnused, //122 SPELL_EFFECT_122 unused
183 &Spell::EffectSendTaxi, //123 SPELL_EFFECT_SEND_TAXI taxi/flight related (misc value is taxi path id)
184 &Spell::EffectPlayerPull, //124 SPELL_EFFECT_PLAYER_PULL opposite of knockback effect (pulls player twoard caster)
185 &Spell::EffectModifyThreatPercent, //125 SPELL_EFFECT_MODIFY_THREAT_PERCENT
186 &Spell::EffectStealBeneficialBuff, //126 SPELL_EFFECT_STEAL_BENEFICIAL_BUFF spell steal effect?
187 &Spell::EffectProspecting, //127 SPELL_EFFECT_PROSPECTING Prospecting spell
188 &Spell::EffectApplyAreaAura, //128 SPELL_EFFECT_APPLY_AREA_AURA_FRIEND
189 &Spell::EffectApplyAreaAura, //129 SPELL_EFFECT_APPLY_AREA_AURA_ENEMY
190 &Spell::EffectNULL, //130 SPELL_EFFECT_REDIRECT_THREAT
191 &Spell::EffectUnused, //131 SPELL_EFFECT_131 used in some test spells
192 &Spell::EffectPlayMusic, //132 SPELL_EFFECT_PLAY_MUSIC sound id in misc value (SoundEntries.dbc)
193 &Spell::EffectUnlearnSpecialization, //133 SPELL_EFFECT_UNLEARN_SPECIALIZATION unlearn profession specialization
194 &Spell::EffectKillCredit, //134 SPELL_EFFECT_KILL_CREDIT misc value is creature entry
195 &Spell::EffectNULL, //135 SPELL_EFFECT_CALL_PET
196 &Spell::EffectHealPct, //136 SPELL_EFFECT_HEAL_PCT
197 &Spell::EffectEnergisePct, //137 SPELL_EFFECT_ENERGIZE_PCT
198 &Spell::EffectLeapBack, //138 SPELL_EFFECT_LEAP_BACK Leap back
199 &Spell::EffectUnused, //139 SPELL_EFFECT_CLEAR_QUEST (misc - is quest ID)
200 &Spell::EffectForceCast, //140 SPELL_EFFECT_FORCE_CAST
201 &Spell::EffectNULL, //141 SPELL_EFFECT_141 damage and reduce speed?
202 &Spell::EffectTriggerSpellWithValue, //142 SPELL_EFFECT_TRIGGER_SPELL_WITH_VALUE
203 &Spell::EffectApplyAreaAura, //143 SPELL_EFFECT_APPLY_AREA_AURA_OWNER
204 &Spell::EffectNULL, //144 SPELL_EFFECT_144 Spectral Blast
205 &Spell::EffectNULL, //145 SPELL_EFFECT_145 Black Hole Effect
206 &Spell::EffectActivateRune, //146 SPELL_EFFECT_ACTIVATE_RUNE
207 &Spell::EffectQuestFail, //147 SPELL_EFFECT_QUEST_FAIL quest fail
208 &Spell::EffectUnused, //148 SPELL_EFFECT_148 unused
209 &Spell::EffectCharge2, //149 SPELL_EFFECT_CHARGE2 swoop
210 &Spell::EffectUnused, //150 SPELL_EFFECT_150 unused
211 &Spell::EffectTriggerRitualOfSummoning, //151 SPELL_EFFECT_TRIGGER_SPELL_2
212 &Spell::EffectNULL, //152 SPELL_EFFECT_152 summon Refer-a-Friend
213 &Spell::EffectNULL, //153 SPELL_EFFECT_CREATE_PET misc value is creature entry
214 &Spell::EffectNULL, //154 unused
215 &Spell::EffectTitanGrip, //155 SPELL_EFFECT_TITAN_GRIP Allows you to equip two-handed axes, maces and swords in one hand, but you attack $49152s1% slower than normal.
216 &Spell::EffectEnchantItemPrismatic, //156 SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
217 &Spell::EffectCreateItem2, //157 SPELL_EFFECT_CREATE_ITEM_2 create item or create item template and replace by some randon spell loot item
218 &Spell::EffectMilling, //158 SPELL_EFFECT_MILLING milling
219 &Spell::EffectRenamePet, //159 SPELL_EFFECT_ALLOW_RENAME_PET allow rename pet once again
220 &Spell::EffectNULL, //160 SPELL_EFFECT_160 unused
221 &Spell::EffectNULL, //161 SPELL_EFFECT_TALENT_SPEC_COUNT second talent spec (learn/revert)
222 &Spell::EffectNULL, //162 SPELL_EFFECT_TALENT_SPEC_SELECT activate primary/secondary spec
225 void Spell::EffectNULL(uint32 /*i*/)
227 sLog.outDebug("WORLD: Spell Effect DUMMY");
230 void Spell::EffectUnused(uint32 /*i*/)
232 // NOT USED BY ANY SPELL OR USELESS OR IMPLEMENTED IN DIFFERENT WAY IN MANGOS
235 void Spell::EffectResurrectNew(uint32 i)
237 if(!unitTarget || unitTarget->isAlive())
238 return;
240 if(unitTarget->GetTypeId() != TYPEID_PLAYER)
241 return;
243 if(!unitTarget->IsInWorld())
244 return;
246 Player* pTarget = ((Player*)unitTarget);
248 if(pTarget->isRessurectRequested()) // already have one active request
249 return;
251 uint32 health = damage;
252 uint32 mana = m_spellInfo->EffectMiscValue[i];
253 pTarget->setResurrectRequestData(m_caster->GetGUID(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), health, mana);
254 SendResurrectRequest(pTarget);
257 void Spell::EffectInstaKill(uint32 /*i*/)
259 if( !unitTarget || !unitTarget->isAlive() )
260 return;
262 // Demonic Sacrifice
263 if(m_spellInfo->Id==18788 && unitTarget->GetTypeId()==TYPEID_UNIT)
265 uint32 entry = unitTarget->GetEntry();
266 uint32 spellID;
267 switch(entry)
269 case 416: spellID=18789; break; //imp
270 case 417: spellID=18792; break; //fellhunter
271 case 1860: spellID=18790; break; //void
272 case 1863: spellID=18791; break; //succubus
273 case 17252: spellID=35701; break; //fellguard
274 default:
275 sLog.outError("EffectInstaKill: Unhandled creature entry (%u) case.", entry);
276 return;
279 m_caster->CastSpell(m_caster, spellID, true);
282 if(m_caster == unitTarget) // prevent interrupt message
283 finish();
285 m_caster->DealDamage(unitTarget, unitTarget->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
288 void Spell::EffectEnvirinmentalDMG(uint32 i)
290 uint32 absorb = 0;
291 uint32 resist = 0;
293 // Note: this hack with damage replace required until GO casting not implemented
294 // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support
295 // currently each enemy selected explicitly and self cast damage, we prevent apply self casted spell bonuses/etc
296 damage = m_spellInfo->CalculateSimpleValue(i);
298 m_caster->CalcAbsorbResist(m_caster, GetSpellSchoolMask(m_spellInfo), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
300 m_caster->SendSpellNonMeleeDamageLog(m_caster, m_spellInfo->Id, damage, GetSpellSchoolMask(m_spellInfo), absorb, resist, false, 0, false);
301 if(m_caster->GetTypeId() == TYPEID_PLAYER)
302 ((Player*)m_caster)->EnvironmentalDamage(DAMAGE_FIRE, damage);
305 void Spell::EffectSchoolDMG(uint32 effect_idx)
307 if( unitTarget && unitTarget->isAlive())
309 switch(m_spellInfo->SpellFamilyName)
311 case SPELLFAMILY_GENERIC:
313 switch(m_spellInfo->Id) // better way to check unknown
315 // Meteor like spells (divided damage to targets)
316 case 24340: case 26558: case 28884: // Meteor
317 case 36837: case 38903: case 41276: // Meteor
318 case 26789: // Shard of the Fallen Star
319 case 31436: // Malevolent Cleave
320 case 35181: // Dive Bomb
321 case 40810: case 43267: case 43268: // Saber Lash
322 case 42384: // Brutal Swipe
323 case 45150: // Meteor Slash
324 case 64422: case 64688: // Sonic Screech
326 uint32 count = 0;
327 for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit)
328 if(ihit->effectMask & (1<<effect_idx))
329 ++count;
331 damage /= count; // divide to all targets
332 break;
334 // percent from health with min
335 case 25599: // Thundercrash
337 damage = unitTarget->GetHealth() / 2;
338 if(damage < 200)
339 damage = 200;
340 break;
342 // Intercept (warrior spell trigger)
343 case 20253:
344 case 61491:
346 damage+= uint32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 0.12f);
347 break;
349 // Cataclysmic Bolt
350 case 38441:
352 damage = unitTarget->GetMaxHealth() / 2;
353 break;
355 // Tympanic Tantrum
356 case 62775:
358 damage = unitTarget->GetMaxHealth() / 10;
359 break;
361 // Hand of Rekoning (name not have typos ;) )
362 case 67485:
363 damage += uint32(0.5f * m_caster->GetTotalAttackPowerValue(BASE_ATTACK));
364 break;
366 break;
368 case SPELLFAMILY_MAGE:
369 break;
370 case SPELLFAMILY_WARRIOR:
372 // Bloodthirst
373 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x40000000000))
375 damage = uint32(damage * (m_caster->GetTotalAttackPowerValue(BASE_ATTACK)) / 100);
377 // Shield Slam
378 else if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000020000000000)) && m_spellInfo->Category==1209)
379 damage += int32(m_caster->GetShieldBlockValue());
380 // Victory Rush
381 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x10000000000))
383 damage = uint32(damage * m_caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
384 m_caster->ModifyAuraState(AURA_STATE_WARRIOR_VICTORY_RUSH, false);
386 // Revenge ${$m1+$AP*0.207} to ${$M1+$AP*0.207}
387 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000400))
388 damage+= uint32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 0.207f);
389 // Heroic Throw ${$m1+$AP*.50}
390 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000100000000))
391 damage+= uint32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 0.5f);
392 // Shockwave ${$m3/100*$AP}
393 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000800000000000))
395 int32 pct = m_caster->CalculateSpellDamage(m_spellInfo, 2, m_spellInfo->EffectBasePoints[2], unitTarget);
396 if (pct > 0)
397 damage+= int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * pct / 100);
398 break;
400 // Thunder Clap
401 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000080))
403 damage+=int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 12 / 100);
405 break;
407 case SPELLFAMILY_WARLOCK:
409 // Incinerate Rank 1 & 2
410 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x00004000000000)) && m_spellInfo->SpellIconID==2128)
412 // Incinerate does more dmg (dmg*0.25) if the target have Immolate debuff.
413 // Check aura state for speed but aura state set not only for Immolate spell
414 if(unitTarget->HasAuraState(AURA_STATE_CONFLAGRATE))
416 Unit::AuraList const& RejorRegr = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
417 for(Unit::AuraList::const_iterator i = RejorRegr.begin(); i != RejorRegr.end(); ++i)
419 // Immolate
420 if((*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK &&
421 ((*i)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x00000000000004)))
423 damage += damage/4;
424 break;
429 // Shadowflame
430 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0001000000000000))
432 // Apply DOT part
433 switch(m_spellInfo->Id)
435 case 47897: m_caster->CastSpell(unitTarget, 47960, true); break;
436 case 61290: m_caster->CastSpell(unitTarget, 61291, true); break;
437 default:
438 sLog.outError("Spell::EffectDummy: Unhandeled Shadowflame spell rank %u",m_spellInfo->Id);
439 break;
442 // Conflagrate - consumes Immolate or Shadowflame
443 else if (m_spellInfo->TargetAuraState == AURA_STATE_CONFLAGRATE)
445 Aura const* aura = NULL; // found req. aura for damage calculation
447 Unit::AuraList const &mPeriodic = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
448 for(Unit::AuraList::const_iterator i = mPeriodic.begin(); i != mPeriodic.end(); ++i)
450 // for caster applied auras only
451 if ((*i)->GetSpellProto()->SpellFamilyName != SPELLFAMILY_WARLOCK ||
452 (*i)->GetCasterGUID()!=m_caster->GetGUID())
453 continue;
455 // Immolate
456 if ((*i)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000004))
458 aura = *i; // it selected always if exist
459 break;
462 // Shadowflame
463 if ((*i)->GetSpellProto()->SpellFamilyFlags2 & 0x00000002)
464 aura = *i; // remember but wait possible Immolate as primary priority
467 // found Immolate or Shadowflame
468 if (aura)
470 // DoT not have applied spell bonuses in m_amount
471 int32 damagetick = m_caster->SpellDamageBonus(unitTarget, aura->GetSpellProto(), aura->GetModifier()->m_amount, DOT);
472 damage += damagetick * 4;
474 // Glyph of Conflagrate
475 if (!m_caster->HasAura(56235))
476 unitTarget->RemoveAurasByCasterSpell(aura->GetId(), m_caster->GetGUID());
477 break;
480 break;
482 case SPELLFAMILY_PRIEST:
484 // Shadow Word: Death - deals damage equal to damage done to caster
485 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000200000000))
486 m_caster->CastCustomSpell(m_caster, 32409, &damage, 0, 0, true);
487 // Improved Mind Blast (Mind Blast in shadow form bonus)
488 else if (m_caster->m_form == FORM_SHADOW && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x00002000)))
490 Unit::AuraList const& ImprMindBlast = m_caster->GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER);
491 for(Unit::AuraList::const_iterator i = ImprMindBlast.begin(); i != ImprMindBlast.end(); ++i)
493 if ((*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_PRIEST &&
494 ((*i)->GetSpellProto()->SpellIconID == 95))
496 int chance = (*i)->GetSpellProto()->CalculateSimpleValue(1);
497 if (roll_chance_i(chance))
498 // Mind Trauma
499 m_caster->CastSpell(unitTarget, 48301, true, 0);
500 break;
504 break;
506 case SPELLFAMILY_DRUID:
508 // Ferocious Bite
509 if (m_caster->GetTypeId()==TYPEID_PLAYER && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x000800000)) && m_spellInfo->SpellVisual[0]==6587)
511 // converts up to 30 points of energy into ($f1+$AP/410) additional damage
512 float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
513 float multiple = ap / 410 + m_spellInfo->DmgMultiplier[effect_idx];
514 damage += int32(((Player*)m_caster)->GetComboPoints() * ap * 7 / 100);
515 uint32 energy = m_caster->GetPower(POWER_ENERGY);
516 uint32 used_energy = energy > 30 ? 30 : energy;
517 damage += int32(used_energy * multiple);
518 m_caster->SetPower(POWER_ENERGY,energy-used_energy);
520 // Rake
521 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000001000) && m_spellInfo->Effect[2]==SPELL_EFFECT_ADD_COMBO_POINTS)
523 // $AP*0.01 bonus
524 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
526 // Swipe
527 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0010000000000000))
529 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.08f);
531 break;
533 case SPELLFAMILY_ROGUE:
535 // Envenom
536 if (m_caster->GetTypeId()==TYPEID_PLAYER && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x800000000)))
538 // consume from stack dozes not more that have combo-points
539 if(uint32 combo = ((Player*)m_caster)->GetComboPoints())
541 Aura *poison = 0;
542 // Lookup for Deadly poison (only attacker applied)
543 Unit::AuraList const& auras = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
544 for(Unit::AuraList::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
545 if( (*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_ROGUE &&
546 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x10000)) &&
547 (*itr)->GetCasterGUID()==m_caster->GetGUID() )
549 poison = *itr;
550 break;
552 // count consumed deadly poison doses at target
553 if (poison)
555 uint32 spellId = poison->GetId();
556 uint32 doses = poison->GetStackAmount();
557 if (doses > combo)
558 doses = combo;
559 for (int i=0; i< doses; i++)
560 unitTarget->RemoveSingleSpellAurasFromStack(spellId);
561 damage *= doses;
562 damage += int32(((Player*)m_caster)->GetTotalAttackPowerValue(BASE_ATTACK) * 0.09f * doses);
564 // Eviscerate and Envenom Bonus Damage (item set effect)
565 if(m_caster->GetDummyAura(37169))
566 damage += ((Player*)m_caster)->GetComboPoints()*40;
569 // Eviscerate
570 else if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x00020000)) && m_caster->GetTypeId()==TYPEID_PLAYER)
572 if(uint32 combo = ((Player*)m_caster)->GetComboPoints())
574 float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
575 damage += irand(int32(ap * combo * 0.03f), int32(ap * combo * 0.07f));
577 // Eviscerate and Envenom Bonus Damage (item set effect)
578 if(m_caster->GetDummyAura(37169))
579 damage += combo*40;
582 // Gouge
583 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000008))
585 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.21f);
587 // Instant Poison
588 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000002000))
590 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.10f);
592 // Wound Poison
593 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000010000000))
595 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.04f);
597 break;
599 case SPELLFAMILY_HUNTER:
601 //Gore
602 if (m_spellInfo->SpellIconID == 1578)
604 if (m_caster->HasAura(57627)) // Charge 6 sec post-affect
605 damage *= 2;
607 // Mongoose Bite
608 else if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x000000002)) && m_spellInfo->SpellVisual[0]==342)
610 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.2f);
612 // Counterattack
613 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0008000000000000))
615 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.2f);
617 // Arcane Shot
618 else if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x00000800)) && m_spellInfo->maxLevel > 0)
620 damage += int32(m_caster->GetTotalAttackPowerValue(RANGED_ATTACK)*0.15f);
622 // Steady Shot
623 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x100000000))
625 int32 base = irand((int32)m_caster->GetWeaponDamageRange(RANGED_ATTACK, MINDAMAGE),(int32)m_caster->GetWeaponDamageRange(RANGED_ATTACK, MAXDAMAGE));
626 damage += int32(float(base)/m_caster->GetAttackTime(RANGED_ATTACK)*2800 + m_caster->GetTotalAttackPowerValue(RANGED_ATTACK)*0.1f);
628 // Explosive Trap Effect
629 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x00000004))
631 damage += int32(m_caster->GetTotalAttackPowerValue(RANGED_ATTACK)*0.1f);
633 break;
635 case SPELLFAMILY_PALADIN:
637 // Judgement of Vengeance/Corruption ${1+0.22*$SPH+0.14*$AP} + 10% for each application of Holy Vengeance/Blood Corruption on the target
638 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x800000000)) && m_spellInfo->SpellIconID==2292)
640 uint32 debuf_id;
641 switch(m_spellInfo->Id)
643 case 53733: debuf_id = 53742; break;// Judgement of Corruption -> Blood Corruption
644 case 31804: debuf_id = 31803; break;// Judgement of Vengeance -> Holy Vengeance
645 default: return;
648 float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
649 int32 holy = m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo)) +
650 m_caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellInfo), unitTarget);
651 damage+=int32(ap * 0.14f) + int32(holy * 22 / 100);
652 // Get stack of Holy Vengeance on the target added by caster
653 uint32 stacks = 0;
654 Unit::AuraList const& auras = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE);
655 for(Unit::AuraList::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
657 if( ((*itr)->GetId() == debuf_id) && (*itr)->GetCasterGUID()==m_caster->GetGUID())
659 stacks = (*itr)->GetStackAmount();
660 break;
663 // + 10% for each application of Holy Vengeance on the target
664 if(stacks)
665 damage += damage * stacks * 10 /100;
667 // Avenger's Shield ($m1+0.07*$SPH+0.07*$AP) - ranged sdb for future
668 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000004000))
670 float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
671 int32 holy = m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo)) +
672 m_caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellInfo), unitTarget);
673 damage += int32(ap * 0.07f) + int32(holy * 7 / 100);
675 // Hammer of Wrath ($m1+0.15*$SPH+0.15*$AP) - ranged type sdb future fix
676 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000008000000000))
678 float ap = m_caster->GetTotalAttackPowerValue(BASE_ATTACK);
679 int32 holy = m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo)) +
680 m_caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellInfo), unitTarget);
681 damage += int32(ap * 0.15f) + int32(holy * 15 / 100);
683 // Hammer of the Righteous
684 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0004000000000000))
686 // Add main hand dps * effect[2] amount
687 float average = (m_caster->GetFloatValue(UNIT_FIELD_MINDAMAGE) + m_caster->GetFloatValue(UNIT_FIELD_MAXDAMAGE)) / 2;
688 int32 count = m_caster->CalculateSpellDamage(m_spellInfo, 2, m_spellInfo->EffectBasePoints[2], unitTarget);
689 damage += count * int32(average * IN_MILISECONDS) / m_caster->GetAttackTime(BASE_ATTACK);
691 // Shield of Righteousness
692 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0010000000000000))
694 damage+=int32(m_caster->GetShieldBlockValue());
696 // Judgement
697 else if (m_spellInfo->Id == 54158)
699 // [1 + 0.25 * SPH + 0.16 * AP]
700 damage += int32(m_caster->GetTotalAttackPowerValue(BASE_ATTACK) * 0.16f);
702 break;
706 if(damage >= 0)
707 m_damage += damage;
711 void Spell::EffectDummy(uint32 i)
713 if (!unitTarget && !gameObjTarget && !itemTarget)
714 return;
716 // selection by spell family
717 switch(m_spellInfo->SpellFamilyName)
719 case SPELLFAMILY_GENERIC:
721 switch(m_spellInfo->Id )
723 case 8063: // Deviate Fish
725 if (m_caster->GetTypeId() != TYPEID_PLAYER)
726 return;
728 uint32 spell_id = 0;
729 switch(urand(1,5))
731 case 1: spell_id = 8064; break; // Sleepy
732 case 2: spell_id = 8065; break; // Invigorate
733 case 3: spell_id = 8066; break; // Shrink
734 case 4: spell_id = 8067; break; // Party Time!
735 case 5: spell_id = 8068; break; // Healthy Spirit
737 m_caster->CastSpell(m_caster, spell_id, true, NULL);
738 return;
740 case 8213: // Savory Deviate Delight
742 if (m_caster->GetTypeId() != TYPEID_PLAYER)
743 return;
745 uint32 spell_id = 0;
746 switch(urand(1,2))
748 // Flip Out - ninja
749 case 1: spell_id = (m_caster->getGender() == GENDER_MALE ? 8219 : 8220); break;
750 // Yaaarrrr - pirate
751 case 2: spell_id = (m_caster->getGender() == GENDER_MALE ? 8221 : 8222); break;
753 m_caster->CastSpell(m_caster,spell_id,true,NULL);
754 return;
756 case 8593: // Symbol of life (restore creature to life)
757 case 31225: // Shimmering Vessel (restore creature to life)
759 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
760 return;
761 ((Creature*)unitTarget)->setDeathState(JUST_ALIVED);
762 return;
764 case 12162: // Deep wounds
765 case 12850: // (now good common check for this spells)
766 case 12868:
768 if (!unitTarget)
769 return;
771 float damage;
772 // DW should benefit of attack power, damage percent mods etc.
773 // TODO: check if using offhand damage is correct and if it should be divided by 2
774 if (m_caster->haveOffhandWeapon() && m_caster->getAttackTimer(BASE_ATTACK) > m_caster->getAttackTimer(OFF_ATTACK))
775 damage = (m_caster->GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE) + m_caster->GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE))/2;
776 else
777 damage = (m_caster->GetFloatValue(UNIT_FIELD_MINDAMAGE) + m_caster->GetFloatValue(UNIT_FIELD_MAXDAMAGE))/2;
779 switch (m_spellInfo->Id)
781 case 12162: damage *= 0.16f; break; // Rank 1
782 case 12850: damage *= 0.32f; break; // Rank 2
783 case 12868: damage *= 0.48f; break; // Rank 3
784 default:
785 sLog.outError("Spell::EffectDummy: Spell %u not handled in DW",m_spellInfo->Id);
786 return;
789 // get remaining damage of old Deep Wound aura
790 Aura* deepWound = unitTarget->GetAura(12721, 0);
791 if (deepWound)
793 int32 remainingTicks = deepWound->GetAuraDuration() / deepWound->GetModifier()->periodictime;
794 damage += remainingTicks * deepWound->GetModifier()->m_amount;
797 // 1 tick/sec * 6 sec = 6 ticks
798 int32 deepWoundsDotBasePoints0 = int32(damage / 6);
799 m_caster->CastCustomSpell(unitTarget, 12721, &deepWoundsDotBasePoints0, NULL, NULL, true, NULL);
800 return;
802 case 13120: // net-o-matic
804 if (!unitTarget)
805 return;
807 uint32 spell_id = 0;
809 uint32 roll = urand(0, 99);
811 if (roll < 2) // 2% for 30 sec self root (off-like chance unknown)
812 spell_id = 16566;
813 else if (roll < 4) // 2% for 20 sec root, charge to target (off-like chance unknown)
814 spell_id = 13119;
815 else // normal root
816 spell_id = 13099;
818 m_caster->CastSpell(unitTarget,spell_id,true,NULL);
819 return;
821 case 13567: // Dummy Trigger
823 // can be used for different aura triggering, so select by aura
824 if (!m_triggeredByAuraSpell || !unitTarget)
825 return;
827 switch(m_triggeredByAuraSpell->Id)
829 case 26467: // Persistent Shield
830 m_caster->CastCustomSpell(unitTarget, 26470, &damage, NULL, NULL, true);
831 break;
832 default:
833 sLog.outError("EffectDummy: Non-handled case for spell 13567 for triggered aura %u",m_triggeredByAuraSpell->Id);
834 break;
836 return;
838 case 15998: // Capture Worg Pup
839 case 29435: // Capture Female Kaliri Hatchling
841 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
842 return;
844 Creature* creatureTarget = (Creature*)unitTarget;
846 creatureTarget->ForcedDespawn();
847 return;
849 case 16589: // Noggenfogger Elixir
851 if (m_caster->GetTypeId() != TYPEID_PLAYER)
852 return;
854 uint32 spell_id = 0;
855 switch(urand(1, 3))
857 case 1: spell_id = 16595; break;
858 case 2: spell_id = 16593; break;
859 default:spell_id = 16591; break;
862 m_caster->CastSpell(m_caster, spell_id, true, NULL);
863 return;
865 case 17251: // Spirit Healer Res
867 if (!unitTarget || !m_originalCaster)
868 return;
870 if (m_originalCaster->GetTypeId() == TYPEID_PLAYER)
872 WorldPacket data(SMSG_SPIRIT_HEALER_CONFIRM, 8);
873 data << uint64(unitTarget->GetGUID());
874 ((Player*)m_originalCaster)->GetSession()->SendPacket( &data );
876 return;
878 case 17271: // Test Fetid Skull
880 if (!itemTarget && m_caster->GetTypeId()!=TYPEID_PLAYER)
881 return;
883 uint32 spell_id = roll_chance_i(50)
884 ? 17269 // Create Resonating Skull
885 : 17270; // Create Bone Dust
887 m_caster->CastSpell(m_caster, spell_id, true, NULL);
888 return;
890 case 20577: // Cannibalize
891 if (unitTarget)
892 m_caster->CastSpell(m_caster, 20578, false, NULL);
893 return;
894 case 23019: // Crystal Prison Dummy DND
896 if (!unitTarget || !unitTarget->isAlive() || unitTarget->GetTypeId() != TYPEID_UNIT || ((Creature*)unitTarget)->isPet())
897 return;
899 Creature* creatureTarget = (Creature*)unitTarget;
900 if (creatureTarget->isPet())
901 return;
903 GameObject* pGameObj = new GameObject;
905 Map *map = creatureTarget->GetMap();
907 // create before death for get proper coordinates
908 if (!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), 179644, map, m_caster->GetPhaseMask(),
909 creatureTarget->GetPositionX(), creatureTarget->GetPositionY(), creatureTarget->GetPositionZ(),
910 creatureTarget->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY) )
912 delete pGameObj;
913 return;
916 pGameObj->SetRespawnTime(creatureTarget->GetRespawnTime()-time(NULL));
917 pGameObj->SetOwnerGUID(m_caster->GetGUID() );
918 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel() );
919 pGameObj->SetSpellId(m_spellInfo->Id);
921 creatureTarget->ForcedDespawn();
923 DEBUG_LOG("AddObject at SpellEfects.cpp EffectDummy");
924 map->Add(pGameObj);
926 return;
928 case 23074: // Arcanite Dragonling
929 if (!m_CastItem)
930 return;
931 m_caster->CastSpell(m_caster, 19804, true, m_CastItem);
932 return;
933 case 23075: // Mithril Mechanical Dragonling
934 if (!m_CastItem)
935 return;
936 m_caster->CastSpell(m_caster, 12749, true, m_CastItem);
937 return;
938 case 23076: // Mechanical Dragonling
939 if (!m_CastItem)
940 return;
941 m_caster->CastSpell(m_caster, 4073, true, m_CastItem);
942 return;
943 case 23133: // Gnomish Battle Chicken
944 if (!m_CastItem)
945 return;
946 m_caster->CastSpell(m_caster, 13166, true, m_CastItem);
947 return;
948 case 23448: // Transporter Arrival - Ultrasafe Transporter: Gadgetzan - backfires
950 int32 r = irand(0, 119);
951 if (r < 20) // Transporter Malfunction - 1/6 polymorph
952 m_caster->CastSpell(m_caster, 23444, true);
953 else if (r < 100) // Evil Twin - 4/6 evil twin
954 m_caster->CastSpell(m_caster, 23445, true);
955 else // Transporter Malfunction - 1/6 miss the target
956 m_caster->CastSpell(m_caster, 36902, true);
957 return;
959 case 23453: // Gnomish Transporter - Ultrasafe Transporter: Gadgetzan
960 if (roll_chance_i(50)) // Gadgetzan Transporter - success
961 m_caster->CastSpell(m_caster, 23441, true);
962 else // Gadgetzan Transporter Failure - failure
963 m_caster->CastSpell(m_caster, 23446, true);
964 return;
965 case 23645: // Hourglass Sand
966 m_caster->RemoveAurasDueToSpell(23170); // Brood Affliction: Bronze
967 return;
968 case 23725: // Gift of Life (warrior bwl trinket)
969 m_caster->CastSpell(m_caster, 23782, true);
970 m_caster->CastSpell(m_caster, 23783, true);
971 return;
972 case 25860: // Reindeer Transformation
974 if (!m_caster->HasAuraType(SPELL_AURA_MOUNTED))
975 return;
977 float flyspeed = m_caster->GetSpeedRate(MOVE_FLIGHT);
978 float speed = m_caster->GetSpeedRate(MOVE_RUN);
980 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
982 //5 different spells used depending on mounted speed and if mount can fly or not
983 if (flyspeed >= 4.1f)
984 // Flying Reindeer
985 m_caster->CastSpell(m_caster, 44827, true); //310% flying Reindeer
986 else if (flyspeed >= 3.8f)
987 // Flying Reindeer
988 m_caster->CastSpell(m_caster, 44825, true); //280% flying Reindeer
989 else if (flyspeed >= 1.6f)
990 // Flying Reindeer
991 m_caster->CastSpell(m_caster, 44824, true); //60% flying Reindeer
992 else if (speed >= 2.0f)
993 // Reindeer
994 m_caster->CastSpell(m_caster, 25859, true); //100% ground Reindeer
995 else
996 // Reindeer
997 m_caster->CastSpell(m_caster, 25858, true); //60% ground Reindeer
999 return;
1001 case 26074: // Holiday Cheer
1002 // implemented at client side
1003 return;
1004 case 28006: // Arcane Cloaking
1006 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER )
1007 // Naxxramas Entry Flag Effect DND
1008 m_caster->CastSpell(unitTarget, 29294, true);
1009 return;
1011 case 29200: // Purify Helboar Meat
1013 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1014 return;
1016 uint32 spell_id = roll_chance_i(50)
1017 ? 29277 // Summon Purified Helboar Meat
1018 : 29278; // Summon Toxic Helboar Meat
1020 m_caster->CastSpell(m_caster,spell_id,true,NULL);
1021 return;
1023 case 29858: // Soulshatter
1024 if (unitTarget && unitTarget->GetTypeId() == TYPEID_UNIT && unitTarget->IsHostileTo(m_caster))
1025 m_caster->CastSpell(unitTarget,32835,true);
1026 return;
1027 case 30458: // Nigh Invulnerability
1028 if (!m_CastItem)
1029 return;
1030 if (roll_chance_i(86)) // Nigh-Invulnerability - success
1031 m_caster->CastSpell(m_caster, 30456, true, m_CastItem);
1032 else // Complete Vulnerability - backfire in 14% casts
1033 m_caster->CastSpell(m_caster, 30457, true, m_CastItem);
1034 return;
1035 case 30507: // Poultryizer
1036 if(!m_CastItem)
1037 return;
1038 if (roll_chance_i(80)) // Poultryized! - success
1039 m_caster->CastSpell(unitTarget, 30501, true, m_CastItem);
1040 else // Poultryized! - backfire 20%
1041 m_caster->CastSpell(unitTarget, 30504, true, m_CastItem);
1042 return;
1043 case 33060: // Make a Wish
1045 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1046 return;
1048 uint32 spell_id = 0;
1050 switch(urand(1,5))
1052 case 1: spell_id = 33053; break; // Mr Pinchy's Blessing
1053 case 2: spell_id = 33057; break; // Summon Mighty Mr. Pinchy
1054 case 3: spell_id = 33059; break; // Summon Furious Mr. Pinchy
1055 case 4: spell_id = 33062; break; // Tiny Magical Crawdad
1056 case 5: spell_id = 33064; break; // Mr. Pinchy's Gift
1059 m_caster->CastSpell(m_caster, spell_id, true, NULL);
1060 return;
1062 case 34665: //Administer Antidote
1064 if (!unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER )
1065 return;
1066 // Spell has scriptable target but for sure.
1067 if (unitTarget->GetTypeId() != TYPEID_UNIT)
1068 return;
1070 uint32 health = unitTarget->GetHealth();
1071 float x, y, z, o;
1073 unitTarget->GetPosition(x, y, z);
1074 o = unitTarget->GetOrientation();
1075 ((Creature*)unitTarget)->ForcedDespawn();
1077 if (Creature* summon = m_caster->SummonCreature(16992, x, y, z, o,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,180000))
1079 summon->SetHealth(health);
1080 ((Player*)m_caster)->RewardPlayerAndGroupAtEvent(16992, summon);
1082 if (summon->AI())
1083 summon->AI()->AttackStart(m_caster);
1085 return;
1087 case 35745: // Socrethar's Stone
1089 uint32 spell_id;
1090 switch(m_caster->GetAreaId())
1092 case 3900: spell_id = 35743; break; // Socrethar Portal
1093 case 3742: spell_id = 35744; break; // Socrethar Portal
1094 default: return;
1097 m_caster->CastSpell(m_caster, spell_id, true);
1098 return;
1100 case 37674: // Chaos Blast
1102 if (!unitTarget)
1103 return;
1105 int32 basepoints0 = 100;
1106 m_caster->CastCustomSpell(unitTarget, 37675, &basepoints0, NULL, NULL, true);
1107 return;
1109 case 40802: // Mingo's Fortune Generator (Mingo's Fortune Giblets)
1111 // selecting one from Bloodstained Fortune item
1112 uint32 newitemid;
1113 switch(urand(1, 20))
1115 case 1: newitemid = 32688; break;
1116 case 2: newitemid = 32689; break;
1117 case 3: newitemid = 32690; break;
1118 case 4: newitemid = 32691; break;
1119 case 5: newitemid = 32692; break;
1120 case 6: newitemid = 32693; break;
1121 case 7: newitemid = 32700; break;
1122 case 8: newitemid = 32701; break;
1123 case 9: newitemid = 32702; break;
1124 case 10: newitemid = 32703; break;
1125 case 11: newitemid = 32704; break;
1126 case 12: newitemid = 32705; break;
1127 case 13: newitemid = 32706; break;
1128 case 14: newitemid = 32707; break;
1129 case 15: newitemid = 32708; break;
1130 case 16: newitemid = 32709; break;
1131 case 17: newitemid = 32710; break;
1132 case 18: newitemid = 32711; break;
1133 case 19: newitemid = 32712; break;
1134 case 20: newitemid = 32713; break;
1135 default:
1136 return;
1139 DoCreateItem(i, newitemid);
1140 return;
1142 // Demon Broiled Surprise
1143 /* FIX ME: Required for correct work implementing implicit target 7 (in pair (22,7))
1144 case 43723:
1146 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1147 return;
1149 ((Player*)m_caster)->CastSpell(unitTarget, 43753, true);
1150 return;
1153 case 44875: // Complete Raptor Capture
1155 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
1156 return;
1158 Creature* creatureTarget = (Creature*)unitTarget;
1160 creatureTarget->ForcedDespawn();
1162 //cast spell Raptor Capture Credit
1163 m_caster->CastSpell(m_caster, 42337, true, NULL);
1164 return;
1166 case 44997: // Converting Sentry
1168 //Converted Sentry Credit
1169 m_caster->CastSpell(m_caster, 45009, true);
1170 return;
1172 case 45030: // Impale Emissary
1174 // Emissary of Hate Credit
1175 m_caster->CastSpell(m_caster, 45088, true);
1176 return;
1178 case 49357: // Brewfest Mount Transformation
1179 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1180 return;
1182 if (!m_caster->HasAuraType(SPELL_AURA_MOUNTED))
1183 return;
1185 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1187 // Ram for Alliance, Kodo for Horde
1188 if (((Player *)m_caster)->GetTeam() == ALLIANCE)
1190 if (m_caster->GetSpeedRate(MOVE_RUN) >= 2.0f)
1191 // 100% Ram
1192 m_caster->CastSpell(m_caster, 43900, true);
1193 else
1194 // 60% Ram
1195 m_caster->CastSpell(m_caster, 43899, true);
1197 else
1199 if (((Player *)m_caster)->GetSpeedRate(MOVE_RUN) >= 2.0f)
1200 // 100% Kodo
1201 m_caster->CastSpell(m_caster, 49379, true);
1202 else
1203 // 60% Kodo
1204 m_caster->CastSpell(m_caster, 49378, true);
1206 return;
1207 case 50243: // Teach Language
1209 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1210 return;
1212 // spell has a 1/3 chance to trigger one of the below
1213 if (roll_chance_i(66))
1214 return;
1215 if (((Player*)m_caster)->GetTeam() == ALLIANCE)
1217 // 1000001 - gnomish binary
1218 m_caster->CastSpell(m_caster, 50242, true);
1220 else
1222 // 01001000 - goblin binary
1223 m_caster->CastSpell(m_caster, 50246, true);
1226 return;
1228 case 51582: //Rocket Boots Engaged (Rocket Boots Xtreme and Rocket Boots Xtreme Lite)
1230 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1231 return;
1233 if (BattleGround* bg = ((Player*)m_caster)->GetBattleGround())
1234 bg->EventPlayerDroppedFlag((Player*)m_caster);
1236 m_caster->CastSpell(m_caster, 30452, true, NULL);
1237 return;
1239 case 51592: // Pickup Primordial Hatchling
1241 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT)
1242 return;
1244 Creature* creatureTarget = (Creature*)unitTarget;
1246 creatureTarget->ForcedDespawn();
1247 return;
1250 case 52308: // Take Sputum Sample
1252 switch(i)
1254 case 0:
1256 uint32 spellID = m_spellInfo->CalculateSimpleValue(0);
1257 uint32 reqAuraID = m_spellInfo->CalculateSimpleValue(1);
1259 if (m_caster->HasAura(reqAuraID,0))
1260 m_caster->CastSpell(m_caster, spellID, true, NULL);
1261 return;
1263 case 1:
1264 return; // additional data for dummy[0]
1266 return;
1268 case 52759: // Ancestral Awakening
1269 if (!unitTarget)
1270 return;
1271 m_caster->CastCustomSpell(unitTarget, 52752, &damage, NULL, NULL, true);
1272 return;
1273 case 52845: // Brewfest Mount Transformation (Faction Swap)
1274 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1275 return;
1277 if (!m_caster->HasAuraType(SPELL_AURA_MOUNTED))
1278 return;
1280 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
1282 // Ram for Horde, Kodo for Alliance
1283 if (((Player *)m_caster)->GetTeam() == HORDE)
1285 if (m_caster->GetSpeedRate(MOVE_RUN) >= 2.0f)
1286 // Swift Brewfest Ram, 100% Ram
1287 m_caster->CastSpell(m_caster, 43900, true);
1288 else
1289 // Brewfest Ram, 60% Ram
1290 m_caster->CastSpell(m_caster, 43899, true);
1292 else
1294 if (((Player *)m_caster)->GetSpeedRate(MOVE_RUN) >= 2.0f)
1295 // Great Brewfest Kodo, 100% Kodo
1296 m_caster->CastSpell(m_caster, 49379, true);
1297 else
1298 // Brewfest Riding Kodo, 60% Kodo
1299 m_caster->CastSpell(m_caster, 49378, true);
1301 return;
1302 case 53341: // Rune of Cinderglacier
1303 case 53343: // Rune of Razorice
1305 // Runeforging Credit
1306 m_caster->CastSpell(m_caster, 54586, true);
1307 return;
1309 case 55004: // Nitro Boosts
1310 if (!m_CastItem)
1311 return;
1312 if (roll_chance_i(95)) // Nitro Boosts - success
1313 m_caster->CastSpell(m_caster, 54861, true, m_CastItem);
1314 else // Knocked Up - backfire 5%
1315 m_caster->CastSpell(m_caster, 46014, true, m_CastItem);
1316 return;
1317 case 58418: // Portal to Orgrimmar
1318 case 58420: // Portal to Stormwind
1319 return; // implemented in EffectScript[0]
1320 case 59640: // Underbelly Elixir
1322 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1323 return;
1325 uint32 spell_id = 0;
1326 switch(urand(1,3))
1328 case 1: spell_id = 59645; break;
1329 case 2: spell_id = 59831; break;
1330 case 3: spell_id = 59843; break;
1332 m_caster->CastSpell(m_caster,spell_id,true,NULL);
1333 return;
1335 case 60932: // Disengage (one from creature versions)
1336 if (!unitTarget)
1337 return;
1338 m_caster->CastSpell(unitTarget,60934,true,NULL);
1339 return;
1340 case 67019: // Flask of the North
1342 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1343 return;
1345 uint32 spell_id = 0;
1346 switch(m_caster->getClass())
1348 case CLASS_WARRIOR:
1349 case CLASS_DEATH_KNIGHT:
1350 spell_id = 67018; // STR for Warriors, Death Knights
1351 break;
1352 case CLASS_ROGUE:
1353 case CLASS_HUNTER:
1354 spell_id = 67017; // AP for Rogues, Hunters
1355 break;
1356 case CLASS_PRIEST:
1357 case CLASS_MAGE:
1358 case CLASS_WARLOCK:
1359 spell_id = 67016; // SPD for Priests, Mages, Warlocks
1360 break;
1361 case CLASS_SHAMAN:
1362 // random (SPD, AP)
1363 spell_id = roll_chance_i(50) ? 67016 : 67017;
1364 break;
1365 case CLASS_PALADIN:
1366 case CLASS_DRUID:
1367 default:
1368 // random (SPD, STR)
1369 spell_id = roll_chance_i(50) ? 67016 : 67018;
1370 break;
1372 m_caster->CastSpell(m_caster, spell_id, true);
1373 return;
1376 break;
1378 case SPELLFAMILY_MAGE:
1379 switch(m_spellInfo->Id )
1381 case 11958: // Cold Snap
1383 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1384 return;
1386 // immediately finishes the cooldown on Frost spells
1387 const SpellCooldowns& cm = ((Player *)m_caster)->GetSpellCooldownMap();
1388 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1390 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1392 if (spellInfo->SpellFamilyName == SPELLFAMILY_MAGE &&
1393 (GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_FROST) &&
1394 spellInfo->Id != 11958 && GetSpellRecoveryTime(spellInfo) > 0)
1396 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first, true);
1398 else
1399 ++itr;
1401 return;
1403 case 32826: // Polymorph Cast Visual
1405 if (unitTarget && unitTarget->GetTypeId() == TYPEID_UNIT)
1407 //Polymorph Cast Visual Rank 1
1408 const uint32 spell_list[6] = {
1409 32813, // Squirrel Form
1410 32816, // Giraffe Form
1411 32817, // Serpent Form
1412 32818, // Dragonhawk Form
1413 32819, // Worgen Form
1414 32820 // Sheep Form
1416 unitTarget->CastSpell( unitTarget, spell_list[urand(0, 5)], true);
1418 return;
1421 break;
1422 case SPELLFAMILY_WARRIOR:
1423 // Charge
1424 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x1)) && m_spellInfo->SpellVisual[0] == 867)
1426 int32 chargeBasePoints0 = damage;
1427 m_caster->CastCustomSpell(m_caster, 34846, &chargeBasePoints0, NULL, NULL, true);
1428 return;
1430 // Execute
1431 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x20000000))
1433 if(!unitTarget)
1434 return;
1436 uint32 rage = m_caster->GetPower(POWER_RAGE);
1438 // up to max 30 rage cost
1439 if(rage > 300)
1440 rage = 300;
1442 // Glyph of Execution bonus
1443 uint32 rage_modified = rage;
1445 if (Aura *aura = m_caster->GetDummyAura(58367))
1446 rage_modified += aura->GetModifier()->m_amount*10;
1448 int32 basePoints0 = damage+int32(rage_modified * m_spellInfo->DmgMultiplier[i] +
1449 m_caster->GetTotalAttackPowerValue(BASE_ATTACK)*0.2f);
1451 m_caster->CastCustomSpell(unitTarget, 20647, &basePoints0, NULL, NULL, true, 0);
1453 // Sudden Death
1454 if(m_caster->HasAura(52437))
1456 Unit::AuraList const& auras = m_caster->GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL);
1457 for (Unit::AuraList::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
1459 // Only Sudden Death have this SpellIconID with SPELL_AURA_PROC_TRIGGER_SPELL
1460 if ((*itr)->GetSpellProto()->SpellIconID == 1989)
1462 // saved rage top stored in next affect
1463 uint32 lastrage = (*itr)->GetSpellProto()->CalculateSimpleValue(1)*10;
1464 if(lastrage < rage)
1465 rage -= lastrage;
1466 break;
1471 m_caster->SetPower(POWER_RAGE,m_caster->GetPower(POWER_RAGE)-rage);
1472 return;
1474 // Slam
1475 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000200000))
1477 if(!unitTarget)
1478 return;
1479 m_damage+=m_caster->CalculateDamage(m_attackType, false);
1480 m_damage+=damage;
1481 return;
1483 // Concussion Blow
1484 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000004000000))
1486 m_damage+= uint32(damage * m_caster->GetTotalAttackPowerValue(BASE_ATTACK) / 100);
1487 return;
1490 switch(m_spellInfo->Id)
1492 // Warrior's Wrath
1493 case 21977:
1495 if (!unitTarget)
1496 return;
1497 m_caster->CastSpell(unitTarget, 21887, true);// spell mod
1498 return;
1500 // Last Stand
1501 case 12975:
1503 int32 healthModSpellBasePoints0 = int32(m_caster->GetMaxHealth()*0.3);
1504 m_caster->CastCustomSpell(m_caster, 12976, &healthModSpellBasePoints0, NULL, NULL, true, NULL);
1505 return;
1507 // Bloodthirst
1508 case 23881:
1510 m_caster->CastCustomSpell(unitTarget, 23885, &damage, NULL, NULL, true, NULL);
1511 return;
1514 break;
1515 case SPELLFAMILY_WARLOCK:
1516 // Life Tap
1517 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000040000))
1519 // In 303 exist spirit depend
1520 uint32 spirit = uint32(m_caster->GetStat(STAT_SPIRIT));
1521 switch (m_spellInfo->Id)
1523 case 1454: damage+=spirit; break;
1524 case 1455: damage+=spirit*15/10; break;
1525 case 1456: damage+=spirit*2; break;
1526 case 11687: damage+=spirit*25/10; break;
1527 case 11688:
1528 case 11689:
1529 case 27222:
1530 case 57946: damage+=spirit*3; break;
1531 default:
1532 sLog.outError("Spell::EffectDummy: %u Life Tap need set spirit multipler", m_spellInfo->Id);
1533 return;
1535 // Think its not need (also need remove Life Tap from SpellDamageBonus or add new value)
1536 // damage = m_caster->SpellDamageBonus(m_caster, m_spellInfo,uint32(damage > 0 ? damage : 0), SPELL_DIRECT_DAMAGE);
1537 if (unitTarget && (int32(unitTarget->GetHealth()) > damage))
1539 // Shouldn't Appear in Combat Log
1540 unitTarget->ModifyHealth(-damage);
1542 int32 mana = damage;
1543 // Improved Life Tap mod
1544 Unit::AuraList const& auraDummy = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
1545 for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr != auraDummy.end(); ++itr)
1547 if((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (*itr)->GetSpellProto()->SpellIconID == 208)
1548 mana = ((*itr)->GetModifier()->m_amount + 100)* mana / 100;
1550 m_caster->CastCustomSpell(unitTarget, 31818, &mana, NULL, NULL, true);
1552 // Mana Feed
1553 int32 manaFeedVal = 0;
1554 Unit::AuraList const& mod = m_caster->GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER);
1555 for(Unit::AuraList::const_iterator itr = mod.begin(); itr != mod.end(); ++itr)
1557 if((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_WARLOCK && (*itr)->GetSpellProto()->SpellIconID == 1982)
1558 manaFeedVal+= (*itr)->GetModifier()->m_amount;
1560 if (manaFeedVal > 0)
1562 manaFeedVal = manaFeedVal * mana / 100;
1563 m_caster->CastCustomSpell(m_caster, 32553, &manaFeedVal, NULL, NULL, true, NULL);
1566 else
1567 SendCastResult(SPELL_FAILED_FIZZLE);
1568 return;
1570 break;
1571 case SPELLFAMILY_PRIEST:
1572 // Penance
1573 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0080000000000000))
1575 if (!unitTarget)
1576 return;
1578 int hurt = 0;
1579 int heal = 0;
1580 switch(m_spellInfo->Id)
1582 case 47540: hurt = 47758; heal = 47757; break;
1583 case 53005: hurt = 53001; heal = 52986; break;
1584 case 53006: hurt = 53002; heal = 52987; break;
1585 case 53007: hurt = 53003; heal = 52988; break;
1586 default:
1587 sLog.outError("Spell::EffectDummy: Spell %u Penance need set correct heal/damage spell", m_spellInfo->Id);
1588 return;
1590 if (m_caster->IsFriendlyTo(unitTarget))
1591 m_caster->CastSpell(unitTarget, heal, true, 0);
1592 else
1593 m_caster->CastSpell(unitTarget, hurt, true, 0);
1594 return;
1596 break;
1597 case SPELLFAMILY_DRUID:
1598 // Starfall
1599 if (m_spellInfo->SpellFamilyFlags2 & UI64LIT(0x00000100))
1601 //Shapeshifting into an animal form or mounting cancels the effect.
1602 if(m_caster->GetCreatureType() == CREATURE_TYPE_BEAST || m_caster->IsMounted())
1604 if(m_triggeredByAuraSpell)
1605 m_caster->RemoveAurasDueToSpell(m_triggeredByAuraSpell->Id);
1606 return;
1609 //Any effect which causes you to lose control of your character will supress the starfall effect.
1610 if (m_caster->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_FLEEING | UNIT_STAT_ROOT | UNIT_STAT_CONFUSED))
1611 return;
1613 switch(m_spellInfo->Id)
1615 case 50286: m_caster->CastSpell(unitTarget, 50288, true); return;
1616 case 53196: m_caster->CastSpell(unitTarget, 53191, true); return;
1617 case 53197: m_caster->CastSpell(unitTarget, 53194, true); return;
1618 case 53198: m_caster->CastSpell(unitTarget, 53195, true); return;
1619 default:
1620 sLog.outError("Spell::EffectDummy: Unhandeled Starfall spell rank %u",m_spellInfo->Id);
1621 return;
1624 break;
1625 case SPELLFAMILY_ROGUE:
1626 switch(m_spellInfo->Id )
1628 case 5938: // Shiv
1630 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1631 return;
1633 Player *pCaster = ((Player*)m_caster);
1635 Item *item = pCaster->GetWeaponForAttack(OFF_ATTACK);
1636 if (!item)
1637 return;
1639 // all poison enchantments is temporary
1640 uint32 enchant_id = item->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT);
1641 if (!enchant_id)
1642 return;
1644 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
1645 if (!pEnchant)
1646 return;
1648 for (int s=0;s<3;s++)
1650 if (pEnchant->type[s]!=ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL)
1651 continue;
1653 SpellEntry const* combatEntry = sSpellStore.LookupEntry(pEnchant->spellid[s]);
1654 if (!combatEntry || combatEntry->Dispel != DISPEL_POISON)
1655 continue;
1657 m_caster->CastSpell(unitTarget, combatEntry, true, item);
1660 m_caster->CastSpell(unitTarget, 5940, true);
1661 return;
1663 case 14185: // Preparation
1665 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1666 return;
1668 //immediately finishes the cooldown on certain Rogue abilities
1669 const SpellCooldowns& cm = ((Player *)m_caster)->GetSpellCooldownMap();
1670 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1672 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1674 if (spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && (spellInfo->SpellFamilyFlags & UI64LIT(0x0000024000000860)))
1675 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first,true);
1676 else
1677 ++itr;
1679 return;
1681 case 31231: // Cheat Death
1683 m_caster->CastSpell(m_caster, 45182, true);
1684 return;
1687 break;
1688 case SPELLFAMILY_HUNTER:
1689 // Steady Shot
1690 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x100000000))
1692 if (!unitTarget || !unitTarget->isAlive())
1693 return;
1695 bool found = false;
1697 // check dazed affect
1698 Unit::AuraList const& decSpeedList = unitTarget->GetAurasByType(SPELL_AURA_MOD_DECREASE_SPEED);
1699 for(Unit::AuraList::const_iterator iter = decSpeedList.begin(); iter != decSpeedList.end(); ++iter)
1701 if ((*iter)->GetSpellProto()->SpellIconID==15 && (*iter)->GetSpellProto()->Dispel==0)
1703 found = true;
1704 break;
1708 if (found)
1709 m_damage+= damage;
1710 return;
1713 // Disengage
1714 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000400000000000))
1716 Unit* target = unitTarget;
1717 uint32 spellid;
1718 switch(m_spellInfo->Id)
1720 case 57635: spellid = 57636; break; // one from creature cases
1721 case 61507: spellid = 61508; break; // one from creature cases
1722 default:
1723 sLog.outError("Spell %u not handled propertly in EffectDummy(Disengage)",m_spellInfo->Id);
1724 return;
1726 if (!target || !target->isAlive())
1727 return;
1728 m_caster->CastSpell(target,spellid,true,NULL);
1731 switch(m_spellInfo->Id)
1733 case 23989: // Readiness talent
1735 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1736 return;
1738 //immediately finishes the cooldown for hunter abilities
1739 const SpellCooldowns& cm = ((Player*)m_caster)->GetSpellCooldownMap();
1740 for (SpellCooldowns::const_iterator itr = cm.begin(); itr != cm.end();)
1742 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
1744 if (spellInfo->SpellFamilyName == SPELLFAMILY_HUNTER && spellInfo->Id != 23989 && GetSpellRecoveryTime(spellInfo) > 0 )
1745 ((Player*)m_caster)->RemoveSpellCooldown((itr++)->first,true);
1746 else
1747 ++itr;
1749 return;
1751 case 37506: // Scatter Shot
1753 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1754 return;
1756 // break Auto Shot and autohit
1757 m_caster->InterruptSpell(CURRENT_AUTOREPEAT_SPELL);
1758 m_caster->AttackStop();
1759 ((Player*)m_caster)->SendAttackSwingCancelAttack();
1760 return;
1762 // Last Stand
1763 case 53478:
1765 if (!unitTarget)
1766 return;
1767 int32 healthModSpellBasePoints0 = int32(unitTarget->GetMaxHealth() * 0.3);
1768 unitTarget->CastCustomSpell(unitTarget, 53479, &healthModSpellBasePoints0, NULL, NULL, true, NULL);
1769 return;
1771 // Master's Call
1772 case 53271:
1774 Pet* pet = m_caster->GetPet();
1775 if (!pet || !unitTarget)
1776 return;
1778 pet->CastSpell(unitTarget, m_spellInfo->CalculateSimpleValue(i), true);
1779 return;
1782 break;
1783 case SPELLFAMILY_PALADIN:
1784 switch(m_spellInfo->SpellIconID)
1786 case 156: // Holy Shock
1788 if (!unitTarget)
1789 return;
1791 int hurt = 0;
1792 int heal = 0;
1794 switch(m_spellInfo->Id)
1796 case 20473: hurt = 25912; heal = 25914; break;
1797 case 20929: hurt = 25911; heal = 25913; break;
1798 case 20930: hurt = 25902; heal = 25903; break;
1799 case 27174: hurt = 27176; heal = 27175; break;
1800 case 33072: hurt = 33073; heal = 33074; break;
1801 case 48824: hurt = 48822; heal = 48820; break;
1802 case 48825: hurt = 48823; heal = 48821; break;
1803 default:
1804 sLog.outError("Spell::EffectDummy: Spell %u not handled in HS",m_spellInfo->Id);
1805 return;
1808 if (m_caster->IsFriendlyTo(unitTarget))
1809 m_caster->CastSpell(unitTarget, heal, true, 0);
1810 else
1811 m_caster->CastSpell(unitTarget, hurt, true, 0);
1813 return;
1815 case 561: // Judgement of command
1817 if (!unitTarget)
1818 return;
1820 uint32 spell_id = m_currentBasePoints[i]+1;
1821 SpellEntry const* spell_proto = sSpellStore.LookupEntry(spell_id);
1822 if (!spell_proto)
1823 return;
1825 m_caster->CastSpell(unitTarget, spell_proto, true, NULL);
1826 return;
1830 switch(m_spellInfo->Id)
1832 // Judgement of Righteousness (0.2*$AP+0.32*$SPH) holy added in spellDamagBonus
1833 case 20187:
1835 if (!unitTarget)
1836 return;
1837 m_damage+=int32(0.2f*m_caster->GetTotalAttackPowerValue(BASE_ATTACK));
1838 return;
1840 case 31789: // Righteous Defense (step 1)
1842 if (m_caster->GetTypeId() != TYPEID_PLAYER)
1844 SendCastResult(SPELL_FAILED_TARGET_AFFECTING_COMBAT);
1845 return;
1848 // 31989 -> dummy effect (step 1) + dummy effect (step 2) -> 31709 (taunt like spell for each target)
1849 Unit* friendTarget = !unitTarget || unitTarget->IsFriendlyTo(m_caster) ? unitTarget : unitTarget->getVictim();
1850 if (friendTarget)
1852 Player* player = friendTarget->GetCharmerOrOwnerPlayerOrPlayerItself();
1853 if (!player || !player->IsInSameRaidWith((Player*)m_caster))
1854 friendTarget = NULL;
1857 // non-standard cast requirement check
1858 if (!friendTarget || friendTarget->getAttackers().empty())
1860 ((Player*)m_caster)->RemoveSpellCooldown(m_spellInfo->Id,true);
1861 SendCastResult(SPELL_FAILED_TARGET_AFFECTING_COMBAT);
1862 return;
1865 // Righteous Defense (step 2) (in old version 31980 dummy effect)
1866 // Clear targets for eff 1
1867 for(std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin();ihit != m_UniqueTargetInfo.end();++ihit)
1868 ihit->effectMask &= ~(1<<1);
1870 // not empty (checked), copy
1871 Unit::AttackerSet attackers = friendTarget->getAttackers();
1873 // selected from list 3
1874 for(int i = 0; i < std::min(size_t(3),attackers.size()); ++i)
1876 Unit::AttackerSet::iterator aItr = attackers.begin();
1877 std::advance(aItr, rand() % attackers.size());
1878 AddUnitTarget((*aItr), 1);
1879 attackers.erase(aItr);
1882 // now let next effect cast spell at each target.
1883 return;
1885 case 37877: // Blessing of Faith
1887 if (!unitTarget)
1888 return;
1890 uint32 spell_id = 0;
1891 switch(unitTarget->getClass())
1893 case CLASS_DRUID: spell_id = 37878; break;
1894 case CLASS_PALADIN: spell_id = 37879; break;
1895 case CLASS_PRIEST: spell_id = 37880; break;
1896 case CLASS_SHAMAN: spell_id = 37881; break;
1897 default: return; // ignore for not healing classes
1900 m_caster->CastSpell(m_caster, spell_id, true);
1901 return;
1904 break;
1905 case SPELLFAMILY_SHAMAN:
1906 // Cleansing Totem
1907 if ((m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000004000000)) && m_spellInfo->SpellIconID==1673)
1909 if (unitTarget)
1910 m_caster->CastSpell(unitTarget, 52025, true);
1911 return;
1913 // Healing Stream Totem
1914 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000002000))
1916 if (unitTarget)
1917 m_caster->CastCustomSpell(unitTarget, 52042, &damage, 0, 0, true, 0, 0, m_originalCasterGUID);
1918 return;
1920 // Mana Spring Totem
1921 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000004000))
1923 if (!unitTarget || unitTarget->getPowerType()!=POWER_MANA)
1924 return;
1925 m_caster->CastCustomSpell(unitTarget, 52032, &damage, 0, 0, true, 0, 0, m_originalCasterGUID);
1926 return;
1928 if (m_spellInfo->Id == 39610) // Mana Tide Totem effect
1930 if (!unitTarget || unitTarget->getPowerType() != POWER_MANA)
1931 return;
1932 // Glyph of Mana Tide
1933 if (Unit *owner = m_caster->GetOwner())
1934 if (Aura *dummy = owner->GetDummyAura(55441))
1935 damage+=dummy->GetModifier()->m_amount;
1936 // Regenerate 6% of Total Mana Every 3 secs
1937 int32 EffectBasePoints0 = unitTarget->GetMaxPower(POWER_MANA) * damage / 100;
1938 m_caster->CastCustomSpell(unitTarget, 39609, &EffectBasePoints0, NULL, NULL, true, NULL, NULL, m_originalCasterGUID);
1939 return;
1941 // Lava Lash
1942 if (m_spellInfo->SpellFamilyFlags2 & 0x00000004)
1944 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
1945 return;
1946 Item *item = ((Player*)m_caster)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND);
1947 if (item)
1949 // Damage is increased if your off-hand weapon is enchanted with Flametongue.
1950 Unit::AuraList const& auraDummy = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
1951 for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr != auraDummy.end(); ++itr)
1953 if ((*itr)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_SHAMAN &&
1954 ((*itr)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000200000)) &&
1955 (*itr)->GetCastItemGUID() == item->GetGUID())
1957 m_damage += m_damage * damage / 100;
1958 return;
1962 return;
1964 break;
1965 case SPELLFAMILY_DEATHKNIGHT:
1966 // Death Coil
1967 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x002000))
1969 if (m_caster->IsFriendlyTo(unitTarget))
1971 if (unitTarget->GetCreatureType() != CREATURE_TYPE_UNDEAD)
1972 return;
1974 int32 bp = damage * 1.5f;
1975 m_caster->CastCustomSpell(unitTarget, 47633, &bp, NULL, NULL, true);
1977 else
1979 int32 bp = damage;
1980 m_caster->CastCustomSpell(unitTarget, 47632, &bp, NULL, NULL, true);
1982 return;
1984 // Hungering Cold
1985 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000100000000000))
1987 m_caster->CastSpell(m_caster, 51209, true);
1988 return;
1990 // Death Strike
1991 else if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000010))
1993 uint32 count = 0;
1994 Unit::AuraMap const& auras = unitTarget->GetAuras();
1995 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
1997 if (itr->second->GetSpellProto()->Dispel == DISPEL_DISEASE &&
1998 itr->second->GetCasterGUID() == m_caster->GetGUID() &&
1999 IsSpellLastAuraEffect(itr->second->GetSpellProto(), itr->second->GetEffIndex()))
2001 ++count;
2002 // max. 15%
2003 if (count == 3)
2004 break;
2008 int32 bp = count * m_caster->GetMaxHealth() * m_spellInfo->DmgMultiplier[0] / 100;
2009 m_caster->CastCustomSpell(m_caster, 45470, &bp, NULL, NULL, true);
2010 return;
2012 break;
2015 // pet auras
2016 if (PetAura const* petSpell = sSpellMgr.GetPetAura(m_spellInfo->Id, i))
2018 m_caster->AddPetAura(petSpell);
2019 return;
2022 // Script based implementation. Must be used only for not good for implementation in core spell effects
2023 // So called only for not proccessed cases
2024 if (gameObjTarget)
2025 Script->EffectDummyGameObj(m_caster, m_spellInfo->Id, i, gameObjTarget);
2026 else if (unitTarget && unitTarget->GetTypeId()==TYPEID_UNIT)
2027 Script->EffectDummyCreature(m_caster, m_spellInfo->Id, i, (Creature*)unitTarget);
2028 else if (itemTarget)
2029 Script->EffectDummyItem(m_caster, m_spellInfo->Id, i, itemTarget);
2032 void Spell::EffectTriggerSpellWithValue(uint32 i)
2034 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2036 // normal case
2037 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2039 if(!spellInfo)
2041 sLog.outError("EffectTriggerSpellWithValue of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2042 return;
2045 int32 bp = damage;
2046 m_caster->CastCustomSpell(unitTarget,triggered_spell_id,&bp,&bp,&bp,true,NULL,NULL,m_originalCasterGUID);
2049 void Spell::EffectTriggerRitualOfSummoning(uint32 i)
2051 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2052 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2054 if(!spellInfo)
2056 sLog.outError("EffectTriggerRitualOfSummoning of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2057 return;
2060 finish();
2062 m_caster->CastSpell(unitTarget,spellInfo,false);
2065 void Spell::EffectForceCast(uint32 i)
2067 if( !unitTarget )
2068 return;
2070 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[i];
2072 // normal case
2073 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2075 if(!spellInfo)
2077 sLog.outError("EffectForceCast of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2078 return;
2081 unitTarget->CastSpell(unitTarget, spellInfo, true, NULL, NULL, m_originalCasterGUID);
2084 void Spell::EffectTriggerSpell(uint32 effIndex)
2086 // only unit case known
2087 if (!unitTarget)
2089 if(gameObjTarget || itemTarget)
2090 sLog.outError("Spell::EffectTriggerSpell (Spell: %u): Unsupported non-unit case!",m_spellInfo->Id);
2091 return;
2094 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[effIndex];
2096 // special cases
2097 switch(triggered_spell_id)
2099 // Vanish (not exist)
2100 case 18461:
2102 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
2103 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
2104 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STALKED);
2106 // if this spell is given to NPC it must handle rest by it's own AI
2107 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
2108 return;
2110 // get highest rank of the Stealth spell
2111 uint32 spellId = 0;
2112 const PlayerSpellMap& sp_list = ((Player*)unitTarget)->GetSpellMap();
2113 for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr)
2115 // only highest rank is shown in spell book, so simply check if shown in spell book
2116 if (!itr->second->active || itr->second->disabled || itr->second->state == PLAYERSPELL_REMOVED)
2117 continue;
2119 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
2120 if (!spellInfo)
2121 continue;
2123 if (spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE_STEALTH)
2125 spellId = spellInfo->Id;
2126 break;
2130 // no Stealth spell found
2131 if (!spellId)
2132 return;
2134 // reset cooldown on it if needed
2135 if (((Player*)unitTarget)->HasSpellCooldown(spellId))
2136 ((Player*)unitTarget)->RemoveSpellCooldown(spellId);
2138 m_caster->CastSpell(unitTarget, spellId, true);
2139 return;
2141 // just skip
2142 case 23770: // Sayge's Dark Fortune of *
2143 // not exist, common cooldown can be implemented in scripts if need.
2144 return;
2145 // Brittle Armor - (need add max stack of 24575 Brittle Armor)
2146 case 29284:
2148 // Brittle Armor
2149 SpellEntry const* spell = sSpellStore.LookupEntry(24575);
2150 if (!spell)
2151 return;
2153 for (int j=0; j < spell->StackAmount; ++j)
2154 m_caster->CastSpell(unitTarget, spell->Id, true, m_CastItem, NULL, m_originalCasterGUID);
2155 return;
2157 // Mercurial Shield - (need add max stack of 26464 Mercurial Shield)
2158 case 29286:
2160 // Mercurial Shield
2161 SpellEntry const* spell = sSpellStore.LookupEntry(26464);
2162 if (!spell)
2163 return;
2165 for (int j=0; j < spell->StackAmount; ++j)
2166 m_caster->CastSpell(unitTarget, spell->Id, true, m_CastItem, NULL, m_originalCasterGUID);
2167 return;
2169 // Righteous Defense
2170 case 31980:
2172 m_caster->CastSpell(unitTarget, 31790, true, m_CastItem, NULL, m_originalCasterGUID);
2173 return;
2175 // Cloak of Shadows
2176 case 35729:
2178 Unit::AuraMap& Auras = unitTarget->GetAuras();
2179 for(Unit::AuraMap::iterator iter = Auras.begin(); iter != Auras.end(); ++iter)
2181 // remove all harmful spells on you...
2182 if( // ignore positive and passive auras
2183 !iter->second->IsPositive() && !iter->second->IsPassive() &&
2184 // ignore physical auras
2185 (GetSpellSchoolMask(iter->second->GetSpellProto()) & SPELL_SCHOOL_MASK_NORMAL)==0 )
2187 m_caster->RemoveAurasDueToSpell(iter->second->GetSpellProto()->Id);
2188 iter = Auras.begin();
2191 return;
2193 // Priest Shadowfiend (34433) need apply mana gain trigger aura on pet
2194 case 41967:
2196 if (Unit *pet = unitTarget->GetPet())
2197 pet->CastSpell(pet, 28305, true);
2198 return;
2202 // normal case
2203 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2204 if (!spellInfo)
2206 sLog.outError("EffectTriggerSpell of spell %u: triggering unknown spell id %i", m_spellInfo->Id,triggered_spell_id);
2207 return;
2210 // select formal caster for triggered spell
2211 Unit* caster = m_caster;
2213 // some triggered spells require specific equipment
2214 if (spellInfo->EquippedItemClass >=0 && m_caster->GetTypeId()==TYPEID_PLAYER)
2216 // main hand weapon required
2217 if (spellInfo->AttributesEx3 & SPELL_ATTR_EX3_MAIN_HAND)
2219 Item* item = ((Player*)m_caster)->GetWeaponForAttack(BASE_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 // offhand hand weapon required
2231 if (spellInfo->AttributesEx3 & SPELL_ATTR_EX3_REQ_OFFHAND)
2233 Item* item = ((Player*)m_caster)->GetWeaponForAttack(OFF_ATTACK, true, false);
2235 // skip spell if no weapon in slot or broken
2236 if (!item)
2237 return;
2239 // skip spell if weapon not fit to triggered spell
2240 if (!item->IsFitToSpellRequirements(spellInfo))
2241 return;
2244 else
2246 // Note: not exist spells with weapon req. and IsSpellHaveCasterSourceTargets == true
2247 // so this just for speedup places in else
2248 caster = IsSpellWithCasterSourceTargetsOnly(spellInfo) ? unitTarget : m_caster;
2251 caster->CastSpell(unitTarget,spellInfo,true,NULL,NULL,m_originalCasterGUID);
2254 void Spell::EffectTriggerMissileSpell(uint32 effect_idx)
2256 uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[effect_idx];
2258 // normal case
2259 SpellEntry const *spellInfo = sSpellStore.LookupEntry( triggered_spell_id );
2261 if(!spellInfo)
2263 sLog.outError("EffectTriggerMissileSpell of spell %u (eff: %u): triggering unknown spell id %u",
2264 m_spellInfo->Id,effect_idx,triggered_spell_id);
2265 return;
2268 if (m_CastItem)
2269 DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id);
2271 m_caster->CastSpell(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, spellInfo, true, m_CastItem, 0, m_originalCasterGUID);
2274 void Spell::EffectJump(uint32 i)
2276 if(m_caster->isInFlight())
2277 return;
2279 // Init dest coordinates
2280 float x,y,z,o;
2281 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
2283 x = m_targets.m_destX;
2284 y = m_targets.m_destY;
2285 z = m_targets.m_destZ;
2287 if(m_spellInfo->EffectImplicitTargetA[i] == TARGET_BEHIND_VICTIM)
2289 // explicit cast data from client or server-side cast
2290 // some spell at client send caster
2291 Unit* pTarget = NULL;
2292 if(m_targets.getUnitTarget() && m_targets.getUnitTarget()!=m_caster)
2293 pTarget = m_targets.getUnitTarget();
2294 else if(unitTarget->getVictim())
2295 pTarget = m_caster->getVictim();
2296 else if(m_caster->GetTypeId() == TYPEID_PLAYER)
2297 pTarget = ObjectAccessor::GetUnit(*m_caster, ((Player*)m_caster)->GetSelection());
2299 o = pTarget ? pTarget->GetOrientation() : m_caster->GetOrientation();
2301 else
2302 o = m_caster->GetOrientation();
2304 else if(unitTarget)
2306 unitTarget->GetContactPoint(m_caster,x,y,z,CONTACT_DISTANCE);
2307 o = m_caster->GetOrientation();
2309 else if(gameObjTarget)
2311 gameObjTarget->GetContactPoint(m_caster,x,y,z,CONTACT_DISTANCE);
2312 o = m_caster->GetOrientation();
2314 else
2316 sLog.outError( "Spell::EffectJump - unsupported target mode for spell ID %u", m_spellInfo->Id );
2317 return;
2320 m_caster->NearTeleportTo(x, y, z, o, true);
2323 void Spell::EffectTeleportUnits(uint32 i)
2325 if(!unitTarget || unitTarget->isInFlight())
2326 return;
2328 switch (m_spellInfo->EffectImplicitTargetB[i])
2330 case TARGET_INNKEEPER_COORDINATES:
2332 // Only players can teleport to innkeeper
2333 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
2334 return;
2336 ((Player*)unitTarget)->TeleportToHomebind(unitTarget==m_caster ? TELE_TO_SPELL : 0);
2337 return;
2339 case TARGET_AREAEFFECT_INSTANT: // in all cases first TARGET_TABLE_X_Y_Z_COORDINATES
2340 case TARGET_TABLE_X_Y_Z_COORDINATES:
2342 SpellTargetPosition const* st = sSpellMgr.GetSpellTargetPosition(m_spellInfo->Id);
2343 if(!st)
2345 sLog.outError( "Spell::EffectTeleportUnits - unknown Teleport coordinates for spell ID %u", m_spellInfo->Id );
2346 return;
2349 if(st->target_mapId==unitTarget->GetMapId())
2350 unitTarget->NearTeleportTo(st->target_X,st->target_Y,st->target_Z,st->target_Orientation,unitTarget==m_caster);
2351 else if(unitTarget->GetTypeId()==TYPEID_PLAYER)
2352 ((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);
2353 break;
2355 case TARGET_BEHIND_VICTIM:
2357 Unit *pTarget = NULL;
2359 // explicit cast data from client or server-side cast
2360 // some spell at client send caster
2361 if(m_targets.getUnitTarget() && m_targets.getUnitTarget()!=unitTarget)
2362 pTarget = m_targets.getUnitTarget();
2363 else if(unitTarget->getVictim())
2364 pTarget = unitTarget->getVictim();
2365 else if(unitTarget->GetTypeId() == TYPEID_PLAYER)
2366 pTarget = ObjectAccessor::GetUnit(*unitTarget, ((Player*)unitTarget)->GetSelection());
2368 // Init dest coordinates
2369 float x = m_targets.m_destX;
2370 float y = m_targets.m_destY;
2371 float z = m_targets.m_destZ;
2372 float orientation = pTarget ? pTarget->GetOrientation() : unitTarget->GetOrientation();
2373 unitTarget->NearTeleportTo(x,y,z,orientation,unitTarget==m_caster);
2374 return;
2376 default:
2378 // If not exist data for dest location - return
2379 if(!(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION))
2381 sLog.outError( "Spell::EffectTeleportUnits - unknown EffectImplicitTargetB[%u] = %u for spell ID %u", i, m_spellInfo->EffectImplicitTargetB[i], m_spellInfo->Id );
2382 return;
2384 // Init dest coordinates
2385 float x = m_targets.m_destX;
2386 float y = m_targets.m_destY;
2387 float z = m_targets.m_destZ;
2388 float orientation = unitTarget->GetOrientation();
2389 // Teleport
2390 unitTarget->NearTeleportTo(x,y,z,orientation,unitTarget==m_caster);
2391 return;
2395 // post effects for TARGET_TABLE_X_Y_Z_COORDINATES
2396 switch ( m_spellInfo->Id )
2398 // Dimensional Ripper - Everlook
2399 case 23442:
2401 int32 r = irand(0, 119);
2402 if ( r >= 70 ) // 7/12 success
2404 if ( r < 100 ) // 4/12 evil twin
2405 m_caster->CastSpell(m_caster, 23445, true);
2406 else // 1/12 fire
2407 m_caster->CastSpell(m_caster, 23449, true);
2409 return;
2411 // Ultrasafe Transporter: Toshley's Station
2412 case 36941:
2414 if ( roll_chance_i(50) ) // 50% success
2416 int32 rand_eff = urand(1, 7);
2417 switch ( rand_eff )
2419 case 1:
2420 // soul split - evil
2421 m_caster->CastSpell(m_caster, 36900, true);
2422 break;
2423 case 2:
2424 // soul split - good
2425 m_caster->CastSpell(m_caster, 36901, true);
2426 break;
2427 case 3:
2428 // Increase the size
2429 m_caster->CastSpell(m_caster, 36895, true);
2430 break;
2431 case 4:
2432 // Decrease the size
2433 m_caster->CastSpell(m_caster, 36893, true);
2434 break;
2435 case 5:
2436 // Transform
2438 if (((Player*)m_caster)->GetTeam() == ALLIANCE )
2439 m_caster->CastSpell(m_caster, 36897, true);
2440 else
2441 m_caster->CastSpell(m_caster, 36899, true);
2442 break;
2444 case 6:
2445 // chicken
2446 m_caster->CastSpell(m_caster, 36940, true);
2447 break;
2448 case 7:
2449 // evil twin
2450 m_caster->CastSpell(m_caster, 23445, true);
2451 break;
2454 return;
2456 // Dimensional Ripper - Area 52
2457 case 36890:
2459 if ( roll_chance_i(50) ) // 50% success
2461 int32 rand_eff = urand(1, 4);
2462 switch ( rand_eff )
2464 case 1:
2465 // soul split - evil
2466 m_caster->CastSpell(m_caster, 36900, true);
2467 break;
2468 case 2:
2469 // soul split - good
2470 m_caster->CastSpell(m_caster, 36901, true);
2471 break;
2472 case 3:
2473 // Increase the size
2474 m_caster->CastSpell(m_caster, 36895, true);
2475 break;
2476 case 4:
2477 // Transform
2479 if (((Player*)m_caster)->GetTeam() == ALLIANCE )
2480 m_caster->CastSpell(m_caster, 36897, true);
2481 else
2482 m_caster->CastSpell(m_caster, 36899, true);
2483 break;
2487 return;
2492 void Spell::EffectApplyAura(uint32 i)
2494 if(!unitTarget)
2495 return;
2497 // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load)
2498 if ( (!unitTarget->isAlive() && !(IsDeathOnlySpell(m_spellInfo) || IsDeathPersistentSpell(m_spellInfo))) &&
2499 (unitTarget->GetTypeId() != TYPEID_PLAYER || !((Player*)unitTarget)->GetSession()->PlayerLoading()) )
2500 return;
2502 Unit* caster = m_originalCaster ? m_originalCaster : m_caster;
2503 if(!caster)
2504 return;
2506 sLog.outDebug("Spell: Aura is: %u", m_spellInfo->EffectApplyAuraName[i]);
2508 Aura* Aur = CreateAura(m_spellInfo, i, &m_currentBasePoints[i], unitTarget, caster, m_CastItem);
2510 // Now Reduce spell duration using data received at spell hit
2511 int32 duration = Aur->GetAuraMaxDuration();
2512 int32 limitduration = GetDiminishingReturnsLimitDuration(m_diminishGroup,m_spellInfo);
2513 unitTarget->ApplyDiminishingToDuration(m_diminishGroup, duration, m_caster, m_diminishLevel,limitduration);
2514 Aur->setDiminishGroup(m_diminishGroup);
2516 // if Aura removed and deleted, do not continue.
2517 if(duration== 0 && !(Aur->IsPermanent()))
2519 delete Aur;
2520 return;
2523 if(duration != Aur->GetAuraMaxDuration())
2525 Aur->SetAuraMaxDuration(duration);
2526 Aur->SetAuraDuration(duration);
2529 unitTarget->AddAura(Aur);
2532 void Spell::EffectUnlearnSpecialization( uint32 i )
2534 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
2535 return;
2537 Player *_player = (Player*)unitTarget;
2538 uint32 spellToUnlearn = m_spellInfo->EffectTriggerSpell[i];
2540 _player->removeSpell(spellToUnlearn);
2542 sLog.outDebug( "Spell: Player %u has unlearned spell %u from NpcGUID: %u", _player->GetGUIDLow(), spellToUnlearn, m_caster->GetGUIDLow() );
2545 void Spell::EffectPowerDrain(uint32 i)
2547 if(m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2548 return;
2550 Powers drain_power = Powers(m_spellInfo->EffectMiscValue[i]);
2552 if(!unitTarget)
2553 return;
2554 if(!unitTarget->isAlive())
2555 return;
2556 if(unitTarget->getPowerType() != drain_power)
2557 return;
2558 if(damage < 0)
2559 return;
2561 uint32 curPower = unitTarget->GetPower(drain_power);
2563 //add spell damage bonus
2564 damage=m_caster->SpellDamageBonus(unitTarget,m_spellInfo,uint32(damage),SPELL_DIRECT_DAMAGE);
2566 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
2567 uint32 power = damage;
2568 if (drain_power == POWER_MANA)
2569 power -= unitTarget->GetSpellCritDamageReduction(power);
2571 int32 new_damage;
2572 if(curPower < power)
2573 new_damage = curPower;
2574 else
2575 new_damage = power;
2577 unitTarget->ModifyPower(drain_power,-new_damage);
2579 // Don`t restore from self drain
2580 if(drain_power == POWER_MANA && m_caster != unitTarget)
2582 float manaMultiplier = m_spellInfo->EffectMultipleValue[i];
2583 if(manaMultiplier==0)
2584 manaMultiplier = 1;
2586 if(Player *modOwner = m_caster->GetSpellModOwner())
2587 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, manaMultiplier);
2589 int32 gain = int32(new_damage * manaMultiplier);
2591 m_caster->EnergizeBySpell(m_caster, m_spellInfo->Id, gain, POWER_MANA);
2595 void Spell::EffectSendEvent(uint32 EffectIndex)
2598 we do not handle a flag dropping or clicking on flag in battleground by sendevent system
2600 sLog.outDebug("Spell ScriptStart %u for spellid %u in EffectSendEvent ", m_spellInfo->EffectMiscValue[EffectIndex], m_spellInfo->Id);
2601 m_caster->GetMap()->ScriptsStart(sEventScripts, m_spellInfo->EffectMiscValue[EffectIndex], m_caster, focusObject);
2604 void Spell::EffectPowerBurn(uint32 i)
2606 if (m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2607 return;
2609 Powers powertype = Powers(m_spellInfo->EffectMiscValue[i]);
2611 if (!unitTarget)
2612 return;
2613 if (!unitTarget->isAlive())
2614 return;
2615 if (unitTarget->getPowerType()!=powertype)
2616 return;
2617 if (damage < 0)
2618 return;
2620 // burn x% of target's mana, up to maximum of 2x% of caster's mana (Mana Burn)
2621 if (m_spellInfo->ManaCostPercentage)
2623 uint32 maxdamage = m_caster->GetMaxPower(powertype) * damage * 2 / 100;
2624 damage = unitTarget->GetMaxPower(powertype) * damage / 100;
2625 if(damage > maxdamage) damage = maxdamage;
2628 int32 curPower = int32(unitTarget->GetPower(powertype));
2630 // resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
2631 uint32 power = damage;
2632 if (powertype == POWER_MANA)
2633 power -= unitTarget->GetSpellCritDamageReduction(power);
2635 int32 new_damage = (curPower < power) ? curPower : power;
2637 unitTarget->ModifyPower(powertype, -new_damage);
2638 float multiplier = m_spellInfo->EffectMultipleValue[i];
2640 if (Player *modOwner = m_caster->GetSpellModOwner())
2641 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
2643 new_damage = int32(new_damage * multiplier);
2644 m_damage += new_damage;
2647 void Spell::EffectHeal( uint32 /*i*/ )
2649 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2651 // Try to get original caster
2652 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2654 // Skip if m_originalCaster not available
2655 if (!caster)
2656 return;
2658 int32 addhealth = damage;
2660 // Vessel of the Naaru (Vial of the Sunwell trinket)
2661 if (m_spellInfo->Id == 45064)
2663 // Amount of heal - depends from stacked Holy Energy
2664 int damageAmount = 0;
2665 Unit::AuraList const& mDummyAuras = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
2666 for(Unit::AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i)
2667 if ((*i)->GetId() == 45062)
2668 damageAmount+=(*i)->GetModifier()->m_amount;
2669 if (damageAmount)
2670 m_caster->RemoveAurasDueToSpell(45062);
2672 addhealth += damageAmount;
2674 // Death Pact (percent heal)
2675 else if (m_spellInfo->Id==48743)
2676 addhealth = addhealth * unitTarget->GetMaxHealth() / 100;
2677 // Swiftmend - consumes Regrowth or Rejuvenation
2678 else if (m_spellInfo->TargetAuraState == AURA_STATE_SWIFTMEND && unitTarget->HasAuraState(AURA_STATE_SWIFTMEND))
2680 Unit::AuraList const& RejorRegr = unitTarget->GetAurasByType(SPELL_AURA_PERIODIC_HEAL);
2681 // find most short by duration
2682 Aura *targetAura = NULL;
2683 for(Unit::AuraList::const_iterator i = RejorRegr.begin(); i != RejorRegr.end(); ++i)
2685 if ((*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_DRUID &&
2686 // Regrowth or Rejuvenation 0x40 | 0x10
2687 ((*i)->GetSpellProto()->SpellFamilyFlags & UI64LIT(0x0000000000000050)))
2689 if (!targetAura || (*i)->GetAuraDuration() < targetAura->GetAuraDuration())
2690 targetAura = *i;
2694 if (!targetAura)
2696 sLog.outError("Target (GUID: %u TypeId: %u) has aurastate AURA_STATE_SWIFTMEND but no matching aura.", unitTarget->GetGUIDLow(), unitTarget->GetTypeId());
2697 return;
2699 int idx = 0;
2700 while(idx < 3)
2702 if(targetAura->GetSpellProto()->EffectApplyAuraName[idx] == SPELL_AURA_PERIODIC_HEAL)
2703 break;
2704 idx++;
2707 int32 tickheal = caster->SpellHealingBonus(unitTarget, targetAura->GetSpellProto(), targetAura->GetModifier()->m_amount, DOT);
2708 int32 tickcount = GetSpellDuration(targetAura->GetSpellProto()) / targetAura->GetSpellProto()->EffectAmplitude[idx];
2710 // Glyph of Swiftmend
2711 if (!caster->HasAura(54824))
2712 unitTarget->RemoveAurasDueToSpell(targetAura->GetId());
2714 addhealth += tickheal * tickcount;
2716 else
2717 addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, addhealth, HEAL);
2719 m_healing+=addhealth;
2723 void Spell::EffectHealPct( uint32 /*i*/ )
2725 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2727 // Try to get original caster
2728 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2730 // Skip if m_originalCaster not available
2731 if (!caster)
2732 return;
2734 uint32 addhealth = unitTarget->GetMaxHealth() * damage / 100;
2735 if (Player* modOwner = m_caster->GetSpellModOwner())
2736 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DAMAGE, addhealth, this);
2738 int32 gain = caster->DealHeal(unitTarget, addhealth, m_spellInfo);
2739 unitTarget->getHostileRefManager().threatAssist(m_caster, float(gain) * 0.5f, m_spellInfo);
2743 void Spell::EffectHealMechanical( uint32 /*i*/ )
2745 // Mechanic creature type should be correctly checked by targetCreatureType field
2746 if (unitTarget && unitTarget->isAlive() && damage >= 0)
2748 // Try to get original caster
2749 Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster;
2751 // Skip if m_originalCaster not available
2752 if (!caster)
2753 return;
2755 uint32 addhealth = caster->SpellHealingBonus(unitTarget, m_spellInfo, uint32(damage), HEAL);
2756 caster->DealHeal(unitTarget, addhealth, m_spellInfo);
2760 void Spell::EffectHealthLeech(uint32 i)
2762 if (!unitTarget)
2763 return;
2764 if (!unitTarget->isAlive())
2765 return;
2767 if (damage < 0)
2768 return;
2770 sLog.outDebug("HealthLeech :%i", damage);
2772 uint32 curHealth = unitTarget->GetHealth();
2773 damage = m_caster->SpellNonMeleeDamageLog(unitTarget, m_spellInfo->Id, damage );
2774 if (curHealth < damage)
2775 damage = curHealth;
2777 float multiplier = m_spellInfo->EffectMultipleValue[i];
2779 if (Player *modOwner = m_caster->GetSpellModOwner())
2780 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_MULTIPLE_VALUE, multiplier);
2782 uint32 heal = uint32(damage*multiplier);
2783 if (m_caster->isAlive())
2785 heal = m_caster->SpellHealingBonus(m_caster, m_spellInfo, heal, HEAL);
2786 m_caster->DealHeal(m_caster, heal, m_spellInfo);
2790 void Spell::DoCreateItem(uint32 i, uint32 itemtype)
2792 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
2793 return;
2795 Player* player = (Player*)unitTarget;
2797 uint32 newitemid = itemtype;
2798 ItemPrototype const *pProto = ObjectMgr::GetItemPrototype( newitemid );
2799 if(!pProto)
2801 player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
2802 return;
2805 // bg reward have some special in code work
2806 uint32 bgType = 0;
2807 switch(m_spellInfo->Id)
2809 case SPELL_AV_MARK_WINNER:
2810 case SPELL_AV_MARK_LOSER:
2811 bgType = BATTLEGROUND_AV;
2812 break;
2813 case SPELL_WS_MARK_WINNER:
2814 case SPELL_WS_MARK_LOSER:
2815 bgType = BATTLEGROUND_WS;
2816 break;
2817 case SPELL_AB_MARK_WINNER:
2818 case SPELL_AB_MARK_LOSER:
2819 bgType = BATTLEGROUND_AB;
2820 break;
2821 default:
2822 break;
2825 uint32 num_to_add;
2827 // TODO: maybe all this can be replaced by using correct calculated `damage` value
2828 if(pProto->Class != ITEM_CLASS_CONSUMABLE || m_spellInfo->SpellFamilyName != SPELLFAMILY_MAGE)
2830 int32 basePoints = m_currentBasePoints[i];
2831 int32 randomPoints = m_spellInfo->EffectDieSides[i];
2832 if (randomPoints)
2833 num_to_add = basePoints + irand(1, randomPoints);
2834 else
2835 num_to_add = basePoints + 1;
2837 else if (pProto->MaxCount == 1)
2838 num_to_add = 1;
2839 else if(player->getLevel() >= m_spellInfo->spellLevel)
2841 int32 basePoints = m_currentBasePoints[i];
2842 float pointPerLevel = m_spellInfo->EffectRealPointsPerLevel[i];
2843 num_to_add = basePoints + 1 + uint32((player->getLevel() - m_spellInfo->spellLevel)*pointPerLevel);
2845 else
2846 num_to_add = 2;
2848 if (num_to_add < 1)
2849 num_to_add = 1;
2850 if (num_to_add > pProto->GetMaxStackSize())
2851 num_to_add = pProto->GetMaxStackSize();
2853 // init items_count to 1, since 1 item will be created regardless of specialization
2854 int items_count=1;
2855 // the chance to create additional items
2856 float additionalCreateChance=0.0f;
2857 // the maximum number of created additional items
2858 uint8 additionalMaxNum=0;
2859 // get the chance and maximum number for creating extra items
2860 if ( canCreateExtraItems(player, m_spellInfo->Id, additionalCreateChance, additionalMaxNum) )
2862 // roll with this chance till we roll not to create or we create the max num
2863 while ( roll_chance_f(additionalCreateChance) && items_count<=additionalMaxNum )
2864 ++items_count;
2867 // really will be created more items
2868 num_to_add *= items_count;
2870 // can the player store the new item?
2871 ItemPosCountVec dest;
2872 uint32 no_space = 0;
2873 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, newitemid, num_to_add, &no_space );
2874 if( msg != EQUIP_ERR_OK )
2876 // convert to possible store amount
2877 if( msg == EQUIP_ERR_INVENTORY_FULL || msg == EQUIP_ERR_CANT_CARRY_MORE_OF_THIS )
2878 num_to_add -= no_space;
2879 else
2881 // if not created by another reason from full inventory or unique items amount limitation
2882 player->SendEquipError( msg, NULL, NULL );
2883 return;
2887 if(num_to_add)
2889 // create the new item and store it
2890 Item* pItem = player->StoreNewItem( dest, newitemid, true, Item::GenerateItemRandomPropertyId(newitemid));
2892 // was it successful? return error if not
2893 if(!pItem)
2895 player->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
2896 return;
2899 // set the "Crafted by ..." property of the item
2900 if( pItem->GetProto()->Class != ITEM_CLASS_CONSUMABLE && pItem->GetProto()->Class != ITEM_CLASS_QUEST)
2901 pItem->SetUInt32Value(ITEM_FIELD_CREATOR, player->GetGUIDLow());
2903 // send info to the client
2904 if(pItem)
2905 player->SendNewItem(pItem, num_to_add, true, bgType == 0);
2907 // we succeeded in creating at least one item, so a levelup is possible
2908 if(bgType == 0)
2909 player->UpdateCraftSkill(m_spellInfo->Id);
2912 // for battleground marks send by mail if not add all expected
2913 if(no_space > 0 && bgType)
2915 if(BattleGround* bg = sBattleGroundMgr.GetBattleGroundTemplate(BattleGroundTypeId(bgType)))
2916 bg->SendRewardMarkByMail(player, newitemid, no_space);
2920 void Spell::EffectCreateItem(uint32 i)
2922 DoCreateItem(i,m_spellInfo->EffectItemType[i]);
2925 void Spell::EffectCreateItem2(uint32 i)
2927 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
2928 return;
2929 Player* player = (Player*)m_caster;
2931 uint32 item_id = m_spellInfo->EffectItemType[i];
2933 DoCreateItem(i, item_id);
2935 // special case: fake item replaced by generate using spell_loot_template
2936 if (IsLootCraftingSpell(m_spellInfo))
2938 if (!player->HasItemCount(item_id, 1))
2939 return;
2941 // remove reagent
2942 uint32 count = 1;
2943 player->DestroyItemCount(item_id, count, true);
2945 // create some random items
2946 player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
2950 void Spell::EffectCreateRandomItem(uint32 i)
2952 if (m_caster->GetTypeId()!=TYPEID_PLAYER)
2953 return;
2954 Player* player = (Player*)m_caster;
2956 // create some random items
2957 player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
2960 void Spell::EffectPersistentAA(uint32 i)
2962 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
2964 if (Player* modOwner = m_caster->GetSpellModOwner())
2965 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RADIUS, radius);
2967 int32 duration = GetSpellDuration(m_spellInfo);
2968 DynamicObject* dynObj = new DynamicObject;
2969 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))
2971 delete dynObj;
2972 return;
2974 dynObj->SetUInt32Value(OBJECT_FIELD_TYPE, 65);
2975 dynObj->SetUInt32Value(GAMEOBJECT_DISPLAYID, 368003);
2976 dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x01eeeeee);
2977 m_caster->AddDynObject(dynObj);
2978 m_caster->GetMap()->Add(dynObj);
2981 void Spell::EffectEnergize(uint32 i)
2983 if(!unitTarget)
2984 return;
2985 if(!unitTarget->isAlive())
2986 return;
2988 if(m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
2989 return;
2991 Powers power = Powers(m_spellInfo->EffectMiscValue[i]);
2993 // Some level depends spells
2994 int level_multiplier = 0;
2995 int level_diff = 0;
2996 switch (m_spellInfo->Id)
2998 case 9512: // Restore Energy
2999 level_diff = m_caster->getLevel() - 40;
3000 level_multiplier = 2;
3001 break;
3002 case 24571: // Blood Fury
3003 level_diff = m_caster->getLevel() - 60;
3004 level_multiplier = 10;
3005 break;
3006 case 24532: // Burst of Energy
3007 level_diff = m_caster->getLevel() - 60;
3008 level_multiplier = 4;
3009 break;
3010 case 31930: // Judgements of the Wise
3011 case 63375: // Improved Stormstrike
3012 damage = damage * unitTarget->GetCreateMana() / 100;
3013 break;
3014 default:
3015 break;
3018 if (level_diff > 0)
3019 damage -= level_multiplier * level_diff;
3021 if(damage < 0)
3022 return;
3024 if(unitTarget->GetMaxPower(power) == 0)
3025 return;
3027 m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, damage, power);
3029 // Mad Alchemist's Potion
3030 if (m_spellInfo->Id == 45051)
3032 // find elixirs on target
3033 uint32 elixir_mask = 0;
3034 Unit::AuraMap& Auras = unitTarget->GetAuras();
3035 for(Unit::AuraMap::iterator itr = Auras.begin(); itr != Auras.end(); ++itr)
3037 uint32 spell_id = itr->second->GetId();
3038 if(uint32 mask = sSpellMgr.GetSpellElixirMask(spell_id))
3039 elixir_mask |= mask;
3042 // get available elixir mask any not active type from battle/guardian (and flask if no any)
3043 elixir_mask = (elixir_mask & ELIXIR_FLASK_MASK) ^ ELIXIR_FLASK_MASK;
3045 // get all available elixirs by mask and spell level
3046 std::vector<uint32> elixirs;
3047 SpellElixirMap const& m_spellElixirs = sSpellMgr.GetSpellElixirMap();
3048 for(SpellElixirMap::const_iterator itr = m_spellElixirs.begin(); itr != m_spellElixirs.end(); ++itr)
3050 if (itr->second & elixir_mask)
3052 if (itr->second & (ELIXIR_UNSTABLE_MASK | ELIXIR_SHATTRATH_MASK))
3053 continue;
3055 SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first);
3056 if (spellInfo && (spellInfo->spellLevel < m_spellInfo->spellLevel || spellInfo->spellLevel > unitTarget->getLevel()))
3057 continue;
3059 elixirs.push_back(itr->first);
3063 if (!elixirs.empty())
3065 // cast random elixir on target
3066 uint32 rand_spell = urand(0,elixirs.size()-1);
3067 m_caster->CastSpell(unitTarget,elixirs[rand_spell],true,m_CastItem);
3072 void Spell::EffectEnergisePct(uint32 i)
3074 if (!unitTarget)
3075 return;
3076 if (!unitTarget->isAlive())
3077 return;
3079 if (m_spellInfo->EffectMiscValue[i] < 0 || m_spellInfo->EffectMiscValue[i] >= MAX_POWERS)
3080 return;
3082 Powers power = Powers(m_spellInfo->EffectMiscValue[i]);
3084 uint32 maxPower = unitTarget->GetMaxPower(power);
3085 if (maxPower == 0)
3086 return;
3088 uint32 gain = damage * maxPower / 100;
3089 m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, gain, power);
3092 void Spell::SendLoot(uint64 guid, LootType loottype)
3094 Player* player = (Player*)m_caster;
3095 if (!player)
3096 return;
3098 if (gameObjTarget)
3100 if (Script->GOHello(player, gameObjTarget))
3101 return;
3103 switch (gameObjTarget->GetGoType())
3105 case GAMEOBJECT_TYPE_DOOR:
3106 case GAMEOBJECT_TYPE_BUTTON:
3107 gameObjTarget->UseDoorOrButton();
3108 player->GetMap()->ScriptsStart(sGameObjectScripts, gameObjTarget->GetDBTableGUIDLow(), player, gameObjTarget);
3109 return;
3111 case GAMEOBJECT_TYPE_QUESTGIVER:
3112 // start or end quest
3113 player->PrepareQuestMenu(guid);
3114 player->SendPreparedQuest(guid);
3115 return;
3117 case GAMEOBJECT_TYPE_SPELL_FOCUS:
3118 // triggering linked GO
3119 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->spellFocus.linkedTrapId)
3120 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3121 return;
3123 case GAMEOBJECT_TYPE_GOOBER:
3124 // goober_scripts can be triggered if the player don't have the quest
3125 if (gameObjTarget->GetGOInfo()->goober.eventId)
3127 sLog.outDebug("Goober ScriptStart id %u for GO %u", gameObjTarget->GetGOInfo()->goober.eventId,gameObjTarget->GetDBTableGUIDLow());
3128 player->GetMap()->ScriptsStart(sEventScripts, gameObjTarget->GetGOInfo()->goober.eventId, player, gameObjTarget);
3131 // cast goober spell
3132 if (gameObjTarget->GetGOInfo()->goober.questId)
3133 ///Quest require to be active for GO using
3134 if (player->GetQuestStatus(gameObjTarget->GetGOInfo()->goober.questId) != QUEST_STATUS_INCOMPLETE)
3135 return;
3137 gameObjTarget->AddUniqueUse(player);
3138 gameObjTarget->SetLootState(GO_JUST_DEACTIVATED);
3140 //TODO? Objective counting called without spell check but with quest objective check
3141 // if send spell id then this line will duplicate to spell casting call (double counting)
3142 // So we or have this line and not required in quest_template have reqSpellIdN
3143 // or must remove this line and required in DB have data in quest_template have reqSpellIdN for all quest using cases.
3144 player->CastedCreatureOrGO(gameObjTarget->GetEntry(), gameObjTarget->GetGUID(), 0);
3146 // triggering linked GO
3147 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->goober.linkedTrapId)
3148 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3150 return;
3152 case GAMEOBJECT_TYPE_CHEST:
3153 // TODO: possible must be moved to loot release (in different from linked triggering)
3154 if (gameObjTarget->GetGOInfo()->chest.eventId)
3156 sLog.outDebug("Chest ScriptStart id %u for GO %u", gameObjTarget->GetGOInfo()->chest.eventId,gameObjTarget->GetDBTableGUIDLow());
3157 player->GetMap()->ScriptsStart(sEventScripts, gameObjTarget->GetGOInfo()->chest.eventId, player, gameObjTarget);
3160 // triggering linked GO
3161 if (uint32 trapEntry = gameObjTarget->GetGOInfo()->chest.linkedTrapId)
3162 gameObjTarget->TriggeringLinkedGameObject(trapEntry,m_caster);
3164 // Don't return, let loots been taken
3165 default:
3166 break;
3170 // Send loot
3171 player->SendLoot(guid, loottype);
3174 void Spell::EffectOpenLock(uint32 effIndex)
3176 if (!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER)
3178 sLog.outDebug( "WORLD: Open Lock - No Player Caster!");
3179 return;
3182 Player* player = (Player*)m_caster;
3184 uint32 lockId = 0;
3185 uint64 guid = 0;
3187 // Get lockId
3188 if (gameObjTarget)
3190 GameObjectInfo const* goInfo = gameObjTarget->GetGOInfo();
3191 // Arathi Basin banner opening !
3192 if (goInfo->type == GAMEOBJECT_TYPE_BUTTON && goInfo->button.noDamageImmune ||
3193 goInfo->type == GAMEOBJECT_TYPE_GOOBER && goInfo->goober.losOK)
3195 //CanUseBattleGroundObject() already called in CheckCast()
3196 // in battleground check
3197 if (BattleGround *bg = player->GetBattleGround())
3199 // check if it's correct bg
3200 if (bg->GetTypeID() == BATTLEGROUND_AB || bg->GetTypeID() == BATTLEGROUND_AV)
3201 bg->EventPlayerClickedOnFlag(player, gameObjTarget);
3202 return;
3205 else if (goInfo->type == GAMEOBJECT_TYPE_FLAGSTAND)
3207 //CanUseBattleGroundObject() already called in CheckCast()
3208 // in battleground check
3209 if (BattleGround *bg = player->GetBattleGround())
3211 if (bg->GetTypeID() == BATTLEGROUND_EY)
3212 bg->EventPlayerClickedOnFlag(player, gameObjTarget);
3213 return;
3216 lockId = goInfo->GetLockId();
3217 guid = gameObjTarget->GetGUID();
3219 else if (itemTarget)
3221 lockId = itemTarget->GetProto()->LockID;
3222 guid = itemTarget->GetGUID();
3224 else
3226 sLog.outDebug( "WORLD: Open Lock - No GameObject/Item Target!");
3227 return;
3230 SkillType skillId = SKILL_NONE;
3231 int32 reqSkillValue = 0;
3232 int32 skillValue;
3234 SpellCastResult res = CanOpenLock(effIndex, lockId, skillId, reqSkillValue, skillValue);
3235 if (res != SPELL_CAST_OK)
3237 SendCastResult(res);
3238 return;
3241 SendLoot(guid, LOOT_SKINNING);
3243 // not allow use skill grow at item base open
3244 if (!m_CastItem && skillId != SKILL_NONE)
3246 // update skill if really known
3247 if (uint32 pureSkillValue = player->GetPureSkillValue(skillId))
3249 if (gameObjTarget)
3251 // Allow one skill-up until respawned
3252 if (!gameObjTarget->IsInSkillupList(player->GetGUIDLow()) &&
3253 player->UpdateGatherSkill(skillId, pureSkillValue, reqSkillValue))
3254 gameObjTarget->AddToSkillupList(player->GetGUIDLow());
3256 else if (itemTarget)
3258 // Do one skill-up
3259 player->UpdateGatherSkill(skillId, pureSkillValue, reqSkillValue);
3265 void Spell::EffectSummonChangeItem(uint32 i)
3267 if (m_caster->GetTypeId() != TYPEID_PLAYER)
3268 return;
3270 Player *player = (Player*)m_caster;
3272 // applied only to using item
3273 if (!m_CastItem)
3274 return;
3276 // ... only to item in own inventory/bank/equip_slot
3277 if (m_CastItem->GetOwnerGUID()!=player->GetGUID())
3278 return;
3280 uint32 newitemid = m_spellInfo->EffectItemType[i];
3281 if (!newitemid)
3282 return;
3284 uint16 pos = m_CastItem->GetPos();
3286 Item *pNewItem = Item::CreateItem( newitemid, 1, player);
3287 if (!pNewItem)
3288 return;
3290 for(uint8 j= PERM_ENCHANTMENT_SLOT; j<=TEMP_ENCHANTMENT_SLOT; ++j)
3292 if (m_CastItem->GetEnchantmentId(EnchantmentSlot(j)))
3293 pNewItem->SetEnchantment(EnchantmentSlot(j), m_CastItem->GetEnchantmentId(EnchantmentSlot(j)), m_CastItem->GetEnchantmentDuration(EnchantmentSlot(j)), m_CastItem->GetEnchantmentCharges(EnchantmentSlot(j)));
3296 if (m_CastItem->GetUInt32Value(ITEM_FIELD_DURABILITY) < m_CastItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY))
3298 double loosePercent = 1 - m_CastItem->GetUInt32Value(ITEM_FIELD_DURABILITY) / double(m_CastItem->GetUInt32Value(ITEM_FIELD_MAXDURABILITY));
3299 player->DurabilityLoss(pNewItem, loosePercent);
3302 if (player->IsInventoryPos(pos))
3304 ItemPosCountVec dest;
3305 uint8 msg = player->CanStoreItem( m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), dest, pNewItem, true );
3306 if (msg == EQUIP_ERR_OK)
3308 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3310 // prevent crash at access and unexpected charges counting with item update queue corrupt
3311 if (m_CastItem==m_targets.getItemTarget())
3312 m_targets.setItemTarget(NULL);
3314 m_CastItem = NULL;
3316 player->StoreItem( dest, pNewItem, true);
3317 return;
3320 else if (player->IsBankPos (pos))
3322 ItemPosCountVec dest;
3323 uint8 msg = player->CanBankItem( m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), dest, pNewItem, true );
3324 if (msg == EQUIP_ERR_OK)
3326 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3328 // prevent crash at access and unexpected charges counting with item update queue corrupt
3329 if (m_CastItem==m_targets.getItemTarget())
3330 m_targets.setItemTarget(NULL);
3332 m_CastItem = NULL;
3334 player->BankItem( dest, pNewItem, true);
3335 return;
3338 else if (player->IsEquipmentPos (pos))
3340 uint16 dest;
3341 uint8 msg = player->CanEquipItem( m_CastItem->GetSlot(), dest, pNewItem, true );
3342 if (msg == EQUIP_ERR_OK)
3344 player->DestroyItem(m_CastItem->GetBagSlot(), m_CastItem->GetSlot(), true);
3346 // prevent crash at access and unexpected charges counting with item update queue corrupt
3347 if (m_CastItem==m_targets.getItemTarget())
3348 m_targets.setItemTarget(NULL);
3350 m_CastItem = NULL;
3352 player->EquipItem( dest, pNewItem, true);
3353 player->AutoUnequipOffhandIfNeed();
3354 return;
3358 // fail
3359 delete pNewItem;
3362 void Spell::EffectProficiency(uint32 /*i*/)
3364 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
3365 return;
3366 Player *p_target = (Player*)unitTarget;
3368 uint32 subClassMask = m_spellInfo->EquippedItemSubClassMask;
3369 if (m_spellInfo->EquippedItemClass == ITEM_CLASS_WEAPON && !(p_target->GetWeaponProficiency() & subClassMask))
3371 p_target->AddWeaponProficiency(subClassMask);
3372 p_target->SendProficiency(ITEM_CLASS_WEAPON, p_target->GetWeaponProficiency());
3374 if (m_spellInfo->EquippedItemClass == ITEM_CLASS_ARMOR && !(p_target->GetArmorProficiency() & subClassMask))
3376 p_target->AddArmorProficiency(subClassMask);
3377 p_target->SendProficiency(ITEM_CLASS_ARMOR, p_target->GetArmorProficiency());
3381 void Spell::EffectApplyAreaAura(uint32 i)
3383 if (!unitTarget)
3384 return;
3385 if (!unitTarget->isAlive())
3386 return;
3388 AreaAura* Aur = new AreaAura(m_spellInfo, i, &m_currentBasePoints[i], unitTarget, m_caster, m_CastItem);
3389 unitTarget->AddAura(Aur);
3392 void Spell::EffectSummonType(uint32 i)
3394 uint32 prop_id = m_spellInfo->EffectMiscValueB[i];
3395 SummonPropertiesEntry const *summon_prop = sSummonPropertiesStore.LookupEntry(prop_id);
3396 if(!summon_prop)
3398 sLog.outError("EffectSummonType: Unhandled summon type %u", prop_id);
3399 return;
3402 switch(summon_prop->Group)
3404 // faction handled later on, or loaded from template
3405 case SUMMON_PROP_GROUP_WILD:
3406 case SUMMON_PROP_GROUP_FRIENDLY:
3408 switch(summon_prop->Type)
3410 case SUMMON_PROP_TYPE_OTHER:
3412 // those are classical totems - effectbasepoints is their hp and not summon ammount!
3413 //SUMMON_TYPE_TOTEM = 121: 23035, battlestands
3414 //SUMMON_TYPE_TOTEM2 = 647: 52893, Anti-Magic Zone (npc used)
3415 if(prop_id == 121 || prop_id == 647)
3416 EffectSummonTotem(i);
3417 else
3418 EffectSummonWild(i, summon_prop->FactionId);
3419 break;
3421 case SUMMON_PROP_TYPE_SUMMON:
3422 case SUMMON_PROP_TYPE_GUARDIAN:
3423 case SUMMON_PROP_TYPE_ARMY:
3424 case SUMMON_PROP_TYPE_DK:
3425 case SUMMON_PROP_TYPE_CONSTRUCT:
3427 // JC golems - 32804, etc -- fits much better totem AI
3428 if(m_spellInfo->SpellIconID == 2056)
3429 EffectSummonTotem(i);
3430 if(prop_id == 832) // scrapbot
3431 EffectSummonWild(i, summon_prop->FactionId);
3432 else
3433 EffectSummonGuardian(i, summon_prop->FactionId);
3434 break;
3436 case SUMMON_PROP_TYPE_TOTEM:
3437 EffectSummonTotem(i, summon_prop->Slot);
3438 break;
3439 case SUMMON_PROP_TYPE_CRITTER:
3440 EffectSummonCritter(i, summon_prop->FactionId);
3441 break;
3442 case SUMMON_PROP_TYPE_PHASING:
3443 case SUMMON_PROP_TYPE_LIGHTWELL:
3444 case SUMMON_PROP_TYPE_REPAIR_BOT:
3445 EffectSummonWild(i, summon_prop->FactionId);
3446 break;
3447 case SUMMON_PROP_TYPE_SIEGE_VEH:
3448 case SUMMON_PROP_TYPE_DRAKE_VEH:
3449 // TODO
3450 // EffectSummonVehicle(i);
3451 break;
3452 default:
3453 sLog.outError("EffectSummonType: Unhandled summon type %u", summon_prop->Type);
3454 break;
3456 break;
3458 case SUMMON_PROP_GROUP_PETS:
3460 // FIXME : multiple summons - not yet supported as pet
3461 //1562 - force of nature - sid 33831
3462 //1161 - feral spirit - sid 51533
3463 if(prop_id == 1562) // 3 uncontrolable instead of one controllable :/
3464 EffectSummonGuardian(i, summon_prop->FactionId);
3465 else
3466 EffectSummon(i);
3467 break;
3469 case SUMMON_PROP_GROUP_CONTROLLABLE:
3471 // no type here
3472 // maybe wrong - but thats the handler currently used for those
3473 EffectSummonGuardian(i, summon_prop->FactionId);
3474 break;
3476 case SUMMON_PROP_GROUP_VEHICLE:
3478 // TODO
3479 // EffectSummonVehicle(i);
3480 break;
3482 default:
3483 sLog.outError("EffectSummonType: Unhandled summon group type %u", summon_prop->Group);
3484 break;
3488 void Spell::EffectSummon(uint32 i)
3490 if (m_caster->GetPetGUID())
3491 return;
3493 if (!unitTarget)
3494 return;
3495 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
3496 if (!pet_entry)
3497 return;
3498 uint32 level = m_caster->getLevel();
3499 Pet* spawnCreature = new Pet(SUMMON_PET);
3501 int32 duration = GetSpellDuration(m_spellInfo);
3502 if(Player* modOwner = m_caster->GetSpellModOwner())
3503 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
3505 if (m_caster->GetTypeId()==TYPEID_PLAYER && spawnCreature->LoadPetFromDB((Player*)m_caster,pet_entry))
3507 // Summon in dest location
3508 float x, y, z;
3509 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3511 x = m_targets.m_destX;
3512 y = m_targets.m_destY;
3513 z = m_targets.m_destZ;
3514 spawnCreature->Relocate(m_targets.m_destX, m_targets.m_destY, m_targets.m_destZ, -m_caster->GetOrientation());
3517 // set timer for unsummon
3518 if (duration > 0)
3519 spawnCreature->SetDuration(duration);
3521 return;
3524 Map *map = m_caster->GetMap();
3525 uint32 pet_number = sObjectMgr.GeneratePetNumber();
3526 if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
3527 m_spellInfo->EffectMiscValue[i], pet_number))
3529 sLog.outErrorDb("Spell::EffectSummon: no such creature entry %u",m_spellInfo->EffectMiscValue[i]);
3530 delete spawnCreature;
3531 return;
3534 // Summon in dest location
3535 float x, y, z;
3536 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3538 x = m_targets.m_destX;
3539 y = m_targets.m_destY;
3540 z = m_targets.m_destZ;
3542 else
3543 m_caster->GetClosePoint(x, y, z, spawnCreature->GetObjectSize());
3545 spawnCreature->Relocate(x, y, z, -m_caster->GetOrientation());
3547 if (!spawnCreature->IsPositionValid())
3549 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
3550 spawnCreature->GetGUIDLow(), spawnCreature->GetEntry(), spawnCreature->GetPositionX(), spawnCreature->GetPositionY());
3551 delete spawnCreature;
3552 return;
3555 // set timer for unsummon
3556 if (duration > 0)
3557 spawnCreature->SetDuration(duration);
3559 spawnCreature->SetOwnerGUID(m_caster->GetGUID());
3560 spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
3561 spawnCreature->setPowerType(POWER_MANA);
3562 spawnCreature->setFaction(m_caster->getFaction());
3563 spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS, 0);
3564 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
3565 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
3566 spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
3567 spawnCreature->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
3568 spawnCreature->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
3569 spawnCreature->SetCreatorGUID(m_caster->GetGUID());
3570 spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3572 spawnCreature->InitStatsForLevel(level, m_caster);
3574 spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
3576 spawnCreature->AIM_Initialize();
3577 spawnCreature->InitPetCreateSpells();
3578 spawnCreature->InitLevelupSpellsForLevel();
3579 spawnCreature->SetHealth(spawnCreature->GetMaxHealth());
3580 spawnCreature->SetPower(POWER_MANA, spawnCreature->GetMaxPower(POWER_MANA));
3582 std::string name = m_caster->GetName();
3583 name.append(petTypeSuffix[spawnCreature->getPetType()]);
3584 spawnCreature->SetName( name );
3586 map->Add((Creature*)spawnCreature);
3588 m_caster->SetPet(spawnCreature);
3590 if (m_caster->GetTypeId() == TYPEID_PLAYER)
3592 spawnCreature->GetCharmInfo()->SetReactState( REACT_DEFENSIVE );
3593 spawnCreature->SavePetToDB(PET_SAVE_AS_CURRENT);
3594 ((Player*)m_caster)->PetSpellInitialize();
3598 void Spell::EffectLearnSpell(uint32 i)
3600 if (!unitTarget)
3601 return;
3603 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
3605 if (m_caster->GetTypeId() == TYPEID_PLAYER)
3606 EffectLearnPetSpell(i);
3608 return;
3611 Player *player = (Player*)unitTarget;
3613 uint32 spellToLearn = ((m_spellInfo->Id==SPELL_ID_GENERIC_LEARN) || (m_spellInfo->Id==SPELL_ID_GENERIC_LEARN_PET)) ? damage : m_spellInfo->EffectTriggerSpell[i];
3614 player->learnSpell(spellToLearn,false);
3616 sLog.outDebug( "Spell: Player %u has learned spell %u from NpcGUID=%u", player->GetGUIDLow(), spellToLearn, m_caster->GetGUIDLow() );
3619 void Spell::EffectDispel(uint32 i)
3621 if (!unitTarget)
3622 return;
3624 // Fill possible dispell list
3625 std::vector <Aura *> dispel_list;
3627 // Create dispel mask by dispel type
3628 uint32 dispel_type = m_spellInfo->EffectMiscValue[i];
3629 uint32 dispelMask = GetDispellMask( DispelType(dispel_type) );
3630 Unit::AuraMap const& auras = unitTarget->GetAuras();
3631 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr)
3633 Aura *aur = (*itr).second;
3634 if (aur && (1<<aur->GetSpellProto()->Dispel) & dispelMask)
3636 if(aur->GetSpellProto()->Dispel == DISPEL_MAGIC)
3638 bool positive = true;
3639 if (!aur->IsPositive())
3640 positive = false;
3641 else
3642 positive = (aur->GetSpellProto()->AttributesEx & SPELL_ATTR_EX_NEGATIVE)==0;
3644 // do not remove positive auras if friendly target
3645 // negative auras if non-friendly target
3646 if (positive == unitTarget->IsFriendlyTo(m_caster))
3647 continue;
3649 // Add aura to dispel list (all stack cases)
3650 for(int k = 0; k < aur->GetStackAmount(); ++k)
3651 dispel_list.push_back(aur);
3654 // Ok if exist some buffs for dispel try dispel it
3655 if (!dispel_list.empty())
3657 std::list < std::pair<uint32,uint64> > success_list;// (spell_id,casterGuid)
3658 std::list < uint32 > fail_list; // spell_id
3660 // some spells have effect value = 0 and all from its by meaning expect 1
3661 if(!damage)
3662 damage = 1;
3664 // Dispell N = damage buffs (or while exist buffs for dispel)
3665 for (int32 count=0; count < damage && !dispel_list.empty(); ++count)
3667 // Random select buff for dispel
3668 std::vector<Aura*>::iterator dispel_itr = dispel_list.begin();
3669 std::advance(dispel_itr,urand(0, dispel_list.size()-1));
3671 Aura *aur = *dispel_itr;
3673 // remove entry from dispel_list
3674 dispel_list.erase(dispel_itr);
3676 SpellEntry const* spellInfo = aur->GetSpellProto();
3677 // Base dispel chance
3678 // TODO: possible chance depend from spell level??
3679 int32 miss_chance = 0;
3680 // Apply dispel mod from aura caster
3681 if (Unit *caster = aur->GetCaster())
3683 if ( Player* modOwner = caster->GetSpellModOwner() )
3684 modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_RESIST_DISPEL_CHANCE, miss_chance, this);
3686 // Try dispel
3687 if (roll_chance_i(miss_chance))
3688 fail_list.push_back(spellInfo->Id);
3689 else
3690 success_list.push_back(std::pair<uint32,uint64>(aur->GetId(),aur->GetCasterGUID()));
3692 // Send success log and really remove auras
3693 if (!success_list.empty())
3695 int32 count = success_list.size();
3696 WorldPacket data(SMSG_SPELLDISPELLOG, 8+8+4+1+4+count*5);
3697 data.append(unitTarget->GetPackGUID()); // Victim GUID
3698 data.append(m_caster->GetPackGUID()); // Caster GUID
3699 data << uint32(m_spellInfo->Id); // Dispel spell id
3700 data << uint8(0); // not used
3701 data << uint32(count); // count
3702 for (std::list<std::pair<uint32,uint64> >::iterator j = success_list.begin(); j != success_list.end(); ++j)
3704 SpellEntry const* spellInfo = sSpellStore.LookupEntry(j->first);
3705 data << uint32(spellInfo->Id); // Spell Id
3706 data << uint8(0); // 0 - dispeled !=0 cleansed
3707 unitTarget->RemoveSingleAuraDueToSpellByDispel(spellInfo->Id, j->second, m_caster);
3709 m_caster->SendMessageToSet(&data, true);
3711 // On success dispel
3712 // Devour Magic
3713 if (m_spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK && m_spellInfo->Category == SPELLCATEGORY_DEVOUR_MAGIC)
3715 int32 heal_amount = m_spellInfo->CalculateSimpleValue(1);
3716 m_caster->CastCustomSpell(m_caster, 19658, &heal_amount, NULL, NULL, true);
3719 // Send fail log to client
3720 if (!fail_list.empty())
3722 // Failed to dispell
3723 WorldPacket data(SMSG_DISPEL_FAILED, 8+8+4+4*fail_list.size());
3724 data << uint64(m_caster->GetGUID()); // Caster GUID
3725 data << uint64(unitTarget->GetGUID()); // Victim GUID
3726 data << uint32(m_spellInfo->Id); // Dispell spell id
3727 for (std::list< uint32 >::iterator j = fail_list.begin(); j != fail_list.end(); ++j)
3728 data << uint32(*j); // Spell Id
3729 m_caster->SendMessageToSet(&data, true);
3734 void Spell::EffectDualWield(uint32 /*i*/)
3736 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
3737 ((Player*)unitTarget)->SetCanDualWield(true);
3740 void Spell::EffectPull(uint32 /*i*/)
3742 // TODO: create a proper pull towards distract spell center for distract
3743 sLog.outDebug("WORLD: Spell Effect DUMMY");
3746 void Spell::EffectDistract(uint32 /*i*/)
3748 // Check for possible target
3749 if (!unitTarget || unitTarget->isInCombat())
3750 return;
3752 // target must be OK to do this
3753 if( unitTarget->hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_STUNNED | UNIT_STAT_FLEEING ) )
3754 return;
3756 float angle = unitTarget->GetAngle(m_targets.m_destX, m_targets.m_destY);
3758 if ( unitTarget->GetTypeId() == TYPEID_PLAYER )
3760 // For players just turn them
3761 WorldPacket data;
3762 ((Player*)unitTarget)->BuildTeleportAckMsg(&data, unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), angle);
3763 ((Player*)unitTarget)->GetSession()->SendPacket( &data );
3764 ((Player*)unitTarget)->SetPosition(unitTarget->GetPositionX(), unitTarget->GetPositionY(), unitTarget->GetPositionZ(), angle, false);
3766 else
3768 // Set creature Distracted, Stop it, And turn it
3769 unitTarget->SetOrientation(angle);
3770 unitTarget->StopMoving();
3771 unitTarget->GetMotionMaster()->MoveDistract(damage * IN_MILISECONDS);
3775 void Spell::EffectPickPocket(uint32 /*i*/)
3777 if (m_caster->GetTypeId() != TYPEID_PLAYER)
3778 return;
3780 // victim must be creature and attackable
3781 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || m_caster->IsFriendlyTo(unitTarget))
3782 return;
3784 // victim have to be alive and humanoid or undead
3785 if (unitTarget->isAlive() && (unitTarget->GetCreatureTypeMask() & CREATURE_TYPEMASK_HUMANOID_OR_UNDEAD) != 0)
3787 int32 chance = 10 + int32(m_caster->getLevel()) - int32(unitTarget->getLevel());
3789 if (chance > irand(0, 19))
3791 // Stealing successful
3792 //sLog.outDebug("Sending loot from pickpocket");
3793 ((Player*)m_caster)->SendLoot(unitTarget->GetGUID(),LOOT_PICKPOCKETING);
3795 else
3797 // Reveal action + get attack
3798 m_caster->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH);
3799 if (((Creature*)unitTarget)->AI())
3800 ((Creature*)unitTarget)->AI()->AttackedBy(m_caster);
3805 void Spell::EffectAddFarsight(uint32 i)
3807 if(m_caster->GetTypeId() != TYPEID_PLAYER)
3808 return;
3810 int32 duration = GetSpellDuration(m_spellInfo);
3811 DynamicObject* dynObj = new DynamicObject;
3813 // set radius to 0: spell not expected to work as persistent aura
3814 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))
3816 delete dynObj;
3817 return;
3819 dynObj->SetUInt32Value(OBJECT_FIELD_TYPE, 65);
3820 dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x80000002);
3821 m_caster->AddDynObject(dynObj);
3822 m_caster->GetMap()->Add(dynObj);
3823 ((Player*)m_caster)->SetFarSightGUID(dynObj->GetGUID());
3826 void Spell::EffectSummonWild(uint32 i, uint32 forceFaction)
3828 uint32 creature_entry = m_spellInfo->EffectMiscValue[i];
3829 if (!creature_entry)
3830 return;
3832 uint32 level = m_caster->getLevel();
3834 // level of creature summoned using engineering item based at engineering skill level
3835 if (m_caster->GetTypeId()==TYPEID_PLAYER && m_CastItem)
3837 ItemPrototype const *proto = m_CastItem->GetProto();
3838 if (proto && proto->RequiredSkill == SKILL_ENGINERING)
3840 uint16 skill202 = ((Player*)m_caster)->GetSkillValue(SKILL_ENGINERING);
3841 if (skill202)
3842 level = skill202/5;
3846 // select center of summon position
3847 float center_x = m_targets.m_destX;
3848 float center_y = m_targets.m_destY;
3849 float center_z = m_targets.m_destZ;
3851 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3852 int32 duration = GetSpellDuration(m_spellInfo);
3853 TempSummonType summonType = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_OR_DEAD_DESPAWN;
3855 int32 amount = damage > 0 ? damage : 1;
3857 for(int32 count = 0; count < amount; ++count)
3859 float px, py, pz;
3860 // If dest location if present
3861 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3863 // Summon 1 unit in dest location
3864 if (count == 0)
3866 px = m_targets.m_destX;
3867 py = m_targets.m_destY;
3868 pz = m_targets.m_destZ;
3870 // Summon in random point all other units if location present
3871 else
3872 m_caster->GetRandomPoint(center_x, center_y, center_z, radius, px, py, pz);
3874 // Summon if dest location not present near caster
3875 else
3876 m_caster->GetClosePoint(px, py, pz, 3.0f);
3878 if(Creature *summon = m_caster->SummonCreature(creature_entry, px, py, pz, m_caster->GetOrientation(), summonType, duration))
3880 summon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3881 summon->SetCreatorGUID(m_caster->GetGUID());
3883 if(forceFaction)
3884 summon->setFaction(forceFaction);
3889 void Spell::EffectSummonGuardian(uint32 i, uint32 forceFaction)
3891 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
3892 if (!pet_entry)
3893 return;
3895 // in another case summon new
3896 uint32 level = m_caster->getLevel();
3898 // level of pet summoned using engineering item based at engineering skill level
3899 if (m_caster->GetTypeId() == TYPEID_PLAYER && m_CastItem)
3901 ItemPrototype const *proto = m_CastItem->GetProto();
3902 if (proto && proto->RequiredSkill == SKILL_ENGINERING)
3904 uint16 skill202 = ((Player*)m_caster)->GetSkillValue(SKILL_ENGINERING);
3905 if (skill202)
3907 level = skill202 / 5;
3912 // select center of summon position
3913 float center_x = m_targets.m_destX;
3914 float center_y = m_targets.m_destY;
3915 float center_z = m_targets.m_destZ;
3917 float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
3918 int32 duration = GetSpellDuration(m_spellInfo);
3919 if(Player* modOwner = m_caster->GetSpellModOwner())
3920 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
3922 int32 amount = damage > 0 ? damage : 1;
3924 for(int32 count = 0; count < amount; ++count)
3926 Pet* spawnCreature = new Pet(GUARDIAN_PET);
3928 Map *map = m_caster->GetMap();
3929 uint32 pet_number = sObjectMgr.GeneratePetNumber();
3930 if (!spawnCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map,m_caster->GetPhaseMask(),
3931 m_spellInfo->EffectMiscValue[i], pet_number))
3933 sLog.outError("no such creature entry %u", m_spellInfo->EffectMiscValue[i]);
3934 delete spawnCreature;
3935 return;
3938 float px, py, pz;
3939 // If dest location if present
3940 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
3942 // Summon 1 unit in dest location
3943 if (count == 0)
3945 px = m_targets.m_destX;
3946 py = m_targets.m_destY;
3947 pz = m_targets.m_destZ;
3949 // Summon in random point all other units if location present
3950 else
3951 m_caster->GetRandomPoint(center_x, center_y, center_z, radius, px, py, pz);
3953 // Summon if dest location not present near caster
3954 else
3955 m_caster->GetClosePoint(px, py, pz,spawnCreature->GetObjectSize());
3957 spawnCreature->Relocate(px, py, pz, m_caster->GetOrientation());
3959 if (!spawnCreature->IsPositionValid())
3961 sLog.outError("Pet (guidlow %d, entry %d) not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)",
3962 spawnCreature->GetGUIDLow(), spawnCreature->GetEntry(), spawnCreature->GetPositionX(), spawnCreature->GetPositionY());
3963 delete spawnCreature;
3964 return;
3967 if (duration > 0)
3968 spawnCreature->SetDuration(duration);
3970 spawnCreature->SetOwnerGUID(m_caster->GetGUID());
3971 spawnCreature->setPowerType(POWER_MANA);
3972 spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, spawnCreature->GetCreatureInfo()->npcflag);
3973 spawnCreature->setFaction(forceFaction ? forceFaction : m_caster->getFaction());
3974 spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS, 0);
3975 spawnCreature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
3976 spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
3977 spawnCreature->SetCreatorGUID(m_caster->GetGUID());
3978 spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
3980 spawnCreature->InitStatsForLevel(level, m_caster);
3981 spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
3983 spawnCreature->AIM_Initialize();
3985 m_caster->AddGuardian(spawnCreature);
3987 map->Add((Creature*)spawnCreature);
3991 void Spell::EffectTeleUnitsFaceCaster(uint32 i)
3993 if (!unitTarget)
3994 return;
3996 if (unitTarget->isInFlight())
3997 return;
3999 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
4001 float fx, fy, fz;
4002 m_caster->GetClosePoint(fx, fy, fz, unitTarget->GetObjectSize(), dis);
4004 unitTarget->NearTeleportTo(fx, fy, fz, -m_caster->GetOrientation(), unitTarget==m_caster);
4007 void Spell::EffectLearnSkill(uint32 i)
4009 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4010 return;
4012 if (damage < 0)
4013 return;
4015 uint32 skillid = m_spellInfo->EffectMiscValue[i];
4016 uint16 skillval = ((Player*)unitTarget)->GetPureSkillValue(skillid);
4017 ((Player*)unitTarget)->SetSkill(skillid, skillval ? skillval : 1, damage * 75);
4020 void Spell::EffectAddHonor(uint32 /*i*/)
4022 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4023 return;
4025 // not scale value for item based reward (/10 value expected)
4026 if (m_CastItem)
4028 ((Player*)unitTarget)->RewardHonor(NULL, 1, damage / 10);
4029 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());
4030 return;
4033 // do not allow to add too many honor for player (50 * 21) = 1040 at level 70, or (50 * 31) = 1550 at level 80
4034 if (damage <= 50)
4036 uint32 honor_reward = MaNGOS::Honor::hk_honor_at_level(unitTarget->getLevel(), damage);
4037 ((Player*)unitTarget)->RewardHonor(NULL, 1, honor_reward);
4038 sLog.outDebug("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (scale) to player: %u", m_spellInfo->Id, honor_reward, ((Player*)unitTarget)->GetGUIDLow());
4040 else
4042 //maybe we have correct honor_gain in damage already
4043 ((Player*)unitTarget)->RewardHonor(NULL, 1, damage);
4044 sLog.outError("SpellEffect::AddHonor (spell_id %u) rewards %u honor points (non scale) for player: %u", m_spellInfo->Id, damage, ((Player*)unitTarget)->GetGUIDLow());
4048 void Spell::EffectTradeSkill(uint32 /*i*/)
4050 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4051 return;
4052 // uint32 skillid = m_spellInfo->EffectMiscValue[i];
4053 // uint16 skillmax = ((Player*)unitTarget)->(skillid);
4054 // ((Player*)unitTarget)->SetSkill(skillid,skillval?skillval:1,skillmax+75);
4057 void Spell::EffectEnchantItemPerm(uint32 effect_idx)
4059 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4060 return;
4061 if (!itemTarget)
4062 return;
4064 Player* p_caster = (Player*)m_caster;
4066 // not grow at item use at item case
4067 p_caster->UpdateCraftSkill(m_spellInfo->Id);
4069 uint32 enchant_id = m_spellInfo->EffectMiscValue[effect_idx];
4070 if (!enchant_id)
4071 return;
4073 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4074 if (!pEnchant)
4075 return;
4077 // item can be in trade slot and have owner diff. from caster
4078 Player* item_owner = itemTarget->GetOwner();
4079 if (!item_owner)
4080 return;
4082 if (item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4084 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(perm): %s (Entry: %d) for player: %s (Account: %u)",
4085 p_caster->GetName(),p_caster->GetSession()->GetAccountId(),
4086 itemTarget->GetProto()->Name1,itemTarget->GetEntry(),
4087 item_owner->GetName(),item_owner->GetSession()->GetAccountId());
4090 // remove old enchanting before applying new if equipped
4091 item_owner->ApplyEnchantment(itemTarget,PERM_ENCHANTMENT_SLOT,false);
4093 itemTarget->SetEnchantment(PERM_ENCHANTMENT_SLOT, enchant_id, 0, 0);
4095 // add new enchanting if equipped
4096 item_owner->ApplyEnchantment(itemTarget,PERM_ENCHANTMENT_SLOT,true);
4099 void Spell::EffectEnchantItemPrismatic(uint32 effect_idx)
4101 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4102 return;
4103 if (!itemTarget)
4104 return;
4106 Player* p_caster = (Player*)m_caster;
4108 uint32 enchant_id = m_spellInfo->EffectMiscValue[effect_idx];
4109 if (!enchant_id)
4110 return;
4112 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4113 if (!pEnchant)
4114 return;
4116 // support only enchantings with add socket in this slot
4118 bool add_socket = false;
4119 for(int i = 0; i < 3; ++i)
4121 if (pEnchant->type[i]==ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET)
4123 add_socket = true;
4124 break;
4127 if (!add_socket)
4129 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.",
4130 m_spellInfo->Id,SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC,ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET);
4131 return;
4135 // item can be in trade slot and have owner diff. from caster
4136 Player* item_owner = itemTarget->GetOwner();
4137 if (!item_owner)
4138 return;
4140 if (item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4142 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(perm): %s (Entry: %d) for player: %s (Account: %u)",
4143 p_caster->GetName(),p_caster->GetSession()->GetAccountId(),
4144 itemTarget->GetProto()->Name1,itemTarget->GetEntry(),
4145 item_owner->GetName(),item_owner->GetSession()->GetAccountId());
4148 // remove old enchanting before applying new if equipped
4149 item_owner->ApplyEnchantment(itemTarget,PRISMATIC_ENCHANTMENT_SLOT,false);
4151 itemTarget->SetEnchantment(PRISMATIC_ENCHANTMENT_SLOT, enchant_id, 0, 0);
4153 // add new enchanting if equipped
4154 item_owner->ApplyEnchantment(itemTarget,PRISMATIC_ENCHANTMENT_SLOT,true);
4157 void Spell::EffectEnchantItemTmp(uint32 i)
4159 if (m_caster->GetTypeId() != TYPEID_PLAYER)
4160 return;
4162 Player* p_caster = (Player*)m_caster;
4164 // Rockbiter Weapon apply to both weapon
4165 if (m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN && m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000400000))
4167 uint32 spell_id = 0;
4169 // enchanting spell selected by calculated damage-per-sec stored in Effect[1] base value
4170 // Note: damage calculated (correctly) with rounding int32(float(v)) but
4171 // RW enchantments applied damage int32(float(v)+0.5), this create 0..1 difference sometime
4172 switch(damage)
4174 // Rank 1
4175 case 2: spell_id = 36744; break; // 0% [ 7% == 2, 14% == 2, 20% == 2]
4176 // Rank 2
4177 case 4: spell_id = 36753; break; // 0% [ 7% == 4, 14% == 4]
4178 case 5: spell_id = 36751; break; // 20%
4179 // Rank 3
4180 case 6: spell_id = 36754; break; // 0% [ 7% == 6, 14% == 6]
4181 case 7: spell_id = 36755; break; // 20%
4182 // Rank 4
4183 case 9: spell_id = 36761; break; // 0% [ 7% == 6]
4184 case 10: spell_id = 36758; break; // 14%
4185 case 11: spell_id = 36760; break; // 20%
4186 default:
4187 sLog.outError("Spell::EffectEnchantItemTmp: Damage %u not handled in S'RW",damage);
4188 return;
4192 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id);
4193 if (!spellInfo)
4195 sLog.outError("Spell::EffectEnchantItemTmp: unknown spell id %i", spell_id);
4196 return;
4199 for(int j = BASE_ATTACK; j <= OFF_ATTACK; ++j)
4201 if (Item* item = p_caster->GetWeaponForAttack(WeaponAttackType(j)))
4203 if (item->IsFitToSpellRequirements(m_spellInfo))
4205 Spell *spell = new Spell(m_caster, spellInfo, true);
4206 SpellCastTargets targets;
4207 targets.setItemTarget( item );
4208 spell->prepare(&targets);
4212 return;
4215 if (!itemTarget)
4216 return;
4218 uint32 enchant_id = m_spellInfo->EffectMiscValue[i];
4220 if (!enchant_id)
4222 sLog.outError("Spell %u Effect %u (SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY) have 0 as enchanting id",m_spellInfo->Id,i);
4223 return;
4226 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
4227 if(!pEnchant)
4229 sLog.outError("Spell %u Effect %u (SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY) have not existed enchanting id %u ",m_spellInfo->Id,i,enchant_id);
4230 return;
4233 // select enchantment duration
4234 uint32 duration;
4236 // rogue family enchantments exception by duration
4237 if(m_spellInfo->Id == 38615)
4238 duration = 1800; // 30 mins
4239 // other rogue family enchantments always 1 hour (some have spell damage=0, but some have wrong data in EffBasePoints)
4240 else if(m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE)
4241 duration = 3600; // 1 hour
4242 // shaman family enchantments
4243 else if(m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN)
4244 duration = 1800; // 30 mins
4245 // other cases with this SpellVisual already selected
4246 else if(m_spellInfo->SpellVisual[0] == 215)
4247 duration = 1800; // 30 mins
4248 // some fishing pole bonuses
4249 else if(m_spellInfo->SpellVisual[0] == 563)
4250 duration = 600; // 10 mins
4251 // shaman rockbiter enchantments
4252 else if(m_spellInfo->SpellVisual[0] == 0)
4253 duration = 1800; // 30 mins
4254 else if(m_spellInfo->Id == 29702)
4255 duration = 300; // 5 mins
4256 else if(m_spellInfo->Id == 37360)
4257 duration = 300; // 5 mins
4258 // default case
4259 else
4260 duration = 3600; // 1 hour
4262 // item can be in trade slot and have owner diff. from caster
4263 Player* item_owner = itemTarget->GetOwner();
4264 if(!item_owner)
4265 return;
4267 if(item_owner!=p_caster && p_caster->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) )
4269 sLog.outCommand(p_caster->GetSession()->GetAccountId(),"GM %s (Account: %u) enchanting(temp): %s (Entry: %d) for player: %s (Account: %u)",
4270 p_caster->GetName(), p_caster->GetSession()->GetAccountId(),
4271 itemTarget->GetProto()->Name1, itemTarget->GetEntry(),
4272 item_owner->GetName(), item_owner->GetSession()->GetAccountId());
4275 // remove old enchanting before applying new if equipped
4276 item_owner->ApplyEnchantment(itemTarget,TEMP_ENCHANTMENT_SLOT, false);
4278 itemTarget->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, duration * 1000, 0);
4280 // add new enchanting if equipped
4281 item_owner->ApplyEnchantment(itemTarget, TEMP_ENCHANTMENT_SLOT, true);
4284 void Spell::EffectTameCreature(uint32 /*i*/)
4286 // Caster must be player, checked in Spell::CheckCast
4287 // Spell can be triggered, we need to check original caster prior to caster
4288 Player* plr = (Player*)(m_originalCaster ? m_originalCaster : m_caster);
4290 Creature* creatureTarget = (Creature*)unitTarget;
4292 // cast finish successfully
4293 //SendChannelUpdate(0);
4294 finish();
4296 Pet* pet = plr->CreateTamedPetFrom(creatureTarget, m_spellInfo->Id);
4297 if(!pet) // in versy specific state like near world end/etc.
4298 return;
4300 // "kill" original creature
4301 creatureTarget->ForcedDespawn();
4303 uint32 level = (creatureTarget->getLevel() < (plr->getLevel() - 5)) ? (plr->getLevel() - 5) : creatureTarget->getLevel();
4305 // prepare visual effect for levelup
4306 pet->SetUInt32Value(UNIT_FIELD_LEVEL, level - 1);
4308 // add to world
4309 pet->GetMap()->Add((Creature*)pet);
4311 // visual effect for levelup
4312 pet->SetUInt32Value(UNIT_FIELD_LEVEL, level);
4314 // caster have pet now
4315 plr->SetPet(pet);
4317 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
4318 plr->PetSpellInitialize();
4321 void Spell::EffectSummonPet(uint32 i)
4323 uint32 petentry = m_spellInfo->EffectMiscValue[i];
4325 Pet *OldSummon = m_caster->GetPet();
4327 // if pet requested type already exist
4328 if( OldSummon )
4330 if(petentry == 0 || OldSummon->GetEntry() == petentry)
4332 // pet in corpse state can't be summoned
4333 if( OldSummon->isDead() )
4334 return;
4336 OldSummon->GetMap()->Remove((Creature*)OldSummon,false);
4338 float px, py, pz;
4339 m_caster->GetClosePoint(px, py, pz, OldSummon->GetObjectSize());
4341 OldSummon->Relocate(px, py, pz, OldSummon->GetOrientation());
4342 m_caster->GetMap()->Add((Creature*)OldSummon);
4344 if(m_caster->GetTypeId() == TYPEID_PLAYER && OldSummon->isControlled() )
4346 ((Player*)m_caster)->PetSpellInitialize();
4348 return;
4351 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4352 ((Player*)m_caster)->RemovePet(OldSummon,(OldSummon->getPetType()==HUNTER_PET ? PET_SAVE_AS_DELETED : PET_SAVE_NOT_IN_SLOT),false);
4353 else
4354 return;
4357 Pet* NewSummon = new Pet;
4359 // petentry==0 for hunter "call pet" (current pet summoned if any)
4360 if(m_caster->GetTypeId() == TYPEID_PLAYER && NewSummon->LoadPetFromDB((Player*)m_caster,petentry))
4362 if(NewSummon->getPetType()==SUMMON_PET)
4364 // Remove Demonic Sacrifice auras (known pet)
4365 Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4366 for(Unit::AuraList::const_iterator itr = auraClassScripts.begin();itr!=auraClassScripts.end();)
4368 if((*itr)->GetModifier()->m_miscvalue == 2228)
4370 m_caster->RemoveAurasDueToSpell((*itr)->GetId());
4371 itr = auraClassScripts.begin();
4373 else
4374 ++itr;
4378 return;
4381 // not error in case fail hunter call pet
4382 if(!petentry)
4384 delete NewSummon;
4385 return;
4388 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(petentry);
4390 if(!cInfo)
4392 sLog.outError("EffectSummonPet: creature entry %u not found.",petentry);
4393 delete NewSummon;
4394 return;
4397 Map *map = m_caster->GetMap();
4398 uint32 pet_number = sObjectMgr.GeneratePetNumber();
4399 if(!NewSummon->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
4400 petentry, pet_number))
4402 delete NewSummon;
4403 return;
4406 float px, py, pz;
4407 m_caster->GetClosePoint(px, py, pz, NewSummon->GetObjectSize());
4409 NewSummon->Relocate(px, py, pz, m_caster->GetOrientation());
4411 if(!NewSummon->IsPositionValid())
4413 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
4414 NewSummon->GetGUIDLow(), NewSummon->GetEntry(), NewSummon->GetPositionX(), NewSummon->GetPositionY());
4415 delete NewSummon;
4416 return;
4419 uint32 petlevel = m_caster->getLevel();
4420 NewSummon->setPetType(SUMMON_PET);
4422 uint32 faction = m_caster->getFaction();
4423 if(m_caster->GetTypeId() == TYPEID_UNIT)
4425 if ( ((Creature*)m_caster)->isTotem() )
4426 NewSummon->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE);
4427 else
4428 NewSummon->GetCharmInfo()->SetReactState(REACT_DEFENSIVE);
4431 NewSummon->SetOwnerGUID(m_caster->GetGUID());
4432 NewSummon->SetCreatorGUID(m_caster->GetGUID());
4433 NewSummon->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
4434 NewSummon->setFaction(faction);
4435 NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048);
4436 NewSummon->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
4437 NewSummon->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
4438 NewSummon->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
4439 NewSummon->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
4440 NewSummon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
4442 NewSummon->GetCharmInfo()->SetPetNumber(pet_number, true);
4443 // this enables pet details window (Shift+P)
4445 // this enables popup window (pet dismiss, cancel), hunter pet additional flags set later
4446 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4447 NewSummon->SetUInt32Value(UNIT_FIELD_FLAGS,UNIT_FLAG_PVP_ATTACKABLE);
4449 if(m_caster->IsPvP())
4450 NewSummon->SetPvP(true);
4452 NewSummon->InitStatsForLevel(petlevel, m_caster);
4453 NewSummon->InitPetCreateSpells();
4454 NewSummon->InitLevelupSpellsForLevel();
4455 NewSummon->InitTalentForLevel();
4457 if(NewSummon->getPetType()==SUMMON_PET)
4459 // Remove Demonic Sacrifice auras (new pet)
4460 Unit::AuraList const& auraClassScripts = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4461 for(Unit::AuraList::const_iterator itr = auraClassScripts.begin();itr!=auraClassScripts.end();)
4463 if((*itr)->GetModifier()->m_miscvalue==2228)
4465 m_caster->RemoveAurasDueToSpell((*itr)->GetId());
4466 itr = auraClassScripts.begin();
4468 else
4469 ++itr;
4472 // generate new name for summon pet
4473 std::string new_name=sObjectMgr.GeneratePetName(petentry);
4474 if(!new_name.empty())
4475 NewSummon->SetName(new_name);
4477 else if(NewSummon->getPetType()==HUNTER_PET)
4478 NewSummon->SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_NOT_ALLOWED);
4480 NewSummon->AIM_Initialize();
4481 NewSummon->SetHealth(NewSummon->GetMaxHealth());
4482 NewSummon->SetPower(POWER_MANA, NewSummon->GetMaxPower(POWER_MANA));
4484 map->Add((Creature*)NewSummon);
4486 m_caster->SetPet(NewSummon);
4487 sLog.outDebug("New Pet has guid %u", NewSummon->GetGUIDLow());
4489 if(m_caster->GetTypeId() == TYPEID_PLAYER)
4491 NewSummon->SavePetToDB(PET_SAVE_AS_CURRENT);
4492 ((Player*)m_caster)->PetSpellInitialize();
4496 void Spell::EffectLearnPetSpell(uint32 i)
4498 if(m_caster->GetTypeId() != TYPEID_PLAYER)
4499 return;
4501 Player *_player = (Player*)m_caster;
4503 Pet *pet = _player->GetPet();
4504 if(!pet)
4505 return;
4506 if(!pet->isAlive())
4507 return;
4509 SpellEntry const *learn_spellproto = sSpellStore.LookupEntry(m_spellInfo->EffectTriggerSpell[i]);
4510 if(!learn_spellproto)
4511 return;
4513 pet->learnSpell(learn_spellproto->Id);
4515 pet->SavePetToDB(PET_SAVE_AS_CURRENT);
4516 _player->PetSpellInitialize();
4519 void Spell::EffectTaunt(uint32 /*i*/)
4521 if (!unitTarget)
4522 return;
4524 // this effect use before aura Taunt apply for prevent taunt already attacking target
4525 // for spell as marked "non effective at already attacking target"
4526 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
4528 if (unitTarget->getVictim()==m_caster)
4530 SendCastResult(SPELL_FAILED_DONT_REPORT);
4531 return;
4535 // Also use this effect to set the taunter's threat to the taunted creature's highest value
4536 if (unitTarget->CanHaveThreatList() && unitTarget->getThreatManager().getCurrentVictim())
4537 unitTarget->getThreatManager().addThreat(m_caster,unitTarget->getThreatManager().getCurrentVictim()->getThreat());
4540 void Spell::EffectWeaponDmg(uint32 i)
4542 if(!unitTarget)
4543 return;
4544 if(!unitTarget->isAlive())
4545 return;
4547 // multiple weapon dmg effect workaround
4548 // execute only the last weapon damage
4549 // and handle all effects at once
4550 for (int j = 0; j < 3; ++j)
4552 switch(m_spellInfo->Effect[j])
4554 case SPELL_EFFECT_WEAPON_DAMAGE:
4555 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
4556 case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
4557 case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
4558 if (j < i) // we must calculate only at last weapon effect
4559 return;
4560 break;
4564 // some spell specific modifiers
4565 bool spellBonusNeedWeaponDamagePercentMod = false; // if set applied weapon damage percent mode to spell bonus
4567 float weaponDamagePercentMod = 1.0f; // applied to weapon damage and to fixed effect damage bonus
4568 float totalDamagePercentMod = 1.0f; // applied to final bonus+weapon damage
4569 bool normalized = false;
4571 int32 spell_bonus = 0; // bonus specific for spell
4572 switch(m_spellInfo->SpellFamilyName)
4574 case SPELLFAMILY_WARRIOR:
4576 // Devastate bonus and sunder armor refresh
4577 if(m_spellInfo->SpellVisual[0] == 12295 && m_spellInfo->SpellIconID == 1508)
4579 uint32 stack = 0;
4580 // Need refresh all Sunder Armor auras from this caster
4581 Unit::AuraMap& suAuras = unitTarget->GetAuras();
4582 SpellEntry const *spellInfo;
4583 for(Unit::AuraMap::iterator itr = suAuras.begin(); itr != suAuras.end(); ++itr)
4585 spellInfo = (*itr).second->GetSpellProto();
4586 if( spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR &&
4587 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000004000)) &&
4588 (*itr).second->GetCasterGUID() == m_caster->GetGUID())
4590 (*itr).second->RefreshAura();
4591 stack = (*itr).second->GetStackAmount();
4592 break;
4595 if (stack)
4596 spell_bonus += stack * CalculateDamage(2, unitTarget);
4597 if (!stack || stack < spellInfo->StackAmount)
4598 // Devastate causing Sunder Armor Effect
4599 // and no need to cast over max stack amount
4600 m_caster->CastSpell(unitTarget, 58567, true);
4602 break;
4604 case SPELLFAMILY_ROGUE:
4606 // Mutilate (for each hand)
4607 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x600000000))
4609 bool found = false;
4610 // fast check
4611 if(unitTarget->HasAuraState(AURA_STATE_DEADLY_POISON))
4612 found = true;
4613 // full aura scan
4614 else
4616 Unit::AuraMap const& auras = unitTarget->GetAuras();
4617 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
4619 if(itr->second->GetSpellProto()->Dispel == DISPEL_POISON)
4621 found = true;
4622 break;
4627 if(found)
4628 totalDamagePercentMod *= 1.2f; // 120% if poisoned
4630 // Fan of Knives
4631 else if (m_caster->GetTypeId()==TYPEID_PLAYER && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0004000000000000)))
4633 Item* weapon = ((Player*)m_caster)->GetWeaponForAttack(m_attackType,true,true);
4634 if (weapon && weapon->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER)
4635 totalDamagePercentMod *= 1.5f; // 150% to daggers
4637 break;
4639 case SPELLFAMILY_PALADIN:
4641 // Seal of Command - receive benefit from Spell Damage and Healing
4642 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x00000002000000))
4644 spellBonusNeedWeaponDamagePercentMod = true;// apply weaponDamagePercentMod to spell_bonus (and then to all bonus, fixes and weapon already have applied)
4645 spell_bonus += int32(0.23f*m_caster->SpellBaseDamageBonus(GetSpellSchoolMask(m_spellInfo)));
4646 spell_bonus += int32(0.29f*m_caster->SpellBaseDamageBonusForVictim(GetSpellSchoolMask(m_spellInfo), unitTarget));
4648 break;
4650 case SPELLFAMILY_SHAMAN:
4652 // Skyshatter Harness item set bonus
4653 // Stormstrike
4654 if(m_spellInfo->SpellFamilyFlags & UI64LIT(0x001000000000))
4656 Unit::AuraList const& m_OverrideClassScript = m_caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
4657 for(Unit::AuraList::const_iterator citr = m_OverrideClassScript.begin(); citr != m_OverrideClassScript.end(); ++citr)
4659 // Stormstrike AP Buff
4660 if ( (*citr)->GetModifier()->m_miscvalue == 5634 )
4662 m_caster->CastSpell(m_caster, 38430, true, NULL, *citr);
4663 break;
4667 break;
4669 case SPELLFAMILY_DEATHKNIGHT:
4671 // Blood Strike, Heart Strike, Obliterate
4672 // Blood-Caked Strike, Scourge Strike
4673 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0002000001400000) ||
4674 m_spellInfo->SpellIconID == 1736 || m_spellInfo->SpellIconID == 3143)
4676 uint32 count = 0;
4677 Unit::AuraMap const& auras = unitTarget->GetAuras();
4678 for(Unit::AuraMap::const_iterator itr = auras.begin(); itr!=auras.end(); ++itr)
4680 if(itr->second->GetSpellProto()->Dispel == DISPEL_DISEASE &&
4681 itr->second->GetCasterGUID() == m_caster->GetGUID() &&
4682 IsSpellLastAuraEffect(itr->second->GetSpellProto(), itr->second->GetEffIndex()))
4683 ++count;
4686 if (count)
4688 // Effect 1(for Blood-Caked Strike)/3(other) damage is bonus
4689 float bonus = count * CalculateDamage(m_spellInfo->SpellIconID == 1736 ? 0 : 2, unitTarget) / 100.0f;
4690 // Blood Strike, Blood-Caked Strike and Obliterate store bonus*2
4691 if (m_spellInfo->SpellFamilyFlags & UI64LIT(0x0002000000400000) ||
4692 m_spellInfo->SpellIconID == 1736)
4693 bonus /= 2.0f;
4695 totalDamagePercentMod *= 1.0f + bonus;
4698 // Glyph of Blood Strike
4699 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000400000) &&
4700 m_caster->HasAura(59332) &&
4701 unitTarget->HasAuraType(SPELL_AURA_MOD_DECREASE_SPEED))
4703 totalDamagePercentMod *= 1.2f; // 120% if snared
4705 // Glyph of Death Strike
4706 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000010) &&
4707 m_caster->HasAura(59336))
4709 int32 rp = m_caster->GetPower(POWER_RUNIC_POWER) / 10;
4710 if(rp > 25)
4711 rp = 25;
4712 totalDamagePercentMod *= 1.0f + rp / 100.0f;
4714 // Glyph of Plague Strike
4715 if( m_spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000001) &&
4716 m_caster->HasAura(58657) )
4718 totalDamagePercentMod *= 1.2f;
4720 break;
4724 int32 fixed_bonus = 0;
4725 for (int j = 0; j < 3; ++j)
4727 switch(m_spellInfo->Effect[j])
4729 case SPELL_EFFECT_WEAPON_DAMAGE:
4730 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL:
4731 fixed_bonus += CalculateDamage(j, unitTarget);
4732 break;
4733 case SPELL_EFFECT_NORMALIZED_WEAPON_DMG:
4734 fixed_bonus += CalculateDamage(j, unitTarget);
4735 normalized = true;
4736 break;
4737 case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE:
4738 weaponDamagePercentMod *= float(CalculateDamage(j, unitTarget)) / 100.0f;
4740 // applied only to prev.effects fixed damage
4741 fixed_bonus = int32(fixed_bonus*weaponDamagePercentMod);
4742 break;
4743 default:
4744 break; // not weapon damage effect, just skip
4748 // apply weaponDamagePercentMod to spell bonus also
4749 if(spellBonusNeedWeaponDamagePercentMod)
4750 spell_bonus = int32(spell_bonus*weaponDamagePercentMod);
4752 // non-weapon damage
4753 int32 bonus = spell_bonus + fixed_bonus;
4755 // apply to non-weapon bonus weapon total pct effect, weapon total flat effect included in weapon damage
4756 if(bonus)
4758 UnitMods unitMod;
4759 switch(m_attackType)
4761 default:
4762 case BASE_ATTACK: unitMod = UNIT_MOD_DAMAGE_MAINHAND; break;
4763 case OFF_ATTACK: unitMod = UNIT_MOD_DAMAGE_OFFHAND; break;
4764 case RANGED_ATTACK: unitMod = UNIT_MOD_DAMAGE_RANGED; break;
4767 float weapon_total_pct = m_caster->GetModifierValue(unitMod, TOTAL_PCT);
4768 bonus = int32(bonus*weapon_total_pct);
4771 // + weapon damage with applied weapon% dmg to base weapon damage in call
4772 bonus += int32(m_caster->CalculateDamage(m_attackType, normalized)*weaponDamagePercentMod);
4774 // total damage
4775 bonus = int32(bonus*totalDamagePercentMod);
4777 // prevent negative damage
4778 m_damage+= uint32(bonus > 0 ? bonus : 0);
4780 // Hemorrhage
4781 if (m_spellInfo->SpellFamilyName==SPELLFAMILY_ROGUE && (m_spellInfo->SpellFamilyFlags & UI64LIT(0x2000000)))
4783 if(m_caster->GetTypeId()==TYPEID_PLAYER)
4784 ((Player*)m_caster)->AddComboPoints(unitTarget, 1);
4786 // Mangle (Cat): CP
4787 else if (m_spellInfo->SpellFamilyName==SPELLFAMILY_DRUID && (m_spellInfo->SpellFamilyFlags==UI64LIT(0x0000040000000000)))
4789 if(m_caster->GetTypeId()==TYPEID_PLAYER)
4790 ((Player*)m_caster)->AddComboPoints(unitTarget, 1);
4792 else if(m_spellInfo->SpellFamilyName==SPELLFAMILY_PALADIN)
4794 // Judgement of Blood/of the Martyr backlash damage (33%)
4795 if(m_spellInfo->SpellFamilyFlags & 0x0000000800000000LL && m_spellInfo->SpellIconID==153)
4797 int32 damagePoint = m_damage * 33 / 100;
4798 if(m_spellInfo->Id == 31898)
4799 m_caster->CastCustomSpell(m_caster, 32220, &damagePoint, NULL, NULL, true);
4800 else
4801 m_caster->CastCustomSpell(m_caster, 53725, &damagePoint, NULL, NULL, true);
4805 // take ammo
4806 if(m_attackType == RANGED_ATTACK && m_caster->GetTypeId() == TYPEID_PLAYER)
4808 Item *pItem = ((Player*)m_caster)->GetWeaponForAttack(RANGED_ATTACK, true, false);
4810 // wands don't have ammo
4811 if (!pItem || pItem->GetProto()->SubClass == ITEM_SUBCLASS_WEAPON_WAND)
4812 return;
4814 if (pItem->GetProto()->InventoryType == INVTYPE_THROWN)
4816 if(pItem->GetMaxStackCount()==1)
4818 // decrease durability for non-stackable throw weapon
4819 ((Player*)m_caster)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_RANGED);
4821 else
4823 // decrease items amount for stackable throw weapon
4824 uint32 count = 1;
4825 ((Player*)m_caster)->DestroyItemCount( pItem, count, true);
4828 else if(uint32 ammo = ((Player*)m_caster)->GetUInt32Value(PLAYER_AMMO_ID))
4829 ((Player*)m_caster)->DestroyItemCount(ammo, 1, true);
4833 void Spell::EffectThreat(uint32 /*i*/)
4835 if(!unitTarget || !unitTarget->isAlive() || !m_caster->isAlive())
4836 return;
4838 if(!unitTarget->CanHaveThreatList())
4839 return;
4841 unitTarget->AddThreat(m_caster, float(damage), false, GetSpellSchoolMask(m_spellInfo), m_spellInfo);
4844 void Spell::EffectHealMaxHealth(uint32 /*i*/)
4846 if(!unitTarget)
4847 return;
4848 if(!unitTarget->isAlive())
4849 return;
4851 uint32 heal = m_caster->GetMaxHealth();
4853 m_healing += heal;
4856 void Spell::EffectInterruptCast(uint32 /*i*/)
4858 if(!unitTarget)
4859 return;
4860 if(!unitTarget->isAlive())
4861 return;
4863 // TODO: not all spells that used this effect apply cooldown at school spells
4864 // also exist case: apply cooldown to interrupted cast only and to all spells
4865 for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
4867 if (Spell* spell = unitTarget->GetCurrentSpell(CurrentSpellTypes(i)))
4869 SpellEntry const* curSpellInfo = spell->m_spellInfo;
4870 // check if we can interrupt spell
4871 if ((curSpellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_INTERRUPT) && curSpellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE )
4873 unitTarget->ProhibitSpellScholl(GetSpellSchoolMask(curSpellInfo), GetSpellDuration(m_spellInfo));
4874 unitTarget->InterruptSpell(CurrentSpellTypes(i),false);
4880 void Spell::EffectSummonObjectWild(uint32 i)
4882 uint32 gameobject_id = m_spellInfo->EffectMiscValue[i];
4884 GameObject* pGameObj = new GameObject;
4886 WorldObject* target = focusObject;
4887 if( !target )
4888 target = m_caster;
4890 float x, y, z;
4891 if(m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
4893 x = m_targets.m_destX;
4894 y = m_targets.m_destY;
4895 z = m_targets.m_destZ;
4897 else
4898 m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE);
4900 Map *map = target->GetMap();
4902 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id, map,
4903 m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
4905 delete pGameObj;
4906 return;
4909 int32 duration = GetSpellDuration(m_spellInfo);
4911 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
4912 pGameObj->SetSpellId(m_spellInfo->Id);
4914 // Wild object not have owner and check clickable by players
4915 map->Add(pGameObj);
4917 if(pGameObj->GetGoType() == GAMEOBJECT_TYPE_FLAGDROP && m_caster->GetTypeId() == TYPEID_PLAYER)
4919 Player *pl = (Player*)m_caster;
4920 BattleGround* bg = ((Player *)m_caster)->GetBattleGround();
4922 switch(pGameObj->GetMapId())
4924 case 489: //WS
4926 if(bg && bg->GetTypeID()==BATTLEGROUND_WS && bg->GetStatus() == STATUS_IN_PROGRESS)
4928 uint32 team = ALLIANCE;
4930 if(pl->GetTeam() == team)
4931 team = HORDE;
4933 ((BattleGroundWS*)bg)->SetDroppedFlagGUID(pGameObj->GetGUID(),team);
4935 break;
4937 case 566: //EY
4939 if(bg && bg->GetTypeID()==BATTLEGROUND_EY && bg->GetStatus() == STATUS_IN_PROGRESS)
4941 ((BattleGroundEY*)bg)->SetDroppedFlagGUID(pGameObj->GetGUID());
4943 break;
4948 if(uint32 linkedEntry = pGameObj->GetGOInfo()->GetLinkedGameObjectEntry())
4950 GameObject* linkedGO = new GameObject;
4951 if(linkedGO->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, map,
4952 m_caster->GetPhaseMask(), x, y, z, target->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 100, GO_STATE_READY))
4954 linkedGO->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
4955 linkedGO->SetSpellId(m_spellInfo->Id);
4957 // Wild object not have owner and check clickable by players
4958 map->Add(linkedGO);
4960 else
4962 delete linkedGO;
4963 linkedGO = NULL;
4964 return;
4969 void Spell::EffectScriptEffect(uint32 effIndex)
4971 // TODO: we must implement hunter pet summon at login there (spell 6962)
4973 switch(m_spellInfo->SpellFamilyName)
4975 case SPELLFAMILY_GENERIC:
4977 switch(m_spellInfo->Id)
4979 // PX-238 Winter Wondervolt TRAP
4980 case 26275:
4982 uint32 spells[4] = { 26272, 26157, 26273, 26274 };
4984 // check presence
4985 for(int j = 0; j < 4; ++j)
4986 if(unitTarget->HasAura(spells[j],0))
4987 return;
4989 // select spell
4990 uint32 iTmpSpellId = spells[urand(0,3)];
4992 // cast
4993 unitTarget->CastSpell(unitTarget, iTmpSpellId, true);
4994 return;
4996 // Bending Shinbone
4997 case 8856:
4999 if(!itemTarget && m_caster->GetTypeId()!=TYPEID_PLAYER)
5000 return;
5002 uint32 spell_id = 0;
5003 switch(urand(1, 5))
5005 case 1: spell_id = 8854; break;
5006 default: spell_id = 8855; break;
5009 m_caster->CastSpell(m_caster,spell_id,true,NULL);
5010 return;
5012 // Brittle Armor - need remove one 24575 Brittle Armor aura
5013 case 24590:
5014 unitTarget->RemoveSingleSpellAurasFromStack(24575);
5015 return;
5016 // Mercurial Shield - need remove one 26464 Mercurial Shield aura
5017 case 26465:
5018 unitTarget->RemoveSingleSpellAurasFromStack(26464);
5019 return;
5020 // Orb teleport spells
5021 case 25140:
5022 case 25143:
5023 case 25650:
5024 case 25652:
5025 case 29128:
5026 case 29129:
5027 case 35376:
5028 case 35727:
5030 if(!unitTarget)
5031 return;
5033 uint32 spellid;
5034 switch(m_spellInfo->Id)
5036 case 25140: spellid = 32571; break;
5037 case 25143: spellid = 32572; break;
5038 case 25650: spellid = 30140; break;
5039 case 25652: spellid = 30141; break;
5040 case 29128: spellid = 32568; break;
5041 case 29129: spellid = 32569; break;
5042 case 35376: spellid = 25649; break;
5043 case 35727: spellid = 35730; break;
5044 default:
5045 return;
5048 unitTarget->CastSpell(unitTarget,spellid,false);
5049 return;
5051 // Shadow Flame (All script effects, not just end ones to prevent player from dodging the last triggered spell)
5052 case 22539:
5053 case 22972:
5054 case 22975:
5055 case 22976:
5056 case 22977:
5057 case 22978:
5058 case 22979:
5059 case 22980:
5060 case 22981:
5061 case 22982:
5062 case 22983:
5063 case 22984:
5064 case 22985:
5066 if(!unitTarget || !unitTarget->isAlive())
5067 return;
5069 // Onyxia Scale Cloak
5070 if(unitTarget->GetDummyAura(22683))
5071 return;
5073 // Shadow Flame
5074 m_caster->CastSpell(unitTarget, 22682, true);
5075 return;
5077 // Summon Black Qiraji Battle Tank
5078 case 26656:
5080 if(!unitTarget)
5081 return;
5083 // Prevent stacking of mounts
5084 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
5086 // Two separate mounts depending on area id (allows use both in and out of specific instance)
5087 if (unitTarget->GetAreaId() == 3428)
5088 unitTarget->CastSpell(unitTarget, 25863, false);
5089 else
5090 unitTarget->CastSpell(unitTarget, 26655, false);
5091 return;
5093 // Piccolo of the Flaming Fire
5094 case 17512:
5096 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5097 return;
5098 unitTarget->HandleEmoteCommand(EMOTE_STATE_DANCE);
5099 return;
5101 // Demonic Empowerment (succubus Vanish effect)
5102 case 54436:
5104 if(!unitTarget)
5105 return;
5107 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
5108 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
5109 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STALKED);
5110 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_STUN);
5111 return;
5113 // Escape artist
5114 case 20589:
5116 if(!unitTarget)
5117 return;
5119 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
5120 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOD_DECREASE_SPEED);
5121 return;
5123 // Mirren's Drinking Hat
5124 case 29830:
5126 uint32 item = 0;
5127 switch ( urand(1, 6) )
5129 case 1:
5130 case 2:
5131 case 3:
5132 item = 23584; break; // Loch Modan Lager
5133 case 4:
5134 case 5:
5135 item = 23585; break; // Stouthammer Lite
5136 case 6:
5137 item = 23586; break; // Aerie Peak Pale Ale
5139 if (item)
5140 DoCreateItem(effIndex,item);
5141 break;
5143 // Improved Sprint
5144 case 30918:
5146 if(!unitTarget)
5147 return;
5148 // Removes snares and roots.
5149 unitTarget->RemoveAurasAtMechanicImmunity(IMMUNE_TO_ROOT_AND_SNARE_MASK,30918,true);
5150 break;
5152 // Flame Crash
5153 case 41126:
5155 if(!unitTarget)
5156 return;
5158 unitTarget->CastSpell(unitTarget, 41131, true);
5159 break;
5161 // Force Cast - Portal Effect: Sunwell Isle
5162 case 44876:
5164 if(!unitTarget)
5165 return;
5167 unitTarget->CastSpell(unitTarget, 44870, true);
5168 break;
5170 // Goblin Weather Machine
5171 case 46203:
5173 if(!unitTarget)
5174 return;
5176 uint32 spellId = 0;
5177 switch(rand() % 4)
5179 case 0: spellId = 46740; break;
5180 case 1: spellId = 46739; break;
5181 case 2: spellId = 46738; break;
5182 case 3: spellId = 46736; break;
5184 unitTarget->CastSpell(unitTarget, spellId, true);
5185 break;
5187 //5,000 Gold
5188 case 46642:
5190 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5191 return;
5193 ((Player*)unitTarget)->ModifyMoney(50000000);
5195 break;
5197 // Emblazon Runeblade
5198 case 51770:
5200 if(!m_originalCaster)
5201 return;
5203 m_originalCaster->CastSpell(m_originalCaster, damage, false);
5204 break;
5206 // Death Gate
5207 case 52751:
5209 if(!unitTarget || unitTarget->getClass() != CLASS_DEATH_KNIGHT)
5210 return;
5211 // triggered spell is stored in m_spellInfo->EffectBasePoints[0]
5212 unitTarget->CastSpell(unitTarget, damage, false);
5213 break;
5215 // Winged Steed of the Ebon Blade
5216 case 54729:
5218 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5219 return;
5221 // Prevent stacking of mounts
5222 unitTarget->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
5224 // Triggered spell id dependent of riding skill
5225 if(uint16 skillval = ((Player*)unitTarget)->GetSkillValue(SKILL_RIDING))
5227 if (skillval >= 300)
5228 unitTarget->CastSpell(unitTarget, 54727, true);
5229 else
5230 unitTarget->CastSpell(unitTarget, 54726, true);
5232 return;
5234 case 55693: // Remove Collapsing Cave Aura
5235 if(!unitTarget)
5236 return;
5237 unitTarget->RemoveAurasDueToSpell(m_spellInfo->CalculateSimpleValue(effIndex));
5238 break;
5239 case 58418: // Portal to Orgrimmar
5240 case 58420: // Portal to Stormwind
5242 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER || effIndex!=0)
5243 return;
5245 uint32 spellID = m_spellInfo->CalculateSimpleValue(0);
5246 uint32 questID = m_spellInfo->CalculateSimpleValue(1);
5248 if (((Player*)unitTarget)->GetQuestStatus(questID) == QUEST_STATUS_COMPLETE && !((Player*)unitTarget)->GetQuestRewardStatus (questID))
5249 unitTarget->CastSpell(unitTarget, spellID, true);
5251 return;
5253 case 59317: // Teleporting
5254 if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5255 return;
5257 // return from top
5258 if (((Player*)unitTarget)->GetAreaId() == 4637)
5259 unitTarget->CastSpell(unitTarget, 59316, true);
5260 // teleport atop
5261 else
5262 unitTarget->CastSpell(unitTarget, 59314, true);
5264 return;
5265 // random spell learn instead placeholder
5266 case 60893: // Northrend Alchemy Research
5267 case 61177: // Northrend Inscription Research
5268 case 61288: // Minor Inscription Research
5269 case 61756: // Northrend Inscription Research (FAST QA VERSION)
5270 case 64323: // Book of Glyph Mastery
5272 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5273 return;
5275 // learn random explicit discovery recipe (if any)
5276 if(uint32 discoveredSpell = GetExplicitDiscoverySpell(m_spellInfo->Id, (Player*)m_caster))
5277 ((Player*)m_caster)->learnSpell(discoveredSpell, false);
5278 return;
5281 break;
5283 case SPELLFAMILY_WARLOCK:
5285 switch(m_spellInfo->Id)
5287 // Healthstone creating spells
5288 case 6201:
5289 case 6202:
5290 case 5699:
5291 case 11729:
5292 case 11730:
5293 case 27230:
5294 case 47871:
5295 case 47878:
5297 if(!unitTarget)
5298 return;
5299 uint32 itemtype;
5300 uint32 rank = 0;
5301 Unit::AuraList const& mDummyAuras = unitTarget->GetAurasByType(SPELL_AURA_DUMMY);
5302 for(Unit::AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i)
5304 if((*i)->GetId() == 18692)
5306 rank = 1;
5307 break;
5309 else if((*i)->GetId() == 18693)
5311 rank = 2;
5312 break;
5316 static uint32 const itypes[8][3] = {
5317 { 5512, 19004, 19005}, // Minor Healthstone
5318 { 5511, 19006, 19007}, // Lesser Healthstone
5319 { 5509, 19008, 19009}, // Healthstone
5320 { 5510, 19010, 19011}, // Greater Healthstone
5321 { 9421, 19012, 19013}, // Major Healthstone
5322 {22103, 22104, 22105}, // Master Healthstone
5323 {36889, 36890, 36891}, // Demonic Healthstone
5324 {36892, 36893, 36894} // Fel Healthstone
5327 switch(m_spellInfo->Id)
5329 case 6201:
5330 itemtype=itypes[0][rank];break; // Minor Healthstone
5331 case 6202:
5332 itemtype=itypes[1][rank];break; // Lesser Healthstone
5333 case 5699:
5334 itemtype=itypes[2][rank];break; // Healthstone
5335 case 11729:
5336 itemtype=itypes[3][rank];break; // Greater Healthstone
5337 case 11730:
5338 itemtype=itypes[4][rank];break; // Major Healthstone
5339 case 27230:
5340 itemtype=itypes[5][rank];break; // Master Healthstone
5341 case 47871:
5342 itemtype=itypes[6][rank];break; // Demonic Healthstone
5343 case 47878:
5344 itemtype=itypes[7][rank];break; // Fel Healthstone
5345 default:
5346 return;
5348 DoCreateItem( effIndex, itemtype );
5349 return;
5351 // Demonic Empowerment
5352 case 47193:
5354 if(!unitTarget)
5355 return;
5356 uint32 entry = unitTarget->GetEntry();
5357 uint32 spellID;
5358 switch(entry)
5360 case 416: spellID = 54444; break; //imp
5361 case 417: spellID = 54509; break; //fellhunter
5362 case 1860: spellID = 54443; break; //void
5363 case 1863: spellID = 54435; break; //succubus
5364 case 17252: spellID = 54508; break; //fellguard
5365 default:
5366 return;
5368 unitTarget->CastSpell(unitTarget,spellID,true);
5369 return;
5371 // Everlasting Affliction
5372 case 47422:
5374 // Need refresh caster corruption auras on target
5375 Unit::AuraMap& suAuras = unitTarget->GetAuras();
5376 for(Unit::AuraMap::iterator itr = suAuras.begin(); itr != suAuras.end(); ++itr)
5378 SpellEntry const *spellInfo = (*itr).second->GetSpellProto();
5379 if(spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK &&
5380 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000000002)) &&
5381 (*itr).second->GetCasterGUID()==m_caster->GetGUID())
5382 (*itr).second->RefreshAura();
5384 return;
5386 // Guarded by The Light (Paladin spell with SPELLFAMILY_WARLOCK)
5387 case 63521:
5389 // Divine Plea, refresh on target (3 aura slots)
5390 if (Aura* aura = unitTarget->GetAura(54428,0))
5391 aura->RefreshAura();
5392 return;
5395 break;
5397 case SPELLFAMILY_PRIEST:
5399 switch(m_spellInfo->Id)
5401 // Pain and Suffering
5402 case 47948:
5404 if (!unitTarget)
5405 return;
5406 // Refresh Shadow Word: Pain on target
5407 Unit::AuraMap& auras = unitTarget->GetAuras();
5408 for(Unit::AuraMap::iterator itr = auras.begin(); itr != auras.end(); ++itr)
5410 SpellEntry const *spellInfo = (*itr).second->GetSpellProto();
5411 if (spellInfo->SpellFamilyName == SPELLFAMILY_PRIEST &&
5412 (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000008000)) &&
5413 (*itr).second->GetCasterGUID() == m_caster->GetGUID())
5415 (*itr).second->RefreshAura();
5416 return;
5419 return;
5421 default:
5422 break;
5424 break;
5426 case SPELLFAMILY_HUNTER:
5428 switch(m_spellInfo->Id)
5430 // Chimera Shot
5431 case 53209:
5433 if(!unitTarget)
5434 return;
5435 uint32 spellId = 0;
5436 int32 basePoint = 0;
5437 Unit* target = unitTarget;
5438 Unit::AuraMap& Auras = unitTarget->GetAuras();
5439 for(Unit::AuraMap::iterator i = Auras.begin(); i != Auras.end(); ++i)
5441 Aura *aura = (*i).second;
5442 if (aura->GetCasterGUID() != m_caster->GetGUID())
5443 continue;
5444 // Search only Serpent Sting, Viper Sting, Scorpid Sting auras
5445 uint64 familyFlag = aura->GetSpellProto()->SpellFamilyFlags;
5446 if (!(familyFlag & UI64LIT(0x000000800000C000)))
5447 continue;
5448 // Refresh aura duration
5449 aura->RefreshAura();
5451 // Serpent Sting - Instantly deals 40% of the damage done by your Serpent Sting.
5452 if ((familyFlag & UI64LIT(0x0000000000004000)) && aura->GetEffIndex() == 0)
5454 // m_amount already include RAP bonus
5455 basePoint = aura->GetModifier()->m_amount * 5 * 40 / 100;
5456 spellId = 53353; // Chimera Shot - Serpent
5458 // Viper Sting - Instantly restores mana to you equal to 60% of the total amount drained by your Viper Sting.
5459 if ((familyFlag & UI64LIT(0x0000008000000000)) && aura->GetEffIndex() == 0)
5461 uint32 target_max_mana = unitTarget->GetMaxPower(POWER_MANA);
5462 if (!target_max_mana)
5463 continue;
5465 // ignore non positive values (can be result apply spellmods to aura damage
5466 uint32 pdamage = aura->GetModifier()->m_amount > 0 ? aura->GetModifier()->m_amount : 0;
5468 // Special case: draining x% of mana (up to a maximum of 2*x% of the caster's maximum mana)
5469 uint32 maxmana = m_caster->GetMaxPower(POWER_MANA) * pdamage * 2 / 100;
5471 pdamage = target_max_mana * pdamage / 100;
5472 if (pdamage > maxmana)
5473 pdamage = maxmana;
5475 pdamage *= 4; // total aura damage
5476 basePoint = pdamage * 60 / 100;
5477 spellId = 53358; // Chimera Shot - Viper
5478 target = m_caster;
5480 // Scorpid Sting - Attempts to Disarm the target for 10 sec. This effect cannot occur more than once per 1 minute.
5481 if (familyFlag & UI64LIT(0x0000000000008000))
5482 spellId = 53359; // Chimera Shot - Scorpid
5483 // ?? nothing say in spell desc (possibly need addition check)
5484 //if ((familyFlag & UI64LIT(0x0000010000000000)) || // dot
5485 // (familyFlag & UI64LIT(0x0000100000000000))) // stun
5487 // spellId = 53366; // 53366 Chimera Shot - Wyvern
5490 if (spellId)
5491 m_caster->CastCustomSpell(target, spellId, &basePoint, 0, 0, false);
5492 return;
5494 case 53412: // Invigoration (pet triggered script, master targeted)
5496 if (!unitTarget)
5497 return;
5499 Unit::AuraList const& auras = unitTarget->GetAurasByType(SPELL_AURA_DUMMY);
5500 for(Unit::AuraList::const_iterator i = auras.begin();i != auras.end(); ++i)
5502 // Invigoration (master talent)
5503 if ((*i)->GetModifier()->m_miscvalue == 8 && (*i)->GetSpellProto()->SpellIconID == 3487)
5505 if (roll_chance_i((*i)->GetModifier()->m_amount))
5507 unitTarget->CastSpell(unitTarget, 53398, true, NULL, (*i), m_caster->GetGUID());
5508 break;
5512 return;
5514 // Master's Call
5515 case 53271:
5517 if (!unitTarget)
5518 return;
5520 // script effect have in value, but this outdated removed part
5521 unitTarget->CastSpell(unitTarget, 62305, true);
5522 return;
5524 default:
5525 break;
5527 break;
5529 case SPELLFAMILY_PALADIN:
5531 // Judgement (seal trigger)
5532 if (m_spellInfo->Category == SPELLCATEGORY_JUDGEMENT)
5534 if(!unitTarget || !unitTarget->isAlive())
5535 return;
5536 uint32 spellId1 = 0;
5537 uint32 spellId2 = 0;
5539 // Judgement self add switch
5540 switch (m_spellInfo->Id)
5542 case 53407: spellId1 = 20184; break; // Judgement of Justice
5543 case 20271: // Judgement of Light
5544 case 57774: spellId1 = 20185; break; // Judgement of Light
5545 case 53408: spellId1 = 20186; break; // Judgement of Wisdom
5546 default:
5547 sLog.outError("Unsupported Judgement (seal trigger) spell (Id: %u) in Spell::EffectScriptEffect",m_spellInfo->Id);
5548 return;
5550 // offensive seals have aura dummy in 2 effect
5551 Unit::AuraList const& m_dummyAuras = m_caster->GetAurasByType(SPELL_AURA_DUMMY);
5552 for(Unit::AuraList::const_iterator itr = m_dummyAuras.begin(); itr != m_dummyAuras.end(); ++itr)
5554 // search seal (offensive seals have judgement's aura dummy spell id in 2 effect
5555 if ((*itr)->GetEffIndex() != 2 || !IsSealSpell((*itr)->GetSpellProto()))
5556 continue;
5557 spellId2 = (*itr)->GetModifier()->m_amount;
5558 SpellEntry const *judge = sSpellStore.LookupEntry(spellId2);
5559 if (!judge)
5560 continue;
5561 break;
5563 // if there were no offensive seals than there is seal with proc trigger aura
5564 if (!spellId2)
5566 Unit::AuraList const& procTriggerAuras = m_caster->GetAurasByType(SPELL_AURA_PROC_TRIGGER_SPELL);
5567 for(Unit::AuraList::const_iterator itr = procTriggerAuras.begin(); itr != procTriggerAuras.end(); ++itr)
5569 if ((*itr)->GetEffIndex() != 0 || !IsSealSpell((*itr)->GetSpellProto()))
5570 continue;
5571 spellId2 = 54158;
5572 break;
5575 if (spellId1)
5576 m_caster->CastSpell(unitTarget, spellId1, true);
5577 if (spellId2)
5578 m_caster->CastSpell(unitTarget, spellId2, true);
5579 return;
5582 case SPELLFAMILY_POTION:
5584 switch(m_spellInfo->Id)
5586 // Dreaming Glory
5587 case 28698:
5589 if(!unitTarget)
5590 return;
5591 unitTarget->CastSpell(unitTarget, 28694, true);
5592 break;
5594 // Netherbloom
5595 case 28702:
5597 if(!unitTarget)
5598 return;
5599 // 25% chance of casting a random buff
5600 if(roll_chance_i(75))
5601 return;
5603 // triggered spells are 28703 to 28707
5604 // Note: some sources say, that there was the possibility of
5605 // receiving a debuff. However, this seems to be removed by a patch.
5606 const uint32 spellid = 28703;
5608 // don't overwrite an existing aura
5609 for(uint8 i = 0; i < 5; ++i)
5610 if(unitTarget->HasAura(spellid + i, 0))
5611 return;
5612 unitTarget->CastSpell(unitTarget, spellid+urand(0, 4), true);
5613 break;
5616 // Nightmare Vine
5617 case 28720:
5619 if(!unitTarget)
5620 return;
5621 // 25% chance of casting Nightmare Pollen
5622 if(roll_chance_i(75))
5623 return;
5624 unitTarget->CastSpell(unitTarget, 28721, true);
5625 break;
5628 break;
5630 case SPELLFAMILY_DEATHKNIGHT:
5632 switch(m_spellInfo->Id)
5634 // Pestilence
5635 case 50842:
5637 if(!unitTarget)
5638 return;
5640 Unit* mainTarget = m_targets.getUnitTarget();
5641 if(!mainTarget)
5642 return;
5644 // do only refresh diseases on main target if caster has Glyph of Disease
5645 if(mainTarget == unitTarget && !m_caster->HasAura(63334))
5646 return;
5648 // Blood Plague
5649 if(mainTarget->HasAura(55078))
5650 m_caster->CastSpell(unitTarget, 55078, true);
5652 // Frost Fever
5653 if(mainTarget->HasAura(55095))
5654 m_caster->CastSpell(unitTarget, 55095, true);
5656 break;
5659 break;
5663 // normal DB scripted effect
5664 if(!unitTarget)
5665 return;
5667 sLog.outDebug("Spell ScriptStart spellid %u in EffectScriptEffect ", m_spellInfo->Id);
5668 m_caster->GetMap()->ScriptsStart(sSpellScripts, m_spellInfo->Id, m_caster, unitTarget);
5671 void Spell::EffectSanctuary(uint32 /*i*/)
5673 if(!unitTarget)
5674 return;
5675 //unitTarget->CombatStop();
5677 unitTarget->CombatStop();
5678 unitTarget->getHostileRefManager().deleteReferences(); // stop all fighting
5679 // Vanish allows to remove all threat and cast regular stealth so other spells can be used
5680 if(m_spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE && (m_spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE_VANISH))
5682 ((Player *)m_caster)->RemoveSpellsCausingAura(SPELL_AURA_MOD_ROOT);
5686 void Spell::EffectAddComboPoints(uint32 /*i*/)
5688 if(!unitTarget)
5689 return;
5691 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5692 return;
5694 if(damage <= 0)
5695 return;
5697 ((Player*)m_caster)->AddComboPoints(unitTarget, damage);
5700 void Spell::EffectDuel(uint32 i)
5702 if(!m_caster || !unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER || unitTarget->GetTypeId() != TYPEID_PLAYER)
5703 return;
5705 Player *caster = (Player*)m_caster;
5706 Player *target = (Player*)unitTarget;
5708 // caster or target already have requested duel
5709 if( caster->duel || target->duel || !target->GetSocial() || target->GetSocial()->HasIgnore(caster->GetGUIDLow()) )
5710 return;
5712 // Players can only fight a duel with each other outside (=not inside dungeons and not in capital cities)
5713 // Don't have to check the target's map since you cannot challenge someone across maps
5714 uint32 mapid = caster->GetMapId();
5715 if( mapid != 0 && mapid != 1 && mapid != 530 && mapid != 571 && mapid != 609)
5717 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5718 return;
5721 AreaTableEntry const* casterAreaEntry = GetAreaEntryByAreaID(caster->GetZoneId());
5722 if(casterAreaEntry && (casterAreaEntry->flags & AREA_FLAG_CAPITAL) )
5724 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5725 return;
5728 AreaTableEntry const* targetAreaEntry = GetAreaEntryByAreaID(target->GetZoneId());
5729 if(targetAreaEntry && (targetAreaEntry->flags & AREA_FLAG_CAPITAL) )
5731 SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here
5732 return;
5735 //CREATE DUEL FLAG OBJECT
5736 GameObject* pGameObj = new GameObject;
5738 uint32 gameobject_id = m_spellInfo->EffectMiscValue[i];
5740 Map *map = m_caster->GetMap();
5741 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), gameobject_id,
5742 map, m_caster->GetPhaseMask(),
5743 m_caster->GetPositionX()+(unitTarget->GetPositionX()-m_caster->GetPositionX())/2 ,
5744 m_caster->GetPositionY()+(unitTarget->GetPositionY()-m_caster->GetPositionY())/2 ,
5745 m_caster->GetPositionZ(),
5746 m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
5748 delete pGameObj;
5749 return;
5752 pGameObj->SetUInt32Value(GAMEOBJECT_FACTION, m_caster->getFaction() );
5753 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL, m_caster->getLevel()+1 );
5754 int32 duration = GetSpellDuration(m_spellInfo);
5755 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
5756 pGameObj->SetSpellId(m_spellInfo->Id);
5758 m_caster->AddGameObject(pGameObj);
5759 map->Add(pGameObj);
5760 //END
5762 // Send request
5763 WorldPacket data(SMSG_DUEL_REQUESTED, 8 + 8);
5764 data << uint64(pGameObj->GetGUID());
5765 data << uint64(caster->GetGUID());
5766 caster->GetSession()->SendPacket(&data);
5767 target->GetSession()->SendPacket(&data);
5769 // create duel-info
5770 DuelInfo *duel = new DuelInfo;
5771 duel->initiator = caster;
5772 duel->opponent = target;
5773 duel->startTime = 0;
5774 duel->startTimer = 0;
5775 caster->duel = duel;
5777 DuelInfo *duel2 = new DuelInfo;
5778 duel2->initiator = caster;
5779 duel2->opponent = caster;
5780 duel2->startTime = 0;
5781 duel2->startTimer = 0;
5782 target->duel = duel2;
5784 caster->SetUInt64Value(PLAYER_DUEL_ARBITER, pGameObj->GetGUID());
5785 target->SetUInt64Value(PLAYER_DUEL_ARBITER, pGameObj->GetGUID());
5788 void Spell::EffectStuck(uint32 /*i*/)
5790 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5791 return;
5793 if(!sWorld.getConfig(CONFIG_CAST_UNSTUCK))
5794 return;
5796 Player* pTarget = (Player*)unitTarget;
5798 sLog.outDebug("Spell Effect: Stuck");
5799 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());
5801 if(pTarget->isInFlight())
5802 return;
5804 // homebind location is loaded always
5805 pTarget->TeleportToHomebind(unitTarget==m_caster ? TELE_TO_SPELL : 0);
5807 // Stuck spell trigger Hearthstone cooldown
5808 SpellEntry const *spellInfo = sSpellStore.LookupEntry(8690);
5809 if(!spellInfo)
5810 return;
5811 Spell spell(pTarget, spellInfo, true, 0);
5812 spell.SendSpellCooldown();
5815 void Spell::EffectSummonPlayer(uint32 /*i*/)
5817 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5818 return;
5820 // Evil Twin (ignore player summon, but hide this for summoner)
5821 if(unitTarget->GetDummyAura(23445))
5822 return;
5824 float x, y, z;
5825 m_caster->GetClosePoint(x, y, z, unitTarget->GetObjectSize());
5827 ((Player*)unitTarget)->SetSummonPoint(m_caster->GetMapId(),x,y,z);
5829 WorldPacket data(SMSG_SUMMON_REQUEST, 8+4+4);
5830 data << uint64(m_caster->GetGUID()); // summoner guid
5831 data << uint32(m_caster->GetZoneId()); // summoner zone
5832 data << uint32(MAX_PLAYER_SUMMON_DELAY*IN_MILISECONDS); // auto decline after msecs
5833 ((Player*)unitTarget)->GetSession()->SendPacket(&data);
5836 static ScriptInfo generateActivateCommand()
5838 ScriptInfo si;
5839 si.command = SCRIPT_COMMAND_ACTIVATE_OBJECT;
5840 return si;
5843 void Spell::EffectActivateObject(uint32 effect_idx)
5845 if(!gameObjTarget)
5846 return;
5848 static ScriptInfo activateCommand = generateActivateCommand();
5850 int32 delay_secs = m_spellInfo->EffectMiscValue[effect_idx];
5852 gameObjTarget->GetMap()->ScriptCommandStart(activateCommand, delay_secs, m_caster, gameObjTarget);
5855 void Spell::EffectApplyGlyph(uint32 i)
5857 if(m_caster->GetTypeId() != TYPEID_PLAYER)
5858 return;
5860 Player *player = (Player*)m_caster;
5862 // apply new one
5863 if(uint32 glyph = m_spellInfo->EffectMiscValue[i])
5865 if(GlyphPropertiesEntry const *gp = sGlyphPropertiesStore.LookupEntry(glyph))
5867 if(GlyphSlotEntry const *gs = sGlyphSlotStore.LookupEntry(player->GetGlyphSlot(m_glyphIndex)))
5869 if(gp->TypeFlags != gs->TypeFlags)
5871 SendCastResult(SPELL_FAILED_INVALID_GLYPH);
5872 return; // glyph slot mismatch
5876 // remove old glyph
5877 if(uint32 oldglyph = player->GetGlyph(m_glyphIndex))
5879 if(GlyphPropertiesEntry const *old_gp = sGlyphPropertiesStore.LookupEntry(oldglyph))
5881 player->RemoveAurasDueToSpell(old_gp->SpellId);
5882 player->SetGlyph(m_glyphIndex, 0);
5886 player->CastSpell(m_caster, gp->SpellId, true);
5887 player->SetGlyph(m_glyphIndex, glyph);
5888 player->SendTalentsInfoData(false);
5893 void Spell::EffectSummonTotem(uint32 i, uint8 slot)
5895 slot = slot ? (slot - 1): 255;
5897 if(slot < MAX_TOTEM)
5899 uint64 guid = m_caster->m_TotemSlot[slot];
5900 if(guid != 0)
5902 Creature *OldTotem = m_caster->GetMap()->GetCreature(guid);
5903 if(OldTotem && OldTotem->isTotem())
5904 ((Totem*)OldTotem)->UnSummon();
5908 uint32 team = 0;
5909 if (m_caster->GetTypeId()==TYPEID_PLAYER)
5910 team = ((Player*)m_caster)->GetTeam();
5912 Totem* pTotem = new Totem;
5914 if(!pTotem->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), m_caster->GetMap(), m_caster->GetPhaseMask(),
5915 m_spellInfo->EffectMiscValue[i], team ))
5917 delete pTotem;
5918 return;
5921 float angle = slot < MAX_TOTEM ? M_PI/MAX_TOTEM - (slot*2*M_PI/MAX_TOTEM) : 0;
5923 float x, y, z;
5924 m_caster->GetClosePoint(x, y, z, pTotem->GetObjectSize(), 2.0f, angle);
5926 // totem must be at same Z in case swimming caster and etc.
5927 if( fabs( z - m_caster->GetPositionZ() ) > 5 )
5928 z = m_caster->GetPositionZ();
5930 pTotem->Relocate(x, y, z, m_caster->GetOrientation());
5932 if(slot < MAX_TOTEM)
5933 m_caster->m_TotemSlot[slot] = pTotem->GetGUID();
5935 pTotem->SetOwner(m_caster->GetGUID());
5936 pTotem->SetTypeBySummonSpell(m_spellInfo); // must be after Create call where m_spells initilized
5938 int32 duration=GetSpellDuration(m_spellInfo);
5939 if(Player* modOwner = m_caster->GetSpellModOwner())
5940 modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_DURATION, duration);
5941 pTotem->SetDuration(duration);
5943 if (damage) // if not spell info, DB values used
5945 pTotem->SetMaxHealth(damage);
5946 pTotem->SetHealth(damage);
5949 pTotem->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
5951 if(m_caster->GetTypeId() == TYPEID_PLAYER)
5952 pTotem->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
5954 if(m_caster->IsPvP())
5955 pTotem->SetPvP(true);
5957 pTotem->Summon(m_caster);
5959 if(slot < MAX_TOTEM && m_caster->GetTypeId() == TYPEID_PLAYER)
5961 WorldPacket data(SMSG_TOTEM_CREATED, 1 + 8 + 4 + 4);
5962 data << uint8(slot);
5963 data << uint64(pTotem->GetGUID());
5964 data << uint32(duration);
5965 data << uint32(m_spellInfo->Id);
5966 ((Player*)m_caster)->SendDirectMessage(&data);
5970 void Spell::EffectEnchantHeldItem(uint32 i)
5972 // this is only item spell effect applied to main-hand weapon of target player (players in area)
5973 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
5974 return;
5976 Player* item_owner = (Player*)unitTarget;
5977 Item* item = item_owner->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
5979 if(!item )
5980 return;
5982 // must be equipped
5983 if(!item ->IsEquipped())
5984 return;
5986 if (m_spellInfo->EffectMiscValue[i])
5988 uint32 enchant_id = m_spellInfo->EffectMiscValue[i];
5989 int32 duration = GetSpellDuration(m_spellInfo); //Try duration index first ..
5990 if(!duration)
5991 duration = m_currentBasePoints[i]+1; //Base points after ..
5992 if(!duration)
5993 duration = 10; //10 seconds for enchants which don't have listed duration
5995 SpellItemEnchantmentEntry const *pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
5996 if(!pEnchant)
5997 return;
5999 // Always go to temp enchantment slot
6000 EnchantmentSlot slot = TEMP_ENCHANTMENT_SLOT;
6002 // Enchantment will not be applied if a different one already exists
6003 if(item->GetEnchantmentId(slot) && item->GetEnchantmentId(slot) != enchant_id)
6004 return;
6006 // Apply the temporary enchantment
6007 item->SetEnchantment(slot, enchant_id, duration*IN_MILISECONDS, 0);
6008 item_owner->ApplyEnchantment(item, slot, true);
6012 void Spell::EffectDisEnchant(uint32 /*i*/)
6014 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6015 return;
6017 Player* p_caster = (Player*)m_caster;
6018 if(!itemTarget || !itemTarget->GetProto()->DisenchantID)
6019 return;
6021 p_caster->UpdateCraftSkill(m_spellInfo->Id);
6023 ((Player*)m_caster)->SendLoot(itemTarget->GetGUID(),LOOT_DISENCHANTING);
6025 // item will be removed at disenchanting end
6028 void Spell::EffectInebriate(uint32 /*i*/)
6030 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6031 return;
6033 Player *player = (Player*)unitTarget;
6034 uint16 currentDrunk = player->GetDrunkValue();
6035 uint16 drunkMod = damage * 256;
6036 if (currentDrunk + drunkMod > 0xFFFF)
6037 currentDrunk = 0xFFFF;
6038 else
6039 currentDrunk += drunkMod;
6040 player->SetDrunkValue(currentDrunk, m_CastItem ? m_CastItem->GetEntry() : 0);
6043 void Spell::EffectFeedPet(uint32 i)
6045 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6046 return;
6048 Player *_player = (Player*)m_caster;
6050 Item* foodItem = m_targets.getItemTarget();
6051 if(!foodItem)
6052 return;
6054 Pet *pet = _player->GetPet();
6055 if(!pet)
6056 return;
6058 if(!pet->isAlive())
6059 return;
6061 int32 benefit = pet->GetCurrentFoodBenefitLevel(foodItem->GetProto()->ItemLevel);
6062 if(benefit <= 0)
6063 return;
6065 uint32 count = 1;
6066 _player->DestroyItemCount(foodItem,count,true);
6067 // TODO: fix crash when a spell has two effects, both pointed at the same item target
6069 m_caster->CastCustomSpell(pet, m_spellInfo->EffectTriggerSpell[i], &benefit, NULL, NULL, true);
6072 void Spell::EffectDismissPet(uint32 /*i*/)
6074 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6075 return;
6077 Pet* pet = m_caster->GetPet();
6079 // not let dismiss dead pet
6080 if(!pet||!pet->isAlive())
6081 return;
6083 ((Player*)m_caster)->RemovePet(pet, PET_SAVE_NOT_IN_SLOT);
6086 void Spell::EffectSummonObject(uint32 i)
6088 uint32 go_id = m_spellInfo->EffectMiscValue[i];
6090 uint8 slot = 0;
6091 switch(m_spellInfo->Effect[i])
6093 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1: slot = 0; break;
6094 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2: slot = 1; break;
6095 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3: slot = 2; break;
6096 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4: slot = 3; break;
6097 default: return;
6100 if(uint64 guid = m_caster->m_ObjectSlot[slot])
6102 if(GameObject* obj = m_caster ? m_caster->GetMap()->GetGameObject(guid) : NULL)
6103 obj->SetLootState(GO_JUST_DEACTIVATED);
6104 m_caster->m_ObjectSlot[slot] = 0;
6107 GameObject* pGameObj = new GameObject;
6109 float x, y, z;
6110 // If dest location if present
6111 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6113 x = m_targets.m_destX;
6114 y = m_targets.m_destY;
6115 z = m_targets.m_destZ;
6117 // Summon in random point all other units if location present
6118 else
6119 m_caster->GetClosePoint(x, y, z, DEFAULT_WORLD_OBJECT_SIZE);
6121 Map *map = m_caster->GetMap();
6122 if(!pGameObj->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), go_id, map,
6123 m_caster->GetPhaseMask(), x, y, z, m_caster->GetOrientation(), 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
6125 delete pGameObj;
6126 return;
6129 pGameObj->SetUInt32Value(GAMEOBJECT_LEVEL,m_caster->getLevel());
6130 int32 duration = GetSpellDuration(m_spellInfo);
6131 pGameObj->SetRespawnTime(duration > 0 ? duration/IN_MILISECONDS : 0);
6132 pGameObj->SetSpellId(m_spellInfo->Id);
6133 m_caster->AddGameObject(pGameObj);
6135 map->Add(pGameObj);
6137 m_caster->m_ObjectSlot[slot] = pGameObj->GetGUID();
6140 void Spell::EffectResurrect(uint32 /*effIndex*/)
6142 if(!unitTarget)
6143 return;
6144 if(unitTarget->GetTypeId() != TYPEID_PLAYER)
6145 return;
6147 if(unitTarget->isAlive())
6148 return;
6149 if(!unitTarget->IsInWorld())
6150 return;
6152 switch (m_spellInfo->Id)
6154 // Defibrillate (Goblin Jumper Cables) have 33% chance on success
6155 case 8342:
6156 if (roll_chance_i(67))
6158 m_caster->CastSpell(m_caster, 8338, true, m_CastItem);
6159 return;
6161 break;
6162 // Defibrillate (Goblin Jumper Cables XL) have 50% chance on success
6163 case 22999:
6164 if (roll_chance_i(50))
6166 m_caster->CastSpell(m_caster, 23055, true, m_CastItem);
6167 return;
6169 break;
6170 default:
6171 break;
6174 Player* pTarget = ((Player*)unitTarget);
6176 if(pTarget->isRessurectRequested()) // already have one active request
6177 return;
6179 uint32 health = pTarget->GetMaxHealth() * damage / 100;
6180 uint32 mana = pTarget->GetMaxPower(POWER_MANA) * damage / 100;
6182 pTarget->setResurrectRequestData(m_caster->GetGUID(), m_caster->GetMapId(), m_caster->GetPositionX(), m_caster->GetPositionY(), m_caster->GetPositionZ(), health, mana);
6183 SendResurrectRequest(pTarget);
6186 void Spell::EffectAddExtraAttacks(uint32 /*i*/)
6188 if(!unitTarget || !unitTarget->isAlive())
6189 return;
6191 if( unitTarget->m_extraAttacks )
6192 return;
6194 unitTarget->m_extraAttacks = damage;
6197 void Spell::EffectParry(uint32 /*i*/)
6199 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6200 ((Player*)unitTarget)->SetCanParry(true);
6203 void Spell::EffectBlock(uint32 /*i*/)
6205 if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER)
6206 ((Player*)unitTarget)->SetCanBlock(true);
6209 void Spell::EffectLeapForward(uint32 i)
6211 if(unitTarget->isInFlight())
6212 return;
6214 if( m_spellInfo->rangeIndex == 1) //self range
6216 float dis = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i]));
6218 // before caster
6219 float fx, fy, fz;
6220 unitTarget->GetClosePoint(fx, fy, fz, unitTarget->GetObjectSize(), dis);
6221 float ox, oy, oz;
6222 unitTarget->GetPosition(ox, oy, oz);
6224 float fx2, fy2, fz2; // getObjectHitPos overwrite last args in any result case
6225 if(VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(unitTarget->GetMapId(), ox,oy,oz+0.5, fx,fy,oz+0.5,fx2,fy2,fz2, -0.5))
6227 fx = fx2;
6228 fy = fy2;
6229 fz = fz2;
6230 unitTarget->UpdateGroundPositionZ(fx, fy, fz);
6233 unitTarget->NearTeleportTo(fx, fy, fz, unitTarget->GetOrientation(), unitTarget == m_caster);
6237 void Spell::EffectLeapBack(uint32 i)
6239 if(unitTarget->isInFlight())
6240 return;
6242 m_caster->KnockBackFrom(unitTarget,float(m_spellInfo->EffectMiscValue[i])/10,float(damage)/10);
6245 void Spell::EffectReputation(uint32 i)
6247 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6248 return;
6250 Player *_player = (Player*)unitTarget;
6252 int32 rep_change = m_currentBasePoints[i]+1; // field store reputation change -1
6254 uint32 faction_id = m_spellInfo->EffectMiscValue[i];
6256 FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id);
6258 if(!factionEntry)
6259 return;
6261 _player->GetReputationMgr().ModifyReputation(factionEntry, rep_change);
6264 void Spell::EffectQuestComplete(uint32 i)
6266 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6267 return;
6269 Player *_player = (Player*)m_caster;
6271 uint32 quest_id = m_spellInfo->EffectMiscValue[i];
6272 _player->AreaExploredOrEventHappens(quest_id);
6275 void Spell::EffectSelfResurrect(uint32 i)
6277 if(!unitTarget || unitTarget->isAlive())
6278 return;
6279 if(unitTarget->GetTypeId() != TYPEID_PLAYER)
6280 return;
6281 if(!unitTarget->IsInWorld())
6282 return;
6284 uint32 health = 0;
6285 uint32 mana = 0;
6287 // flat case
6288 if(damage < 0)
6290 health = uint32(-damage);
6291 mana = m_spellInfo->EffectMiscValue[i];
6293 // percent case
6294 else
6296 health = uint32(damage/100.0f*unitTarget->GetMaxHealth());
6297 if(unitTarget->GetMaxPower(POWER_MANA) > 0)
6298 mana = uint32(damage/100.0f*unitTarget->GetMaxPower(POWER_MANA));
6301 Player *plr = ((Player*)unitTarget);
6302 plr->ResurrectPlayer(0.0f);
6304 plr->SetHealth( health );
6305 plr->SetPower(POWER_MANA, mana );
6306 plr->SetPower(POWER_RAGE, 0 );
6307 plr->SetPower(POWER_ENERGY, plr->GetMaxPower(POWER_ENERGY) );
6309 plr->SpawnCorpseBones();
6312 void Spell::EffectSkinning(uint32 /*i*/)
6314 if(unitTarget->GetTypeId() != TYPEID_UNIT )
6315 return;
6316 if(!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER)
6317 return;
6319 Creature* creature = (Creature*) unitTarget;
6320 int32 targetLevel = creature->getLevel();
6322 uint32 skill = creature->GetCreatureInfo()->GetRequiredLootSkill();
6324 ((Player*)m_caster)->SendLoot(creature->GetGUID(),LOOT_SKINNING);
6325 creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);
6327 int32 reqValue = targetLevel < 10 ? 0 : targetLevel < 20 ? (targetLevel-10)*10 : targetLevel*5;
6329 int32 skillValue = ((Player*)m_caster)->GetPureSkillValue(skill);
6331 // Double chances for elites
6332 ((Player*)m_caster)->UpdateGatherSkill(skill, skillValue, reqValue, creature->isElite() ? 2 : 1 );
6335 void Spell::EffectCharge(uint32 /*i*/)
6337 if (!unitTarget)
6338 return;
6340 //TODO: research more ContactPoint/attack distance.
6341 //3.666666 instead of ATTACK_DISTANCE(5.0f) in below seem to give more accurate result.
6342 float x, y, z;
6343 unitTarget->GetContactPoint(m_caster, x, y, z, 3.666666f);
6345 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6346 ((Creature *)unitTarget)->StopMoving();
6348 // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
6349 m_caster->SendMonsterMove(x, y, z, 0, m_caster->GetTypeId()==TYPEID_PLAYER ? MONSTER_MOVE_WALK : ((Creature*)m_caster)->GetMonsterMoveFlags(), 1);
6351 if (m_caster->GetTypeId() != TYPEID_PLAYER)
6352 m_caster->GetMap()->CreatureRelocation((Creature*)m_caster,x,y,z,m_caster->GetOrientation());
6354 // not all charge effects used in negative spells
6355 if (unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
6356 m_caster->Attack(unitTarget,true);
6359 void Spell::EffectCharge2(uint32 /*i*/)
6361 float x, y, z;
6362 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6364 x = m_targets.m_destX;
6365 y = m_targets.m_destY;
6366 z = m_targets.m_destZ;
6368 if (unitTarget->GetTypeId() != TYPEID_PLAYER)
6369 ((Creature *)unitTarget)->StopMoving();
6371 else if (unitTarget && unitTarget != m_caster)
6372 unitTarget->GetContactPoint(m_caster, x, y, z, 3.666666f);
6373 else
6374 return;
6376 // Only send MOVEMENTFLAG_WALK_MODE, client has strange issues with other move flags
6377 m_caster->SendMonsterMove(x, y, z, 0, m_caster->GetTypeId()==TYPEID_PLAYER ? MONSTER_MOVE_WALK : ((Creature*)m_caster)->GetMonsterMoveFlags(), 1);
6379 if (m_caster->GetTypeId() != TYPEID_PLAYER)
6380 m_caster->GetMap()->CreatureRelocation((Creature*)m_caster,x,y,z,m_caster->GetOrientation());
6382 // not all charge effects used in negative spells
6383 if (unitTarget && unitTarget != m_caster && !IsPositiveSpell(m_spellInfo->Id))
6384 m_caster->Attack(unitTarget,true);
6387 void Spell::EffectSummonCritter(uint32 i, uint32 forceFaction)
6389 if(m_caster->GetTypeId() != TYPEID_PLAYER)
6390 return;
6391 Player* player = (Player*)m_caster;
6393 uint32 pet_entry = m_spellInfo->EffectMiscValue[i];
6394 if(!pet_entry)
6395 return;
6397 Pet* old_critter = player->GetMiniPet();
6399 // for same pet just despawn
6400 if(old_critter && old_critter->GetEntry() == pet_entry)
6402 player->RemoveMiniPet();
6403 return;
6406 // despawn old pet before summon new
6407 if(old_critter)
6408 player->RemoveMiniPet();
6410 // summon new pet
6411 Pet* critter = new Pet(MINI_PET);
6413 Map *map = m_caster->GetMap();
6414 uint32 pet_number = sObjectMgr.GeneratePetNumber();
6415 if(!critter->Create(map->GenerateLocalLowGuid(HIGHGUID_PET), map, m_caster->GetPhaseMask(),
6416 pet_entry, pet_number))
6418 sLog.outError("Spell::EffectSummonCritter, spellid %u: no such creature entry %u", m_spellInfo->Id, pet_entry);
6419 delete critter;
6420 return;
6423 float x, y, z;
6424 // If dest location if present
6425 if (m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)
6427 x = m_targets.m_destX;
6428 y = m_targets.m_destY;
6429 z = m_targets.m_destZ;
6431 // Summon if dest location not present near caster
6432 else
6433 m_caster->GetClosePoint(x, y, z, critter->GetObjectSize());
6435 critter->Relocate(x, y, z, m_caster->GetOrientation());
6437 if(!critter->IsPositionValid())
6439 sLog.outError("Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",
6440 critter->GetGUIDLow(), critter->GetEntry(), critter->GetPositionX(), critter->GetPositionY());
6441 delete critter;
6442 return;
6445 critter->SetOwnerGUID(m_caster->GetGUID());
6446 critter->SetCreatorGUID(m_caster->GetGUID());
6448 critter->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
6449 critter->setFaction(forceFaction ? forceFaction : m_caster->getFaction());
6450 critter->AIM_Initialize();
6451 critter->InitPetCreateSpells(); // e.g. disgusting oozeling has a create spell as critter...
6452 //critter->InitLevelupSpellsForLevel(); // none?
6453 critter->SelectLevel(critter->GetCreatureInfo()); // some summoned creaters have different from 1 DB data for level/hp
6454 critter->SetUInt32Value(UNIT_NPC_FLAGS, critter->GetCreatureInfo()->npcflag);
6455 // some mini-pets have quests
6457 // set timer for unsummon
6458 int32 duration = GetSpellDuration(m_spellInfo);
6459 if(duration > 0)
6460 critter->SetDuration(duration);
6462 std::string name = player->GetName();
6463 name.append(petTypeSuffix[critter->getPetType()]);
6464 critter->SetName( name );
6465 player->SetMiniPet(critter);
6467 map->Add((Creature*)critter);
6470 void Spell::EffectKnockBack(uint32 i)
6472 if(!unitTarget)
6473 return;
6475 unitTarget->KnockBackFrom(m_caster,float(m_spellInfo->EffectMiscValue[i])/10,float(damage)/10);
6478 void Spell::EffectSendTaxi(uint32 i)
6480 if(!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
6481 return;
6483 ((Player*)unitTarget)->ActivateTaxiPathTo(m_spellInfo->EffectMiscValue[i],m_spellInfo->Id);
6486 void Spell::EffectPlayerPull(uint32 i)
6488 if(!unitTarget)
6489 return;
6491 unitTarget->KnockBackFrom(m_caster,float(damage ? damage : unitTarget->GetDistance2d(m_caster)),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->SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED);
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);