From d4044536cbe7538b0a21aac70beb43de9828d21d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 11 Dec 2014 14:55:26 +0100 Subject: [PATCH] Some fixes to putOnTop/buttomOfLibrary of player to handle cards and permanents. --- .../common/PutOnLibraryTargetEffect.java | 12 +++- Mage/src/mage/players/PlayerImpl.java | 65 +++++++++---------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/Mage/src/mage/abilities/effects/common/PutOnLibraryTargetEffect.java b/Mage/src/mage/abilities/effects/common/PutOnLibraryTargetEffect.java index a800e541f2..82e673820d 100644 --- a/Mage/src/mage/abilities/effects/common/PutOnLibraryTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/PutOnLibraryTargetEffect.java @@ -110,7 +110,11 @@ public class PutOnLibraryTargetEffect extends OneShotEffect { iterator.remove(); } } - owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, onTop); + if (onTop) { + owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true); + } else { + owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true); + } } } while (!permanents.isEmpty()) { @@ -125,7 +129,11 @@ public class PutOnLibraryTargetEffect extends OneShotEffect { iterator.remove(); } } - owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, onTop); + if (onTop) { + owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true); + } else { + owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true); + } } } return true; diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index d7fef78a5b..88c4b8e53d 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -819,13 +819,8 @@ public abstract class PlayerImpl implements Player, Serializable { public boolean putCardsOnBottomOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder) { if (cards.size() != 0) { if (!anyOrder) { - for (UUID cardId : cards) { - Card card =game.getCard(cardId); - - if (card != null) { - Zone fromZone = game.getState().getZone(cardId); - this.moveCardToLibraryWithInfo(card, source.getSourceId(), game, fromZone, false, false); - } + for (UUID objectId : cards) { + moveObjectToLibrary(objectId, source.getSourceId(), game, false, false); } } else { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library (last one chosen will be bottommost)")); @@ -835,32 +830,36 @@ public abstract class PlayerImpl implements Player, Serializable { Card chosenCard = cards.get(target.getFirstTarget(), game); if (chosenCard != null) { cards.remove(chosenCard); - Zone fromZone = game.getState().getZone(chosenCard.getId()); - this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, false, false); + moveObjectToLibrary(chosenCard.getId(), source.getSourceId(), game, false, false); } target.clearChosen(); } if (cards.size() == 1) { Card chosenCard = cards.get(cards.iterator().next(), game); - Zone fromZone = game.getState().getZone(chosenCard.getId()); - this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, false, false); + moveObjectToLibrary(chosenCard.getId(), source.getSourceId(), game, false, false); } } } return true; } + + + /** + * Can be cards or permanents that go to library + * + * @param cards + * @param game + * @param source + * @param anyOrder + * @return + */ @Override public boolean putCardsOnTopOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder) { if (cards.size() != 0) { if (!anyOrder) { for (UUID cardId : cards) { - Card card =game.getCard(cardId); - - if (card != null) { - Zone fromZone = game.getState().getZone(cardId); - this.moveCardToLibraryWithInfo(card, source.getSourceId(), game, fromZone, true, false); - } + moveObjectToLibrary(cardId, source.getSourceId(), game, true, false); } } else { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the top of your library (last one chosen will be topmost)")); @@ -870,33 +869,31 @@ public abstract class PlayerImpl implements Player, Serializable { Card chosenCard = cards.get(target.getFirstTarget(), game); if (chosenCard != null) { cards.remove(chosenCard); - Zone fromZone = game.getState().getZone(chosenCard.getId()); - if (fromZone.equals(Zone.BATTLEFIELD)) { - Permanent permanent = game.getPermanent(chosenCard.getId()); - this.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, fromZone, true, false); - } else { - this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, true, false); - } + moveObjectToLibrary(chosenCard.getId(), source.getSourceId(), game, true, false); } target.clearChosen(); } if (cards.size() == 1) { - // Card chosenCard = cards.get(cards.iterator().next(), game); - UUID cardId = cards.iterator().next(); - Zone fromZone = game.getState().getZone(cardId); - if (fromZone.equals(Zone.BATTLEFIELD)) { - Permanent permanent = game.getPermanent(cardId); - this.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, fromZone, true, false); - } else { - Card chosenCard = cards.get(cardId, game); - this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, true, false); - } + moveObjectToLibrary(cards.iterator().next(), source.getSourceId(), game, true, false); } } } return true; } + private boolean moveObjectToLibrary(UUID objectId, UUID sourceId, Game game, boolean toTop, boolean withName) { + MageObject mageObject =game.getObject(objectId); + if (mageObject != null) { + Zone fromZone = game.getState().getZone(objectId); + if ((mageObject instanceof Permanent)) { + return this.moveCardToLibraryWithInfo((Permanent) mageObject, sourceId, game, fromZone, toTop, withName); + } else if (mageObject instanceof Card) { + return this.moveCardToLibraryWithInfo((Card) mageObject, sourceId, game, fromZone, toTop, withName); + } + } + return false; + } + @Override public void setCastSourceIdWithoutMana(UUID sourceId) { castSourceIdWithoutMana = sourceId;