Ejemplo n.º 1
0
 @Override
 public boolean apply(Game game, Ability source) {
   UUID exileId = CardUtil.getCardExileZoneId(game, source);
   for (UUID opponentId : game.getOpponents(source.getControllerId())) {
     Player opponent = game.getPlayer(opponentId);
     if (opponent != null) {
       Cards cards = new CardsImpl();
       cards.addAll(opponent.getHand());
       for (UUID cardId : cards) {
         Card card = game.getCard(cardId);
         if (card != null) {
           card.moveToExile(exileId, "Ashiok, Nightmare Weaver", source.getSourceId(), game);
         }
       }
       cards.clear();
       cards.addAll(opponent.getGraveyard());
       for (UUID cardId : cards) {
         Card card = game.getCard(cardId);
         if (card != null) {
           card.moveToExile(exileId, "Ashiok, Nightmare Weaver", source.getSourceId(), game);
         }
       }
     }
   }
   return true;
 }
Ejemplo n.º 2
0
  private void exileCards(Player player, int count, Ability source, Game game) {
    int amount =
        Math.min(
            count,
            player.getHand().size()
                + game.getBattlefield().getAllActivePermanents(player.getId()).size());

    while (amount > 0) {
      Target target = new TargetControlledPermanent(0, 1, filter, true);
      if (target.canChoose(player.getId(), game)
          && player.choose(Outcome.Exile, target, source.getSourceId(), game)) {

        for (UUID targetId : target.getTargets()) {
          Permanent chosen = game.getPermanent(targetId);
          if (chosen != null) {
            chosen.moveToExile(source.getId(), "Descent into Madness", source.getSourceId(), game);
            amount--;
          }
        }
      }

      if (amount > 0) {
        TargetCard targetInHand = new TargetCard(Zone.HAND, filterInHand);
        if (targetInHand.canChoose(player.getId(), game)
            && player.choose(Outcome.Exile, player.getHand(), targetInHand, game)) {

          Card card = player.getHand().get(targetInHand.getFirstTarget(), game);
          if (card != null) {
            card.moveToExile(source.getId(), "Descent into Madness", source.getSourceId(), game);
            amount--;
          }
        }
      }
    }
  }
Ejemplo n.º 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());
  }
Ejemplo n.º 4
0
 @Override
 public boolean apply(Game game, Ability source) {
   Permanent sourcePermanent =
       (Permanent)
           game.getLastKnownInformation(
               targetPointer.getFirst(game, source), Constants.Zone.BATTLEFIELD);
   if (sourcePermanent == null) {
     return false;
   }
   Player controller = game.getPlayer(source.getControllerId());
   if (controller == null) {
     return false;
   }
   Cards revealed = new CardsImpl();
   Card artifactCard = null;
   Cards nonArtifactCards = new CardsImpl();
   Player player = game.getPlayer(sourcePermanent.getControllerId());
   while (artifactCard == null && player.getLibrary().size() > 0) {
     Card card = player.getLibrary().removeFromTop(game);
     revealed.add(card);
     if (card.getCardType().contains(CardType.ARTIFACT)) artifactCard = card;
     else nonArtifactCards.add(card);
   }
   player.revealCards("Shape Anew", revealed, game);
   if (artifactCard != null) {
     artifactCard.putOntoBattlefield(
         game, Constants.Zone.LIBRARY, source.getId(), player.getId());
   }
   player.getLibrary().addAll(nonArtifactCards.getCards(game), game);
   player.shuffleLibrary(game);
   return true;
 }
Ejemplo n.º 5
0
  @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;
  }
Ejemplo n.º 6
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
      FilterCard filter = new FilterCard("red instant or sorcery card from your graveyard to play");
      filter.add(new ColorPredicate(ObjectColor.RED));
      filter.add(
          Predicates.or(
              new CardTypePredicate(CardType.INSTANT), new CardTypePredicate(CardType.SORCERY)));

      String message =
          "Play red instant or sorcery card from your graveyard without paying its mana cost?";
      Set<Card> cards = player.getGraveyard().getCards(filter, game);
      TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
      while (!cards.isEmpty() && player.chooseUse(outcome, message, source, game)) {
        target.clearChosen();
        if (player.choose(outcome, target, source.getSourceId(), game)) {
          Card card = game.getCard(target.getFirstTarget());
          if (card != null) {
            player.cast(card.getSpellAbility(), game, true);
            player.getGraveyard().remove(card);
            cards.remove(card);
          }
        }
      }

      return true;
    }
    return false;
  }
