Ejemplo n.º 1
0
 @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;
 }
Ejemplo n.º 2
0
 @Override
 public boolean apply(Game game, Ability source) {
   CardsImpl cardsInExile = new CardsImpl();
   TargetCard target = new TargetCard(Zone.EXILED, new FilterCreatureCard());
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     ExileZone exile = game.getExile().getExileZone(exileId);
     if (exile != null) {
       LinkedList<UUID> cards = new LinkedList<>(exile);
       for (UUID cardId : cards) {
         Card card = game.getCard(cardId);
         cardsInExile.add(card);
       }
       if (controller.choose(Outcome.PutCreatureInPlay, cardsInExile, target, game)) {
         Card chosenCard = game.getCard(target.getFirstTarget());
         return controller.moveCards(chosenCard, Zone.BATTLEFIELD, source, game);
       }
     }
   }
   return false;
 }
Ejemplo n.º 3
0
  @Override
  public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
    Permanent eyeOfTheStorm = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (spell != null && eyeOfTheStorm != null) {
      Player spellController = game.getPlayer(spell.getControllerId());
      Card card = spell.getCard();
      if (spellController == null || card == null || !instantOrSorceryfilter.match(card, game)) {
        return false;
      }

      UUID exileZoneId =
          CardUtil.getExileZoneId(
              game, source.getSourceId(), eyeOfTheStorm.getZoneChangeCounter(game));
      if (spellController.moveCardsToExile(
          spell, source, game, true, exileZoneId, eyeOfTheStorm.getIdName())) {
        eyeOfTheStorm.imprint(card.getId(), game);

        if (eyeOfTheStorm.getImprinted() != null && eyeOfTheStorm.getImprinted().size() > 0) {
          CardsImpl copiedCards = new CardsImpl();
          for (UUID uuid : eyeOfTheStorm.getImprinted()) {
            card = game.getCard(uuid);

            // Check if owner of card is still in game
            if (card != null && game.getPlayer(card.getOwnerId()) != null) {
              if (card.isSplitCard()) {
                copiedCards.add(((SplitCard) card).getLeftHalfCard());
                copiedCards.add(((SplitCard) card).getRightHalfCard());
              } else {
                copiedCards.add(card);
              }
            }
          }

          boolean continueCasting = true;
          while (continueCasting) {
            continueCasting =
                copiedCards.size() > 1
                    && spellController.chooseUse(
                        outcome,
                        "Cast one of the copied cards without paying its mana cost?",
                        source,
                        game);

            Card cardToCopy;
            if (copiedCards.size() == 1) {
              cardToCopy = copiedCards.getCards(game).iterator().next();
            } else {
              TargetCard target = new TargetCard(1, Zone.EXILED, new FilterCard("card to copy"));
              spellController.choose(Outcome.Copy, copiedCards, target, game);
              cardToCopy = copiedCards.get(target.getFirstTarget(), game);
              copiedCards.remove(cardToCopy);
            }
            if (cardToCopy != null) {
              Card copy = game.copyCard(cardToCopy, source, source.getControllerId());
              if (spellController.chooseUse(
                  outcome, "Cast the copied card without paying mana cost?", source, game)) {
                spellController.cast(copy.getSpellAbility(), game, true);
              }
            }
          }
          return true;
        }
      }
    }
    return false;
  }
Ejemplo n.º 4
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;
  }