Ejemplo n.º 1
0
 @Override
 public boolean apply(Game game, Ability source) {
   boolean result = false;
   Player graveyardPlayer = null;
   for (UUID cardInGraveyard : targetPointer.getTargets(game, source)) {
     Card card = game.getCard(cardInGraveyard);
     if (card != null) {
       for (Player player : game.getPlayers().values()) {
         if (player.getGraveyard().contains(card.getId())) {
           graveyardPlayer = player;
           player.getGraveyard().remove(card);
           result |= card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
         }
       }
     }
   }
   Card card = game.getCard(source.getSourceId());
   result |= card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
   Player player = game.getPlayer(card.getOwnerId());
   if (player != null) {
     player.shuffleLibrary(game);
   }
   if (graveyardPlayer != null && !graveyardPlayer.equals(player)) {
     graveyardPlayer.shuffleLibrary(game);
   }
   return result;
 }
Ejemplo n.º 2
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.º 3
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject sourceObject = source.getSourceObject(game);
   if (sourceObject != null && controller != null) {
     TargetCardInYourGraveyard target =
         new TargetCardInYourGraveyard(
             new FilterInstantOrSorceryCard("instant or sorcery card from your graveyard"));
     if (controller.chooseTarget(outcome, target, source, game)) {
       UUID exileId =
           CardUtil.getExileZoneId(
               game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
       Card card = controller.getGraveyard().get(target.getFirstTarget(), game);
       if (card != null) {
         controller.moveCardToExileWithInfo(
             card,
             exileId,
             sourceObject.getIdName(),
             source.getSourceId(),
             game,
             Zone.GRAVEYARD,
             true);
       }
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 4
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   MageObject mageObject = game.getObject(source.getSourceId());
   if (controller != null && mageObject != null) {
     Choice typeChoice = new ChoiceImpl(true);
     typeChoice.setMessage("Choose creature type");
     typeChoice.setChoices(CardRepository.instance.getCreatureTypes());
     while (!controller.choose(outcome, typeChoice, game)) {
       if (!controller.canRespond()) {
         return false;
       }
     }
     if (!game.isSimulation()) {
       game.informPlayers(
           mageObject.getName()
               + ": "
               + controller.getLogName()
               + " has chosen "
               + typeChoice.getChoice());
     }
     Cards cardsToLibrary = new CardsImpl();
     FilterCreatureCard filter = new FilterCreatureCard();
     filter.add(new SubtypePredicate(typeChoice.getChoice()));
     cardsToLibrary.addAll(
         controller
             .getGraveyard()
             .getCards(filter, source.getSourceId(), source.getControllerId(), game));
     controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false);
     controller.shuffleLibrary(game);
     return true;
   }
   return false;
 }
Ejemplo n.º 5
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.º 6
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player sourcePlayer = game.getPlayer(source.getControllerId());
   for (UUID playerId : sourcePlayer.getInRange()) {
     Player player = game.getPlayer(playerId);
     if (player != null) {
       player.getLibrary().addAll(player.getHand().getCards(game), game);
       player.getLibrary().addAll(player.getGraveyard().getCards(game), game);
       player.shuffleLibrary(game);
       player.getHand().clear();
       player.getGraveyard().clear();
       player.drawCards(7, game);
     }
   }
   return true;
 }
Ejemplo n.º 7
0
 @Override
 public boolean checkInterveningIfClause(Game game) {
   Player controller = game.getPlayer(controllerId);
   if (controller != null && controller.getGraveyard().contains(sourceId)) {
     return super.checkInterveningIfClause(game);
   }
   return false;
 }
Ejemplo n.º 8
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     return controller.moveCards(
         controller.getGraveyard().getCards(filter, game), Zone.BATTLEFIELD, source, game);
   }
   return false;
 }
