mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Extracted MagicMirror handling
This commit is contained in:
		| @@ -263,35 +263,9 @@ void DefaultSpellMechanics::castNormal(const SpellCastEnvironment * env, const B | ||||
|  | ||||
| 	logGlobal->debugStream() << "will affect: " << ctx.attackedCres.size() << " stacks"; | ||||
|  | ||||
|  | ||||
| 	//checking if creatures resist | ||||
| 	handleResistance(env, ctx.attackedCres, ctx.sc); | ||||
|  | ||||
| 	//reflection is applied only to negative spells | ||||
| 	//if it is actual spell and can be reflected to single target, no recurrence | ||||
| 	const bool tryMagicMirror = owner->isNegative() && owner->level && owner->getLevelInfo(0).range == "0"; | ||||
| 	if(tryMagicMirror) | ||||
| 	{ | ||||
| 		for(auto s : ctx.attackedCres) | ||||
| 		{ | ||||
| 			const int mirrorChance = (s)->valOfBonuses(Bonus::MAGIC_MIRROR); | ||||
| 			if(env->getRandomGenerator().nextInt(99) < mirrorChance) | ||||
| 				reflected.push_back(s); | ||||
| 		} | ||||
|  | ||||
| 		vstd::erase_if(ctx.attackedCres, [&reflected](const CStack * s) | ||||
| 		{ | ||||
| 			return vstd::contains(reflected, s); | ||||
| 		}); | ||||
|  | ||||
| 		for(auto s : reflected) | ||||
| 		{ | ||||
| 			BattleSpellCast::CustomEffect effect; | ||||
| 			effect.effect = 3; | ||||
| 			effect.stack = s->ID; | ||||
| 			ctx.sc.customEffects.push_back(effect); | ||||
| 		} | ||||
| 	} | ||||
| 	handleMagicMirror(env, ctx, reflected); | ||||
|  | ||||
| 	applyBattleEffects(env, parameters, ctx); | ||||
|  | ||||
| @@ -764,6 +738,35 @@ void DefaultSpellMechanics::handleImmunities(const CBattleInfoCallback * cb, con | ||||
| 	vstd::erase_if(stacks, predicate); | ||||
| } | ||||
|  | ||||
| void DefaultSpellMechanics::handleMagicMirror(const SpellCastEnvironment * env, SpellCastContext & ctx, std::vector <const CStack*> & reflected) const | ||||
| { | ||||
| 	//reflection is applied only to negative spells | ||||
| 	//if it is actual spell and can be reflected to single target, no recurrence | ||||
| 	const bool tryMagicMirror = owner->isNegative() && owner->level && owner->getLevelInfo(0).range == "0"; | ||||
| 	if(tryMagicMirror) | ||||
| 	{ | ||||
| 		for(auto s : ctx.attackedCres) | ||||
| 		{ | ||||
| 			const int mirrorChance = (s)->valOfBonuses(Bonus::MAGIC_MIRROR); | ||||
| 			if(env->getRandomGenerator().nextInt(99) < mirrorChance) | ||||
| 				reflected.push_back(s); | ||||
| 		} | ||||
|  | ||||
| 		vstd::erase_if(ctx.attackedCres, [&reflected](const CStack * s) | ||||
| 		{ | ||||
| 			return vstd::contains(reflected, s); | ||||
| 		}); | ||||
|  | ||||
| 		for(auto s : reflected) | ||||
| 		{ | ||||
| 			BattleSpellCast::CustomEffect effect; | ||||
| 			effect.effect = 3; | ||||
| 			effect.stack = s->ID; | ||||
| 			ctx.sc.customEffects.push_back(effect); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void DefaultSpellMechanics::handleResistance(const SpellCastEnvironment * env, std::vector<const CStack* >& attackedCres, BattleSpellCast& sc) const | ||||
| { | ||||
| 	//checking if creatures resist | ||||
|   | ||||
| @@ -67,7 +67,9 @@ protected: | ||||
| private: | ||||
| 	void castNormal(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, std::vector <const CStack*> & reflected) const; | ||||
| 	void castMagicMirror(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters) const; | ||||
|  | ||||
| 	void handleImmunities(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx, std::vector<const CStack *> & stacks) const; | ||||
| 	void handleMagicMirror(const SpellCastEnvironment * env, SpellCastContext & ctx, std::vector <const CStack*> & reflected) const; | ||||
| 	void handleResistance(const SpellCastEnvironment * env, std::vector<const CStack*> & attackedCres, BattleSpellCast & sc) const; | ||||
|  | ||||
| 	friend class SpellCastContext; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user