aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Spells/Spell.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2011-03-04 21:18:38 +0100
committerShauren <shauren.trinity@gmail.com>2011-03-04 21:19:43 +0100
commit7120f1eff80c9f057a40831a10d8975c0a8a7439 (patch)
treee77c66ff87570d1484b2cf81be6920ad5cd5e7fd /src/server/game/Spells/Spell.cpp
parenta9582964d3ca140a1ec1d5894b79e72ed15a65a6 (diff)
Core/Spells:
* Implemented on CheckCast spell script hook * Added possibility to send SPELL_FAILED_CUSTOM_ERROR and added enum with all possible options for it Scripts/Spells: * Added example script for CheckCast hook with SPELL_FAILED_CUSTOM_ERROR (profession research and Book of Glyph Mastery)
Diffstat (limited to 'src/server/game/Spells/Spell.cpp')
-rwxr-xr-xsrc/server/game/Spells/Spell.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index b89e1167f2c..e1f16e50be0 100755
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -425,6 +425,7 @@ m_spellInfo(sSpellMgr->GetSpellForDifficultyFromSpell(info, Caster)),
m_caster(Caster), m_spellValue(new SpellValue(m_spellInfo))
{
m_customAttr = sSpellMgr->GetSpellCustomAttr(m_spellInfo->Id);
+ m_customError = SPELL_CUSTOM_ERROR_NONE;
m_skipCheck = skipCheck;
m_selfContainer = NULL;
m_referencedFromCurrentSpell = false;
@@ -3742,10 +3743,10 @@ void Spell::SendCastResult(SpellCastResult result)
if (m_caster->ToPlayer()->GetSession()->PlayerLoading()) // don't send cast results at loading time
return;
- SendCastResult((Player*)m_caster,m_spellInfo,m_cast_count,result);
+ SendCastResult(m_caster->ToPlayer(), m_spellInfo, m_cast_count, result, m_customError);
}
-void Spell::SendCastResult(Player* caster, SpellEntry const* spellInfo, uint8 cast_count, SpellCastResult result)
+void Spell::SendCastResult(Player* caster, SpellEntry const* spellInfo, uint8 cast_count, SpellCastResult result, SpellCustomErrors customError /*= SPELL_CUSTOM_ERROR_NONE*/)
{
if (result == SPELL_CAST_OK)
return;
@@ -3807,6 +3808,9 @@ void Spell::SendCastResult(Player* caster, SpellEntry const* spellInfo, uint8 ca
data << uint32(pProto->ItemLimitCategory);
break;
}
+ case SPELL_FAILED_CUSTOM_ERROR:
+ data << uint32(customError);
+ break;
default:
break;
}
@@ -5009,6 +5013,11 @@ SpellCastResult Spell::CheckCast(bool strict)
return castResult;
}
+ // script hook
+ castResult = CallScriptCheckCastHandlers();
+ if (castResult != SPELL_CAST_OK)
+ return castResult;
+
for (int i = 0; i < MAX_SPELL_EFFECTS; i++)
{
// for effects of spells that have only one target
@@ -7216,6 +7225,25 @@ void Spell::PrepareScriptHitHandlers()
(*scritr)->_InitHit();
}
+SpellCastResult Spell::CallScriptCheckCastHandlers()
+{
+ SpellCastResult retVal = SPELL_CAST_OK;
+ for (std::list<SpellScript *>::iterator scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end() ; ++scritr)
+ {
+ (*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_CHECK_CAST);
+ std::list<SpellScript::CheckCastHandler>::iterator hookItrEnd = (*scritr)->OnCheckCast.end(), hookItr = (*scritr)->OnCheckCast.begin();
+ for (; hookItr != hookItrEnd; ++hookItr)
+ {
+ SpellCastResult tempResult = (*hookItr).Call(*scritr);
+ if (retVal == SPELL_CAST_OK)
+ retVal = tempResult;
+ }
+
+ (*scritr)->_FinishScriptCall();
+ }
+ return retVal;
+}
+
bool Spell::CallScriptEffectHandlers(SpellEffIndex effIndex)
{
// execute script effect handler hooks and check if effects was prevented