1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Extract general dispell logic

This commit is contained in:
AlexVinS 2015-04-11 16:27:14 +03:00
parent b8b9abcc08
commit 0134266fa1
4 changed files with 23 additions and 43 deletions

View File

@ -19,16 +19,7 @@ void AntimagicMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast
{
DefaultSpellMechanics::applyBattle(battle, packet);
for(auto stackID : packet->affectedCres)
{
if(vstd::contains(packet->resisted, stackID))
{
logGlobal->errorStream() << "Resistance to positive spell " << owner->name;
continue;
}
CStack * s = battle->getStack(stackID);
s->popBonuses([&](const Bonus *b) -> bool
doDispell(battle, packet, [this](const Bonus * b) -> bool
{
if(b->source == Bonus::SPELL_EFFECT)
{
@ -36,7 +27,6 @@ void AntimagicMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast
}
return false; //not a spell effect
});
}
}
///ChainLightningMechanics
@ -163,21 +153,7 @@ void CureMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * pac
void DispellMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const
{
DefaultSpellMechanics::applyBattle(battle, packet);
for(auto stackID : packet->affectedCres)
{
if(vstd::contains(packet->resisted, stackID))
{
logGlobal->errorStream() << "Resistance to DISPELL";
continue;
}
CStack *s = battle->getStack(stackID);
s->popBonuses([&](const Bonus *b) -> bool
{
return Selector::sourceType(Bonus::SPELL_EFFECT)(b);
});
}
doDispell(battle, packet, Selector::sourceType(Bonus::SPELL_EFFECT));
}
ESpellCastProblem::ESpellCastProblem DispellMechanics::isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const

View File

@ -723,3 +723,15 @@ ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::isImmuneByStack(cons
//by default use general algorithm
return owner->isImmuneBy(obj);
}
void DefaultSpellMechanics::doDispell(BattleInfo * battle, const BattleSpellCast * packet, const CSelector & selector) const
{
for(auto stackID : packet->affectedCres)
{
if(vstd::contains(packet->resisted, stackID))
continue;
CStack *s = battle->getStack(stackID);
s->popBonuses(selector);
}
}

View File

@ -51,4 +51,6 @@ protected:
///actual adventure cast implementation
virtual bool applyAdventureEffects(const SpellCastEnvironment * env, AdventureSpellCastParameters & parameters) const;
void doDispell(BattleInfo * battle, const BattleSpellCast * packet, const CSelector & selector) const;
};

View File

@ -60,17 +60,7 @@ void DispellHelpfulMechanics::applyBattle(BattleInfo * battle, const BattleSpell
{
DefaultSpellMechanics::applyBattle(battle, packet);
for(auto stackID : packet->affectedCres)
{
if(vstd::contains(packet->resisted, stackID))
continue;
CStack *s = battle->getStack(stackID);
s->popBonuses([&](const Bonus *b) -> bool
{
return Selector::positiveSpellEffects(b);
});
}
doDispell(battle, packet, Selector::positiveSpellEffects);
}
ESpellCastProblem::ESpellCastProblem DispellHelpfulMechanics::isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const