Exemple #1
0
  /**
   * Check that a DiesTriggeredAbility of a creature does not trigger if the creature dies face down
   */
  @Test
  public void testDiesTriggeredDoesNotTriggerIfFaceDown() {
    // Flying
    // When Ashcloud Phoenix dies, return it to the battlefield face down.
    // Morph (You may cast this card face down as a 2/2 creature for . Turn it face up any time for
    // its morph cost.)
    // When Ashcloud Phoenix is turned face up, it deals 2 damage to each player.
    addCard(Zone.HAND, playerA, "Ashcloud Phoenix", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);

    addCard(Zone.HAND, playerB, "Lightning Bolt", 1);
    addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1);

    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ashcloud Phoenix");
    setChoice(playerA, "Yes"); // cast it face down as 2/2 creature

    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", "");

    setStopAt(1, PhaseStep.BEGIN_COMBAT);
    execute();

    assertLife(playerA, 20);
    assertLife(playerB, 20);

    assertGraveyardCount(playerB, "Lightning Bolt", 1);
    assertGraveyardCount(playerA, "Ashcloud Phoenix", 1);

    for (Card card : playerA.getGraveyard().getCards(currentGame)) {
      if (card.getName().equals("Ashcloud Phoenix")) {
        Assert.assertEquals(
            "Ashcloud Phoenix has to be face up in graveyard", false, card.isFaceDown(currentGame));
        break;
      }
    }
  }
Exemple #2
0
  /** Check if a face down Morph creature gets exiled, it will be face up in exile zone. */
  @Test
  public void testExileFaceDownCreature() {
    addCard(Zone.HAND, playerA, "Birchlore Rangers", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);

    addCard(Zone.HAND, playerB, "Swords to Plowshares", 1);
    addCard(Zone.BATTLEFIELD, playerB, "Plains", 1);

    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Birchlore Rangers");
    setChoice(playerA, "Yes"); // cast it face down as 2/2 creature

    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Swords to Plowshares", "");

    setStopAt(1, PhaseStep.BEGIN_COMBAT);
    execute();

    assertLife(playerA, 22); // + 2 from Swords to Plowshares
    assertLife(playerB, 20);

    assertGraveyardCount(playerB, "Swords to Plowshares", 1);
    assertExileCount("Birchlore Rangers", 1);

    for (Card card : currentGame.getExile().getAllCards(currentGame)) {
      if (card.getName().equals("Birchlore Rangers")) {
        Assert.assertEquals(
            "Birchlore Rangers has to be face up in exile", false, card.isFaceDown(currentGame));
        break;
      }
    }
  }
Exemple #3
0
  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());
  }
Exemple #4
0
  @Override
  public boolean apply(Game game, Ability source) {
    RevealTargetFromHandCost revealCost = null;
    for (Cost cost : source.getCosts()) {
      if (cost instanceof RevealTargetFromHandCost) {
        revealCost = (RevealTargetFromHandCost) cost;
      }
    }

    Player controller = game.getPlayer(source.getControllerId());
    Card sourceCard = game.getCard(source.getSourceId());
    if (controller != null && sourceCard != null && revealCost != null) {
      int live = revealCost.getNumberRevealedCards() * 3;
      if (live > 0) {
        controller.gainLife(live, game);
      }
      game.informPlayers(
          new StringBuilder(sourceCard.getName())
              .append(": ")
              .append(controller.getName())
              .append(" revealed ")
              .append(revealCost.getNumberRevealedCards())
              .append(revealCost.getNumberRevealedCards() == 1 ? "white card" : "white cards")
              .append(" and gained ")
              .append(live)
              .append(" live")
              .toString());
      return true;
    }
    return false;
  }
