Ejemplo n.º 1
0
  @Override
  public boolean apply(Game game, Ability source) {
    Cards cardsToCast = new CardsImpl();
    Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (targetOpponent != null && sourceObject != null) {
      List<Card> allCards = targetOpponent.getLibrary().getTopCards(game, 7);
      Cards cards = new CardsImpl(Zone.LIBRARY, allCards);
      targetOpponent.revealCards(
          sourceObject.getIdName() + " - " + targetOpponent.getName() + "'s top library cards",
          cards,
          game);
      for (Card card : allCards) {
        if (filter.match(card, game)) {
          cardsToCast.add(card);
        }
      }
      // cast an instant or sorcery for free
      if (cardsToCast.size() > 0) {
        int numberOfSpells = 1;
        if (SpellMasteryCondition.getInstance().apply(game, source)) {
          numberOfSpells++;
        }
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {

          TargetCard target = new TargetCard(Zone.LIBRARY, filter); // zone should be ignored here
          target.setNotTarget(true);
          while (numberOfSpells > 0
              && cardsToCast.size() > 0
              && controller.chooseUse(
                  outcome,
                  "Cast an instant or sorcery card from among them for free?",
                  source,
                  game)
              && controller.choose(outcome, cardsToCast, target, game)) {
            Card card = cardsToCast.get(target.getFirstTarget(), game);
            if (card != null) {
              controller.cast(card.getSpellAbility(), game, true);
              numberOfSpells--;
              cardsToCast.remove(card);
              allCards.remove(card);
            }
            if (!controller.isInGame()) {
              return false;
            }
            target.clearChosen();
          }
        }

        targetOpponent.moveCards(allCards, Zone.LIBRARY, Zone.GRAVEYARD, source, game);
      }
      return true;
    }
    return false;
  }
Ejemplo n.º 2
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
      if (controller.chooseUse(Outcome.Benefit, choiceText, source, game)) {
        Set<Card> sideboard = controller.getSideboard().getCards(filter, game);
        List<Card> exile = game.getExile().getAllCards(game);
        Cards filteredCards = new CardsImpl();
        Card card = null;

        for (Card sideboardCard : sideboard) {
          filteredCards.add(sideboardCard.getId());
        }
        for (Card exileCard : exile) {
          if (exileCard.getOwnerId().equals(source.getControllerId())
              && exileCard.hasSubtype("Eldrazi")) {
            filteredCards.add(exileCard);
          }
        }

        if (filteredCards.isEmpty()) {
          game.informPlayer(
              controller,
              "You have no "
                  + filter.getMessage()
                  + " outside the game (your sideboard) or in exile.");
        } else {
          TargetCard target = new TargetCard(Zone.OUTSIDE, filter);
          target.setNotTarget(true);
          if (controller.choose(outcome, filteredCards, target, game)) {
            card = controller.getSideboard().get(target.getFirstTarget(), game);
            if (card == null) {
              card = game.getCard(target.getFirstTarget());
            }
          }
        }

        if (card != null) {
          card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
          controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
        }
      }
      return true;
    }
    return false;
  }