1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Fixed morale and luck chance lookup.

This commit is contained in:
Warzyw647 2023-10-13 20:43:15 +02:00
parent 802e1bb961
commit 8058efb3bd
2 changed files with 4 additions and 4 deletions

View File

@ -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<size_t>(diceSize.size() - 1, attackerLuck);
size_t diceIndex = std::min<size_t>(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<size_t>(diceSize.size() - 1, -attackerLuck);
size_t diceIndex = std::min<size_t>(diceSize.size(), -attackerLuck) - 1; // array index, so 0-indexed
if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1)
bat.flags |= BattleAttack::UNLUCKY;

View File

@ -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<size_t>(diceSize.size()-1, -nextStackMorale);
size_t diceIndex = std::min<size_t>(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<size_t>(diceSize.size()-1, nextStackMorale);
size_t diceIndex = std::min<size_t>(diceSize.size(), nextStackMorale) - 1; // array index, so 0-indexed
if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1)
{