diff options
| author | QAston <qaston@gmail.com> | 2011-09-25 13:29:17 +0200 |
|---|---|---|
| committer | QAston <qaston@gmail.com> | 2011-09-25 13:29:50 +0200 |
| commit | e949ad3adbfe22c11ec4d731b0fcfb9cc284f064 (patch) | |
| tree | 62ae43a852fac7d879e1b9dcc53b9facbb8f6a7c /src/server/game | |
| parent | b07cc3751f46d3bc848b7d1c3f5b350c7be084ee (diff) | |
Core/Spells: spell effect handling improvements
* Call spell effect handlers in 4 modes:
- SPELL_EFFECT_HANDLE_LAUNCH - called when spell is launched (cast just finished)
- SPELL_EFFECT_HANDLE_LAUNCH_TARGET - called when spell is launched for each target in spell target map
- SPELL_EFFECT_HANDLE_HIT - called when spell hits its destination
- SPELL_EFFECT_HANDLE_HIT_TARGET - called when spell hits it's target from spell target map
*Correctly implement SPELL_EFFECT_TRIGGER_SPELL, SPELL_EFFECT_TRIGGER_SPELL_WITH_VALUE, SPELL_EFFECT_TRIGGER_MISSILE_SPELL_WITH_VALUE, SPELL_EFFECT_TRIGGER_MISSILE_SPELL
*Remove spell system hacks which became obsolete with this commit
Core/SpellScripts:
add OnEffectLaunch, OnEffectLaunchTarget, OnEffectHit, OnEffectHitTarget hooks for new effect handle modes and remove OnEffect hook.
A generic rule of thumb how to update your scripts (will work for nearly all cases) for spell system noobs:
if your spell script used GetHitXXXX function, you need to use OnEffectHitTarget, otherwise use
OnEffectHit
Diffstat (limited to 'src/server/game')
| -rwxr-xr-x | src/server/game/Miscellaneous/SharedDefines.h | 2 | ||||
| -rwxr-xr-x | src/server/game/Spells/Spell.cpp | 199 | ||||
| -rwxr-xr-x | src/server/game/Spells/Spell.h | 15 | ||||
| -rwxr-xr-x | src/server/game/Spells/SpellEffects.cpp | 982 | ||||
| -rw-r--r-- | src/server/game/Spells/SpellInfo.cpp | 29 | ||||
| -rw-r--r-- | src/server/game/Spells/SpellInfo.h | 3 | ||||
| -rwxr-xr-x | src/server/game/Spells/SpellMgr.cpp | 49 | ||||
| -rwxr-xr-x | src/server/game/Spells/SpellScript.cpp | 97 | ||||
| -rwxr-xr-x | src/server/game/Spells/SpellScript.h | 34 |
9 files changed, 854 insertions, 556 deletions
diff --git a/src/server/game/Miscellaneous/SharedDefines.h b/src/server/game/Miscellaneous/SharedDefines.h index f3857c07cee..9d015a5284d 100755 --- a/src/server/game/Miscellaneous/SharedDefines.h +++ b/src/server/game/Miscellaneous/SharedDefines.h @@ -803,7 +803,7 @@ enum SpellEffects SPELL_EFFECT_PULL_TOWARDS_DEST = 145, SPELL_EFFECT_ACTIVATE_RUNE = 146, SPELL_EFFECT_QUEST_FAIL = 147, - SPELL_EFFECT_148 = 148, + SPELL_EFFECT_TRIGGER_MISSILE_SPELL_WITH_VALUE = 148, SPELL_EFFECT_CHARGE_DEST = 149, SPELL_EFFECT_QUEST_START = 150, SPELL_EFFECT_TRIGGER_SPELL_2 = 151, diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 33d03999ad4..274544b1b00 100755 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -483,7 +483,6 @@ m_caster((info->AttributesEx6 & SPELL_ATTR6_CAST_BY_CHARMER && caster->GetCharme m_delayAtDamageCount = 0; m_applyMultiplierMask = 0; - m_effectMask = 0; m_auraScaleMask = 0; // Get data for type of attack @@ -1166,7 +1165,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target) // can't use default call because of threading, do stuff as fast as possible for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i) if (farMask & (1 << i)) - HandleEffects(unit, NULL, NULL, i); + HandleEffects(unit, NULL, NULL, i, SPELL_EFFECT_HANDLE_HIT_TARGET); return; } @@ -1563,7 +1562,7 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit* unit, const uint32 effectMask, bool for (uint32 effectNumber = 0; effectNumber < MAX_SPELL_EFFECTS; ++effectNumber) if (effectMask & (1 << effectNumber)) - HandleEffects(unit, NULL, NULL, effectNumber); + HandleEffects(unit, NULL, NULL, effectNumber, SPELL_EFFECT_HANDLE_HIT_TARGET); return SPELL_MISS_NONE; } @@ -1655,7 +1654,7 @@ void Spell::DoAllEffectOnTarget(GOTargetInfo* target) for (uint32 effectNumber = 0; effectNumber < MAX_SPELL_EFFECTS; ++effectNumber) if (effectMask & (1 << effectNumber)) - HandleEffects(NULL, NULL, go, effectNumber); + HandleEffects(NULL, NULL, go, effectNumber, SPELL_EFFECT_HANDLE_HIT_TARGET); CallScriptOnHitHandlers(); @@ -1678,7 +1677,7 @@ void Spell::DoAllEffectOnTarget(ItemTargetInfo* target) for (uint32 effectNumber = 0; effectNumber < MAX_SPELL_EFFECTS; ++effectNumber) if (effectMask & (1 << effectNumber)) - HandleEffects(NULL, target->item, NULL, effectNumber); + HandleEffects(NULL, target->item, NULL, effectNumber, SPELL_EFFECT_HANDLE_HIT_TARGET); CallScriptOnHitHandlers(); @@ -3187,29 +3186,12 @@ void Spell::cast(bool skipCheck) TakeReagents(); } - if (m_spellInfo->AttributesCu & SPELL_ATTR0_CU_DIRECT_DAMAGE) - CalculateDamageDoneForAllTargets(); - // CAST SPELL SendSpellCooldown(); PrepareScriptHitHandlers(); - for (uint32 i = 0; i < MAX_SPELL_EFFECTS; ++i) - { - switch (m_spellInfo->Effects[i].Effect) - { - case SPELL_EFFECT_CHARGE: - case SPELL_EFFECT_CHARGE_DEST: - case SPELL_EFFECT_JUMP: - case SPELL_EFFECT_JUMP_DEST: - case SPELL_EFFECT_LEAP_BACK: - case SPELL_EFFECT_ACTIVATE_RUNE: - HandleEffects(NULL, NULL, NULL, i); - m_effectMask |= (1<<i); - break; - } - } + HandleLaunchPhase(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()... SendSpellGo(); @@ -3372,67 +3354,40 @@ uint64 Spell::handle_delayed(uint64 t_offset) void Spell::_handle_immediate_phase() { m_spellAura = NULL; + // initialize Diminishing Returns Data + m_diminishLevel = DIMINISHING_LEVEL_1; + m_diminishGroup = DIMINISHING_NONE; + // handle some immediate features of the spell here HandleThreatSpells(); PrepareScriptHitHandlers(); + // handle effects with SPELL_EFFECT_HANDLE_HIT mode for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j) { - if (m_spellInfo->Effects[j].Effect == 0) + // don't do anything for empty effect + if (!m_spellInfo->Effects[j].IsEffect()) continue; - // apply Send Event effect to ground in case empty target lists - if (m_spellInfo->Effects[j].Effect == SPELL_EFFECT_SEND_EVENT && !HaveTargetsForEffect(j)) - { - HandleEffects(NULL, NULL, NULL, j); - continue; - } + // call effect handlers to handle destination hit + HandleEffects(NULL, NULL, NULL, j, SPELL_EFFECT_HANDLE_HIT); } - // initialize Diminishing Returns Data - m_diminishLevel = DIMINISHING_LEVEL_1; - m_diminishGroup = DIMINISHING_NONE; - // process items for (std::list<ItemTargetInfo>::iterator ihit= m_UniqueItemInfo.begin(); ihit != m_UniqueItemInfo.end(); ++ihit) DoAllEffectOnTarget(&(*ihit)); if (!m_originalCaster) return; - uint8 oldEffMask = m_effectMask; - // process ground - for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j) - { - if (!m_spellInfo->Effects[j].IsEffect()) - continue; - - if (m_spellInfo->Effects[j].GetUsedTargetObjectType() == TARGET_OBJECT_TYPE_DEST) - { - if (!m_targets.HasDst()) // FIXME: this will ignore dest set in effect - m_targets.SetDst(*m_caster); - HandleEffects(m_originalCaster, NULL, NULL, j); - m_effectMask |= (1<<j); - } - else if (m_spellInfo->Effects[j].GetUsedTargetObjectType() && !m_spellInfo->Effects[j].GetImplicitTargetType()) - { - HandleEffects(m_originalCaster, NULL, NULL, j); - m_effectMask |= (1<<j); - } - } - if (oldEffMask != m_effectMask && m_UniqueTargetInfo.empty()) + // Handle procs on cast + // TODO: finish new proc system:P + if (m_UniqueTargetInfo.empty()) { uint32 procAttacker = m_procAttacker; if (!procAttacker) { - bool positive = true; - for (uint8 i = 0; i< MAX_SPELL_EFFECTS; ++i) - // If at least one effect negative spell is negative hit - if (m_effectMask & (1<<i) && !m_spellInfo->IsPositiveEffect(i)) - { - positive = false; - break; - } + bool positive = m_spellInfo->IsPositive(); switch (m_spellInfo->DmgClass) { case SPELL_DAMAGE_CLASS_MAGIC: @@ -4571,12 +4526,9 @@ void Spell::HandleThreatSpells() sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Spell %u, added an additional %f threat for %s %u target(s)", m_spellInfo->Id, threat, m_spellInfo->_IsPositiveSpell() ? "assisting" : "harming", uint32(m_UniqueTargetInfo.size())); } -void Spell::HandleEffects(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGOTarget, uint32 i) +void Spell::HandleEffects(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGOTarget, uint32 i, SpellEffectHandleMode mode) { - //effect has been handled, skip it - if (m_effectMask & (1<<i)) - return; - + effectHandleMode = mode; unitTarget = pUnitTarget; itemTarget = pItemTarget; gameObjTarget = pGOTarget; @@ -4585,10 +4537,10 @@ void Spell::HandleEffects(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGOT sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Spell: %u Effect : %u", m_spellInfo->Id, eff); - //we do not need DamageMultiplier here. + // we do not need DamageMultiplier here. damage = CalculateDamage(i, NULL); - bool preventDefault = CallScriptEffectHandlers((SpellEffIndex)i); + bool preventDefault = CallScriptEffectHandlers((SpellEffIndex)i, mode); if (!preventDefault && eff < TOTAL_SPELL_EFFECTS) { @@ -6598,14 +6550,24 @@ bool Spell::IsValidDeadOrAliveTarget(Unit const* target) const return false; } -void Spell::CalculateDamageDoneForAllTargets() +void Spell::HandleLaunchPhase() { + // handle effects with SPELL_EFFECT_HANDLE_LAUNCH mode + for (uint32 i = 0; i < MAX_SPELL_EFFECTS; ++i) + { + // don't do anything for empty effect + if (!m_spellInfo->Effects[i].IsEffect()) + continue; + + HandleEffects(NULL, NULL, NULL, i, SPELL_EFFECT_HANDLE_LAUNCH); + } + float multiplier[MAX_SPELL_EFFECTS]; for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i) if (m_applyMultiplierMask & (1 << i)) multiplier[i] = m_spellInfo->Effects[i].CalcDamageMultiplier(m_originalCaster, this); - bool usesAmmo = true; + bool usesAmmo = m_spellInfo->AttributesCu & SPELL_ATTR0_CU_DIRECT_DAMAGE; Unit::AuraEffectList const& Auras = m_caster->GetAuraEffectsByType(SPELL_AURA_ABILITY_CONSUME_NO_AMMO); for (Unit::AuraEffectList::const_iterator j = Auras.begin(); j != Auras.end(); ++j) { @@ -6615,16 +6577,12 @@ void Spell::CalculateDamageDoneForAllTargets() for (std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit) { - TargetInfo &target = *ihit; + TargetInfo& target = *ihit; uint32 mask = target.effectMask; if (!mask) continue; - Unit* unit = m_caster->GetGUID() == target.targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, target.targetGUID); - if (!unit) // || !unit->isAlive()) do we need to check alive here? - continue; - // do not consume ammo anymore for Hunter's volley spell if (IsTriggered() && m_spellInfo->SpellFamilyName == SPELLFAMILY_HUNTER && m_spellInfo->IsAOE()) usesAmmo = false; @@ -6650,49 +6608,30 @@ void Spell::CalculateDamageDoneForAllTargets() break; } } - - if (target.missCondition == SPELL_MISS_NONE) // In case spell hit target, do all effect on that target - { - target.damage += CalculateDamageDone(unit, mask, multiplier); - target.crit = m_caster->isSpellCrit(unit, m_spellInfo, m_spellSchoolMask, m_attackType); - } - else if (target.missCondition == SPELL_MISS_REFLECT) // In case spell reflect from target, do all effect on caster (if hit) - { - if (target.reflectResult == SPELL_MISS_NONE) // If reflected spell hit caster -> do all effect on him - { - target.damage += CalculateDamageDone(m_caster, mask, multiplier); - target.crit = m_caster->isSpellCrit(m_caster, m_spellInfo, m_spellSchoolMask, m_attackType); - } - } + DoAllEffectOnLaunchTarget(target, multiplier); } } -int32 Spell::CalculateDamageDone(Unit* unit, const uint32 effectMask, float * multiplier) +void Spell::DoAllEffectOnLaunchTarget(TargetInfo& targetInfo, float* multiplier) { - int32 damageDone = 0; - unitTarget = unit; + Unit* unit = NULL; + // In case spell hit target, do all effect on that target + if (targetInfo.missCondition == SPELL_MISS_NONE) + unit = m_caster->GetGUID() == targetInfo.targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, targetInfo.targetGUID); + // In case spell reflect from target, do all effect on caster (if hit) + else if (targetInfo.missCondition == SPELL_MISS_REFLECT && targetInfo.reflectResult == SPELL_MISS_NONE) + unit = m_caster; + if (!unit) + return; + for (uint32 i = 0; i < MAX_SPELL_EFFECTS; ++i) { - if (effectMask & (1<<i)) + if (targetInfo.effectMask & (1<<i)) { m_damage = 0; - damage = CalculateDamage(i, NULL); + m_healing = 0; - switch (m_spellInfo->Effects[i].Effect) - { - case SPELL_EFFECT_SCHOOL_DAMAGE: - SpellDamageSchoolDmg((SpellEffIndex)i); - break; - case SPELL_EFFECT_WEAPON_DAMAGE: - case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL: - case SPELL_EFFECT_NORMALIZED_WEAPON_DMG: - case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE: - SpellDamageWeaponDmg((SpellEffIndex)i); - break; - case SPELL_EFFECT_HEAL: - SpellDamageHeal((SpellEffIndex)i); - break; - } + HandleEffects(unit, NULL, NULL, i, SPELL_EFFECT_HANDLE_LAUNCH_TARGET); if (m_damage > 0) { @@ -6716,12 +6655,11 @@ int32 Spell::CalculateDamageDone(Unit* unit, const uint32 effectMask, float * mu m_damage = int32(m_damage * m_damageMultipliers[i]); m_damageMultipliers[i] *= multiplier[i]; } - - damageDone += m_damage; + targetInfo.damage += m_damage; } } - return damageDone; + targetInfo.crit = m_caster->isSpellCrit(unit, m_spellInfo, m_spellSchoolMask, m_attackType); } SpellCastResult Spell::CanOpenLock(uint32 effIndex, uint32 lockId, SkillType& skillId, int32& reqSkillValue, int32& skillValue) @@ -7031,14 +6969,41 @@ SpellCastResult Spell::CallScriptCheckCastHandlers() return retVal; } -bool Spell::CallScriptEffectHandlers(SpellEffIndex effIndex) +bool Spell::CallScriptEffectHandlers(SpellEffIndex effIndex, SpellEffectHandleMode mode) { // execute script effect handler hooks and check if effects was prevented bool preventDefault = false; for (std::list<SpellScript*>::iterator scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end() ; ++scritr) { - (*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_EFFECT); - std::list<SpellScript::EffectHandler>::iterator effEndItr = (*scritr)->OnEffect.end(), effItr = (*scritr)->OnEffect.begin(); + std::list<SpellScript::EffectHandler>::iterator effItr, effEndItr; + SpellScriptHookType hookType; + switch (mode) + { + case SPELL_EFFECT_HANDLE_LAUNCH: + effItr = (*scritr)->OnEffectLaunch.begin(); + effEndItr = (*scritr)->OnEffectLaunch.end(); + hookType = SPELL_SCRIPT_HOOK_EFFECT_LAUNCH; + break; + case SPELL_EFFECT_HANDLE_LAUNCH_TARGET: + effItr = (*scritr)->OnEffectLaunchTarget.begin(); + effEndItr = (*scritr)->OnEffectLaunchTarget.end(); + hookType = SPELL_SCRIPT_HOOK_EFFECT_LAUNCH_TARGET; + break; + case SPELL_EFFECT_HANDLE_HIT: + effItr = (*scritr)->OnEffectHit.begin(); + effEndItr = (*scritr)->OnEffectHit.end(); + hookType = SPELL_SCRIPT_HOOK_EFFECT_HIT; + break; + case SPELL_EFFECT_HANDLE_HIT_TARGET: + effItr = (*scritr)->OnEffectHitTarget.begin(); + effEndItr = (*scritr)->OnEffectHitTarget.end(); + hookType = SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET; + break; + default: + ASSERT(false); + break; + } + (*scritr)->_PrepareScriptCall(hookType); for (; effItr != effEndItr ; ++effItr) // effect execution can be prevented if (!(*scritr)->_IsEffectPrevented(effIndex) && (*effItr).IsEffectAffected(m_spellInfo, effIndex)) diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index c0a752ce704..6070df7e0aa 100755 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -282,7 +282,6 @@ class Spell void EffectLearnPetSpell(SpellEffIndex effIndex); void EffectWeaponDmg(SpellEffIndex effIndex); void EffectForceCast(SpellEffIndex effIndex); - void EffectForceCastWithValue(SpellEffIndex effIndex); void EffectTriggerSpell(SpellEffIndex effIndex); void EffectTriggerMissileSpell(SpellEffIndex effIndex); void EffectThreat(SpellEffIndex effIndex); @@ -337,7 +336,6 @@ class Spell void EffectUnlearnSpecialization(SpellEffIndex effIndex); void EffectHealPct(SpellEffIndex effIndex); void EffectEnergizePct(SpellEffIndex effIndex); - void EffectTriggerSpellWithValue(SpellEffIndex effIndex); void EffectTriggerRitualOfSummoning(SpellEffIndex effIndex); void EffectSummonRaFFriend(SpellEffIndex effIndex); void EffectKillCreditPersonal(SpellEffIndex effIndex); @@ -440,7 +438,7 @@ class Spell void SendChannelStart(uint32 duration); void SendResurrectRequest(Player* target); - void HandleEffects(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGOTarget, uint32 i); + void HandleEffects(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGOTarget, uint32 i, SpellEffectHandleMode mode); void HandleThreatSpells(); SpellInfo const* const m_spellInfo; @@ -539,6 +537,7 @@ class Spell Item* itemTarget; GameObject* gameObjTarget; int32 damage; + SpellEffectHandleMode effectHandleMode; // used in effects handlers Aura* m_spellAura; @@ -612,11 +611,8 @@ class Spell void SearchChainTarget(std::list<Unit*> &unitList, float radius, uint32 unMaxTargets, SpellTargets TargetType); WorldObject* SearchNearbyTarget(float range, SpellTargets TargetType, SpellEffIndex effIndex); bool IsValidDeadOrAliveTarget(Unit const* target) const; - void CalculateDamageDoneForAllTargets(); - int32 CalculateDamageDone(Unit* unit, const uint32 effectMask, float *multiplier); - void SpellDamageSchoolDmg(SpellEffIndex effIndex); - void SpellDamageWeaponDmg(SpellEffIndex effIndex); - void SpellDamageHeal(SpellEffIndex effIndex); + void HandleLaunchPhase(); + void DoAllEffectOnLaunchTarget(TargetInfo& targetInfo, float* multiplier); void PrepareTargetProcessing(); void FinishTargetProcessing(); @@ -630,7 +626,7 @@ class Spell void LoadScripts(); SpellCastResult CallScriptCheckCastHandlers(); void PrepareScriptHitHandlers(); - bool CallScriptEffectHandlers(SpellEffIndex effIndex); + bool CallScriptEffectHandlers(SpellEffIndex effIndex, SpellEffectHandleMode mode); void CallScriptBeforeHitHandlers(); void CallScriptOnHitHandlers(); void CallScriptAfterHitHandlers(); @@ -661,7 +657,6 @@ class Spell SpellInfo const* m_triggeredByAuraSpell; bool m_skipCheck; - uint32 m_effectMask; uint8 m_auraScaleMask; ByteBuffer * m_effectExecuteData[MAX_SPELL_EFFECTS]; diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index c8e3c195e32..0637c25e3ab 100755 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -206,14 +206,14 @@ pEffect SpellEffects[TOTAL_SPELL_EFFECTS]= &Spell::EffectLeapBack, //138 SPELL_EFFECT_LEAP_BACK Leap back &Spell::EffectQuestClear, //139 SPELL_EFFECT_CLEAR_QUEST Reset quest status (miscValue - quest ID) &Spell::EffectForceCast, //140 SPELL_EFFECT_FORCE_CAST - &Spell::EffectForceCastWithValue, //141 SPELL_EFFECT_FORCE_CAST_WITH_VALUE - &Spell::EffectTriggerSpellWithValue, //142 SPELL_EFFECT_TRIGGER_SPELL_WITH_VALUE + &Spell::EffectForceCast, //141 SPELL_EFFECT_FORCE_CAST_WITH_VALUE + &Spell::EffectTriggerSpell, //142 SPELL_EFFECT_TRIGGER_SPELL_WITH_VALUE &Spell::EffectApplyAreaAura, //143 SPELL_EFFECT_APPLY_AREA_AURA_OWNER &Spell::EffectKnockBack, //144 SPELL_EFFECT_KNOCK_BACK_DEST &Spell::EffectPullTowards, //145 SPELL_EFFECT_PULL_TOWARDS_DEST Black Hole Effect &Spell::EffectActivateRune, //146 SPELL_EFFECT_ACTIVATE_RUNE &Spell::EffectQuestFail, //147 SPELL_EFFECT_QUEST_FAIL quest fail - &Spell::EffectUnused, //148 SPELL_EFFECT_148 1 spell - 43509 + &Spell::EffectTriggerMissileSpell, //148 SPELL_EFFECT_TRIGGER_MISSILE_SPELL_WITH_VALUE &Spell::EffectChargeDest, //149 SPELL_EFFECT_CHARGE_DEST &Spell::EffectQuestStart, //150 SPELL_EFFECT_QUEST_START &Spell::EffectTriggerRitualOfSummoning, //151 SPELL_EFFECT_TRIGGER_SPELL_2 @@ -244,6 +244,9 @@ void Spell::EffectUnused(SpellEffIndex /*effIndex*/) void Spell::EffectResurrectNew(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->isAlive()) return; @@ -267,6 +270,9 @@ void Spell::EffectResurrectNew(SpellEffIndex effIndex) void Spell::EffectInstaKill(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || !unitTarget->isAlive()) return; @@ -284,6 +290,9 @@ void Spell::EffectInstaKill(SpellEffIndex /*effIndex*/) void Spell::EffectEnvironmentalDMG(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || !unitTarget->isAlive()) return; @@ -297,12 +306,11 @@ void Spell::EffectEnvironmentalDMG(SpellEffIndex /*effIndex*/) unitTarget->ToPlayer()->EnvironmentalDamage(DAMAGE_FIRE, damage); } -void Spell::EffectSchoolDMG(SpellEffIndex /*effIndex*/) +void Spell::EffectSchoolDMG(SpellEffIndex effIndex) { -} + if (effectHandleMode == SPELL_EFFECT_HANDLE_LAUNCH_TARGET) + return; -void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) -{ bool apply_direct_bonus = true; if (unitTarget && unitTarget->isAlive()) @@ -744,6 +752,9 @@ void Spell::SpellDamageSchoolDmg(SpellEffIndex effIndex) void Spell::EffectDummy(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget && !gameObjTarget && !itemTarget) return; @@ -1540,44 +1551,230 @@ void Spell::EffectDummy(SpellEffIndex effIndex) sScriptMgr->OnDummyEffect(m_caster, m_spellInfo->Id, effIndex, itemTarget); } -void Spell::EffectTriggerSpellWithValue(SpellEffIndex effIndex) +void Spell::EffectTriggerSpell(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET + && effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH) + return; + uint32 triggered_spell_id = m_spellInfo->Effects[effIndex].TriggerSpell; + // todo: move those to spell scripts + if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_TRIGGER_SPELL + && effectHandleMode == SPELL_EFFECT_HANDLE_LAUNCH_TARGET) + { + // special cases + switch(triggered_spell_id) + { + // Mirror Image + case 58832: + { + // Glyph of Mirror Image + if (m_caster->HasAura(63093)) + m_caster->CastSpell(m_caster, 65047, true); // Mirror Image + + break; + } + // Vanish (not exist) + case 18461: + { + unitTarget->RemoveMovementImpairingAuras(); + unitTarget->RemoveAurasByType(SPELL_AURA_MOD_STALKED); + + // If this spell is given to an NPC, it must handle the rest using its own AI + if (unitTarget->GetTypeId() != TYPEID_PLAYER) + return; + + // See if we already are stealthed. If so, we're done. + if (unitTarget->HasAura(1784)) + return; + + // Reset cooldown on stealth if needed + if (unitTarget->ToPlayer()->HasSpellCooldown(1784)) + unitTarget->ToPlayer()->RemoveSpellCooldown(1784); + + triggered_spell_id = 1784; + break; + } + // Demonic Empowerment -- succubus + case 54437: + { + unitTarget->RemoveMovementImpairingAuras(); + unitTarget->RemoveAurasByType(SPELL_AURA_MOD_STALKED); + unitTarget->RemoveAurasByType(SPELL_AURA_MOD_STUN); + + // Cast Lesser Invisibility + triggered_spell_id = 7870; + break; + } + // just skip + case 23770: // Sayge's Dark Fortune of * + // not exist, common cooldown can be implemented in scripts if need. + return; + // Brittle Armor - (need add max stack of 24575 Brittle Armor) + case 29284: + { + // Brittle Armor + SpellInfo const* spell = sSpellMgr->GetSpellInfo(24575); + if (!spell) + return; + + for (uint32 j = 0; j < spell->StackAmount; ++j) + m_caster->CastSpell(unitTarget, spell->Id, true); + return; + } + // Mercurial Shield - (need add max stack of 26464 Mercurial Shield) + case 29286: + { + // Mercurial Shield + SpellInfo const* spell = sSpellMgr->GetSpellInfo(26464); + if (!spell) + return; + + for (uint32 j = 0; j < spell->StackAmount; ++j) + m_caster->CastSpell(unitTarget, spell->Id, true); + return; + } + // Righteous Defense + case 31980: + { + m_caster->CastSpell(unitTarget, 31790, true); + return; + } + // Cloak of Shadows + case 35729: + { + uint32 dispelMask = SpellInfo::GetDispelMask(DISPEL_ALL); + Unit::AuraApplicationMap& Auras = unitTarget->GetAppliedAuras(); + for (Unit::AuraApplicationMap::iterator iter = Auras.begin(); iter != Auras.end();) + { + // remove all harmful spells on you... + SpellInfo const* spell = iter->second->GetBase()->GetSpellInfo(); + if ((spell->DmgClass == SPELL_DAMAGE_CLASS_MAGIC // only affect magic spells + || ((spell->GetDispelMask()) & dispelMask)) + // ignore positive and passive auras + && !iter->second->IsPositive() && !iter->second->GetBase()->IsPassive()) + { + m_caster->RemoveAura(iter); + } + else + ++iter; + } + return; + } + // Priest Shadowfiend (34433) need apply mana gain trigger aura on pet + case 41967: + { + if (Unit* pet = unitTarget->GetGuardianPet()) + pet->CastSpell(pet, 28305, true); + return; + } + } + } + // normal case SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(triggered_spell_id); - if (!spellInfo) { - sLog->outError("EffectTriggerSpellWithValue of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id); + sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Spell::EffectTriggerSpell spell %u tried to trigger unknown spell %u", m_spellInfo->Id, triggered_spell_id); return; } - int32 bp = damage; + SpellCastTargets targets; + if (effectHandleMode == SPELL_EFFECT_HANDLE_LAUNCH_TARGET) + { + if (!spellInfo->NeedsToBeTriggeredByCaster()) + return; + targets.SetUnitTarget(unitTarget); + } + else //if (effectHandleMode == SPELL_EFFECT_HANDLE_LAUNCH) + { + if (spellInfo->NeedsToBeTriggeredByCaster() && !(m_spellInfo->Effects[effIndex].GetProvidedTargetMask() & TARGET_FLAG_UNIT_MASK)) + return; + + if (spellInfo->GetExplicitTargetMask() & TARGET_FLAG_DEST_LOCATION) + targets.SetDst(m_targets); - Unit* caster = spellInfo->NeedsToBeTriggeredByCaster() ? m_caster : unitTarget; + targets.SetUnitTarget(m_caster); + } + + CustomSpellValues values; + // set basepoints for trigger with value effect + if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_TRIGGER_SPELL_WITH_VALUE) + { + // maybe need to set value only when basepoints == 0? + values.AddSpellMod(SPELLVALUE_BASE_POINT0, damage); + values.AddSpellMod(SPELLVALUE_BASE_POINT1, damage); + values.AddSpellMod(SPELLVALUE_BASE_POINT2, damage); + } - caster->CastCustomSpell(unitTarget, triggered_spell_id, &bp, &bp, &bp, true); + // Remove spell cooldown (not category) if spell triggering spell with cooldown and same category + if (m_caster->GetTypeId() == TYPEID_PLAYER && m_spellInfo->CategoryRecoveryTime && spellInfo->CategoryRecoveryTime + && m_spellInfo->Category == spellInfo->Category) + m_caster->ToPlayer()->RemoveSpellCooldown(spellInfo->Id); + + // original caster guid only for GO cast + m_caster->CastSpell(targets, spellInfo, &values, TRIGGERED_FULL_MASK, NULL, NULL, m_originalCasterGUID); } -void Spell::EffectTriggerRitualOfSummoning(SpellEffIndex effIndex) +void Spell::EffectTriggerMissileSpell(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET + && effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + uint32 triggered_spell_id = m_spellInfo->Effects[effIndex].TriggerSpell; - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(triggered_spell_id); + // normal case + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(triggered_spell_id); if (!spellInfo) { - sLog->outError("EffectTriggerRitualOfSummoning of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id); + sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Spell::EffectTriggerSpell spell %u tried to trigger unknown spell %u", m_spellInfo->Id, triggered_spell_id); return; } - finish(); + SpellCastTargets targets; + if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT_TARGET) + { + if (!spellInfo->NeedsToBeTriggeredByCaster()) + return; + targets.SetUnitTarget(unitTarget); + } + else //if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT) + { + if (spellInfo->NeedsToBeTriggeredByCaster() && !(m_spellInfo->Effects[effIndex].GetProvidedTargetMask() & TARGET_FLAG_UNIT_MASK)) + return; + + if (spellInfo->GetExplicitTargetMask() & TARGET_FLAG_DEST_LOCATION) + targets.SetDst(m_targets); + + targets.SetUnitTarget(m_caster); + } - m_caster->CastSpell(unitTarget, spellInfo, false); + CustomSpellValues values; + // set basepoints for trigger with value effect + if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_TRIGGER_MISSILE_SPELL_WITH_VALUE) + { + // maybe need to set value only when basepoints == 0? + values.AddSpellMod(SPELLVALUE_BASE_POINT0, damage); + values.AddSpellMod(SPELLVALUE_BASE_POINT1, damage); + values.AddSpellMod(SPELLVALUE_BASE_POINT2, damage); + } + + // Remove spell cooldown (not category) if spell triggering spell with cooldown and same category + if (m_caster->GetTypeId() == TYPEID_PLAYER && m_spellInfo->CategoryRecoveryTime && spellInfo->CategoryRecoveryTime + && m_spellInfo->Category == spellInfo->Category) + m_caster->ToPlayer()->RemoveSpellCooldown(spellInfo->Id); + + // original caster guid only for GO cast + m_caster->CastSpell(targets, spellInfo, &values, TRIGGERED_FULL_MASK, NULL, NULL, m_originalCasterGUID); } void Spell::EffectForceCast(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -1588,11 +1785,11 @@ void Spell::EffectForceCast(SpellEffIndex effIndex) if (!spellInfo) { - sLog->outError("EffectForceCast of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id); + sLog->outError("Spell::EffectForceCast of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id); return; } - if (damage) + if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_FORCE_CAST && damage) { switch (m_spellInfo->Id) { @@ -1610,224 +1807,55 @@ void Spell::EffectForceCast(SpellEffIndex effIndex) break; } } - unitTarget->CastSpell(m_caster, spellInfo, true); -} - -void Spell::EffectForceCastWithValue(SpellEffIndex effIndex) -{ - if (!unitTarget) - return; - - uint32 triggered_spell_id = m_spellInfo->Effects[effIndex].TriggerSpell; - - // normal case - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(triggered_spell_id); - if (!spellInfo) + CustomSpellValues values; + // set basepoints for trigger with value effect + if (m_spellInfo->Effects[effIndex].Effect == SPELL_EFFECT_FORCE_CAST_WITH_VALUE) { - sLog->outError("EffectForceCastWithValue of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id); - return; + // maybe need to set value only when basepoints == 0? + values.AddSpellMod(SPELLVALUE_BASE_POINT0, damage); + values.AddSpellMod(SPELLVALUE_BASE_POINT1, damage); + values.AddSpellMod(SPELLVALUE_BASE_POINT2, damage); } - int32 bp = damage; - unitTarget->CastCustomSpell(m_caster, spellInfo->Id, &bp, &bp, &bp, true); + SpellCastTargets targets; + targets.SetUnitTarget(m_caster); + + unitTarget->CastSpell(targets, spellInfo, &values, TRIGGERED_FULL_MASK); } -void Spell::EffectTriggerSpell(SpellEffIndex effIndex) +void Spell::EffectTriggerRitualOfSummoning(SpellEffIndex effIndex) { - // only unit case known - if (!unitTarget) - { - if (gameObjTarget || itemTarget) - sLog->outError("Spell::EffectTriggerSpell (Spell: %u): Unsupported non-unit case!", m_spellInfo->Id); + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) return; - } uint32 triggered_spell_id = m_spellInfo->Effects[effIndex].TriggerSpell; - Unit* originalCaster = NULL; - - // special cases - switch(triggered_spell_id) - { - // Mirror Image - case 58832: - { - // Glyph of Mirror Image - if (m_caster->HasAura(63093)) - m_caster->CastSpell(m_caster, 65047, true); // Mirror Image - - break; - } - // Vanish (not exist) - case 18461: - { - unitTarget->RemoveMovementImpairingAuras(); - unitTarget->RemoveAurasByType(SPELL_AURA_MOD_STALKED); - - // If this spell is given to an NPC, it must handle the rest using its own AI - if (unitTarget->GetTypeId() != TYPEID_PLAYER) - return; - - // See if we already are stealthed. If so, we're done. - if (unitTarget->HasAura(1784)) - return; - - // Reset cooldown on stealth if needed - if (unitTarget->ToPlayer()->HasSpellCooldown(1784)) - unitTarget->ToPlayer()->RemoveSpellCooldown(1784); - - triggered_spell_id = 1784; - break; - } - // Demonic Empowerment -- succubus - case 54437: - { - unitTarget->RemoveMovementImpairingAuras(); - unitTarget->RemoveAurasByType(SPELL_AURA_MOD_STALKED); - unitTarget->RemoveAurasByType(SPELL_AURA_MOD_STUN); - - // Cast Lesser Invisibility - triggered_spell_id = 7870; - break; - } - // just skip - case 23770: // Sayge's Dark Fortune of * - // not exist, common cooldown can be implemented in scripts if need. - return; - // Brittle Armor - (need add max stack of 24575 Brittle Armor) - case 29284: - { - // Brittle Armor - SpellInfo const* spell = sSpellMgr->GetSpellInfo(24575); - if (!spell) - return; - - for (uint32 j = 0; j < spell->StackAmount; ++j) - m_caster->CastSpell(unitTarget, spell->Id, true); - return; - } - // Mercurial Shield - (need add max stack of 26464 Mercurial Shield) - case 29286: - { - // Mercurial Shield - SpellInfo const* spell = sSpellMgr->GetSpellInfo(26464); - if (!spell) - return; - - for (uint32 j = 0; j < spell->StackAmount; ++j) - m_caster->CastSpell(unitTarget, spell->Id, true); - return; - } - // Righteous Defense - case 31980: - { - m_caster->CastSpell(unitTarget, 31790, true); - return; - } - // Cloak of Shadows - case 35729: - { - uint32 dispelMask = SpellInfo::GetDispelMask(DISPEL_ALL); - Unit::AuraApplicationMap& Auras = unitTarget->GetAppliedAuras(); - for (Unit::AuraApplicationMap::iterator iter = Auras.begin(); iter != Auras.end();) - { - // remove all harmful spells on you... - SpellInfo const* spell = iter->second->GetBase()->GetSpellInfo(); - if ((spell->DmgClass == SPELL_DAMAGE_CLASS_MAGIC // only affect magic spells - || ((spell->GetDispelMask()) & dispelMask)) - // ignore positive and passive auras - && !iter->second->IsPositive() && !iter->second->GetBase()->IsPassive()) - { - m_caster->RemoveAura(iter); - } - else - ++iter; - } - return; - } - // Priest Shadowfiend (34433) need apply mana gain trigger aura on pet - case 41967: - { - if (Unit* pet = unitTarget->GetGuardianPet()) - pet->CastSpell(pet, 28305, true); - return; - } - // Empower Rune Weapon - case 53258: - return; // skip, hack-added in spell effect - // Snake Trap - case 57879: - originalCaster = m_originalCaster; - break; - // Coldflame - case 33801: - return; // just make the core stfu - } - - // normal case - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(triggered_spell_id); - if (!spellInfo) - { - sLog->outError("EffectTriggerSpell of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id); - return; - } - - // Remove spell cooldown (not category) if spell triggering spell with cooldown and same category - // Needed by freezing arrow and few other spells - if (m_caster->GetTypeId() == TYPEID_PLAYER && m_spellInfo->CategoryRecoveryTime && spellInfo->CategoryRecoveryTime - && m_spellInfo->Category == spellInfo->Category) - m_caster->ToPlayer()->RemoveSpellCooldown(spellInfo->Id); - - // Note: not exist spells with weapon req. and IsSpellHaveCasterSourceTargets == true - // so this just for speedup places in else - Unit* caster = spellInfo->NeedsToBeTriggeredByCaster() ? m_caster : unitTarget; - - caster->CastSpell(unitTarget, spellInfo, true, 0, 0, (originalCaster ? originalCaster->GetGUID() : 0)); -} - -void Spell::EffectTriggerMissileSpell(SpellEffIndex effIndex) -{ - uint32 triggered_spell_id = m_spellInfo->Effects[effIndex].TriggerSpell; - - // normal case SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(triggered_spell_id); if (!spellInfo) { - sLog->outError("EffectTriggerMissileSpell of spell %u (eff: %u): triggering unknown spell id %u", - m_spellInfo->Id, effIndex, triggered_spell_id); + sLog->outError("EffectTriggerRitualOfSummoning of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id); return; } - if (m_CastItem) - sLog->outStaticDebug("WORLD: cast Item spellId - %i", spellInfo->Id); - - // Remove spell cooldown (not category) if spell triggering spell with cooldown and same category - // Needed by freezing arrow and few other spells - if (m_caster->GetTypeId() == TYPEID_PLAYER && m_spellInfo->CategoryRecoveryTime && spellInfo->CategoryRecoveryTime - && m_spellInfo->Category == spellInfo->Category) - m_caster->ToPlayer()->RemoveSpellCooldown(spellInfo->Id); + finish(); - float x, y, z; - m_targets.GetDst()->GetPosition(x, y, z); - m_caster->CastSpell(x, y, z, spellInfo->Id, true, m_CastItem, 0, m_originalCasterGUID); + m_caster->CastSpell((Unit*)NULL, spellInfo, false); } void Spell::EffectJump(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET) + return; + if (m_caster->isInFlight()) return; - float x, y, z; - if (m_targets.GetUnitTarget()) - m_targets.GetUnitTarget()->GetContactPoint(m_caster, x, y, z, CONTACT_DISTANCE); - else if (m_targets.GetGOTarget()) - m_targets.GetGOTarget()->GetContactPoint(m_caster, x, y, z, CONTACT_DISTANCE); - else - { - sLog->outError("Spell::EffectJump - unsupported target mode for spell ID %u", m_spellInfo->Id); + if (!unitTarget) return; - } + + float x, y, z; + unitTarget->GetContactPoint(m_caster, x, y, z, CONTACT_DISTANCE); float speedXY, speedZ; CalculateJumpSpeeds(effIndex, m_caster->GetExactDist2d(x, y), speedXY, speedZ); @@ -1836,34 +1864,18 @@ void Spell::EffectJump(SpellEffIndex effIndex) void Spell::EffectJumpDest(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH) + return; + if (m_caster->isInFlight()) return; + if (!m_targets.HasDst()) + return; + // Init dest coordinates float x, y, z; - if (m_targets.HasDst()) - { - m_targets.GetDst()->GetPosition(x, y, z); - - if (m_spellInfo->Effects[effIndex].TargetA.GetTarget() == TARGET_DEST_TARGET_BACK) - { - // explicit cast data from client or server-side cast - // some spell at client send caster - Unit* pTarget = NULL; - if (m_targets.GetUnitTarget() && m_targets.GetUnitTarget() != m_caster) - pTarget = m_targets.GetUnitTarget(); - else if (m_caster->getVictim()) - pTarget = m_caster->getVictim(); - else if (m_caster->GetTypeId() == TYPEID_PLAYER) - pTarget = ObjectAccessor::GetUnit(*m_caster, m_caster->ToPlayer()->GetSelection()); - - } - } - else - { - sLog->outError("Spell::EffectJumpDest - unsupported target mode for spell ID %u", m_spellInfo->Id); - return; - } + m_targets.GetDst()->GetPosition(x, y, z); float speedXY, speedZ; CalculateJumpSpeeds(effIndex, m_caster->GetExactDist2d(x, y), speedXY, speedZ); @@ -1883,6 +1895,9 @@ void Spell::CalculateJumpSpeeds(uint8 i, float dist, float & speedXY, float & sp void Spell::EffectTeleportUnits(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->isInFlight()) return; @@ -2046,6 +2061,9 @@ void Spell::EffectTeleportUnits(SpellEffIndex /*effIndex*/) void Spell::EffectApplyAura(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!m_spellAura || !unitTarget) return; ASSERT(unitTarget == m_spellAura->GetOwner()); @@ -2054,6 +2072,9 @@ void Spell::EffectApplyAura(SpellEffIndex effIndex) void Spell::EffectApplyAreaAura(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!m_spellAura || !unitTarget) return; ASSERT (unitTarget == m_spellAura->GetOwner()); @@ -2062,6 +2083,9 @@ void Spell::EffectApplyAreaAura(SpellEffIndex effIndex) void Spell::EffectUnlearnSpecialization(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -2075,6 +2099,9 @@ void Spell::EffectUnlearnSpecialization(SpellEffIndex effIndex) void Spell::EffectPowerDrain(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_spellInfo->Effects[effIndex].MiscValue < 0 || m_spellInfo->Effects[effIndex].MiscValue >= int8(MAX_POWERS)) return; @@ -2109,18 +2136,30 @@ void Spell::EffectPowerDrain(SpellEffIndex effIndex) void Spell::EffectSendEvent(SpellEffIndex effIndex) { - /* - we do not handle a flag dropping or clicking on flag in battleground by sendevent system - */ - sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Spell ScriptStart %u for spellid %u in EffectSendEvent ", m_spellInfo->Effects[effIndex].MiscValue, m_spellInfo->Id); + // we do not handle a flag dropping or clicking on flag in battleground by sendevent system + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET + && effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; Object* target = NULL; - if (focusObject) - target = focusObject; - else if (unitTarget) - target = unitTarget; - else if (gameObjTarget) - target = gameObjTarget; + + // call events for target if present + if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT_TARGET) + { + if (unitTarget) + target = unitTarget; + else if (gameObjTarget) + target = gameObjTarget; + } + // call event with no target or focus target when no targets could be found due to no dbc entry + else if (!m_spellInfo->Effects[effIndex].GetProvidedTargetMask()) + { + if (focusObject) + target = focusObject; + // TODO: there should be a possibility to pass dest target to event script + } + + sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Spell ScriptStart %u for spellid %u in EffectSendEvent ", m_spellInfo->Effects[effIndex].MiscValue, m_spellInfo->Id); if (ZoneScript* zoneScript = m_caster->GetZoneScript()) zoneScript->ProcessEvent(unitTarget, m_spellInfo->Effects[effIndex].MiscValue); @@ -2130,6 +2169,9 @@ void Spell::EffectSendEvent(SpellEffIndex effIndex) void Spell::EffectPowerBurn(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_spellInfo->Effects[effIndex].MiscValue < 0 || m_spellInfo->Effects[effIndex].MiscValue >= int8(MAX_POWERS)) return; @@ -2166,10 +2208,9 @@ void Spell::EffectPowerBurn(SpellEffIndex effIndex) void Spell::EffectHeal(SpellEffIndex /*effIndex*/) { -} + if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET) + return; -void Spell::SpellDamageHeal(SpellEffIndex /*effIndex*/) -{ if (unitTarget && unitTarget->isAlive() && damage >= 0) { // Try to get original caster @@ -2284,6 +2325,9 @@ void Spell::SpellDamageHeal(SpellEffIndex /*effIndex*/) void Spell::EffectHealPct(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || !unitTarget->isAlive() || damage < 0) return; @@ -2300,6 +2344,9 @@ void Spell::EffectHealPct(SpellEffIndex /*effIndex*/) void Spell::EffectHealMechanical(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || !unitTarget->isAlive() || damage < 0) return; @@ -2312,6 +2359,9 @@ void Spell::EffectHealMechanical(SpellEffIndex /*effIndex*/) void Spell::EffectHealthLeech(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || !unitTarget->isAlive() || damage < 0) return; @@ -2337,7 +2387,7 @@ void Spell::DoCreateItem(uint32 /*i*/, uint32 itemtype) if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; - Player* player = (Player*)unitTarget; + Player* player = unitTarget->ToPlayer(); uint32 newitemid = itemtype; ItemTemplate const* pProto = sObjectMgr->GetItemTemplate(newitemid); @@ -2445,15 +2495,22 @@ void Spell::DoCreateItem(uint32 /*i*/, uint32 itemtype) void Spell::EffectCreateItem(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + DoCreateItem(effIndex, m_spellInfo->Effects[effIndex].ItemType); ExecuteLogEffectCreateItem(effIndex, m_spellInfo->Effects[effIndex].ItemType); } void Spell::EffectCreateItem2(SpellEffIndex effIndex) { - if (m_caster->GetTypeId() != TYPEID_PLAYER) + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; - Player* player = (Player*)m_caster; + + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) + return; + + Player* player = unitTarget->ToPlayer(); uint32 item_id = m_spellInfo->Effects[effIndex].ItemType; @@ -2483,9 +2540,12 @@ void Spell::EffectCreateItem2(SpellEffIndex effIndex) void Spell::EffectCreateRandomItem(SpellEffIndex /*effIndex*/) { - if (m_caster->GetTypeId() != TYPEID_PLAYER) + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; - Player* player = (Player*)m_caster; + + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) + return; + Player* player = unitTarget->ToPlayer(); // create some random items player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell); @@ -2494,6 +2554,9 @@ void Spell::EffectCreateRandomItem(SpellEffIndex /*effIndex*/) void Spell::EffectPersistentAA(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + if (!m_spellAura) { Unit* caster = m_caster->GetEntry() == WORLD_TRIGGER ? m_originalCaster : m_caster; @@ -2526,6 +2589,9 @@ void Spell::EffectPersistentAA(SpellEffIndex effIndex) void Spell::EffectEnergize(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; if (!unitTarget->isAlive()) @@ -2628,6 +2694,9 @@ void Spell::EffectEnergize(SpellEffIndex effIndex) void Spell::EffectEnergizePct(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; if (!unitTarget->isAlive()) @@ -2717,13 +2786,16 @@ void Spell::SendLoot(uint64 guid, LootType loottype) void Spell::EffectOpenLock(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) { sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "WORLD: Open Lock - No Player Caster!"); return; } - Player* player = (Player*)m_caster; + Player* player = m_caster->ToPlayer(); uint32 lockId = 0; uint64 guid = 0; @@ -2819,10 +2891,13 @@ void Spell::EffectOpenLock(SpellEffIndex effIndex) void Spell::EffectSummonChangeItem(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; - Player* player = (Player*)m_caster; + Player* player = m_caster->ToPlayer(); // applied only to using item if (!m_CastItem) @@ -2918,9 +2993,12 @@ void Spell::EffectSummonChangeItem(SpellEffIndex effIndex) void Spell::EffectProficiency(SpellEffIndex /*effIndex*/) { - if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; - Player* p_target = unitTarget->ToPlayer(); + Player* p_target = m_caster->ToPlayer(); uint32 subClassMask = m_spellInfo->EquippedItemSubClassMask; if (m_spellInfo->EquippedItemClass == ITEM_CLASS_WEAPON && !(p_target->GetWeaponProficiency() & subClassMask)) @@ -2937,6 +3015,9 @@ void Spell::EffectProficiency(SpellEffIndex /*effIndex*/) void Spell::EffectSummonType(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + uint32 entry = m_spellInfo->Effects[effIndex].MiscValue; if (!entry) return; @@ -3086,6 +3167,9 @@ void Spell::EffectSummonType(SpellEffIndex effIndex) void Spell::EffectLearnSpell(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -3108,6 +3192,9 @@ typedef std::list< std::pair<uint32, uint64> > DispelList; typedef std::list< std::pair<Aura* , uint8> > DispelChargesList; void Spell::EffectDispel(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -3246,6 +3333,9 @@ void Spell::EffectDispel(SpellEffIndex effIndex) void Spell::EffectDualWield(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + unitTarget->SetCanDualWield(true); if (unitTarget->GetTypeId() == TYPEID_UNIT) unitTarget->ToCreature()->UpdateDamagePhysical(OFF_ATTACK); @@ -3259,6 +3349,9 @@ void Spell::EffectPull(SpellEffIndex effIndex) void Spell::EffectDistract(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + // Check for possible target if (!unitTarget || unitTarget->isInCombat()) return; @@ -3287,6 +3380,9 @@ void Spell::EffectDistract(SpellEffIndex /*effIndex*/) void Spell::EffectPickPocket(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; @@ -3301,6 +3397,9 @@ void Spell::EffectPickPocket(SpellEffIndex /*effIndex*/) void Spell::EffectAddFarsight(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; @@ -3326,6 +3425,9 @@ void Spell::EffectAddFarsight(SpellEffIndex effIndex) void Spell::EffectUntrainTalents(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || m_caster->GetTypeId() == TYPEID_PLAYER) return; @@ -3335,6 +3437,9 @@ void Spell::EffectUntrainTalents(SpellEffIndex /*effIndex*/) void Spell::EffectTeleUnitsFaceCaster(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -3351,6 +3456,9 @@ void Spell::EffectTeleUnitsFaceCaster(SpellEffIndex effIndex) void Spell::EffectLearnSkill(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -3364,6 +3472,9 @@ void Spell::EffectLearnSkill(SpellEffIndex effIndex) void Spell::EffectAddHonor(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -3392,15 +3503,21 @@ void Spell::EffectAddHonor(SpellEffIndex /*effIndex*/) void Spell::EffectTradeSkill(SpellEffIndex /*effIndex*/) { - if (unitTarget->GetTypeId() != TYPEID_PLAYER) + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; // uint32 skillid = m_spellInfo->Effects[i].MiscValue; // uint16 skillmax = unitTarget->ToPlayer()->(skillid); - // unitTarget->ToPlayer()->SetSkill(skillid, skillval?skillval:1, skillmax+75); + // m_caster->ToPlayer()->SetSkill(skillid, skillval?skillval:1, skillmax+75); } void Spell::EffectEnchantItemPerm(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; if (!itemTarget) @@ -3461,6 +3578,9 @@ void Spell::EffectEnchantItemPerm(SpellEffIndex effIndex) void Spell::EffectEnchantItemPrismatic(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; if (!itemTarget) @@ -3521,6 +3641,9 @@ void Spell::EffectEnchantItemPrismatic(SpellEffIndex effIndex) void Spell::EffectEnchantItemTmp(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; @@ -3528,7 +3651,7 @@ void Spell::EffectEnchantItemTmp(SpellEffIndex effIndex) // Rockbiter Weapon apply to both weapon if (!itemTarget) - return; + return; if (m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN && m_spellInfo->SpellFamilyFlags[0] & 0x400000) { uint32 spell_id = 0; @@ -3649,6 +3772,9 @@ void Spell::EffectEnchantItemTmp(SpellEffIndex effIndex) void Spell::EffectTameCreature(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_caster->GetPetGUID()) return; @@ -3702,6 +3828,9 @@ void Spell::EffectTameCreature(SpellEffIndex /*effIndex*/) void Spell::EffectSummonPet(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + Player* owner = NULL; if (m_originalCaster) { @@ -3781,6 +3910,9 @@ void Spell::EffectSummonPet(SpellEffIndex effIndex) void Spell::EffectLearnPetSpell(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -3804,6 +3936,9 @@ void Spell::EffectLearnPetSpell(SpellEffIndex effIndex) void Spell::EffectTaunt(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -3837,12 +3972,11 @@ void Spell::EffectTaunt(SpellEffIndex /*effIndex*/) unitTarget->ToCreature()->AI()->AttackStart(m_caster); } -void Spell::EffectWeaponDmg(SpellEffIndex /*effIndex*/) +void Spell::EffectWeaponDmg(SpellEffIndex effIndex) { -} + if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET) + return; -void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) -{ if (!unitTarget || !unitTarget->isAlive()) return; @@ -4132,6 +4266,9 @@ void Spell::SpellDamageWeaponDmg(SpellEffIndex effIndex) void Spell::EffectThreat(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || !unitTarget->isAlive() || !m_caster->isAlive()) return; @@ -4143,6 +4280,9 @@ void Spell::EffectThreat(SpellEffIndex /*effIndex*/) void Spell::EffectHealMaxHealth(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || !unitTarget->isAlive()) return; @@ -4169,6 +4309,9 @@ void Spell::EffectHealMaxHealth(SpellEffIndex /*effIndex*/) void Spell::EffectInterruptCast(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || !unitTarget->isAlive()) return; @@ -4198,6 +4341,9 @@ void Spell::EffectInterruptCast(SpellEffIndex effIndex) void Spell::EffectSummonObjectWild(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + uint32 gameobject_id = m_spellInfo->Effects[effIndex].MiscValue; GameObject* pGameObj = new GameObject; @@ -4287,6 +4433,9 @@ void Spell::EffectSummonObjectWild(SpellEffIndex effIndex) void Spell::EffectScriptEffect(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + // TODO: we must implement hunter pet summon at login there (spell 6962) switch(m_spellInfo->SpellFamilyName) @@ -5327,6 +5476,9 @@ void Spell::EffectScriptEffect(SpellEffIndex effIndex) void Spell::EffectSanctuary(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -5357,6 +5509,9 @@ void Spell::EffectSanctuary(SpellEffIndex /*effIndex*/) void Spell::EffectAddComboPoints(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -5371,6 +5526,9 @@ void Spell::EffectAddComboPoints(SpellEffIndex /*effIndex*/) void Spell::EffectDuel(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -5455,13 +5613,16 @@ void Spell::EffectDuel(SpellEffIndex effIndex) void Spell::EffectStuck(SpellEffIndex /*effIndex*/) { - if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + + if (!m_caster || m_caster->GetTypeId() != TYPEID_PLAYER) return; if (!sWorld->getBoolConfig(CONFIG_CAST_UNSTUCK)) return; - Player* pTarget = (Player*)unitTarget; + Player* pTarget = (Player*)m_caster; sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Spell Effect: Stuck"); 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()); @@ -5469,9 +5630,9 @@ void Spell::EffectStuck(SpellEffIndex /*effIndex*/) if (pTarget->isInFlight()) return; - pTarget->TeleportTo(pTarget->GetStartPosition(), unitTarget == m_caster ? TELE_TO_SPELL : 0); + pTarget->TeleportTo(pTarget->GetStartPosition(), m_caster == m_caster ? TELE_TO_SPELL : 0); // homebind location is loaded always - // pTarget->TeleportTo(pTarget->m_homebindMapId, pTarget->m_homebindX, pTarget->m_homebindY, pTarget->m_homebindZ, pTarget->GetOrientation(), (unitTarget == m_caster ? TELE_TO_SPELL : 0)); + // pTarget->TeleportTo(pTarget->m_homebindMapId, pTarget->m_homebindX, pTarget->m_homebindY, pTarget->m_homebindZ, pTarget->GetOrientation(), (m_caster == m_caster ? TELE_TO_SPELL : 0)); // Stuck spell trigger Hearthstone cooldown SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(8690); @@ -5483,6 +5644,10 @@ void Spell::EffectStuck(SpellEffIndex /*effIndex*/) void Spell::EffectSummonPlayer(SpellEffIndex /*effIndex*/) { + // workaround - this effect should not use target map + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -5504,6 +5669,9 @@ void Spell::EffectSummonPlayer(SpellEffIndex /*effIndex*/) void Spell::EffectActivateObject(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!gameObjTarget) return; @@ -5517,6 +5685,9 @@ void Spell::EffectActivateObject(SpellEffIndex /*effIndex*/) void Spell::EffectApplyGlyph(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER || m_glyphIndex >= MAX_GLYPH_SLOT_INDEX) return; @@ -5572,6 +5743,9 @@ void Spell::EffectApplyGlyph(SpellEffIndex effIndex) void Spell::EffectEnchantHeldItem(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + // this is only item spell effect applied to main-hand weapon of target player (players in area) if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -5614,6 +5788,9 @@ void Spell::EffectEnchantHeldItem(SpellEffIndex effIndex) void Spell::EffectDisEnchant(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; @@ -5630,6 +5807,9 @@ void Spell::EffectDisEnchant(SpellEffIndex /*effIndex*/) void Spell::EffectInebriate(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -5645,12 +5825,15 @@ void Spell::EffectInebriate(SpellEffIndex /*effIndex*/) void Spell::EffectFeedPet(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; Player* _player = m_caster->ToPlayer(); - Item* foodItem = m_targets.GetItemTarget(); + Item* foodItem = itemTarget; if (!foodItem) return; @@ -5676,21 +5859,23 @@ void Spell::EffectFeedPet(SpellEffIndex effIndex) void Spell::EffectDismissPet(SpellEffIndex effIndex) { - if (m_caster->GetTypeId() != TYPEID_PLAYER) + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; - Pet* pet = m_caster->ToPlayer()->GetPet(); - - // not let dismiss dead pet - if (!pet||!pet->isAlive()) + if (!unitTarget || !unitTarget->isPet()) return; + Pet* pet = unitTarget->ToPet(); + ExecuteLogEffectUnsummonObject(effIndex, pet); - m_caster->ToPlayer()->RemovePet(pet, PET_SAVE_NOT_IN_SLOT); + pet->GetOwner()->RemovePet(pet, PET_SAVE_NOT_IN_SLOT); } void Spell::EffectSummonObject(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + uint32 go_id = m_spellInfo->Effects[effIndex].MiscValue; uint8 slot = 0; @@ -5753,6 +5938,9 @@ void Spell::EffectSummonObject(SpellEffIndex effIndex) void Spell::EffectResurrect(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; if (unitTarget->GetTypeId() != TYPEID_PLAYER) @@ -5808,6 +5996,9 @@ void Spell::EffectResurrect(SpellEffIndex effIndex) void Spell::EffectAddExtraAttacks(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || !unitTarget->isAlive() || !unitTarget->getVictim()) return; @@ -5821,19 +6012,28 @@ void Spell::EffectAddExtraAttacks(SpellEffIndex effIndex) void Spell::EffectParry(SpellEffIndex /*effIndex*/) { - if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER) - unitTarget->ToPlayer()->SetCanParry(true); + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + + if (m_caster->GetTypeId() == TYPEID_PLAYER) + m_caster->ToPlayer()->SetCanParry(true); } void Spell::EffectBlock(SpellEffIndex /*effIndex*/) { - if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER) - unitTarget->ToPlayer()->SetCanBlock(true); + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + + if (m_caster->GetTypeId() == TYPEID_PLAYER) + m_caster->ToPlayer()->SetCanBlock(true); } void Spell::EffectLeap(SpellEffIndex /*effIndex*/) { - if (unitTarget->isInFlight()) + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + + if (!unitTarget || unitTarget->isInFlight()) return; if (!m_targets.HasDst()) @@ -5844,12 +6044,15 @@ void Spell::EffectLeap(SpellEffIndex /*effIndex*/) void Spell::EffectReputation(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; Player* _player = unitTarget->ToPlayer(); - int32 rep_change = damage;//+1; // field store reputation change -1 + int32 rep_change = damage; uint32 faction_id = m_spellInfo->Effects[effIndex].MiscValue; @@ -5872,14 +6075,13 @@ void Spell::EffectReputation(SpellEffIndex effIndex) void Spell::EffectQuestComplete(SpellEffIndex effIndex) { - Player* player = NULL; - if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER) - player = (Player*)unitTarget; - else if (m_caster->GetTypeId() == TYPEID_PLAYER) - player = (Player*)m_caster; - else + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) + return; + Player* player = unitTarget->ToPlayer(); + uint32 questId = m_spellInfo->Effects[effIndex].MiscValue; if (questId) { @@ -5897,6 +6099,9 @@ void Spell::EffectQuestComplete(SpellEffIndex effIndex) void Spell::EffectForceDeselect(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + WorldPacket data(SMSG_CLEAR_TARGET, 8); data << uint64(m_caster->GetGUID()); m_caster->SendMessageToSet(&data, true); @@ -5904,11 +6109,14 @@ void Spell::EffectForceDeselect(SpellEffIndex /*effIndex*/) void Spell::EffectSelfResurrect(SpellEffIndex effIndex) { - if (!unitTarget || unitTarget->isAlive()) + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) return; - if (unitTarget->GetTypeId() != TYPEID_PLAYER) + + if (!m_caster || m_caster->isAlive()) return; - if (!unitTarget->IsInWorld()) + if (m_caster->GetTypeId() != TYPEID_PLAYER) + return; + if (!m_caster->IsInWorld()) return; uint32 health = 0; @@ -5923,12 +6131,12 @@ void Spell::EffectSelfResurrect(SpellEffIndex effIndex) // percent case else { - health = unitTarget->CountPctFromMaxHealth(damage); - if (unitTarget->GetMaxPower(POWER_MANA) > 0) - mana = CalculatePctN(unitTarget->GetMaxPower(POWER_MANA), damage); + health = m_caster->CountPctFromMaxHealth(damage); + if (m_caster->GetMaxPower(POWER_MANA) > 0) + mana = CalculatePctN(m_caster->GetMaxPower(POWER_MANA), damage); } - Player* plr = unitTarget->ToPlayer(); + Player* plr = m_caster->ToPlayer(); plr->ResurrectPlayer(0.0f); plr->SetHealth(health); @@ -5941,6 +6149,9 @@ void Spell::EffectSelfResurrect(SpellEffIndex effIndex) void Spell::EffectSkinning(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (unitTarget->GetTypeId() != TYPEID_UNIT) return; if (m_caster->GetTypeId() != TYPEID_PLAYER) @@ -5964,21 +6175,32 @@ void Spell::EffectSkinning(SpellEffIndex /*effIndex*/) void Spell::EffectCharge(SpellEffIndex /*effIndex*/) { - Unit* target = m_targets.GetUnitTarget(); - if (!target) - return; + if (effectHandleMode == SPELL_EFFECT_HANDLE_LAUNCH_TARGET) + { + if (!unitTarget) + return; - float x, y, z; - target->GetContactPoint(m_caster, x, y, z); - m_caster->GetMotionMaster()->MoveCharge(x, y, z); + float x, y, z; + unitTarget->GetContactPoint(m_caster, x, y, z); + m_caster->GetMotionMaster()->MoveCharge(x, y, z); + } - // not all charge effects used in negative spells - if (!m_spellInfo->IsPositive() && m_caster->GetTypeId() == TYPEID_PLAYER) - m_caster->Attack(target, true); + if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT_TARGET) + { + if (!unitTarget) + return; + + // not all charge effects used in negative spells + if (!m_spellInfo->IsPositive() && m_caster->GetTypeId() == TYPEID_PLAYER) + m_caster->Attack(unitTarget, true); + } } void Spell::EffectChargeDest(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH) + return; + if (m_targets.HasDst()) { float x, y, z; @@ -5989,6 +6211,9 @@ void Spell::EffectChargeDest(SpellEffIndex /*effIndex*/) void Spell::EffectKnockBack(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -6044,30 +6269,26 @@ void Spell::EffectKnockBack(SpellEffIndex effIndex) void Spell::EffectLeapBack(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH_TARGET) + return; + + if (!unitTarget) + return; + float speedxy = float(m_spellInfo->Effects[effIndex].MiscValue)/10; float speedz = float(damage/10); - if (!speedxy) - { - if (m_targets.GetUnitTarget()) - m_caster->JumpTo(m_targets.GetUnitTarget(), speedz); - } - else - { - //1891: Disengage - m_caster->JumpTo(speedxy, speedz, m_spellInfo->SpellIconID != 1891); - } + //1891: Disengage + m_caster->JumpTo(speedxy, speedz, m_spellInfo->SpellIconID != 1891); } void Spell::EffectQuestClear(SpellEffIndex effIndex) { - Player* pPlayer = NULL; - if (m_caster->GetTypeId() == TYPEID_PLAYER) - pPlayer = m_caster->ToPlayer(); - else if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER) - pPlayer = unitTarget->ToPlayer(); + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; - if (!pPlayer) + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; + Player* pPlayer = unitTarget->ToPlayer(); uint32 quest_id = m_spellInfo->Effects[effIndex].MiscValue; @@ -6099,6 +6320,9 @@ void Spell::EffectQuestClear(SpellEffIndex effIndex) void Spell::EffectSendTaxi(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6107,6 +6331,9 @@ void Spell::EffectSendTaxi(SpellEffIndex effIndex) void Spell::EffectPullTowards(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -6130,6 +6357,9 @@ void Spell::EffectPullTowards(SpellEffIndex effIndex) void Spell::EffectDispelMechanic(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -6156,6 +6386,9 @@ void Spell::EffectDispelMechanic(SpellEffIndex effIndex) void Spell::EffectSummonDeadPet(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; Player* _player = m_caster->ToPlayer(); @@ -6184,6 +6417,9 @@ void Spell::EffectSummonDeadPet(SpellEffIndex /*effIndex*/) void Spell::EffectDestroyAllTotems(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + int32 mana = 0; for (uint8 slot = SUMMON_SLOT_TOTEM; slot < MAX_TOTEM_SLOT; ++slot) { @@ -6210,6 +6446,9 @@ void Spell::EffectDestroyAllTotems(SpellEffIndex /*effIndex*/) void Spell::EffectDurabilityDamage(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6235,6 +6474,9 @@ void Spell::EffectDurabilityDamage(SpellEffIndex effIndex) void Spell::EffectDurabilityDamagePCT(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6261,6 +6503,9 @@ void Spell::EffectDurabilityDamagePCT(SpellEffIndex effIndex) void Spell::EffectModifyThreatPercent(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; @@ -6269,6 +6514,9 @@ void Spell::EffectModifyThreatPercent(SpellEffIndex /*effIndex*/) void Spell::EffectTransmitted(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + uint32 name_id = m_spellInfo->Effects[effIndex].MiscValue; GameObjectTemplate const* goinfo = sObjectMgr->GetGameObjectTemplate(name_id); @@ -6411,6 +6659,9 @@ void Spell::EffectTransmitted(SpellEffIndex effIndex) void Spell::EffectProspecting(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; @@ -6433,6 +6684,9 @@ void Spell::EffectProspecting(SpellEffIndex /*effIndex*/) void Spell::EffectMilling(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; @@ -6455,6 +6709,9 @@ void Spell::EffectMilling(SpellEffIndex /*effIndex*/) void Spell::EffectSkill(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "WORLD: SkillEFFECT"); } @@ -6464,9 +6721,10 @@ void Spell::EffectSkill(SpellEffIndex /*effIndex*/) This is why we use a half sec delay between the visual effect and the resurrection itself */ void Spell::EffectSpiritHeal(SpellEffIndex /*effIndex*/) { - /* - if (!unitTarget || unitTarget->isAlive()) + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) return; + + /* if (unitTarget->GetTypeId() != TYPEID_PLAYER) return; if (!unitTarget->IsInWorld()) @@ -6482,6 +6740,9 @@ void Spell::EffectSpiritHeal(SpellEffIndex /*effIndex*/) // remove insignia spell effect void Spell::EffectSkinPlayerCorpse(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Effect: SkinPlayerCorpse"); if ((m_caster->GetTypeId() != TYPEID_PLAYER) || (unitTarget->GetTypeId() != TYPEID_PLAYER) || (unitTarget->isAlive())) return; @@ -6491,6 +6752,9 @@ void Spell::EffectSkinPlayerCorpse(SpellEffIndex /*effIndex*/) void Spell::EffectStealBeneficialBuff(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Effect: StealBeneficialBuff"); if (!unitTarget || unitTarget == m_caster) // can't steal from self @@ -6593,6 +6857,9 @@ void Spell::EffectStealBeneficialBuff(SpellEffIndex effIndex) void Spell::EffectKillCreditPersonal(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6601,6 +6868,9 @@ void Spell::EffectKillCreditPersonal(SpellEffIndex effIndex) void Spell::EffectKillCredit(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6617,6 +6887,9 @@ void Spell::EffectKillCredit(SpellEffIndex effIndex) void Spell::EffectQuestFail(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6625,6 +6898,9 @@ void Spell::EffectQuestFail(SpellEffIndex effIndex) void Spell::EffectQuestStart(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6640,6 +6916,9 @@ void Spell::EffectQuestStart(SpellEffIndex effIndex) void Spell::EffectActivateRune(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_LAUNCH) + return; + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; @@ -6678,6 +6957,9 @@ void Spell::EffectActivateRune(SpellEffIndex effIndex) void Spell::EffectCreateTamedPet(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER || unitTarget->GetPetGUID() || unitTarget->getClass() != CLASS_HUNTER) return; @@ -6703,6 +6985,9 @@ void Spell::EffectCreateTamedPet(SpellEffIndex effIndex) void Spell::EffectDiscoverTaxi(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; uint32 nodeid = m_spellInfo->Effects[effIndex].MiscValue; @@ -6712,18 +6997,27 @@ void Spell::EffectDiscoverTaxi(SpellEffIndex effIndex) void Spell::EffectTitanGrip(SpellEffIndex /*effIndex*/) { - if (unitTarget && unitTarget->GetTypeId() == TYPEID_PLAYER) - unitTarget->ToPlayer()->SetCanTitanGrip(true); + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + + if (m_caster->GetTypeId() == TYPEID_PLAYER) + m_caster->ToPlayer()->SetCanTitanGrip(true); } void Spell::EffectRedirectThreat(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (unitTarget) m_caster->SetReducedThreatPercent((uint32)damage, unitTarget->GetGUID()); } void Spell::EffectGameObjectDamage(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!gameObjTarget) return; @@ -6740,6 +7034,9 @@ void Spell::EffectGameObjectDamage(SpellEffIndex /*effIndex*/) void Spell::EffectGameObjectRepair(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!gameObjTarget) return; @@ -6748,6 +7045,9 @@ void Spell::EffectGameObjectRepair(SpellEffIndex /*effIndex*/) void Spell::EffectGameObjectSetDestructionState(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!gameObjTarget || !m_originalCaster) return; @@ -6868,6 +7168,9 @@ void Spell::GetSummonPosition(uint32 i, Position &pos, float radius, uint32 coun void Spell::EffectRenamePet(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_UNIT || !unitTarget->ToCreature()->isPet() || ((Pet*)unitTarget)->getPetType() != HUNTER_PET) return; @@ -6877,6 +7180,9 @@ void Spell::EffectRenamePet(SpellEffIndex /*effIndex*/) void Spell::EffectPlayMusic(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6895,6 +7201,9 @@ void Spell::EffectPlayMusic(SpellEffIndex effIndex) void Spell::EffectSpecCount(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6903,6 +7212,9 @@ void Spell::EffectSpecCount(SpellEffIndex /*effIndex*/) void Spell::EffectActivateSpec(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6911,6 +7223,9 @@ void Spell::EffectActivateSpec(SpellEffIndex /*effIndex*/) void Spell::EffectPlayerNotification(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -6937,6 +7252,9 @@ void Spell::EffectPlayerNotification(SpellEffIndex effIndex) void Spell::EffectRemoveAura(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget) return; // there may be need of specifying casterguid of removed auras @@ -6945,7 +7263,10 @@ void Spell::EffectRemoveAura(SpellEffIndex effIndex) void Spell::EffectCastButtons(SpellEffIndex effIndex) { - if (!unitTarget || m_caster->GetTypeId() != TYPEID_PLAYER) + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT) + return; + + if (m_caster->GetTypeId() != TYPEID_PLAYER) return; Player* p_caster = m_caster->ToPlayer(); @@ -6979,12 +7300,15 @@ void Spell::EffectCastButtons(SpellEffIndex effIndex) continue; TriggerCastFlags triggerFlags = TriggerCastFlags(TRIGGERED_IGNORE_GCD | TRIGGERED_IGNORE_CAST_IN_PROGRESS | TRIGGERED_CAST_DIRECTLY); - m_caster->CastSpell(unitTarget, spell_id, triggerFlags); + m_caster->CastSpell(m_caster, spell_id, triggerFlags); } } void Spell::EffectRechargeManaGem(SpellEffIndex /*effIndex*/) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -7012,6 +7336,9 @@ void Spell::EffectRechargeManaGem(SpellEffIndex /*effIndex*/) void Spell::EffectBind(SpellEffIndex effIndex) { + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; + if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; @@ -7065,7 +7392,10 @@ void Spell::EffectBind(SpellEffIndex effIndex) player->SendDirectMessage(&data); } -void Spell::EffectSummonRaFFriend(SpellEffIndex effIndex) { +void Spell::EffectSummonRaFFriend(SpellEffIndex effIndex) +{ + if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET) + return; if (m_caster->GetTypeId() != TYPEID_PLAYER || !unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER) return; diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp index 78bf88a7144..50b27615224 100644 --- a/src/server/game/Spells/SpellInfo.cpp +++ b/src/server/game/Spells/SpellInfo.cpp @@ -204,20 +204,6 @@ uint32 SpellImplicitTargetInfo::GetExplicitTargetMask(bool& srcSet, bool& dstSet return targetMask; } -bool SpellImplicitTargetInfo::IsPosition(uint32 targetType) -{ - switch (SpellImplicitTargetInfo::Type[targetType]) - { - case TARGET_TYPE_DEST_CASTER: - case TARGET_TYPE_DEST_TARGET: - case TARGET_TYPE_DEST_DEST: - return true; - default: - break; - } - return false; -} - bool SpellImplicitTargetInfo::InitStaticData() { InitTypeData(); @@ -656,6 +642,11 @@ float SpellEffectInfo::CalcRadius(Unit* caster, Spell* spell) const return radius; } +uint32 SpellEffectInfo::GetProvidedTargetMask() const +{ + return GetTargetFlagMask(TargetA.GetObjectType()) | GetTargetFlagMask(TargetB.GetObjectType()); +} + uint32 SpellEffectInfo::GetMissingTargetMask(bool srcSet /*= false*/, bool dstSet /*= false*/, uint32 mask /*=0*/) const { uint32 effImplicitTargetMask = GetTargetFlagMask(GetUsedTargetObjectType()); @@ -692,7 +683,7 @@ SpellTargetObjectTypes SpellEffectInfo::GetUsedTargetObjectType() const SpellEffectInfo::StaticData SpellEffectInfo::_data[TOTAL_SPELL_EFFECTS] = { - // implicit target type used target object type + // implicit target type used target object type {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_NONE}, // 0 {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 1 SPELL_EFFECT_INSTAKILL {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 2 SPELL_EFFECT_SCHOOL_DAMAGE @@ -725,7 +716,7 @@ SpellEffectInfo::StaticData SpellEffectInfo::_data[TOTAL_SPELL_EFFECTS] = {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT_AND_DEST},// 29 SPELL_EFFECT_LEAP {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_UNIT}, // 30 SPELL_EFFECT_ENERGIZE {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 31 SPELL_EFFECT_WEAPON_PERCENT_DAMAGE - {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_DEST}, // 32 SPELL_EFFECT_TRIGGER_MISSILE + {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_NONE}, // 32 SPELL_EFFECT_TRIGGER_MISSILE {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_GOBJ_ITEM}, // 33 SPELL_EFFECT_OPEN_LOCK {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_UNIT}, // 34 SPELL_EFFECT_SUMMON_CHANGE_ITEM {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 35 SPELL_EFFECT_APPLY_AREA_AURA_PARTY @@ -735,7 +726,7 @@ SpellEffectInfo::StaticData SpellEffectInfo::_data[TOTAL_SPELL_EFFECTS] = {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_UNIT}, // 39 SPELL_EFFECT_LANGUAGE {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 40 SPELL_EFFECT_DUAL_WIELD {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 41 SPELL_EFFECT_JUMP - {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT_AND_DEST},// 42 SPELL_EFFECT_JUMP_DEST + {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_DEST}, // 42 SPELL_EFFECT_JUMP_DEST {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT_AND_DEST},// 43 SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 44 SPELL_EFFECT_SKILL_STEP {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 45 SPELL_EFFECT_ADD_HONOR @@ -841,10 +832,10 @@ SpellEffectInfo::StaticData SpellEffectInfo::_data[TOTAL_SPELL_EFFECTS] = {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT_AND_DEST},// 145 SPELL_EFFECT_PULL_TOWARDS_DEST {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 146 SPELL_EFFECT_ACTIVATE_RUNE {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 147 SPELL_EFFECT_QUEST_FAIL - {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_NONE}, // 148 SPELL_EFFECT_148 + {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_NONE}, // 148 SPELL_EFFECT_TRIGGER_MISSILE_SPELL_WITH_VALUE {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_DEST}, // 149 SPELL_EFFECT_CHARGE_DEST {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 150 SPELL_EFFECT_QUEST_START - {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_DEST}, // 151 SPELL_EFFECT_TRIGGER_SPELL_2 + {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_NONE}, // 151 SPELL_EFFECT_TRIGGER_SPELL_2 {EFFECT_IMPLICIT_TARGET_NONE, TARGET_OBJECT_TYPE_NONE}, // 152 SPELL_EFFECT_SUMMON_RAF_FRIEND {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 153 SPELL_EFFECT_CREATE_TAMED_PET {EFFECT_IMPLICIT_TARGET_EXPLICIT, TARGET_OBJECT_TYPE_UNIT}, // 154 SPELL_EFFECT_DISCOVER_TAXI diff --git a/src/server/game/Spells/SpellInfo.h b/src/server/game/Spells/SpellInfo.h index 680652ea922..9b29120ef1c 100644 --- a/src/server/game/Spells/SpellInfo.h +++ b/src/server/game/Spells/SpellInfo.h @@ -228,9 +228,7 @@ public: uint32 GetExplicitTargetMask(bool& srcSet, bool& dstSet) const; // temporarily avalible to public - static bool IsPosition(uint32 targetType); static SpellSelectTargetTypes Type[TOTAL_SPELL_TARGETS]; - private: static bool InitStaticData(); static void InitTypeData(); @@ -295,6 +293,7 @@ public: bool HasRadius() const; float CalcRadius(Unit* caster = NULL, Spell* = NULL) const; + uint32 GetProvidedTargetMask() const; uint32 GetMissingTargetMask(bool srcSet = false, bool destSet = false, uint32 mask = 0) const; SpellEffectImplicitTargetTypes GetImplicitTargetType() const; diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index a0098237e18..d84d9e40f7d 100755 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -2905,11 +2905,6 @@ void SpellMgr::LoadDbcDataCorrections() if (!spellInfo->speed && !spellInfo->SpellFamilyName) spellInfo->speed = SPEED_CHARGE; break; - case SPELL_EFFECT_TRIGGER_SPELL: - if (SpellImplicitTargetInfo::IsPosition(spellInfo->EffectImplicitTargetA[j]) || - spellInfo->Targets & (TARGET_FLAG_SOURCE_LOCATION | TARGET_FLAG_DEST_LOCATION)) - spellInfo->Effect[j] = SPELL_EFFECT_TRIGGER_MISSILE; - break; } } @@ -2956,10 +2951,6 @@ void SpellMgr::LoadDbcDataCorrections() case 59372: // Energize Cores spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_SRC_AREA_ENEMY; break; - case 3286: // Bind - spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_TARGET_ENEMY; - spellInfo->EffectImplicitTargetA[1] = TARGET_UNIT_TARGET_ENEMY; - break; case 8494: // Mana Shield (rank 2) // because of bug in dbc spellInfo->procChance = 0; @@ -2977,14 +2968,6 @@ void SpellMgr::LoadDbcDataCorrections() // Entries were not updated after spell effect change, we have to do that manually :/ spellInfo->AttributesEx3 |= SPELL_ATTR3_CAN_PROC_WITH_TRIGGERED; break; - case 16007: // Draco-Incarcinatrix 900 - // was 46, but effect is aura effect - spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_NEARBY_ENTRY; - spellInfo->EffectImplicitTargetB[0] = TARGET_DEST_NEARBY_ENTRY; - break; - case 19465: // Improved Stings, only rank 2 of this spell has target for effect 2 = TARGET_DST_DB - spellInfo->EffectImplicitTargetA[2] = TARGET_UNIT_CASTER; - break; case 59725: // Improved Spell Reflection - aoe aura // Target entry seems to be wrong for this spell :/ spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_CASTER_AREA_PARTY; @@ -3007,13 +2990,8 @@ void SpellMgr::LoadDbcDataCorrections() case 42611: // Shoot case 62374: // Pursued case 61588: // Blazing Harpoon - spellInfo->MaxAffectedTargets = 1; - break; case 52479: // Gift of the Harvester spellInfo->MaxAffectedTargets = 1; - // a trap always has dst = src? - spellInfo->EffectImplicitTargetA[0] = TARGET_DEST_CASTER; - spellInfo->EffectImplicitTargetA[1] = TARGET_DEST_CASTER; break; case 41376: // Spite case 39992: // Needle Spine @@ -3091,15 +3069,10 @@ void SpellMgr::LoadDbcDataCorrections() // add corruption to affected spells spellInfo->EffectSpellClassMask[1][0] |= 2; break; - case 49305: // Teleport to Boss 1 DND - case 64981: // Summon Random Vanquished Tentacle - spellInfo->EffectImplicitTargetB[0] = TARGET_UNIT_CASTER; - break; case 51852: // The Eye of Acherus (no spawn in phase 2 in db) spellInfo->EffectMiscValue[0] |= 1; break; - case 18541: // Ritual of Doom Effect (temp hack, current targeting system requires implicit targets to be set. Was target_dest_caster) - case 51904: // Summon Ghouls On Scarlet Crusade (core does not know the triggered spell is summon spell) + case 51904: // Summon Ghouls On Scarlet Crusade (this should use conditions table, script for this spell needs to be fixed) spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_CASTER; break; case 29809: // Desecration Arm - 36 instead of 37 - typo? :/ @@ -3151,10 +3124,6 @@ void SpellMgr::LoadDbcDataCorrections() spellInfo->EffectImplicitTargetB[0] = TARGET_UNIT_SRC_AREA_ALLY; spellInfo->EffectImplicitTargetB[1] = TARGET_UNIT_SRC_AREA_ALLY; break; - case 31687: // Summon Water Elemental - // 322-330 switch - effect changed to dummy, target entry not changed in client:( - spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_CASTER; - break; case 57994: // Wind Shear - improper data for EFFECT_1 in 3.3.5 DBC, but is correct in 4.x spellInfo->Effect[EFFECT_1] = SPELL_EFFECT_MODIFY_THREAT_PERCENT; spellInfo->EffectBasePoints[EFFECT_1] = -6; // -5% @@ -3173,12 +3142,12 @@ void SpellMgr::LoadDbcDataCorrections() case 53246: // Marked for Death (Rank 5) spellInfo->EffectSpellClassMask[0] = flag96(423937, 276955137, 2049); break; - case 70728: // Exploit Weakness - case 70840: // Devious Minds + case 70728: // Exploit Weakness (needs target selection script) + case 70840: // Devious Minds (needs target selection script) spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_CASTER; spellInfo->EffectImplicitTargetB[0] = TARGET_UNIT_PET; break; - case 70893: // Culling The Herd + case 70893: // Culling The Herd (needs target selection script) spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_CASTER; spellInfo->EffectImplicitTargetB[0] = TARGET_UNIT_MASTER; break; @@ -3310,10 +3279,10 @@ void SpellMgr::LoadDbcDataCorrections() case 72507: // Mutated Plague (Professor Putricide) spellInfo->EffectRadiusIndex[0] = 28; // 50000yd break; - case 70911: // Unbound Plague (Professor Putricide) - case 72854: // Unbound Plague (Professor Putricide) - case 72855: // Unbound Plague (Professor Putricide) - case 72856: // Unbound Plague (Professor Putricide) + case 70911: // Unbound Plague (Professor Putricide) (needs target selection script) + case 72854: // Unbound Plague (Professor Putricide) (needs target selection script) + case 72855: // Unbound Plague (Professor Putricide) (needs target selection script) + case 72856: // Unbound Plague (Professor Putricide) (needs target selection script) spellInfo->EffectImplicitTargetB[0] = TARGET_UNIT_TARGET_ENEMY; break; case 71518: // Unholy Infusion Quest Credit (Professor Putricide) @@ -3340,7 +3309,7 @@ void SpellMgr::LoadDbcDataCorrections() case 71085: // Mana Void (periodic aura) spellInfo->DurationIndex = 9; // 30 seconds (missing) break; - case 70936: // Summon Suppressor + case 70936: // Summon Suppressor (needs target selection script) spellInfo->EffectImplicitTargetA[0] = TARGET_UNIT_TARGET_ANY; spellInfo->EffectImplicitTargetB[0] = 0; break; diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp index 5c9a6a23304..2d83b2e8f1a 100755 --- a/src/server/game/Spells/SpellScript.cpp +++ b/src/server/game/Spells/SpellScript.cpp @@ -215,9 +215,21 @@ void SpellScript::UnitTargetHandler::Call(SpellScript* spellScript, std::list<Un bool SpellScript::_Validate(SpellInfo const* entry) { - for (std::list<EffectHandler>::iterator itr = OnEffect.begin(); itr != OnEffect.end(); ++itr) + for (std::list<EffectHandler>::iterator itr = OnEffectLaunch.begin(); itr != OnEffectLaunch.end(); ++itr) if (!(*itr).GetAffectedEffectsMask(entry)) - sLog->outError("TSCR: Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffect` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str()); + sLog->outError("TSCR: Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectLaunch` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str()); + + for (std::list<EffectHandler>::iterator itr = OnEffectLaunchTarget.begin(); itr != OnEffectLaunchTarget.end(); ++itr) + if (!(*itr).GetAffectedEffectsMask(entry)) + sLog->outError("TSCR: Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectLaunchTarget` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str()); + + for (std::list<EffectHandler>::iterator itr = OnEffectHit.begin(); itr != OnEffectHit.end(); ++itr) + if (!(*itr).GetAffectedEffectsMask(entry)) + sLog->outError("TSCR: Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectHit` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str()); + + for (std::list<EffectHandler>::iterator itr = OnEffectHitTarget.begin(); itr != OnEffectHitTarget.end(); ++itr) + if (!(*itr).GetAffectedEffectsMask(entry)) + sLog->outError("TSCR: Spell `%u` Effect `%s` of script `%s` did not match dbc effect data - handler bound to hook `OnEffectHitTarget` of SpellScript won't be executed", entry->Id, (*itr).ToString().c_str(), m_scriptName->c_str()); for (std::list<UnitTargetHandler>::iterator itr = OnUnitTargetSelect.begin(); itr != OnUnitTargetSelect.end(); ++itr) if (!(*itr).GetAffectedEffectsMask(entry)) @@ -251,6 +263,33 @@ void SpellScript::_FinishScriptCall() m_currentScriptState = SPELL_SCRIPT_STATE_NONE; } +bool SpellScript::IsInCheckCastHook() const +{ + return m_currentScriptState == SPELL_SCRIPT_HOOK_CHECK_CAST; +} +bool SpellScript::IsInTargetHook() const +{ + switch (m_currentScriptState) + { + case SPELL_SCRIPT_HOOK_EFFECT_LAUNCH_TARGET: + case SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET: + case SPELL_SCRIPT_HOOK_BEFORE_HIT: + case SPELL_SCRIPT_HOOK_HIT: + case SPELL_SCRIPT_HOOK_AFTER_HIT: + return true; + } + return false; +} +bool SpellScript::IsInHitPhase() const +{ + return (m_currentScriptState >= HOOK_SPELL_HIT_START && m_currentScriptState < HOOK_SPELL_HIT_END); +} + +bool SpellScript::IsInEffectHook() const +{ + return (m_currentScriptState >= SPELL_SCRIPT_HOOK_EFFECT_LAUNCH && m_currentScriptState <= SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET); +} + Unit* SpellScript::GetCaster() { return m_spell->GetCaster(); @@ -295,9 +334,9 @@ Item* SpellScript::GetTargetItem() Unit* SpellScript::GetHitUnit() { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitUnit was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitUnit was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return NULL; } return m_spell->unitTarget; @@ -305,9 +344,9 @@ Unit* SpellScript::GetHitUnit() Creature* SpellScript::GetHitCreature() { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitCreature was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitCreature was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return NULL; } if (m_spell->unitTarget) @@ -318,9 +357,9 @@ Creature* SpellScript::GetHitCreature() Player* SpellScript::GetHitPlayer() { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitPlayer was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitPlayer was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return NULL; } if (m_spell->unitTarget) @@ -331,9 +370,9 @@ Player* SpellScript::GetHitPlayer() Item* SpellScript::GetHitItem() { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitItem was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitItem was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return NULL; } return m_spell->itemTarget; @@ -341,9 +380,9 @@ Item* SpellScript::GetHitItem() GameObject* SpellScript::GetHitGObj() { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitGObj was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitGObj was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return NULL; } return m_spell->gameObjTarget; @@ -351,9 +390,9 @@ GameObject* SpellScript::GetHitGObj() int32 SpellScript::GetHitDamage() { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitDamage was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitDamage was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return 0; } return m_spell->m_damage; @@ -361,9 +400,9 @@ int32 SpellScript::GetHitDamage() void SpellScript::SetHitDamage(int32 damage) { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::SetHitDamage was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::SetHitDamage was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return; } m_spell->m_damage = damage; @@ -371,9 +410,9 @@ void SpellScript::SetHitDamage(int32 damage) int32 SpellScript::GetHitHeal() { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitHeal was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitHeal was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return 0; } return m_spell->m_healing; @@ -381,9 +420,9 @@ int32 SpellScript::GetHitHeal() void SpellScript::SetHitHeal(int32 heal) { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::SetHitHeal was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::SetHitHeal was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return; } m_spell->m_healing = heal; @@ -391,9 +430,9 @@ void SpellScript::SetHitHeal(int32 heal) Aura* SpellScript::GetHitAura() { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitAura was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::GetHitAura was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return NULL; } if (!m_spell->m_spellAura) @@ -405,9 +444,9 @@ Aura* SpellScript::GetHitAura() void SpellScript::PreventHitAura() { - if (!IsInHitPhase()) + if (!IsInTargetHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::PreventHitAura was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::PreventHitAura was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return; } if (m_spell->m_spellAura) @@ -416,9 +455,9 @@ void SpellScript::PreventHitAura() void SpellScript::PreventHitEffect(SpellEffIndex effIndex) { - if (!IsInHitPhase()) + if (!IsInHitPhase() && !IsInEffectHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::PreventHitEffect was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::PreventHitEffect was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return; } m_hitPreventEffectMask |= 1 << effIndex; @@ -427,9 +466,9 @@ void SpellScript::PreventHitEffect(SpellEffIndex effIndex) void SpellScript::PreventHitDefaultEffect(SpellEffIndex effIndex) { - if (!IsInHitPhase()) + if (!IsInHitPhase() && !IsInEffectHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::PreventHitDefaultEffect was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::PreventHitDefaultEffect was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return; } m_hitPreventDefaultEffectMask |= 1 << effIndex; @@ -439,7 +478,7 @@ int32 SpellScript::GetEffectValue() { if (!IsInEffectHook()) { - sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::PreventHitDefaultEffect was called while spell not in hit phase!", m_scriptName->c_str(), m_scriptSpellId); + sLog->outError("TSCR: Script: `%s` Spell: `%u`: function SpellScript::PreventHitDefaultEffect was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId); return 0; } return m_spell->damage; diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h index 8a742cbd118..af814798a3a 100755 --- a/src/server/game/Spells/SpellScript.h +++ b/src/server/game/Spells/SpellScript.h @@ -122,7 +122,10 @@ class _SpellScript // SpellScript interface - enum used for runtime checks of script function calls enum SpellScriptHookType { - SPELL_SCRIPT_HOOK_EFFECT = SPELL_SCRIPT_STATE_END, + SPELL_SCRIPT_HOOK_EFFECT_LAUNCH = SPELL_SCRIPT_STATE_END, + SPELL_SCRIPT_HOOK_EFFECT_LAUNCH_TARGET, + SPELL_SCRIPT_HOOK_EFFECT_HIT, + SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET, SPELL_SCRIPT_HOOK_BEFORE_HIT, SPELL_SCRIPT_HOOK_HIT, SPELL_SCRIPT_HOOK_AFTER_HIT, @@ -130,7 +133,7 @@ enum SpellScriptHookType SPELL_SCRIPT_HOOK_CHECK_CAST, }; -#define HOOK_SPELL_HIT_START SPELL_SCRIPT_HOOK_EFFECT +#define HOOK_SPELL_HIT_START SPELL_SCRIPT_HOOK_EFFECT_HIT #define HOOK_SPELL_HIT_END SPELL_SCRIPT_HOOK_AFTER_HIT + 1 #define HOOK_SPELL_START SPELL_SCRIPT_HOOK_EFFECT #define HOOK_SPELL_END SPELL_SCRIPT_HOOK_CHECK_CAST + 1 @@ -205,9 +208,10 @@ class SpellScript : public _SpellScript bool _IsDefaultEffectPrevented(SpellEffIndex effIndex) { return m_hitPreventDefaultEffectMask & (1<<effIndex); } void _PrepareScriptCall(SpellScriptHookType hookType); void _FinishScriptCall(); - bool IsInCheckCastHook() const { return m_currentScriptState == SPELL_SCRIPT_HOOK_CHECK_CAST; } - bool IsInHitPhase() const { return (m_currentScriptState >= HOOK_SPELL_HIT_START && m_currentScriptState < HOOK_SPELL_HIT_END); } - bool IsInEffectHook() const { return (m_currentScriptState == SPELL_SCRIPT_HOOK_EFFECT); } + bool IsInCheckCastHook() const; + bool IsInTargetHook() const; + bool IsInHitPhase() const; + bool IsInEffectHook() const; private: Spell* m_spell; uint8 m_hitPreventEffectMask; @@ -223,9 +227,12 @@ class SpellScript : public _SpellScript HookList<CheckCastHandler> OnCheckCast; #define SpellCheckCastFn(F) CheckCastHandlerFunction(&F) - // example: OnEffect += SpellEffectFn(class::function, EffectIndexSpecifier, EffectNameSpecifier); + // example: OnEffect**** += SpellEffectFn(class::function, EffectIndexSpecifier, EffectNameSpecifier); // where function is void function(SpellEffIndex effIndex) - HookList<EffectHandler> OnEffect; + HookList<EffectHandler> OnEffectLaunch; + HookList<EffectHandler> OnEffectLaunchTarget; + HookList<EffectHandler> OnEffectHit; + HookList<EffectHandler> OnEffectHitTarget; #define SpellEffectFn(F, I, N) EffectHandlerFunction(&F, I, N) // example: BeforeHit += SpellHitFn(class::function); @@ -244,10 +251,13 @@ class SpellScript : public _SpellScript // hooks are executed in following order, at specified event of spell: // 1. OnUnitTargetSelect - executed just before adding selected targets to final target list - // 2. BeforeHit - executed just before spell hits a target - // 3. OnEffect - executed just before specified effect handler call - // 4. OnHit - executed just before spell deals damage and procs auras - // 5. AfterHit - executed just after spell finishes all it's jobs for target + // 2. OnEffectLaunch - executed just before specified effect handler call - when spell missile is launched + // 3. OnEffectLaunchTarget - executed just before specified effect handler call - when spell missile is launched - called for each target from spell target map + // 4. OnEffectHit - executed just before specified effect handler call - when spell missile hits dest + // 5. BeforeHit - executed just before spell hits a target - called for each target from spell target map + // 6. OnEffectHitTarget - executed just before specified effect handler call - called for each target from spell target map + // 7. OnHit - executed just before spell deals damage and procs auras - when spell hits target - called for each target from spell target map + // 8. AfterHit - executed just after spell finishes all it's jobs for target - called for each target from spell target map // // methods allowing interaction with Spell object @@ -275,7 +285,7 @@ class SpellScript : public _SpellScript // returns: Item which was selected as a spell target or NULL Item* GetTargetItem(); - // methods useable only during spell hit on target phase: + // methods useable only during spell hit on target, or during spell launch on target: // returns: target of current effect if it was Unit otherwise NULL Unit* GetHitUnit(); |
