mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-11 11:31:52 +02:00
Introduce calculateHealedHP again, now in better place.
This commit is contained in:
parent
0929e009db
commit
9ed9075afc
@ -17,32 +17,8 @@
|
||||
///HealingSpellMechanics
|
||||
void HealingSpellMechanics::applyBattleEffects(const SpellCastEnvironment* env, BattleSpellCastParameters& parameters, SpellCastContext& ctx) const
|
||||
{
|
||||
int effectLevel = calculateEffectLevel(parameters);
|
||||
int hpGained = 0;
|
||||
EHealLevel healLevel = getHealLevel(effectLevel);
|
||||
|
||||
if(owner->id == SpellID::SACRIFICE)
|
||||
{
|
||||
if(nullptr == parameters.selectedStack)
|
||||
env->complain("No stack to sacrifice.");
|
||||
else
|
||||
hpGained = (parameters.usedSpellPower + parameters.selectedStack->MaxHealth() + owner->getPower(effectLevel)) * parameters.selectedStack->count;
|
||||
}
|
||||
else if(parameters.casterStack)
|
||||
{
|
||||
int unitSpellPower = parameters.casterStack->valOfBonuses(Bonus::SPECIFIC_SPELL_POWER, owner->id.toEnum());
|
||||
if(unitSpellPower)
|
||||
hpGained = parameters.casterStack->count * unitSpellPower; //Archangel
|
||||
else //Faerie Dragon-like effect - commanders(?)
|
||||
{
|
||||
parameters.usedSpellPower = parameters.casterStack->valOfBonuses(Bonus::CREATURE_SPELL_POWER) * parameters.casterStack->count / 100;
|
||||
hpGained = parameters.usedSpellPower * owner->power + owner->getPower(effectLevel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hpGained = parameters.usedSpellPower * owner->power + owner->getPower(effectLevel); //???
|
||||
}
|
||||
EHealLevel healLevel = getHealLevel(ctx.effectLevel);
|
||||
int hpGained = calculateHealedHP(env, parameters, ctx);
|
||||
StacksHealedOrResurrected shr;
|
||||
shr.lifeDrain = false;
|
||||
shr.tentHealing = false;
|
||||
@ -58,15 +34,34 @@ void HealingSpellMechanics::applyBattleEffects(const SpellCastEnvironment* env,
|
||||
}
|
||||
else
|
||||
{
|
||||
int stackHPgained = parameters.casterHero->getSpellBonus(owner, hpGained, attackedCre);
|
||||
hi.healedHP = attackedCre->calculateHealedHealthPoints(stackHPgained, resurrect);
|
||||
int stackHPgained = parameters.casterHero->getSpellBonus(owner, hpGained, attackedCre);
|
||||
hi.healedHP = attackedCre->calculateHealedHealthPoints(stackHPgained, resurrect);
|
||||
}
|
||||
|
||||
|
||||
hi.lowLevelResurrection = (healLevel == EHealLevel::RESURRECT);
|
||||
shr.healedStacks.push_back(hi);
|
||||
}
|
||||
if(!shr.healedStacks.empty())
|
||||
env->sendAndApply(&shr);
|
||||
env->sendAndApply(&shr);
|
||||
}
|
||||
|
||||
int HealingSpellMechanics::calculateHealedHP(const SpellCastEnvironment* env, const BattleSpellCastParameters& parameters, const SpellCastContext& ctx) const
|
||||
{
|
||||
if(parameters.casterStack)
|
||||
{
|
||||
int unitSpellPower = parameters.casterStack->valOfBonuses(Bonus::SPECIFIC_SPELL_POWER, owner->id.toEnum());
|
||||
if(unitSpellPower)
|
||||
return parameters.casterStack->count * unitSpellPower; //Archangel
|
||||
else //Faerie Dragon-like effect - commanders(?)
|
||||
{
|
||||
int spellPower = parameters.casterStack->valOfBonuses(Bonus::CREATURE_SPELL_POWER) * parameters.casterStack->count / 100;
|
||||
return spellPower * owner->power + owner->getPower(ctx.effectLevel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return parameters.usedSpellPower * owner->power + owner->getPower(ctx.effectLevel); //???
|
||||
}
|
||||
}
|
||||
|
||||
///AntimagicMechanics
|
||||
@ -588,6 +583,15 @@ void SacrificeMechanics::applyBattleEffects(const SpellCastEnvironment * env, Ba
|
||||
env->sendAndApply(&bsr);
|
||||
}
|
||||
|
||||
int SacrificeMechanics::calculateHealedHP(const SpellCastEnvironment* env, const BattleSpellCastParameters& parameters, const SpellCastContext& ctx) const
|
||||
{
|
||||
int res = 0;
|
||||
if(nullptr == parameters.selectedStack)
|
||||
env->complain("No stack to sacrifice.");
|
||||
else
|
||||
res = (parameters.usedSpellPower + parameters.selectedStack->MaxHealth() + owner->getPower(ctx.effectLevel)) * parameters.selectedStack->count;
|
||||
return res;
|
||||
}
|
||||
|
||||
///SpecialRisingSpellMechanics
|
||||
ESpellCastProblem::ESpellCastProblem SpecialRisingSpellMechanics::isImmuneByStack(const CGHeroInstance * caster, const CStack * obj) const
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
HealingSpellMechanics(CSpell * s): DefaultSpellMechanics(s){};
|
||||
protected:
|
||||
void applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const override;
|
||||
|
||||
virtual int calculateHealedHP(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, const SpellCastContext & ctx) const;
|
||||
virtual EHealLevel getHealLevel(int effectLevel) const = 0;
|
||||
};
|
||||
|
||||
@ -130,6 +130,7 @@ public:
|
||||
ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const override;
|
||||
protected:
|
||||
void applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const override;
|
||||
int calculateHealedHP(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, const SpellCastContext & ctx) const override;
|
||||
};
|
||||
|
||||
///all rising spells but SACRIFICE
|
||||
|
@ -316,6 +316,7 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
|
||||
|
||||
StacksInjured si;
|
||||
SpellCastContext ctx(attackedCres, sc, si);
|
||||
ctx.effectLevel = calculateEffectLevel(parameters);
|
||||
|
||||
applyBattleEffects(env, parameters, ctx);
|
||||
|
||||
@ -515,7 +516,6 @@ int DefaultSpellMechanics::calculateEffectLevel(const BattleSpellCastParameters&
|
||||
|
||||
void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
|
||||
{
|
||||
int effectLevel = calculateEffectLevel(parameters);
|
||||
//applying effects
|
||||
if(owner->isOffensiveSpell())
|
||||
{
|
||||
@ -537,7 +537,7 @@ void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env,
|
||||
if(spellDamage)
|
||||
bsa.damageAmount = spellDamage >> chainLightningModifier;
|
||||
else
|
||||
bsa.damageAmount = owner->calculateDamage(parameters.casterHero, attackedCre, effectLevel, parameters.usedSpellPower) >> chainLightningModifier;
|
||||
bsa.damageAmount = owner->calculateDamage(parameters.casterHero, attackedCre, ctx.effectLevel, parameters.usedSpellPower) >> chainLightningModifier;
|
||||
|
||||
ctx.sc.dmgToDisplay += bsa.damageAmount;
|
||||
|
||||
@ -568,7 +568,7 @@ void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env,
|
||||
{
|
||||
int maxDuration = 0;
|
||||
std::vector<Bonus> tmp;
|
||||
owner->getEffects(tmp, effectLevel);
|
||||
owner->getEffects(tmp, ctx.effectLevel);
|
||||
for(Bonus& b : tmp)
|
||||
{
|
||||
//use configured duration if present
|
||||
|
@ -22,7 +22,8 @@ struct SpellCastContext
|
||||
attackedCres(attackedCres), sc(sc), si(si){};
|
||||
std::vector<const CStack *> & attackedCres;
|
||||
BattleSpellCast & sc;
|
||||
StacksInjured & si;
|
||||
StacksInjured & si;
|
||||
int effectLevel;
|
||||
};
|
||||
|
||||
enum class ESpellCastResult
|
||||
|
Loading…
x
Reference in New Issue
Block a user