Example #1
0
  @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;
  }
Example #2
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;
 }
Example #3
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player you = game.getPlayer(source.getControllerId());
   if (you == null) {
     return false;
   }
   Permanent arsenalThresher = game.getPermanent(source.getSourceId());
   FilterArtifactCard filter = new FilterArtifactCard();
   filter.add(new AnotherPredicate());
   if (you.chooseUse(
       Outcome.Benefit, "Do you want to reveal other artifacts in your hand?", game)) {
     Cards cards = new CardsImpl();
     if (you.getHand().count(filter, game) > 0) {
       TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
       if (you.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
         for (UUID uuid : target.getTargets()) {
           cards.add(you.getHand().get(uuid, game));
         }
         you.revealCards("Revealed cards", cards, game);
         if (arsenalThresher != null) {
           arsenalThresher.addCounters(CounterType.P1P1.createInstance(cards.size()), game);
           return true;
         }
       }
     }
   }
   return false;
 }
Example #4
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;
 }
 @Override
 public boolean apply(Game game, Ability source) {
   UUID exileId = CardUtil.getCardExileZoneId(game, source);
   for (UUID opponentId : game.getOpponents(source.getControllerId())) {
     Player opponent = game.getPlayer(opponentId);
     if (opponent != null) {
       Cards cards = new CardsImpl();
       cards.addAll(opponent.getHand());
       for (UUID cardId : cards) {
         Card card = game.getCard(cardId);
         if (card != null) {
           card.moveToExile(exileId, "Ashiok, Nightmare Weaver", source.getSourceId(), game);
         }
       }
       cards.clear();
       cards.addAll(opponent.getGraveyard());
       for (UUID cardId : cards) {
         Card card = game.getCard(cardId);
         if (card != null) {
           card.moveToExile(exileId, "Ashiok, Nightmare Weaver", source.getSourceId(), game);
         }
       }
     }
   }
   return true;
 }
Example #6
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;
 }
Example #7
0
 @Override
 public boolean chooseTarget(
     Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
   if (cards.isEmpty()) return !target.isRequired();
   Card card = cards.getRandom(game);
   target.addTarget(card.getId(), source, game);
   return true;
 }
Example #8
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;
  }
Example #9
0
  /**
   * Checks all available splice effects to be applied.
   *
   * @param abilityToModify
   * @param game
   */
  public void applySpliceEffects(Ability abilityToModify, Game game) {
    if (((SpellAbility) abilityToModify).getSpellAbilityType().equals(SpellAbilityType.SPLICE)) {
      // on a spliced ability of a spell can't be spliced again
      return;
    }
    List<SpliceCardEffect> spliceEffects =
        getApplicableSpliceCardEffects(game, abilityToModify.getControllerId());
    // get the applyable splice abilities
    List<SpliceOntoArcaneAbility> spliceAbilities = new ArrayList<>();
    for (SpliceCardEffect effect : spliceEffects) {
      HashSet<Ability> abilities = spliceCardEffects.getAbility(effect.getId());
      for (Ability ability : abilities) {
        if (effect.applies(abilityToModify, ability, game)) {
          spliceAbilities.add((SpliceOntoArcaneAbility) ability);
        }
      }
    }
    // check if player wants to use splice

    if (spliceAbilities.size() > 0) {
      Player controller = game.getPlayer(abilityToModify.getControllerId());
      if (controller.chooseUse(Outcome.Benefit, "Splice a card?", game)) {
        Cards cardsToReveal = new CardsImpl();
        do {
          FilterCard filter = new FilterCard("a card to splice");
          ArrayList<Predicate<MageObject>> idPredicates = new ArrayList<>();
          for (SpliceOntoArcaneAbility ability : spliceAbilities) {
            idPredicates.add(new CardIdPredicate((ability.getSourceId())));
          }
          filter.add(Predicates.or(idPredicates));
          TargetCardInHand target = new TargetCardInHand(filter);
          controller.chooseTarget(Outcome.Benefit, target, abilityToModify, game);
          UUID cardId = target.getFirstTarget();
          if (cardId != null) {
            SpliceOntoArcaneAbility selectedAbility = null;
            for (SpliceOntoArcaneAbility ability : spliceAbilities) {
              if (ability.getSourceId().equals(cardId)) {
                selectedAbility = ability;
                break;
              }
            }
            if (selectedAbility != null) {
              SpliceCardEffect spliceEffect =
                  (SpliceCardEffect) selectedAbility.getEffects().get(0);
              spliceEffect.apply(game, selectedAbility, abilityToModify);
              cardsToReveal.add(game.getCard(cardId));
              spliceAbilities.remove(selectedAbility);
            }
          }
        } while (!spliceAbilities.isEmpty()
            && controller.chooseUse(Outcome.Benefit, "Splice another card?", game));
        controller.revealCards("Spliced cards", cardsToReveal, game);
      }
    }
  }
