mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Tweak BattleSpellCastParameters
This commit is contained in:
parent
2b434111bf
commit
660203b436
@ -1219,6 +1219,12 @@ int CStack::getEffectValue(const CSpell * spell) const
|
||||
return valOfBonuses(Bonus::SPECIFIC_SPELL_POWER, spell->id.toEnum()) * count;
|
||||
}
|
||||
|
||||
const PlayerColor CStack::getOwner() const
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
|
||||
|
||||
bool CMP_stack::operator()( const CStack* a, const CStack* b )
|
||||
{
|
||||
switch(phase)
|
||||
|
@ -247,6 +247,8 @@ public:
|
||||
|
||||
///damage/heal override(ignores spell configuration, effect level and effect power)
|
||||
int getEffectValue(const CSpell * spell) const override;
|
||||
|
||||
const PlayerColor getOwner() const override;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
|
@ -925,6 +925,11 @@ int CGHeroInstance::getEffectValue(const CSpell * spell) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
const PlayerColor CGHeroInstance::getOwner() const
|
||||
{
|
||||
return tempOwner;
|
||||
}
|
||||
|
||||
bool CGHeroInstance::canCastThisSpell(const CSpell * spell) const
|
||||
{
|
||||
if(nullptr == getArt(ArtifactPosition::SPELLBOOK))
|
||||
|
@ -222,6 +222,8 @@ public:
|
||||
///damage/heal override(ignores spell configuration, effect level and effect power)
|
||||
int getEffectValue(const CSpell * spell) const override;
|
||||
|
||||
const PlayerColor getOwner() const override;
|
||||
|
||||
void deserializationFix();
|
||||
|
||||
void initObj() override;
|
||||
|
@ -28,7 +28,7 @@ void HealingSpellMechanics::applyBattleEffects(const SpellCastEnvironment* env,
|
||||
{
|
||||
StacksHealedOrResurrected::HealInfo hi;
|
||||
hi.stackID = (attackedCre)->ID;
|
||||
int stackHPgained = ctx.caster->getSpellBonus(owner, hpGained, attackedCre);
|
||||
int stackHPgained = parameters.caster->getSpellBonus(owner, hpGained, attackedCre);
|
||||
hi.healedHP = attackedCre->calculateHealedHealthPoints(stackHPgained, resurrect);
|
||||
hi.lowLevelResurrection = (healLevel == EHealLevel::RESURRECT);
|
||||
shr.healedStacks.push_back(hi);
|
||||
|
@ -231,8 +231,6 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
|
||||
return;
|
||||
}
|
||||
|
||||
const ISpellCaster * caster = parameters.caster;
|
||||
|
||||
BattleSpellCast sc;
|
||||
prepareBattleCast(parameters, sc);
|
||||
|
||||
@ -307,9 +305,6 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
|
||||
|
||||
StacksInjured si;
|
||||
SpellCastContext ctx(attackedCres, sc, si);
|
||||
|
||||
ctx.caster = caster;
|
||||
|
||||
applyBattleEffects(env, parameters, ctx);
|
||||
|
||||
env->sendAndApply(&sc);
|
||||
@ -366,16 +361,16 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
|
||||
{
|
||||
int targetHex = (*RandomGeneratorUtil::nextItem(mirrorTargets, env->getRandomGenerator()))->position;
|
||||
|
||||
BattleSpellCastParameters mirrorParameters = parameters;
|
||||
BattleSpellCastParameters mirrorParameters(parameters.cb, attackedCre, owner);
|
||||
mirrorParameters.spellLvl = 0;
|
||||
mirrorParameters.casterSide = 1-parameters.casterSide;
|
||||
mirrorParameters.casterColor = (attackedCre)->owner;
|
||||
mirrorParameters.casterHero = nullptr;
|
||||
mirrorParameters.destination = targetHex;
|
||||
mirrorParameters.mode = ECastingMode::MAGIC_MIRROR;
|
||||
mirrorParameters.casterStack = (attackedCre);
|
||||
mirrorParameters.selectedStack = nullptr;
|
||||
|
||||
mirrorParameters.spellLvl = parameters.spellLvl;
|
||||
mirrorParameters.effectLevel = parameters.effectLevel;
|
||||
mirrorParameters.effectPower = parameters.effectPower;
|
||||
mirrorParameters.effectValue = parameters.effectValue;
|
||||
mirrorParameters.enchantPower = parameters.enchantPower;
|
||||
castMagicMirror(env, mirrorParameters);
|
||||
}
|
||||
}
|
||||
@ -490,9 +485,9 @@ void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env,
|
||||
{
|
||||
BattleStackAttacked bsa;
|
||||
if(spellDamage != 0)
|
||||
bsa.damageAmount = owner->adjustRawDamage(ctx.caster, attackedCre, spellDamage) >> chainLightningModifier;
|
||||
bsa.damageAmount = owner->adjustRawDamage(parameters.caster, attackedCre, spellDamage) >> chainLightningModifier;
|
||||
else
|
||||
bsa.damageAmount = owner->calculateDamage(ctx.caster, attackedCre, parameters.effectLevel, parameters.effectPower) >> chainLightningModifier;
|
||||
bsa.damageAmount = owner->calculateDamage(parameters.caster, attackedCre, parameters.effectLevel, parameters.effectPower) >> chainLightningModifier;
|
||||
|
||||
ctx.sc.dmgToDisplay += bsa.damageAmount;
|
||||
|
||||
@ -798,7 +793,6 @@ void DefaultSpellMechanics::castMagicMirror(const SpellCastEnvironment* env, Bat
|
||||
|
||||
StacksInjured si;
|
||||
SpellCastContext ctx(attackedCres, sc, si);
|
||||
ctx.caster = parameters.casterStack;
|
||||
applyBattleEffects(env, parameters, ctx);
|
||||
|
||||
env->sendAndApply(&sc);
|
||||
|
@ -25,9 +25,6 @@ struct SpellCastContext
|
||||
std::vector<const CStack *> & attackedCres;
|
||||
BattleSpellCast & sc;
|
||||
StacksInjured & si;
|
||||
|
||||
///stack or hero
|
||||
const ISpellCaster * caster;
|
||||
};
|
||||
|
||||
enum class ESpellCastResult
|
||||
|
@ -21,10 +21,10 @@
|
||||
#include "CreatureSpellMechanics.h"
|
||||
|
||||
BattleSpellCastParameters::BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell)
|
||||
: cb(cb), caster(caster), casterSide(0),casterColor(PlayerColor::CANNOT_DETERMINE),
|
||||
spellLvl(-1), destination(BattleHex::INVALID),casterHero(nullptr),
|
||||
: cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)),
|
||||
destination(BattleHex::INVALID),casterHero(nullptr),
|
||||
mode(ECastingMode::HERO_CASTING), casterStack(nullptr), selectedStack(nullptr),
|
||||
effectLevel(-1), effectPower(0), enchantPower(0), effectValue(0)
|
||||
spellLvl(-1), effectLevel(-1), effectPower(0), enchantPower(0), effectValue(0)
|
||||
{
|
||||
casterStack = dynamic_cast<const CStack *>(caster);
|
||||
casterHero = dynamic_cast<const CGHeroInstance *>(caster);
|
||||
|
@ -37,17 +37,17 @@ public:
|
||||
BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell);
|
||||
const BattleInfo * cb;
|
||||
const ISpellCaster * caster;
|
||||
ui8 casterSide;
|
||||
PlayerColor casterColor;
|
||||
///spell school level , -1-use default
|
||||
int spellLvl;
|
||||
const PlayerColor casterColor;
|
||||
const ui8 casterSide;
|
||||
|
||||
BattleHex destination;
|
||||
const CGHeroInstance * casterHero; //deprecated
|
||||
ECastingMode::ECastingMode mode;
|
||||
const CStack * casterStack; //deprecated
|
||||
const CStack * selectedStack;
|
||||
|
||||
|
||||
///spell school level
|
||||
int spellLvl;
|
||||
///spell school level to use for effects
|
||||
int effectLevel;
|
||||
///actual spell-power affecting effect values
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
class CSpell;
|
||||
class CStack;
|
||||
class PlayerColor;
|
||||
|
||||
class DLL_LINKAGE ISpellCaster
|
||||
{
|
||||
@ -43,4 +44,5 @@ public:
|
||||
///damage/heal override(ignores spell configuration, effect level and effect power)
|
||||
virtual int getEffectValue(const CSpell * spell) const = 0;
|
||||
|
||||
virtual const PlayerColor getOwner() const = 0;
|
||||
};
|
||||
|
@ -3877,10 +3877,8 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
||||
vstd::amax(parameters.spellLvl, randSpellcaster->val);
|
||||
vstd::amin (parameters.spellLvl, 3);
|
||||
parameters.effectLevel = parameters.spellLvl;
|
||||
parameters.casterSide = gs->curB->whatSide(stack->owner);
|
||||
parameters.mode = ECastingMode::CREATURE_ACTIVE_CASTING;
|
||||
parameters.destination = destination;
|
||||
parameters.casterColor = stack->owner;
|
||||
parameters.selectedStack = nullptr;
|
||||
spell->battleCast(spellEnv, parameters);
|
||||
}
|
||||
@ -4072,8 +4070,6 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
|
||||
|
||||
BattleSpellCastParameters parameters(gs->curB, h, s);
|
||||
parameters.destination = ba.destinationTile;
|
||||
parameters.casterSide = ba.side;
|
||||
parameters.casterColor = h->tempOwner;
|
||||
parameters.mode = ECastingMode::HERO_CASTING;
|
||||
parameters.selectedStack = gs->curB->battleGetStackByID(ba.selectedStack, false);
|
||||
|
||||
@ -4227,8 +4223,6 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
|
||||
parameters.spellLvl = bonus->val;
|
||||
parameters.effectLevel = bonus->val;//todo: recheck
|
||||
parameters.destination = BattleHex::INVALID;
|
||||
parameters.casterSide = side;
|
||||
parameters.casterColor = st->owner;
|
||||
parameters.mode = ECastingMode::ENCHANTER_CASTING;
|
||||
parameters.selectedStack = nullptr;
|
||||
|
||||
@ -4938,8 +4932,6 @@ void CGameHandler::attackCasting(const BattleAttack & bat, Bonus::BonusType atta
|
||||
parameters.spellLvl = spellLevel;
|
||||
parameters.effectLevel = spellLevel;
|
||||
parameters.destination = destination;
|
||||
parameters.casterSide = !attacker->attackerOwned;
|
||||
parameters.casterColor = attacker->owner;
|
||||
parameters.mode = ECastingMode::AFTER_ATTACK_CASTING;
|
||||
parameters.selectedStack = nullptr;
|
||||
|
||||
@ -4969,8 +4961,6 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat )
|
||||
parameters.spellLvl = 0;
|
||||
parameters.effectLevel = 0;
|
||||
parameters.destination = gs->curB->battleGetStackByID(bat.bsa.at(0).stackAttacked)->position;
|
||||
parameters.casterSide = !attacker->attackerOwned;
|
||||
parameters.casterColor = attacker->owner;
|
||||
parameters.effectPower = power;
|
||||
parameters.mode = ECastingMode::AFTER_ATTACK_CASTING;
|
||||
parameters.selectedStack = nullptr;
|
||||
@ -5279,8 +5269,6 @@ void CGameHandler::runBattle()
|
||||
parameters.spellLvl = 3;
|
||||
parameters.effectLevel = 3;
|
||||
parameters.destination = BattleHex::INVALID;
|
||||
parameters.casterSide = i;
|
||||
parameters.casterColor = h->tempOwner;
|
||||
parameters.mode = ECastingMode::PASSIVE_CASTING;
|
||||
parameters.selectedStack = nullptr;
|
||||
parameters.enchantPower = b->val;
|
||||
|
Loading…
Reference in New Issue
Block a user