Переглянути джерело

Merge pull request #4573 from kdmcser/stack_level_updater_for_commander

make TimesStackLevelUpdater support commander
Ivan Savenko 1 рік тому
батько
коміт
9a08e2eb0f
1 змінених файлів з 10 додано та 3 видалено
  1. 10 3
      lib/bonuses/Updaters.cpp

+ 10 - 3
lib/bonuses/Updaters.cpp

@@ -145,7 +145,7 @@ JsonNode ArmyMovementUpdater::toJsonNode() const
 }
 std::shared_ptr<Bonus> TimesStackLevelUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) const
 {
-	if(context.getNodeType() == CBonusSystemNode::STACK_INSTANCE)
+	if(context.getNodeType() == CBonusSystemNode::STACK_INSTANCE || context.getNodeType() == CBonusSystemNode::COMMANDER)
 	{
 		int level = dynamic_cast<const CStackInstance &>(context).getLevel();
 		auto newBonus = std::make_shared<Bonus>(*b);
@@ -155,8 +155,7 @@ std::shared_ptr<Bonus> TimesStackLevelUpdater::createUpdatedBonus(const std::sha
 	else if(context.getNodeType() == CBonusSystemNode::STACK_BATTLE)
 	{
 		const auto & stack = dynamic_cast<const CStack &>(context);
-		//only update if stack doesn't have an instance (summons, war machines)
-		//otherwise we'd end up multiplying twice
+		//update if stack doesn't have an instance (summons, war machines)
 		if(stack.base == nullptr)
 		{
 			int level = stack.unitType()->getLevel();
@@ -164,6 +163,14 @@ std::shared_ptr<Bonus> TimesStackLevelUpdater::createUpdatedBonus(const std::sha
 			newBonus->val *= level;
 			return newBonus;
 		}
+		// If these are not handled here, the final outcome may potentially be incorrect.
+		else
+		{
+			int level = dynamic_cast<const CStackInstance*>(stack.base)->getLevel();
+			auto newBonus = std::make_shared<Bonus>(*b);
+			newBonus->val *= level;
+			return newBonus;
+		}
 	}
 	return b;
 }