コード例 #1
0
ファイル: TableManager.java プロジェクト: heron-da-cruz/mage
  public void removeTable(UUID tableId) {
    if (tables.containsKey(tableId)) {

      TableController tableController = controllers.get(tableId);
      if (tableController != null) {
        controllers.remove(tableId);
        tableController.cleanUp();
      }

      Table table = tables.get(tableId);
      tables.remove(tableId);

      // If table is not finished, the table has to be removed completly (if finished it will be
      // removed in GamesRoomImpl.Update())
      if (!table.getState().equals(TableState.FINISHED)) {
        GamesRoomManager.getInstance().removeTable(tableId);
      }
      if (table.getMatch() != null && table.getMatch().getGame() != null) {
        table.getMatch().getGame().end();
      }
    }
  }
コード例 #2
0
ファイル: TableController.java プロジェクト: magefree/mage
 public synchronized boolean submitDeck(UUID userId, DeckCardLists deckList) throws MageException {
   UUID playerId = userPlayerMap.get(userId);
   if (table.isTournament()) {
     TournamentPlayer player = tournament.getPlayer(playerId);
     if (player == null || player.hasQuit()) {
       return true; // so the construct panel closes after submit
     }
   } else if (table.getMatch() != null) {
     MatchPlayer mPlayer = table.getMatch().getPlayer(playerId);
     if (mPlayer == null || mPlayer.hasQuit()) {
       return true; // so the construct panel closes after submit
     }
     if (table.isTournamentSubTable()) {
       TournamentPlayer tournamentPlayer =
           table.getTournament().getPlayer(mPlayer.getPlayer().getId());
       if (tournamentPlayer != null) {
         tournamentPlayer.setStateInfo(""); // reset sideboarding state
       }
     }
   }
   if (table.getState() != TableState.SIDEBOARDING
       && table.getState() != TableState.CONSTRUCTING) {
     return false;
   }
   Deck deck = Deck.load(deckList, false, false);
   if (table.getState() == TableState.SIDEBOARDING && table.getMatch() != null) {
     MatchPlayer mPlayer = table.getMatch().getPlayer(playerId);
     if (mPlayer != null) {
       deck.setName(mPlayer.getDeck().getName());
     }
   }
   if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
     throw new InvalidDeckException(
         "Invalid deck for this format", table.getValidator().getInvalid());
   }
   submitDeck(userId, playerId, deck);
   return true;
 }
コード例 #3
0
ファイル: TableController.java プロジェクト: magefree/mage
  public synchronized boolean joinTable(
      UUID userId,
      String name,
      String playerType,
      int skill,
      DeckCardLists deckList,
      String password)
      throws MageException {
    User user = UserManager.getInstance().getUser(userId);
    if (user == null) {
      return false;
    }
    if (userPlayerMap.containsKey(userId) && playerType.equals("Human")) {
      user.showUserMessage(
          "Join Table", new StringBuilder("You can join a table only one time.").toString());
      return false;
    }
    if (table.getState() != TableState.WAITING) {
      user.showUserMessage("Join Table", "No available seats.");
      return false;
    }
    // check password
    if (!table.getMatch().getOptions().getPassword().isEmpty() && playerType.equals("Human")) {
      if (!table.getMatch().getOptions().getPassword().equals(password)) {
        user.showUserMessage("Join Table", "Wrong password.");
        return false;
      }
    }
    Seat seat = table.getNextAvailableSeat(playerType);
    if (seat == null) {
      user.showUserMessage("Join Table", "No available seats.");
      return false;
    }
    Deck deck = Deck.load(deckList, false, false);

    if (!Main.isTestMode() && !table.getValidator().validate(deck)) {
      StringBuilder sb =
          new StringBuilder("You (")
              .append(name)
              .append(") have an invalid deck for the selected ")
              .append(table.getValidator().getName())
              .append(" Format. \n\n");
      for (Map.Entry<String, String> entry : table.getValidator().getInvalid().entrySet()) {
        sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
      }
      sb.append("\n\nSelect a deck that is appropriate for the selected format and try again!");
      user.showUserMessage("Join Table", sb.toString());
      if (isOwner(userId)) {
        logger.debug(
            "New table removed because owner submitted invalid deck tableId " + table.getId());
        TableManager.getInstance().removeTable(table.getId());
      }
      return false;
    }
    // Check quit ratio.
    int quitRatio = table.getMatch().getOptions().getQuitRatio();
    if (quitRatio < user.getMatchQuitRatio()) {
      String message =
          new StringBuilder("Your quit ratio ")
              .append(user.getMatchQuitRatio())
              .append("% is higher than the table requirement ")
              .append(quitRatio)
              .append("%")
              .toString();
      user.showUserMessage("Join Table", message);
      return false;
    }

    // Check power level for table (currently only used for EDH/Commander table)
    int edhPowerLevel = table.getMatch().getOptions().getEdhPowerLevel();
    if (edhPowerLevel > 0 && table.getValidator().getName().toLowerCase().equals("commander")) {
      int deckEdhPowerLevel = table.getValidator().getEdhPowerLevel(deck);
      if (deckEdhPowerLevel > edhPowerLevel) {
        String message =
            new StringBuilder(
                    "Your deck appears to be too powerful for this table.\n\nReduce the number of extra turn cards, infect, counters, fogs, reconsider your commander. ")
                .append("\nThe table requirement has a maximum power level of ")
                .append(edhPowerLevel)
                .append(" whilst your deck has a calculated power level of ")
                .append(deckEdhPowerLevel)
                .toString();
        user.showUserMessage("Join Table", message);
        return false;
      }
    }

    Player player = createPlayer(name, seat.getPlayerType(), skill);
    if (player == null) {
      String message =
          new StringBuilder("Could not create player ")
              .append(name)
              .append(" of type ")
              .append(seat.getPlayerType())
              .toString();
      logger.warn(
          new StringBuilder("User: "******" => ")
              .append(message)
              .toString());
      user.showUserMessage("Join Table", message);
      return false;
    }
    logger.debug(
        "DECK validated: "
            + table.getValidator().getName()
            + " "
            + player.getName()
            + " "
            + deck.getName());
    if (!player.canJoinTable(table)) {
      user.showUserMessage(
          "Join Table",
          new StringBuilder("A ")
              .append(seat.getPlayerType())
              .append(" player can't join this table.")
              .toString());
      return false;
    }
    match.addPlayer(player, deck);
    table.joinTable(player, seat);
    logger.trace(player.getName() + " joined tableId: " + table.getId());
    // only inform human players and add them to sessionPlayerMap
    if (seat.getPlayer().isHuman()) {
      seat.getPlayer().setUserData(user.getUserData());
      if (!table.isTournamentSubTable()) {
        user.addTable(player.getId(), table);
      }
      user.ccJoinedTable(table.getRoomId(), table.getId(), false);
      userPlayerMap.put(userId, player.getId());
    }
    return true;
  }