Core/ScriptSystem: AfterHit hook can't modify damage/healing, so log it

- Also added const to getter members
This commit is contained in:
ariel-
2018-02-05 14:43:11 -03:00
parent 650a92dc9f
commit ed931cfa19
2 changed files with 60 additions and 43 deletions

View File

@@ -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;
}