コード例 #1
0
ファイル: ShapeAnew.java プロジェクト: bradens/mage
 @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;
 }
コード例 #2
0
ファイル: ExplorersScope.java プロジェクト: petrich0r/mage
  @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;
  }
コード例 #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;
 }
コード例 #4
0
ファイル: RiptideShapeshifter.java プロジェクト: Blinke/mage
 @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;
 }
コード例 #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) {
      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;
  }
コード例 #6
0
ファイル: ProteanHulk.java プロジェクト: jjmarcel/mage-1
  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;
  }
コード例 #7
0
ファイル: HeroesPodium.java プロジェクト: TumbleMagnet/mage
  @Override
  public boolean apply(Game game, Ability source) {

    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Cards cards = new CardsImpl(Zone.PICK);
    int count = source.getManaCostsToPay().getX();
    count = Math.min(player.getLibrary().size(), count);
    boolean legendaryIncluded = false;
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
        if (filter.match(card, game)) {
          legendaryIncluded = true;
        }
        game.setZone(card.getId(), Zone.PICK);
      }
    }
    player.lookAtCards("Heroes' Podium", cards, game);

    // You may reveal a legendary creature card from among them and put it into your hand.
    if (!cards.isEmpty()
        && legendaryIncluded
        && player.chooseUse(
            outcome, "Put a legendary creature card into your hand?", source, game)) {
      if (cards.size() == 1) {
        Card card = cards.getRandom(game);
        cards.remove(card);
        card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
        return true;
      } else {
        TargetCard target = new TargetCard(Zone.PICK, filter);
        if (player.choose(outcome, cards, target, game)) {
          Card card = cards.get(target.getFirstTarget(), game);
          if (card != null) {
            cards.remove(card);
            card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
          }
        }
      }
    }

    // Put the rest on the bottom of your library in a random order
    while (cards.size() > 0) {
      Card card = cards.getRandom(game);
      if (card != null) {
        cards.remove(card);
        card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
      }
    }
    return true;
  }
コード例 #8
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;
  }
コード例 #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);
      }
    }
  }
コード例 #10
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;
  }
コード例 #11
0
ファイル: SingeMindOgre.java プロジェクト: Nick456/mage
 @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;
 }
コード例 #12
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;
    }

    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;
  }
コード例 #13
0
ファイル: Progenitus.java プロジェクト: Nick456/mage
 @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;
 }
コード例 #14
0
ファイル: CloneShell.java プロジェクト: JuanSabino/mage
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Cards cards = new CardsImpl(Zone.PICK);
    int count = Math.min(player.getLibrary().size(), 4);
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      cards.add(card);
      game.setZone(card.getId(), Zone.PICK);
    }

    if (cards.size() == 0) {
      return false;
    }
    TargetCard target1 = new TargetCard(Zone.PICK, filter1);
    if (player.choose(Outcome.Detriment, cards, target1, game)) {
      Card card = cards.get(target1.getFirstTarget(), game);
      if (card != null) {
        cards.remove(card);
        card.moveToExile(getId(), "Clone Shell (Imprint)", source.getSourceId(), game);
        card.setFaceDown(true, game);
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null) {
          permanent.imprint(card.getId(), game);
        }
      }
      target1.clearChosen();
    }

    if (cards.size() > 0) {
      TargetCard target2 = new TargetCard(Zone.PICK, filter2);
      while (player.canRespond() && cards.size() > 1) {
        player.choose(Outcome.Benefit, cards, target2, game);
        Card card = cards.get(target2.getFirstTarget(), game);
        if (card != null) {
          cards.remove(card);
          card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
        }
        target2.clearChosen();
      }
      Card card = cards.get(cards.iterator().next(), game);
      card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
    }

    return true;
  }
コード例 #15
0
ファイル: DanceOfMany.java プロジェクト: BijanT/mage
 @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;
 }
コード例 #16
0
ファイル: ScryEffect.java プロジェクト: TumbleMagnet/mage
 @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;
 }
コード例 #17
0
 @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;
 }
コード例 #18
0
ファイル: CerebralEruption.java プロジェクト: Nick456/mage
 @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;
 }
コード例 #19
0
ファイル: PainSeer.java プロジェクト: joshhazel/mage
  @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;
  }
コード例 #20
0
ファイル: LensOfClarity.java プロジェクト: poixen/mage
  @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;
  }
コード例 #21
0
ファイル: IntoTheWilds.java プロジェクト: kholdfuzion/mage
  @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;
  }
コード例 #22
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;
  }
コード例 #23
0
ファイル: CoercedConfession.java プロジェクト: royk/mage
 @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;
 }
コード例 #24
0
ファイル: KodamasReach.java プロジェクト: TumbleMagnet/mage
 @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;
 }
