From d5feac4bfee4e04c20934eef068f8892ea3d3c8e Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 18 Jan 2014 16:02:46 +0100 Subject: [PATCH] Added TargetController parameter to DiscardEachPlayerEffect. --- .../mage/sets/magic2010/BurningInquiry.java | 54 ++----------- .../mage/sets/magic2011/LilianasSpecter.java | 37 ++------- .../src/mage/sets/magic2012/Smallpox.java | 53 ++++++------- .../mage/sets/modernmasters/DeathCloud.java | 13 +++- .../src/mage/sets/planeshift/UrzasGuilt.java | 10 ++- .../mage/sets/urzassaga/CacklingFiend.java | 31 +------- .../common/DiscardEachPlayerEffect.java | 78 ++++++++++++++----- Mage/src/mage/util/CardUtil.java | 10 ++- 8 files changed, 128 insertions(+), 158 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2010/BurningInquiry.java b/Mage.Sets/src/mage/sets/magic2010/BurningInquiry.java index ffe5a70d08..ae0ab17210 100644 --- a/Mage.Sets/src/mage/sets/magic2010/BurningInquiry.java +++ b/Mage.Sets/src/mage/sets/magic2010/BurningInquiry.java @@ -28,16 +28,12 @@ package mage.sets.magic2010; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.DiscardEachPlayerEffect; import mage.abilities.effects.common.DrawCardAllEffect; -import mage.cards.Card; import mage.cards.CardImpl; -import mage.game.Game; -import mage.players.Player; +import mage.constants.CardType; +import mage.constants.Rarity; /** * @@ -53,7 +49,9 @@ public class BurningInquiry extends CardImpl { // Each player draws three cards, then discards three cards at random. this.getSpellAbility().addEffect(new DrawCardAllEffect(3)); - this.getSpellAbility().addEffect(new BurningInquiryEffect()); + Effect effect = new DiscardEachPlayerEffect(3, true); + effect.setText("then discards three cards at random"); + this.getSpellAbility().addEffect(effect); } public BurningInquiry(final BurningInquiry card) { @@ -65,41 +63,3 @@ public class BurningInquiry extends CardImpl { return new BurningInquiry(this); } } - -class BurningInquiryEffect extends OneShotEffect { - - public BurningInquiryEffect() { - super(Outcome.Discard); - this.staticText = "Each player discards three cards at random"; - } - - public BurningInquiryEffect(final BurningInquiryEffect effect) { - super(effect); - } - - @Override - public BurningInquiryEffect copy() { - return new BurningInquiryEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller == null) { - return false; - } - - for (UUID playerId : controller.getInRange()) { - Player player = game.getPlayer(playerId); - if (player != null) { - for (int i = 0; i < 3; i++) { - Card card = player.getHand().getRandom(game); - if (card != null) { - player.discard(card, source, game); - } - } - } - } - return true; - } -} diff --git a/Mage.Sets/src/mage/sets/magic2011/LilianasSpecter.java b/Mage.Sets/src/mage/sets/magic2011/LilianasSpecter.java index b5c78d2f13..33ce3e0943 100644 --- a/Mage.Sets/src/mage/sets/magic2011/LilianasSpecter.java +++ b/Mage.Sets/src/mage/sets/magic2011/LilianasSpecter.java @@ -29,15 +29,17 @@ package mage.sets.magic2011; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DiscardEachPlayerEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.TargetController; import mage.game.Game; import mage.players.Player; @@ -56,7 +58,7 @@ public class LilianasSpecter extends CardImpl { this.toughness = new MageInt(1); this.addAbility(FlyingAbility.getInstance()); - this.addAbility(new EntersBattlefieldTriggeredAbility(new LilianasSpecterEffect(), false)); + this.addAbility(new EntersBattlefieldTriggeredAbility(new DiscardEachPlayerEffect(TargetController.OPPONENT), false)); } public LilianasSpecter(final LilianasSpecter card) { @@ -69,30 +71,3 @@ public class LilianasSpecter extends CardImpl { } } - -class LilianasSpecterEffect extends OneShotEffect { - - public LilianasSpecterEffect() { - super(Outcome.Discard); - staticText = "each opponent discards a card"; - } - - public LilianasSpecterEffect(final LilianasSpecterEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - for (UUID playerId: game.getOpponents(source.getControllerId())) { - Player player = game.getPlayer(playerId); - player.discard(1, source, game); - } - return true; - } - - @Override - public LilianasSpecterEffect copy() { - return new LilianasSpecterEffect(this); - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/magic2012/Smallpox.java b/Mage.Sets/src/mage/sets/magic2012/Smallpox.java index b97fd495fd..61fccc8909 100644 --- a/Mage.Sets/src/mage/sets/magic2012/Smallpox.java +++ b/Mage.Sets/src/mage/sets/magic2012/Smallpox.java @@ -27,6 +27,7 @@ */ package mage.sets.magic2012; +import java.util.Set; import java.util.UUID; import mage.constants.CardType; import mage.constants.Outcome; @@ -85,36 +86,36 @@ class SmallpoxEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - for (UUID playerId : game.getPlayerList()) { - Player player = game.getPlayer(playerId); - if (player != null) { - player.loseLife(1, game); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + Set players = controller.getInRange(); + for (UUID playerId : players) { + Player player = game.getPlayer(playerId); + if (player != null) { + player.loseLife(1, game); + } } - } - - for (UUID playerId : game.getPlayerList()) { - Player player = game.getPlayer(playerId); - if (player != null) { - player.discard(1, source, game); + for (UUID playerId : players) { + Player player = game.getPlayer(playerId); + if (player != null) { + player.discard(1, source, game); + } } - } - - - for (UUID playerId : game.getPlayerList()) { - Player player = game.getPlayer(playerId); - if (player != null) { - sacrifice(game, source, player, filterCreature); + for (UUID playerId : players) { + Player player = game.getPlayer(playerId); + if (player != null) { + sacrifice(game, source, player, filterCreature); + } } - } - - for (UUID playerId : game.getPlayerList()) { - Player player = game.getPlayer(playerId); - if (player != null) { - sacrifice(game, source, player, filterLand); + for (UUID playerId : players) { + Player player = game.getPlayer(playerId); + if (player != null) { + sacrifice(game, source, player, filterLand); + } } + return true; } - - return true; + return false; } @Override @@ -125,7 +126,7 @@ class SmallpoxEffect extends OneShotEffect { private void sacrifice(Game game, Ability source, Player player, FilterPermanent filter) { Target target = new TargetControlledPermanent(1, 1, filter, false); if (target.canChoose(player.getId(), game)) { - while (!target.isChosen() && target.canChoose(player.getId(), game)) { + while (!target.isChosen() && target.canChoose(player.getId(), game) && player.isInGame()) { player.choose(Outcome.Sacrifice, target, source.getSourceId(), game); } diff --git a/Mage.Sets/src/mage/sets/modernmasters/DeathCloud.java b/Mage.Sets/src/mage/sets/modernmasters/DeathCloud.java index a621948968..53c9d6c828 100644 --- a/Mage.Sets/src/mage/sets/modernmasters/DeathCloud.java +++ b/Mage.Sets/src/mage/sets/modernmasters/DeathCloud.java @@ -32,6 +32,7 @@ import mage.constants.CardType; import mage.constants.Rarity; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.ManacostVariableValue; +import mage.abilities.effects.Effect; import mage.abilities.effects.common.DiscardEachPlayerEffect; import mage.abilities.effects.common.LoseLifePlayersEffect; import mage.abilities.effects.common.SacrificeAllEffect; @@ -54,9 +55,15 @@ public class DeathCloud extends CardImpl { // Each player loses X life, discards X cards, sacrifices X creatures, then sacrifices X lands. DynamicValue xValue = new ManacostVariableValue(); this.getSpellAbility().addEffect(new LoseLifePlayersEffect(xValue)); - this.getSpellAbility().addEffect(new DiscardEachPlayerEffect(xValue, false)); - this.getSpellAbility().addEffect(new SacrificeAllEffect(xValue, new FilterControlledCreaturePermanent("creatures"))); - this.getSpellAbility().addEffect(new SacrificeAllEffect(xValue, new FilterControlledLandPermanent("lands"))); + Effect effect = new DiscardEachPlayerEffect(xValue, false); + effect.setText(", discards X cards"); + this.getSpellAbility().addEffect(effect); + effect = new SacrificeAllEffect(xValue, new FilterControlledCreaturePermanent("creatures")); + effect.setText(", sacrifices X creatures"); + this.getSpellAbility().addEffect(effect); + effect = new SacrificeAllEffect(xValue, new FilterControlledLandPermanent("lands")); + effect.setText("then sacrifices X lands"); + this.getSpellAbility().addEffect(effect); } public DeathCloud(final DeathCloud card) { diff --git a/Mage.Sets/src/mage/sets/planeshift/UrzasGuilt.java b/Mage.Sets/src/mage/sets/planeshift/UrzasGuilt.java index a626e770df..587441e013 100644 --- a/Mage.Sets/src/mage/sets/planeshift/UrzasGuilt.java +++ b/Mage.Sets/src/mage/sets/planeshift/UrzasGuilt.java @@ -28,6 +28,7 @@ package mage.sets.planeshift; import java.util.UUID; +import mage.abilities.effects.Effect; import mage.constants.CardType; import mage.constants.Rarity; import mage.abilities.effects.common.DiscardEachPlayerEffect; @@ -50,9 +51,12 @@ public class UrzasGuilt extends CardImpl { // Each player draws two cards, then discards three cards, then loses 4 life. this.getSpellAbility().addEffect(new DrawCardAllEffect(2)); - this.getSpellAbility().addEffect(new DiscardEachPlayerEffect(3, false)); - this.getSpellAbility().addEffect(new LoseLifeAllEffect(4)); - + Effect effect = new DiscardEachPlayerEffect(3, false); + effect.setText("then discards three cards"); + this.getSpellAbility().addEffect(effect); + effect = new LoseLifeAllEffect(4); + effect.setText("then loses 4 life"); + this.getSpellAbility().addEffect(effect); } public UrzasGuilt(final UrzasGuilt card) { diff --git a/Mage.Sets/src/mage/sets/urzassaga/CacklingFiend.java b/Mage.Sets/src/mage/sets/urzassaga/CacklingFiend.java index b6dd4f54ca..21d6fc29b2 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/CacklingFiend.java +++ b/Mage.Sets/src/mage/sets/urzassaga/CacklingFiend.java @@ -36,8 +36,10 @@ import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DiscardEachPlayerEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; +import mage.constants.TargetController; import mage.game.Game; import mage.players.Player; @@ -56,7 +58,7 @@ public class CacklingFiend extends CardImpl { this.toughness = new MageInt(1); this.addAbility(FlyingAbility.getInstance()); - this.addAbility(new EntersBattlefieldTriggeredAbility(new CacklingFiendEffect(), false)); + this.addAbility(new EntersBattlefieldTriggeredAbility(new DiscardEachPlayerEffect(TargetController.OPPONENT), false)); } public CacklingFiend(final CacklingFiend card) { @@ -69,30 +71,3 @@ public class CacklingFiend extends CardImpl { } } - -class CacklingFiendEffect extends OneShotEffect { - - public CacklingFiendEffect() { - super(Outcome.Discard); - staticText = "each opponent discards a card"; - } - - public CacklingFiendEffect(final CacklingFiendEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - for (UUID playerId: game.getOpponents(source.getControllerId())) { - Player player = game.getPlayer(playerId); - player.discard(1, source, game); - } - return true; - } - - @Override - public CacklingFiendEffect copy() { - return new CacklingFiendEffect(this); - } - -} \ No newline at end of file diff --git a/Mage/src/mage/abilities/effects/common/DiscardEachPlayerEffect.java b/Mage/src/mage/abilities/effects/common/DiscardEachPlayerEffect.java index 10575192f5..f575070e48 100644 --- a/Mage/src/mage/abilities/effects/common/DiscardEachPlayerEffect.java +++ b/Mage/src/mage/abilities/effects/common/DiscardEachPlayerEffect.java @@ -11,6 +11,9 @@ import mage.cards.Card; import mage.cards.Cards; import mage.cards.CardsImpl; import mage.constants.Outcome; +import mage.constants.TargetController; +import static mage.constants.TargetController.NOT_YOU; +import static mage.constants.TargetController.OPPONENT; import mage.filter.FilterCard; import mage.game.Game; import mage.players.Player; @@ -22,25 +25,36 @@ public class DiscardEachPlayerEffect extends OneShotEffect 1?"s":"").toString()); + game.informPlayers(new StringBuilder(player.getName()).append(" discards ").append(Integer.toString(cardsPlayer.size())).append(" card").append(cardsPlayer.size() > 1 ? "s" : "").toString()); } } } @@ -98,8 +124,23 @@ public class DiscardEachPlayerEffect extends OneShotEffect 1) { @@ -113,5 +154,4 @@ public class DiscardEachPlayerEffect extends OneShotEffect