Example #1
0
  @Override
  public boolean apply(Game game, Ability source) {

    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Cards cards = new CardsImpl(Zone.PICK);
    int count = source.getManaCostsToPay().getX();
    count = Math.min(player.getLibrary().size(), count);
    boolean legendaryIncluded = false;
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
        if (filter.match(card, game)) {
          legendaryIncluded = true;
        }
        game.setZone(card.getId(), Zone.PICK);
      }
    }
    player.lookAtCards("Heroes' Podium", cards, game);

    // You may reveal a legendary creature card from among them and put it into your hand.
    if (!cards.isEmpty()
        && legendaryIncluded
        && player.chooseUse(
            outcome, "Put a legendary creature card into your hand?", source, game)) {
      if (cards.size() == 1) {
        Card card = cards.getRandom(game);
        cards.remove(card);
        card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
        return true;
      } else {
        TargetCard target = new TargetCard(Zone.PICK, filter);
        if (player.choose(outcome, cards, target, game)) {
          Card card = cards.get(target.getFirstTarget(), game);
          if (card != null) {
            cards.remove(card);
            card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
          }
        }
      }
    }

    // Put the rest on the bottom of your library in a random order
    while (cards.size() > 0) {
      Card card = cards.getRandom(game);
      if (card != null) {
        cards.remove(card);
        card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
      }
    }
    return true;
  }
Example #2
0
 @Override
 public boolean chooseTarget(
     Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
   if (cards.isEmpty()) return !target.isRequired();
   Card card = cards.getRandom(game);
   target.addTarget(card.getId(), source, game);
   return true;
 }
Example #3
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null) {
     Cards cards = player.getGraveyard();
     for (int i = 0; i < 2 && !cards.isEmpty(); i++) {
       Card card = cards.getRandom(game);
       if (card != null) {
         card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
         cards.remove(card);
         game.informPlayers(card.getName() + " returned to the hand of " + player.getLogName());
       }
     }
     return true;
   }
   return false;
 }
Example #4
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject sourceObject = game.getObject(source.getSourceId());
   if (sourceObject != null && controller != null) {
     Cards cards = new CardsImpl();
     cards.addAll(controller.getLibrary().getTopCards(game, 3));
     if (!cards.isEmpty()) {
       controller.revealCards(staticText, cards, game);
       Card cardToGraveyard;
       if (cards.size() == 1) {
         cardToGraveyard = cards.getRandom(game);
       } else {
         Player opponent;
         Set<UUID> opponents = game.getOpponents(controller.getId());
         if (opponents.size() == 1) {
           opponent = game.getPlayer(opponents.iterator().next());
         } else {
           Target target = new TargetOpponent(true);
           controller.chooseTarget(Outcome.Detriment, target, source, game);
           opponent = game.getPlayer(target.getFirstTarget());
         }
         TargetCard target = new TargetCard(1, Zone.LIBRARY, new FilterCard());
         opponent.chooseTarget(outcome, cards, target, source, game);
         cardToGraveyard = game.getCard(target.getFirstTarget());
       }
       if (cardToGraveyard != null) {
         controller.moveCards(cardToGraveyard, Zone.LIBRARY, Zone.GRAVEYARD, source, game);
         cards.remove(cardToGraveyard);
       }
       controller.moveCards(cards, Zone.LIBRARY, Zone.HAND, source, game);
     }
     return true;
   }
   return false;
 }