Example #10
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;
 }
Example #11
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player targetPlayer = game.getPlayer(source.getFirstTarget());
   if (targetPlayer != null && targetPlayer.getHand().size() > 0) {
     Cards revealed = new CardsImpl();
     Card card = targetPlayer.getHand().getRandom(game);
     revealed.add(card);
     targetPlayer.revealCards("Singe-Mind Ogre", revealed, game);
     targetPlayer.loseLife(card.getManaCost().convertedManaCost(), game);
     return true;
   }
   return false;
 }
  @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;
    }

    int highCMC = 0;
    List<Permanent> controlledArtifacts =
        game.getBattlefield()
            .getAllActivePermanents(new FilterArtifactPermanent(), controller.getId(), game);
    for (Permanent permanent : controlledArtifacts) {
      if (permanent.getSpellAbility() != null) {
        int cmc = permanent.getSpellAbility().getManaCosts().convertedManaCost();
        if (cmc > highCMC) {
          highCMC = cmc;
        }
      }
    }

    Cards cards = new CardsImpl();

    for (int i = 0; i < highCMC; i++) {
      Card card = controller.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
      }
    }
    controller.lookAtCards(sourcePermanent.getIdName(), cards, game);

    if (!cards.isEmpty()) {
      TargetCard target =
          new TargetCard(
              Zone.LIBRARY, new FilterArtifactCard("artifact card to put onto the battlefield"));
      if (target.canChoose(source.getSourceId(), controller.getId(), game)
          && controller.choose(Outcome.Benefit, cards, target, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        if (card != null) {
          controller.revealCards(sourcePermanent.getIdName(), new CardsImpl(card), game);
          cards.remove(card);
          controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
      }
    }

    controller.putCardsOnBottomOfLibrary(cards, game, source, true);
    return true;
  }
Example #13
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;
 }
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
      if (controller.chooseUse(Outcome.Benefit, choiceText, source, game)) {
        Set<Card> sideboard = controller.getSideboard().getCards(filter, game);
        List<Card> exile = game.getExile().getAllCards(game);
        Cards filteredCards = new CardsImpl();
        Card card = null;

        for (Card sideboardCard : sideboard) {
          filteredCards.add(sideboardCard.getId());
        }
        for (Card exileCard : exile) {
          if (exileCard.getOwnerId().equals(source.getControllerId())
              && exileCard.hasSubtype("Eldrazi")) {
            filteredCards.add(exileCard);
          }
        }

        if (filteredCards.isEmpty()) {
          game.informPlayer(
              controller,
              "You have no "
                  + filter.getMessage()
                  + " outside the game (your sideboard) or in exile.");
        } else {
          TargetCard target = new TargetCard(Zone.OUTSIDE, filter);
          target.setNotTarget(true);
          if (controller.choose(outcome, filteredCards, target, game)) {
            card = controller.getSideboard().get(target.getFirstTarget(), game);
            if (card == null) {
              card = game.getCard(target.getFirstTarget());
            }
          }
        }

        if (card != null) {
          card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
          controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
        }
      }
      return true;
    }
    return false;
  }
Example #15
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     List<Permanent> tokenPermanents =
         (List<Permanent>) game.getState().getValue(source.getSourceId() + "_token");
     if (tokenPermanents != null) {
       Cards cards = new CardsImpl();
       for (Permanent permanent : tokenPermanents) {
         cards.add(permanent);
       }
       controller.moveCards(cards, null, Zone.EXILED, source, game);
       return true;
     }
   }
   return false;
 }
Example #16
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null) {
     Cards cards = player.getGraveyard();
     for (int i = 0; i < 2 && !cards.isEmpty(); i++) {
       Card card = cards.getRandom(game);
       if (card != null) {
         card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
         cards.remove(card);
         game.informPlayers(card.getName() + " returned to the hand of " + player.getLogName());
       }
     }
     return true;
   }
   return false;
 }
