@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;
  }
Beispiel #2
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) {
    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;
  }
Beispiel #4
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;
  }
Beispiel #5
0
  Cards ProteanHulkSearch(Game game, Ability source) {
    Cards cardsPicked = new CardsImpl(Zone.PICK);
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
      GameEvent event =
          GameEvent.getEvent(
              GameEvent.EventType.SEARCH_LIBRARY,
              source.getControllerId(),
              source.getControllerId(),
              source.getControllerId(),
              Integer.MAX_VALUE);
      if (!game.replaceEvent(event)) {
        int manaCostLeftToFetch = 6;
        int librarySearchLimit = event.getAmount();

        FilterCard filter =
            new FilterCreatureCard(
                "number of creature cards with total converted mana cost 6 or less (6 CMC left)");
        filter.add(
            new ConvertedManaCostPredicate(ComparisonType.LessThan, manaCostLeftToFetch + 1));
        TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
        target.setCardLimit(librarySearchLimit);

        while (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
          target.choose(
              Outcome.PutCreatureInPlay, source.getControllerId(), source.getControllerId(), game);
          Card card = player.getLibrary().remove(target.getFirstTarget(), game);
          if (card == null) {
            break;
          }
          cardsPicked.add(card);
          game.setZone(card.getId(), Zone.PICK);
          game.getState().getLookedAt(source.getControllerId()).add("Protean Hulk", cardsPicked);

          librarySearchLimit--;
          if (librarySearchLimit == 0) {
            break;
          }
          manaCostLeftToFetch -= card.getManaCost().convertedManaCost();
          filter =
              new FilterCreatureCard(
                  "number of creature cards with total converted mana cost 6 or less ("
                      + manaCostLeftToFetch
                      + " CMC left)");
          filter.add(
              new ConvertedManaCostPredicate(ComparisonType.LessThan, manaCostLeftToFetch + 1));
          target = new TargetCardInLibrary(0, 1, filter);
          target.setCardLimit(librarySearchLimit);
        }
        game.fireEvent(
            GameEvent.getEvent(
                GameEvent.EventType.LIBRARY_SEARCHED,
                source.getControllerId(),
                source.getControllerId()));
      }
    }
    return cardsPicked;
  }
Beispiel #6
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 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;
 }
  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;
  }
Beispiel #9
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;
  }