Ejemplo n.º 7
0
 @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;
 }
Ejemplo n.º 8
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     MageObject mageObject = source.getSourceObject(game);
     Permanent permanent = game.getPermanent(source.getSourceId());
     if (permanent != null
         && mageObject != null
         && new MageObjectReference(permanent, game).refersTo(mageObject, game)) {
       if (permanent.sacrifice(source.getSourceId(), game)) {
         UUID exileId =
             CardUtil.getExileZoneId(
                 game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
         if (exileId != null) {
           ExileZone exileZone = game.getExile().getExileZone(exileId);
           Card exiledCard = null;
           if (exileZone != null) {
             for (Card card : exileZone.getCards(game)) {
               exiledCard = card;
               break;
             }
           }
           if (exiledCard != null) {
             if (exiledCard.getSpellAbility().canChooseTarget(game)) {
               controller.cast(exiledCard.getSpellAbility(), game, true);
             }
           }
         }
       }
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 9
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject sourceObject = source.getSourceObject(game);
   if (controller != null && sourceObject != null) {
     Choice choice = new ChoiceImpl(true);
     choice.setMessage("Choose a creature type:");
     choice.setChoices(CardRepository.instance.getCreatureTypes());
     while (!controller.choose(Outcome.BoostCreature, choice, game)) {
       if (!controller.canRespond()) {
         return false;
       }
     }
     Cards revealedCards = new CardsImpl();
     while (controller.getLibrary().size() > 0) {
       Card card = controller.getLibrary().removeFromTop(game);
       if (card.getCardType().contains(CardType.CREATURE)
           && card.getSubtype().contains(choice.getChoice())) {
         controller.moveCards(card, Zone.BATTLEFIELD, source, game);
         break;
       }
       revealedCards.add(card);
     }
     controller.revealCards(sourceObject.getIdName(), revealedCards, game);
     controller.moveCards(revealedCards, Zone.LIBRARY, source, game);
     controller.shuffleLibrary(source, game);
     return true;
   }
   return false;
 }
Ejemplo n.º 10
0
 @Override
 public void init(Game game, Ability source) {
   Card card = game.getCard(target);
   if (card != null) {
     this.zoneChangeCounter = card.getZoneChangeCounter(game);
   }
 }
Ejemplo n.º 11
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;
  }
Ejemplo n.º 12
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) {
     controller.shuffleLibrary(source, game);
     if (controller.getLibrary().size() > 0) {
       Card card = controller.getLibrary().removeFromTop(game);
       if (card != null) {
         controller.moveCardToExileWithInfo(
             card,
             source.getSourceId(),
             sourceObject.getIdName(),
             source.getSourceId(),
             game,
             Zone.LIBRARY,
             true);
         ContinuousEffect effect = new MindsDesireCastFromExileEffect();
         effect.setTargetPointer(new FixedTarget(card.getId()));
         game.addEffect(effect, source);
       }
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 13
0
  @Override
  public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
      if (permanent.getImprinted().size() > 0) {
        Card card = game.getCard(permanent.getImprinted().get(0));
        if (card != null && card.getCardType().contains(CardType.CREATURE)) {
          switch (layer) {
            case TypeChangingEffects_4:
              if (sublayer == SubLayer.NA) {
                permanent.getSubtype().addAll(card.getSubtype());
              }

              break;
            case PTChangingEffects_7:
              if (sublayer == SubLayer.SetPT_7b) {
                permanent.getPower().setValue(card.getPower().getValue());
                permanent.getToughness().setValue(card.getToughness().getValue());
              }
          }
          return true;
        }
      }
    }
    return false;
  }
Ejemplo n.º 14
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   Permanent permanent = (Permanent) game.getLastKnownInformation(target, Zone.BATTLEFIELD);
   if (permanent != null && controller != null) {
     Player player = game.getPlayer(permanent.getOwnerId());
     if (player != null) {
       FilterCreatureCard filter =
           new FilterCreatureCard(
               new StringBuilder("a creature card from ")
                   .append(player.getLogName())
                   .append("'s graveyard")
                   .toString());
       filter.add(new OwnerIdPredicate(player.getId()));
       Target targetCreature = new TargetCardInGraveyard(filter);
       if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game)
           && controller.chooseTarget(outcome, targetCreature, source, game)) {
         Card card = game.getCard(targetCreature.getFirstTarget());
         if (card != null && game.getState().getZone(card.getId()).equals(Zone.GRAVEYARD)) {
           return card.putOntoBattlefield(
               game, Zone.GRAVEYARD, source.getSourceId(), player.getId());
         }
       }
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 15
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;
      }
    }
  }