Example #17
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null) {
     boolean revealed =
         player
             .isTopCardRevealed(); // by looking at the cards with scry you have not to reveal the
                                   // next card
     player.setTopCardRevealed(false);
     Cards cards = new CardsImpl();
     int count = Math.min(scryNumber, player.getLibrary().size());
     if (count == 0) {
       return true;
     }
     for (int i = 0; i < count; i++) {
       Card card = player.getLibrary().removeFromTop(game);
       cards.add(card);
     }
     TargetCard target1 = new TargetCard(Zone.LIBRARY, filter1);
     target1.setRequired(false);
     // move cards to the bottom of the library
     while (player.isInGame()
         && cards.size() > 0
         && player.choose(Outcome.Detriment, cards, target1, game)) {
       Card card = cards.get(target1.getFirstTarget(), game);
       if (card != null) {
         cards.remove(card);
         player.moveCardToLibraryWithInfo(
             card, source.getSourceId(), game, Zone.LIBRARY, false, false);
       }
       target1.clearChosen();
     }
     // move cards to the top of the library
     player.putCardsOnTopOfLibrary(cards, game, source, true);
     game.fireEvent(
         new GameEvent(
             GameEvent.EventType.SCRY,
             source.getControllerId(),
             source.getSourceId(),
             source.getControllerId()));
     player.setTopCardRevealed(revealed);
     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;
 }
Example #19
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getFirstTarget());
   if (player != null && player.getLibrary().size() > 0) {
     Card card = player.getLibrary().getFromTop(game);
     Cards cards = new CardsImpl();
     cards.add(card);
     player.revealCards("Cerebral Eruption", cards, game);
     game.getState().setValue(source.getId().toString(), card);
     int damage = card.getManaCost().convertedManaCost();
     player.damage(damage, source.getId(), game, false, true);
     for (Permanent perm :
         game.getBattlefield().getAllActivePermanents(filter, player.getId(), game)) {
       perm.damage(damage, source.getId(), game, true, false);
     }
     return true;
   }
   return false;
 }
Example #20
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    if (player.getLibrary().size() > 0) {
      Card card = player.getLibrary().getFromTop(game);
      Cards cards = new CardsImpl();
      cards.add(card);
      player.revealCards("Pain Seer", cards, game);

      if (card != null && card.moveToZone(Zone.HAND, source.getSourceId(), game, false)) {
        player.loseLife(card.getManaCost().convertedManaCost(), game);
        return true;
      }
    }
    return false;
  }
Example #21
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) {
      return false;
    }

    Card card = controller.getLibrary().getFromTop(game);
    if (card != null) {
      Cards cards = new CardsImpl();
      cards.add(card);
      controller.lookAtCards("top card of library - " + controller.getName(), cards, game);
      game.informPlayers(controller.getLogName() + " looks at the top card of his or her library");
    } else {
      return false;
    }

    return true;
  }
Example #22
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller == null) {
     return false;
   }
   Cards cards = new CardsImpl(Zone.LIBRARY);
   cards.addAll(controller.getLibrary().getTopCards(game, 7));
   if (!cards.isEmpty()) {
     TargetCard target =
         new TargetCard(
             Zone.LIBRARY, new FilterCreatureCard("creature card to put on the battlefield"));
     if (controller.choose(Outcome.PutCreatureInPlay, cards, target, game)) {
       Card card = cards.get(target.getFirstTarget(), game);
       if (card != null) {
         cards.remove(card);
         controller.putOntoBattlefieldWithInfo(card, game, Zone.LIBRARY, source.getSourceId());
       }
     }
     if (cards.size() > 0) {
       controller.putCardsOnBottomOfLibrary(cards, game, source, true);
     }
   }
   return true;
 }
Example #23
0
  @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;
  }
Example #24
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (player == null || controller == null) {
      return false;
    }

    Cards cards = new CardsImpl();
    cards.addAll(player.getLibrary().getTopCards(game, 7));
    controller.moveCards(cards, Zone.EXILED, source, game);
    if (cards.getCards(new FilterCreatureCard(), game).size() > 0) {
      TargetCard target = new TargetCard(Zone.EXILED, new FilterCreatureCard());
      if (controller.chooseTarget(outcome, cards, target, source, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        if (card != null) {
          controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, false, null);
        }
      }
    }
    return true;
  }
Example #25
0
 @Override
 public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
   if (cards.isEmpty()) return !target.isRequired();
   Set<UUID> possibleTargets = target.possibleTargets(playerId, cards, game);
   if (possibleTargets.isEmpty()) return !target.isRequired();
   Iterator<UUID> it = possibleTargets.iterator();
   int targetNum = rnd.nextInt(possibleTargets.size());
   UUID targetId = it.next();
   for (int i = 0; i < targetNum; i++) {
     targetId = it.next();
   }
   target.add(targetId, game);
   return true;
 }
