Example #1
0
 @Override
 public boolean apply(Game game, Ability source) {
   ExileZone exile = game.getExile().getExileZone(exileId);
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null && exile != null) {
     if (zone == Zone.GRAVEYARD) {
       controller.moveCards(exile, zone, Zone.EXILED, source, game);
     } else {
       exile = exile.copy();
       for (UUID cardId : exile) {
         Card card = game.getCard(cardId);
         Player owner = game.getPlayer(card.getOwnerId());
         if (owner != null) {
           switch (zone) {
             case BATTLEFIELD:
               card.moveToZone(zone, source.getSourceId(), game, tapped);
               if (!game.isSimulation()) {
                 game.informPlayers(
                     controller.getLogName()
                         + " moves "
                         + card.getLogName()
                         + " to "
                         + zone.toString().toLowerCase());
               }
               break;
             case HAND:
               controller.moveCards(card, Zone.EXILED, Zone.HAND, source, game);
               break;
             case LIBRARY:
               controller.moveCardToLibraryWithInfo(
                   card, source.getSourceId(), game, Zone.EXILED, true, true);
               break;
             case GRAVEYARD:
               controller.moveCards(card, Zone.EXILED, Zone.GRAVEYARD, source, game);
               break;
             default:
               card.moveToZone(zone, source.getSourceId(), game, tapped);
               if (!game.isSimulation()) {
                 game.informPlayers(
                     controller.getLogName()
                         + " moves "
                         + card.getLogName()
                         + " to "
                         + zone.toString().toLowerCase());
               }
           }
         }
       }
       game.getExile().getExileZone(exileId).clear();
     }
     return true;
   }
   return false;
 }
Example #2
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    int amount = new GetXValue().calculate(game, source, this);

    if (controller != null && sourceObject != null) {
      TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard());
      if (controller.searchLibrary(target, game)) {
        Cards chosen = new CardsImpl();
        for (UUID cardId : (List<UUID>) target.getTargets()) {
          Card card = controller.getLibrary().remove(cardId, game);
          chosen.add(card);
        }
        controller.shuffleLibrary(source, game);

        TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop));

        while (chosen.size() > 1 && controller.canRespond()) {
          controller.choose(Outcome.Neutral, chosen, targetToLib, game);
          Card card = chosen.get(targetToLib.getFirstTarget(), game);
          if (card != null) {
            chosen.remove(card);
            controller.moveCardToLibraryWithInfo(
                card, source.getSourceId(), game, Zone.LIBRARY, true, false);
          }
          targetToLib.clearChosen();
        }

        if (chosen.size() == 1) {
          Card card = chosen.get(chosen.iterator().next(), game);
          controller.moveCardToLibraryWithInfo(
              card, source.getSourceId(), game, Zone.LIBRARY, true, false);
        }
      }
      return true;
    }
    return false;
  }
Example #3
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getFirstTarget());
   if (player != null) {
     for (Card card : player.getGraveyard().getCards(game)) {
       player.moveCardToLibraryWithInfo(
           card, source.getSourceId(), game, Zone.GRAVEYARD, true, true);
     }
     player.shuffleLibrary(source, game);
     return true;
   }
   return false;
 }
Example #4
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     for (Permanent creature :
         game.getBattlefield()
             .getActivePermanents(
                 new FilterCreaturePermanent(), controller.getId(), source.getSourceId(), game)) {
       controller.moveCardToLibraryWithInfo(
           creature, source.getSourceId(), game, Zone.BATTLEFIELD, false, true);
     }
     return true;
   }
   return false;
 }
Example #5
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null) {
     boolean revealed =
         player
             .isTopCardRevealed(); // by looking at the cards with scry you have not to reveal the
                                   // next card
     player.setTopCardRevealed(false);
     Cards cards = new CardsImpl();
     int count = Math.min(scryNumber, player.getLibrary().size());
     if (count == 0) {
       return true;
     }
     for (int i = 0; i < count; i++) {
       Card card = player.getLibrary().removeFromTop(game);
       cards.add(card);
     }
     TargetCard target1 = new TargetCard(Zone.LIBRARY, filter1);
     target1.setRequired(false);
     // move cards to the bottom of the library
     while (player.isInGame()
         && cards.size() > 0
         && player.choose(Outcome.Detriment, cards, target1, game)) {
       Card card = cards.get(target1.getFirstTarget(), game);
       if (card != null) {
         cards.remove(card);
         player.moveCardToLibraryWithInfo(
             card, source.getSourceId(), game, Zone.LIBRARY, false, false);
       }
       target1.clearChosen();
     }
     // move cards to the top of the library
     player.putCardsOnTopOfLibrary(cards, game, source, true);
     game.fireEvent(
         new GameEvent(
             GameEvent.EventType.SCRY,
             source.getControllerId(),
             source.getSourceId(),
             source.getControllerId()));
     player.setTopCardRevealed(revealed);
     return true;
   }
   return false;
 }
 @Override
 public boolean apply(Game game, Ability source) {
   Card sourceCard = game.getCard(source.getSourceId());
   MageObject sourceObject = game.getObject(source.getSourceId());
   if (sourceCard != null) {
     Player player = game.getPlayer(sourceCard.getOwnerId());
     if (player != null) {
       Zone fromZone = game.getState().getZone(sourceCard.getId());
       Cards cards = new CardsImpl();
       cards.add(sourceCard);
       player.revealCards(sourceObject.getLogName(), cards, game);
       player.moveCardToLibraryWithInfo(
           sourceCard, source.getSourceId(), game, fromZone, true, true);
       player.shuffleLibrary(game);
       return true;
     }
   }
   return false;
 }
Example #7
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   Card sourceCard = game.getCard(source.getSourceId());
   if (controller != null && sourceCard != null) {
     if (game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
       boolean onTop =
           controller.chooseUse(
               outcome,
               "Put "
                   + sourceCard.getName()
                   + " on top of it's owners library (otherwise on bottom)?",
               source,
               game);
       controller.moveCardToLibraryWithInfo(
           sourceCard, source.getSourceId(), game, Zone.GRAVEYARD, onTop, true);
     }
     return true;
   }
   return false;
 }