@Override public boolean removeFromHand(Card card, Game game) { return hand.remove(card.getId()); }
/** * Return a card back to top. * * @param game Game context */ @Override public void undoAction(Game game) { for (int index = drawnCards.size() - 1; index >= 0; index--) { Card card = drawnCards.get(index); player.getHand().remove(card); player.getLibrary().putOnTop(card, game); } } }
public boolean hasBottomHalf(Game game) { boolean value = bottomLastZoneChangeCounter == bottomHalfCard.getZoneChangeCounter(game) && halves.contains(bottomHalfCard.getId()); if (!value) { halves.remove(bottomHalfCard); } return value; }
public boolean hasTopHalf(Game game) { boolean value = topLastZoneChangeCounter == topHalfCard.getZoneChangeCounter(game) && halves.contains(topHalfCard.getId()); if (!value) { halves.remove(topHalfCard); } return value; }
public static List<Card> chooseOrder(String message, Cards cards, Player player, Game game) { List<Card> order = new ArrayList<>(); TargetCard target = new TargetCard(Zone.ALL, new FilterCard(message)); target.setRequired(true); while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); UUID targetObjectId = target.getFirstTarget(); order.add(cards.get(targetObjectId, game)); cards.remove(targetObjectId); target.clearChosen(); } order.add(cards.getCards(game).iterator().next()); return order; }
private Card pickCard(Game game, Player player, Cards cards, String message) { if (cards.isEmpty()) { return null; } if (cards.size() == 1) { Card card = cards.getRandom(game); cards.remove(card); return card; } TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard(message)); if (player.choose(Outcome.Benefit, cards, target, game)) { Card card = cards.get(target.getFirstTarget(), game); if (card != null) { cards.remove(card); return card; } } return null; } }
@Override public boolean removeFromZone(Game game, Zone fromZone, UUID sourceId) { if (isCopy()) { return super.removeFromZone(game, fromZone, sourceId); } if (isMelded() && fromZone == Zone.BATTLEFIELD) { Permanent permanent = game.getPermanent(objectId); return permanent != null && permanent.removeFromZone(game, fromZone, sourceId); } boolean topRemoved = hasTopHalf(game) && topHalfCard.removeFromZone(game, fromZone, sourceId); if (!topRemoved) { // The top half isn't being moved with the pair anymore. halves.remove(topHalfCard); } boolean bottomRemoved = hasBottomHalf(game) && bottomHalfCard.removeFromZone(game, fromZone, sourceId); if (!bottomRemoved) { // The bottom half isn't being moved with the pair anymore. halves.remove(bottomHalfCard); } return topRemoved || bottomRemoved; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Cards possibleCards = new CardsImpl(controller.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game)); // Set<Card> cards = controller.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game); Cards toBattlefield = new CardsImpl(); for (int i = 0; i < 2; i++) { Card card = possibleCards.getRandom(game); if (card != null) { toBattlefield.add(card); possibleCards.remove(card); } } controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); MageObject sourceObject = game.getObject(source.getSourceId()); if (controller == null || sourceObject == null) { return false; } Cards cards = new CardsImpl(); cards.addAll(controller.getLibrary().getTopCards(game, 2)); if (!cards.isEmpty()) { controller.revealCards(sourceObject.getIdName(), cards, game); Set<Card> toBattlefield = new LinkedHashSet<>(); for (Card card : cards.getCards(new FilterLandCard(), source.getSourceId(), source.getControllerId(), game)) { cards.remove(card); toBattlefield.add(card); } controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, false, true, null); controller.moveCards(cards, Zone.HAND, source, game); } return true; }
@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()); } else { return false; } } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5)); boolean properCardFound = cards.count(filterPutInHand, game) > 0; if (!cards.isEmpty()) { controller.revealCards(source, cards, game); TargetCard target = new TargetCard(Zone.LIBRARY, filterPutInHand); if (properCardFound && controller.choose(Outcome.DrawCard, cards, target, game)) { Card card = game.getCard(target.getFirstTarget()); if (card != null) { controller.moveCards(card, Zone.HAND, source, game); cards.remove(card); } } controller.moveCards(cards, Zone.GRAVEYARD, source, game); } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5)); if (!cards.isEmpty()) { controller.lookAtCards(source, null, cards, game); TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put in your hand")); if (controller.choose(Outcome.Benefit, cards, target, game)) { Card card = cards.get(target.getFirstTarget(), game); if (card != null) { controller.moveCards(card, Zone.HAND, source, game); cards.remove(card); } } controller.moveCards(cards, Zone.EXILED, source, game); } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(getTargetPointer().getFirst(game, source)); Player controller = game.getPlayer(source.getControllerId()); if (controller != null && player != null) { Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 3)); if (!cards.isEmpty()) { TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("Card to put back on top of library")); if (controller.chooseTarget(Outcome.Benefit, cards, target, source, game)) { Card card = cards.get(target.getFirstTarget(), game); if (card != null) { cards.remove(card); } } controller.moveCards(cards, Zone.GRAVEYARD, source, game); } return true; } return false; }
@Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return false; } Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX())); controller.lookAtCards(source, null, cards, game); TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to stay at the top of library")); if (controller.choose(outcome, cards, target, game)) { cards.remove(target.getFirstTarget()); } controller.putCardsOnBottomOfLibrary(cards, game, source, false); game.applyEffects(); controller.drawCards(1, game, event.getAppliedEffects()); discard(); return true; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source)); if (controller != null && opponent != null) { Cards cards = new CardsImpl(); cards.addAll(opponent.getLibrary().getTopCards(game, 2)); if (!cards.isEmpty()) { TargetCard target = new TargetCardInLibrary(new FilterCard("card to exile")); if (controller.choose(Outcome.Exile, cards, target, game)) { Card card = cards.get(target.getFirstTarget(), game); if (card != null) { cards.remove(card); opponent.moveCards(card, Zone.EXILED, source, game); } } } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source)); if (controller != null && opponent != null) { Cards cards = new CardsImpl(); cards.addAll(opponent.getLibrary().getTopCards(game, 2)); if (!cards.isEmpty()) { TargetCard target = new TargetCardInLibrary(new FilterCard("card to put into graveyard")); controller.choose(Outcome.Benefit, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { cards.remove(card); controller.moveCards(card, Zone.GRAVEYARD, source, game); } } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(getTargetPointer().getFirst(game, source)); if (player == null) { return false; } Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 3)); player.lookAtCards(source, null, cards, game); TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put on top of your library")); if (player.choose(Outcome.Benefit, cards, target, game)) { Card card = cards.get(target.getFirstTarget(), game); if (card != null) { cards.remove(card); game.informPlayers(source.getSourceObject(game).getIdName() + ": " + player.getLogName() + " puts a card back on top of their library"); } } player.moveCards(cards, Zone.EXILED, source, game); return true; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Set<Card> cardsSet = controller.getLibrary().getTopCards(game, 6); Cards cards = new CardsImpl(); for (Card card : cardsSet) { cards.add(card); } TargetCard target = new TargetCardInLibrary(0, 1, new FilterNonlandCard("card to cast without paying its mana cost")); if (controller.choose(Outcome.PlayForFree, cards, target, game)) { Card card = controller.getLibrary().getCard(target.getFirstTarget(), game); if (card != null && controller.cast(card.getSpellAbility(), game, true, new MageObjectReference(source.getSourceObject(game), game))) { cards.remove(card); } } controller.putCardsOnBottomOfLibrary(cards, game, source, false); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); Permanent permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); if (player == null || permanent == null) { return false; } Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, permanent.getCounters(game).getCount(CounterType.CHARGE))); if (!cards.isEmpty()) { player.lookAtCards(source, null, cards, game); TargetCard target = new TargetCard(Zone.LIBRARY, 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); player.moveCards(card, Zone.HAND, source, game); } } player.putCardsOnBottomOfLibrary(cards, game, source, true); } return true; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent permanent = ((FixedTarget) getTargetPointer()).getTargetedPermanentOrLKIBattlefield(game); if (controller != null && permanent != null) { Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, permanent.getPower().getValue())); if (!cards.isEmpty()) { TargetCard target = new TargetCardInHand(new FilterCard("card to put on top of your library")); controller.choose(Outcome.Benefit, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { cards.remove(card); controller.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, true); } controller.putCardsOnBottomOfLibrary(cards, game, source, true); } return true; } return false; } }