From e2f960c8fd39a5e81b45d1be1f3c86da933149dd Mon Sep 17 00:00:00 2001 From: bugfi5h Date: Wed, 26 Apr 2017 19:41:18 +0200 Subject: [PATCH 1/3] Added Card: Natural Balance --- .../src/mage/cards/n/NaturalBalance.java | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/n/NaturalBalance.java diff --git a/Mage.Sets/src/mage/cards/n/NaturalBalance.java b/Mage.Sets/src/mage/cards/n/NaturalBalance.java new file mode 100644 index 0000000000..16ac660a5f --- /dev/null +++ b/Mage.Sets/src/mage/cards/n/NaturalBalance.java @@ -0,0 +1,137 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.cards.n; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.cards.CardsImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.TargetController; +import mage.constants.Zone; +import mage.filter.common.FilterBasicLandCard; +import mage.filter.common.FilterControlledLandPermanent; +import mage.filter.common.FilterLandPermanent; +import mage.filter.predicate.permanent.ControllerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.players.PlayerList; +import mage.target.common.TargetCardInLibrary; +import mage.target.common.TargetControlledPermanent; + +/** + * + * @author Rene - bugisemail at gmail dot com + */ +public class NaturalBalance extends CardImpl { + + public NaturalBalance(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{G}{G}"); + + + // Each player who controls six or more lands chooses five lands he or she controls and sacrifices the rest. Each player who controls four or fewer lands may search his or her library for up to X basic land cards and put them onto the battlefield, where X is five minus the number of lands he or she controls. Then each player who searched his or her library this way shuffles it. + this.getSpellAbility().addEffect(new NaturalBalanceEffect()); + } + + public NaturalBalance(final NaturalBalance card) { + super(card); + } + + @Override + public NaturalBalance copy() { + return new NaturalBalance(this); + } + + class NaturalBalanceEffect extends OneShotEffect { + + public NaturalBalanceEffect() { + super(Outcome.PutCardInPlay); + this.staticText = "Each player who controls six or more lands chooses five lands he or she controls and sacrifices the rest. Each player who controls four or fewer lands may search his or her library for up to X basic land cards and put them onto the battlefield, where X is five minus the number of lands he or she controls. Then each player who searched his or her library this way shuffles it."; + } + + public NaturalBalanceEffect(final NaturalBalanceEffect effect) { + super(effect); + } + + @Override + public NaturalBalanceEffect copy() { + return new NaturalBalanceEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) + { + PlayerList players = game.getState().getPlayerList(controller.getId()); + for (UUID playerId : players) + { + Player player = game.getPlayer(playerId); + if (player != null) + { + int landCount = game.getBattlefield().countAll(new FilterControlledLandPermanent(), player.getId(), game); + if (landCount>5) + { + //Sacrifice lands till you have 5 + TargetControlledPermanent target = new TargetControlledPermanent(5, 5, new FilterControlledLandPermanent("lands to keep"), true); + if (target.choose(Outcome.Sacrifice, player.getId(), source.getSourceId(), game)) + { + for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledLandPermanent(), player.getId(), source.getSourceId(), game)) + { + if (permanent != null && !target.getTargets().contains(permanent.getId())) + { + permanent.sacrifice(source.getId(), game); + } + } + } + }else if(landCount<5) + { + //Play basic lands till you have 5 + FilterLandPermanent filter = new FilterLandPermanent(); + filter.add(new ControllerPredicate(TargetController.YOU)); + int amount = 5 - landCount; + TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterBasicLandCard()); + if (player.searchLibrary(target, game)) + { + player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null); + } + player.shuffleLibrary(source, game); + } + } + } + return true; + } + return false; + } + } +} From f20496e40ffe61f7d6fa2401f4427d505ce3662f Mon Sep 17 00:00:00 2001 From: bugfi5h Date: Wed, 26 Apr 2017 23:11:46 +0200 Subject: [PATCH 2/3] Auto indent class --- .../src/mage/cards/n/NaturalBalance.java | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/Mage.Sets/src/mage/cards/n/NaturalBalance.java b/Mage.Sets/src/mage/cards/n/NaturalBalance.java index 16ac660a5f..ad75b2eec3 100644 --- a/Mage.Sets/src/mage/cards/n/NaturalBalance.java +++ b/Mage.Sets/src/mage/cards/n/NaturalBalance.java @@ -57,7 +57,6 @@ public class NaturalBalance extends CardImpl { public NaturalBalance(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{G}{G}"); - // Each player who controls six or more lands chooses five lands he or she controls and sacrifices the rest. Each player who controls four or fewer lands may search his or her library for up to X basic land cards and put them onto the battlefield, where X is five minus the number of lands he or she controls. Then each player who searched his or her library this way shuffles it. this.getSpellAbility().addEffect(new NaturalBalanceEffect()); @@ -71,7 +70,7 @@ public class NaturalBalance extends CardImpl { public NaturalBalance copy() { return new NaturalBalance(this); } - + class NaturalBalanceEffect extends OneShotEffect { public NaturalBalanceEffect() { @@ -91,42 +90,33 @@ public class NaturalBalance extends CardImpl { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) - { + if (controller != null) { PlayerList players = game.getState().getPlayerList(controller.getId()); - for (UUID playerId : players) - { + for (UUID playerId : players) { Player player = game.getPlayer(playerId); - if (player != null) - { + if (player != null) { int landCount = game.getBattlefield().countAll(new FilterControlledLandPermanent(), player.getId(), game); - if (landCount>5) - { + if (landCount > 5) { //Sacrifice lands till you have 5 TargetControlledPermanent target = new TargetControlledPermanent(5, 5, new FilterControlledLandPermanent("lands to keep"), true); - if (target.choose(Outcome.Sacrifice, player.getId(), source.getSourceId(), game)) - { - for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledLandPermanent(), player.getId(), source.getSourceId(), game)) - { - if (permanent != null && !target.getTargets().contains(permanent.getId())) - { + if (target.choose(Outcome.Sacrifice, player.getId(), source.getSourceId(), game)) { + for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledLandPermanent(), player.getId(), source.getSourceId(), game)) { + if (permanent != null && !target.getTargets().contains(permanent.getId())) { permanent.sacrifice(source.getId(), game); } } } - }else if(landCount<5) - { + } else if (landCount < 5) { //Play basic lands till you have 5 FilterLandPermanent filter = new FilterLandPermanent(); filter.add(new ControllerPredicate(TargetController.YOU)); int amount = 5 - landCount; TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterBasicLandCard()); - if (player.searchLibrary(target, game)) - { + if (player.searchLibrary(target, game)) { player.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null); } player.shuffleLibrary(source, game); - } + } } } return true; From 59a790e320cb8ce5aaacb6511462e6b3b1d336c8 Mon Sep 17 00:00:00 2001 From: bugfi5h Date: Thu, 27 Apr 2017 06:33:35 +0200 Subject: [PATCH 3/3] Using getPlayersInRange instead of getPlayersList --- Mage.Sets/src/mage/cards/n/NaturalBalance.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Mage.Sets/src/mage/cards/n/NaturalBalance.java b/Mage.Sets/src/mage/cards/n/NaturalBalance.java index ad75b2eec3..82cf67c3bc 100644 --- a/Mage.Sets/src/mage/cards/n/NaturalBalance.java +++ b/Mage.Sets/src/mage/cards/n/NaturalBalance.java @@ -29,7 +29,6 @@ package mage.cards.n; import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -91,7 +90,7 @@ public class NaturalBalance extends CardImpl { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - PlayerList players = game.getState().getPlayerList(controller.getId()); + PlayerList players = game.getState().getPlayersInRange(controller.getId(),game); for (UUID playerId : players) { Player player = game.getPlayer(playerId); if (player != null) {