1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Random with history for combat abilities

This commit is contained in:
Ivan Savenko
2025-05-18 22:12:39 +03:00
parent 87323f08d9
commit 157b4fea74
4 changed files with 45 additions and 42 deletions

View File

@@ -390,7 +390,7 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
const CreatureID stackCreatureId = next->unitType()->getId();
if ((stackCreatureId == CreatureID::ARROW_TOWERS || stackCreatureId == CreatureID::BALLISTA)
&& (!curOwner || gameHandler->getRandomGenerator().nextInt(99) >= curOwner->valOfBonuses(BonusType::MANUAL_CONTROL, BonusSubtypeID(stackCreatureId))))
&& (!curOwner || !gameHandler->randomizer->rollCombatAbility(curOwner->id, curOwner->valOfBonuses(BonusType::MANUAL_CONTROL, BonusSubtypeID(stackCreatureId)))))
{
BattleAction attack;
attack.actionType = EActionType::SHOOT;
@@ -462,7 +462,7 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
return true;
}
if (!curOwner || gameHandler->getRandomGenerator().nextInt(99) >= curOwner->valOfBonuses(BonusType::MANUAL_CONTROL, BonusSubtypeID(CreatureID(CreatureID::CATAPULT))))
if (!curOwner || !gameHandler->randomizer->rollCombatAbility(curOwner->id, curOwner->valOfBonuses(BonusType::MANUAL_CONTROL, BonusSubtypeID(CreatureID(CreatureID::CATAPULT)))))
{
BattleAction attack;
attack.actionType = EActionType::CATAPULT;
@@ -487,7 +487,7 @@ bool BattleFlowProcessor::tryMakeAutomaticAction(const CBattleInfoCallback & bat
return true;
}
if (!curOwner || gameHandler->getRandomGenerator().nextInt(99) >= curOwner->valOfBonuses(BonusType::MANUAL_CONTROL, BonusSubtypeID(CreatureID(CreatureID::FIRST_AID_TENT))))
if (!curOwner || !gameHandler->randomizer->rollCombatAbility(curOwner->id, curOwner->valOfBonuses(BonusType::MANUAL_CONTROL, BonusSubtypeID(CreatureID(CreatureID::FIRST_AID_TENT)))))
{
RandomGeneratorUtil::randomShuffle(possibleStacks, gameHandler->getRandomGenerator());
const CStack * toBeHealed = possibleStacks.front();
@@ -738,6 +738,7 @@ void BattleFlowProcessor::stackTurnTrigger(const CBattleInfoCallback & battle, c
}
if (st->isLiving() && !st->hasBonusOfType(BonusType::FEARLESS))
{
ObjectInstanceID opponentArmyID = battle.battleGetArmyObject(battle.otherSide(st->unitSide()))->id;
bool fearsomeCreature = false;
for (const CStack * stack : battle.battleGetAllStacks(true))
{
@@ -749,7 +750,7 @@ void BattleFlowProcessor::stackTurnTrigger(const CBattleInfoCallback & battle, c
}
if (fearsomeCreature)
{
if (gameHandler->getRandomGenerator().nextInt(99) < 10) //fixed 10%
if (gameHandler->randomizer->rollCombatAbility(opponentArmyID, 10)) //fixed 10%
{
bte.effect = vstd::to_underlying(BonusType::FEAR);
gameHandler->sendAndApply(bte);