From bf8123b7a520c568fe13cd16a993c0913c472e66 Mon Sep 17 00:00:00 2001 From: davidmfritz <> Date: Wed, 31 Oct 2018 22:50:13 +0100 Subject: [PATCH 1/4] Implementation of the card Clear the Land --- Mage.Sets/src/mage/cards/c/ClearTheLand.java | 91 +++++++++++++++++++ Mage.Sets/src/mage/sets/MercadianMasques.java | 1 + 2 files changed, 92 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/c/ClearTheLand.java diff --git a/Mage.Sets/src/mage/cards/c/ClearTheLand.java b/Mage.Sets/src/mage/cards/c/ClearTheLand.java new file mode 100644 index 0000000000..45c621021e --- /dev/null +++ b/Mage.Sets/src/mage/cards/c/ClearTheLand.java @@ -0,0 +1,91 @@ +package mage.cards.c; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.cards.Cards; +import mage.cards.CardsImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.game.Game; +import mage.players.Library; +import mage.players.Player; +import mage.players.Players; + +/** + * + * @author davidmfritz + */ +public final class ClearTheLand extends CardImpl { + + public ClearTheLand(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{G}"); + + + // Each player reveals the top five cards of his or her library, puts all land cards revealed this way onto the battlefield tapped, and exiles the rest. + getSpellAbility().addEffect(new ClearTheLandEffect()); + } + + public ClearTheLand(final ClearTheLand card) { + super(card); + } + + @Override + public ClearTheLand copy() { + return new ClearTheLand(this); + } +} + +class ClearTheLandEffect extends OneShotEffect { + + public ClearTheLandEffect() { + super(Outcome.Benefit); + this.staticText = "Each player reveals the top five cards of his or her library, puts all land cards revealed this way onto the battlefield tapped, and exiles the rest."; + } + + public ClearTheLandEffect(final ClearTheLandEffect effect) { + super(effect); + } + + @Override + public ClearTheLandEffect copy() { + return new ClearTheLandEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + + int numOfCardsToReveal = 5; + boolean tapped = true; + + Player controller = game.getPlayer(source.getControllerId()); + + if (controller != null) { + Players allPlayers = game.getPlayers(); + for (Player player : allPlayers.values()) { + if (player != null) { + Library library = player.getLibrary(); + Cards cardsToReveal = new CardsImpl(); + for (int i = 0; i < numOfCardsToReveal; i++) { + if (library.hasCards()) { + Card card = library.getFromTop(game); + cardsToReveal.add(card); + if (card.isLand()) { + player.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, true, null); + } else { + player.moveCards(card, Zone.EXILED, source, game); + } + } + } + player.revealCards(source, "Revealed cards for " + player.getName(), cardsToReveal, game); + } + } + return true; + } + return false; + } +} diff --git a/Mage.Sets/src/mage/sets/MercadianMasques.java b/Mage.Sets/src/mage/sets/MercadianMasques.java index a1110e968c..aa70db5e8a 100644 --- a/Mage.Sets/src/mage/sets/MercadianMasques.java +++ b/Mage.Sets/src/mage/sets/MercadianMasques.java @@ -75,6 +75,7 @@ public final class MercadianMasques extends ExpansionSet { cards.add(new SetCardInfo("Cho-Manno, Revolutionary", 11, Rarity.RARE, mage.cards.c.ChoMannoRevolutionary.class)); cards.add(new SetCardInfo("Cho-Manno's Blessing", 12, Rarity.COMMON, mage.cards.c.ChoMannosBlessing.class)); cards.add(new SetCardInfo("Cinder Elemental", 183, Rarity.UNCOMMON, mage.cards.c.CinderElemental.class)); + cards.add(new SetCardInfo("Clear the Land", 235, Rarity.RARE, mage.cards.c.ClearTheLand.class)); cards.add(new SetCardInfo("Close Quarters", 184, Rarity.UNCOMMON, mage.cards.c.CloseQuarters.class)); cards.add(new SetCardInfo("Cloud Sprite", 67, Rarity.COMMON, mage.cards.c.CloudSprite.class)); cards.add(new SetCardInfo("Coastal Piracy", 68, Rarity.UNCOMMON, mage.cards.c.CoastalPiracy.class)); From 336732eba28cd53c5031334bb0b316280ead3f40 Mon Sep 17 00:00:00 2001 From: davidmfritz Date: Wed, 31 Oct 2018 23:27:16 +0100 Subject: [PATCH 2/4] Performance fix to get out of the loop quicker if library is empty --- Mage.Sets/src/mage/cards/c/ClearTheLand.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Mage.Sets/src/mage/cards/c/ClearTheLand.java b/Mage.Sets/src/mage/cards/c/ClearTheLand.java index 45c621021e..1bc1f4ad01 100644 --- a/Mage.Sets/src/mage/cards/c/ClearTheLand.java +++ b/Mage.Sets/src/mage/cards/c/ClearTheLand.java @@ -71,14 +71,15 @@ class ClearTheLandEffect extends OneShotEffect { Library library = player.getLibrary(); Cards cardsToReveal = new CardsImpl(); for (int i = 0; i < numOfCardsToReveal; i++) { - if (library.hasCards()) { - Card card = library.getFromTop(game); - cardsToReveal.add(card); - if (card.isLand()) { - player.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, true, null); - } else { - player.moveCards(card, Zone.EXILED, source, game); - } + if (!library.hasCards()) { + break; + } + Card card = library.getFromTop(game); + cardsToReveal.add(card); + if (card.isLand()) { + player.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, true, null); + } else { + player.moveCards(card, Zone.EXILED, source, game); } } player.revealCards(source, "Revealed cards for " + player.getName(), cardsToReveal, game); From 1dc421a545bac0d0f67726206986f2c6579f342c Mon Sep 17 00:00:00 2001 From: davidmfritz Date: Thu, 1 Nov 2018 10:13:57 +0100 Subject: [PATCH 3/4] Fixed to get the correct player list Refactor to reveal first, then take action --- Mage.Sets/src/mage/cards/c/ClearTheLand.java | 26 +++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Mage.Sets/src/mage/cards/c/ClearTheLand.java b/Mage.Sets/src/mage/cards/c/ClearTheLand.java index 1bc1f4ad01..13b9be2f02 100644 --- a/Mage.Sets/src/mage/cards/c/ClearTheLand.java +++ b/Mage.Sets/src/mage/cards/c/ClearTheLand.java @@ -14,7 +14,6 @@ import mage.constants.Zone; import mage.game.Game; import mage.players.Library; import mage.players.Player; -import mage.players.Players; /** * @@ -59,30 +58,27 @@ class ClearTheLandEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int numOfCardsToReveal = 5; boolean tapped = true; Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - Players allPlayers = game.getPlayers(); - for (Player player : allPlayers.values()) { + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); if (player != null) { Library library = player.getLibrary(); Cards cardsToReveal = new CardsImpl(); - for (int i = 0; i < numOfCardsToReveal; i++) { - if (!library.hasCards()) { - break; - } - Card card = library.getFromTop(game); - cardsToReveal.add(card); - if (card.isLand()) { - player.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, true, null); - } else { - player.moveCards(card, Zone.EXILED, source, game); + cardsToReveal.addAll(library.getTopCards(game, 5)); + if (!cardsToReveal.isEmpty()) { + player.revealCards(source, "Revealed cards for " + player.getName(), cardsToReveal, game); + for (Card card : cardsToReveal.getCards(game)) { + if (card.isLand()) { + player.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, true, null); + } else { + player.moveCards(card, Zone.EXILED, source, game); + } } } - player.revealCards(source, "Revealed cards for " + player.getName(), cardsToReveal, game); } } return true; From c37832944ea9ec003dba0f792e614067e885b802 Mon Sep 17 00:00:00 2001 From: davidmfritz Date: Thu, 1 Nov 2018 11:51:36 +0100 Subject: [PATCH 4/4] Fixed cards to put onto the battlefield to one call Fixed cards to put into exile to one call --- Mage.Sets/src/mage/cards/c/ClearTheLand.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Mage.Sets/src/mage/cards/c/ClearTheLand.java b/Mage.Sets/src/mage/cards/c/ClearTheLand.java index 13b9be2f02..abb2b34557 100644 --- a/Mage.Sets/src/mage/cards/c/ClearTheLand.java +++ b/Mage.Sets/src/mage/cards/c/ClearTheLand.java @@ -71,13 +71,17 @@ class ClearTheLandEffect extends OneShotEffect { cardsToReveal.addAll(library.getTopCards(game, 5)); if (!cardsToReveal.isEmpty()) { player.revealCards(source, "Revealed cards for " + player.getName(), cardsToReveal, game); + Cards cardsToPutOnBattlefield = new CardsImpl(); + Cards cardsToExile = new CardsImpl(); for (Card card : cardsToReveal.getCards(game)) { if (card.isLand()) { - player.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, true, null); + cardsToPutOnBattlefield.add(card); } else { - player.moveCards(card, Zone.EXILED, source, game); + cardsToExile.add(card); } } + player.moveCards(cardsToPutOnBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, tapped, false, true, null); + player.moveCards(cardsToExile.getCards(game), Zone.EXILED, source, game); } } }