Exemple #5
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Card card = player.getLibrary().getFromTop(game);
    if (card != null) {
      Cards cards = new CardsImpl();
      cards.add(card);
      player.lookAtCards("Explorer's Scope", cards, game);
      if (card.getCardType().contains(CardType.LAND)) {
        String message = "Put " + card.getName() + " onto the battlefield tapped?";
        if (player.chooseUse(Outcome.PutLandInPlay, message, game)) {
          if (card.putOntoBattlefield(
              game, Zone.LIBRARY, source.getId(), source.getControllerId())) {
            Permanent permanent = game.getPermanent(card.getId());
            if (permanent != null) {
              permanent.setTapped(true);
            }
          }
        }
      }
    }
    return true;
  }
 @Override
 public boolean applies(Ability abilityToModify, Ability source, Game game) {
   if ((abilityToModify instanceof SpellAbility || abilityToModify instanceof FlashbackAbility)
       && abilityToModify.getControllerId().equals(source.getControllerId())) {
     Card card = game.getCard(abilityToModify.getSourceId());
     return card.getName().equals(game.getState().getValue(source.getSourceId().toString()));
   }
   return false;
 }
 private void postPileToLog(String pileName, Set<Card> cards, Game game) {
   StringBuilder message = new StringBuilder(pileName).append(": ");
   for (Card card : cards) {
     message.append(card.getName()).append(" ");
   }
   if (cards.isEmpty()) {
     message.append(" (empty)");
   }
   game.informPlayers(message.toString());
 }
  @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;
  }
Exemple #9
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (player != null && controller != null) {
      Choice cardChoice = new ChoiceImpl();
      cardChoice.setChoices(CardRepository.instance.getNonLandNames());
      cardChoice.clearChoice();

      while (!controller.choose(Outcome.Exile, cardChoice, game)) {
        game.debugMessage("player canceled choosing name. retrying.");
      }

      String cardName = cardChoice.getChoice();
      game.informPlayers("CranialExtraction, named card: [" + cardName + "]");
      for (Card card : player.getGraveyard().getCards(game)) {
        if (card.getName().equals(cardName)) {
          card.moveToExile(null, "", source.getId(), game);
        }
      }
      for (Card card : player.getHand().getCards(game)) {
        if (card.getName().equals(cardName)) {
          card.moveToExile(null, "", source.getId(), game);
        }
      }
      for (Card card : player.getLibrary().getCards(game)) {
        if (card.getName().equals(cardName)) {
          card.moveToExile(null, "", source.getId(), game);
        }
      }
      controller.lookAtCards("CranialExtraction Hand", player.getHand(), game);
      controller.lookAtCards(
          "CranialExtraction Library",
          new CardsImpl(Zone.PICK, player.getLibrary().getCards(game)),
          game);
      player.shuffleLibrary(game);
    }
    return true;
  }
Exemple #10
0
  @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;
  }
Exemple #11
0
  /**
   * Champion one or more creature types or if the subtype array is empty champion every creature.
   *
   * @param card
   * @param subtypes subtypes to champion with, if empty all creatures can be used
   * @param requiresCreature for cards that specifically require championing another creature
   */
  public ChampionAbility(Card card, String[] subtypes, boolean requiresCreature) {
    super(Zone.BATTLEFIELD, null);

    this.subtypes = subtypes;
    StringBuilder sb = new StringBuilder("another ");
    ArrayList<Predicate<MageObject>> subtypesPredicates = new ArrayList<>();
    if (!subtypes[0].isEmpty()) {
      int i = 0;
      for (String subtype : this.subtypes) {
        subtypesPredicates.add(new SubtypePredicate(subtype));
        if (i == 0) {
          sb.append(subtype);
        } else {
          sb.append(" or ").append(subtype);
        }
        i++;
      }
    } else {
      sb.append("creature");
    }
    this.objectDescription = sb.toString();
    FilterControlledPermanent filter = new FilterControlledPermanent(objectDescription);
    if (!subtypesPredicates.isEmpty()) {
      filter.add(Predicates.or(subtypesPredicates));
    }
    if (requiresCreature) {
      filter.add(new CardTypePredicate(CardType.CREATURE));
    }
    filter.add(new AnotherPredicate());

    // When this permanent enters the battlefield, sacrifice it unless you exile another [object]
    // you control.
    Ability ability1 =
        new EntersBattlefieldTriggeredAbility(
            new SacrificeSourceUnlessPaysEffect(
                new ChampionExileCost(
                    filter,
                    new StringBuilder(card.getName()).append(" championed permanents").toString())),
            false);
    ability1.setRuleVisible(false);
    addSubAbility(ability1);

    // When this permanent leaves the battlefield, return the exiled card to the battlefield under
    // its owner's control.
    Ability ability2 =
        new LeavesBattlefieldTriggeredAbility(
            new ReturnFromExileForSourceEffect(Zone.BATTLEFIELD), false);
    ability2.setRuleVisible(false);
    addSubAbility(ability2);
  }
 @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;
 }
