Search in sources :

Example 41 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleBOARDLAYOUT2.

/**
 * handle the "board layout" message, new format
 * @param games  Games the client is playing, for method reuse by SOCPlayerClient
 * @param mes  the message
 * @since 1.1.08
 * @return True if game was found and layout understood, false otherwise
 */
public static boolean handleBOARDLAYOUT2(Map<String, SOCGame> games, SOCBoardLayout2 mes) {
    SOCGame ga = games.get(mes.getGame());
    if (ga == null)
        return false;
    SOCBoard bd = ga.getBoard();
    final int bef = mes.getBoardEncodingFormat();
    if (bef == SOCBoard.BOARD_ENCODING_LARGE) {
        // v3
        ((SOCBoardLarge) bd).setLandHexLayout(mes.getIntArrayPart("LH"));
        ga.setPlayersLandHexCoordinates();
        int hex = mes.getIntPart("RH");
        if (hex != 0)
            bd.setRobberHex(hex, false);
        hex = mes.getIntPart("PH");
        if (hex != 0)
            ((SOCBoardLarge) bd).setPirateHex(hex, false);
        int[] portLayout = mes.getIntArrayPart("PL");
        if (portLayout != null)
            bd.setPortsLayout(portLayout);
        int[] x = mes.getIntArrayPart("PX");
        if (x != null)
            ((SOCBoardLarge) bd).setPlayerExcludedLandAreas(x);
        x = mes.getIntArrayPart("RX");
        if (x != null)
            ((SOCBoardLarge) bd).setRobberExcludedLandAreas(x);
        x = mes.getIntArrayPart("CV");
        if (x != null)
            ((SOCBoardLarge) bd).setVillageAndClothLayout(x);
        x = mes.getIntArrayPart("LS");
        if (x != null)
            ((SOCBoardLarge) bd).addLoneLegalSettlements(ga, x);
        HashMap<String, int[]> others = mes.getAddedParts();
        if (others != null)
            ((SOCBoardLarge) bd).setAddedLayoutParts(others);
    } else if (bef <= SOCBoard.BOARD_ENCODING_6PLAYER) {
        // v1 or v2
        bd.setHexLayout(mes.getIntArrayPart("HL"));
        bd.setNumberLayout(mes.getIntArrayPart("NL"));
        bd.setRobberHex(mes.getIntPart("RH"), false);
        int[] portLayout = mes.getIntArrayPart("PL");
        if (portLayout != null)
            bd.setPortsLayout(portLayout);
    } else {
        // Should not occur: Server has sent an unrecognized format
        System.err.println("Cannot recognize game encoding v" + bef + " for game " + ga.getName());
        return false;
    }
    ga.updateAtBoardLayout();
    return true;
}
Also used : SOCBoardLarge(soc.game.SOCBoardLarge) SOCBoard(soc.game.SOCBoard) SOCGame(soc.game.SOCGame)

Example 42 with SOCGame

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

the class SOCDisplaylessPlayerClient method handlePLAYERELEMENT.

/**
 * handle the "player information" message: Finds game by name and calls
 * {@link #handlePLAYERELEMENT(SOCGame, SOCPlayer, int, int, int, int)}.
 * @param mes  the message
 */
protected void handlePLAYERELEMENT(SOCPlayerElement mes) {
    final SOCGame ga = games.get(mes.getGame());
    if (ga == null)
        return;
    final int pn = mes.getPlayerNumber();
    final int action = mes.getAction(), amount = mes.getAmount();
    final int etype = mes.getElementType();
    handlePLAYERELEMENT(ga, null, pn, action, etype, amount, nickname);
}
Also used : SOCGame(soc.game.SOCGame)

Example 43 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleSETSPECIALITEM.

/**
 * Handle the "set special item" message.
 * This method handles only {@link SOCSetSpecialItem#OP_SET OP_SET} and {@link SOCSetSpecialItem#OP_CLEAR OP_CLEAR}
 * and ignores other operations, such as {@link SOCSetSpecialItem#OP_PICK OP_PICK}.  If your client needs to react
 * to those other operations, override this method.
 *
 * @param games  Games the client is playing, for method reuse by SOCPlayerClient
 * @param mes  the message
 * @since 2.0.00
 */
