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

Do not ignore 'canRefuse' flag for select mode 'first' and 'random'

This commit is contained in:
Ivan Savenko 2023-12-23 00:35:51 +02:00
parent 20ede710c2
commit ec5fcb3e7c

View File

@ -111,11 +111,20 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *h) const
selectRewardWthMessage(h, rewards, configuration.onSelect);
break;
case Rewardable::SELECT_FIRST: // give first available
grantRewardWithMessage(h, rewards.front(), true);
if (configuration.canRefuse)
selectRewardWthMessage(h, { rewards.front() }, configuration.info.at(rewards.front()).message);
else
grantRewardWithMessage(h, rewards.front(), true);
break;
case Rewardable::SELECT_RANDOM: // give random
grantRewardWithMessage(h, *RandomGeneratorUtil::nextItem(rewards, cb->gameState()->getRandomGenerator()), true);
{
ui32 rewardIndex = *RandomGeneratorUtil::nextItem(rewards, cb->gameState()->getRandomGenerator());
if (configuration.canRefuse)
selectRewardWthMessage(h, { rewardIndex }, configuration.info.at(rewardIndex).message);
else
grantRewardWithMessage(h, rewardIndex, true);
break;
}
}
break;
}