diff --git a/Mage.Sets/src/mage/cards/k/KrarksThumb.java b/Mage.Sets/src/mage/cards/k/KrarksThumb.java index 3acb3bde5a..66f31eb386 100644 --- a/Mage.Sets/src/mage/cards/k/KrarksThumb.java +++ b/Mage.Sets/src/mage/cards/k/KrarksThumb.java @@ -1,7 +1,6 @@ package mage.cards.k; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ReplacementEffectImpl; @@ -9,25 +8,28 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; import mage.game.Game; +import mage.game.events.FlipCoinEvent; import mage.game.events.GameEvent; import mage.players.Player; +import mage.util.CardUtil; import mage.util.RandomUtil; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class KrarksThumb extends CardImpl { public KrarksThumb(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{2}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}"); addSuperType(SuperType.LEGENDARY); // If you would flip a coin, instead flip two coins and ignore one. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new KrarksThumbEffect())); } - public KrarksThumb(final KrarksThumb card) { + private KrarksThumb(final KrarksThumb card) { super(card); } @@ -44,26 +46,30 @@ class KrarksThumbEffect extends ReplacementEffectImpl { staticText = "If you would flip a coin, instead flip two coins and ignore one"; } - KrarksThumbEffect(final KrarksThumbEffect effect) { + private KrarksThumbEffect(final KrarksThumbEffect effect) { super(effect); } @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player player = game.getPlayer(event.getPlayerId()); - if (player != null) { - // because second flip is ignored it may not be done by the player method - boolean secondCoinFlip = RandomUtil.nextBoolean(); - if (!game.isSimulation()) { - game.informPlayers("[Flip a coin] " + player.getLogName() + (secondCoinFlip ? " won (head)." : " lost (tail).")); - } - if (player.chooseUse(outcome, "Ignore the first coin flip?", source, game)) { - event.setFlag(secondCoinFlip); - game.informPlayers(player.getLogName() + " ignores the first coin flip."); - } else { - game.informPlayers(player.getLogName() + " ignores the second coin flip."); - } + if (player == null || !player.getId().equals(source.getControllerId())) { + return false; } + FlipCoinEvent flipEvent = (FlipCoinEvent) event; + boolean secondFlip = RandomUtil.nextBoolean(); + game.informPlayers(player.getLogName() + " flipped a " + flipEvent.getResultName() + + " and a " + CardUtil.booleanToFlipName(secondFlip) + ); + boolean chosenFlip = player.chooseUse( + Outcome.Benefit, "Choose which coin you want", + "(You chose " + flipEvent.getChosenName() + ")", + flipEvent.getResultName(), CardUtil.booleanToFlipName(secondFlip), source, game + ); + if (!chosenFlip) { + flipEvent.setResult(secondFlip); + } + game.informPlayers(player.getLogName() + " chooses to keep " + flipEvent.getResultName()); return false; } diff --git a/Mage/src/main/java/mage/game/events/CoinFlippedEvent.java b/Mage/src/main/java/mage/game/events/CoinFlippedEvent.java index 8360680db2..b7dad08225 100644 --- a/Mage/src/main/java/mage/game/events/CoinFlippedEvent.java +++ b/Mage/src/main/java/mage/game/events/CoinFlippedEvent.java @@ -1,5 +1,7 @@ package mage.game.events; +import mage.util.CardUtil; + import java.util.UUID; /** @@ -21,10 +23,18 @@ public class CoinFlippedEvent extends GameEvent { return result; } + public String getResultName() { + return CardUtil.booleanToFlipName(result); + } + public boolean getChosen() { return chosen; } + public String getChosenName() { + return CardUtil.booleanToFlipName(chosen); + } + public boolean isWinnable() { return winnable; } diff --git a/Mage/src/main/java/mage/game/events/FlipCoinEvent.java b/Mage/src/main/java/mage/game/events/FlipCoinEvent.java index 6e9e268292..c2dceaa73e 100644 --- a/Mage/src/main/java/mage/game/events/FlipCoinEvent.java +++ b/Mage/src/main/java/mage/game/events/FlipCoinEvent.java @@ -1,5 +1,7 @@ package mage.game.events; +import mage.util.CardUtil; + import java.util.UUID; /** @@ -21,6 +23,10 @@ public class FlipCoinEvent extends GameEvent { return result; } + public String getResultName() { + return CardUtil.booleanToFlipName(result); + } + public void setResult(boolean result) { this.result = result; } @@ -29,6 +35,10 @@ public class FlipCoinEvent extends GameEvent { return chosen; } + public String getChosenName() { + return CardUtil.booleanToFlipName(chosen); + } + public boolean isWinnable() { return winnable; } diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 95e7e60fbc..abf0db8c5b 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2558,7 +2558,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean flipCoin(Ability source, Game game, boolean winnable) { - return this.flipCoin(source, game, true, null); + return this.flipCoin(source, game, winnable, null); } /** diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 9b3cfe75ca..c81981296e 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -354,6 +354,13 @@ public final class CardUtil { return message; } + public static String booleanToFlipName(boolean flip) { + if (flip) { + return "Heads"; + } + return "Tails"; + } + public static boolean checkNumeric(String s) { return s.chars().allMatch(Character::isDigit);