Browse Source

Spells can now define color muxer effect (e.g. Bloodlust & Petrify)

Ivan Savenko 2 years ago
parent
commit
bab5922951

+ 20 - 22
client/battle/BattleInterface.cpp

@@ -361,7 +361,7 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
 			executeOnAnimationCondition(EAnimationEvents::BEFORE_HIT, true, [=]()
 			{
 				stacksController->addNewAnim(new CastAnimation(*this, casterStack, targetedTile, curInt->cb->battleGetStackByPos(targetedTile), spell));
-				displaySpellCast(spellID, casterStack->getPosition());
+				displaySpellCast(spell, casterStack->getPosition());
 			});
 		}
 		else
@@ -377,7 +377,7 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
 	}
 
 	executeOnAnimationCondition(EAnimationEvents::HIT, true, [=](){
-		displaySpellHit(spellID, targetedTile);
+		displaySpellHit(spell, targetedTile);
 	});
 
 	//queuing affect animation
@@ -388,12 +388,7 @@ void BattleInterface::spellCast(const BattleSpellCast * sc)
 		if(stack)
 		{
 			executeOnAnimationCondition(EAnimationEvents::HIT, true, [=](){
-				if (spellID == SpellID::BLOODLUST)
-					stacksController->addNewAnim( new ColorTransformAnimation(*this, stack, "bloodlust", spell));
-				else if (spellID == SpellID::STONE_GAZE)
-					stacksController->addNewAnim( new ColorTransformAnimation(*this, stack, "petrification",  spell));
-				else
-					displaySpellEffect(spellID, stack->getPosition());
+				displaySpellEffect(spell, stack->getPosition());
 			});
 		}
 	}
@@ -460,13 +455,22 @@ void BattleInterface::displayBattleLog(const std::vector<MetaString> & battleLog
 	}
 }
 
-void BattleInterface::displaySpellAnimationQueue(const CSpell::TAnimationQueue & q, BattleHex destinationTile, bool isHit)
+void BattleInterface::displaySpellAnimationQueue(const CSpell * spell, const CSpell::TAnimationQueue & q, BattleHex destinationTile, bool isHit)
 {
 	for(const CSpell::TAnimation & animation : q)
 	{
 		if(animation.pause > 0)
 			stacksController->addNewAnim(new DummyAnimation(*this, animation.pause));
-		else
+
+		if (!animation.effectName.empty())
+		{
+			const CStack * destStack = getCurrentPlayerInterface()->cb->battleGetStackByPos(destinationTile, false);
+
+			if (destStack)
+				stacksController->addNewAnim(new ColorTransformAnimation(*this, destStack, animation.effectName, spell ));
+		}
+
+		if(!animation.resourceName.empty())
 		{
 			int flags = 0;
 
@@ -487,28 +491,22 @@ void BattleInterface::displaySpellAnimationQueue(const CSpell::TAnimationQueue &
 	}
 }
 
-void BattleInterface::displaySpellCast(SpellID spellID, BattleHex destinationTile)
+void BattleInterface::displaySpellCast(const CSpell * spell, BattleHex destinationTile)
 {
-	const CSpell * spell = spellID.toSpell();
-
 	if(spell)
-		displaySpellAnimationQueue(spell->animationInfo.cast, destinationTile, false);
+		displaySpellAnimationQueue(spell, spell->animationInfo.cast, destinationTile, false);
 }
 
-void BattleInterface::displaySpellEffect(SpellID spellID, BattleHex destinationTile)
+void BattleInterface::displaySpellEffect(const CSpell * spell, BattleHex destinationTile)
 {
-	const CSpell *spell = spellID.toSpell();
-
 	if(spell)
-		displaySpellAnimationQueue(spell->animationInfo.affect, destinationTile, false);
+		displaySpellAnimationQueue(spell, spell->animationInfo.affect, destinationTile, false);
 }
 
-void BattleInterface::displaySpellHit(SpellID spellID, BattleHex destinationTile)
+void BattleInterface::displaySpellHit(const CSpell * spell, BattleHex destinationTile)
 {
-	const CSpell * spell = spellID.toSpell();
-
 	if(spell)
-		displaySpellAnimationQueue(spell->animationInfo.hit, destinationTile, true);
+		displaySpellAnimationQueue(spell, spell->animationInfo.hit, destinationTile, true);
 }
 
 void BattleInterface::setAnimSpeed(int set)

+ 4 - 4
client/battle/BattleInterface.h

@@ -206,10 +206,10 @@ public:
 
 	void displayBattleLog(const std::vector<MetaString> & battleLog);
 
-	void displaySpellAnimationQueue(const CSpell::TAnimationQueue & q, BattleHex destinationTile, bool isHit);
-	void displaySpellCast(SpellID spellID, BattleHex destinationTile); //displays spell`s cast animation
-	void displaySpellEffect(SpellID spellID, BattleHex destinationTile); //displays spell`s affected animation
-	void displaySpellHit(SpellID spellID, BattleHex destinationTile); //displays spell`s affected animation
+	void displaySpellAnimationQueue(const CSpell * spell, const CSpell::TAnimationQueue & q, BattleHex destinationTile, bool isHit);
+	void displaySpellCast(const CSpell * spell, BattleHex destinationTile); //displays spell`s cast animation
+	void displaySpellEffect(const CSpell * spell, BattleHex destinationTile); //displays spell`s affected animation
+	void displaySpellHit(const CSpell * spell, BattleHex destinationTile); //displays spell`s affected animation
 
 	void endAction(const BattleAction* action);
 

+ 2 - 2
client/battle/BattleStacksController.cpp

@@ -451,7 +451,7 @@ void BattleStacksController::stacksAreAttacked(std::vector<StackAttackedInfo> at
 				owner.effectsController->displayEffect(EBattleEffect::FIRE_SHIELD, soundBase::FIRESHIE, attackedInfo.attacker->getPosition());
 
 			if (attackedInfo.spellEffect != SpellID::NONE)
-				owner.displaySpellEffect(attackedInfo.spellEffect, attackedInfo.defender->getPosition());
+				owner.displaySpellEffect(attackedInfo.spellEffect.toSpell(), attackedInfo.defender->getPosition());
 		});
 	}
 
