1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

make TimesStackLevelUpdater support commander

This commit is contained in:
kdmcser 2024-09-09 19:03:56 +08:00
parent 1212fce62c
commit b84d653a99

View File

@ -145,7 +145,7 @@ JsonNode ArmyMovementUpdater::toJsonNode() const
} }
std::shared_ptr<Bonus> TimesStackLevelUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) 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(); int level = dynamic_cast<const CStackInstance &>(context).getLevel();
auto newBonus = std::make_shared<Bonus>(*b); 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) else if(context.getNodeType() == CBonusSystemNode::STACK_BATTLE)
{ {
const auto & stack = dynamic_cast<const CStack &>(context); const auto & stack = dynamic_cast<const CStack &>(context);
//only update if stack doesn't have an instance (summons, war machines) //update if stack doesn't have an instance (summons, war machines)
//otherwise we'd end up multiplying twice
if(stack.base == nullptr) if(stack.base == nullptr)
{ {
int level = stack.unitType()->getLevel(); int level = stack.unitType()->getLevel();
@ -164,6 +163,14 @@ std::shared_ptr<Bonus> TimesStackLevelUpdater::createUpdatedBonus(const std::sha
newBonus->val *= level; newBonus->val *= level;
return newBonus; 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; return b;
} }