From 050043c6b6e329f543a115fa8f5e8bd047316943 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 19 Mar 2015 15:54:08 +0100 Subject: [PATCH] * Added logic that a player can order cards if more than one card goes simultanously to graveyard. --- .../src/mage/sets/magic2010/JaceBeleren.java | 5 +- Mage.Sets/src/mage/sets/tenth/Traumatize.java | 20 ++---- .../PutLibraryIntoGraveTargetEffect.java | 13 +--- .../mage/abilities/keyword/DredgeAbility.java | 11 ++-- Mage/src/mage/players/Player.java | 16 +++++ Mage/src/mage/players/PlayerImpl.java | 64 ++++++++++++++++++- 6 files changed, 96 insertions(+), 33 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2010/JaceBeleren.java b/Mage.Sets/src/mage/sets/magic2010/JaceBeleren.java index 0dd2d23f65..4baf258182 100644 --- a/Mage.Sets/src/mage/sets/magic2010/JaceBeleren.java +++ b/Mage.Sets/src/mage/sets/magic2010/JaceBeleren.java @@ -54,17 +54,18 @@ public class JaceBeleren extends CardImpl { this.color.setBlue(true); this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(3)), false)); - + // +2: Each player draws a card. this.addAbility(new LoyaltyAbility(new DrawCardAllEffect(1), 2)); + // -1: Target player draws a card. LoyaltyAbility ability1 = new LoyaltyAbility(new DrawCardTargetEffect(1), -1); ability1.addTarget(new TargetPlayer()); this.addAbility(ability1); + // -10: Target player puts the top twenty cards of his or her library into his or her graveyard. LoyaltyAbility ability2 = new LoyaltyAbility(new PutLibraryIntoGraveTargetEffect(20), -10); ability2.addTarget(new TargetPlayer()); this.addAbility(ability2); - } public JaceBeleren(final JaceBeleren card) { diff --git a/Mage.Sets/src/mage/sets/tenth/Traumatize.java b/Mage.Sets/src/mage/sets/tenth/Traumatize.java index ed007aa180..dd82d0fadf 100644 --- a/Mage.Sets/src/mage/sets/tenth/Traumatize.java +++ b/Mage.Sets/src/mage/sets/tenth/Traumatize.java @@ -35,7 +35,6 @@ import mage.constants.Rarity; import mage.constants.Zone; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; import mage.cards.CardImpl; import mage.game.Game; import mage.players.Player; @@ -50,7 +49,7 @@ public class Traumatize extends CardImpl { public Traumatize(UUID ownerId) { super(ownerId, 119, "Traumatize", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{3}{U}{U}"); this.expansionSetCode = "10E"; - this.color.setBlue(true); + this.getSpellAbility().addTarget(new TargetPlayer()); this.getSpellAbility().addEffect(new TraumatizeEffect()); } @@ -79,17 +78,12 @@ class TraumatizeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getFirstTarget()); - Card card; - int amount = player.getLibrary().size() / 2; - for (int i = 0; i < amount; i++) { - card = player.getLibrary().removeFromTop(game); - if (card != null) { - card.moveToZone(Zone.GRAVEYARD, source.getSourceId(), game, false); - } else { - break; - } + if (player != null) { + int amount = player.getLibrary().size() / 2; + player.moveCardsToGraveyardWithInfo(player.getLibrary().getTopCards(game, amount), source, game, Zone.LIBRARY); + return true; } - return true; + return false; } @Override @@ -97,4 +91,4 @@ class TraumatizeEffect extends OneShotEffect { return new TraumatizeEffect(this); } -} \ No newline at end of file +} diff --git a/Mage/src/mage/abilities/effects/common/PutLibraryIntoGraveTargetEffect.java b/Mage/src/mage/abilities/effects/common/PutLibraryIntoGraveTargetEffect.java index 816a683d75..5ac6c37a0a 100644 --- a/Mage/src/mage/abilities/effects/common/PutLibraryIntoGraveTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/PutLibraryIntoGraveTargetEffect.java @@ -35,7 +35,6 @@ import mage.abilities.Mode; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; import mage.game.Game; import mage.players.Player; import mage.util.CardUtil; @@ -77,15 +76,7 @@ public class PutLibraryIntoGraveTargetEffect extends OneShotEffect { if (player != null) { // putting cards to grave shouldn't end the game, so getting minimun available int cardsCount = Math.min(amount.calculate(game, source, this), player.getLibrary().size()); - for (int i = 0; i < cardsCount; i++) { - Card card = player.getLibrary().getFromTop(game); - if (card != null) { - player.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, Zone.LIBRARY); - } - else { - break; - } - } + player.moveCardsToGraveyardWithInfo(player.getLibrary().getTopCards(game, cardsCount), source, game, Zone.LIBRARY); return true; } return false; @@ -98,7 +89,7 @@ public class PutLibraryIntoGraveTargetEffect extends OneShotEffect { sb.append("Target ").append(mode.getTargets().get(0).getTargetName()); sb.append(" puts the top "); - if (message.isEmpty()) { + if (message.isEmpty()) { if (amount.toString().equals("1")) { sb.append("card "); } else { diff --git a/Mage/src/mage/abilities/keyword/DredgeAbility.java b/Mage/src/mage/abilities/keyword/DredgeAbility.java index 90ca2f30ff..f720094d54 100644 --- a/Mage/src/mage/abilities/keyword/DredgeAbility.java +++ b/Mage/src/mage/abilities/keyword/DredgeAbility.java @@ -31,6 +31,8 @@ import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.Card; +import mage.cards.Cards; +import mage.cards.CardsImpl; import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Zone; @@ -98,12 +100,9 @@ class DredgeEffect extends ReplacementEffectImpl { && player.chooseUse(outcome, new StringBuilder("Dredge ").append(sourceCard.getName()). append("? (").append(amount).append(" cards go from top of library to graveyard)").toString(), game)) { game.informPlayers(new StringBuilder(player.getName()).append(" dreges ").append(sourceCard.getName()).toString()); - for (int i = 0; i < amount; i++) { - Card card = player.getLibrary().removeFromTop(game); - if (card != null) { - player.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, Zone.LIBRARY); - } - } + Cards cardsToGrave = new CardsImpl(); + cardsToGrave.addAll(player.getLibrary().getTopCards(game, amount)); + player.moveCardsToGraveyardWithInfo(cardsToGrave, source, game, Zone.LIBRARY); player.moveCardToHandWithInfo(sourceCard, source.getSourceId(), game, Zone.GRAVEYARD); return true; } diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 1719996dca..abb5471e89 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -461,6 +461,22 @@ public interface Player extends MageItem, Copyable { */ boolean moveCardToGraveyardWithInfo(Card card, UUID sourceId, Game game, Zone fromZone); + + /** + * Moves 1 to n cards to the graveyard. The owner of the cards may determine the order, + * if more than one card is moved to graveyard. + * Uses card.moveToZone and posts a inform message about moving the card to graveyard + * into the game log + * + * @param cards + * @param source + * @param game + * @param fromZone if null, this info isn't postet + * @return + */ + boolean moveCardsToGraveyardWithInfo(Cards cards, Ability source, Game game, Zone fromZone); + boolean moveCardsToGraveyardWithInfo(List cards, Ability source, Game game, Zone fromZone); + /** * Uses card.moveToZone and posts a inform message about moving the card to graveyard * into the game log diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 6349b1526a..8a49e96cf1 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -2764,7 +2764,69 @@ public abstract class PlayerImpl implements Player, Serializable { } return result; } - + + @Override + public boolean moveCardsToGraveyardWithInfo(Cards allCards, Ability source, Game game, Zone fromZone) { + ArrayList cards = new ArrayList<>(); + cards.addAll(allCards.getCards(game)); + return moveCardsToGraveyardWithInfo(cards, source, game, fromZone); + } + + @Override + public boolean moveCardsToGraveyardWithInfo(List allCards, Ability source, Game game, Zone fromZone) { + while (!allCards.isEmpty()) { + // identify cards from one owner + Cards cards = new CardsImpl(); + UUID ownerId = null; + for (Card card: allCards) { + if (cards.isEmpty()) { + ownerId = card.getOwnerId(); + } + if (card.getOwnerId().equals(ownerId)) { + cards.add(card); + } + } + allCards.removeAll(cards); + // move cards ot graveyard in order the owner decides + if (cards.size() != 0) { + TargetCard target = new TargetCard(fromZone, new FilterCard("card to put on the top of your graveyard (last one chosen will be topmost)")); + target.setRequired(true); + Player choosingPlayer = this; + if (ownerId != this.getId()) { + choosingPlayer = game.getPlayer(ownerId); + } + if (choosingPlayer == null) { + continue; + } + boolean chooseOrder = true; + if (cards.size() > 2) { + chooseOrder = choosingPlayer.chooseUse(Outcome.Neutral, "Do you like to choose the order the cards go to graveyard?", game); + } + if (chooseOrder) { + while (choosingPlayer.isInGame() && cards.size() > 1) { + choosingPlayer.chooseTarget(Outcome.Neutral, cards, target, source, game); + UUID targetObjectId = target.getFirstTarget(); + Card card = cards.get(targetObjectId, game); + cards.remove(targetObjectId); + if (card != null) { + choosingPlayer.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, fromZone); + } + target.clearChosen(); + } + if (cards.size() == 1) { + choosingPlayer.moveCardToGraveyardWithInfo(cards.getCards(game).iterator().next(), source.getSourceId(), game, fromZone); + } + } else { + for (Card card : cards.getCards(game)) { + choosingPlayer.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, fromZone); + } + } + } + + } + return true; + } + @Override public boolean moveCardToGraveyardWithInfo(Card card, UUID sourceId, Game game, Zone fromZone) { boolean result = false;