Example #26
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(targetPointer.getFirst(game, source));
   if (player != null) {
     int foundCreatures = 0;
     Cards cards = new CardsImpl();
     for (Card card : player.getLibrary().getTopCards(game, 4)) {
       cards.add(card);
       if (card.getCardType().contains(CardType.CREATURE)) {
         ++foundCreatures;
       }
     }
     player.moveCards(cards, Zone.GRAVEYARD, source, game);
     if (foundCreatures > 0) {
       Player controller = game.getPlayer(source.getControllerId());
       if (controller != null) {
         controller.drawCards(foundCreatures, game);
       }
     }
     return true;
   }
   return false;
 }
Example #27
0
  @Override
  public boolean apply(Game game, Ability source) {
    Cards cardsToCast = new CardsImpl();
    Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (targetOpponent != null && sourceObject != null) {
      List<Card> allCards = targetOpponent.getLibrary().getTopCards(game, 7);
      Cards cards = new CardsImpl(Zone.LIBRARY, allCards);
      targetOpponent.revealCards(
          sourceObject.getIdName() + " - " + targetOpponent.getName() + "'s top library cards",
          cards,
          game);
      for (Card card : allCards) {
        if (filter.match(card, game)) {
          cardsToCast.add(card);
        }
      }
      // cast an instant or sorcery for free
      if (cardsToCast.size() > 0) {
        int numberOfSpells = 1;
        if (SpellMasteryCondition.getInstance().apply(game, source)) {
          numberOfSpells++;
        }
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {

          TargetCard target = new TargetCard(Zone.LIBRARY, filter); // zone should be ignored here
          target.setNotTarget(true);
          while (numberOfSpells > 0
              && cardsToCast.size() > 0
              && controller.chooseUse(
                  outcome,
                  "Cast an instant or sorcery card from among them for free?",
                  source,
                  game)
              && controller.choose(outcome, cardsToCast, target, game)) {
            Card card = cardsToCast.get(target.getFirstTarget(), game);
            if (card != null) {
              controller.cast(card.getSpellAbility(), game, true);
              numberOfSpells--;
              cardsToCast.remove(card);
              allCards.remove(card);
            }
            if (!controller.isInGame()) {
              return false;
            }
            target.clearChosen();
          }
        }

        targetOpponent.moveCards(allCards, Zone.LIBRARY, Zone.GRAVEYARD, source, game);
      }
      return true;
    }
    return false;
  }
Example #28
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) {
     return false;
   }
   Permanent faceDownCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
   if (faceDownCreature != null) {
     Permanent copyFaceDown = faceDownCreature.copy();
     copyFaceDown.setFaceDown(false, game);
     Cards cards = new CardsImpl();
     cards.add(copyFaceDown);
     Player player = game.getPlayer(faceDownCreature.getControllerId());
     controller.lookAtCards("face down card - " + mageObject.getName(), cards, game);
     if (player != null) {
       game.informPlayers(
           controller.getLogName() + " looks at a face down creature of " + player.getLogName());
     }
   } else {
     return false;
   }
   return true;
 }
Example #29
0
  @Override
  public boolean apply(Game game, Ability source) {
    boolean isMountain = false;
    Card sourceCard = game.getCard(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());

    if (player == null || sourceCard == null) {
      return false;
    }
    Cards cards = new CardsImpl(Zone.PICK);
    while (player.getLibrary().size() > 0) {
      Card card = player.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
        if (card.getCardType().contains(CardType.LAND)) {
          if (card.getSubtype().contains("Mountain")) {
            isMountain = true;
          }
          break;
        }
      } else {
        break;
      }
    }
    player.revealCards(sourceCard.getName(), cards, game);
    int damage = cards.size();
    if (isMountain == true) {
      damage *= 2;
    }

    Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
    if (permanent != null) {
      permanent.damage(damage, source.getSourceId(), game, true, false);
    } else {
      Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
      if (targetPlayer != null) {
        targetPlayer.damage(damage, source.getSourceId(), game, false, true);
      }
    }

    TargetCard target =
        new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library"));
    target.setRequired(true);
    while (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.PICK, source.getId(), game, false);
      }
      target.clearChosen();
    }

    return true;
  }
Example #30
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;
  }