Search in sources :

Example 31 with SOCPlayer

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

the class SOCDisplaylessPlayerClient method handleREMOVEPIECE.

/**
 * A player's piece (a ship) has been removed from the board. Updates game state.
 *<P>
 * Currently, only ships can be removed, in game scenario {@code _SC_PIRI}.
 * Other {@code pieceType}s are ignored.
 * @since 2.0.00
 */
protected void handleREMOVEPIECE(SOCRemovePiece mes) {
    final String gaName = mes.getGame();
    SOCGame ga = games.get(gaName);
    if (ga == null)
        // Not one of our games
        return;
    SOCPlayer player = ga.getPlayer(mes.getParam1());
    final int pieceType = mes.getParam2();
    final int pieceCoordinate = mes.getParam3();
    switch(pieceType) {
        case SOCPlayingPiece.SHIP:
            ga.removeShip(new SOCShip(player, pieceCoordinate, null));
            break;
        default:
            System.err.println("Displayless.updateAtPieceRemoved called for un-handled type " + pieceType);
    }
}
Also used : SOCShip(soc.game.SOCShip) SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame)

Example 32 with SOCPlayer

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

the class SOCDisplaylessPlayerClient method handleDEVCARDACTION.

/**
 * handle the "development card action" message
 * @param isPractice  Is the server local, or remote?  Client can be connected
 *                only to local, or remote.
 * @param mes  the message
 */
protected void handleDEVCARDACTION(final boolean isPractice, final SOCDevCardAction mes) {
    SOCGame ga = games.get(mes.getGame());
    if (ga != null) {
        SOCPlayer player = ga.getPlayer(mes.getPlayerNumber());
        int ctype = mes.getCardType();
        if ((!isPractice) && (sVersion < SOCDevCardConstants.VERSION_FOR_NEW_TYPES)) {
            if (ctype == SOCDevCardConstants.KNIGHT_FOR_VERS_1_X)
                ctype = SOCDevCardConstants.KNIGHT;
            else if (ctype == SOCDevCardConstants.UNKNOWN_FOR_VERS_1_X)
                ctype = SOCDevCardConstants.UNKNOWN;
        }
        switch(mes.getAction()) {
            case SOCDevCardAction.DRAW:
                player.getInventory().addDevCard(1, SOCInventory.NEW, ctype);
                break;
            case SOCDevCardAction.PLAY:
                player.getInventory().removeDevCard(SOCInventory.OLD, ctype);
                break;
            case SOCDevCardAction.ADD_OLD:
                player.getInventory().addDevCard(1, SOCInventory.OLD, ctype);
                break;
            case SOCDevCardAction.ADD_NEW:
                player.getInventory().addDevCard(1, SOCInventory.NEW, ctype);
                break;
        }
    }
}
Also used : SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame)

Example 33 with SOCPlayer

use of soc.game.SOCPlayer 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 34 with SOCPlayer

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

the class SOCDisplaylessPlayerClient method handleDICERESULTRESOURCES.

/**
 * Handle all players' dice roll result resources: static version to share with SOCPlayerClient.
 * Game players gain resources.
 * @param mes  Message data
 * @param ga  Game to update
 * @param nickname  Our client player's nickname, needed for element data update
 * @param skipResourceCount  If true, ignore the resource part of the message
 *     because caller will handle that separately.
 * @since 2.0.00
 */
public static final void handleDICERESULTRESOURCES(final SOCDiceResultResources mes, final SOCGame ga, final String nickname, final boolean skipResourceCount) {
    final int n = mes.playerNum.size();
    for (// current index reading from playerNum and playerRsrc
    int p = 0; // current index reading from playerNum and playerRsrc
    p < n; // current index reading from playerNum and playerRsrc
    ++p) {
        final SOCResourceSet rs = mes.playerRsrc.get(p);
        final int pn = mes.playerNum.get(p);
        final SOCPlayer pl = ga.getPlayer(pn);
        pl.getResources().add(rs);
        if (!skipResourceCount)
            handlePLAYERELEMENT_simple(ga, pl, pn, SOCPlayerElement.SET, SOCPlayerElement.RESOURCE_COUNT, mes.playerResTotal.get(p), nickname);
    }
}
Also used : SOCResourceSet(soc.game.SOCResourceSet) SOCPlayer(soc.game.SOCPlayer)

Example 35 with SOCPlayer

use of soc.game.SOCPlayer 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)

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