mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 19:41:59 -08:00
Fixes #3022 : Game of Chaos refactor and fix
This commit is contained in:
parent
523703b373
commit
dcc8dc68f9
1 changed files with 18 additions and 19 deletions
|
|
@ -87,38 +87,33 @@ class GameOfChaosEffect extends OneShotEffect {
|
||||||
Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source));
|
Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||||
|
|
||||||
if (you != null && targetOpponent != null) {
|
if (you != null && targetOpponent != null) {
|
||||||
|
|
||||||
boolean continueFlipping = true;
|
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
|
boolean youWonLastFlip = false; // tracks if you won the flip last, negation of it means opponent won last
|
||||||
int lifeAmount = 1; // starts with 1 life
|
int lifeAmount = 1; // starts stakes with 1 life
|
||||||
|
|
||||||
while (continueFlipping) {
|
while (continueFlipping) {
|
||||||
|
if (youWonFlip) { // flipper of coin wins, flipper gain 1 and non-flipper loses 1
|
||||||
if (youWinFlip) { // flipper of coin wins, flipper gain 1 and non-flipper loses 1
|
|
||||||
handleLifeChangesFromFlip(game, you, targetOpponent, lifeAmount);
|
handleLifeChangesFromFlip(game, you, targetOpponent, lifeAmount);
|
||||||
if (targetOpponent.canRespond() && you.canRespond()) {
|
if (!cannotContinueFlipping(you, targetOpponent)) {
|
||||||
continueFlipping = you.chooseUse(outcome, "Flip again?", source, game);
|
continueFlipping = you.chooseUse(outcome, "You gained " + lifeAmount + " life! Flip again for double the life stakes?", source, game);
|
||||||
youWonLastFlip = true;
|
youWonLastFlip = true;
|
||||||
}
|
}
|
||||||
} else { // non-flipper wins, flipper lose 1 and non-flipper gains 1
|
} else { // non-flipper wins, flipper lose 1 and non-flipper gains 1
|
||||||
handleLifeChangesFromFlip(game, targetOpponent, you, lifeAmount);
|
handleLifeChangesFromFlip(game, targetOpponent, you, lifeAmount);
|
||||||
if (targetOpponent.canRespond() && you.canRespond()) {
|
if (!cannotContinueFlipping(you, targetOpponent)) {
|
||||||
continueFlipping = targetOpponent.chooseUse(outcome, "Flip again?", source, game);
|
continueFlipping = targetOpponent.chooseUse(outcome, "You gained " + lifeAmount + " life! Flip again for double the life stakes?", source, game);
|
||||||
youWonLastFlip = false;
|
youWonLastFlip = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetOpponent.canRespond() || !you.canRespond()) {
|
if (cannotContinueFlipping(you, targetOpponent))
|
||||||
continueFlipping = false;
|
continueFlipping = false;
|
||||||
}
|
|
||||||
|
|
||||||
if (continueFlipping) {
|
if (continueFlipping) {
|
||||||
lifeAmount *= 2; // double the life each time
|
lifeAmount *= 2; // double the life each time
|
||||||
if (youWonLastFlip) {
|
youWonFlip = youWonLastFlip ? you.flipCoin(game) : !targetOpponent.flipCoin(game); // negate the opponent's results for proper evaluation of if you won in next iteration
|
||||||
youWinFlip = you.flipCoin(game);
|
|
||||||
} else {
|
|
||||||
youWinFlip = !targetOpponent.flipCoin(game); // negate the results for proper evaluation above
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,4 +126,8 @@ class GameOfChaosEffect extends OneShotEffect {
|
||||||
playerGainingLife.gainLife(lifeAmount, game);
|
playerGainingLife.gainLife(lifeAmount, game);
|
||||||
playerLosingLife.loseLife(lifeAmount, game, false);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue