updated Krark's Thumb, still doesn't work in multiples

This commit is contained in:
Evan Kranzler 2019-01-15 16:55:45 -05:00
parent 57a362ae29
commit c34f611279
5 changed files with 51 additions and 18 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);
}
/**

View file

@ -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);