コード例 #1
0
 @Override
 public boolean apply(Game game, Ability source) {
   boolean result = false;
   Player graveyardPlayer = null;
   for (UUID cardInGraveyard : targetPointer.getTargets(game, source)) {
     Card card = game.getCard(cardInGraveyard);
     if (card != null) {
       for (Player player : game.getPlayers().values()) {
         if (player.getGraveyard().contains(card.getId())) {
           graveyardPlayer = player;
           player.getGraveyard().remove(card);
           result |= card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
         }
       }
     }
   }
   Card card = game.getCard(source.getSourceId());
   result |= card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
   Player player = game.getPlayer(card.getOwnerId());
   if (player != null) {
     player.shuffleLibrary(game);
   }
   if (graveyardPlayer != null && !graveyardPlayer.equals(player)) {
     graveyardPlayer.shuffleLibrary(game);
   }
   return result;
 }
コード例 #2
0
ファイル: CerebralEruption.java プロジェクト: Nick456/mage
 @Override
 public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
   Card revealed = (Card) game.getState().getValue(source.getId().toString());
   if (revealed != null && revealed.getCardType().contains(CardType.LAND)) {
     card.moveToZone(Zone.HAND, source.getId(), game, false);
   } else {
     card.moveToZone(Zone.GRAVEYARD, source.getId(), game, false);
   }
 }
コード例 #3
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;
  }
コード例 #4
0
ファイル: ViewFromAbove.java プロジェクト: xdaft/mage
  @Override
  public void postResolve(Card card, Ability source, UUID controllerId, Game game) {
    FilterPermanent filter = new FilterPermanent("white permanent");
    filter.add(new ColorPredicate(ObjectColor.WHITE));

    if (game.getBattlefield().countAll(filter, source.getControllerId(), game) > 0) {
      card.moveToZone(Zone.HAND, source.getId(), game, false);
    } else {
      card.moveToZone(Zone.GRAVEYARD, source.getId(), game, false);
    }
  }
コード例 #5
0
 @Override
 public boolean apply(Game game, Ability source) {
   ExileZone exile = game.getExile().getExileZone(exileId);
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null && exile != null) {
     if (zone == Zone.GRAVEYARD) {
       controller.moveCards(exile, zone, Zone.EXILED, source, game);
     } else {
       exile = exile.copy();
       for (UUID cardId : exile) {
         Card card = game.getCard(cardId);
         Player owner = game.getPlayer(card.getOwnerId());
         if (owner != null) {
           switch (zone) {
             case BATTLEFIELD:
               card.moveToZone(zone, source.getSourceId(), game, tapped);
               if (!game.isSimulation()) {
                 game.informPlayers(
                     controller.getLogName()
                         + " moves "
                         + card.getLogName()
                         + " to "
                         + zone.toString().toLowerCase());
               }
               break;
             case HAND:
               controller.moveCards(card, Zone.EXILED, Zone.HAND, source, game);
               break;
             case LIBRARY:
               controller.moveCardToLibraryWithInfo(
                   card, source.getSourceId(), game, Zone.EXILED, true, true);
               break;
             case GRAVEYARD:
               controller.moveCards(card, Zone.EXILED, Zone.GRAVEYARD, source, game);
               break;
             default:
               card.moveToZone(zone, source.getSourceId(), game, tapped);
               if (!game.isSimulation()) {
                 game.informPlayers(
                     controller.getLogName()
                         + " moves "
                         + card.getLogName()
                         + " to "
                         + zone.toString().toLowerCase());
               }
           }
         }
       }
       game.getExile().getExileZone(exileId).clear();
     }
     return true;
   }
   return false;
 }
コード例 #6
0
 @Override
 protected void init(UUID choosingPlayerId) {
   Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Commander effects"));
   // Move commander to command zone
   for (UUID playerId : state.getPlayerList(startingPlayerId)) {
     Player player = getPlayer(playerId);
     if (player != null) {
       if (player.getSideboard().size() > 0) {
         Card commander = getCard((UUID) player.getSideboard().toArray()[0]);
         if (commander != null) {
           player.setCommanderId(commander.getId());
           commander.moveToZone(Zone.COMMAND, null, this, true);
           commander.getAbilities().setControllerId(player.getId());
           ability.addEffect(
               new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary));
           ability.addEffect(new CommanderCostModification(commander.getId()));
           ability.addEffect(
               new CommanderManaReplacementEffect(
                   player.getId(), CardUtil.getColorIdentity(commander)));
           getState().setValue(commander.getId() + "_castCount", 0);
           CommanderInfoWatcher watcher =
               new CommanderInfoWatcher(commander.getId(), CHECK_COMMANDER_DAMAGE);
           getState().getWatchers().add(watcher);
           watcher.addCardInfoToCommander(this);
         }
       }
     }
   }
   this.getState().addAbility(ability, null);
   super.init(choosingPlayerId);
   if (startingPlayerSkipsDraw) {
     state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
   }
 }
