Search in sources :

Example 31 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleINVENTORYITEMACTION.

/**
 * Handle the "inventory item action" message by updating player inventory.
 * @param games  The hashtable of client's {@link SOCGame}s; key = game name
 * @param mes  the message
 * @return  True if this message is a "cannot play this type now" from server for our client player.
 * @since 2.0.00
 */
public static boolean handleINVENTORYITEMACTION(Hashtable<String, SOCGame> games, SOCInventoryItemAction mes) {
    SOCGame ga = games.get(mes.getGame());
    if (ga == null)
        return false;
    if ((mes.playerNumber == -1) || (mes.action == SOCInventoryItemAction.CANNOT_PLAY))
        return true;
    SOCPlayer pl = ga.getPlayer(mes.playerNumber);
    if (pl == null)
        return false;
    SOCInventory inv = pl.getInventory();
    SOCInventoryItem item = null;
    switch(mes.action) {
        case SOCInventoryItemAction.ADD_PLAYABLE:
        case SOCInventoryItemAction.ADD_OTHER:
            inv.addItem(SOCInventoryItem.createForScenario(ga, mes.itemType, (mes.action == SOCInventoryItemAction.ADD_PLAYABLE), mes.isKept, mes.isVP, mes.canCancelPlay));
            break;
        case SOCInventoryItemAction.PLAYED:
            if (mes.isKept)
                inv.keepPlayedItem(mes.itemType);
            else
                item = inv.removeItem(SOCInventory.PLAYABLE, mes.itemType);
            if (!SOCInventoryItem.isPlayForPlacement(ga, mes.itemType))
                break;
        case SOCInventoryItemAction.PLACING_EXTRA:
            if (item == null)
                item = SOCInventoryItem.createForScenario(ga, mes.itemType, true, mes.isKept, mes.isVP, mes.canCancelPlay);
            ga.setPlacingItem(item);
            break;
    }
    return false;
}
Also used : SOCInventoryItem(soc.game.SOCInventoryItem) SOCInventory(soc.game.SOCInventory) SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame)

Example 32 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleCHANGEFACE.

/**
 * handle the "change face" message
 * @param mes  the message
 */
protected void handleCHANGEFACE(SOCChangeFace mes) {
    SOCGame ga = games.get(mes.getGame());
    if (ga != null) {
        SOCPlayer player = ga.getPlayer(mes.getPlayerNumber());
        player.setFaceId(mes.getFaceId());
    }
}
Also used : SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame)

Example 33 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleRESETBOARDAUTH.

/**
 * handle board reset
 * (new game with same players, same game name, new layout).
 * Create new Game object, destroy old one.
 * For human players, the reset message will be followed
 * with others which will fill in the game state.
 * For robots, they must discard game state and ask to re-join.
 *
 * @param mes  the message
 *
 * @see soc.server.SOCServer#resetBoardAndNotify(String, int)
 * @see soc.game.SOCGame#resetAsCopy()
 */
protected void handleRESETBOARDAUTH(SOCResetBoardAuth mes) {
    String gname = mes.getGame();
    SOCGame ga = games.get(gname);
    if (ga == null)
        // Not one of our games
        return;
    SOCGame greset = ga.resetAsCopy();
    greset.isPractice = ga.isPractice;
    games.put(gname, greset);
    ga.destroyGame();
}
Also used : SOCGame(soc.game.SOCGame)

Example 34 with SOCGame

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

the class SOCDisplaylessPlayerClient method handlePOTENTIALSETTLEMENTS.

/**
 * handle the "list of potential settlements" message
 * @param mes  the message
 * @param games  The hashtable of client's {@link SOCGame}s; key = game name
 * @throws IllegalStateException if the board has
 *     {@link SOCBoardLarge#getAddedLayoutPart(String) SOCBoardLarge.getAddedLayoutPart("AL")} != {@code null} but
 *     badly formed (node list number 0, or a node list number not followed by a land area number).
 *     This Added Layout Part is rarely used, and this would be discovered quickly while testing
 *     the board layout that contained it.
 */
public static void handlePOTENTIALSETTLEMENTS(SOCPotentialSettlements mes, Hashtable<String, SOCGame> games) throws IllegalStateException {
    SOCGame ga = games.get(mes.getGame());
    if (ga == null)
        return;
    final List<Integer> vset = mes.getPotentialSettlements();
    final HashSet<Integer>[] las = mes.landAreasLegalNodes;
    // must set for players after pl.setPotentialAndLegalSettlements, if not null
    final int[] loneSettles;
    // usually null, except in _SC_PIRI
    final int[][] legalSeaEdges = mes.legalSeaEdges;
    int pn = mes.getPlayerNumber();
    if (ga.hasSeaBoard) {
        SOCBoardLarge bl = ((SOCBoardLarge) ga.getBoard());
        if ((pn == -1) || ((pn == 0) && bl.getLegalSettlements().isEmpty()))
            bl.setLegalSettlements(vset, mes.startingLandArea, // throws IllegalStateException if board layout
            las);
        // has malformed Added Layout Part "AL"
        // usually null, except in _SC_PIRI
        loneSettles = bl.getAddedLayoutPart("LS");
    } else {
        loneSettles = null;
    }
    if (pn != -1) {
        SOCPlayer player = ga.getPlayer(pn);
        player.setPotentialAndLegalSettlements(vset, true, las);
        if (loneSettles != null)
            player.addLegalSettlement(loneSettles[pn], false);
        if (legalSeaEdges != null)
            player.setRestrictedLegalShips(legalSeaEdges[0]);
    } else {
        for (pn = ga.maxPlayers - 1; pn >= 0; --pn) {
            SOCPlayer pl = ga.getPlayer(pn);
            pl.setPotentialAndLegalSettlements(vset, true, las);
            if (loneSettles != null)
                pl.addLegalSettlement(loneSettles[pn], false);
            if (legalSeaEdges != null)
                pl.setRestrictedLegalShips(legalSeaEdges[pn]);
        }
    }
}
Also used : SOCBoardLarge(soc.game.SOCBoardLarge) SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame) HashSet(java.util.HashSet)

Example 35 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleBOARDLAYOUT.

/**
 * handle the "board layout" message
 * @param mes  the message
 */
protected void handleBOARDLAYOUT(SOCBoardLayout mes) {
    SOCGame ga = games.get(mes.getGame());
    if (ga != null) {
        // BOARDLAYOUT is always the v1 board encoding (oldest format)
        SOCBoard bd = ga.getBoard();
        bd.setHexLayout(mes.getHexLayout());
        bd.setNumberLayout(mes.getNumberLayout());
        bd.setRobberHex(mes.getRobberHex(), false);
        ga.updateAtBoardLayout();
    }
}
Also used : SOCBoard(soc.game.SOCBoard) 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