@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) { Player controller = game.getPlayer(source.getControllerId()); Permanent permanent = (Permanent) game.getLastKnownInformation(target, Zone.BATTLEFIELD); if (permanent != null && controller != null) { Player player = game.getPlayer(permanent.getOwnerId()); if (player != null) { FilterCreatureCard filter = new FilterCreatureCard( new StringBuilder("a creature card from ") .append(player.getLogName()) .append("'s graveyard") .toString()); filter.add(new OwnerIdPredicate(player.getId())); Target targetCreature = new TargetCardInGraveyard(filter); if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, targetCreature, source, game)) { Card card = game.getCard(targetCreature.getFirstTarget()); if (card != null && game.getState().getZone(card.getId()).equals(Zone.GRAVEYARD)) { return card.putOntoBattlefield( game, Zone.GRAVEYARD, source.getSourceId(), player.getId()); } } return true; } } return false; }
@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; }
@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) { UUID exileId = source.getSourceId(); ExileZone exile = game.getExile().getExileZone(exileId); if (exile != null) { exile = exile.copy(); for (UUID cardId : exile) { Card card = game.getCard(cardId); card.putOntoBattlefield(game, Zone.EXILED, source.getSourceId(), card.getOwnerId()); } game.getExile().getExileZone(exileId).clear(); return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player == null || !player.chooseUse(Outcome.PutCreatureInPlay, choiceText, game)) { return false; } TargetCardInHand target = new TargetCardInHand(filter); if (player.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) { Card card = game.getCard(target.getFirstTarget()); if (card != null) { card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), source.getControllerId()); return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); for (Card card : player.getGraveyard().getCards(filterZombie, game)) { card.putOntoBattlefield(game, Zone.GRAVEYARD, source.getSourceId(), source.getControllerId()); Permanent permanent = game.getPermanent(card.getId()); if (permanent != null) { permanent.setTapped(true); } } for (Permanent permanent : game.getBattlefield().getActivePermanents(filterHuman, source.getControllerId(), game)) { permanent.destroy(source.getSourceId(), game, false); } return true; }
@Override public boolean apply(Game game, Ability source) { Card card = game.getCard(source.getFirstTarget()); if (card != null) { card.addAbility(HasteAbility.getInstance()); card.putOntoBattlefield(game, Zone.GRAVEYARD, source.getId(), source.getControllerId()); ExileTargetEffect exileEffect = new ExileTargetEffect(); exileEffect.setTargetPointer(new FixedTarget(card.getId())); DelayedTriggeredAbility delayedAbility = new AtEndOfTurnDelayedTriggeredAbility(exileEffect); delayedAbility.setSourceId(source.getSourceId()); delayedAbility.setControllerId(source.getControllerId()); game.addDelayedTriggeredAbility(delayedAbility); return true; } return false; }
@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; }
@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 player = game.getPlayer(source.getControllerId()); if (player == null) { return false; } if (player.searchLibrary(target, game)) { if (target.getTargets().size() > 0) { for (UUID cardId : (List<UUID>) target.getTargets()) { Card card = player.getLibrary().getCard(cardId, game); if (card != null) { card.putOntoBattlefield( game, Zone.LIBRARY, source.getSourceId(), source.getControllerId(), tapped); } } } player.shuffleLibrary(game); return true; } if (forceShuffle) { player.shuffleLibrary(game); } return false; }
@Override public boolean apply(Game game, Ability source) { Player you = game.getPlayer(source.getControllerId()); Permanent attackingCreature = game.getPermanent(getTargetPointer().getFirst(game, source)); if (you != null && attackingCreature != null) { FilterCard filter = new FilterCard("aura that could enchant the lone attacking creature"); filter.add(new SubtypePredicate("Aura")); filter.add(new AuraCardCanAttachToPermanentId(attackingCreature.getId())); if (you.chooseUse(Outcome.Benefit, "Do you want to search your library?", source, game)) { TargetCardInLibrary target = new TargetCardInLibrary(filter); target.setNotTarget(true); if (you.searchLibrary(target, game)) { if (target.getFirstTarget() != null) { Card aura = game.getCard(target.getFirstTarget()); game.getState().setValue("attachTo:" + aura.getId(), attackingCreature); aura.putOntoBattlefield(game, Zone.LIBRARY, source.getSourceId(), you.getId()); return attackingCreature.addAttachment(aura.getId(), game); } } } you.shuffleLibrary(game); } 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 resolve(Game game) { boolean result; if (this.getCardType().contains(CardType.INSTANT) || this.getCardType().contains(CardType.SORCERY)) { int index = 0; result = false; boolean legalParts = false; for (SpellAbility spellAbility : this.spellAbilities) { for (UUID modeId : spellAbility.getModes().getSelectedModes()) { spellAbility.getModes().setMode(spellAbility.getModes().get(modeId)); if (spellAbility.getTargets().stillLegal(spellAbility, game)) { legalParts = true; if (!spellAbility.getSpellAbilityType().equals(SpellAbilityType.SPLICE)) { updateOptionalCosts(index); } result |= spellAbility.resolve(game); } } index++; } if (legalParts) { if (!copiedSpell) { for (Effect effect : ability.getEffects()) { if (effect instanceof PostResolveEffect) { ((PostResolveEffect) effect).postResolve(card, ability, controllerId, game); return result; } } if (!card.isCopy() && game.getState().getZone(card.getId()) == Zone.STACK) { card.moveToZone(Zone.GRAVEYARD, ability.getId(), game, false); } } return result; } // 20091005 - 608.2b game.informPlayers(getName() + " has been fizzled."); counter(null, game); return false; } else if (this.getCardType().contains(CardType.ENCHANTMENT) && this.getSubtype().contains("Aura")) { if (ability.getTargets().stillLegal(ability, game)) { updateOptionalCosts(0); if (card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId)) { return ability.resolve(game); } return false; } if (this.getCardType() .contains( CardType.CREATURE)) { // e.g. Creature with Bestow (rule confirmation yet missing) updateOptionalCosts(0); result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId); return result; } else { // 20091005 - 608.2b game.informPlayers(getName() + " has been fizzled."); counter(null, game); return false; } } else { updateOptionalCosts(0); result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId); return result; } }
@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; }