From 523703b373a4723002974150fba981b38f185b0e Mon Sep 17 00:00:00 2001 From: drmDev Date: Sun, 26 Mar 2017 10:33:41 -0400 Subject: [PATCH 1/2] merge --- Mage.Sets/src/mage/cards/g/GameOfChaos.java | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Mage.Sets/src/mage/cards/g/GameOfChaos.java b/Mage.Sets/src/mage/cards/g/GameOfChaos.java index c5fe1e97ec..fad781efce 100644 --- a/Mage.Sets/src/mage/cards/g/GameOfChaos.java +++ b/Mage.Sets/src/mage/cards/g/GameOfChaos.java @@ -85,38 +85,36 @@ class GameOfChaosEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player you = game.getPlayer(source.getControllerId()); Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source)); - if (you != null && targetOpponent != null) { - + + if (you != null && targetOpponent != null) { boolean continueFlipping = true; boolean youWinFlip = you.flipCoin(game); // controller flips first - boolean controllerWonLast = false; + boolean youWonLastFlip = false; // tracks if you won the flip last, negation of it means opponent won last int lifeAmount = 1; // starts with 1 life while (continueFlipping) { if (youWinFlip) { // flipper of coin wins, flipper gain 1 and non-flipper loses 1 - you.gainLife(lifeAmount, game); - targetOpponent.loseLife(lifeAmount, game, false); + handleLifeChangesFromFlip(game, you, targetOpponent, lifeAmount); if (targetOpponent.canRespond() && you.canRespond()) { continueFlipping = you.chooseUse(outcome, "Flip again?", source, game); - controllerWonLast = true; + youWonLastFlip = true; } } else { // non-flipper wins, flipper lose 1 and non-flipper gains 1 - you.loseLife(lifeAmount, game, false); - targetOpponent.gainLife(lifeAmount, game); + handleLifeChangesFromFlip(game, targetOpponent, you, lifeAmount); if (targetOpponent.canRespond() && you.canRespond()) { continueFlipping = targetOpponent.chooseUse(outcome, "Flip again?", source, game); - controllerWonLast = false; + youWonLastFlip = false; } } - if (!targetOpponent.canRespond() && !you.canRespond()) { + if (!targetOpponent.canRespond() || !you.canRespond()) { continueFlipping = false; } - if (continueFlipping) { + if (continueFlipping) { lifeAmount *= 2; // double the life each time - if (controllerWonLast) { + if (youWonLastFlip) { youWinFlip = you.flipCoin(game); } else { youWinFlip = !targetOpponent.flipCoin(game); // negate the results for proper evaluation above @@ -128,4 +126,9 @@ class GameOfChaosEffect extends OneShotEffect { } return false; } + + private void handleLifeChangesFromFlip(Game game, Player playerGainingLife, Player playerLosingLife, int lifeAmount) { + playerGainingLife.gainLife(lifeAmount, game); + playerLosingLife.loseLife(lifeAmount, game, false); + } } \ No newline at end of file From dcc8dc68f9a854ade71a27e5ec451bd9fa689f35 Mon Sep 17 00:00:00 2001 From: drmDev Date: Sun, 26 Mar 2017 11:55:18 -0400 Subject: [PATCH 2/2] Fixes #3022 : Game of Chaos refactor and fix --- Mage.Sets/src/mage/cards/g/GameOfChaos.java | 37 ++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/Mage.Sets/src/mage/cards/g/GameOfChaos.java b/Mage.Sets/src/mage/cards/g/GameOfChaos.java index fad781efce..e59575b636 100644 --- a/Mage.Sets/src/mage/cards/g/GameOfChaos.java +++ b/Mage.Sets/src/mage/cards/g/GameOfChaos.java @@ -86,39 +86,34 @@ class GameOfChaosEffect extends OneShotEffect { Player you = game.getPlayer(source.getControllerId()); Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source)); - if (you != null && targetOpponent != null) { + if (you != null && targetOpponent != null) { + boolean continueFlipping = true; - boolean youWinFlip = you.flipCoin(game); // controller flips first + boolean youWonFlip = you.flipCoin(game); // controller flips first boolean youWonLastFlip = false; // tracks if you won the flip last, negation of it means opponent won last - int lifeAmount = 1; // starts with 1 life - - while (continueFlipping) { - - if (youWinFlip) { // flipper of coin wins, flipper gain 1 and non-flipper loses 1 + int lifeAmount = 1; // starts stakes with 1 life + + while (continueFlipping) { + if (youWonFlip) { // flipper of coin wins, flipper gain 1 and non-flipper loses 1 handleLifeChangesFromFlip(game, you, targetOpponent, lifeAmount); - if (targetOpponent.canRespond() && you.canRespond()) { - continueFlipping = you.chooseUse(outcome, "Flip again?", source, game); + if (!cannotContinueFlipping(you, targetOpponent)) { + continueFlipping = you.chooseUse(outcome, "You gained " + lifeAmount + " life! Flip again for double the life stakes?", source, game); youWonLastFlip = true; } } else { // non-flipper wins, flipper lose 1 and non-flipper gains 1 handleLifeChangesFromFlip(game, targetOpponent, you, lifeAmount); - if (targetOpponent.canRespond() && you.canRespond()) { - continueFlipping = targetOpponent.chooseUse(outcome, "Flip again?", source, game); + if (!cannotContinueFlipping(you, targetOpponent)) { + continueFlipping = targetOpponent.chooseUse(outcome, "You gained " + lifeAmount + " life! Flip again for double the life stakes?", source, game); youWonLastFlip = false; } } - if (!targetOpponent.canRespond() || !you.canRespond()) { + if (cannotContinueFlipping(you, targetOpponent)) continueFlipping = false; - } - + if (continueFlipping) { lifeAmount *= 2; // double the life each time - if (youWonLastFlip) { - youWinFlip = you.flipCoin(game); - } else { - youWinFlip = !targetOpponent.flipCoin(game); // negate the results for proper evaluation above - } + youWonFlip = youWonLastFlip ? you.flipCoin(game) : !targetOpponent.flipCoin(game); // negate the opponent's results for proper evaluation of if you won in next iteration } } @@ -131,4 +126,8 @@ class GameOfChaosEffect extends OneShotEffect { playerGainingLife.gainLife(lifeAmount, game); playerLosingLife.loseLife(lifeAmount, game, false); } + + private boolean cannotContinueFlipping(Player you, Player opponent) { + return (!you.canRespond() || !opponent.canRespond() || (you.canLoseByZeroOrLessLife() && you.getLife() <= 0) || (opponent.canLoseByZeroOrLessLife() && opponent.getLife() <= 0)); + } } \ No newline at end of file