Ejemplo n.º 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;
  }
Ejemplo n.º 2
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.º 3
0
  @Override
  public boolean apply(Game game, Ability source) {
    boolean isMountain = false;
    Card sourceCard = game.getCard(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());

    if (player == null || sourceCard == null) {
      return false;
    }
    Cards cards = new CardsImpl(Zone.PICK);
    while (player.getLibrary().size() > 0) {
      Card card = player.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
        if (card.getCardType().contains(CardType.LAND)) {
          if (card.getSubtype().contains("Mountain")) {
            isMountain = true;
          }
          break;
        }
      } else {
        break;
      }
    }
    player.revealCards(sourceCard.getName(), cards, game);
    int damage = cards.size();
    if (isMountain == true) {
      damage *= 2;
    }

    Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
    if (permanent != null) {
      permanent.damage(damage, source.getSourceId(), game, true, false);
    } else {
      Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
      if (targetPlayer != null) {
        targetPlayer.damage(damage, source.getSourceId(), game, false, true);
      }
    }

    TargetCard target =
        new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library"));
    target.setRequired(true);
    while (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.PICK, source.getId(), game, false);
      }
      target.clearChosen();
    }

    return true;
  }
Ejemplo n.º 4
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller == null) {
     return false;
   }
   Cards cards = new CardsImpl(Zone.LIBRARY);
   cards.addAll(controller.getLibrary().getTopCards(game, 7));
   if (!cards.isEmpty()) {
     TargetCard target =
         new TargetCard(
             Zone.LIBRARY, new FilterCreatureCard("creature card to put on the battlefield"));
     if (controller.choose(Outcome.PutCreatureInPlay, cards, target, game)) {
       Card card = cards.get(target.getFirstTarget(), game);
       if (card != null) {
         cards.remove(card);
         controller.putOntoBattlefieldWithInfo(card, game, Zone.LIBRARY, source.getSourceId());
       }
     }
     if (cards.size() > 0) {
       controller.putCardsOnBottomOfLibrary(cards, game, source, true);
     }
   }
   return true;
 }
Ejemplo n.º 5
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player you = game.getPlayer(source.getControllerId());
   if (you == null) {
     return false;
   }
   Permanent arsenalThresher = game.getPermanent(source.getSourceId());
   FilterArtifactCard filter = new FilterArtifactCard();
   filter.add(new AnotherPredicate());
   if (you.chooseUse(
       Outcome.Benefit, "Do you want to reveal other artifacts in your hand?", game)) {
     Cards cards = new CardsImpl();
     if (you.getHand().count(filter, game) > 0) {
       TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
       if (you.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
         for (UUID uuid : target.getTargets()) {
           cards.add(you.getHand().get(uuid, game));
         }
         you.revealCards("Revealed cards", cards, game);
         if (arsenalThresher != null) {
           arsenalThresher.addCounters(CounterType.P1P1.createInstance(cards.size()), game);
           return true;
         }
       }
     }
   }
   return false;
 }
