From 1ce4675df6d31f7d70c67e49fe88a84d922fdf57 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Tue, 6 Sep 2016 13:33:11 +0300 Subject: [PATCH] Tweaks --- lib/spells/CDefaultSpellMechanics.cpp | 10 ++++++-- lib/spells/ISpellMechanics.cpp | 37 ++++++++++++++------------- lib/spells/ISpellMechanics.h | 8 +++--- server/CGameHandler.cpp | 12 ++++----- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/lib/spells/CDefaultSpellMechanics.cpp b/lib/spells/CDefaultSpellMechanics.cpp index 4257559f2..625c65ef1 100644 --- a/lib/spells/CDefaultSpellMechanics.cpp +++ b/lib/spells/CDefaultSpellMechanics.cpp @@ -262,13 +262,19 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, const B return; } - std::vector reflected, reflectedIgnore;//for magic mirror + std::vector reflected;//for magic mirror cast(env, parameters, reflected); //Magic Mirror effect for(auto & attackedCre : reflected) { + if(parameters.mode == ECastingMode::MAGIC_MIRROR) + { + logGlobal->error("Magic mirror recurrence!"); + return; + } + TStacks mirrorTargets = parameters.cb->battleGetStacksIf([this, parameters](const CStack * battleStack) { //Get all enemy stacks. Magic mirror can reflect to immune creature (with no effect) @@ -287,7 +293,7 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, const B mirrorParameters.effectPower = parameters.effectPower; mirrorParameters.effectValue = parameters.effectValue; mirrorParameters.enchantPower = parameters.enchantPower; - cast(env, mirrorParameters, reflectedIgnore); + mirrorParameters.cast(env); } } } diff --git a/lib/spells/ISpellMechanics.cpp b/lib/spells/ISpellMechanics.cpp index 7843530fd..64c98d7e4 100644 --- a/lib/spells/ISpellMechanics.cpp +++ b/lib/spells/ISpellMechanics.cpp @@ -34,15 +34,26 @@ BattleSpellCastParameters::Destination::Destination(const BattleHex & destinatio } -BattleSpellCastParameters::BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell) - : cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)), +BattleSpellCastParameters::BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell_) + : spell(spell_), cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)), casterHero(nullptr), mode(ECastingMode::HERO_CASTING), casterStack(nullptr), spellLvl(-1), effectLevel(-1), effectPower(0), enchantPower(0), effectValue(0) { casterStack = dynamic_cast(caster); casterHero = dynamic_cast(caster); - prepare(spell); + + spellLvl = caster->getSpellSchoolLevel(spell); + effectLevel = caster->getEffectLevel(spell); + effectPower = caster->getEffectPower(spell); + effectValue = caster->getEffectValue(spell); + enchantPower = caster->getEnchantPower(spell); + + vstd::amax(spellLvl, 0); + vstd::amax(effectLevel, 0); + vstd::amax(enchantPower, 0); + vstd::amax(enchantPower, 0); + vstd::amax(effectValue, 0); } void BattleSpellCastParameters::aimToHex(const BattleHex& destination) @@ -58,26 +69,16 @@ void BattleSpellCastParameters::aimToStack(const CStack * destination) destinations.push_back(Destination(destination)); } +void BattleSpellCastParameters::cast(const SpellCastEnvironment * env) +{ + spell->battleCast(env, *this); +} + BattleHex BattleSpellCastParameters::getFirstDestinationHex() const { return destinations.at(0).hexValue; } -void BattleSpellCastParameters::prepare(const CSpell * spell) -{ - spellLvl = caster->getSpellSchoolLevel(spell); - effectLevel = caster->getEffectLevel(spell); - effectPower = caster->getEffectPower(spell); - effectValue = caster->getEffectValue(spell); - enchantPower = caster->getEnchantPower(spell); - - vstd::amax(spellLvl, 0); - vstd::amax(effectLevel, 0); - vstd::amax(enchantPower, 0); - vstd::amax(enchantPower, 0); - vstd::amax(effectValue, 0); -} - ///ISpellMechanics ISpellMechanics::ISpellMechanics(CSpell * s): owner(s) diff --git a/lib/spells/ISpellMechanics.h b/lib/spells/ISpellMechanics.h index 4ece618c1..eb5d2bcbf 100644 --- a/lib/spells/ISpellMechanics.h +++ b/lib/spells/ISpellMechanics.h @@ -45,11 +45,15 @@ public: const BattleHex hexValue; }; - BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell); + BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell_); void aimToHex(const BattleHex & destination); void aimToStack(const CStack * destination); + + void cast(const SpellCastEnvironment * env); + BattleHex getFirstDestinationHex() const; + const CSpell * spell; const BattleInfo * cb; const ISpellCaster * caster; const PlayerColor casterColor; @@ -71,8 +75,6 @@ public: int enchantPower; ///for Archangel-like casting int effectValue; -private: - void prepare(const CSpell * spell); }; struct DLL_LINKAGE SpellTargetingContext diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 22d8f6a8c..62a89edd6 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -4171,7 +4171,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) parameters.effectLevel = parameters.spellLvl; parameters.mode = ECastingMode::CREATURE_ACTIVE_CASTING; parameters.aimToHex(destination);//todo: allow multiple destinations - spell->battleCast(spellEnv, parameters); + parameters.cast(spellEnv); } sendAndApply(&end_action); break; @@ -4382,7 +4382,7 @@ bool CGameHandler::makeCustomAction( BattleAction &ba ) StartAction start_action(ba); sendAndApply(&start_action); //start spell casting - s->battleCast(spellEnv, parameters); + parameters.cast(spellEnv); sendAndApply(&end_action); if( !gs->curB->battleGetStackByID(gs->curB->activeStack)) @@ -4523,7 +4523,7 @@ void CGameHandler::stackTurnTrigger(const CStack * st) parameters.aimToHex(BattleHex::INVALID); parameters.mode = ECastingMode::ENCHANTER_CASTING; - spell->battleCast(spellEnv, parameters); + parameters.cast(spellEnv); //todo: move to mechanics BattleSetStackProperty ssp; @@ -5233,7 +5233,7 @@ void CGameHandler::attackCasting(const BattleAttack & bat, Bonus::BonusType atta parameters.aimToStack(oneOfAttacked); parameters.mode = ECastingMode::AFTER_ATTACK_CASTING; - spell->battleCast(spellEnv, parameters); + parameters.cast(spellEnv); } } } @@ -5262,7 +5262,7 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat ) parameters.effectPower = power; parameters.mode = ECastingMode::AFTER_ATTACK_CASTING; - spell->battleCast(this->spellEnv, parameters); + parameters.cast(spellEnv); }; attackCasting(bat, Bonus::SPELL_AFTER_ATTACK, attacker); @@ -5568,7 +5568,7 @@ void CGameHandler::runBattle() parameters.aimToHex(BattleHex::INVALID); parameters.mode = ECastingMode::PASSIVE_CASTING; parameters.enchantPower = b->val; - spell->battleCast(spellEnv, parameters); + parameters.cast(spellEnv); } } }