diff options
| author | QAston <none@none> | 2010-07-24 22:41:42 +0200 |
|---|---|---|
| committer | QAston <none@none> | 2010-07-24 22:41:42 +0200 |
| commit | 2352fc7cdfff0e677f6516c0ab2b91d3efc9ab70 (patch) | |
| tree | 470b0d66f513cb62b6be88863003408864d117ae /src/server/game/Spells/Spell.cpp | |
| parent | 687cd83bddfbc5416ba11bff53c8a636747a5802 (diff) | |
*Add base scripting interfce for spells - thanks to Brian for help in making it compile with GCC.
*Add hook for handling spell effects in new scripting system.
--HG--
branch : trunk
Diffstat (limited to 'src/server/game/Spells/Spell.cpp')
| -rw-r--r-- | src/server/game/Spells/Spell.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index a53142bf296..eb7c2c9b4fa 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -52,6 +52,7 @@ #include "ScriptMgr.h" #include "ConditionMgr.h" #include "DisableMgr.h" +#include "SpellScript.h" #define SPELL_CHANNEL_UPDATE_INTERVAL (1 * IN_MILLISECONDS) @@ -455,6 +456,14 @@ Spell::Spell(Unit* Caster, SpellEntry const *info, bool triggered, uint64 origin Spell::~Spell() { + // unload scripts + while(!m_loadedScripts.empty()) + { + std::list<SpellScript *>::iterator itr = m_loadedScripts.begin(); + (*itr)->Unload(); + delete (*itr); + m_loadedScripts.erase(itr); + } if (m_referencedFromCurrentSpell && m_selfContainer && *m_selfContainer == this) { // Clean the reference to avoid later crash. @@ -2748,6 +2757,7 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const * triggere finish(false); return; } + LoadScripts(); if (m_caster->GetTypeId() == TYPEID_PLAYER) m_caster->ToPlayer()->SetSpellModTakingSpell(this, true); @@ -4479,7 +4489,6 @@ void Spell::HandleThreatSpells(uint32 spellId) void Spell::HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i) { - if (!sScriptMgr.OnSpellCast(pUnitTarget,pItemTarget,pGOTarget,i,m_spellInfo)) return; @@ -4495,12 +4504,21 @@ void Spell::HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTar sLog.outDebug("Spell: %u Effect : %u", m_spellInfo->Id, eff); + for(std::list<SpellScript *>::iterator scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end() ; ++scritr) + { + std::list<SpellScript::EffectHandler>::iterator effEndItr = (*scritr)->EffectHandlers.end(), effItr = (*scritr)->EffectHandlers.begin(); + for(; effItr != effEndItr ; ++effItr) + { + if ((*effItr).IsEffectAffected(m_spellInfo, i)) + (*effItr).Call(*scritr, (SpellEffIndex)i); + } + } + //we do not need DamageMultiplier here. damage = CalculateDamage(i, NULL); if (eff < TOTAL_SPELL_EFFECTS) { - //sLog.outDebug("WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff); (this->*SpellEffects[eff])(i); } } @@ -7076,3 +7094,21 @@ void Spell::SelectTrajTargets() m_targets.setDst(x, y, z, m_caster->GetOrientation()); } } + +void Spell::LoadScripts() +{ + sLog.outError("Spell::LoadScripts"); + sScriptMgr.CreateSpellScripts(m_spellInfo->Id, m_loadedScripts); + for(std::list<SpellScript *>::iterator itr = m_loadedScripts.begin(); itr != m_loadedScripts.end() ;) + { + if (!(*itr)->_Load(this)) + { + std::list<SpellScript *>::iterator bitr = itr; + ++itr; + m_loadedScripts.erase(bitr); + continue; + } + (*itr)->Register(); + ++itr; + } +} |
