From a024c6879c55d85b370bf930732a037bd7f5d185 Mon Sep 17 00:00:00 2001 From: csacro <50425802+csacro@users.noreply.github.com> Date: Mon, 4 May 2020 21:53:40 +0200 Subject: [PATCH] implemented #121 --- .../execution/ActionExecutor_Gamble.cpp | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/gameLogic/execution/ActionExecutor_Gamble.cpp b/src/gameLogic/execution/ActionExecutor_Gamble.cpp index 7b1e6cff..7dd50791 100644 --- a/src/gameLogic/execution/ActionExecutor_Gamble.cpp +++ b/src/gameLogic/execution/ActionExecutor_Gamble.cpp @@ -2,12 +2,31 @@ // Created by jonas on 28.04.20. // #include "ActionExecutor.hpp" +#include "util/GameLogicUtils.hpp" namespace spy::gameplay { bool ActionExecutor::executeGamble(State &s, const GambleAction &op) { auto character = s.getCharacters().getByUUID(op.getCharacterId()); character->subActionPoint(); - // TODO: implement - return false; + auto targetField = s.getMap().getField(op.getTarget()); + + double winningChance = 18/37; + if (character->hasProperty(character::PropertyEnum::LUCKY_DEVIL)) { + winningChance = 32/37; + } else if (character->hasProperty(character::PropertyEnum::JINX)) { + winningChance = 13/37; + } + winningChance = targetField.isInverted() ? (1-winningChance) : winningChance; + + bool won = util::GameLogicUtils::probabilityTestWithCharacter(s, *character, winningChance); + if (won) { + character->setChips(character->getChips() + op.getStake()); + targetField.setChipAmount(targetField.getChipAmount().value() - op.getStake()); + } else { + character->setChips(character->getChips() - op.getStake()); + targetField.setChipAmount(targetField.getChipAmount().value() + op.getStake()); + } + + return won; } } \ No newline at end of file