Ejemplo n.º 16
0
  @Override
  public boolean apply(Game game, Ability source) {
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (card != null) {
      PutTokenOntoBattlefieldCopyTargetEffect effect =
          new PutTokenOntoBattlefieldCopyTargetEffect(
              source.getControllerId(), CardType.ARTIFACT, true);
      effect.setTargetPointer(
          new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
      effect.apply(game, source);
      for (Permanent addedToken : effect.getAddedPermanent()) {
        SacrificeTargetEffect sacrificeEffect =
            new SacrificeTargetEffect(
                "Sacrifice the token at the beginning of the next end step",
                source.getControllerId());
        sacrificeEffect.setTargetPointer(new FixedTarget(addedToken, game));
        DelayedTriggeredAbility delayedAbility =
            new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect);
        game.addDelayedTriggeredAbility(delayedAbility, source);
      }
      return true;
    }

    return false;
  }
Ejemplo n.º 17
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;
      }
    }
  }
Ejemplo n.º 18
0
 @Override
 public boolean apply(Game game, Ability source) {
   Card creature = null;
   Player opponent = game.getPlayer(source.getFirstTarget());
   CardsImpl cards = new CardsImpl();
   boolean creatureFound = false;
   while (opponent.getLibrary().size() > 0 && !creatureFound) {
     Card card = opponent.getLibrary().removeFromTop(game);
     if (card != null) {
       if (card.getCardType().contains(CardType.CREATURE)) {
         creature = card;
         creatureFound = true;
       }
       if (!creatureFound) {
         cards.add(card);
       }
     }
   }
   if (!cards.isEmpty()) {
     opponent.revealCards("Telemin Performance", cards, game);
     opponent.moveCards(cards, Zone.GRAVEYARD, source, game);
   }
   if (creature != null) {
     return creature.putOntoBattlefield(
         game, Zone.LIBRARY, source.getSourceId(), source.getControllerId());
   }
   return false;
 }
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject sourceObject = source.getSourceObject(game);
   if (controller != null && sourceObject != null) {
     Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
     UUID exileId =
         CardUtil.getExileZoneId(
             game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
     if (permanent != null) {
       return controller.moveCardToExileWithInfo(
           permanent,
           exileId,
           sourceObject.getIdName(),
           source.getSourceId(),
           game,
           Zone.BATTLEFIELD,
           true);
     } else {
       Card card = game.getCard(getTargetPointer().getFirst(game, source));
       if (card != null) {
         return controller.moveCardToExileWithInfo(
             card,
             exileId,
             sourceObject.getIdName(),
             source.getSourceId(),
             game,
             game.getState().getZone(card.getId()),
             true);
       }
     }
   }
   return false;
 }
Ejemplo n.º 20
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
      Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source));
      if (damagedPlayer == null) {
        return false;
      }
      FilterCard filter =
          new FilterCard(
              "target instant or sorcery card from " + damagedPlayer.getName() + "'s graveyard");
      filter.add(new OwnerIdPredicate(damagedPlayer.getId()));
      filter.add(
          Predicates.or(
              new CardTypePredicate(CardType.INSTANT), new CardTypePredicate(CardType.SORCERY)));

      Target target = new TargetCardInGraveyard(filter);
      if (controller.chooseTarget(Outcome.PlayForFree, target, source, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
          controller.cast(card.getSpellAbility(), game, true);
          game.addEffect(new WrexialReplacementEffect(card.getId()), source);
        }
      }
      return true;
    }
    return false;
  }
Ejemplo n.º 21
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;
  }
Ejemplo n.º 22
0
 @Override
 public boolean chooseTarget(
     Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
   if (cards.isEmpty()) return !target.isRequired();
   Card card = cards.getRandom(game);
   target.addTarget(card.getId(), source, game);
   return true;
 }
Ejemplo n.º 23
0
 @Override
 public boolean replaceEvent(GameEvent event, Ability source, Game game) {
   Card card = game.getCard(source.getFirstTarget());
   if (card != null) {
     card.moveToExile(null, "", source.getId(), game);
   }
   return true;
 }
