Exemplo n.º 1
0
 @Override
 public boolean apply(Game game, Ability source) {
   boolean result = false;
   Player graveyardPlayer = null;
   for (UUID cardInGraveyard : targetPointer.getTargets(game, source)) {
     Card card = game.getCard(cardInGraveyard);
     if (card != null) {
       for (Player player : game.getPlayers().values()) {
         if (player.getGraveyard().contains(card.getId())) {
           graveyardPlayer = player;
           player.getGraveyard().remove(card);
           result |= card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
         }
       }
     }
   }
   Card card = game.getCard(source.getSourceId());
   result |= card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
   Player player = game.getPlayer(card.getOwnerId());
   if (player != null) {
     player.shuffleLibrary(game);
   }
   if (graveyardPlayer != null && !graveyardPlayer.equals(player)) {
     graveyardPlayer.shuffleLibrary(game);
   }
   return result;
 }
Exemplo n.º 2
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject mageObject = game.getObject(source.getSourceId());
   if (controller != null && mageObject != null) {
     Choice typeChoice = new ChoiceImpl(true);
     typeChoice.setMessage("Choose creature type");
     typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
     while (!controller.choose(outcome, typeChoice, game)) {
       if (!controller.canRespond()) {
         return false;
       }
     }
     if (!game.isSimulation()) {
       game.informPlayers(
           mageObject.getName()
               + ": "
               + controller.getLogName()
               + " has chosen "
               + typeChoice.getChoice());
     }
     Cards cardsToLibrary = new CardsImpl();
     FilterCreatureCard filter = new FilterCreatureCard();
     filter.add(new SubtypePredicate(typeChoice.getChoice()));
     cardsToLibrary.addAll(
         controller
             .getGraveyard()
             .getCards(filter, source.getSourceId(), source.getControllerId(), game));
     controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false);
     controller.shuffleLibrary(game);
     return true;
   }
   return false;
 }
Exemplo n.º 3
0
 @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;
 }
Exemplo n.º 4
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject sourceObject = source.getSourceObject(game);
   if (controller != null && sourceObject != null) {
     controller.shuffleLibrary(source, game);
     if (controller.getLibrary().size() > 0) {
       Card card = controller.getLibrary().removeFromTop(game);
       if (card != null) {
         controller.moveCardToExileWithInfo(
             card,
             source.getSourceId(),
             sourceObject.getIdName(),
             source.getSourceId(),
             game,
             Zone.LIBRARY,
             true);
         ContinuousEffect effect = new MindsDesireCastFromExileEffect();
         effect.setTargetPointer(new FixedTarget(card.getId()));
         game.addEffect(effect, source);
       }
     }
     return true;
   }
   return false;
 }
Exemplo n.º 5
0
 @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;
 }
Exemplo n.º 6
0
  @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;
    }
    for (UUID playerId : controller.getInRange()) {
      Player player = game.getPlayer(playerId);
      String playerName = new StringBuilder(player.getLogName()).append("'s").toString();
      if (source.getControllerId().equals(player.getId())) {
        playerName = "your";
      }
      TargetCardInLibrary target =
          new TargetCardInLibrary(
              new FilterNonlandCard(
                  new StringBuilder("nonland card from ")
                      .append(playerName)
                      .append(" library")
                      .toString()));
      if (controller.searchLibrary(target, game, playerId)) {
        UUID targetId = target.getFirstTarget();
        Card card = player.getLibrary().remove(targetId, game);
        if (card != null) {
          controller.moveCardToExileWithInfo(
              card,
              CardUtil.getCardExileZoneId(game, source),
              sourcePermanent.getIdName(),
              source.getSourceId(),
              game,
              Zone.LIBRARY,
              true);
        }
      }
      player.shuffleLibrary(game);
    }

    ExileZone jaceExileZone =
        game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
    if (jaceExileZone == null) {
      return true;
    }
    FilterCard filter = new FilterCard("card to cast without mana costs");
    TargetCardInExile target = new TargetCardInExile(filter, source.getSourceId());
    while (jaceExileZone.count(filter, game) > 0
        && controller.choose(Outcome.PlayForFree, jaceExileZone, target, game)) {
      Card card = game.getCard(target.getFirstTarget());
      if (card != null) {
        if (controller.cast(card.getSpellAbility(), game, true)) {
          game.getExile().removeCard(card, game);
        }
      }
      target.clearChosen();
    }
    return true;
  }
Exemplo n.º 7
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    TargetCardInLibrary target = new TargetCardInLibrary();
    if (player.searchLibrary(target, game)) {
      Card card = player.getLibrary().remove(target.getFirstTarget(), game);
      if (card != null) {
        card.moveToZone(Zone.EXILED, source.getSourceId(), game, false);
        player.shuffleLibrary(game);

        StringBuilder sb = new StringBuilder();
        sb.append("Have ").append(player.getLogName()).append(" put ").append(card.getName());
        sb.append(" in his hand? If none of his opponents says yes, he'll draw three cards.");

        boolean putInHand = false;
        Set<UUID> opponents = game.getOpponents(source.getControllerId());
        for (UUID opponentUuid : opponents) {
          Player opponent = game.getPlayer(opponentUuid);
          if (opponent != null
              && !putInHand
              && opponent.chooseUse(Outcome.Neutral, sb.toString(), source, game)) {
            putInHand = true;
          }
        }

        if (putInHand) {
          game.getExile().getPermanentExile().remove(card);
          card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
        } else {
          player.drawCards(3, game);
        }
        return true;
      }
    }
    player.shuffleLibrary(game);
    return false;
  }
