コード例 #1
0
ファイル: TransformAbility.java プロジェクト: joshhazel/mage
  public static void transform(Permanent permanent, Card sourceCard, Game game) {

    if (sourceCard == null) {
      return;
    }

    permanent.setName(sourceCard.getName());
    permanent.getColor().setColor(sourceCard.getColor());
    permanent.getManaCost().clear();
    permanent.getManaCost().add(sourceCard.getManaCost());
    permanent.getCardType().clear();
    for (CardType type : sourceCard.getCardType()) {
      permanent.getCardType().add(type);
    }
    permanent.getSubtype().clear();
    for (String type : sourceCard.getSubtype()) {
      permanent.getSubtype().add(type);
    }
    permanent.getSupertype().clear();
    for (String type : sourceCard.getSupertype()) {
      permanent.getSupertype().add(type);
    }
    permanent.setExpansionSetCode(sourceCard.getExpansionSetCode());
    permanent.getAbilities().clear();
    for (Ability ability : sourceCard.getAbilities()) {
      permanent.addAbility(ability, game);
    }
    permanent.getPower().setValue(sourceCard.getPower().getValue());
    permanent.getToughness().setValue(sourceCard.getToughness().getValue());
  }
コード例 #2
0
ファイル: LivingLore.java プロジェクト: TumbleMagnet/mage
 @Override
 public boolean apply(Game game, Ability source) {
   MageObject mageObject = source.getSourceObject(game);
   Permanent permanent = game.getPermanent(source.getSourceId());
   if (permanent != null
       && mageObject == null
       && new MageObjectReference(permanent, game).refersTo(mageObject, game)) {
     discard();
     return false;
   }
   UUID exileId =
       CardUtil.getExileZoneId(
           game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
   if (exileId != null) {
     ExileZone exileZone = game.getExile().getExileZone(exileId);
     if (exileZone == null) {
       return false;
     }
     Card exiledCard = null;
     for (Card card : exileZone.getCards(game)) {
       exiledCard = card;
       break;
     }
     if (exiledCard != null) {
       int value = exiledCard.getManaCost().convertedManaCost();
       permanent.getPower().setValue(value);
       permanent.getToughness().setValue(value);
     }
   }
   return true;
 }
コード例 #3
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;
  }
コード例 #4
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;
 }
コード例 #5
0
ファイル: DimirDoppelganger.java プロジェクト: nigelzor/mage
  @Override
  public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getFirstTarget());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (card == null || permanent == null) {
      return false;
    }
    card.moveToExile(null, "Dimir Doppelganger", source.getSourceId(), game);
    Card cardToCopy = card.copy();
    cardToCopy.assignNewId();
    permanent.setName(cardToCopy.getName());
    permanent.getPower().setValue(cardToCopy.getPower().getValue());
    permanent.getToughness().setValue(cardToCopy.getToughness().getValue());
    permanent.getColor(game).setColor(cardToCopy.getColor(game));
    permanent.getManaCost().clear();
    permanent.getManaCost().add(cardToCopy.getManaCost());
    permanent.getCardType().clear();
    for (CardType type : cardToCopy.getCardType()) {
      if (!permanent.getCardType().contains(type)) {
        permanent.getCardType().add(type);
      }
    }
    permanent.getSubtype(game).clear();
    for (String type : cardToCopy.getSubtype(game)) {
      if (!permanent.getSubtype(game).contains(type)) {
        permanent.getSubtype(game).add(type);
      }
    }
    permanent.getSupertype().clear();
    for (String type : cardToCopy.getSupertype()) {
      if (!permanent.getSupertype().contains(type)) {
        permanent.getSupertype().add(type);
      }
    }
    permanent.removeAllAbilities(source.getSourceId(), game);
    // gains ability of Dimir Doppelganger
    Ability dimirDoppelgangerAbility =
        new SimpleActivatedAbility(
            Zone.BATTLEFIELD, new DimirDoppelgangerEffect(), new ManaCostsImpl("{1}{U}{B}"));
    dimirDoppelgangerAbility.addTarget(
        new TargetCardInGraveyard(new FilterCreatureCard("creature card in a graveyard")));
    permanent.addAbility(dimirDoppelgangerAbility, source.getSourceId(), game);

    for (Ability ability : cardToCopy.getAbilities()) {
      if (!permanent.getAbilities().contains(ability)) {
        permanent.addAbility(ability, source.getSourceId(), game);
      }
    }
    return true;
  }
コード例 #6
0
ファイル: LifeDeath.java プロジェクト: joshhazel/mage
 @Override
 public boolean apply(Game game, Ability source) {
   Card creatureCard = game.getCard(this.getTargetPointer().getFirst(game, source));
   Player controller = game.getPlayer(source.getControllerId());
   if (creatureCard != null && controller != null) {
     boolean result = false;
     if (game.getState().getZone(creatureCard.getId()).equals(Zone.GRAVEYARD)) {
       result =
           controller.putOntoBattlefieldWithInfo(
               creatureCard, game, Zone.GRAVEYARD, source.getSourceId());
     }
     controller.loseLife(creatureCard.getManaCost().convertedManaCost(), game);
     return result;
   }
   return false;
 }
コード例 #7
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;
 }
コード例 #8
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;
  }
コード例 #9
0
ファイル: DeckGenerator.java プロジェクト: glerman/mage
 /**
  * Generates all spells for the deck. Each card is retrieved from the database and checked against
  * the converted mana cost (CMC) needed for the current card pool. If a card's CMC matches the CMC
  * range required by the pool, it is added to the deck. This ensures that the majority of cards
  * fit a fixed mana curve for the deck, and it is playable. Creatures and non-creatures are
  * retrieved separately to ensure the deck contains a reasonable mix of both.
  *
  * @param criteria the criteria to search for in the database.
  * @param spellCount the number of spells that match the criteria needed in the deck.
  */
 private static void generateSpells(CardCriteria criteria, int spellCount) {
   List<CardInfo> cardPool = CardRepository.instance.findCards(criteria);
   int retrievedCount = cardPool.size();
   List<DeckGeneratorCMC> deckCMCs = genPool.getCMCsForSpellCount(spellCount);
   Random random = new Random();
   int count = 0;
   int reservesAdded = 0;
   if (retrievedCount > 0 && retrievedCount >= spellCount) {
     int tries = 0;
     while (count < spellCount) {
       Card card = cardPool.get(random.nextInt(retrievedCount)).getMockCard();
       if (genPool.isValidSpellCard(card)) {
         int cardCMC = card.getManaCost().convertedManaCost();
         for (DeckGeneratorCMC deckCMC : deckCMCs) {
           if (cardCMC >= deckCMC.min && cardCMC <= deckCMC.max) {
             int currentAmount = deckCMC.getAmount();
             if (currentAmount > 0) {
               deckCMC.setAmount(currentAmount - 1);
               genPool.addCard(card.copy());
               count++;
             }
           } else {
             if (reservesAdded < genPool.getDeckSize() / 2) {
               genPool.tryAddReserve(card, cardCMC);
               reservesAdded++;
             }
           }
         }
       }
       tries++;
       if (tries > MAX_TRIES) {
         // Break here, we'll fill in random missing ones later
         break;
       }
     }
   } else {
     throw new IllegalStateException("Not enough cards to generate deck.");
   }
 }
コード例 #10
0
ファイル: Spell.java プロジェクト: quercitron/mage
 @Override
 public ManaCosts<ManaCost> getManaCost() {
   return card.getManaCost();
 }