Example #1
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Card card = player.getLibrary().getFromTop(game);
    if (card != null) {
      Cards cards = new CardsImpl();
      cards.add(card);
      player.lookAtCards("Explorer's Scope", cards, game);
      if (card.getCardType().contains(CardType.LAND)) {
        String message = "Put " + card.getName() + " onto the battlefield tapped?";
        if (player.chooseUse(Outcome.PutLandInPlay, message, game)) {
          if (card.putOntoBattlefield(
              game, Zone.LIBRARY, source.getId(), source.getControllerId())) {
            Permanent permanent = game.getPermanent(card.getId());
            if (permanent != null) {
              permanent.setTapped(true);
            }
          }
        }
      }
    }
    return true;
  }
Example #2
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   Player player = game.getPlayer(targetPointer.getFirst(game, source));
   if (player != null && controller != null) {
     controller.lookAtCards("Walker of Secret Ways", player.getHand(), game);
   }
   return true;
 }
Example #3
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 #4
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (player != null && controller != null) {
      Choice cardChoice = new ChoiceImpl();
      cardChoice.setChoices(CardRepository.instance.getNonLandNames());
      cardChoice.clearChoice();

      while (!controller.choose(Outcome.Exile, cardChoice, game)) {
        game.debugMessage("player canceled choosing name. retrying.");
      }

      String cardName = cardChoice.getChoice();
      game.informPlayers("CranialExtraction, named card: [" + cardName + "]");
      for (Card card : player.getGraveyard().getCards(game)) {
        if (card.getName().equals(cardName)) {
          card.moveToExile(null, "", source.getId(), game);
        }
      }
      for (Card card : player.getHand().getCards(game)) {
        if (card.getName().equals(cardName)) {
          card.moveToExile(null, "", source.getId(), game);
        }
      }
      for (Card card : player.getLibrary().getCards(game)) {
        if (card.getName().equals(cardName)) {
          card.moveToExile(null, "", source.getId(), game);
        }
      }
      controller.lookAtCards("CranialExtraction Hand", player.getHand(), game);
      controller.lookAtCards(
          "CranialExtraction Library",
          new CardsImpl(Zone.PICK, player.getLibrary().getCards(game)),
          game);
      player.shuffleLibrary(game);
    }
    return true;
  }
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller == null || sourcePermanent == null) {
      return false;
    }

    int highCMC = 0;
    List<Permanent> controlledArtifacts =
        game.getBattlefield()
            .getAllActivePermanents(new FilterArtifactPermanent(), controller.getId(), game);
    for (Permanent permanent : controlledArtifacts) {
      if (permanent.getSpellAbility() != null) {
        int cmc = permanent.getSpellAbility().getManaCosts().convertedManaCost();
        if (cmc > highCMC) {
          highCMC = cmc;
        }
      }
    }

    Cards cards = new CardsImpl();

    for (int i = 0; i < highCMC; i++) {
      Card card = controller.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
      }
    }
    controller.lookAtCards(sourcePermanent.getIdName(), cards, game);

    if (!cards.isEmpty()) {
      TargetCard target =
          new TargetCard(
              Zone.LIBRARY, new FilterArtifactCard("artifact card to put onto the battlefield"));
      if (target.canChoose(source.getSourceId(), controller.getId(), game)
          && controller.choose(Outcome.Benefit, cards, target, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        if (card != null) {
          controller.revealCards(sourcePermanent.getIdName(), new CardsImpl(card), game);
          cards.remove(card);
          controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
      }
    }

    controller.putCardsOnBottomOfLibrary(cards, game, source, true);
    return true;
  }
Example #6
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller == null || mageObject == null) {
      return false;
    }

    Card card = controller.getLibrary().getFromTop(game);
    if (card != null) {
      Cards cards = new CardsImpl();
      cards.add(card);
      controller.lookAtCards("top card of library - " + controller.getName(), cards, game);
      game.informPlayers(controller.getLogName() + " looks at the top card of his or her library");
    } else {
      return false;
    }

    return true;
  }
Example #7
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Card card = player.getLibrary().getFromTop(game);
    if (card != null) {
      Cards cards = new CardsImpl();
      cards.add(card);
      player.lookAtCards("Into the Wilds", cards, game);
      if (filter.match(card, game)) {
        String message = "Put " + card.getName() + " onto the battlefield?";
        if (player.chooseUse(outcome, message, game)) {
          return card.putOntoBattlefield(
              game, Zone.LIBRARY, source.getId(), source.getControllerId(), false);
        }
      }
    }
    return true;
  }
