From bb28394f715dfffc1776e542d52e7b2742ab2f61 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 2 Jun 2015 22:50:57 +0200 Subject: [PATCH] * Helm of Obedience - Fixed that card movement to graveyard was not handled correct. It was not checked, if card was really moved to graveyard (fixes #1004). --- .../mage/sets/alliances/HelmOfObedience.java | 40 +++++----- .../replacement/LeylineOfTheVoidTest.java | 76 +++++++++++++++++++ Mage/src/mage/players/PlayerImpl.java | 15 ++-- .../common/PlayerLostLifeWatcher.java | 8 +- 4 files changed, 108 insertions(+), 31 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/replacement/LeylineOfTheVoidTest.java diff --git a/Mage.Sets/src/mage/sets/alliances/HelmOfObedience.java b/Mage.Sets/src/mage/sets/alliances/HelmOfObedience.java index 6f3768f2913..76325f76e42 100644 --- a/Mage.Sets/src/mage/sets/alliances/HelmOfObedience.java +++ b/Mage.Sets/src/mage/sets/alliances/HelmOfObedience.java @@ -97,32 +97,32 @@ class HelmOfObedienceEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(targetPointer.getFirst(game, source)); - if (player != null) { + Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source)); + if (targetOpponent != null) { int max = amount.calculate(game, source, this); if(max != 0){ int numberOfCard = 0; - while(player.getLibrary().size() > 0) { - Card card = player.getLibrary().removeFromTop(game); + while(targetOpponent.getLibrary().size() > 0) { + Card card = targetOpponent.getLibrary().removeFromTop(game); if (card != null){ - player.moveCards(card, Zone.LIBRARY, Zone.GRAVEYARD, source, game); - if(card.getCardType().contains(CardType.CREATURE)){ - // If a creature card is put into that graveyard this way, sacrifice Helm of Obedience - // and put that card onto the battlefield under your control. - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - if (sourcePermanent != null) { - sourcePermanent.sacrifice(source.getSourceId(), game); - } - if (game.getState().getZone(card.getId()).equals(Zone.GRAVEYARD)) { - card.putOntoBattlefield(game, Zone.GRAVEYARD, source.getSourceId(), source.getControllerId()); - } - break; - } - else{ - numberOfCard++; - if(numberOfCard >= max){ + if (targetOpponent.moveCards(card, Zone.LIBRARY, Zone.GRAVEYARD, source, game)) { + if(card.getCardType().contains(CardType.CREATURE)){ + // If a creature card is put into that graveyard this way, sacrifice Helm of Obedience + // and put that card onto the battlefield under your control. + Permanent sourcePermanent = game.getPermanent(source.getSourceId()); + if (sourcePermanent != null) { + sourcePermanent.sacrifice(source.getSourceId(), game); + } + if (game.getState().getZone(card.getId()).equals(Zone.GRAVEYARD)) { + card.putOntoBattlefield(game, Zone.GRAVEYARD, source.getSourceId(), source.getControllerId()); + } break; + } else{ + numberOfCard++; + if(numberOfCard >= max){ + break; + } } } } else{ diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/LeylineOfTheVoidTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/LeylineOfTheVoidTest.java new file mode 100644 index 00000000000..20b7bdec98d --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/LeylineOfTheVoidTest.java @@ -0,0 +1,76 @@ +/* + * 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 org.mage.test.cards.replacement; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ + +public class LeylineOfTheVoidTest extends CardTestPlayerBase { + + /** + * Leyline of the Void is on the battlefield, Helm of Obedience is used on + * an opponent with X=1. Now the Helm states to mill "until a creature card + * or X cards are put into the graveyard this way". For each of those milled + * cards, Leyline states to "remove [them] from the game instead". In other + * words: Leyline + Helm and X of at least 1 exiles the library of one + * unlucky opponent. Or should, because right now it doesn't. Right now it's + * Helm's originally intended "X or 1st Creature" amount of cards that after + * it's effect get exiled. + */ + @Test + public void testGrindstoneProgenius() { + addCard(Zone.BATTLEFIELD, playerA, "Plains"); + + // If Leyline of the Void is in your opening hand, you may begin the game with it on the battlefield. + // If a card would be put into an opponent's graveyard from anywhere, exile it instead. + addCard(Zone.BATTLEFIELD, playerA, "Leyline of the Void"); + + // {X}, {T}: Target opponent puts cards from the top of his or her library into his or her graveyard until a creature card or X cards are put into that graveyard this way, whichever comes first. If a creature card is put into that graveyard this way, sacrifice Helm of Obedience and put that card onto the battlefield under your control. X can't be 0. + addCard(Zone.BATTLEFIELD, playerA, "Helm of Obedience"); + + + activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "{X},{T}: Target opponent puts cards", playerB); + setChoice(playerA, "X=1"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertExileCount(playerB, 71); // All cards go to exile replaced from Leyline of the void + } + +} + + diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 16ce833b928..ccb4b5fa2a2 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -2900,6 +2900,8 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean moveCardsToGraveyardWithInfo(List allCards, Ability source, Game game, Zone fromZone) { + boolean result = true; + UUID sourceId = source == null ? null : source.getSourceId(); while (!allCards.isEmpty()) { // identify cards from one owner Cards cards = new CardsImpl(); @@ -2914,7 +2916,7 @@ public abstract class PlayerImpl implements Player, Serializable { cards.add(card); } } - // move cards ot graveyard in order the owner decides + // move cards to graveyard in order the owner decides if (!cards.isEmpty()) { Player choosingPlayer = this; if (ownerId != this.getId()) { @@ -2936,22 +2938,21 @@ public abstract class PlayerImpl implements Player, Serializable { Card card = cards.get(targetObjectId, game); cards.remove(targetObjectId); if (card != null) { - choosingPlayer.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, fromZone); + result &= choosingPlayer.moveCardToGraveyardWithInfo(card, sourceId, game, fromZone); } target.clearChosen(); } if (cards.size() == 1) { - choosingPlayer.moveCardToGraveyardWithInfo(cards.getCards(game).iterator().next(), source == null ? null : source.getSourceId(), game, fromZone); + result &= choosingPlayer.moveCardToGraveyardWithInfo(cards.getCards(game).iterator().next(), sourceId, game, fromZone); } } else { for (Card card : cards.getCards(game)) { - choosingPlayer.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, fromZone); + result &= choosingPlayer.moveCardToGraveyardWithInfo(card, sourceId, game, fromZone); } } - } - + } } - return true; + return result; } @Override diff --git a/Mage/src/mage/watchers/common/PlayerLostLifeWatcher.java b/Mage/src/mage/watchers/common/PlayerLostLifeWatcher.java index ae1a8247fe5..26b16292c40 100644 --- a/Mage/src/mage/watchers/common/PlayerLostLifeWatcher.java +++ b/Mage/src/mage/watchers/common/PlayerLostLifeWatcher.java @@ -68,9 +68,9 @@ public class PlayerLostLifeWatcher extends Watcher { if (playerId != null) { Integer amount = amountOfLifeLostThisTurn.get(playerId); if (amount == null) { - amount = Integer.valueOf(event.getAmount()); + amount = event.getAmount(); } else { - amount = Integer.valueOf(amount + event.getAmount()); + amount = amount + event.getAmount(); } amountOfLifeLostThisTurn.put(playerId, amount); } @@ -80,7 +80,7 @@ public class PlayerLostLifeWatcher extends Watcher { public int getLiveLost(UUID playerId) { Integer amount = amountOfLifeLostThisTurn.get(playerId); if (amount != null) { - return amount.intValue(); + return amount; } return 0; } @@ -88,7 +88,7 @@ public class PlayerLostLifeWatcher extends Watcher { public int getLiveLostLastTurn(UUID playerId) { Integer amount = amountOfLifeLostLastTurn.get(playerId); if (amount != null) { - return amount.intValue(); + return amount; } return 0; }