Browse Source

Few spell-related tweaks

AlexVinS 8 years ago
parent
commit
3c893a6bec

+ 0 - 5
lib/spells/CSpellHandler.cpp

@@ -133,11 +133,6 @@ bool CSpell::adventureCast(const SpellCastEnvironment * env, AdventureSpellCastP
 void CSpell::battleCast(const SpellCastEnvironment * env,  const BattleSpellCastParameters & parameters) const
 {
 	assert(env);
-	if(parameters.destinations.size()<1)
-	{
-		env->complain("Spell must have at least one destination");
-		return;
-	}
 	mechanics->battleCast(env, parameters);
 }
 

+ 13 - 0
lib/spells/ISpellMechanics.cpp

@@ -82,11 +82,24 @@ void BattleSpellCastParameters::aimToStack(const CStack * destination)
 
 void BattleSpellCastParameters::cast(const SpellCastEnvironment * env)
 {
+	if(destinations.empty())
+		aimToHex(BattleHex::INVALID);
 	spell->battleCast(env, *this);
 }
 
+void BattleSpellCastParameters::castIfPossible(const SpellCastEnvironment * env)
+{
+	if(ESpellCastProblem::OK == cb->battleCanCastThisSpell(caster, spell, mode))
+		cast(env);
+}
+
 BattleHex BattleSpellCastParameters::getFirstDestinationHex() const
 {
+	if(destinations.empty())
+	{
+		logGlobal->error("Spell have no destinations.");
+        return BattleHex::INVALID;
+	}
 	return destinations.at(0).hexValue;
 }
 

+ 3 - 0
lib/spells/ISpellMechanics.h

@@ -56,6 +56,9 @@ public:
 
 	void cast(const SpellCastEnvironment * env);
 
+	///cast with silent check for permitted cast
+	void castIfPossible(const SpellCastEnvironment * env);
+
 	BattleHex getFirstDestinationHex() const;
 
 	int getEffectValue() const;

+ 1 - 8
server/CGameHandler.cpp

@@ -4581,9 +4581,7 @@ void CGameHandler::stackTurnTrigger(const CStack *st)
 					BattleSpellCastParameters parameters(gs->curB, st, spell);
 					parameters.spellLvl = bonus->val;
 					parameters.effectLevel = bonus->val;//todo: recheck
-					parameters.aimToHex(BattleHex::INVALID);
 					parameters.mode = ECastingMode::ENCHANTER_CASTING;
-
 					parameters.cast(spellEnv);
 
 					//todo: move to mechanics
@@ -5302,7 +5300,6 @@ void CGameHandler::handleAfterAttackCasting(const BattleAttack & bat)
 		parameters.aimToStack(gs->curB->battleGetStackByID(bat.bsa.at(0).stackAttacked));
 		parameters.effectPower = power;
 		parameters.mode = ECastingMode::AFTER_ATTACK_CASTING;
-
 		parameters.cast(spellEnv);
 	};
 
@@ -5691,16 +5688,12 @@ void CGameHandler::runBattle()
 			{
 				const CSpell * spell = SpellID(b->subtype).toSpell();
 
-				if (ESpellCastProblem::OK != gs->curB->battleCanCastThisSpell(h, spell, ECastingMode::PASSIVE_CASTING))
-					continue;
-
 				BattleSpellCastParameters parameters(gs->curB, h, spell);
 				parameters.spellLvl = 3;
 				parameters.effectLevel = 3;
-				parameters.aimToHex(BattleHex::INVALID);
 				parameters.mode = ECastingMode::PASSIVE_CASTING;
 				parameters.enchantPower = b->val;
-				parameters.cast(spellEnv);
+				parameters.castIfPossible(spellEnv);
 			}
 		}
 	}