[8197] Use more similar code for triggered and precast spells.

Also better error reporting at not existed spells.
Clear use in comments for this 2 dependent cast ways.
This commit is contained in:
VladimirMangos 2009-07-18 21:20:33 +04:00
parent 49b201e22b
commit 9c91796443
4 changed files with 50 additions and 19 deletions

View file

@ -1238,12 +1238,7 @@ void Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask)
unit->IncrDiminishing(m_diminishGroup);
// Apply additional spell effects to target
while (!m_preCastSpells.empty())
{
uint32 spellId = *m_preCastSpells.begin();
m_caster->CastSpell(unit, spellId, true, m_CastItem);
m_preCastSpells.erase(m_preCastSpells.begin());
}
CastPreCastSpells(unit);
for(uint32 effectNumber = 0; effectNumber < 3; ++effectNumber)
{
@ -2283,6 +2278,7 @@ void Spell::cast(bool skipCheck)
}
}
// different triggred (for caster) and precast (casted before apply effect to target) cases
switch(m_spellInfo->SpellFamilyName)
{
case SPELLFAMILY_GENERIC:
@ -2765,7 +2761,7 @@ void Spell::finish(bool ok)
// call triggered spell only at successful cast (after clear combo points -> for add some if need)
if(!m_TriggerSpells.empty())
TriggerSpell();
CastTriggerSpells();
// Stop Attack for some spells
if( m_spellInfo->Attributes & SPELL_ATTR_STOP_ATTACK_TARGET )
@ -3604,15 +3600,48 @@ void Spell::HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTar
*/
}
void Spell::TriggerSpell()
void Spell::AddTriggeredSpell( uint32 spellId )
{
for(TriggerSpells::const_iterator si=m_TriggerSpells.begin(); si!=m_TriggerSpells.end(); ++si)
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId );
if(!spellInfo)
{
sLog.outError("Spell::AddTriggeredSpell: unknown spell id %u used as triggred spell for spell %u)", spellId, m_spellInfo->Id);
return;
}
m_TriggerSpells.push_back(spellInfo);
}
void Spell::AddPrecastSpell( uint32 spellId )
{
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId );
if(!spellInfo)
{
sLog.outError("Spell::AddPrecastSpell: unknown spell id %u used as pre-cast spell for spell %u)", spellId, m_spellInfo->Id);
return;
}
m_preCastSpells.push_back(spellInfo);
}
void Spell::CastTriggerSpells()
{
for(SpellInfoList::const_iterator si=m_TriggerSpells.begin(); si!=m_TriggerSpells.end(); ++si)
{
Spell* spell = new Spell(m_caster, (*si), true, m_originalCasterGUID, m_selfContainer);
spell->prepare(&m_targets); // use original spell original targets
}
}
void Spell::CastPreCastSpells(Unit* target)
{
for(SpellInfoList::const_iterator si=m_preCastSpells.begin(); si!=m_preCastSpells.end(); ++si)
m_caster->CastSpell(target, (*si), true, m_CastItem);
}
SpellCastResult Spell::CheckCast(bool strict)
{
// check cooldowns to prevent cheating
@ -5802,4 +5831,4 @@ void Spell::FillRaidOrPartyHealthPriorityTargets( UnitList &TagUnitMap, Unit* ta
TagUnitMap.push_back(healthQueue.top().getUnit());
healthQueue.pop();
}
}
}

View file

@ -333,7 +333,6 @@ class Spell
void TakeRunePower();
void TakeReagents();
void TakeCastItem();
void TriggerSpell();
SpellCastResult CheckCast(bool strict);
SpellCastResult CheckPetCast(Unit* target);
@ -438,8 +437,12 @@ class Spell
bool CheckTargetCreatureType(Unit* target) const;
void AddTriggeredSpell(SpellEntry const* spell) { m_TriggerSpells.push_back(spell); }
void AddPrecastSpell(uint32 spellId) { m_preCastSpells.push_back(spellId); }
void AddTriggeredSpell(SpellEntry const* spellInfo) { m_TriggerSpells.push_back(spellInfo); }
void AddPrecastSpell(SpellEntry const* spellInfo) { m_preCastSpells.push_back(spellInfo); }
void AddTriggeredSpell(uint32 spellId);
void AddPrecastSpell(uint32 spellId);
void CastPreCastSpells(Unit* target);
void CastTriggerSpells();
void CleanupTargetList();
protected:
@ -558,10 +561,9 @@ class Spell
// -------------------------------------------
//List For Triggered Spells
typedef std::list<SpellEntry const*> TriggerSpells;
typedef std::list<uint32> SpellPrecasts;
TriggerSpells m_TriggerSpells;
SpellPrecasts m_preCastSpells;
typedef std::list<SpellEntry const*> SpellInfoList;
SpellInfoList m_TriggerSpells; // casted by caster to same targets settings in m_targets at success finish of current spell
SpellInfoList m_preCastSpells; // casted by caster to each target at spell hit before spell effects apply
uint32 m_spellState;
uint32 m_timer;

View file

@ -2034,7 +2034,7 @@ void Spell::EffectTriggerSpell(uint32 i)
m_caster->CastSpell(unitTarget,spellInfo,true,m_CastItem,NULL,m_originalCasterGUID);
}
else
m_TriggerSpells.push_back(spellInfo);
AddTriggeredSpell(spellInfo);
}
void Spell::EffectTriggerMissileSpell(uint32 effect_idx)

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "8196"
#define REVISION_NR "8197"
#endif // __REVISION_NR_H__