1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-12-01 23:12:49 +02:00

support setting dice molecule for rolling morale and luck

This commit is contained in:
kdmcser
2025-03-16 23:44:38 +08:00
parent daa57f30d5
commit ffb31cc77c
6 changed files with 41 additions and 20 deletions

View File

@@ -940,19 +940,19 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
if(attackerLuck > 0)
{
auto diceSize = gameHandler->getSettings().getVector(EGameSettings::COMBAT_GOOD_LUCK_DICE);
size_t diceIndex = std::min<size_t>(diceSize.size(), attackerLuck) - 1; // array index, so 0-indexed
auto diceVector = gameHandler->getSettings().getDiceVector(EGameSettings::COMBAT_GOOD_LUCK_DICE);
size_t diceIndex = std::min<size_t>(diceVector.size(), attackerLuck) - 1; // array index, so 0-indexed
if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1)
if(diceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceVector[diceIndex].second) <= diceVector[diceIndex].first)
bat.flags |= BattleAttack::LUCKY;
}
if(attackerLuck < 0)
{
auto diceSize = gameHandler->getSettings().getVector(EGameSettings::COMBAT_BAD_LUCK_DICE);
size_t diceIndex = std::min<size_t>(diceSize.size(), -attackerLuck) - 1; // array index, so 0-indexed
auto diceVector = gameHandler->getSettings().getDiceVector(EGameSettings::COMBAT_BAD_LUCK_DICE);
size_t diceIndex = std::min<size_t>(diceVector.size(), -attackerLuck) - 1; // array index, so 0-indexed
if(diceSize.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceSize[diceIndex]) == 1)
if(diceVector.size() > 0 && gameHandler->getRandomGenerator().nextInt(1, diceVector[diceIndex].second) <= diceVector[diceIndex].first)
bat.flags |= BattleAttack::UNLUCKY;
}