Ejemplo n.º 6
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Cards cards = new CardsImpl(Zone.PICK);
    int count = Math.min(player.getLibrary().size(), 4);
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      cards.add(card);
      game.setZone(card.getId(), Zone.PICK);
    }

    if (cards.size() == 0) {
      return false;
    }
    TargetCard target1 = new TargetCard(Zone.PICK, filter1);
    if (player.choose(Outcome.Detriment, cards, target1, game)) {
      Card card = cards.get(target1.getFirstTarget(), game);
      if (card != null) {
        cards.remove(card);
        card.moveToExile(getId(), "Clone Shell (Imprint)", source.getSourceId(), game);
        card.setFaceDown(true, game);
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null) {
          permanent.imprint(card.getId(), game);
        }
      }
      target1.clearChosen();
    }

    if (cards.size() > 0) {
      TargetCard target2 = new TargetCard(Zone.PICK, filter2);
      while (player.canRespond() && cards.size() > 1) {
        player.choose(Outcome.Benefit, cards, target2, game);
        Card card = cards.get(target2.getFirstTarget(), game);
        if (card != null) {
          cards.remove(card);
          card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
        }
        target2.clearChosen();
      }
      Card card = cards.get(cards.iterator().next(), game);
      card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
    }

    return true;
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
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 = 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.revealCards("Fact or Fiction", cards, game);

    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    if (!opponents.isEmpty()) {
      Player opponent = game.getPlayer(opponents.iterator().next());
      TargetCard target =
          new TargetCard(
              0, cards.size(), Zone.PICK, new FilterCard("cards to put in the first pile"));

      Cards pile1 = new CardsImpl();
      if (opponent.choose(Outcome.Neutral, cards, target, game)) {
        List<UUID> targets = target.getTargets();
        for (UUID targetId : targets) {
          Card card = cards.get(targetId, game);
          if (card != null) {
            pile1.add(card);
            cards.remove(card);
          }
        }
      }

      player.revealCards("Pile 1 (Fact or Fiction)", pile1, game);
      player.revealCards("Pile 2 (Fact or Fiction)", cards, game);

      Choice choice = new ChoiceImpl(true);
      choice.setMessage("Select a pile of cards to put into your hand:");

      StringBuilder sb = new StringBuilder("Pile 1: ");
      for (UUID cardId : pile1) {
        Card card = pile1.get(cardId, game);
        if (card != null) {
          sb.append(card.getName()).append("; ");
        }
      }
      sb.delete(sb.length() - 2, sb.length());
      choice.getChoices().add(sb.toString());

      sb = new StringBuilder("Pile 2: ");
      for (UUID cardId : cards) {
        Card card = cards.get(cardId, game);
        if (card != null) {
          sb.append(card.getName()).append("; ");
        }
      }
      sb.delete(sb.length() - 2, sb.length());
      choice.getChoices().add(sb.toString());

      Zone pile1Zone = Zone.GRAVEYARD;
      Zone pile2Zone = Zone.HAND;
      if (player.choose(Outcome.Neutral, choice, game)) {
        if (choice.getChoice().startsWith("Pile 1")) {
          pile1Zone = Zone.HAND;
          pile2Zone = Zone.GRAVEYARD;
        }
      }

      for (UUID cardUuid : pile1) {
        Card card = pile1.get(cardUuid, game);
        if (card != null) {
          card.moveToZone(pile1Zone, source.getId(), game, false);
        }
      }
      for (UUID cardUuid : cards) {
        Card card = cards.get(cardUuid, game);
        if (card != null) {
          card.moveToZone(pile2Zone, source.getId(), game, false);
        }
      }
    }

    return true;
  }
Ejemplo n.º 11
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Cards cards = new CardsImpl();
    int count = Math.min(player.getLibrary().size(), 3);
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
      }
    }
    player.revealCards("Jace, Architect of Thought", cards, game);

    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    if (!opponents.isEmpty()) {
      Player opponent = null;
      if (opponents.size() > 1) {
        TargetOpponent targetOpponent = new TargetOpponent();
        if (player.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
          opponent = game.getPlayer(targetOpponent.getFirstTarget());
        }
      }
      if (opponent == null) {
        opponent = game.getPlayer(opponents.iterator().next());
      }

      TargetCard target =
          new TargetCard(
              0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
      target.setRequired(false);
      Cards pile1 = new CardsImpl();
      if (opponent.choose(Outcome.Neutral, cards, target, game)) {
        for (UUID targetId : (List<UUID>) target.getTargets()) {
          Card card = cards.get(targetId, game);
          if (card != null) {
            pile1.add(card);
            cards.remove(card);
          }
        }
      }
      player.revealCards("Pile 1 (Jace, Architect of Thought)", pile1, game);
      player.revealCards("Pile 2 (Jace, Architect of Thought)", cards, game);

      postPileToLog("Pile 1", pile1.getCards(game), game);
      postPileToLog("Pile 2", cards.getCards(game), game);

      Cards cardsToHand = cards;
      Cards cardsToLibrary = pile1;
      List<Card> cardPile1 = new ArrayList<>();
      List<Card> cardPile2 = new ArrayList<>();
      for (UUID cardId : pile1) {
        cardPile1.add(game.getCard(cardId));
      }
      for (UUID cardId : cards) {
        cardPile2.add(game.getCard(cardId));
      }

      boolean pileChoice =
          player.choosePile(
              Outcome.Neutral,
              "Choose a pile to to put into your hand.",
              cardPile1,
              cardPile2,
              game);
      if (pileChoice) {
        cardsToHand = pile1;
        cardsToLibrary = cards;
      }
      game.informPlayers(player.getLogName() + " chose pile" + (pileChoice ? "1" : "2"));

      for (UUID cardUuid : cardsToHand) {
        Card card = cardsToHand.get(cardUuid, game);
        if (card != null) {
          player.moveCards(card, null, Zone.HAND, source, game);
        }
      }

      player.putCardsOnBottomOfLibrary(cardsToLibrary, game, source, true);
      return true;
    }
    return false;
  }
Ejemplo n.º 12
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;
  }
Ejemplo n.º 13
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;
  }