Exemple #13
0
 @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;
 }
Exemple #14
0
 @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;
 }
Exemple #15
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   if (player != null) {
     Cards cards = player.getGraveyard();
     for (int i = 0; i < 2 && !cards.isEmpty(); i++) {
       Card card = cards.getRandom(game);
       if (card != null) {
         card.moveToZone(Zone.HAND, source.getSourceId(), game, true);
         cards.remove(card);
         game.informPlayers(card.getName() + " returned to the hand of " + player.getLogName());
       }
     }
     return true;
   }
   return false;
 }
  @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;
  }
Exemple #17
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) {
     if (game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
       boolean onTop =
           controller.chooseUse(
               outcome,
               "Put "
                   + sourceCard.getName()
                   + " on top of it's owners library (otherwise on bottom)?",
               source,
               game);
       controller.moveCardToLibraryWithInfo(
           sourceCard, source.getSourceId(), game, Zone.GRAVEYARD, onTop, true);
     }
     return true;
   }
   return false;
 }
Exemple #18
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
      return false;
    }

    Card card = player.getLibrary().getFromTop(game);
    if (card != null) {
      Cards cards = new CardsImpl();
      cards.add(card);
      player.lookAtCards("Into the Wilds", cards, game);
      if (filter.match(card, game)) {
        String message = "Put " + card.getName() + " onto the battlefield?";
        if (player.chooseUse(outcome, message, game)) {
          return card.putOntoBattlefield(
              game, Zone.LIBRARY, source.getId(), source.getControllerId(), false);
        }
      }
    }
    return true;
  }
Exemple #19
0
  /**
   * Check that a DiesTriggeredAbility of a creature does not trigger if the creature dies face down
   * in combat
   */
  @Test
  public void testDiesTriggeredDoesNotTriggerInCombatIfFaceDown() {
    // Flying
    // When Ashcloud Phoenix dies, return it to the battlefield face down.
    // Morph (You may cast this card face down as a 2/2 creature for . Turn it face up any time for
    // its morph cost.)
    // When Ashcloud Phoenix is turned face up, it deals 2 damage to each player.
    addCard(Zone.HAND, playerA, "Ashcloud Phoenix", 1);
    addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);

    // First strike, forestwalk, vigilance
    // (This creature deals combat damage before creatures without first strike, it can't be blocked
    // as long as defending player controls a Forest, and attacking doesn't cause this creature to
    // tap.)
    addCard(Zone.BATTLEFIELD, playerB, "Mirri, Cat Warrior");

    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ashcloud Phoenix");
    setChoice(playerA, "Yes"); // cast it face down as 2/2 creature

    attack(2, playerB, "Mirri, Cat Warrior");
    block(2, playerA, "", "Mirri, Cat Warrior");

    setStopAt(2, PhaseStep.POSTCOMBAT_MAIN);
    execute();

    assertGraveyardCount(playerA, "Ashcloud Phoenix", 1);

    for (Card card : playerA.getGraveyard().getCards(currentGame)) {
      if (card.getName().equals("Ashcloud Phoenix")) {
        Assert.assertEquals(
            "Ashcloud Phoenix has to be face up in graveyard", false, card.isFaceDown(currentGame));
        break;
      }
    }

    assertLife(playerA, 20);
    assertLife(playerB, 20);
  }
