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