1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-06 00:24:11 +02:00

Merge pull request #4573 from kdmcser/stack_level_updater_for_commander

make TimesStackLevelUpdater support commander
This commit is contained in:
Ivan Savenko 2024-09-12 14:16:16 +03:00 committed by GitHub
commit 9a08e2eb0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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;
} }