Exemplo n.º 8
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     Cards cards = new CardsImpl();
     cards.addAll(controller.getGraveyard().getCards(new FilterCreatureCard(), game));
     controller.putCardsOnTopOfLibrary(cards, game, source, false);
     controller.shuffleLibrary(source, game);
     return true;
   }
   return false;
 }
Exemplo n.º 9
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     if (controller.searchLibrary(target, game)) {
       controller.moveCards(new CardsImpl(target.getTargets()), Zone.GRAVEYARD, source, game);
     }
     controller.shuffleLibrary(source, game);
     return true;
   }
   return false;
 }
Exemplo n.º 10
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getFirstTarget());
   if (player != null) {
     for (Card card : player.getGraveyard().getCards(game)) {
       player.moveCardToLibraryWithInfo(
           card, source.getSourceId(), game, Zone.GRAVEYARD, true, true);
     }
     player.shuffleLibrary(source, game);
     return true;
   }
   return false;
 }
Exemplo n.º 11
0
 @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 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;
 }
Exemplo n.º 13
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player sourcePlayer = game.getPlayer(source.getControllerId());
   for (UUID playerId : sourcePlayer.getInRange()) {
     Player player = game.getPlayer(playerId);
     if (player != null) {
       player.getLibrary().addAll(player.getHand().getCards(game), game);
       player.getLibrary().addAll(player.getGraveyard().getCards(game), game);
       player.shuffleLibrary(game);
       player.getHand().clear();
       player.getGraveyard().clear();
       player.drawCards(7, game);
     }
   }
   return true;
 }
Exemplo n.º 14
0
 @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;
 }
Exemplo n.º 15
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null) {
     Cards cardsPicked = this.ProteanHulkSearch(game, source);
     for (UUID cardId : cardsPicked) {
       Card card = game.getCard(cardId);
       if (card != null) {
         player.putOntoBattlefieldWithInfo(card, game, Zone.PICK, source.getSourceId());
       }
     }
     player.shuffleLibrary(game);
     return true;
   }
   return false;
 }
Exemplo n.º 16
0
 @Override
 public void endMulligan(UUID playerId) {
   // return cards to
   Player player = getPlayer(playerId);
   if (player != null && mulliganedCards.containsKey(playerId)) {
     for (Card card : mulliganedCards.get(playerId).getCards(this)) {
       if (card != null) {
         getExile().removeCard(card, this);
         player.getLibrary().putOnTop(card, this);
         getState().setZone(card.getId(), Zone.LIBRARY);
         card.setFaceDown(false, this);
       }
     }
     if (mulliganedCards.get(playerId).size() > 0) {
       player.shuffleLibrary(this);
     }
   }
 }
Exemplo n.º 17
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player you = game.getPlayer(source.getControllerId());
   if (you != null) {
     if (you.getLibrary().size() > 0) {
       TargetCardInLibrary target = new TargetCardInLibrary(filter);
       if (you.searchLibrary(target, game, you.getId())) {
         UUID targetId = target.getFirstTarget();
         Card card = you.getLibrary().remove(targetId, game);
         if (card != null) {
           you.cast(card.getSpellAbility(), game, true);
         }
       }
     }
     you.shuffleLibrary(game);
     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;
 }
Exemplo n.º 19
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
       Player player = game.getPlayer(playerId);
       if (player != null) {
         for (Card card : player.getHand().getCards(game)) {
           card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
         }
         for (Card card : player.getGraveyard().getCards(game)) {
           card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
         }
         player.shuffleLibrary(source, game);
       }
     }
     controller.drawCards(7, game);
     return true;
   }
   return false;
 }
Exemplo n.º 20
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    int amount = new GetXValue().calculate(game, source, this);

    if (controller != null && sourceObject != null) {
      TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard());
      if (controller.searchLibrary(target, game)) {
        Cards chosen = new CardsImpl();
        for (UUID cardId : (List<UUID>) target.getTargets()) {
          Card card = controller.getLibrary().remove(cardId, game);
          chosen.add(card);
        }
        controller.shuffleLibrary(source, game);

        TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop));

        while (chosen.size() > 1 && controller.canRespond()) {
          controller.choose(Outcome.Neutral, chosen, targetToLib, game);
          Card card = chosen.get(targetToLib.getFirstTarget(), game);
          if (card != null) {
            chosen.remove(card);
            controller.moveCardToLibraryWithInfo(
                card, source.getSourceId(), game, Zone.LIBRARY, true, false);
          }
          targetToLib.clearChosen();
        }

        if (chosen.size() == 1) {
          Card card = chosen.get(chosen.iterator().next(), game);
          controller.moveCardToLibraryWithInfo(
              card, source.getSourceId(), game, Zone.LIBRARY, true, false);
        }
      }
      return true;
    }
    return false;
  }