Exemple #20
0
  @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;
  }
Exemple #21
0
 @Override
 public String getName() {
   return card.getName();
 }
Exemple #22
0
  public String getValue(boolean useHidden, Game game) {
    StringBuilder sb = new StringBuilder(1024);

    sb.append(turnNum)
        .append(turn.getPhaseType())
        .append(turn.getStepType())
        .append(activePlayerId)
        .append(priorityPlayerId);

    for (Player player : players.values()) {
      sb.append("player").append(player.isPassed()).append(player.getLife()).append("hand");
      if (useHidden) {
        sb.append(player.getHand());
      } else {
        sb.append(player.getHand().size());
      }
      sb.append("library").append(player.getLibrary().size());
      sb.append("graveyard");
      for (Card card : player.getGraveyard().getCards(game)) {
        sb.append(card.getName());
      }
    }

    sb.append("permanents");
    List<String> perms = new ArrayList<String>();
    for (Permanent permanent : battlefield.getAllPermanents()) {
      perms.add(permanent.getValue());
    }
    Collections.sort(perms);
    sb.append(perms);

    sb.append("spells");
    for (StackObject spell : stack) {
      sb.append(spell.getControllerId()).append(spell.getName());
      sb.append(spell.getStackAbility().toString());
      for (Mode mode : spell.getStackAbility().getModes().values()) {
        if (!mode.getTargets().isEmpty()) {
          sb.append("targets");
          for (Target target : mode.getTargets()) {
            sb.append(target.getTargets());
          }
        }
        if (!mode.getChoices().isEmpty()) {
          sb.append("choices");
          for (Choice choice : mode.getChoices()) {
            sb.append(choice.getChoice());
          }
        }
      }
    }

    for (ExileZone zone : exile.getExileZones()) {
      sb.append("exile").append(zone.getName()).append(zone);
    }

    sb.append("combat");
    for (CombatGroup group : combat.getGroups()) {
      sb.append(group.getDefenderId()).append(group.getAttackers()).append(group.getBlockers());
    }

    return sb.toString();
  }
Exemple #23
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card sourceCard = game.getCard(source.getSourceId());
    Map<UUID, Integer> payLife = new HashMap<>();
    int currentLifePaid;
    int totalPaidLife;
    if (controller != null) {
      PlayerList playerList = game.getState().getPlayerList().copy();
      while (!playerList.get().equals(source.getControllerId()) && controller.isInGame()) {
        playerList.getNext();
      }
      Player currentPlayer = game.getPlayer(playerList.get());
      UUID firstInactivePlayer = null;

      while (controller.isInGame()) {
        if (firstInactivePlayer == null) {
          firstInactivePlayer = currentPlayer.getId();
        }
        if (currentPlayer != null
            && currentPlayer.isInGame()
            && controller.getInRange().contains(currentPlayer.getId())) {
          currentLifePaid = 0;
          totalPaidLife = 0;
          if (currentPlayer.chooseUse(Outcome.AIDontUseIt, "Pay life?", source, game)) {
            totalPaidLife =
                currentPlayer.getAmount(0, controller.getLife(), "Pay how many life?", game);
            if (totalPaidLife > 0) {
              currentPlayer.loseLife(totalPaidLife, game);
              if (payLife.get(currentPlayer.getId()) == null) {
                payLife.put(currentPlayer.getId(), totalPaidLife);
              } else {
                currentLifePaid = payLife.get(currentPlayer.getId());
                payLife.put(currentPlayer.getId(), currentLifePaid + totalPaidLife);
              }
            }
            game.informPlayers(
                new StringBuilder(sourceCard.getName())
                    .append(": ")
                    .append(currentPlayer.getLogName())
                    .append(" pays ")
                    .append(payLife.get(currentPlayer.getId()))
                    .append(" life")
                    .toString());
            firstInactivePlayer = null;
          }
        }

        // get next player
        playerList.getNext();
        currentPlayer = game.getPlayer(playerList.get());

        // if all player since this player didn't put permanent in play finish the process
        if (currentPlayer.getId().equals(firstInactivePlayer)) {
          break;
        }
      }

      // create tokens according to life spent by each player
      RatToken token = new RatToken();
      for (Map.Entry<UUID, Integer> entry : payLife.entrySet()) {
        Player player = game.getPlayer(entry.getKey());
        if (player != null) {
          token.putOntoBattlefield(entry.getValue(), game, source.getSourceId(), player.getId());
        }
      }
    }
    return true;
  }
  @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;
  }
