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);
}
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);
}
}
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]);
}
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());
}
}
}
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} >= 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);
}
}
Aggregations