Search in sources :

Example 56 with SOCPlayer

use of soc.game.SOCPlayer in project JSettlers2 by jdmonin.

the class SOCServerMessageHandler method handleCHANGEFACE.

// / General messages during a game ///
/**
 * handle "change face" message.
 *
 * @param c  the connection
 * @param mes  the message
 * @since 1.0.0
 */
private void handleCHANGEFACE(Connection c, final SOCChangeFace mes) {
    final String gaName = mes.getGame();
    final SOCGame ga = gameList.getGameData(gaName);
    if (ga == null)
        return;
    SOCPlayer player = ga.getPlayer(c.getData());
    if (player == null)
        return;
    final int id = mes.getFaceId();
    if ((id <= 0) && !player.isRobot())
        // only bots should use bot icons
        return;
    player.setFaceId(id);
    srv.messageToGame(gaName, new SOCChangeFace(gaName, player.getPlayerNumber(), id));
}
Also used : SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame)

Example 57 with SOCPlayer

use of soc.game.SOCPlayer in project JSettlers2 by jdmonin.

the class SOCServerMessageHandler method processDebugCommand_gameStats.

/**
 * Print time-remaining and other game stats.
 * Includes more detail beyond the end-game stats sent in {@link SOCGameHandler#sendGameStateOVER(SOCGame)}.
 *<P>
 * Before v1.1.20, this method was {@code processDebugCommand_checktime(..)}.
 *
 * @param c  Client requesting the stats
 * @param gaName  {@code gameData.getName()}
 * @param gameData  Game to print stats
 * @param isCheckTime  True if called from *CHECKTIME* server command, false for *STATS*.
 *     If true, mark text as urgent when sending remaining time before game expires.
 * @since 1.1.07
 */
void processDebugCommand_gameStats(Connection c, final String gaName, SOCGame gameData, final boolean isCheckTime) {
    if (gameData == null)
        return;
    // "-- Game statistics: --"
    srv.messageToPlayerKeyed(c, gaName, "stats.game.title");
    // Rounds played: 20
    srv.messageToPlayerKeyed(c, gaName, "stats.game.rounds", gameData.getRoundCount());
    // player's stats
    if (c.getVersion() >= SOCPlayerStats.VERSION_FOR_RES_ROLL) {
        SOCPlayer cp = gameData.getPlayer(c.getData());
        if (cp != null)
            srv.messageToPlayer(c, new SOCPlayerStats(cp, SOCPlayerStats.STYPE_RES_ROLL));
    }
    // time
    Date gstart = gameData.getStartTime();
    if (gstart != null) {
        long gameSeconds = ((new Date().getTime() - gstart.getTime()) + 500L) / 1000L;
        long gameMinutes = (gameSeconds + 29L) / 60L;
        // "This game started 5 minutes ago."
        srv.messageToPlayerKeyed(c, gaName, "stats.game.startedago", gameMinutes);
    // Ignore possible "1 minutes"; that game is too short to worry about.
    }
    if (// practice games don't expire
    !gameData.isPractice) {
        // If isCheckTime, use ">>>" in message text to mark as urgent:
        // ">>> This game will expire in 15 minutes."
        srv.messageToPlayerKeyed(c, gaName, ((isCheckTime) ? "stats.game.willexpire.urgent" : "stats.game.willexpire"), Integer.valueOf((int) ((gameData.getExpiration() - System.currentTimeMillis()) / 60000)));
    }
}
Also used : SOCPlayer(soc.game.SOCPlayer) Date(java.util.Date)

Example 58 with SOCPlayer

use of soc.game.SOCPlayer in project JSettlers2 by jdmonin.

the class SOCServerMessageHandler method handleSETSEATLOCK.

/**
 * handle "set seat lock" message.
 *
 * @param c  the connection
 * @param mes  the message
 * @since 1.0.0
 */
private void handleSETSEATLOCK(Connection c, final SOCSetSeatLock mes) {
    final SOCGame.SeatLockState sl = mes.getLockState();
    final String gaName = mes.getGame();
    SOCGame ga = gameList.getGameData(gaName);
    if (ga == null)
        return;
    SOCPlayer player = ga.getPlayer(c.getData());
    if (player == null)
        return;
    try {
        final int pn = mes.getPlayerNumber();
        ga.setSeatLock(pn, sl);
        if ((sl != SOCGame.SeatLockState.CLEAR_ON_RESET) || (ga.clientVersionLowest >= 2000)) {
            srv.messageToGame(gaName, mes);
        } else {
            // older clients won't recognize that lock state
            srv.messageToGameForVersions(ga, 2000, Integer.MAX_VALUE, mes, true);
            srv.messageToGameForVersions(ga, -1, 1999, new SOCSetSeatLock(gaName, pn, SOCGame.SeatLockState.LOCKED), true);
        }
    } catch (IllegalStateException e) {
        // "Cannot set that lock right now."
        srv.messageToPlayerKeyed(c, gaName, "reply.lock.cannot");
    }
}
Also used : SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame)

Example 59 with SOCPlayer

use of soc.game.SOCPlayer in project JSettlers2 by jdmonin.

the class SOCGameBoardReset method sortPlayerConnections.

