浏览代码

Allow custom effect animation on any stack during spell cast.

AlexVinS 10 年之前
父节点
当前提交
caf8ae62cc
共有 3 个文件被更改,包括 30 次插入9 次删除
  1. 4 4
      client/battle/CBattleInterface.cpp
  2. 14 2
      lib/NetPacks.h
  3. 12 3
      lib/spells/CDefaultSpellMechanics.cpp

+ 4 - 4
client/battle/CBattleInterface.cpp

@@ -1307,11 +1307,11 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
 		displaySpellEffect(spellID, position);
 	}
 
-	//queuing resist animation
-	for(auto & elem : sc->resisted)
+	//queuing additional animation
+	for(auto & elem : sc->customEffects)
 	{
-		BattleHex position = curInt->cb->battleGetStackByID(elem, false)->position;
-		displayEffect(78, position);
+		BattleHex position = curInt->cb->battleGetStackByID(elem.stack, false)->position;
+		displayEffect(elem.effect, position);
 	}
 
 	//displaying message in console

+ 14 - 2
lib/NetPacks.h

@@ -1478,6 +1478,18 @@ struct EndAction : public CPackForClient//3008
 
 struct BattleSpellCast : public CPackForClient//3009
 {
+	///custom effect (resistance, reflection, etc)
+	struct CustomEffect
+	{
+		/// WoG AC format
+		ui32 effect;		
+		ui32 stack;
+		template <typename Handler> void serialize(Handler &h, const int version)
+		{
+			h & effect & stack;
+		}		
+	};
+
 	BattleSpellCast(){type = 3009; casterStack = -1;};
 	DLL_LINKAGE void applyGs(CGameState *gs);
 	void applyCl(CClient *cl);
@@ -1488,13 +1500,13 @@ struct BattleSpellCast : public CPackForClient//3009
 	ui8 skill; //caster's skill level
 	ui8 manaGained; //mana channeling ability
 	BattleHex tile; //destination tile (may not be set in some global/mass spells
-	std::vector<ui32> resisted; //ids of creatures that resisted this spell
+	std::vector<CustomEffect> customEffects;
 	std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
 	si32 casterStack;// -1 if not cated by creature, >=0 caster stack ID
 	bool castByHero; //if true - spell has been casted by hero, otherwise by a creature
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & dmgToDisplay & side & id & skill & manaGained & tile & resisted & affectedCres & casterStack & castByHero;
+		h & dmgToDisplay & side & id & skill & manaGained & tile & customEffects & affectedCres & casterStack & castByHero;
 	}
 };
 

+ 12 - 3
lib/spells/CDefaultSpellMechanics.cpp

@@ -265,20 +265,29 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
 	//resistance is applied only to negative spells
 	if(owner->isNegative())
 	{
+		std::vector <const CStack*> resisted;
 		for(auto s : attackedCres)
 		{
 			const int prob = std::min((s)->magicResistance(), 100); //probability of resistance in %
 
 			if(env->getRandomGenerator().nextInt(99) < prob)
 			{
-				sc.resisted.push_back(s->ID);
+				resisted.push_back(s);
 			}
 		}
 
-		vstd::erase_if(attackedCres, [&sc](const CStack * s)
+		vstd::erase_if(attackedCres, [&resisted](const CStack * s)
 		{
-			return vstd::contains(sc.resisted, s->ID);
+			return vstd::contains(resisted, s);
 		});
+
+		for(auto s : resisted)
+		{
+			BattleSpellCast::CustomEffect effect;
+			effect.effect = 78;
+			effect.stack = s->ID;
+			sc.customEffects.push_back(effect);
+		}
 	}
 
 	for(auto cre : attackedCres)