Search in sources :

Example 46 with SOCGame

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

the class SOCDisplaylessPlayerClient method handlePLAYERELEMENTS.

/**
 * Handle the PlayerElements message: Finds game by name, and loops calling
 * {@link #handlePLAYERELEMENT(SOCGame, SOCPlayer, int, int, int, int)}.
 * @param mes  the message
 * @since 2.0.00
 */
protected void handlePLAYERELEMENTS(final SOCPlayerElements mes) {
    final SOCGame ga = games.get(mes.getGame());
    if (ga == null)
        return;
    final int pn = mes.getPlayerNumber();
    final SOCPlayer pl = (pn != -1) ? ga.getPlayer(pn) : null;
    final int action = mes.getAction();
    final int[] etypes = mes.getElementTypes(), amounts = mes.getAmounts();
    for (int i = 0; i < etypes.length; ++i) handlePLAYERELEMENT(ga, pl, pn, action, etypes[i], amounts[i], nickname);
}
Also used : SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame)

Example 47 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleMAKEOFFER.

/**
 * handle the "make offer" message
 * @param mes  the message
 */
protected void handleMAKEOFFER(SOCMakeOffer mes) {
    SOCGame ga = games.get(mes.getGame());
    if (ga != null) {
        SOCTradeOffer offer = mes.getOffer();
        ga.getPlayer(offer.getFrom()).setCurrentOffer(offer);
    }
}
Also used : SOCTradeOffer(soc.game.SOCTradeOffer) SOCGame(soc.game.SOCGame)

Example 48 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleGAMEELEMENTS.

/**
 * Handle the GameElements message: Finds game by name, and loops calling
 * {@link #handleGAMEELEMENT(SOCGame, int, int)}.
 * @param mes  the message
 * @since 2.0.00
 */
protected void handleGAMEELEMENTS(final SOCGameElements mes) {
    final SOCGame ga = games.get(mes.getGame());
    if (ga == null)
        return;
    final int[] etypes = mes.getElementTypes(), values = mes.getValues();
    for (int i = 0; i < etypes.length; ++i) handleGAMEELEMENT(ga, etypes[i], values[i]);
}
Also used : SOCGame(soc.game.SOCGame)

Example 49 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleLEAVEGAME.

/**
 * handle the "leave game" message
 * @param mes  the message
 */
protected void handleLEAVEGAME(SOCLeaveGame mes) {
    String gn = (mes.getGame());
    SOCGame ga = games.get(gn);
    if (ga != null) {
        SOCPlayer player = ga.getPlayer(mes.getNickname());
        if (player != null) {
            // 
            // This user was not a spectator
            // 
            ga.removePlayer(mes.getNickname());
        }
    }
}
Also used : SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame)

Example 50 with SOCGame

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

the class SOCDisplaylessPlayerClient method handleSIMPLEREQUEST.

/**
 * Update any game data from "simple request" announcements from the server.
 * Currently ignores them except for:
 *<UL>
 * <LI> {@link SOCSimpleRequest#TRADE_PORT_PLACE TRADE_PORT_PLACE}:
 *     Calls {@link SOCGame#placePort(SOCPlayer, int, int)} if {@code pn} &gt;= 0
 *</UL>
 *
 * @param games  Games the client is playing, for method reuse by SOCPlayerClient
 * @param mes  the message
 * @since 2.0.00
 */
public static void handleSIMPLEREQUEST(final Map<String, SOCGame> games, final SOCSimpleRequest mes) {
    final String gaName = mes.getGame();
    SOCGame ga = games.get(gaName);
    if (ga == null)
        // Not one of our games
        return;
    final int pn = mes.getPlayerNumber(), rtype = mes.getRequestType(), value1 = mes.getValue1(), value2 = mes.getValue2();
    switch(rtype) {
        case SOCSimpleRequest.TRADE_PORT_PLACE:
            if (// if pn -1, request was rejected
            pn >= 0)
                ga.placePort(ga.getPlayer(pn), value1, value2);
        case SOCSimpleRequest.PROMPT_PICK_RESOURCES:
        case SOCSimpleRequest.SC_PIRI_FORT_ATTACK:
            break;
        default:
            // Ignore unknown types.
            // Since the bots and server are almost always the same version, this
            // shouldn't often occur: print for debugging.
            System.err.println("DPC.handleSIMPLEREQUEST: Unknown type ignored: " + rtype + " in game " + gaName);
    }
}
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