コード例 #25
0
ファイル: LensOfClarity.java プロジェクト: poixen/mage
 @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;
 }
コード例 #26
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     List<Card> cards = new ArrayList<>();
     List<Permanent> permanents = new ArrayList<>();
     for (UUID targetId : targetPointer.getTargets(game, source)) {
       switch (game.getState().getZone(targetId)) {
         case BATTLEFIELD:
           Permanent permanent = game.getPermanent(targetId);
           if (permanent != null) {
             permanents.add(permanent);
           }
           break;
         case GRAVEYARD:
           Card card = game.getCard(targetId);
           if (card != null && game.getState().getZone(targetId).equals(Zone.GRAVEYARD)) {
             cards.add(card);
           }
           break;
       }
     }
     // Plow Under
     // 10/4/2004 	The owner decides the order the two lands are stacked there.
     while (!cards.isEmpty()) {
       Card card = cards.iterator().next();
       if (card != null) {
         Player owner = game.getPlayer(card.getOwnerId());
         Cards cardsPlayer = new CardsImpl();
         for (Iterator<Card> iterator = cards.iterator(); iterator.hasNext(); ) {
           Card next = iterator.next();
           if (next.getOwnerId().equals(owner.getId())) {
             cardsPlayer.add(next);
             iterator.remove();
           }
         }
         if (onTop) {
           owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
         } else {
           owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true);
         }
       }
     }
     while (!permanents.isEmpty()) {
       Permanent permanent = permanents.iterator().next();
       if (permanent != null) {
         Player owner = game.getPlayer(permanent.getOwnerId());
         Cards cardsPlayer = new CardsImpl();
         for (Iterator<Permanent> iterator = permanents.iterator(); iterator.hasNext(); ) {
           Permanent next = iterator.next();
           if (next.getOwnerId().equals(owner.getId())) {
             cardsPlayer.add(next);
             iterator.remove();
           }
         }
         if (onTop) {
           owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
         } else {
           owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true);
         }
       }
     }
     return true;
   }
   return false;
 }
コード例 #27
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    Card sourceCard = game.getCard(source.getSourceId());
    if (player != null && controller != null) {
      if (revealAllCards) {
        this.numberCardsToReveal = new StaticValue(player.getHand().size());
      }
      int numberToReveal = this.numberCardsToReveal.calculate(game, source, this);
      if (numberToReveal > 0) {
        Cards revealedCards = new CardsImpl(Zone.HAND);
        numberToReveal = Math.min(player.getHand().size(), numberToReveal);
        if (player.getHand().size() > numberToReveal) {
          TargetCardInHand chosenCards =
              new TargetCardInHand(
                  numberToReveal,
                  numberToReveal,
                  new FilterCard("card in " + player.getLogName() + "'s hand"));
          chosenCards.setNotTarget(true);
          if (chosenCards.canChoose(player.getId(), game)
              && player.chooseTarget(
                  Outcome.Discard, player.getHand(), chosenCards, source, game)) {
            if (!chosenCards.getTargets().isEmpty()) {
              List<UUID> targets = chosenCards.getTargets();
              for (UUID targetid : targets) {
                Card card = game.getCard(targetid);
                if (card != null) {
                  revealedCards.add(card);
                }
              }
            }
          }
        } else {
          revealedCards.addAll(player.getHand());
        }

        player.revealCards(
            sourceCard != null ? sourceCard.getName() : "Discard", revealedCards, game);

        boolean result = true;
        int filteredCardsCount =
            revealedCards.count(filter, source.getSourceId(), source.getControllerId(), game);
        int numberToDiscard =
            Math.min(this.numberCardsToDiscard.calculate(game, source, this), filteredCardsCount);
        if (numberToDiscard > 0) {
          TargetCard target = new TargetCard(numberToDiscard, Zone.HAND, filter);
          if (controller.choose(Outcome.Benefit, revealedCards, target, game)) {
            for (Object targetId : target.getTargets()) {
              Card card = revealedCards.get((UUID) targetId, game);
              if (card != null) {
                if (!player.discard(card, source, game)) {
                  result = false;
                }
              }
            }
          }
        }
        return result;
      }
      return true;
    }
    return false;
  }
