Пример #1
0
  /**
   * @param game
   * @param source
   * @return
   */
  @Override
  public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
    if (!this.hasSourceObjectAbility(game, source, event)) {
      return false;
    }
    if (zone.equals(Zone.COMMAND)) {
      if (this.getSourceId() == null) { // commander effects
        return true;
      }
      MageObject object = game.getObject(this.getSourceId());
      // emblem are always actual
      if (object != null && object instanceof Emblem) {
        return true;
      }
    }

    UUID parameterSourceId;
    // for singleton abilities like Flying we can't rely on abilities' source because it's only once
    // in continuous effects
    // so will use the sourceId of the object itself that came as a parameter if it is not null
    if (this instanceof MageSingleton && source != null) {
      parameterSourceId = source.getId();
    } else {
      parameterSourceId = getSourceId();
    }
    // check agains shortLKI for effects that move multiple object at the same time (e.g. destroy
    // all)
    if (game.getShortLivingLKI(getSourceId(), getZone())) {
      return true;
    }
    // check against current state
    Zone test = game.getState().getZone(parameterSourceId);
    return test != null && zone.match(test);
  }
Пример #2
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;
 }
Пример #3
0
  private void parseLine(String line) {
    if (parserState.equals(ParserState.EXPECTED)) {
      expectedResults.add(line); // just remember for future use
      return;
    }

    Matcher m = pattern.matcher(line);
    if (m.matches()) {

      String zone = m.group(1);
      String nickname = m.group(2);

      if (nickname.equals("ComputerA") || nickname.equals("ComputerB")) {
        List<Card> cards = null;
        List<PermanentCard> perms = null;
        Zone gameZone;
        if ("hand".equalsIgnoreCase(zone)) {
          gameZone = Zone.HAND;
          cards = nickname.equals("ComputerA") ? handCardsA : handCardsB;
        } else if ("battlefield".equalsIgnoreCase(zone)) {
          gameZone = Zone.BATTLEFIELD;
          perms = nickname.equals("ComputerA") ? battlefieldCardsA : battlefieldCardsB;
        } else if ("graveyard".equalsIgnoreCase(zone)) {
          gameZone = Zone.GRAVEYARD;
          cards = nickname.equals("ComputerA") ? graveyardCardsA : graveyardCardsB;
        } else if ("library".equalsIgnoreCase(zone)) {
          gameZone = Zone.LIBRARY;
          cards = nickname.equals("ComputerA") ? libraryCardsA : libraryCardsB;
        } else if ("player".equalsIgnoreCase(zone)) {
          String command = m.group(3);
          if ("life".equals(command)) {
            if (nickname.equals("ComputerA")) {
              commandsA.put(Zone.OUTSIDE, "life:" + m.group(4));
            } else {
              commandsB.put(Zone.OUTSIDE, "life:" + m.group(4));
            }
          }
          return;
        } else {
          return; // go parse next line
        }

        String cardName = m.group(3);
        Integer amount = Integer.parseInt(m.group(4));
        boolean tapped = m.group(5) != null && m.group(5).equals(":{tapped}");

        if (cardName.equals("clear")) {
          if (nickname.equals("ComputerA")) {
            commandsA.put(gameZone, "clear");
          } else {
            commandsB.put(gameZone, "clear");
          }
        } else {
          for (int i = 0; i < amount; i++) {
            CardInfo cardInfo = CardRepository.instance.findCard(cardName);
            Card card = cardInfo != null ? cardInfo.getCard() : null;
            if (card != null) {
              if (gameZone.equals(Zone.BATTLEFIELD)) {
                PermanentCard p = new PermanentCard(card, null);
                p.setTapped(tapped);
                perms.add(p);
              } else {
                cards.add(card);
              }
            } else {
              logger.fatal("Couldn't find a card: " + cardName);
              logger.fatal("line: " + line);
            }
          }
        }
      } else {
        logger.warn("Unknown player: " + nickname);
      }
    } else {
      logger.warn("Init string wasn't parsed: " + line);
    }
  }