public static final void handleSETSPECIALITEM(final Map<String, SOCGame> games, SOCSetSpecialItem mes) {
    final SOCGame ga = games.get(mes.getGame());
    if (ga == null)
        return;
    final String typeKey = mes.typeKey;
    final int gi = mes.gameItemIndex, pi = mes.playerItemIndex, pn = mes.playerNumber;
    switch(mes.op) {
        case SOCSetSpecialItem.OP_CLEAR:
            {
                if (gi != -1)
                    ga.setSpecialItem(typeKey, gi, null);
                if ((pn != -1) && (pi != -1)) {
                    SOCPlayer pl = ga.getPlayer(pn);
                    if (pl != null)
                        pl.setSpecialItem(typeKey, pi, null);
                }
            }
            break;
        case SOCSetSpecialItem.OP_SET:
            {
                if ((gi == -1) && ((pi == -1) || (pn == -1))) {
                    // malformed message
                    return;
                }
                SOCSpecialItem item = ga.getSpecialItem(typeKey, gi, pi, pn);
                final SOCPlayer pl = (pn != -1) ? ga.getPlayer(pn) : null;
                if (item != null) {
                    item.setPlayer(pl);
                    item.setCoordinates(mes.coord);
                    item.setLevel(mes.level);
                    item.setStringValue(mes.sv);
                } else {
                    item = new SOCSpecialItem(pl, mes.coord, mes.level, mes.sv, null, null);
                }
                if (gi != -1) {
                    item.setGameIndex(gi);
                    ga.setSpecialItem(typeKey, gi, item);
                }
                if ((pi != -1) && (pl != null))
                    pl.setSpecialItem(typeKey, pi, item);
            }
            break;
    }
}
Also used : SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame) SOCSpecialItem(soc.game.SOCSpecialItem)

Example 44 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleSITDOWN.

/**
 * handle the "player sitting down" message
 * @param mes  the message
 */
protected void handleSITDOWN(SOCSitDown mes) {
    /**
     * tell the game that a player is sitting
     */
    SOCGame ga = games.get(mes.getGame());
    if (ga != null) {
        ga.takeMonitor();
        try {
            ga.addPlayer(mes.getNickname(), mes.getPlayerNumber());
            /**
             * set the robot flag
             */
            ga.getPlayer(mes.getPlayerNumber()).setRobotFlag(mes.isRobot(), false);
        } catch (Exception e) {
            ga.releaseMonitor();
            System.out.println("Exception caught - " + e);
            e.printStackTrace();
        }
        ga.releaseMonitor();
    }
}
Also used : SOCGame(soc.game.SOCGame) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 45 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleJOINGAMEAUTH.

/**
 * handle the "join game authorization" message
 * @param mes  the message
 * @param isPractice Is the server local for practice, or remote?
 */
protected void handleJOINGAMEAUTH(SOCJoinGameAuth mes, final boolean isPractice) {
    gotPassword = true;
    SOCGame ga = new SOCGame(mes.getGame());
    if (ga != null) {
        ga.isPractice = isPractice;
        games.put(mes.getGame(), ga);
    }
}
Also used : SOCGame(soc.game.SOCGame)

Aggregations

SOCGame (soc.game.SOCGame)60 SOCPlayer (soc.game.SOCPlayer)17 Connection (soc.server.genericServer.Connection)7 SOCBoardLarge (soc.game.SOCBoardLarge)5 MissingResourceException (java.util.MissingResourceException)3 Vector (java.util.Vector)3 SOCBoard (soc.game.SOCBoard)3 StringConnection (soc.server.genericServer.StringConnection)3 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 SOCResourceSet (soc.game.SOCResourceSet)2 SOCShip (soc.game.SOCShip)2 SOCTradeOffer (soc.game.SOCTradeOffer)2 SOCVillage (soc.game.SOCVillage)2 SOCGameBoardReset (soc.util.SOCGameBoardReset)2 Color (java.awt.Color)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1