1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

WIP on SpellCastContext

This commit is contained in:
AlexVinS 2016-09-06 05:11:32 +03:00
parent 1d840a33a5
commit 9ee954edcc
3 changed files with 37 additions and 17 deletions

View File

@ -136,6 +136,26 @@ void SpellCastContext::prepareBattleCast(const BattleSpellCastParameters & param
sc.manaGained = 0;
}
void SpellCastContext::addDamageToDisplay(const si32 value)
{
sc.dmgToDisplay += value;
}
void SpellCastContext::setDamageToDisplay(const si32 value)
{
sc.dmgToDisplay = value;
}
void SpellCastContext::sendCastPacket(const SpellCastEnvironment * env)
{
for(auto sta : attackedCres)
{
sc.affectedCres.insert(sta->ID);
}
env->sendAndApply(&sc);
}
///DefaultSpellMechanics
void DefaultSpellMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast * packet) const
{
@ -234,13 +254,9 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
}
}
for(auto cre : ctx.attackedCres)
{
ctx.sc.affectedCres.insert(cre->ID);
}
applyBattleEffects(env, parameters, ctx);
env->sendAndApply(&ctx.sc);
ctx.sendCastPacket(env);
if(parameters.mode == ECastingMode::HERO_CASTING)
{
@ -421,7 +437,7 @@ void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env,
else
bsa.damageAmount = owner->calculateDamage(parameters.caster, attackedCre, parameters.effectLevel, parameters.effectPower) >> chainLightningModifier;
ctx.sc.dmgToDisplay += bsa.damageAmount;
ctx.addDamageToDisplay(bsa.damageAmount);
bsa.stackAttacked = (attackedCre)->ID;
if(parameters.mode == ECastingMode::ENCHANTER_CASTING) //multiple damage spells cast
@ -720,14 +736,10 @@ void DefaultSpellMechanics::castMagicMirror(const SpellCastEnvironment* env, Bat
handleResistance(env, ctx.attackedCres, ctx.sc);
for(auto cre : ctx.attackedCres)
{
ctx.sc.affectedCres.insert(cre->ID);
}
applyBattleEffects(env, parameters, ctx);
env->sendAndApply(&ctx.sc);
ctx.sendCastPacket(env);
if(!ctx.si.stacks.empty()) //after spellcast info shows
env->sendAndApply(&ctx.si);

View File

@ -20,10 +20,15 @@ class SpellCastContext
public:
const DefaultSpellMechanics * mechanics;
std::vector<const CStack *> attackedCres;//must be vector, as in Chain Lightning order matters
BattleSpellCast sc;
BattleSpellCast sc;//todo: make private
StacksInjured si;
SpellCastContext(const DefaultSpellMechanics * mechanics_, const BattleSpellCastParameters & parameters);
void addDamageToDisplay(const si32 value);
void setDamageToDisplay(const si32 value);
void sendCastPacket(const SpellCastEnvironment * env);
private:
void prepareBattleCast(const BattleSpellCastParameters & parameters);
};

View File

@ -20,7 +20,7 @@ void AcidBreathDamageMechanics::applyBattleEffects(const SpellCastEnvironment *
{
//todo: this should be effectValue
//calculating dmg to display
ctx.sc.dmgToDisplay = parameters.effectPower;
ctx.setDamageToDisplay(parameters.effectPower);
for(auto & attackedCre : ctx.attackedCres) //no immunities
{
@ -39,9 +39,12 @@ void AcidBreathDamageMechanics::applyBattleEffects(const SpellCastEnvironment *
void DeathStareMechanics::applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
{
//calculating dmg to display
ctx.sc.dmgToDisplay = parameters.effectPower;
si32 dmgToDisplay = parameters.effectPower;
if(!ctx.attackedCres.empty())
vstd::amin(ctx.sc.dmgToDisplay, (*ctx.attackedCres.begin())->count); //stack is already reduced after attack
vstd::amin(dmgToDisplay, (*ctx.attackedCres.begin())->count); //stack is already reduced after attack
ctx.setDamageToDisplay(dmgToDisplay);
for(auto & attackedCre : ctx.attackedCres)
{