Exemple #25
0
  public GameView(GameState state, Game game) {
    for (Player player : state.getPlayers().values()) {
      players.add(new PlayerView(player, state, game));
    }
    for (StackObject stackObject : state.getStack()) {
      if (stackObject instanceof StackAbility) {
        MageObject object = game.getObject(stackObject.getSourceId());
        Card card = game.getCard(stackObject.getSourceId());
        if (card != null) {
          if (object != null) {
            stack.put(
                stackObject.getId(),
                new StackAbilityView(
                    game, (StackAbility) stackObject, card.getName(), new CardView(card)));
          } else {
            stack.put(
                stackObject.getId(),
                new StackAbilityView(game, (StackAbility) stackObject, "", new CardView(card)));
          }
          if (card.canTransform()) {
            updateLatestCardView(game, card, stackObject.getId());
          }
          checkPaid(stackObject.getId(), (StackAbility) stackObject);
        } else if (object != null) {
          if (object instanceof PermanentToken) {
            PermanentToken token = (PermanentToken) object;
            stack.put(stackObject.getId(), new CardView(token));
            checkPaid(stackObject.getId(), (StackAbility) stackObject);
          } else {
            StackAbility stackAbility = ((StackAbility) object);
            stackAbility.newId();
            MageObject emblem = game.getEmblem(stackAbility.getSourceId());
            if (emblem != null) {
              Card sourceCard = game.getCard(((CommandObject) emblem).getSourceId());
              if (sourceCard != null) {
                stackAbility.setName("Emblem " + sourceCard.getName());
                stackAbility.setExpansionSetCode(sourceCard.getExpansionSetCode());
              }
            }

            stack.put(stackObject.getId(), new CardView(stackAbility));
            checkPaid(stackObject.getId(), stackAbility);
          }
        }
      } else {
        stack.put(stackObject.getId(), new CardView((Spell) stackObject));
        checkPaid(stackObject.getId(), (Spell) stackObject);
      }
      // stackOrder.add(stackObject.getId());
    }
    // Collections.reverse(stackOrder);
    for (ExileZone exileZone : state.getExile().getExileZones()) {
      exiles.add(new ExileView(exileZone, game));
    }
    for (String name : state.getRevealed().keySet()) {
      revealed.add(new RevealedView(name, state.getRevealed().get(name), game));
    }
    this.phase = state.getTurn().getPhaseType();
    this.step = state.getTurn().getStepType();
    this.turn = state.getTurnNum();
    if (state.getActivePlayerId() != null)
      this.activePlayerName = state.getPlayer(state.getActivePlayerId()).getName();
    else this.activePlayerName = "";
    if (state.getPriorityPlayerId() != null)
      this.priorityPlayerName = state.getPlayer(state.getPriorityPlayerId()).getName();
    else this.priorityPlayerName = "";
    for (CombatGroup combatGroup : state.getCombat().getGroups()) {
      combat.add(new CombatGroupView(combatGroup, game));
    }
    this.special =
        state.getSpecialActions().getControlledBy(state.getPriorityPlayerId()).size() > 0;
  }
 public OverloadAbility(Card card, Effect effect, ManaCosts costs, TimingRule timingRule) {
   super(costs, card.getName() + " with overload");
   this.addEffect(effect);
   this.timing = timingRule;
 }
