diff --git a/server/battles/BattleActionProcessor.cpp b/server/battles/BattleActionProcessor.cpp index 34cd08213..fc491160c 100644 --- a/server/battles/BattleActionProcessor.cpp +++ b/server/battles/BattleActionProcessor.cpp @@ -884,7 +884,7 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const if(attackerLuck > 0) { auto diceSize = VLC->settings()->getVector(EGameSettings::COMBAT_GOOD_LUCK_DICE); - size_t diceIndex = std::min(diceSize.size() - 1, attackerLuck); + size_t diceIndex = std::min(diceSize.size(), attackerLuck) - 1; // array index, so 0-indexed if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1) bat.flags |= BattleAttack::LUCKY; @@ -893,7 +893,7 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const if(attackerLuck < 0) { auto diceSize = VLC->settings()->getVector(EGameSettings::COMBAT_BAD_LUCK_DICE); - size_t diceIndex = std::min(diceSize.size() - 1, -attackerLuck); + size_t diceIndex = std::min(diceSize.size(), -attackerLuck) - 1; // array index, so 0-indexed if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1) bat.flags |= BattleAttack::UNLUCKY; diff --git a/server/battles/BattleFlowProcessor.cpp b/server/battles/BattleFlowProcessor.cpp index 85f214df0..8be9c9f0f 100644 --- a/server/battles/BattleFlowProcessor.cpp +++ b/server/battles/BattleFlowProcessor.cpp @@ -340,7 +340,7 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat if(!next->hadMorale && !next->waited() && nextStackMorale < 0) { auto diceSize = VLC->settings()->getVector(EGameSettings::COMBAT_BAD_MORALE_DICE); - size_t diceIndex = std::min(diceSize.size()-1, -nextStackMorale); + size_t diceIndex = std::min(diceSize.size(), -nextStackMorale) - 1; // array index, so 0-indexed if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1) { @@ -492,7 +492,7 @@ bool BattleFlowProcessor::rollGoodMorale(const CBattleInfoCallback & battle, con && nextStackMorale > 0) { auto diceSize = VLC->settings()->getVector(EGameSettings::COMBAT_GOOD_MORALE_DICE); - size_t diceIndex = std::min(diceSize.size()-1, nextStackMorale); + size_t diceIndex = std::min(diceSize.size(), nextStackMorale) - 1; // array index, so 0-indexed if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1) {