1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Implemented spell countering.

This commit is contained in:
Michał W. Urbańczyk
2012-09-13 23:41:03 +00:00
parent 96a92d0f45
commit 74f9c19a7c
4 changed files with 40 additions and 27 deletions

View File

@@ -1239,20 +1239,28 @@ DLL_LINKAGE void BattleSpellCast::applyGs( CGameState *gs )
}
}
if(id == 35 || id == 78) //dispel and dispel helpful spells
//Handle spells removing effects from stacks
const CSpell *spell = VLC->spellh->spells[id];
const bool removeAllSpells = id == Spells::DISPEL;
const bool removeHelpful = id == Spells::DISPEL_HELPFUL_SPELLS;
BOOST_FOREACH(auto stackID, affectedCres)
{
bool onlyHelpful = id == 78;
for(std::set<ui32>::const_iterator it = affectedCres.begin(); it != affectedCres.end(); ++it)
if(vstd::contains(resisted, stackID))
continue;
CStack *s = gs->curB->getStack(stackID);
s->popBonuses([&](const Bonus *b) -> bool
{
CStack *s = gs->curB->getStack(*it);
if(s && !vstd::contains(resisted, s->ID)) //if stack exists and it didn't resist
{
if(onlyHelpful)
s->popBonuses(Selector::positiveSpellEffects);
else
s->popBonuses(Selector::sourceType(Bonus::SPELL_EFFECT));
}
}
//check for each bonus if it should be removed
const bool isSpellEffect = Selector::sourceType(Bonus::SPELL_EFFECT)(b);
const bool isPositiveSpell = Selector::positiveSpellEffects(b);
const int spellID = isSpellEffect ? b->sid : -1;
return (removeHelpful && isPositiveSpell)
|| (removeAllSpells && isSpellEffect)
|| vstd::contains(spell->counteredSpells, spellID);
});
}
}