@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; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Player opponent = game.getPlayer(source.getFirstTarget()); Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); if (controller != null && opponent != null && sourcePermanent != null) { opponent.revealCards(sourcePermanent.getName(), opponent.getHand(), game); TargetCard target = new TargetCard(Zone.PICK, new FilterNonlandCard("nonland card to exile")); if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) { Card card = opponent.getHand().get(target.getFirstTarget(), game); if (card != null) { controller.moveCardToExileWithInfo( card, CardUtil.getCardExileZoneId(game, source), sourcePermanent.getName(), source.getSourceId(), game, Zone.HAND); } } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Card creature = null; Player opponent = game.getPlayer(source.getFirstTarget()); CardsImpl cards = new CardsImpl(); boolean creatureFound = false; while (opponent.getLibrary().size() > 0 && !creatureFound) { Card card = opponent.getLibrary().removeFromTop(game); if (card != null) { if (card.getCardType().contains(CardType.CREATURE)) { creature = card; creatureFound = true; } if (!creatureFound) { cards.add(card); } } } if (!cards.isEmpty()) { opponent.revealCards("Telemin Performance", cards, game); opponent.moveCards(cards, Zone.GRAVEYARD, source, game); } if (creature != null) { return creature.putOntoBattlefield( game, Zone.LIBRARY, source.getSourceId(), source.getControllerId()); } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); MageObject sourceObject = source.getSourceObject(game); if (controller != null && sourceObject != null) { Choice choice = new ChoiceImpl(true); choice.setMessage("Choose a creature type:"); choice.setChoices(CardRepository.instance.getCreatureTypes()); while (!controller.choose(Outcome.BoostCreature, choice, game)) { if (!controller.canRespond()) { return false; } } Cards revealedCards = new CardsImpl(); while (controller.getLibrary().size() > 0) { Card card = controller.getLibrary().removeFromTop(game); if (card.getCardType().contains(CardType.CREATURE) && card.getSubtype().contains(choice.getChoice())) { controller.moveCards(card, Zone.BATTLEFIELD, source, game); break; } revealedCards.add(card); } controller.revealCards(sourceObject.getIdName(), revealedCards, game); controller.moveCards(revealedCards, Zone.LIBRARY, source, game); controller.shuffleLibrary(source, game); return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Permanent sourcePermanent = (Permanent) game.getLastKnownInformation( targetPointer.getFirst(game, source), Constants.Zone.BATTLEFIELD); if (sourcePermanent == null) { return false; } Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return false; } Cards revealed = new CardsImpl(); Card artifactCard = null; Cards nonArtifactCards = new CardsImpl(); Player player = game.getPlayer(sourcePermanent.getControllerId()); while (artifactCard == null && player.getLibrary().size() > 0) { Card card = player.getLibrary().removeFromTop(game); revealed.add(card); if (card.getCardType().contains(CardType.ARTIFACT)) artifactCard = card; else nonArtifactCards.add(card); } player.revealCards("Shape Anew", revealed, game); if (artifactCard != null) { artifactCard.putOntoBattlefield( game, Constants.Zone.LIBRARY, source.getId(), player.getId()); } player.getLibrary().addAll(nonArtifactCards.getCards(game), game); player.shuffleLibrary(game); return true; }
@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; }
/** * Checks all available splice effects to be applied. * * @param abilityToModify * @param game */ public void applySpliceEffects(Ability abilityToModify, Game game) { if (((SpellAbility) abilityToModify).getSpellAbilityType().equals(SpellAbilityType.SPLICE)) { // on a spliced ability of a spell can't be spliced again return; } List<SpliceCardEffect> spliceEffects = getApplicableSpliceCardEffects(game, abilityToModify.getControllerId()); // get the applyable splice abilities List<SpliceOntoArcaneAbility> spliceAbilities = new ArrayList<>(); for (SpliceCardEffect effect : spliceEffects) { HashSet<Ability> abilities = spliceCardEffects.getAbility(effect.getId()); for (Ability ability : abilities) { if (effect.applies(abilityToModify, ability, game)) { spliceAbilities.add((SpliceOntoArcaneAbility) ability); } } } // check if player wants to use splice if (spliceAbilities.size() > 0) { Player controller = game.getPlayer(abilityToModify.getControllerId()); if (controller.chooseUse(Outcome.Benefit, "Splice a card?", game)) { Cards cardsToReveal = new CardsImpl(); do { FilterCard filter = new FilterCard("a card to splice"); ArrayList<Predicate<MageObject>> idPredicates = new ArrayList<>(); for (SpliceOntoArcaneAbility ability : spliceAbilities) { idPredicates.add(new CardIdPredicate((ability.getSourceId()))); } filter.add(Predicates.or(idPredicates)); TargetCardInHand target = new TargetCardInHand(filter); controller.chooseTarget(Outcome.Benefit, target, abilityToModify, game); UUID cardId = target.getFirstTarget(); if (cardId != null) { SpliceOntoArcaneAbility selectedAbility = null; for (SpliceOntoArcaneAbility ability : spliceAbilities) { if (ability.getSourceId().equals(cardId)) { selectedAbility = ability; break; } } if (selectedAbility != null) { SpliceCardEffect spliceEffect = (SpliceCardEffect) selectedAbility.getEffects().get(0); spliceEffect.apply(game, selectedAbility, abilityToModify); cardsToReveal.add(game.getCard(cardId)); spliceAbilities.remove(selectedAbility); } } } while (!spliceAbilities.isEmpty() && controller.chooseUse(Outcome.Benefit, "Splice another card?", game)); controller.revealCards("Spliced cards", cardsToReveal, game); } } }
@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; }
@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.getLibrary().size() > 0) { Card card = controller.getLibrary().getFromTop(game); if (card == null) { return false; } controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game); if (card.getCardType().contains(CardType.CREATURE)) { FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(); boolean found = false; for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) { if (CardUtil.shareSubtypes(card, permanent, game)) { found = true; break; } } if (found) { game.informPlayers( sourceObject.getLogName() + ": Found a creature that shares a creature type with the revealed card."); if (controller.chooseUse(Outcome.Benefit, "Cast the card?", source, game)) { controller.cast(card.getSpellAbility(), game, true); } else { game.informPlayers( sourceObject.getLogName() + ": " + controller.getLogName() + " canceled casting the card."); controller.getLibrary().putOnBottom(card, game); } } else { game.informPlayers( sourceObject.getLogName() + ": No creature that shares a creature type with the revealed card."); controller.getLibrary().putOnBottom(card, game); } } else { game.informPlayers( sourceObject.getLogName() + ": Put " + card.getLogName() + " on the bottom."); controller.getLibrary().putOnBottom(card, game); } return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { Player targetPlayer = game.getPlayer(source.getFirstTarget()); if (targetPlayer != null && targetPlayer.getHand().size() > 0) { Cards revealed = new CardsImpl(); Card card = targetPlayer.getHand().getRandom(game); revealed.add(card); targetPlayer.revealCards("Singe-Mind Ogre", revealed, game); targetPlayer.loseLife(card.getManaCost().convertedManaCost(), game); return true; } return false; }
@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; }
@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) { Card card = game.getCard(source.getSourceId()); if (card != null) { Player player = game.getPlayer(card.getOwnerId()); if (player != null) { Cards cards = new CardsImpl(); cards.add(card); player.revealCards("Progenitus", cards, game); card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true); player.shuffleLibrary(game); return true; } } return false; }
@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; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getFirstTarget()); if (player != null && player.getLibrary().size() > 0) { Card card = player.getLibrary().getFromTop(game); Cards cards = new CardsImpl(); cards.add(card); player.revealCards("Cerebral Eruption", cards, game); game.getState().setValue(source.getId().toString(), card); int damage = card.getManaCost().convertedManaCost(); player.damage(damage, source.getId(), game, false, true); for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, player.getId(), game)) { perm.damage(damage, source.getId(), game, true, false); } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Card sourceCard = game.getCard(source.getSourceId()); MageObject sourceObject = game.getObject(source.getSourceId()); if (sourceCard != null) { Player player = game.getPlayer(sourceCard.getOwnerId()); if (player != null) { Zone fromZone = game.getState().getZone(sourceCard.getId()); Cards cards = new CardsImpl(); cards.add(sourceCard); player.revealCards(sourceObject.getLogName(), cards, game); player.moveCardToLibraryWithInfo( sourceCard, source.getSourceId(), game, fromZone, true, true); player.shuffleLibrary(game); return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player == null) { return false; } if (player.getLibrary().size() > 0) { Card card = player.getLibrary().getFromTop(game); Cards cards = new CardsImpl(); cards.add(card); player.revealCards("Pain Seer", cards, game); if (card != null && card.moveToZone(Zone.HAND, source.getSourceId(), game, false)) { player.loseLife(card.getManaCost().convertedManaCost(), game); return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { TargetCardInLibrary target = new TargetCardInLibrary(0, 2, new FilterBasicLandCard()); Player player = game.getPlayer(source.getControllerId()); if (player.searchLibrary(target, game)) { if (target.getTargets().size() > 0) { Cards revealed = new CardsImpl(); for (UUID cardId : target.getTargets()) { Card card = player.getLibrary().getCard(cardId, game); revealed.add(card); } player.revealCards("Kodama's Reach", revealed, game); if (target.getTargets().size() == 2) { TargetCard target2 = new TargetCard(Zone.PICK, filter); player.choose(Outcome.Benefit, revealed, target2, game); Card card = revealed.get(target2.getFirstTarget(), game); if (card != null) { player.putOntoBattlefieldWithInfo(card, game, Zone.LIBRARY, source.getSourceId(), true); revealed.remove(card); } card = revealed.getCards(game).iterator().next(); if (card != null) { player.moveCardToHandWithInfo(card, source.getSourceId(), game, Zone.LIBRARY); } } else if (target.getTargets().size() == 1) { Card card = revealed.getCards(game).iterator().next(); if (card != null) { player.putOntoBattlefieldWithInfo(card, game, Zone.LIBRARY, source.getSourceId(), true); } } } player.shuffleLibrary(game); return true; } player.shuffleLibrary(game); return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Card sourceCard = game.getCard(source.getSourceId()); if (controller == null || sourceCard == null) { return false; } if (controller.getLibrary().size() > 0) { controller.shuffleLibrary(game); Card card = controller.getLibrary().getFromTop(game); if (card == null) { return false; } controller.revealCards(sourceCard.getName(), new CardsImpl(card), game); if (card.getCardType().contains(CardType.LAND)) { String message = "Put " + card.getName() + " onto the battlefield?"; if (controller.chooseUse(Outcome.PutLandInPlay, message, game)) { card.putOntoBattlefield( game, Zone.LIBRARY, source.getSourceId(), source.getControllerId()); return sourceCard.moveToZone(Zone.HAND, source.getSourceId(), game, false); } } else { if (controller.chooseUse( outcome, new StringBuilder("Cast ") .append(card.getName()) .append(" without paying its mana cost?") .toString(), game)) { return controller.cast(card.getSpellAbility(), game, true); } } 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 (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; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(targetPointer.getFirst(game, source)); Player controller = game.getPlayer(source.getControllerId()); Card sourceCard = game.getCard(source.getSourceId()); if (player != null && controller != null) { if (revealAllCards) { this.numberCardsToReveal = new StaticValue(player.getHand().size()); } int numberToReveal = this.numberCardsToReveal.calculate(game, source, this); if (numberToReveal > 0) { Cards revealedCards = new CardsImpl(Zone.HAND); numberToReveal = Math.min(player.getHand().size(), numberToReveal); if (player.getHand().size() > numberToReveal) { TargetCardInHand chosenCards = new TargetCardInHand( numberToReveal, numberToReveal, new FilterCard("card in " + player.getLogName() + "'s hand")); chosenCards.setNotTarget(true); if (chosenCards.canChoose(player.getId(), game) && player.chooseTarget( Outcome.Discard, player.getHand(), chosenCards, source, game)) { if (!chosenCards.getTargets().isEmpty()) { List<UUID> targets = chosenCards.getTargets(); for (UUID targetid : targets) { Card card = game.getCard(targetid); if (card != null) { revealedCards.add(card); } } } } } else { revealedCards.addAll(player.getHand()); } player.revealCards( sourceCard != null ? sourceCard.getName() : "Discard", revealedCards, game); boolean result = true; int filteredCardsCount = revealedCards.count(filter, source.getSourceId(), source.getControllerId(), game); int numberToDiscard = Math.min(this.numberCardsToDiscard.calculate(game, source, this), filteredCardsCount); if (numberToDiscard > 0) { TargetCard target = new TargetCard(numberToDiscard, Zone.HAND, filter); if (controller.choose(Outcome.Benefit, revealedCards, target, game)) { for (Object targetId : target.getTargets()) { Card card = revealedCards.get((UUID) targetId, game); if (card != null) { if (!player.discard(card, source, game)) { result = false; } } } } } return result; } return true; } return false; }
@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; }
@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; }
@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; }
@Override public boolean apply(Game game, Ability source) { Player you = game.getPlayer(source.getControllerId()); Cards cards = new CardsImpl(); FilterCard filterWhite = new FilterCard("white card"); filterWhite.add(new ColorPredicate(ObjectColor.WHITE)); FilterCard filterBlue = new FilterCard("blue card"); filterBlue.add(new ColorPredicate(ObjectColor.BLUE)); FilterCard filterBlack = new FilterCard("black card"); filterBlack.add(new ColorPredicate(ObjectColor.BLACK)); FilterCard filterRed = new FilterCard("red card"); filterRed.add(new ColorPredicate(ObjectColor.RED)); FilterCard filterGreen = new FilterCard("green card"); filterGreen.add(new ColorPredicate(ObjectColor.GREEN)); TargetCardInLibrary targetWhite = new TargetCardInLibrary(filterWhite); TargetCardInLibrary targetBlue = new TargetCardInLibrary(filterBlue); TargetCardInLibrary targetBlack = new TargetCardInLibrary(filterBlack); TargetCardInLibrary targetRed = new TargetCardInLibrary(filterRed); TargetCardInLibrary targetGreen = new TargetCardInLibrary(filterGreen); if (you != null && you.getLibrary().size() > 0) { if (you.searchLibrary(targetWhite, game)) { if (targetWhite.getTargets().size() > 0) { for (UUID cardId : (List<UUID>) targetWhite.getTargets()) { Card card = you.getLibrary().remove(cardId, game); if (card != null) { cards.add(card); } } } } } if (you != null && you.getLibrary().size() > 0) { if (you.searchLibrary(targetBlue, game)) { if (targetBlue.getTargets().size() > 0) { for (UUID cardId : (List<UUID>) targetBlue.getTargets()) { Card card = you.getLibrary().remove(cardId, game); if (card != null) { cards.add(card); } } } } } if (you != null && you.getLibrary().size() > 0) { if (you.searchLibrary(targetBlack, game)) { if (targetBlack.getTargets().size() > 0) { for (UUID cardId : (List<UUID>) targetBlack.getTargets()) { Card card = you.getLibrary().remove(cardId, game); if (card != null) { cards.add(card); } } } } } if (you != null && you.getLibrary().size() > 0) { if (you.searchLibrary(targetRed, game)) { if (targetRed.getTargets().size() > 0) { for (UUID cardId : (List<UUID>) targetRed.getTargets()) { Card card = you.getLibrary().remove(cardId, game); if (card != null) { cards.add(card); } } } } } if (you != null && you.getLibrary().size() > 0) { if (you.searchLibrary(targetGreen, game)) { if (targetGreen.getTargets().size() > 0) { for (UUID cardId : (List<UUID>) targetGreen.getTargets()) { Card card = you.getLibrary().remove(cardId, game); if (card != null) { cards.add(card); } } } } } if (you != null) { you.revealCards("Conflux", cards, game); for (Card card : cards.getCards(game)) { card.moveToZone(Zone.HAND, source.getSourceId(), game, true); } you.shuffleLibrary(source, game); } return true; }