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