/**
 * Grab connection information for this game's humans and robots.
 * memberConns is from _old_ game, so robots are included.
 * Robots aren't copied to the new game, and must re-join.
 *<P>
 * Two modes:
 *<P>
 * If currently copying a game, assumes newGame is from oldGame via {@link SOCGame#resetAsCopy()},
 * and newGame contains only the human players, oldGame contains all human and robot players.
 *<P>
 * If not copying a game, only inspecting one, then oldGame is null, and assumes newGame has all
 * players (both human and robot).
 *
 * @param newGame New game (if resetting), or only game
 * @param oldGame Old game (if resetting), or null
 * @param memberConns Members of old game, from {@link soc.server.SOCGameListAtServer#getMembers(String)};
 *                   a Vector of {@link Connection}s
 * @param humanConns New array to fill with human players; indexed 0 to SOCGame.MAXPLAYERS-1.
 *                   humanConns[pn] will be the human player at position pn, or null.
 * @param robotConns New array to fill with robot players; indexed 0 to SOCGame.MAXPLAYERS-1.
 *                   robotConns[pn] will be the robot player at position pn, or null.
 *
 * @return The number of human players in newGame
 */
public static int sortPlayerConnections(SOCGame newGame, SOCGame oldGame, Vector<Connection> memberConns, Connection[] humanConns, Connection[] robotConns) {
    // This enum is easier than enumerating all connected clients;
    // there is no server-wide mapping of clientname -> connection.
    int numHuman = 0;
    Enumeration<Connection> playersEnum = memberConns.elements();
    while (playersEnum.hasMoreElements()) {
        Connection pCon = playersEnum.nextElement();
        String pname = pCon.getData();
        SOCPlayer p = newGame.getPlayer(pname);
        if (p != null) {
            int pn = p.getPlayerNumber();
            if (p.isRobot())
                robotConns[pn] = pCon;
            else {
                humanConns[pn] = pCon;
                ++numHuman;
            }
        } else if (oldGame != null) {
            // No such player in new game.
            // Assume is robot player in old game.
            p = oldGame.getPlayer(pname);
            if (p != null) {
                int pn = p.getPlayerNumber();
                if (p.isRobot())
                    robotConns[pn] = pCon;
                else
                    // should not happen
                    D.ebugPrintln("findPlayerConnections assert failed: human player not copied: " + pn);
            }
        }
    }
    // Check all player positions after enum
    for (int pn = 0; pn < newGame.maxPlayers; ++pn) {
        if (!newGame.isSeatVacant(pn)) {
            if ((humanConns[pn] == null) && (robotConns[pn] == null))
                D.ebugPrintln("findPlayerConnections assert failed: did not find player " + pn);
        } else {
            if ((humanConns[pn] != null) || ((robotConns[pn] != null) && ((oldGame == null) || oldGame.isSeatVacant(pn))))
                D.ebugPrintln("findPlayerConnections assert failed: memberlist had vacant player " + pn);
        }
    }
    return numHuman;
}
Also used : Connection(soc.server.genericServer.Connection) SOCPlayer(soc.game.SOCPlayer)

Example 60 with SOCPlayer

use of soc.game.SOCPlayer in project JSettlers2 by jdmonin.

the class SOCPlayerClient method updateGameEndStats.

/**
 * If we're playing in a game that's just finished, update the scores.
 *  This is used to show the true scores, including hidden
 *  victory-point cards, at the game's end.
 *  @since 1.1.00
 */
public void updateGameEndStats(String game, final int[] scores) {
    SOCGame ga = games.get(game);
    if (ga == null)
        // Not playing in that game
        return;
    if (ga.getGameState() != SOCGame.OVER) {
        System.err.println("L4044: pcli.updateGameEndStats called at state " + ga.getGameState());
        // Should not have been sent; game is not yet over.
        return;
    }
    PlayerClientListener pcl = clientListeners.get(game);
    if (pcl == null)
        return;
    Map<SOCPlayer, Integer> scoresMap = new HashMap<SOCPlayer, Integer>();
    for (int i = 0; i < scores.length; ++i) {
        scoresMap.put(ga.getPlayer(i), Integer.valueOf(scores[i]));
    }
    pcl.gameEnded(scoresMap);
}
Also used : HashMap(java.util.HashMap) SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame)

Aggregations

SOCPlayer (soc.game.SOCPlayer)61 SOCGame (soc.game.SOCGame)17 SOCShip (soc.game.SOCShip)12 SOCSettlement (soc.game.SOCSettlement)11 SOCRoad (soc.game.SOCRoad)9 SOCResourceSet (soc.game.SOCResourceSet)8 SOCCity (soc.game.SOCCity)7 SOCBoardLarge (soc.game.SOCBoardLarge)6 SOCFortress (soc.game.SOCFortress)5 ArrayList (java.util.ArrayList)4 SOCBoard (soc.game.SOCBoard)4 Connection (soc.server.genericServer.Connection)4 SOCInventoryItem (soc.game.SOCInventoryItem)3 SOCVillage (soc.game.SOCVillage)3 SQLException (java.sql.SQLException)2 Iterator (java.util.Iterator)2 Stack (java.util.Stack)2 SOCLRPathData (soc.game.SOCLRPathData)2 SOCPlayingPiece (soc.game.SOCPlayingPiece)2 SOCSpecialItem (soc.game.SOCSpecialItem)2