瀏覽代碼

Support for Mana Channeling ability.

DjWarmonger 14 年之前
父節點
當前提交
b4d0ebf9ab
共有 4 個文件被更改,包括 41 次插入18 次删除
  1. 8 0
      client/CBattleInterface.cpp
  2. 3 1
      lib/NetPacks.h
  3. 10 17
      lib/NetPacksLib.cpp
  4. 20 0
      server/CGameHandler.cpp

+ 8 - 0
client/CBattleInterface.cpp

@@ -3376,6 +3376,14 @@ void CBattleInterface::spellCast( const BattleSpellCast * sc )
 		console->addText(dmgInfo); //todo: casualties (?)
 	}
 	waitForAnims();
+	//mana absorption
+	if (sc->manaGained)
+	{
+		Point leftHero = Point(15, 30) + pos;
+		Point rightHero = Point(755, 30) + pos;
+		addNewAnim(new CSpellEffectAnim(this, sc->side ? "SP07_A.DEF" : "SP07_B.DEF", leftHero.x, leftHero.y, 0, 0, false));
+		addNewAnim(new CSpellEffectAnim(this, sc->side ? "SP07_B.DEF" : "SP07_A.DEF", rightHero.x, rightHero.y, 0, 0, false));
+	}
 }
 
 void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse)

+ 3 - 1
lib/NetPacks.h

@@ -1382,6 +1382,8 @@ struct BattleSpellCast : public CPackForClient//3009
 	ui8 side; //which hero did cast spell: 0 - attacker, 1 - defender
 	ui32 id; //id of spell
 	ui8 skill; //caster's skill level
+	ui8 spellCost;
+	ui8 manaGained; //mana channeling ability
 	THex tile; //destination tile (may not be set in some global/mass spells
 	std::vector<ui32> resisted; //ids of creatures that resisted this spell
 	std::set<ui32> affectedCres; //ids of creatures affected by this spell, generally used if spell does not set any effect (like dispel or cure)
@@ -1389,7 +1391,7 @@ struct BattleSpellCast : public CPackForClient//3009
 	ui8 castedByHero; //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 & tile & resisted & affectedCres & attackerType & castedByHero;
+		h & dmgToDisplay & side & id & skill & spellCost & manaGained & tile & resisted & affectedCres & attackerType & castedByHero;
 	}
 };
 

+ 10 - 17
lib/NetPacksLib.cpp

@@ -1044,27 +1044,20 @@ DLL_EXPORT void StartAction::applyGs( CGameState *gs )
 DLL_EXPORT void BattleSpellCast::applyGs( CGameState *gs )
 {
 	assert(gs->curB);
-	CGHeroInstance *h = (side) ? gs->curB->heroes[1] : gs->curB->heroes[0];
-	if(h && castedByHero)
+	if (castedByHero)
 	{
-		int spellCost = 0;
-		if(gs->curB)
-		{
-			spellCost = gs->curB->getSpellCost(VLC->spellh->spells[id], h);
-		}
-		else
+		CGHeroInstance * h = gs->curB->heroes[side];
+		CGHeroInstance * enemy = gs->curB->heroes[1-side];
+
+		h->mana -= spellCost;
+			amax(h->mana, 0);
+		if (enemy && manaGained)
+			enemy->mana += manaGained;
+		if (side >= 0 && side < 2)
 		{
-			spellCost = VLC->spellh->spells[id]->costs[skill];
+			gs->curB->castSpells[side]++;
 		}
-		h->mana -= spellCost;
-		if (h->mana < 0)
-			h->mana = 0;
 	}
-	if(side >= 0 && side < 2 && castedByHero)
-	{
-		gs->curB->castSpells[side]++;
-	}
-
 
 	if(id == 35 || id == 78) //dispel and dispel helpful spells
 	{

+ 20 - 0
server/CGameHandler.cpp

@@ -3496,6 +3496,26 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, THex destinati
 	sc.dmgToDisplay = 0;
 	sc.castedByHero = (bool)caster;
 	sc.attackerType = (stack ? stack->type->idNumber : -1);
+	sc.manaGained = 0;
+	sc.spellCost = 0;
+
+	if (caster) //calculate spell cost
+	{
+		sc.spellCost = gs->curB->getSpellCost(VLC->spellh->spells[spellID], caster);
+
+		if (secHero && mode == SpellCasting::HERO_CASTING) //handle mana channel
+		{
+			int manaChannel = 0;
+			BOOST_FOREACH(CStack * stack, gs->curB->stacks) //TODO: shouldn't bonus system handle it somehow?
+			{
+				if (stack->owner == secHero->tempOwner)
+				{
+					amax(manaChannel, stack->valOfBonuses(Bonus::MANA_CHANNELING));
+				}
+			}
+			sc.manaGained = (manaChannel * sc.spellCost) / 100;
+		}
+	}
 
 	//calculating affected creatures for all spells
 	std::set<CStack*> attackedCres;