コード例 #7
0
ファイル: HelmOfObedience.java プロジェクト: xdaft/mage
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player != null) {
      int max = amount.calculate(game, source);
      if (max != 0) {
        int numberOfCard = 0;

        while (player.getLibrary().size() > 0) {
          Card card = player.getLibrary().removeFromTop(game);
          if (card != null) {
            if (card.moveToZone(Constants.Zone.GRAVEYARD, source.getId(), game, false)) {
              if (card.getCardType().contains(CardType.CREATURE)) {
                break;
              } else {
                numberOfCard++;
                if (numberOfCard >= max) {
                  break;
                }
              }
            }
          } else {
            return false;
          }
        }
      }
    }
    return true;
  }
コード例 #8
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;
  }
コード例 #9
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;
  }
コード例 #10
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

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

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

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

        if (putInHand) {
          game.getExile().getPermanentExile().remove(card);
          card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
        } else {
          player.drawCards(3, game);
        }
        return true;
      }
    }
    player.shuffleLibrary(game);
    return false;
  }
コード例 #11
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
       Player player = game.getPlayer(playerId);
       if (player != null) {
         for (Card card : player.getHand().getCards(game)) {
           card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
         }
         for (Card card : player.getGraveyard().getCards(game)) {
           card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
         }
         player.shuffleLibrary(source, game);
       }
     }
     controller.drawCards(7, game);
     return true;
   }
   return false;
 }
コード例 #12
0
ファイル: Riftsweeper.java プロジェクト: nigelzor/mage
 @Override
 public boolean apply(Game game, Ability source) {
   Card card = game.getCard(targetPointer.getFirst(game, source));
   if (card != null) {
     // remove exiting suspend counters
     card.getCounters(game).clear();
     // move to exile
     card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
     game.getPlayer(card.getOwnerId()).shuffleLibrary(source, game);
     game.informPlayers(
         new StringBuilder("Riftsweeper: Choosen card was ").append(card.getName()).toString());
     return true;
   }
   return false;
 }
コード例 #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
  @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;
  }
コード例 #15
0
ファイル: MakeAWish.java プロジェクト: poixen/mage
 @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;
 }
コード例 #16
0
ファイル: VengefulPharaoh.java プロジェクト: Nick456/mage
 @Override
 public boolean apply(Game game, Ability source) {
   boolean applied = false;
   Permanent permanent = game.getPermanent(source.getFirstTarget());
   if (permanent != null) {
     permanent.destroy(source.getId(), game, false);
     applied = true;
   }
   Player player = game.getPlayer(source.getControllerId());
   Card card = game.getCard(source.getSourceId());
   if (card != null && player != null) {
     player.getGraveyard().remove(card);
     card.moveToZone(Zone.LIBRARY, source.getId(), game, true);
     applied = true;
   }
   return applied;
 }
コード例 #17
0
ファイル: FaithsReward.java プロジェクト: xdaft/mage
 @Override
 public boolean apply(Game game, Ability source) {
   FaithsRewardWatcher watcher =
       (FaithsRewardWatcher) game.getState().getWatchers().get("FaithsRewardWatcher");
   if (watcher != null) {
     for (UUID id : watcher.cards) {
       Card c = game.getCard(id);
       if (c != null
           && c.getOwnerId().equals(source.getControllerId())
           && game.getState().getZone(id) == Constants.Zone.GRAVEYARD) {
         c.moveToZone(Constants.Zone.BATTLEFIELD, source.getSourceId(), game, false);
       }
     }
     return true;
   }
   return false;
 }
コード例 #18
0
ファイル: SurrealMemoir.java プロジェクト: joshhazel/mage
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null) {
     FilterCard filter = new FilterCard("instant card");
     filter.add(new CardTypePredicate(CardType.INSTANT));
     Card[] cards = player.getGraveyard().getCards(filter, game).toArray(new Card[0]);
     if (cards.length > 0) {
       Random rnd = new Random();
       Card card = cards[rnd.nextInt(cards.length)];
       card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
       game.informPlayers(card.getName() + "returned to the hand of" + player.getName());
       return true;
     }
   }
   return false;
 }
