Example #1
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;
 }
  @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 #3
0
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject sourceObject = game.getObject(source.getSourceId());
   if (controller != null && sourceObject != null) {
     Card card = game.getCard(event.getTargetId());
     if (card != null) {
       Cards cards = new CardsImpl(card);
       controller.revealCards(sourceObject.getIdName(), cards, game);
       controller.putCardsOnBottomOfLibrary(cards, game, source, false);
       return true;
     }
   }
   return false;
 }
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     List<Card> cards = new ArrayList<>();
     List<Permanent> permanents = new ArrayList<>();
     for (UUID targetId : targetPointer.getTargets(game, source)) {
       switch (game.getState().getZone(targetId)) {
         case BATTLEFIELD:
           Permanent permanent = game.getPermanent(targetId);
           if (permanent != null) {
             permanents.add(permanent);
           }
           break;
         case GRAVEYARD:
           Card card = game.getCard(targetId);
           if (card != null && game.getState().getZone(targetId).equals(Zone.GRAVEYARD)) {
             cards.add(card);
           }
           break;
       }
     }
     // Plow Under
     // 10/4/2004 	The owner decides the order the two lands are stacked there.
     while (!cards.isEmpty()) {
       Card card = cards.iterator().next();
       if (card != null) {
         Player owner = game.getPlayer(card.getOwnerId());
         Cards cardsPlayer = new CardsImpl();
         for (Iterator<Card> iterator = cards.iterator(); iterator.hasNext(); ) {
           Card next = iterator.next();
           if (next.getOwnerId().equals(owner.getId())) {
             cardsPlayer.add(next);
             iterator.remove();
           }
         }
         if (onTop) {
           owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
         } else {
           owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true);
         }
       }
     }
     while (!permanents.isEmpty()) {
       Permanent permanent = permanents.iterator().next();
       if (permanent != null) {
         Player owner = game.getPlayer(permanent.getOwnerId());
         Cards cardsPlayer = new CardsImpl();
         for (Iterator<Permanent> iterator = permanents.iterator(); iterator.hasNext(); ) {
           Permanent next = iterator.next();
           if (next.getOwnerId().equals(owner.getId())) {
             cardsPlayer.add(next);
             iterator.remove();
           }
         }
         if (onTop) {
           owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
         } else {
           owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, 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) {
      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;
  }
Example #6
0
  @Override
  public boolean apply(Game game, Ability source) {
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject == null) {
      return false;
    }
    Map<UUID, Set<Card>> permanentsOwned = new HashMap<>();
    Collection<Permanent> permanents = game.getBattlefield().getAllActivePermanents();
    for (Permanent permanent : permanents) {
      Set<Card> set = permanentsOwned.get(permanent.getOwnerId());
      if (set == null) {
        set = new LinkedHashSet<>();
      }
      set.add(permanent);
      permanentsOwned.put(permanent.getOwnerId(), set);
    }

    // shuffle permanents into owner's library
    Map<UUID, Integer> permanentsCount = new HashMap<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
      Player player = game.getPlayer(playerId);
      if (player != null) {
        Set<Card> set = permanentsOwned.remove(playerId);
        Integer count = 0;
        if (set != null) {
          count = set.size();
          player.moveCards(set, Zone.BATTLEFIELD, Zone.LIBRARY, source, game);
        }

        if (count > 0) {
          player.shuffleLibrary(game);
        }
        permanentsCount.put(playerId, count);
      }
    }

    game.applyEffects(); // so effects from creatures that were on the battlefield won't trigger
    // from draw or later put into play

    Map<UUID, CardsImpl> cardsRevealed = new HashMap<>();

    // draw cards and reveal them
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
      Player player = game.getPlayer(playerId);
      if (player != null) {
        Integer count = Math.min(permanentsCount.get(player.getId()), player.getLibrary().size());
        CardsImpl cards = new CardsImpl();
        for (int i = 0; i < count; i++) {
          Card card = player.getLibrary().removeFromTop(game);
          if (card != null) {
            cards.add(card);
          }
        }
        player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ")", cards, game);
        cardsRevealed.put(player.getId(), cards);
      }
    }

    // put artifacts, creaturs and lands onto the battlefield
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
      Player player = game.getPlayer(playerId);
      if (player != null) {
        CardsImpl cards = cardsRevealed.get(player.getId());
        for (Card card : cards.getCards(game)) {
          if (card != null
              && (card.getCardType().contains(CardType.ARTIFACT)
                  || card.getCardType().contains(CardType.CREATURE)
                  || card.getCardType().contains(CardType.LAND))) {
            card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId());
            cards.remove(card);
          }
        }
      }
    }
    // put enchantments onto the battlefield
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
      Player player = game.getPlayer(playerId);
      if (player != null) {
        CardsImpl cards = cardsRevealed.get(player.getId());
        for (Card card : cards.getCards(game)) {
          if (card != null && card.getCardType().contains(CardType.ENCHANTMENT)) {
            card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId());
            cards.remove(card);
          }
        }
      }
    }
    // put the rest of the cards on buttom of the library
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
      Player player = game.getPlayer(playerId);
      if (player != null) {
        CardsImpl cards = cardsRevealed.get(player.getId());
        player.putCardsOnBottomOfLibrary(cards, game, source, false);
      }
    }
    return true;
  }