Ejemplo n.º 24
0
  Cards ProteanHulkSearch(Game game, Ability source) {
    Cards cardsPicked = new CardsImpl(Zone.PICK);
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
      GameEvent event =
          GameEvent.getEvent(
              GameEvent.EventType.SEARCH_LIBRARY,
              source.getControllerId(),
              source.getControllerId(),
              source.getControllerId(),
              Integer.MAX_VALUE);
      if (!game.replaceEvent(event)) {
        int manaCostLeftToFetch = 6;
        int librarySearchLimit = event.getAmount();

        FilterCard filter =
            new FilterCreatureCard(
                "number of creature cards with total converted mana cost 6 or less (6 CMC left)");
        filter.add(
            new ConvertedManaCostPredicate(ComparisonType.LessThan, manaCostLeftToFetch + 1));
        TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
        target.setCardLimit(librarySearchLimit);

        while (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
          target.choose(
              Outcome.PutCreatureInPlay, source.getControllerId(), source.getControllerId(), game);
          Card card = player.getLibrary().remove(target.getFirstTarget(), game);
          if (card == null) {
            break;
          }
          cardsPicked.add(card);
          game.setZone(card.getId(), Zone.PICK);
          game.getState().getLookedAt(source.getControllerId()).add("Protean Hulk", cardsPicked);

          librarySearchLimit--;
          if (librarySearchLimit == 0) {
            break;
          }
          manaCostLeftToFetch -= card.getManaCost().convertedManaCost();
          filter =
              new FilterCreatureCard(
                  "number of creature cards with total converted mana cost 6 or less ("
                      + manaCostLeftToFetch
                      + " CMC left)");
          filter.add(
              new ConvertedManaCostPredicate(ComparisonType.LessThan, manaCostLeftToFetch + 1));
          target = new TargetCardInLibrary(0, 1, filter);
          target.setCardLimit(librarySearchLimit);
        }
        game.fireEvent(
            GameEvent.getEvent(
                GameEvent.EventType.LIBRARY_SEARCHED,
                source.getControllerId(),
                source.getControllerId()));
      }
    }
    return cardsPicked;
  }
Ejemplo n.º 25
0
 @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;
 }
Ejemplo n.º 26
0
 @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);
   }
 }
Ejemplo n.º 27
0
 @Override
 public boolean apply(Card input, Game game) {
   for (Target target : input.getSpellAbility().getTargets()) {
     if (target.canTarget(toBeCheckedPermanentId, input.getSpellAbility(), game)) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 28
0
 @Override
 public boolean applies(GameEvent event, Ability source, Game game) {
   if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD
       && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
     Card c = game.getCard(event.getTargetId());
     if (c != null && c.getCardType().contains(CardType.CREATURE)) return true;
   }
   return false;
 }
Ejemplo n.º 29
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;
  }
Ejemplo n.º 30
0
  @java.lang.Override
  public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (permanent != null && player != null) {
      List<UUID> imprinted = permanent.getImprinted();
      if (imprinted.size() > 0) {
        Card imprintedCard = game.getCard(imprinted.get(0));
        if (imprintedCard != null) {
          Choice choice = new ChoiceImpl(true);
          choice.setMessage("Pick a mana color");
          ObjectColor color = imprintedCard.getColor(game);
          if (color.isBlack()) {
            choice.getChoices().add("Black");
          }
          if (color.isRed()) {
            choice.getChoices().add("Red");
          }
          if (color.isBlue()) {
            choice.getChoices().add("Blue");
          }
          if (color.isGreen()) {
            choice.getChoices().add("Green");
          }
          if (color.isWhite()) {
            choice.getChoices().add("White");
          }

          if (choice.getChoices().size() > 0) {
            Mana mana = new Mana();
            if (choice.getChoices().size() == 1) {
              choice.setChoice(choice.getChoices().iterator().next());
            } else {
              player.choose(outcome, choice, game);
            }
            if (choice.getChoice().equals("Black")) {
              player.getManaPool().addMana(Mana.BlackMana, game, source);
            } else if (choice.getChoice().equals("Blue")) {
              player.getManaPool().addMana(Mana.BlueMana, game, source);
            } else if (choice.getChoice().equals("Red")) {
              player.getManaPool().addMana(Mana.RedMana, game, source);
            } else if (choice.getChoice().equals("Green")) {
              player.getManaPool().addMana(Mana.GreenMana, game, source);
            } else if (choice.getChoice().equals("White")) {
              player.getManaPool().addMana(Mana.WhiteMana, game, source);
            } else if (choice.getChoice().equals("Colorless")) {
              player.getManaPool().addMana(Mana.ColorlessMana, game, source);
            }
            checkToFirePossibleEvents(mana, game, source);
            player.getManaPool().addMana(mana, game, source);
          }
        }
      }
    }
    return true;
  }