aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Spells/SpellScript.cpp60
-rw-r--r--src/server/game/Spells/SpellScript.h43
2 files changed, 60 insertions, 43 deletions
diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp
index 224aa2bc327..909ae8c9131 100644
--- a/src/server/game/Spells/SpellScript.cpp
+++ b/src/server/game/Spells/SpellScript.cpp
@@ -397,6 +397,22 @@ bool SpellScript::IsInTargetHook() const
}
return false;
}
+
+bool SpellScript::IsInModifiableHook() const
+{
+ // after hit hook executed after damage/healing is already done
+ // modifying it at this point has no effect
+ 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:
+ return true;
+ }
+ return false;
+}
+
bool SpellScript::IsInHitPhase() const
{
return (m_currentScriptState >= HOOK_SPELL_HIT_START && m_currentScriptState < HOOK_SPELL_HIT_END);
@@ -407,22 +423,22 @@ bool SpellScript::IsInEffectHook() const
return (m_currentScriptState >= SPELL_SCRIPT_HOOK_EFFECT_LAUNCH && m_currentScriptState <= SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET);
}
-Unit* SpellScript::GetCaster()
+Unit* SpellScript::GetCaster() const
{
return m_spell->GetCaster();
}
-Unit* SpellScript::GetOriginalCaster()
+Unit* SpellScript::GetOriginalCaster() const
{
return m_spell->GetOriginalCaster();
}
-SpellInfo const* SpellScript::GetSpellInfo()
+SpellInfo const* SpellScript::GetSpellInfo() const
{
return m_spell->GetSpellInfo();
}
-WorldLocation const* SpellScript::GetExplTargetDest()
+WorldLocation const* SpellScript::GetExplTargetDest() const
{
if (m_spell->m_targets.HasDst())
return m_spell->m_targets.GetDstPos();
@@ -434,27 +450,27 @@ void SpellScript::SetExplTargetDest(WorldLocation& loc)
m_spell->m_targets.SetDst(loc);
}
-WorldObject* SpellScript::GetExplTargetWorldObject()
+WorldObject* SpellScript::GetExplTargetWorldObject() const
{
return m_spell->m_targets.GetObjectTarget();
}
-Unit* SpellScript::GetExplTargetUnit()
+Unit* SpellScript::GetExplTargetUnit() const
{
return m_spell->m_targets.GetUnitTarget();
}
-GameObject* SpellScript::GetExplTargetGObj()
+GameObject* SpellScript::GetExplTargetGObj() const
{
return m_spell->m_targets.GetGOTarget();
}
-Item* SpellScript::GetExplTargetItem()
+Item* SpellScript::GetExplTargetItem() const
{
return m_spell->m_targets.GetItemTarget();
}
-Unit* SpellScript::GetHitUnit()
+Unit* SpellScript::GetHitUnit() const
{
if (!IsInTargetHook())
{
@@ -464,7 +480,7 @@ Unit* SpellScript::GetHitUnit()
return m_spell->unitTarget;
}
-Creature* SpellScript::GetHitCreature()
+Creature* SpellScript::GetHitCreature() const
{
if (!IsInTargetHook())
{
@@ -477,7 +493,7 @@ Creature* SpellScript::GetHitCreature()
return nullptr;
}
-Player* SpellScript::GetHitPlayer()
+Player* SpellScript::GetHitPlayer() const
{
if (!IsInTargetHook())
{
@@ -490,7 +506,7 @@ Player* SpellScript::GetHitPlayer()
return nullptr;
}
-Item* SpellScript::GetHitItem()
+Item* SpellScript::GetHitItem() const
{
if (!IsInTargetHook())
{
@@ -500,7 +516,7 @@ Item* SpellScript::GetHitItem()
return m_spell->itemTarget;
}
-GameObject* SpellScript::GetHitGObj()
+GameObject* SpellScript::GetHitGObj() const
{
if (!IsInTargetHook())
{
@@ -510,7 +526,7 @@ GameObject* SpellScript::GetHitGObj()
return m_spell->gameObjTarget;
}
-WorldLocation* SpellScript::GetHitDest()
+WorldLocation* SpellScript::GetHitDest() const
{
if (!IsInEffectHook())
{
@@ -520,7 +536,7 @@ WorldLocation* SpellScript::GetHitDest()
return m_spell->destTarget;
}
-int32 SpellScript::GetHitDamage()
+int32 SpellScript::GetHitDamage() const
{
if (!IsInTargetHook())
{
@@ -532,7 +548,7 @@ int32 SpellScript::GetHitDamage()
void SpellScript::SetHitDamage(int32 damage)
{
- if (!IsInTargetHook())
+ if (!IsInModifiableHook())
{
TC_LOG_ERROR("scripts", "Script: `%s` Spell: `%u`: function SpellScript::SetHitDamage was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
return;
@@ -540,7 +556,7 @@ void SpellScript::SetHitDamage(int32 damage)
m_spell->m_damage = damage;
}
-int32 SpellScript::GetHitHeal()
+int32 SpellScript::GetHitHeal() const
{
if (!IsInTargetHook())
{
@@ -552,7 +568,7 @@ int32 SpellScript::GetHitHeal()
void SpellScript::SetHitHeal(int32 heal)
{
- if (!IsInTargetHook())
+ if (!IsInModifiableHook())
{
TC_LOG_ERROR("scripts", "Script: `%s` Spell: `%u`: function SpellScript::SetHitHeal was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
return;
@@ -560,7 +576,7 @@ void SpellScript::SetHitHeal(int32 heal)
m_spell->m_healing = heal;
}
-Aura* SpellScript::GetHitAura()
+Aura* SpellScript::GetHitAura() const
{
if (!IsInTargetHook())
{
@@ -628,7 +644,7 @@ void SpellScript::SetEffectValue(int32 value)
m_spell->damage = value;
}
-Item* SpellScript::GetCastItem()
+Item* SpellScript::GetCastItem() const
{
return m_spell->m_CastItem;
}
@@ -638,7 +654,7 @@ void SpellScript::CreateItem(uint32 effIndex, uint32 itemId)
m_spell->DoCreateItem(effIndex, itemId);
}
-SpellInfo const* SpellScript::GetTriggeringSpell()
+SpellInfo const* SpellScript::GetTriggeringSpell() const
{
return m_spell->m_triggeredByAuraSpell;
}
@@ -660,7 +676,7 @@ void SpellScript::SetCustomCastResultMessage(SpellCustomErrors result)
m_spell->m_customError = result;
}
-SpellValue const* SpellScript::GetSpellValue()
+SpellValue const* SpellScript::GetSpellValue() const
{
return m_spell->m_spellValue;
}
diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h
index 946a6bb5b1f..1f76a3a5b59 100644
--- a/src/server/game/Spells/SpellScript.h
+++ b/src/server/game/Spells/SpellScript.h
@@ -295,6 +295,7 @@ class TC_GAME_API SpellScript : public _SpellScript
void _FinishScriptCall();
bool IsInCheckCastHook() const;
bool IsInTargetHook() const;
+ bool IsInModifiableHook() const;
bool IsInHitPhase() const;
bool IsInEffectHook() const;
private:
@@ -375,10 +376,10 @@ class TC_GAME_API SpellScript : public _SpellScript
// methods allowing interaction with Spell object
//
// methods useable during all spell handling phases
- Unit* GetCaster();
- Unit* GetOriginalCaster();
- SpellInfo const* GetSpellInfo();
- SpellValue const* GetSpellValue();
+ Unit* GetCaster() const;
+ Unit* GetOriginalCaster() const;
+ SpellInfo const* GetSpellInfo() const;
+ SpellValue const* GetSpellValue() const;
// methods useable after spell is prepared
// accessors to the explicit targets of the spell
@@ -392,48 +393,48 @@ class TC_GAME_API SpellScript : public _SpellScript
// - ImplicitTargetXX set to TARGET_XXX_TARGET_YYY, _TARGET_ here means that explicit target is used by the effect, so spell needs one too
// returns: WorldLocation which was selected as a spell destination or NULL
- WorldLocation const* GetExplTargetDest();
+ WorldLocation const* GetExplTargetDest() const;
void SetExplTargetDest(WorldLocation& loc);
// returns: WorldObject which was selected as an explicit spell target or NULL if there's no target
- WorldObject* GetExplTargetWorldObject();
+ WorldObject* GetExplTargetWorldObject() const;
// returns: Unit which was selected as an explicit spell target or NULL if there's no target
- Unit* GetExplTargetUnit();
+ Unit* GetExplTargetUnit() const;
// returns: GameObject which was selected as an explicit spell target or NULL if there's no target
- GameObject* GetExplTargetGObj();
+ GameObject* GetExplTargetGObj() const;
// returns: Item which was selected as an explicit spell target or NULL if there's no target
- Item* GetExplTargetItem();
+ Item* GetExplTargetItem() const;
// 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();
+ Unit* GetHitUnit() const;
// returns: target of current effect if it was Creature otherwise NULL
- Creature* GetHitCreature();
+ Creature* GetHitCreature() const;
// returns: target of current effect if it was Player otherwise NULL
- Player* GetHitPlayer();
+ Player* GetHitPlayer() const;
// returns: target of current effect if it was Item otherwise NULL
- Item* GetHitItem();
+ Item* GetHitItem() const;
// returns: target of current effect if it was GameObject otherwise NULL
- GameObject* GetHitGObj();
+ GameObject* GetHitGObj() const;
// returns: destination of current effect
- WorldLocation* GetHitDest();
+ WorldLocation* GetHitDest() const;
// setter/getter for for damage done by spell to target of spell hit
// returns damage calculated before hit, and real dmg done after hit
- int32 GetHitDamage();
+ int32 GetHitDamage() const;
void SetHitDamage(int32 damage);
void PreventHitDamage() { SetHitDamage(0); }
// setter/getter for for heal done by spell to target of spell hit
// returns healing calculated before hit, and real dmg done after hit
- int32 GetHitHeal();
+ int32 GetHitHeal() const;
void SetHitHeal(int32 heal);
void PreventHitHeal() { SetHitHeal(0); }
- Spell* GetSpell() { return m_spell; }
+ Spell* GetSpell() const { return m_spell; }
// returns current spell hit target aura
- Aura* GetHitAura();
+ Aura* GetHitAura() const;
// prevents applying aura on current spell hit target
void PreventHitAura();
@@ -453,13 +454,13 @@ class TC_GAME_API SpellScript : public _SpellScript
void SetEffectValue(int32 value);
// returns: cast item if present.
- Item* GetCastItem();
+ Item* GetCastItem() const;
// Creates item. Calls Spell::DoCreateItem method.
void CreateItem(uint32 effIndex, uint32 itemId);
// Returns SpellInfo from the spell that triggered the current one
- SpellInfo const* GetTriggeringSpell();
+ SpellInfo const* GetTriggeringSpell() const;
// finishes spellcast prematurely with selected error message
void FinishCast(SpellCastResult result, uint32* param1 = nullptr, uint32* param2 = nullptr);