コード例 #19
0
ファイル: SecondSunrise.java プロジェクト: kholdfuzion/mage
 @Override
 public boolean apply(Game game, Ability source) {
   SecondSunriseWatcher watcher =
       (SecondSunriseWatcher) game.getState().getWatchers().get("SecondSunriseWatcher");
   if (watcher != null) {
     for (UUID id : watcher.cards) {
       Card c = game.getCard(id);
       if (c != null && game.getState().getZone(id) == Zone.GRAVEYARD) {
         if (c.getCardType().contains(CardType.ARTIFACT)
             || c.getCardType().contains(CardType.CREATURE)
             || c.getCardType().contains(CardType.ENCHANTMENT)
             || c.getCardType().contains(CardType.LAND))
           c.moveToZone(Zone.BATTLEFIELD, source.getSourceId(), game, false);
       }
     }
     return true;
   }
   return false;
 }
コード例 #20
0
ファイル: BudokaGardener.java プロジェクト: petrich0r/mage
 @Override
 public boolean apply(Game game, Ability source) {
   Card c = game.getCard(targetPointer.getFirst(game, source));
   if (c != null) {
     c.moveToZone(Zone.BATTLEFIELD, source.getSourceId(), game, false);
   }
   if (game.getBattlefield()
           .count(
               DokaiWeaverofLifeToken.filterLands,
               source.getSourceId(),
               source.getControllerId(),
               game)
       >= 10) {
     Permanent p = game.getPermanent(source.getSourceId());
     if (p != null) {
       p.flip(game);
     }
   }
   return true;
 }
コード例 #21
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;
  }
コード例 #22
0
ファイル: MoltenBirth.java プロジェクト: poixen/mage
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   Card molten = game.getCard(source.getSourceId());
   if (controller != null) {
     ElementalToken token = new ElementalToken();
     token.putOntoBattlefield(2, game, source.getSourceId(), source.getControllerId());
     if (controller.flipCoin(game)) {
       molten.moveToZone(Zone.HAND, source.getSourceId(), game, true);
       game.informPlayers(
           controller.getLogName()
               + " won the flip.  "
               + molten.getLogName()
               + " is returned to "
               + controller.getLogName()
               + "'s hand.");
     }
     return true;
   }
   return false;
 }
コード例 #23
0
ファイル: DwellOnThePast.java プロジェクト: poixen/mage
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getFirstTarget());
   if (player != null) {
     List<UUID> targets = source.getTargets().get(1).getTargets();
     boolean shuffle = false;
     for (UUID targetId : targets) {
       Card card = game.getCard(targetId);
       if (card != null) {
         if (player.getGraveyard().contains(card.getId())) {
           player.getGraveyard().remove(card);
           card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
           shuffle = true;
         }
       }
     }
     if (shuffle) {
       player.shuffleLibrary(source, game);
     }
     return true;
   }
   return false;
 }
コード例 #24
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   Card sourceCard = game.getCard(source.getSourceId());
   if (controller == null || sourceCard == null) {
     return false;
   }
   if (controller.getLibrary().size() > 0) {
     controller.shuffleLibrary(game);
     Card card = controller.getLibrary().getFromTop(game);
     if (card == null) {
       return false;
     }
     controller.revealCards(sourceCard.getName(), new CardsImpl(card), game);
     if (card.getCardType().contains(CardType.LAND)) {
       String message = "Put " + card.getName() + " onto the battlefield?";
       if (controller.chooseUse(Outcome.PutLandInPlay, message, game)) {
         card.putOntoBattlefield(
             game, Zone.LIBRARY, source.getSourceId(), source.getControllerId());
         return sourceCard.moveToZone(Zone.HAND, source.getSourceId(), game, false);
       }
     } else {
       if (controller.chooseUse(
           outcome,
           new StringBuilder("Cast ")
               .append(card.getName())
               .append(" without paying its mana cost?")
               .toString(),
           game)) {
         return controller.cast(card.getSpellAbility(), game, true);
       }
     }
     return true;
   }
   return false;
 }
コード例 #25
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;
  }