@@ -606,7 +606,7 @@ void BattleStacksController::stackAttacking( const StackAttackInfo & info )
 	{
 		owner.executeOnAnimationCondition(EAnimationEvents::HIT, true, [=]()
 		{
-			owner.displaySpellHit(spellEffect, tile);
+			owner.displaySpellHit(spellEffect.toSpell(), tile);
 		});
 	}
 

+ 3 - 1
config/spells/ability.json

@@ -3,7 +3,9 @@
 		"index" : 70,
 		"targetType": "NO_TARGET",
 		"animation":{
-			//need special animation
+			"affect":[ {
+				"effectName" : "petrification"
+			} ]
 		},
 		"sounds": {
 			"cast": "PARALYZE"

+ 3 - 1
config/spells/timed.json

@@ -437,7 +437,9 @@
 		"targetType" : "CREATURE",
 
 		"animation":{
-			"affect":["SP12_"] //???
+			"affect":[ {
+				"effectName" : "bloodlust"
+			} ]
 		},
 		"sounds": {
 			"cast": "BLOODLUS"

+ 4 - 2
lib/spells/CSpellHandler.cpp

@@ -522,8 +522,9 @@ void CSpell::serializeJson(JsonSerializeFormat & handler)
 }
 
 ///CSpell::AnimationInfo
-CSpell::AnimationItem::AnimationItem()
-	:resourceName(""),verticalPosition(VerticalPosition::TOP),pause(0)
+CSpell::AnimationItem::AnimationItem() :
+	verticalPosition(VerticalPosition::TOP),
+	pause(0)
 {
 
 }
@@ -890,6 +891,7 @@ CSpell * CSpellHandler::loadFromJson(const std::string & scope, const JsonNode &
 			else if(item.getType() == JsonNode::JsonType::DATA_STRUCT)
 			{
 				newItem.resourceName = item["defName"].String();
+				newItem.effectName   = item["effectName"].String();
 
 				auto vPosStr = item["verticalPosition"].String();
 				if("bottom" == vPosStr)

+ 2 - 0
lib/spells/CSpellHandler.h

@@ -76,6 +76,7 @@ public:
 	struct AnimationItem
 	{
 		std::string resourceName;
+		std::string effectName;
 		VerticalPosition verticalPosition;
 		int pause;
 
@@ -84,6 +85,7 @@ public:
 		template <typename Handler> void serialize(Handler & h, const int version)
 		{
 			h & resourceName;
+			h & effectName;
 			h & verticalPosition;
 			h & pause;
 		}