1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Allow custom effect animation on any stack during spell cast.

This commit is contained in:
AlexVinS 2015-09-14 06:21:49 +03:00
parent 0f0e67dbe3
commit caf8ae62cc
3 changed files with 30 additions and 9 deletions

View File

@ -1307,11 +1307,11 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
displaySpellEffect(spellID, position);
}
//queuing resist animation
for(auto & elem : sc->resisted)
//queuing additional animation
for(auto & elem : sc->customEffects)
{
BattleHex position = curInt->cb->battleGetStackByID(elem, false)->position;
displayEffect(78, position);
BattleHex position = curInt->cb->battleGetStackByID(elem.stack, false)->position;
displayEffect(elem.effect, position);
}
//displaying message in console

View File

@ -1478,6 +1478,18 @@ struct EndAction : public CPackForClient//3008
struct BattleSpellCast : public CPackForClient//3009
{
///custom effect (resistance, reflection, etc)
struct CustomEffect
{
/// WoG AC format
ui32 effect;
ui32 stack;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & effect & stack;
}
};
BattleSpellCast(){type = 3009; casterStack = -1;};
DLL_LINKAGE void applyGs(CGameState *gs);
void applyCl(CClient *cl);
@ -1488,13 +1500,13 @@ struct BattleSpellCast : public CPackForClient//3009
ui8 skill; //caster's skill level
ui8 manaGained; //mana channeling ability
BattleHex tile; //destination tile (may not be set in some global/mass spells
std::vector<ui32> resisted; //ids of creatures that resisted this spell
std::vector<CustomEffect> customEffects;
std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
si32 casterStack;// -1 if not cated by creature, >=0 caster stack ID
bool castByHero; //if true - spell has been casted by hero, otherwise by a creature
template <typename Handler> void serialize(Handler &h, const int version)
{
h & dmgToDisplay & side & id & skill & manaGained & tile & resisted & affectedCres & casterStack & castByHero;
h & dmgToDisplay & side & id & skill & manaGained & tile & customEffects & affectedCres & casterStack & castByHero;
}
};

View File

@ -265,20 +265,29 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
//resistance is applied only to negative spells
if(owner->isNegative())
{
std::vector <const CStack*> resisted;
for(auto s : attackedCres)
{
const int prob = std::min((s)->magicResistance(), 100); //probability of resistance in %
if(env->getRandomGenerator().nextInt(99) < prob)
{
sc.resisted.push_back(s->ID);
resisted.push_back(s);
}
}
vstd::erase_if(attackedCres, [&sc](const CStack * s)
vstd::erase_if(attackedCres, [&resisted](const CStack * s)
{
return vstd::contains(sc.resisted, s->ID);
return vstd::contains(resisted, s);
});
for(auto s : resisted)
{
BattleSpellCast::CustomEffect effect;
effect.effect = 78;
effect.stack = s->ID;
sc.customEffects.push_back(effect);
}
}
for(auto cre : attackedCres)