Ejemplo n.º 1
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.º 2
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.º 3
0
  @Override
  public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller == null || sourcePermanent == null) {
      return false;
    }
    for (UUID playerId : controller.getInRange()) {
      Player player = game.getPlayer(playerId);
      String playerName = new StringBuilder(player.getLogName()).append("'s").toString();
      if (source.getControllerId().equals(player.getId())) {
        playerName = "your";
      }
      TargetCardInLibrary target =
          new TargetCardInLibrary(
              new FilterNonlandCard(
                  new StringBuilder("nonland card from ")
                      .append(playerName)
                      .append(" library")
                      .toString()));
      if (controller.searchLibrary(target, game, playerId)) {
        UUID targetId = target.getFirstTarget();
        Card card = player.getLibrary().remove(targetId, game);
        if (card != null) {
          controller.moveCardToExileWithInfo(
              card,
              CardUtil.getCardExileZoneId(game, source),
              sourcePermanent.getIdName(),
              source.getSourceId(),
              game,
              Zone.LIBRARY,
              true);
        }
      }
      player.shuffleLibrary(game);
    }

    ExileZone jaceExileZone =
        game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
    if (jaceExileZone == null) {
      return true;
    }
    FilterCard filter = new FilterCard("card to cast without mana costs");
    TargetCardInExile target = new TargetCardInExile(filter, source.getSourceId());
    while (jaceExileZone.count(filter, game) > 0
        && controller.choose(Outcome.PlayForFree, jaceExileZone, target, game)) {
      Card card = game.getCard(target.getFirstTarget());
      if (card != null) {
        if (controller.cast(card.getSpellAbility(), game, true)) {
          game.getExile().removeCard(card, game);
        }
      }
      target.clearChosen();
    }
    return true;
  }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
0
 @Override
 public boolean apply(Game game, Ability source) {
   Card card = game.getCard(source.getSourceId());
   if (card != null) {
     ExileZone currentZone = game.getState().getExile().getExileZone(source.getSourceId());
     // return it only from the own exile zone
     if (currentZone != null && currentZone.size() > 0) {
       Player owner = game.getPlayer(card.getOwnerId());
       if (owner != null && owner.moveCards(card, Zone.BATTLEFIELD, source, game)) {
         return true;
       }
     }
   }
   return false;
 }
Ejemplo n.º 6
0
 @Override
 public boolean apply(Game game, Ability source) {
   UUID exileId = source.getSourceId();
   ExileZone exile = game.getExile().getExileZone(exileId);
   if (exile != null) {
     exile = exile.copy();
     for (UUID cardId : exile) {
       Card card = game.getCard(cardId);
       card.putOntoBattlefield(game, Zone.EXILED, source.getSourceId(), card.getOwnerId());
     }
     game.getExile().getExileZone(exileId).clear();
     return true;
   }
   return false;
 }
Ejemplo n.º 7
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     ExileZone exZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
     if (exZone != null) {
       for (Card card : exZone.getCards(game)) {
         if (card != null) {
           controller.moveCardToHandWithInfo(card, source.getSourceId(), game, Zone.EXILED);
         }
       }
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 8
0
 @Override
 public boolean canTarget(UUID id, Ability source, Game game) {
   Card card = game.getCard(id);
   if (card != null && game.getState().getZone(card.getId()) == Zone.EXILED) {
     if (allExileZones) {
       return filter.match(card, source.getControllerId(), game);
     }
     ExileZone exile;
     if (zoneId != null) {
       exile = game.getExile().getExileZone(zoneId);
     } else {
       exile = game.getExile().getPermanentExile();
     }
     if (exile != null && exile.contains(id)) {
       return filter.match(card, source.getControllerId(), game);
     }
   }
   return false;
 }
Ejemplo n.º 9
0
 @Override
 public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
   if (allExileZones) {
     int numberTargets = 0;
     for (ExileZone exileZone : game.getExile().getExileZones()) {
       numberTargets += exileZone.count(filter, sourceId, sourceControllerId, game);
       if (numberTargets >= this.minNumberOfTargets) {
         return true;
       }
     }
   } else {
     ExileZone exileZone = game.getExile().getExileZone(zoneId);
     if (exileZone != null) {
       if (exileZone.count(filter, sourceId, sourceControllerId, game)
           >= this.minNumberOfTargets) {
         return true;
       }
     }
   }
   return false;
 }
Ejemplo n.º 10
0
 @Override
 public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
   Set<UUID> possibleTargets = new HashSet<UUID>();
   if (allExileZones) {
     for (Card card : game.getExile().getAllCards(game)) {
       if (filter.match(card, sourceControllerId, game)) {
         possibleTargets.add(card.getId());
       }
     }
   } else {
     ExileZone exileZone = game.getExile().getExileZone(zoneId);
     if (exileZone != null) {
       for (Card card : exileZone.getCards(game)) {
         if (filter.match(card, sourceControllerId, game)) {
           possibleTargets.add(card.getId());
         }
       }
     }
   }
   return possibleTargets;
 }