@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) { Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source)); if (permanent != null) { if (permanent.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true)) { game.getState().getPlayer(permanent.getOwnerId()).getLibrary().shuffle(); return true; } } return false; }
@Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).isDiesEvent()) { Permanent card = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD); if (card != null && card.getOwnerId().equals(this.controllerId) && card.getCardType().contains(CardType.CREATURE) && !(card instanceof PermanentToken)) { creaturesCount++; } } }
@Override public boolean apply(Game game, Ability source) { for (UUID permanentId : targetPointer.getTargets(game, source)) { Permanent permanent = game.getPermanent(permanentId); if (permanent != null) { Card card = game.getCard(permanent.getId()); int zoneChangeCounter = card.getZoneChangeCounter(); if (permanent.destroy(source.getSourceId(), game, false)) { if (card != null && game.getPlayer(permanent.getOwnerId()).getGraveyard().contains(card.getId()) && card.getZoneChangeCounter() == zoneChangeCounter) { return new CreateTokenEffect( new VampireToken( permanent.getPower().getValue(), permanent.getToughness().getValue())) .apply(game, source); } } } } 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; }
@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; }
public PermanentView(Permanent permanent, Card card, UUID createdForPlayerId, Game game) { super(permanent, game, permanent.getControllerId().equals(createdForPlayerId)); this.controlled = permanent.getControllerId().equals(createdForPlayerId); this.rules = permanent.getRules(game); this.tapped = permanent.isTapped(); this.flipped = permanent.isFlipped(); this.phasedIn = permanent.isPhasedIn(); this.summoningSickness = permanent.hasSummoningSickness(); this.morphed = permanent.isMorphed(); this.manifested = permanent.isManifested(); this.damage = permanent.getDamage(); if (permanent.getAttachments().size() > 0) { attachments = new ArrayList<>(); attachments.addAll(permanent.getAttachments()); } this.attachedTo = permanent.getAttachedTo(); if (isToken()) { original = new CardView(((PermanentToken) permanent).getToken()); original.expansionSetCode = permanent.getExpansionSetCode(); tokenSetCode = original.getTokenSetCode(); } else { if (card != null) { // original may not be face down original = new CardView(card); } else { original = null; } } this.transformed = permanent.isTransformed(); this.copy = permanent.isCopy(); // for fipped, transformed or copied cards, switch the names if (original != null && !original.getName().equals(this.getName())) { if (permanent.isCopy() && permanent.isFlipCard()) { this.alternateName = permanent.getFlipCardName(); this.originalName = this.getName(); } else { if (controlled // controller may always know || (!morphed && !manifested)) { // others don't know for morph or transformed cards this.alternateName = original.getName(); this.originalName = this.getName(); } } } if (!permanent.getOwnerId().equals(permanent.getControllerId())) { Player owner = game.getPlayer(permanent.getOwnerId()); if (owner != null) { this.nameOwner = owner.getName(); } else { this.nameOwner = ""; } } else { this.nameOwner = ""; } if (permanent.isFaceDown(game) && card != null) { if (controlled) { // must be a morphed or manifested card for (Ability permanentAbility : permanent.getAbilities()) { if (permanentAbility instanceof TurnFaceUpAbility && !permanentAbility.getRuleVisible()) { this.rules.add(permanentAbility.getRule(true)); } if (permanentAbility.getWorksFaceDown()) { this.rules.add(permanentAbility.getRule()); } } this.name = card.getName(); this.displayName = card.getName(); this.expansionSetCode = card.getExpansionSetCode(); this.cardNumber = card.getCardNumber(); } else { if (permanent.isManifested()) { this.rules.add( "A manifested creature card can be turned face up any time for it's mana cost." + " A face-down card can also be turned face up for its morph cost."); } else if (permanent.isMorphed()) { this.rules.add( "If the controller has priority, he or she may turn this permanent face up." + " This is a special action; it doesnt use the stack. To do this he or she pays the morph costs," + " then turns this permanent face up."); } } } // determines if shown in it's own column if (permanent.getAttachedTo() != null) { attachedToPermanent = game.getPermanent(permanent.getAttachedTo()) != null; } else { attachedToPermanent = false; } }