Ejemplo n.º 9
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     Cards cards = new CardsImpl();
     cards.addAll(controller.getGraveyard().getCards(new FilterCreatureCard(), game));
     controller.putCardsOnTopOfLibrary(cards, game, source, false);
     controller.shuffleLibrary(source, game);
     return true;
   }
   return false;
 }
 @Override
 public boolean apply(Game game, Ability source) {
   Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
   if (targetPlayer != null) {
     ArrayList<UUID> graveyard = new ArrayList<UUID>(targetPlayer.getGraveyard());
     for (UUID cardId : graveyard) {
       game.getCard(cardId).moveToZone(Zone.EXILED, cardId, game, false);
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 11
0
 @Override
 public boolean apply(Game game, Ability source) {
   Card card = game.getCard(targetPointer.getFirst(game, source));
   if (card != null) {
     Player player = game.getPlayer(card.getOwnerId());
     if (player != null) {
       if (player.getGraveyard().size() == 0) {
         return new FlipSourceEffect(new NighteyesTheDesecratorToken()).apply(game, source);
       }
     }
   }
   return false;
 }
Ejemplo n.º 12
0
 @Override
 public boolean apply(Game game, Ability source, Ability abilityToModify) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     Set<CardType> foundCardTypes = new HashSet<>(8);
     for (Card card : controller.getGraveyard().getCards(game)) {
       foundCardTypes.addAll(card.getCardType());
     }
     CardUtil.reduceCost(abilityToModify, foundCardTypes.size());
     return true;
   }
   return false;
 }
Ejemplo n.º 13
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getFirstTarget());
   if (player != null) {
     for (Card card : player.getGraveyard().getCards(game)) {
       player.moveCardToLibraryWithInfo(
           card, source.getSourceId(), game, Zone.GRAVEYARD, true, true);
     }
     player.shuffleLibrary(source, game);
     return true;
   }
   return false;
 }
