From 74c1cbf6d902b7615b6d2326fdfa97c4edee8ff8 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 16 Jan 2019 15:11:14 -0500 Subject: [PATCH 1/6] begin fix for multiple copies of Krark's Thumb --- .../java/org/mage/test/player/TestPlayer.java | 10 +++ .../java/org/mage/test/stub/PlayerStub.java | 10 +++ Mage/src/main/java/mage/players/Player.java | 63 ++++++++++--------- .../main/java/mage/players/PlayerImpl.java | 14 +++++ 4 files changed, 68 insertions(+), 29 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 4842c49e6d..9a2b439da0 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -2418,6 +2418,16 @@ public class TestPlayer implements Player { computerPlayer.setLoyaltyUsePerTurn(loyaltyUsePerTurn); } + @Override + public int getExtraCoinFlips() { + return computerPlayer.getExtraCoinFlips(); + } + + @Override + public void setExtraCoinFlips(int extraCoinFlips) { + computerPlayer.setExtraCoinFlips(extraCoinFlips); + } + @Override public int getMaxHandSize() { return computerPlayer.getMaxHandSize(); diff --git a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java index 384d89c21f..99e0f8d2ec 100644 --- a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java +++ b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java @@ -262,6 +262,16 @@ public class PlayerStub implements Player { } + @Override + public int getExtraCoinFlips() { + return 0; + } + + @Override + public void setExtraCoinFlips(int extraCoinFlips) { + + } + @Override public int getMaxHandSize() { return 0; diff --git a/Mage/src/main/java/mage/players/Player.java b/Mage/src/main/java/mage/players/Player.java index 0686edb5f4..5816fe8231 100644 --- a/Mage/src/main/java/mage/players/Player.java +++ b/Mage/src/main/java/mage/players/Player.java @@ -74,7 +74,7 @@ public interface Player extends MageItem, Copyable { void setLife(int life, Game game, UUID sourceId); /** - * @param amount amount of life loss + * @param amount amount of life loss * @param game * @param atCombat was the source combat damage * @return @@ -141,6 +141,10 @@ public interface Player extends MageItem, Copyable { void setLoyaltyUsePerTurn(int loyaltyUsePerTurn); + int getExtraCoinFlips(); + + void setExtraCoinFlips(int getExtraCoinFlips); + int getMaxHandSize(); void setMaxHandSize(int maxHandSize); @@ -347,7 +351,7 @@ public interface Player extends MageItem, Copyable { * @param target * @param game * @param targetPlayerId player whose library will be searched - * @param triggerEvents whether searching will trigger any game events + * @param triggerEvents whether searching will trigger any game events * @return true if search was successful */ boolean searchLibrary(TargetCardInLibrary target, Game game, UUID targetPlayerId, boolean triggerEvents); @@ -355,6 +359,7 @@ public interface Player extends MageItem, Copyable { /** * Reveals all players' libraries. Useful for abilities like Jace, Architect of Thought's -8 * that have effects that require information from all libraries. + * * @param source * @param game * @return @@ -366,23 +371,23 @@ public interface Player extends MageItem, Copyable { /** * Plays a card if possible * - * @param card the card that can be cast + * @param card the card that can be cast * @param game - * @param noMana if it's a spell i can be cast without paying mana + * @param noMana if it's a spell i can be cast without paying mana * @param ignoreTiming if it's cast during the resolution of another spell - * no sorcery or play land timing restriction are checked. For a land it has - * to be the turn of the player playing that card. - * @param reference mage object that allows to play the card + * no sorcery or play land timing restriction are checked. For a land it has + * to be the turn of the player playing that card. + * @param reference mage object that allows to play the card * @return */ boolean playCard(Card card, Game game, boolean noMana, boolean ignoreTiming, MageObjectReference reference); /** - * @param card the land card to play + * @param card the land card to play * @param game * @param ignoreTiming false - it won't be checked if the stack is empty and - * you are able to play a Sorcery. It's still checked, if you are able to - * play a land concerning the number of lands you already played. + * you are able to play a Sorcery. It's still checked, if you are able to + * play a land concerning the number of lands you already played. * @return */ boolean playLand(Card card, Game game, boolean ignoreTiming); @@ -528,11 +533,11 @@ public interface Player extends MageItem, Copyable { /** * Moves the cards from cards to the bottom of the players library. * - * @param cards - list of cards that have to be moved - * @param game - game + * @param cards - list of cards that have to be moved + * @param game - game * @param anyOrder - true if player can determine the order of the cards - * else random order - * @param source - source ability + * else random order + * @param source - source ability * @return */ boolean putCardsOnBottomOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder); @@ -553,10 +558,10 @@ public interface Player extends MageItem, Copyable { /** * Moves the cards from cards to the top of players library. * - * @param cards - list of cards that have to be moved - * @param game - game + * @param cards - list of cards that have to be moved + * @param game - game * @param anyOrder - true if player can determine the order of the cards - * @param source - source ability + * @param source - source ability * @return */ boolean putCardsOnTopOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder); @@ -582,8 +587,8 @@ public interface Player extends MageItem, Copyable { /** * Choose the order in which blockers get damage assigned to * - * @param blockers list of blockers where to choose the next one from - * @param combatGroup the concerning combat group + * @param blockers list of blockers where to choose the next one from + * @param combatGroup the concerning combat group * @param blockerOrder the already set order of blockers * @param game * @return blocker next to add to the blocker order @@ -722,11 +727,11 @@ public interface Player extends MageItem, Copyable { * @param toZone * @param source * @param game - * @param tapped the cards are tapped on the battlefield - * @param faceDown the cards are face down in the to zone - * @param byOwner the card is moved (or put onto battlefield) by the owner - * of the card and if target zone is battlefield controls the permanent - * (instead of the controller of the source) + * @param tapped the cards are tapped on the battlefield + * @param faceDown the cards are face down in the to zone + * @param byOwner the card is moved (or put onto battlefield) by the owner + * of the card and if target zone is battlefield controls the permanent + * (instead of the controller of the source) * @param appliedEffects * @return */ @@ -762,7 +767,7 @@ public interface Player extends MageItem, Copyable { * list of applied effects is not saved * * @param card - * @param exileId exile zone id (optional) + * @param exileId exile zone id (optional) * @param exileName name of exile zone (optional) * @param sourceId * @param game @@ -804,7 +809,7 @@ public interface Player extends MageItem, Copyable { * @param sourceId * @param game * @param fromZone if null, this info isn't postet - * @param toTop to the top of the library else to the bottom + * @param toTop to the top of the library else to the bottom * @param withName show the card name in the log * @return */ @@ -829,10 +834,10 @@ public interface Player extends MageItem, Copyable { * without mana (null) or the mana set to manaCosts instead of its normal * mana costs. * - * @param sourceId the source that can be cast without mana + * @param sourceId the source that can be cast without mana * @param manaCosts alternate ManaCost, null if it can be cast without mana - * cost - * @param costs alternate other costs you need to pay + * cost + * @param costs alternate other costs you need to pay */ void setCastSourceIdWithAlternateMana(UUID sourceId, ManaCosts manaCosts, Costs costs); diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index abf0db8c5b..08c8b0d6bc 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -98,6 +98,7 @@ public abstract class PlayerImpl implements Player, Serializable { protected int landsPlayed; protected int landsPerTurn = 1; protected int loyaltyUsePerTurn = 1; + protected int extraCoinFlips = 1; protected int maxHandSize = 7; protected int maxAttackedBy = Integer.MAX_VALUE; protected ManaPool manaPool; @@ -223,6 +224,7 @@ public abstract class PlayerImpl implements Player, Serializable { this.landsPlayed = player.landsPlayed; this.landsPerTurn = player.landsPerTurn; this.loyaltyUsePerTurn = player.loyaltyUsePerTurn; + this.extraCoinFlips = player.extraCoinFlips; this.maxHandSize = player.maxHandSize; this.maxAttackedBy = player.maxAttackedBy; this.manaPool = player.manaPool.copy(); @@ -313,6 +315,7 @@ public abstract class PlayerImpl implements Player, Serializable { this.landsPlayed = player.getLandsPlayed(); this.landsPerTurn = player.getLandsPerTurn(); this.loyaltyUsePerTurn = player.getLoyaltyUsePerTurn(); + this.extraCoinFlips = player.getExtraCoinFlips(); this.maxHandSize = player.getMaxHandSize(); this.maxAttackedBy = player.getMaxAttackedBy(); this.manaPool = player.getManaPool().copy(); @@ -433,6 +436,7 @@ public abstract class PlayerImpl implements Player, Serializable { this.abilities.clear(); this.landsPerTurn = 1; this.loyaltyUsePerTurn = 1; + this.extraCoinFlips = 1; this.maxHandSize = 7; this.maxAttackedBy = Integer.MAX_VALUE; this.canGainLife = true; @@ -2079,6 +2083,16 @@ public abstract class PlayerImpl implements Player, Serializable { this.loyaltyUsePerTurn = loyaltyUsePerTurn; } + @Override + public int getExtraCoinFlips() { + return extraCoinFlips; + } + + @Override + public void setExtraCoinFlips(int extraCoinFlips) { + this.extraCoinFlips = extraCoinFlips; + } + @Override public int getMaxHandSize() { return maxHandSize; From 4736a608b191d28519fec5f215c064f440f94352 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 16 Jan 2019 15:23:01 -0500 Subject: [PATCH 2/6] Update Krark's Thumb --- Mage.Sets/src/mage/cards/k/KrarksThumb.java | 105 +++++++++++++------- 1 file changed, 68 insertions(+), 37 deletions(-) diff --git a/Mage.Sets/src/mage/cards/k/KrarksThumb.java b/Mage.Sets/src/mage/cards/k/KrarksThumb.java index d569882693..a0dbcc7061 100644 --- a/Mage.Sets/src/mage/cards/k/KrarksThumb.java +++ b/Mage.Sets/src/mage/cards/k/KrarksThumb.java @@ -3,16 +3,12 @@ package mage.cards.k; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ReplacementEffectImpl; +import mage.abilities.effects.ContinuousEffectImpl; 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; @@ -26,7 +22,7 @@ public final class KrarksThumb extends CardImpl { addSuperType(SuperType.LEGENDARY); // If you would flip a coin, instead flip two coins and ignore one. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new KrarksThumbEffect())); + this.addAbility(new SimpleStaticAbility(new KrarksThumbEffect())); } private KrarksThumb(final KrarksThumb card) { @@ -39,11 +35,11 @@ public final class KrarksThumb extends CardImpl { } } -class KrarksThumbEffect extends ReplacementEffectImpl { +class KrarksThumbEffect extends ContinuousEffectImpl { KrarksThumbEffect() { super(Duration.WhileOnBattlefield, Outcome.Benefit); - staticText = "If you would flip a coin, instead flip two coins and ignore one"; + staticText = "If you would flip a coin, instead flip two coins and ignore one."; } private KrarksThumbEffect(final KrarksThumbEffect effect) { @@ -51,36 +47,17 @@ class KrarksThumbEffect extends ReplacementEffectImpl { } @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Player player = game.getPlayer(event.getPlayerId()); - 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", - (flipEvent.isWinnable() ? "(You chose " + flipEvent.getChosenName() + ")" : null), - flipEvent.getResultName(), CardUtil.booleanToFlipName(secondFlip), source, game - ); - if (!chosenFlip) { - flipEvent.setResult(secondFlip); - } - game.informPlayers(player.getLogName() + " chooses to keep " + flipEvent.getResultName()); - return false; + public KrarksThumbEffect copy() { + return new KrarksThumbEffect(this); } @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.FLIP_COIN; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - return source.isControlledBy(event.getPlayerId()); + public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + controller.setExtraCoinFlips(controller.getExtraCoinFlips() + 1); + } + return true; } @Override @@ -89,7 +66,61 @@ class KrarksThumbEffect extends ReplacementEffectImpl { } @Override - public KrarksThumbEffect copy() { - return new KrarksThumbEffect(this); + public boolean hasLayer(Layer layer) { + return layer == Layer.RulesEffects; } } +//class KrarksThumbEffect extends ReplacementEffectImpl { +// +// KrarksThumbEffect() { +// super(Duration.WhileOnBattlefield, Outcome.Benefit); +// staticText = "If you would flip a coin, instead flip two coins and ignore one"; +// } +// +// 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 || !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", +// (flipEvent.isWinnable() ? "(You chose " + flipEvent.getChosenName() + ")" : null), +// flipEvent.getResultName(), CardUtil.booleanToFlipName(secondFlip), source, game +// ); +// if (!chosenFlip) { +// flipEvent.setResult(secondFlip); +// } +// game.informPlayers(player.getLogName() + " chooses to keep " + flipEvent.getResultName()); +// return false; +// } +// +// @Override +// public boolean checksEventType(GameEvent event, Game game) { +// return event.getType() == GameEvent.EventType.FLIP_COIN; +// } +// +// @Override +// public boolean applies(GameEvent event, Ability source, Game game) { +// return source.isControlledBy(event.getPlayerId()); +// } +// +// @Override +// public boolean apply(Game game, Ability source) { +// return false; +// } +// +// @Override +// public KrarksThumbEffect copy() { +// return new KrarksThumbEffect(this); +// } +//} From 1144bf3b4f1f6c62331ca8b3adc9f4c1f83616b4 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 16 Jan 2019 18:20:36 -0500 Subject: [PATCH 3/6] finished adding support for multiple copies of Krark's Thumb --- Mage.Sets/src/mage/cards/k/KrarksThumb.java | 2 +- .../main/java/mage/players/PlayerImpl.java | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Mage.Sets/src/mage/cards/k/KrarksThumb.java b/Mage.Sets/src/mage/cards/k/KrarksThumb.java index a0dbcc7061..294cfec83c 100644 --- a/Mage.Sets/src/mage/cards/k/KrarksThumb.java +++ b/Mage.Sets/src/mage/cards/k/KrarksThumb.java @@ -55,7 +55,7 @@ class KrarksThumbEffect extends ContinuousEffectImpl { public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - controller.setExtraCoinFlips(controller.getExtraCoinFlips() + 1); + controller.setExtraCoinFlips(2 * controller.getExtraCoinFlips()); } return true; } diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 08c8b0d6bc..c603706f90 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2587,13 +2587,34 @@ public abstract class PlayerImpl implements Player, Serializable { boolean chosen = false; if (winnable) { chosen = this.chooseUse(Outcome.Benefit, "Heads or tails?", "", "Heads", "Tails", source, game); - game.informPlayers(getLogName() + " chose " + (chosen ? "heads." : "tails.")); + game.informPlayers(getLogName() + " chose " + CardUtil.booleanToFlipName(chosen)); } boolean result = RandomUtil.nextBoolean(); FlipCoinEvent event = new FlipCoinEvent(playerId, source.getSourceId(), result, chosen, winnable); event.addAppliedEffects(appliedEffects); game.replaceEvent(event); - game.informPlayers(getLogName() + " got " + (event.getResult() ? "heads" : "tails")); + if (extraCoinFlips > 1) { + boolean canChooseHeads = event.getResult(); + boolean canChooseTails = !event.getResult(); + boolean tempFlip; + for (int i = 0; i < extraCoinFlips; i++) { + tempFlip = RandomUtil.nextBoolean(); + canChooseHeads = canChooseHeads || tempFlip; + canChooseTails = canChooseTails || !tempFlip; + game.informPlayers(getLogName() + " flipped " + CardUtil.booleanToFlipName(tempFlip)); + } + if (canChooseHeads && canChooseTails) { + event.setResult(chooseUse(Outcome.Benefit, "Choose which flip to keep", + (event.isWinnable() ? "(You called " + event.getChosenName() + ")" : null), + "Heads", "Tails", source, game + )); + } else if (canChooseHeads) { + event.setResult(true); + } else { + event.setResult(false); + } + } + game.informPlayers(getLogName() + " got " + CardUtil.booleanToFlipName(event.getResult())); if (event.isWinnable()) { game.informPlayers(getLogName() + " " + (event.getResult() == event.getChosen() ? "won" : "lost") + " the flip"); } From 191e9903bae6fc8bdf04647c71bcc378b8b9d36e Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 16 Jan 2019 18:25:00 -0500 Subject: [PATCH 4/6] removed some vestigial commented code --- Mage.Sets/src/mage/cards/k/KrarksThumb.java | 59 --------------------- 1 file changed, 59 deletions(-) diff --git a/Mage.Sets/src/mage/cards/k/KrarksThumb.java b/Mage.Sets/src/mage/cards/k/KrarksThumb.java index 294cfec83c..4cca44bc8a 100644 --- a/Mage.Sets/src/mage/cards/k/KrarksThumb.java +++ b/Mage.Sets/src/mage/cards/k/KrarksThumb.java @@ -64,63 +64,4 @@ class KrarksThumbEffect extends ContinuousEffectImpl { public boolean apply(Game game, Ability source) { return false; } - - @Override - public boolean hasLayer(Layer layer) { - return layer == Layer.RulesEffects; - } } -//class KrarksThumbEffect extends ReplacementEffectImpl { -// -// KrarksThumbEffect() { -// super(Duration.WhileOnBattlefield, Outcome.Benefit); -// staticText = "If you would flip a coin, instead flip two coins and ignore one"; -// } -// -// 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 || !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", -// (flipEvent.isWinnable() ? "(You chose " + flipEvent.getChosenName() + ")" : null), -// flipEvent.getResultName(), CardUtil.booleanToFlipName(secondFlip), source, game -// ); -// if (!chosenFlip) { -// flipEvent.setResult(secondFlip); -// } -// game.informPlayers(player.getLogName() + " chooses to keep " + flipEvent.getResultName()); -// return false; -// } -// -// @Override -// public boolean checksEventType(GameEvent event, Game game) { -// return event.getType() == GameEvent.EventType.FLIP_COIN; -// } -// -// @Override -// public boolean applies(GameEvent event, Ability source, Game game) { -// return source.isControlledBy(event.getPlayerId()); -// } -// -// @Override -// public boolean apply(Game game, Ability source) { -// return false; -// } -// -// @Override -// public KrarksThumbEffect copy() { -// return new KrarksThumbEffect(this); -// } -//} From 837503d8f407e1c56c644a2b9aca38e8be0e3a35 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 17 Jan 2019 10:32:02 -0500 Subject: [PATCH 5/6] reworked coin doubling again for some reason --- Mage.Sets/src/mage/cards/k/KrarksThumb.java | 32 +++++++++++++------ .../java/org/mage/test/player/TestPlayer.java | 10 ------ .../java/org/mage/test/stub/PlayerStub.java | 10 ------ .../java/mage/game/events/FlipCoinEvent.java | 9 ++++++ Mage/src/main/java/mage/players/Player.java | 4 --- .../main/java/mage/players/PlayerImpl.java | 21 ++---------- 6 files changed, 34 insertions(+), 52 deletions(-) diff --git a/Mage.Sets/src/mage/cards/k/KrarksThumb.java b/Mage.Sets/src/mage/cards/k/KrarksThumb.java index 4cca44bc8a..09f0427eb2 100644 --- a/Mage.Sets/src/mage/cards/k/KrarksThumb.java +++ b/Mage.Sets/src/mage/cards/k/KrarksThumb.java @@ -3,12 +3,16 @@ package mage.cards.k; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.SuperType; import mage.game.Game; -import mage.players.Player; +import mage.game.events.FlipCoinEvent; +import mage.game.events.GameEvent; import java.util.UUID; @@ -35,7 +39,7 @@ public final class KrarksThumb extends CardImpl { } } -class KrarksThumbEffect extends ContinuousEffectImpl { +class KrarksThumbEffect extends ReplacementEffectImpl { KrarksThumbEffect() { super(Duration.WhileOnBattlefield, Outcome.Benefit); @@ -52,12 +56,20 @@ class KrarksThumbEffect extends ContinuousEffectImpl { } @Override - public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - controller.setExtraCoinFlips(2 * controller.getExtraCoinFlips()); - } - return true; + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + FlipCoinEvent flipCoinEvent = (FlipCoinEvent) event; + flipCoinEvent.setFlipCount(2 * flipCoinEvent.getFlipCount()); + return false; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.FLIP_COIN; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + return source.isControlledBy(event.getPlayerId()); } @Override diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 9a2b439da0..4842c49e6d 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -2418,16 +2418,6 @@ public class TestPlayer implements Player { computerPlayer.setLoyaltyUsePerTurn(loyaltyUsePerTurn); } - @Override - public int getExtraCoinFlips() { - return computerPlayer.getExtraCoinFlips(); - } - - @Override - public void setExtraCoinFlips(int extraCoinFlips) { - computerPlayer.setExtraCoinFlips(extraCoinFlips); - } - @Override public int getMaxHandSize() { return computerPlayer.getMaxHandSize(); diff --git a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java index 99e0f8d2ec..384d89c21f 100644 --- a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java +++ b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java @@ -262,16 +262,6 @@ public class PlayerStub implements Player { } - @Override - public int getExtraCoinFlips() { - return 0; - } - - @Override - public void setExtraCoinFlips(int extraCoinFlips) { - - } - @Override public int getMaxHandSize() { return 0; diff --git a/Mage/src/main/java/mage/game/events/FlipCoinEvent.java b/Mage/src/main/java/mage/game/events/FlipCoinEvent.java index c2dceaa73e..3dc799ad4e 100644 --- a/Mage/src/main/java/mage/game/events/FlipCoinEvent.java +++ b/Mage/src/main/java/mage/game/events/FlipCoinEvent.java @@ -11,6 +11,7 @@ public class FlipCoinEvent extends GameEvent { private boolean result; private final boolean chosen; private final boolean winnable; + private int flipCount = 1; public FlipCoinEvent(UUID playerId, UUID sourceId, boolean result, boolean chosen, boolean winnable) { super(EventType.FLIP_COIN, playerId, sourceId, playerId); @@ -43,6 +44,14 @@ public class FlipCoinEvent extends GameEvent { return winnable; } + public int getFlipCount() { + return flipCount; + } + + public void setFlipCount(int flipCount) { + this.flipCount = flipCount; + } + public CoinFlippedEvent getFlippedEvent() { return new CoinFlippedEvent(playerId, sourceId, result, chosen, winnable); } diff --git a/Mage/src/main/java/mage/players/Player.java b/Mage/src/main/java/mage/players/Player.java index 5816fe8231..286b98f5ac 100644 --- a/Mage/src/main/java/mage/players/Player.java +++ b/Mage/src/main/java/mage/players/Player.java @@ -141,10 +141,6 @@ public interface Player extends MageItem, Copyable { void setLoyaltyUsePerTurn(int loyaltyUsePerTurn); - int getExtraCoinFlips(); - - void setExtraCoinFlips(int getExtraCoinFlips); - int getMaxHandSize(); void setMaxHandSize(int maxHandSize); diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index c603706f90..fd777f1e11 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -98,7 +98,6 @@ public abstract class PlayerImpl implements Player, Serializable { protected int landsPlayed; protected int landsPerTurn = 1; protected int loyaltyUsePerTurn = 1; - protected int extraCoinFlips = 1; protected int maxHandSize = 7; protected int maxAttackedBy = Integer.MAX_VALUE; protected ManaPool manaPool; @@ -224,7 +223,6 @@ public abstract class PlayerImpl implements Player, Serializable { this.landsPlayed = player.landsPlayed; this.landsPerTurn = player.landsPerTurn; this.loyaltyUsePerTurn = player.loyaltyUsePerTurn; - this.extraCoinFlips = player.extraCoinFlips; this.maxHandSize = player.maxHandSize; this.maxAttackedBy = player.maxAttackedBy; this.manaPool = player.manaPool.copy(); @@ -315,7 +313,6 @@ public abstract class PlayerImpl implements Player, Serializable { this.landsPlayed = player.getLandsPlayed(); this.landsPerTurn = player.getLandsPerTurn(); this.loyaltyUsePerTurn = player.getLoyaltyUsePerTurn(); - this.extraCoinFlips = player.getExtraCoinFlips(); this.maxHandSize = player.getMaxHandSize(); this.maxAttackedBy = player.getMaxAttackedBy(); this.manaPool = player.getManaPool().copy(); @@ -436,7 +433,6 @@ public abstract class PlayerImpl implements Player, Serializable { this.abilities.clear(); this.landsPerTurn = 1; this.loyaltyUsePerTurn = 1; - this.extraCoinFlips = 1; this.maxHandSize = 7; this.maxAttackedBy = Integer.MAX_VALUE; this.canGainLife = true; @@ -2083,16 +2079,6 @@ public abstract class PlayerImpl implements Player, Serializable { this.loyaltyUsePerTurn = loyaltyUsePerTurn; } - @Override - public int getExtraCoinFlips() { - return extraCoinFlips; - } - - @Override - public void setExtraCoinFlips(int extraCoinFlips) { - this.extraCoinFlips = extraCoinFlips; - } - @Override public int getMaxHandSize() { return maxHandSize; @@ -2593,12 +2579,11 @@ public abstract class PlayerImpl implements Player, Serializable { FlipCoinEvent event = new FlipCoinEvent(playerId, source.getSourceId(), result, chosen, winnable); event.addAppliedEffects(appliedEffects); game.replaceEvent(event); - if (extraCoinFlips > 1) { + if (event.getFlipCount() > 1) { boolean canChooseHeads = event.getResult(); boolean canChooseTails = !event.getResult(); - boolean tempFlip; - for (int i = 0; i < extraCoinFlips; i++) { - tempFlip = RandomUtil.nextBoolean(); + for (int i = 1; i < event.getFlipCount(); i++) { + boolean tempFlip = RandomUtil.nextBoolean(); canChooseHeads = canChooseHeads || tempFlip; canChooseTails = canChooseTails || !tempFlip; game.informPlayers(getLogName() + " flipped " + CardUtil.booleanToFlipName(tempFlip)); From cbc814d38e9314cdfb2f6851e123a02c3e6a0fc5 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 17 Jan 2019 10:57:53 -0500 Subject: [PATCH 6/6] some log message changes --- Mage/src/main/java/mage/players/PlayerImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index fd777f1e11..155f74cecc 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2579,6 +2579,7 @@ public abstract class PlayerImpl implements Player, Serializable { FlipCoinEvent event = new FlipCoinEvent(playerId, source.getSourceId(), result, chosen, winnable); event.addAppliedEffects(appliedEffects); game.replaceEvent(event); + game.informPlayers(getLogName() + " flipped " + CardUtil.booleanToFlipName(event.getResult())); if (event.getFlipCount() > 1) { boolean canChooseHeads = event.getResult(); boolean canChooseTails = !event.getResult(); @@ -2598,8 +2599,8 @@ public abstract class PlayerImpl implements Player, Serializable { } else { event.setResult(false); } + game.informPlayers(getLogName() + " chose to keep " + CardUtil.booleanToFlipName(event.getResult())); } - game.informPlayers(getLogName() + " got " + CardUtil.booleanToFlipName(event.getResult())); if (event.isWinnable()) { game.informPlayers(getLogName() + " " + (event.getResult() == event.getChosen() ? "won" : "lost") + " the flip"); }