Browse Source

Reverse death animation for resurrection spells

Ivan Savenko 2 years ago
parent
commit
e750bd2713

+ 28 - 1
client/battle/BattleAnimationClasses.cpp

@@ -622,7 +622,6 @@ bool CMovementStartAnimation::init()
 	if( !CBattleAnimation::checkInitialConditions() )
 		return false;
 
-
 	if(!stack || myAnim->isDeadOrDying())
 	{
 		delete this;
@@ -698,6 +697,34 @@ void CReverseAnimation::setupSecondPart()
 		delete this;
 }
 
+bool CResurrectionAnimation::init()
+{
+	if( !CBattleAnimation::checkInitialConditions() )
+		return false;
+
+	if(!stack)
+	{
+		delete this;
+		return false;
+	}
+
+	myAnim->playOnce(ECreatureAnimType::RESURRECTION);
+	myAnim->onAnimationReset += [&](){ delete this; };
+
+	return true;
+}
+
+CResurrectionAnimation::CResurrectionAnimation(BattleInterface & owner, const CStack * stack):
+	CBattleStackAnimation(owner, stack)
+{
+
+}
+
+CResurrectionAnimation::~CResurrectionAnimation()
+{
+
+}
+
 CRangedAttackAnimation::CRangedAttackAnimation(BattleInterface & owner, const CStack * attacker, BattleHex dest_, const CStack * defender)
 	: CAttackAnimation(owner, attacker, dest_, defender),
 	  projectileEmitted(false)

+ 10 - 0
client/battle/BattleAnimationClasses.h

@@ -199,6 +199,16 @@ public:
 	~CReverseAnimation();
 };
 
+/// Resurrects stack from dead state
+class CResurrectionAnimation : public CBattleStackAnimation
+{
+public:
+	bool init() override;
+
+	CResurrectionAnimation(BattleInterface & owner, const CStack * stack);
+	~CResurrectionAnimation();
+};
+
 class CRangedAttackAnimation : public CAttackAnimation
 {
 

+ 8 - 3
client/battle/BattleStacksController.cpp

@@ -158,7 +158,9 @@ void BattleStacksController::stackReset(const CStack * stack)
 	auto animation = iter->second;
 
 	if(stack->alive() && animation->isDeadOrDying())
-		animation->setType(ECreatureAnimType::HOLDING);
+	{
+		addNewAnim(new CResurrectionAnimation(owner, stack));
+	}
 
 	static const ColorShifterMultiplyAndAdd shifterClone ({255, 255, 0, 255}, {0, 0, 255, 0});
 
@@ -167,6 +169,8 @@ void BattleStacksController::stackReset(const CStack * stack)
 		animation->shiftColor(&shifterClone);
 	}
 
+	owner.waitForAnims();
+
 	//TODO: handle more cases
 }
 
@@ -396,7 +400,7 @@ void BattleStacksController::stacksAreAttacked(std::vector<StackAttackedInfo> at
 
 		if(attackedInfo.rebirth)
 		{
-			owner.effectsController->displayEffect(EBattleEffect::RESURRECT, soundBase::RESURECT, attackedInfo.defender->getPosition()); //TODO: play reverse death animation
+			owner.effectsController->displayEffect(EBattleEffect::RESURRECT, soundBase::RESURECT, attackedInfo.defender->getPosition());
 		}
 	}
 	owner.waitForAnims();
@@ -404,10 +408,11 @@ void BattleStacksController::stacksAreAttacked(std::vector<StackAttackedInfo> at
 	for (auto & attackedInfo : attackedInfos)
 	{
 		if (attackedInfo.rebirth)
-			stackAnimation[attackedInfo.defender->ID]->setType(ECreatureAnimType::HOLDING);
+			addNewAnim(new CResurrectionAnimation(owner, attackedInfo.defender));
 		if (attackedInfo.cloneKilled)
 			stackRemoved(attackedInfo.defender->ID);
 	}
+	owner.waitForAnims();
 }
 
 void BattleStacksController::stackMoved(const CStack *stack, std::vector<BattleHex> destHex, int distance)