1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-27 12:22:45 +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

@ -19,16 +19,7 @@ void AntimagicMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast
{ {
DefaultSpellMechanics::applyBattle(battle, packet); DefaultSpellMechanics::applyBattle(battle, packet);
for(auto stackID : packet->affectedCres) doDispell(battle, packet, [this](const Bonus * b) -> bool
{
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
{ {
if(b->source == Bonus::SPELL_EFFECT) if(b->source == Bonus::SPELL_EFFECT)
{ {
@ -37,7 +28,6 @@ void AntimagicMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast
return false; //not a spell effect return false; //not a spell effect
}); });
} }
}
///ChainLightningMechanics ///ChainLightningMechanics
std::set<const CStack *> ChainLightningMechanics::getAffectedStacks(SpellTargetingContext & ctx) const std::set<const CStack *> ChainLightningMechanics::getAffectedStacks(SpellTargetingContext & ctx) const
@ -163,21 +153,7 @@ void CureMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * pac
void DispellMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const void DispellMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const
{ {
DefaultSpellMechanics::applyBattle(battle, packet); DefaultSpellMechanics::applyBattle(battle, packet);
doDispell(battle, packet, Selector::sourceType(Bonus::SPELL_EFFECT));
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);
});
}
} }
ESpellCastProblem::ESpellCastProblem DispellMechanics::isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const ESpellCastProblem::ESpellCastProblem DispellMechanics::isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const

@ -723,3 +723,15 @@ ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::isImmuneByStack(cons
//by default use general algorithm //by default use general algorithm
return owner->isImmuneBy(obj); 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);
}
}

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

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