コード例 #28
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Cards cards = new CardsImpl();
    int count = Math.min(player.getLibrary().size(), 3);
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
      }
    }
    player.revealCards("Jace, Architect of Thought", cards, game);

    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    if (!opponents.isEmpty()) {
      Player opponent = null;
      if (opponents.size() > 1) {
        TargetOpponent targetOpponent = new TargetOpponent();
        if (player.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
          opponent = game.getPlayer(targetOpponent.getFirstTarget());
        }
      }
      if (opponent == null) {
        opponent = game.getPlayer(opponents.iterator().next());
      }

      TargetCard target =
          new TargetCard(
              0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
      target.setRequired(false);
      Cards pile1 = new CardsImpl();
      if (opponent.choose(Outcome.Neutral, cards, target, game)) {
        for (UUID targetId : (List<UUID>) target.getTargets()) {
          Card card = cards.get(targetId, game);
          if (card != null) {
            pile1.add(card);
            cards.remove(card);
          }
        }
      }
      player.revealCards("Pile 1 (Jace, Architect of Thought)", pile1, game);
      player.revealCards("Pile 2 (Jace, Architect of Thought)", cards, game);

      postPileToLog("Pile 1", pile1.getCards(game), game);
      postPileToLog("Pile 2", cards.getCards(game), game);

      Cards cardsToHand = cards;
      Cards cardsToLibrary = pile1;
      List<Card> cardPile1 = new ArrayList<>();
      List<Card> cardPile2 = new ArrayList<>();
      for (UUID cardId : pile1) {
        cardPile1.add(game.getCard(cardId));
      }
      for (UUID cardId : cards) {
        cardPile2.add(game.getCard(cardId));
      }

      boolean pileChoice =
          player.choosePile(
              Outcome.Neutral,
              "Choose a pile to to put into your hand.",
              cardPile1,
              cardPile2,
              game);
      if (pileChoice) {
        cardsToHand = pile1;
        cardsToLibrary = cards;
      }
      game.informPlayers(player.getLogName() + " chose pile" + (pileChoice ? "1" : "2"));

      for (UUID cardUuid : cardsToHand) {
        Card card = cardsToHand.get(cardUuid, game);
        if (card != null) {
          player.moveCards(card, null, Zone.HAND, source, game);
        }
      }

      player.putCardsOnBottomOfLibrary(cardsToLibrary, game, source, true);
      return true;
    }
    return false;
  }
コード例 #29
0
ファイル: Conflux.java プロジェクト: poixen/mage
  @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;
  }
コード例 #30
0
ファイル: FactOrFiction.java プロジェクト: xdaft/mage
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Cards cards = new CardsImpl(Zone.PICK);
    int count = Math.min(player.getLibrary().size(), 5);
    for (int i = 0; i < count; i++) {
      Card card = player.getLibrary().removeFromTop(game);
      if (card != null) {
        cards.add(card);
        game.setZone(card.getId(), Zone.PICK);
      }
    }
    player.revealCards("Fact or Fiction", cards, game);

    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    if (!opponents.isEmpty()) {
      Player opponent = game.getPlayer(opponents.iterator().next());
      TargetCard target =
          new TargetCard(
              0, cards.size(), Zone.PICK, new FilterCard("cards to put in the first pile"));

      Cards pile1 = new CardsImpl();
      if (opponent.choose(Outcome.Neutral, cards, target, game)) {
        List<UUID> targets = target.getTargets();
        for (UUID targetId : targets) {
          Card card = cards.get(targetId, game);
          if (card != null) {
            pile1.add(card);
            cards.remove(card);
          }
        }
      }

      player.revealCards("Pile 1 (Fact or Fiction)", pile1, game);
      player.revealCards("Pile 2 (Fact or Fiction)", cards, game);

      Choice choice = new ChoiceImpl(true);
      choice.setMessage("Select a pile of cards to put into your hand:");

      StringBuilder sb = new StringBuilder("Pile 1: ");
      for (UUID cardId : pile1) {
        Card card = pile1.get(cardId, game);
        if (card != null) {
          sb.append(card.getName()).append("; ");
        }
      }
      sb.delete(sb.length() - 2, sb.length());
      choice.getChoices().add(sb.toString());

      sb = new StringBuilder("Pile 2: ");
      for (UUID cardId : cards) {
        Card card = cards.get(cardId, game);
        if (card != null) {
          sb.append(card.getName()).append("; ");
        }
      }
      sb.delete(sb.length() - 2, sb.length());
      choice.getChoices().add(sb.toString());

      Zone pile1Zone = Zone.GRAVEYARD;
      Zone pile2Zone = Zone.HAND;
      if (player.choose(Outcome.Neutral, choice, game)) {
        if (choice.getChoice().startsWith("Pile 1")) {
          pile1Zone = Zone.HAND;
          pile2Zone = Zone.GRAVEYARD;
        }
      }

      for (UUID cardUuid : pile1) {
        Card card = pile1.get(cardUuid, game);
        if (card != null) {
          card.moveToZone(pile1Zone, source.getId(), game, false);
        }
      }
      for (UUID cardUuid : cards) {
        Card card = cards.get(cardUuid, game);
        if (card != null) {
          card.moveToZone(pile2Zone, source.getId(), game, false);
        }
      }
    }

    return true;
  }