Exemple #27
0
 @Override
 public boolean apply(Card input, Game game) {
   return input.getCardType().contains(CardType.PLANESWALKER)
       && input.getName().contains("Ugin, the Spirit Dragon");
 }
Exemple #28
0
  public PermanentView(Permanent permanent, Card card, UUID createdForPlayerId, Game game) {
    super(permanent, game, permanent.getControllerId().equals(createdForPlayerId));
    this.controlled = permanent.getControllerId().equals(createdForPlayerId);
    this.rules = permanent.getRules(game);
    this.tapped = permanent.isTapped();
    this.flipped = permanent.isFlipped();
    this.phasedIn = permanent.isPhasedIn();
    this.summoningSickness = permanent.hasSummoningSickness();
    this.morphed = permanent.isMorphed();
    this.manifested = permanent.isManifested();
    this.damage = permanent.getDamage();
    if (permanent.getAttachments().size() > 0) {
      attachments = new ArrayList<>();
      attachments.addAll(permanent.getAttachments());
    }
    this.attachedTo = permanent.getAttachedTo();
    if (isToken()) {
      original = new CardView(((PermanentToken) permanent).getToken());
      original.expansionSetCode = permanent.getExpansionSetCode();
      tokenSetCode = original.getTokenSetCode();
    } else {
      if (card != null) {
        // original may not be face down
        original = new CardView(card);
      } else {
        original = null;
      }
    }
    this.transformed = permanent.isTransformed();
    this.copy = permanent.isCopy();

    // for fipped, transformed or copied cards, switch the names
    if (original != null && !original.getName().equals(this.getName())) {
      if (permanent.isCopy() && permanent.isFlipCard()) {
        this.alternateName = permanent.getFlipCardName();
        this.originalName = this.getName();
      } else {
        if (controlled // controller may always know
            || (!morphed && !manifested)) { // others don't know for morph or transformed cards
          this.alternateName = original.getName();
          this.originalName = this.getName();
        }
      }
    }
    if (!permanent.getOwnerId().equals(permanent.getControllerId())) {
      Player owner = game.getPlayer(permanent.getOwnerId());
      if (owner != null) {
        this.nameOwner = owner.getName();
      } else {
        this.nameOwner = "";
      }
    } else {
      this.nameOwner = "";
    }

    if (permanent.isFaceDown(game) && card != null) {
      if (controlled) {
        // must be a morphed or manifested card
        for (Ability permanentAbility : permanent.getAbilities()) {
          if (permanentAbility instanceof TurnFaceUpAbility && !permanentAbility.getRuleVisible()) {
            this.rules.add(permanentAbility.getRule(true));
          }
          if (permanentAbility.getWorksFaceDown()) {
            this.rules.add(permanentAbility.getRule());
          }
        }
        this.name = card.getName();
        this.displayName = card.getName();
        this.expansionSetCode = card.getExpansionSetCode();
        this.cardNumber = card.getCardNumber();
      } else {
        if (permanent.isManifested()) {
          this.rules.add(
              "A manifested creature card can be turned face up any time for it's mana cost."
                  + " A face-down card can also be turned face up for its morph cost.");
        } else if (permanent.isMorphed()) {
          this.rules.add(
              "If the controller has priority, he or she may turn this permanent face up."
                  + " This is a special action; it doesn’t use the stack. To do this he or she pays the morph costs,"
                  + " then turns this permanent face up.");
        }
      }
    }
    // determines if shown in it's own column
    if (permanent.getAttachedTo() != null) {
      attachedToPermanent = game.getPermanent(permanent.getAttachedTo()) != null;
    } else {
      attachedToPermanent = false;
    }
  }