コード例 #26
0
ファイル: Spell.java プロジェクト: quercitron/mage
 @Override
 public void counter(UUID sourceId, Game game) {
   card.moveToZone(Zone.GRAVEYARD, sourceId, game, false);
 }
コード例 #27
0
ファイル: Spell.java プロジェクト: quercitron/mage
 @Override
 public boolean resolve(Game game) {
   boolean result;
   if (this.getCardType().contains(CardType.INSTANT)
       || this.getCardType().contains(CardType.SORCERY)) {
     int index = 0;
     result = false;
     boolean legalParts = false;
     for (SpellAbility spellAbility : this.spellAbilities) {
       for (UUID modeId : spellAbility.getModes().getSelectedModes()) {
         spellAbility.getModes().setMode(spellAbility.getModes().get(modeId));
         if (spellAbility.getTargets().stillLegal(spellAbility, game)) {
           legalParts = true;
           if (!spellAbility.getSpellAbilityType().equals(SpellAbilityType.SPLICE)) {
             updateOptionalCosts(index);
           }
           result |= spellAbility.resolve(game);
         }
       }
       index++;
     }
     if (legalParts) {
       if (!copiedSpell) {
         for (Effect effect : ability.getEffects()) {
           if (effect instanceof PostResolveEffect) {
             ((PostResolveEffect) effect).postResolve(card, ability, controllerId, game);
             return result;
           }
         }
         if (!card.isCopy() && game.getState().getZone(card.getId()) == Zone.STACK) {
           card.moveToZone(Zone.GRAVEYARD, ability.getId(), game, false);
         }
       }
       return result;
     }
     // 20091005 - 608.2b
     game.informPlayers(getName() + " has been fizzled.");
     counter(null, game);
     return false;
   } else if (this.getCardType().contains(CardType.ENCHANTMENT)
       && this.getSubtype().contains("Aura")) {
     if (ability.getTargets().stillLegal(ability, game)) {
       updateOptionalCosts(0);
       if (card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId)) {
         return ability.resolve(game);
       }
       return false;
     }
     if (this.getCardType()
         .contains(
             CardType.CREATURE)) { // e.g. Creature with Bestow (rule confirmation yet missing)
       updateOptionalCosts(0);
       result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId);
       return result;
     } else {
       // 20091005 - 608.2b
       game.informPlayers(getName() + " has been fizzled.");
       counter(null, game);
       return false;
     }
   } else {
     updateOptionalCosts(0);
     result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId);
     return result;
   }
 }
コード例 #28
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;
  }
コード例 #29
0
ファイル: FlashOfInsight.java プロジェクト: TumbleMagnet/mage
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (player == null || sourceObject == null) {
      return false;
    }

    int xValue;
    xValue = source.getManaCostsToPay().getX();

    Cards cards = new CardsImpl(Zone.PICK);
    int count = Math.min(player.getLibrary().size(), xValue);
    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.lookAtCards(sourceObject.getName(), cards, game);

    TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put into your hand"));
    if (player.choose(Outcome.DrawCard, cards, target, game)) {
      Card card = cards.get(target.getFirstTarget(), game);
      if (card != null) {
        cards.remove(card);
        card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
        game.informPlayers(
            sourceObject.getName()
                + ": "
                + player.getLogName()
                + " puts a card into his or her hand");
      }
    }

    target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library"));
    if (cards.size() > 0) {
      game.informPlayers(
          new StringBuilder(sourceObject.getName())
              .append(": ")
              .append(player.getLogName())
              .append(" puts ")
              .append(cards.size() == 1 ? "a" : cards.size())
              .append(" card")
              .append(cards.size() > 1 ? "s" : "")
              .append(" on the bottom of his or her library")
              .toString());
    }
    while (player.isInGame() && 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.LIBRARY, source.getSourceId(), game, false);
      }
      target.clearChosen();
    }
    if (cards.size() == 1) {
      Card card = cards.get(cards.iterator().next(), game);
      card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
    }

    return true;
  }
  public boolean applySearchAndExile(
      Game game, Ability source, String cardName, UUID targetPlayerId) {
    Player player = game.getPlayer(source.getControllerId());
    if (cardName != null && player != null) {
      Player targetPlayer = game.getPlayer(targetPlayerId);
      if (targetPlayer != null) {
        FilterCard filter = new FilterCard("card named " + cardName);
        filter.add(new NamePredicate(cardName));

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

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

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

      targetPlayer.shuffleLibrary(game);

      return true;
    }

    return false;
  }