Ejemplo n.º 14
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getControllerId());
   Permanent permanent = game.getPermanent(source.getSourceId());
   if (permanent != null && player != null) {
     int amount = game.getBattlefield().countAll(filter1, source.getControllerId(), game) - 1;
     amount += player.getGraveyard().count(filter2, game);
     if (amount > 0) {
       permanent.addCounters(CounterType.P1P1.createInstance(amount), game);
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 15
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player player = game.getPlayer(source.getFirstTarget());
   if (player != null) {
     List<UUID> targets = source.getTargets().get(1).getTargets();
     boolean shuffle = false;
     for (UUID targetId : targets) {
       Card card = game.getCard(targetId);
       if (card != null) {
         if (player.getGraveyard().contains(card.getId())) {
           player.getGraveyard().remove(card);
           card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
           shuffle = true;
         }
       }
     }
     if (shuffle) {
       player.shuffleLibrary(source, game);
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 16
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     Card card = game.getCard(source.getSourceId());
     if (card != null) {
       Player owner = game.getPlayer(card.getOwnerId());
       if (owner != null && owner.getGraveyard().contains(card.getId())) {
         controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, true, false, null);
       }
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 17
0
 @Override
 public int calculate(Game game, Ability sourceAbility, Effect effect) {
   int amount = 0;
   PlayerList playerList = game.getPlayerList();
   for (UUID playerUUID : playerList) {
     Player player = game.getPlayer(playerUUID);
     if (player != null) {
       amount +=
           player
               .getGraveyard()
               .count(filter, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
     }
   }
   return amount + 2;
 }
Ejemplo n.º 18
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;
 }
Ejemplo n.º 19
0
 @Override
 public boolean apply(Game game, Ability source) {
   boolean applied = false;
   Permanent permanent = game.getPermanent(source.getFirstTarget());
   if (permanent != null) {
     permanent.destroy(source.getId(), game, false);
     applied = true;
   }
   Player player = game.getPlayer(source.getControllerId());
   Card card = game.getCard(source.getSourceId());
   if (card != null && player != null) {
     player.getGraveyard().remove(card);
     card.moveToZone(Zone.LIBRARY, source.getId(), game, true);
     applied = true;
   }
   return applied;
 }
Ejemplo n.º 20
0
 @Override
 public void adjustTargets(Ability ability, Game game) {
   Target target = ability.getTargets().get(0);
   if (target instanceof DynamicTargetCreaturePermanent) {
     Player controller = game.getPlayer(ability.getControllerId());
     int amount = 0;
     if (controller != null) {
       for (UUID playerId : controller.getInRange()) {
         Player player = game.getPlayer(playerId);
         if (player != null) {
           amount += player.getGraveyard().getCards(filter, game).size();
         }
       }
     }
     ((DynamicTargetCreaturePermanent) target).setMaxNumberOfTargets(amount + 1);
   }
 }
Ejemplo n.º 21
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;
 }
Ejemplo n.º 22
0
  @Override
  public boolean apply(Game game, Ability source) {

    Player player = game.getPlayer(source.getControllerId());

    for (Card card : player.getGraveyard().getCards(filterZombie, game)) {
      card.putOntoBattlefield(game, Zone.GRAVEYARD, source.getSourceId(), source.getControllerId());
      Permanent permanent = game.getPermanent(card.getId());
      if (permanent != null) {
        permanent.setTapped(true);
      }
    }
    for (Permanent permanent :
        game.getBattlefield().getActivePermanents(filterHuman, source.getControllerId(), game)) {
      permanent.destroy(source.getSourceId(), game, false);
    }
    return true;
  }
Ejemplo n.º 23
0
  public String getValue(boolean useHidden) {
    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.getLife()).append("hand");
      if (useHidden) {
        sb.append(player.getHand());
      } else {
        sb.append(player.getHand().size());
      }
      sb.append("library")
          .append(player.getLibrary().size())
          .append("graveyard")
          .append(player.getGraveyard());
    }

    sb.append("permanents");
    for (Permanent permanent : battlefield.getAllPermanents()) {
      sb.append(permanent.getValue());
    }

    sb.append("spells");
    for (StackObject spell : stack) {
      sb.append(spell.getControllerId()).append(spell.getName());
    }

    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();
  }
Ejemplo n.º 24
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player controller = game.getPlayer(source.getControllerId());
   if (controller != null) {
     for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
       Player player = game.getPlayer(playerId);
       if (player != null) {
         for (Card card : player.getHand().getCards(game)) {
           card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
         }
         for (Card card : player.getGraveyard().getCards(game)) {
           card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
         }
         player.shuffleLibrary(source, game);
       }
     }
     controller.drawCards(7, game);
     return true;
   }
   return false;
 }
Ejemplo n.º 25
0
 @Override
 public boolean apply(Game game, Ability source) {
   Player targetPlayer = game.getPlayer(source.getFirstTarget());
   Player controller = game.getPlayer(source.getControllerId());
   if (targetPlayer != null && controller != null) {
     TargetCardInYourGraveyard target = new TargetCardInYourGraveyard();
     target.setRequired(true);
     if (targetPlayer.chooseTarget(Outcome.Exile, target, source, game)) {
       Card card = game.getCard(target.getFirstTarget());
       if (card != null) {
         targetPlayer.getGraveyard().remove(card);
         card.moveToExile(null, "", source.getId(), game);
         if (card.getCardType().contains(CardType.CREATURE)) {
           controller.gainLife(2, game);
         }
       }
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 26
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;
  }
Ejemplo n.º 27
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();
  }
  public boolean applySearchAndExile(
      Game game, Ability source, String cardName, UUID targetPlayerId) {
    Player player = game.getPlayer(source.getControllerId());
    if (cardName != null && player != null) {
      Player targetPlayer = game.getPlayer(targetPlayerId);
      if (targetPlayer != null) {
        FilterCard filter = new FilterCard("card named " + cardName);
        filter.add(new NamePredicate(cardName));

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

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

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

      targetPlayer.shuffleLibrary(game);

      return true;
    }

    return false;
  }