Exemplo n.º 21
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (player != null && controller != null) {
      Choice cardChoice = new ChoiceImpl();
      cardChoice.setChoices(CardRepository.instance.getNonLandNames());
      cardChoice.clearChoice();

      while (!controller.choose(Outcome.Exile, cardChoice, game)) {
        game.debugMessage("player canceled choosing name. retrying.");
      }

      String cardName = cardChoice.getChoice();
      game.informPlayers("CranialExtraction, named card: [" + cardName + "]");
      for (Card card : player.getGraveyard().getCards(game)) {
        if (card.getName().equals(cardName)) {
          card.moveToExile(null, "", source.getId(), game);
        }
      }
      for (Card card : player.getHand().getCards(game)) {
        if (card.getName().equals(cardName)) {
          card.moveToExile(null, "", source.getId(), game);
        }
      }
      for (Card card : player.getLibrary().getCards(game)) {
        if (card.getName().equals(cardName)) {
          card.moveToExile(null, "", source.getId(), game);
        }
      }
      controller.lookAtCards("CranialExtraction Hand", player.getHand(), game);
      controller.lookAtCards(
          "CranialExtraction Library",
          new CardsImpl(Zone.PICK, player.getLibrary().getCards(game)),
          game);
      player.shuffleLibrary(game);
    }
    return true;
  }
Exemplo n.º 22
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getFirstTarget());
   if (player != null) {
     List<UUID> targets = source.getTargets().get(1).getTargets();
     boolean shuffle = false;
     for (UUID targetId : targets) {
       Card card = game.getCard(targetId);
       if (card != null) {
         if (player.getGraveyard().contains(card.getId())) {
           player.getGraveyard().remove(card);
           card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
           shuffle = true;
         }
       }
     }
     if (shuffle) {
       player.shuffleLibrary(source, game);
     }
     return true;
   }
   return false;
 }
Exemplo n.º 23
0
 @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;
 }
Exemplo n.º 24
0
 @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;
 }
Exemplo n.º 25
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;
  }
  public boolean applySearchAndExile(
      Game game, Ability source, String cardName, UUID targetPlayerId) {
    Player player = game.getPlayer(source.getControllerId());
    if (cardName != null && player != null) {
      Player targetPlayer = game.getPlayer(targetPlayerId);
      if (targetPlayer != null) {
        FilterCard filter = new FilterCard("card named " + cardName);
        filter.add(new NamePredicate(cardName));

        // cards in Graveyard
        int cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getGraveyard().count(filter, game));
        if (cardsCount > 0) {
          filter.setMessage(
              "card named " + cardName + " in the graveyard of " + targetPlayer.getName());
          TargetCardInGraveyard target =
              new TargetCardInGraveyard(
                  (graveyardExileOptional ? 0 : cardsCount), cardsCount, filter);
          if (player.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
              Card targetCard = targetPlayer.getGraveyard().get(targetId, game);
              if (targetCard != null) {
                targetPlayer.getGraveyard().remove(targetCard);
                targetCard.moveToZone(Zone.EXILED, source.getId(), game, false);
              }
            }
          }
        }

        // cards in Hand
        cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getHand().count(filter, game));
        if (cardsCount > 0) {
          filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
          TargetCardInHand target = new TargetCardInHand(0, cardsCount, filter);
          if (player.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
              Card targetCard = targetPlayer.getHand().get(targetId, game);
              if (targetCard != null) {
                targetPlayer.getHand().remove(targetCard);
                targetCard.moveToZone(Zone.EXILED, source.getId(), game, false);
              }
            }
          }
        } else {
          if (targetPlayer.getHand().size() > 0) {
            player.lookAtCards(targetPlayer.getName() + " hand", targetPlayer.getHand(), game);
          }
        }

        // cards in Library
        Cards cardsInLibrary = new CardsImpl(Zone.LIBRARY);
        cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
        cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
        if (cardsCount > 0) {
          filter.setMessage(
              "card named " + cardName + " in the library of " + targetPlayer.getName());
          TargetCardInLibrary target = new TargetCardInLibrary(0, cardsCount, filter);
          if (player.choose(Outcome.Exile, cardsInLibrary, target, game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
              Card targetCard = targetPlayer.getLibrary().remove(targetId, game);
              if (targetCard != null) {
                targetCard.moveToZone(Zone.EXILED, source.getId(), game, false);
              }
            }
          }
        } else {
          player.lookAtCards(targetPlayer.getName() + " library", cardsInLibrary, game);
        }
      }

      targetPlayer.shuffleLibrary(game);

      return true;
    }

    return false;
  }
Exemplo n.º 27
0
  @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;
  }