From f42bab2b16a1f720eedc456487f82af99108a248 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 5 Jun 2013 17:26:02 +0200 Subject: [PATCH] Added info how many cards still to discard in discard message of cleanup phase. Added replace effect for coin flipping. --- Mage/src/mage/game/events/GameEvent.java | 10 +++++++-- Mage/src/mage/game/turn/CleanupStep.java | 2 +- Mage/src/mage/game/turn/Turn.java | 7 +++++- Mage/src/mage/players/Player.java | 1 + Mage/src/mage/players/PlayerImpl.java | 28 +++++++++++++++++++----- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Mage/src/mage/game/events/GameEvent.java b/Mage/src/mage/game/events/GameEvent.java index 8f1225e8f9..0869bee074 100644 --- a/Mage/src/mage/game/events/GameEvent.java +++ b/Mage/src/mage/game/events/GameEvent.java @@ -103,6 +103,7 @@ public class GameEvent { SHUFFLE_LIBRARY, LIBRARY_SHUFFLED, ENCHANT_PLAYER, ENCHANTED_PLAYER, CAN_TAKE_MULLIGAN, + FLIP_COIN, //permanent events ENTERS_THE_BATTLEFIELD, @@ -187,14 +188,19 @@ public class GameEvent { return amount; } + public void setAmount(int amount) { + this.amount = amount; + } + public boolean getFlag() { return flag; } - public void setAmount(int amount) { - this.amount = amount; + public void setFlag(boolean flag) { + this.flag = flag; } + public String getData() { return data; } diff --git a/Mage/src/mage/game/turn/CleanupStep.java b/Mage/src/mage/game/turn/CleanupStep.java index a2545866a7..237c5153a2 100644 --- a/Mage/src/mage/game/turn/CleanupStep.java +++ b/Mage/src/mage/game/turn/CleanupStep.java @@ -57,7 +57,7 @@ public class CleanupStep extends Step { Player activePlayer = game.getPlayer(activePlayerId); game.getState().setPriorityPlayerId(activePlayer.getId()); //20091005 - 514.1 - if (!activePlayer.hasLeft() && !activePlayer.hasLost()) { + if (activePlayer.isInGame()) { activePlayer.discardToMax(game); activePlayer.setGameUnderYourControl(true); } diff --git a/Mage/src/mage/game/turn/Turn.java b/Mage/src/mage/game/turn/Turn.java index 55d39d083a..cbc0992b83 100644 --- a/Mage/src/mage/game/turn/Turn.java +++ b/Mage/src/mage/game/turn/Turn.java @@ -239,7 +239,12 @@ public class Turn implements Serializable { this.play(game, activePlayerId); } }*/ - +/** + * Used for some spells with end turn effect (e.g. Time Stop). + * + * @param game + * @param activePlayerId + */ public void endTurn(Game game, UUID activePlayerId) { // Exile all spells and abilities on the stack game.getStack().clear(); diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index fe17449661..82570a9b90 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -197,6 +197,7 @@ public interface Player extends MageItem, Copyable { boolean canBeTargetedBy(MageObject source, Game game); boolean hasProtectionFrom(MageObject source, Game game); boolean flipCoin(Game game); + boolean flipCoin(Game game, ArrayList appliedEffects); void discard(int amount, Ability source, Game game); void discardToMax(Game game); boolean discard(Card card, Ability source, Game game); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 52f366ee1b..e07fc63c35 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -28,6 +28,7 @@ package mage.players; +import java.awt.Event; import mage.Constants.AsThoughEffectType; import mage.Constants.Outcome; import mage.Constants.RangeOfInfluence; @@ -461,10 +462,16 @@ public abstract class PlayerImpl> implements Player, Ser @Override public void discardToMax(Game game) { - while (hand.size() > this.maxHandSize) { - TargetDiscard target = new TargetDiscard(playerId); - choose(Outcome.Discard, target, null, game); - discard(hand.get(target.getFirstTarget(), game), null, game); + int cardsStart = hand.size(); + if (cardsStart > this.maxHandSize) { + while (hand.size() > this.maxHandSize) { + TargetDiscard target = new TargetDiscard(playerId); + target.setTargetName(new StringBuilder(" card to discard (").append(hand.size() - this.maxHandSize).append(" in total)").toString()); + choose(Outcome.Discard, target, null, game); + discard(hand.get(target.getFirstTarget(), game), null, game); + } + int discarded =cardsStart - hand.size(); + game.informPlayers(new StringBuilder(getName()).append(" discards ").append(discarded).append(discarded == 1?"card":"cards").append(" (cleanup)").toString()); } } @@ -1347,15 +1354,24 @@ public abstract class PlayerImpl> implements Player, Ser return false; } + + @Override + public boolean flipCoin(Game game) { + return this.flipCoin(game, null); + } + /** * * @return true if player won the toss */ @Override - public boolean flipCoin(Game game) { + public boolean flipCoin(Game game, ArrayList appliedEffects) { boolean result = rnd.nextBoolean(); game.informPlayers("[Flip a coin] " + getName() + (result ? " won (head)." : " lost (tail).")); - return result; + GameEvent event = new GameEvent(GameEvent.EventType.FLIP_COIN, playerId, null, playerId, 0, result); + event.setAppliedEffects(appliedEffects); + game.replaceEvent(event); + return event.getFlag(); } @Override