Example #8
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject mageObject = game.getObject(source.getSourceId());
   if (controller == null || mageObject == null) {
     return false;
   }
   Permanent faceDownCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
   if (faceDownCreature != null) {
     Permanent copyFaceDown = faceDownCreature.copy();
     copyFaceDown.setFaceDown(false, game);
     Cards cards = new CardsImpl();
     cards.add(copyFaceDown);
     Player player = game.getPlayer(faceDownCreature.getControllerId());
     controller.lookAtCards("face down card - " + mageObject.getName(), cards, game);
     if (player != null) {
       game.informPlayers(
           controller.getLogName() + " looks at a face down creature of " + player.getLogName());
     }
   } else {
     return false;
   }
   return true;
 }
  public boolean applySearchAndExile(
      Game game, Ability source, String cardName, UUID targetPlayerId) {
    Player player = game.getPlayer(source.getControllerId());
    if (cardName != null && player != null) {
      Player targetPlayer = game.getPlayer(targetPlayerId);
      if (targetPlayer != null) {
        FilterCard filter = new FilterCard("card named " + cardName);
        filter.add(new NamePredicate(cardName));

        // cards in Graveyard
        int cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getGraveyard().count(filter, game));
        if (cardsCount > 0) {
          filter.setMessage(
              "card named " + cardName + " in the graveyard of " + targetPlayer.getName());
          TargetCardInGraveyard target =
              new TargetCardInGraveyard(
                  (graveyardExileOptional ? 0 : cardsCount), cardsCount, filter);
          if (player.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
              Card targetCard = targetPlayer.getGraveyard().get(targetId, game);
              if (targetCard != null) {
                targetPlayer.getGraveyard().remove(targetCard);
                targetCard.moveToZone(Zone.EXILED, source.getId(), game, false);
              }
            }
          }
        }

        // cards in Hand
        cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getHand().count(filter, game));
        if (cardsCount > 0) {
          filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
          TargetCardInHand target = new TargetCardInHand(0, cardsCount, filter);
          if (player.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
              Card targetCard = targetPlayer.getHand().get(targetId, game);
              if (targetCard != null) {
                targetPlayer.getHand().remove(targetCard);
                targetCard.moveToZone(Zone.EXILED, source.getId(), game, false);
              }
            }
          }
        } else {
          if (targetPlayer.getHand().size() > 0) {
            player.lookAtCards(targetPlayer.getName() + " hand", targetPlayer.getHand(), game);
          }
        }

        // cards in Library
        Cards cardsInLibrary = new CardsImpl(Zone.LIBRARY);
        cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
        cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
        if (cardsCount > 0) {
          filter.setMessage(
              "card named " + cardName + " in the library of " + targetPlayer.getName());
          TargetCardInLibrary target = new TargetCardInLibrary(0, cardsCount, filter);
          if (player.choose(Outcome.Exile, cardsInLibrary, target, game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
              Card targetCard = targetPlayer.getLibrary().remove(targetId, game);
              if (targetCard != null) {
                targetCard.moveToZone(Zone.EXILED, source.getId(), game, false);
              }
            }
          }
        } else {
          player.lookAtCards(targetPlayer.getName() + " library", cardsInLibrary, game);
        }
      }

      targetPlayer.shuffleLibrary(game);

      return true;
    }

    return false;
  }
Example #10
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (player == null || sourceObject == null) {
      return false;
    }

    int xValue;
    xValue = source.getManaCostsToPay().getX();

    Cards cards = new CardsImpl(Zone.PICK);
    int count = Math.min(player.getLibrary().size(), xValue);
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
        game.setZone(card.getId(), Zone.PICK);
      }
    }
    player.lookAtCards(sourceObject.getName(), cards, game);

    TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put into your hand"));
    if (player.choose(Outcome.DrawCard, cards, target, game)) {
      Card card = cards.get(target.getFirstTarget(), game);
      if (card != null) {
        cards.remove(card);
        card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
        game.informPlayers(
            sourceObject.getName()
                + ": "
                + player.getLogName()
                + " puts a card into his or her hand");
      }
    }

    target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library"));
    if (cards.size() > 0) {
      game.informPlayers(
          new StringBuilder(sourceObject.getName())
              .append(": ")
              .append(player.getLogName())
              .append(" puts ")
              .append(cards.size() == 1 ? "a" : cards.size())
              .append(" card")
              .append(cards.size() > 1 ? "s" : "")
              .append(" on the bottom of his or her library")
              .toString());
    }
    while (player.isInGame() && cards.size() > 1) {
      player.choose(Outcome.Neutral, cards, target, game);
      Card card = cards.get(target.getFirstTarget(), game);
      if (card != null) {
        cards.remove(card);
        card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
      }
      target.clearChosen();
    }
    if (cards.size() == 1) {
      Card card = cards.get(cards.iterator().next(), game);
      card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
    }

    return true;
  }
Example #11
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent enchantment = game.getPermanent(source.getSourceId());

    if (player == null || enchantment.getAttachedTo() == null) {
      return false;
    }

    Permanent creature = game.getPermanent(enchantment.getAttachedTo());
    if (creature == null) {
      return false;
    }

    Cards cards = new CardsImpl(Zone.PICK);
    int count = Math.min(player.getLibrary().size(), 5);
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
        game.setZone(card.getId(), Zone.PICK);
      }
    }
    player.lookAtCards("Call to the Kindred", cards, game);

    FilterCreatureCard filter = new FilterCreatureCard();
    StringBuilder sb = new StringBuilder("creature card with at least one subtype from: ");
    ArrayList<Predicate<MageObject>> subtypes = new ArrayList<Predicate<MageObject>>();
    for (String subtype : creature.getSubtype()) {
      subtypes.add(new SubtypePredicate(subtype));
      sb.append(subtype).append(", ");
    }
    filter.add(Predicates.or(subtypes));
    sb.delete(sb.length() - 2, sb.length());
    filter.setMessage(sb.toString());

    if (cards.count(filter, game) > 0
        && player.chooseUse(
            Outcome.DrawCard,
            "Do you wish to put a creature card onto the battlefield?",
            source,
            game)) {
      TargetCard target = new TargetCard(Zone.PICK, filter);

      if (player.choose(Outcome.PutCreatureInPlay, cards, target, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        if (card != null) {
          cards.remove(card);
          card.putOntoBattlefield(game, Zone.PICK, source.getSourceId(), source.getControllerId());
        }
      }
    }

    TargetCard target =
        new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library"));
    while (player.isInGame() && cards.size() > 1) {
      player.choose(Outcome.Neutral, cards, target, game);
      Card card = cards.get(target.getFirstTarget(), game);
      if (card != null) {
        cards.remove(card);
        card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
      }
      target.clearChosen();
    }
    if (cards.size() == 1) {
      Card card = cards.get(cards.iterator().next(), game);
      card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
    }

    return true;
  }