|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.message.SOCMessage soc.message.SOCInventoryItemAction
public class SOCInventoryItemAction
This message is a client player request, or server response or announcement,
about SOCInventoryItem
s in a player's inventory.
Inventory items are held by a player like SOCDevCard
s.
These special items are used by certain scenarios, and the meaning of
each one's itemType
is specific to the scenario.
An item's current state can be NEW and not yet playable; PLAYABLE now; or KEPT until end of game.
Possible message traffic, by action
:
ADD_PLAYABLE
, ADD_OTHER
PLAY
a playable item
CANNOT_PLAY
, optionally with a reasonCode
PLAYED
to all clients,
including all flags such as isKept
and canCancelPlay
.
Messages after that will indicate new game state or any other results of playing the item.
PLACING_EXTRA
to give the item details such as itemType
and canCancelPlay
.
Play/placement rules are specific to each kind of inventory action, and the PLACING_EXTRA
message may be sent before a game state change or other messages necessary for placement.
See PLACING_EXTRA
's javadoc for client handling.
SOCInventoryItemAction
, it doesn't also send a SOCGameServerText
explaining
the details; the client must print such text based on the SOCInventoryItemAction
received.
Based on SOCDevCardAction
.
_SC_FTRI
: Trade ports received as gifts. SOCGame.PLAY1
or SOCGame.SPECIAL_BUILDING
, current player sends this when they
have a port in their inventory. itemType
is the negative of the port type to play.
If they can place now, server broadcasts SOCInventoryItemAction(PLAYED
) to the game to remove
it from player's inventory, then sends SOCGameState
(PLACING_INV_ITEM
).
(Player interface shouldn't let them place before the new game state is sent.)
When the requesting client receives this PLAYED message, it will call SOCGame.setPlacingItem(SOCInventoryItem)
because SOCInventoryItem.isPlayForPlacement(SOCGame, int)
is true for _SC_FTRI
.
Otherwise, server responds with CANNOT_PLAY
with one of these reasonCode
s:
1 if the requested port type isn't in the player's inventory
2 if the game options don't permit moving trade ports
3 if the game state or current player aren't right to request placement now
4 if player's SOCPlayer.getPortMovePotentialLocations(boolean)
is null
The port may be placed immediately if the player puts a ship at its original location and has
a coastal settlement with room for a port. Such a port will never be in the player's inventory.
The server will immediately send that player PLACING_EXTRA
with the port's details;
see that action's javadoc for client handling of the message.
When the player chooses their placement location, they should send
SOCSimpleRequest
(TRADE_PORT_PLACE
).
See that constant's javadoc for details.
Field Summary | |
---|---|
int |
action
Action, such as ADD_PLAYABLE or PLAY |
static int |
ADD_OTHER
item action ADD_OTHER: From server, add as New or Kept to player's inventory, depending on whether this item's type is kept until end of game |
static int |
ADD_PLAYABLE
item action ADD_PLAYABLE: From server, add as Playable to player's inventory |
boolean |
canCancelPlay
If true, this item being added and its later play or placement can be canceled: SOCInventoryItem.canCancelPlay . |
static int |
CANNOT_PLAY
item action CANNOT_PLAY: From server, the player or bot can't play the requested item at this time. |
private static int |
FLAG_CANCPLAY
canCancelPlay flag position for sending over network in a bit field |
private static int |
FLAG_ISKEPT
isKept flag position for sending over network in a bit field |
private static int |
FLAG_ISVP
isVP flag position for sending over network in a bit field |
private java.lang.String |
game
Name of game; getter required by SOCMessageForGame |
boolean |
isKept
If true, this item being added is kept in inventory until end of game. |
boolean |
isVP
If true, this item being added is worth victory points. |
int |
itemType
The item type code, from SOCInventoryItem.itype |
static int |
PLACING_EXTRA
If some other game action or event causes an item to need placement on the board, but it was never in the player's inventory, server sends PLACING_EXTRA
to give the item details such as itemType and canCancelPlay . |
static int |
PLAY
item action PLAY: Client request to play a PLAYABLE item |
static int |
PLAYED
item action PLAYED: From server, item was played. |
int |
playerNumber
Player number, or -1 for action CANNOT_PLAY |
int |
reasonCode
Optional reason codes for the CANNOT_PLAY action, corresponding
to SOCGame.canPlayInventoryItem(int, int) return codes, or 0. |
private static long |
serialVersionUID
|
Constructor Summary | |
---|---|
SOCInventoryItemAction(java.lang.String ga,
int pn,
int ac,
int it)
Create an InventoryItemAction message, skipping the boolean flags. |
|
SOCInventoryItemAction(java.lang.String ga,
int pn,
int ac,
int it,
boolean kept,
boolean vp,
boolean canCancel)
Create an InventoryItemAction message, with any possible flags. |
|
SOCInventoryItemAction(java.lang.String ga,
int pn,
int ac,
int it,
int rc)
Create an InventoryItemAction message, with optional reasonCode . |
Method Summary | |
---|---|
java.lang.String |
getGame()
Name of game this message is for. |
static SOCInventoryItemAction |
parseDataStr(java.lang.String s)
Parse the command String into an InventoryItemAction message. |
java.lang.String |
toCmd()
INVENTORYITEMACTION sep game sep2 playerNumber sep2 action sep2 itemType [ sep2 rcode ] |
static java.lang.String |
toCmd(java.lang.String ga,
int pn,
int ac,
int it,
int rc)
INVENTORYITEMACTION sep game sep2 playerNumber sep2 action sep2 itemType [ sep2 rcode ] |
java.lang.String |
toString()
Simple human-readable representation, used for debug purposes. |
Methods inherited from class soc.message.SOCMessage |
---|
arrayIntoStringBuf, enumIntoStringBuf, getClassNameShort, getMaximumVersion, getMinimumVersion, getType, isSingleLineAndSafe, isSingleLineAndSafe, toMsg |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface soc.message.SOCMessageForGame |
---|
getType |
Field Detail |
---|
private static final long serialVersionUID
public static final int ADD_PLAYABLE
public static final int ADD_OTHER
public static final int PLAY
public static final int CANNOT_PLAY
public static final int PLAYED
isKept
flag to see if the item should be removed from inventory, or remain with state KEPT.
Call SOCInventoryItem.isPlayForPlacement(SOCGame, int)
: If true, playing this item requires placement;
client receiving the message should call SOCGame.setPlacingItem(SOCInventoryItem)
.
public static final int PLACING_EXTRA
PLACING_EXTRA
to give the item details such as itemType
and canCancelPlay
.
May be sent to entire game or just to the placing current player.
Play/placement rules are specific to each kind of inventory action, and the PLACING_EXTRA
message may be sent before a game state change or other messages necessary for placement. The client
handling PLACING_EXTRA
should call SOCGame.setPlacingItem(SOCInventoryItem)
and wait
for those other messages. When they arrive, client can call SOCGame.getPlacingItem()
to
retrieve the item details.
private static final int FLAG_ISKEPT
isKept
flag position for sending over network in a bit field
private static final int FLAG_ISVP
isVP
flag position for sending over network in a bit field
private static final int FLAG_CANCPLAY
canCancelPlay
flag position for sending over network in a bit field
private final java.lang.String game
SOCMessageForGame
public final int playerNumber
CANNOT_PLAY
public final int itemType
SOCInventoryItem.itype
public final int action
ADD_PLAYABLE
or PLAY
public final int reasonCode
CANNOT_PLAY
action, corresponding
to SOCGame.canPlayInventoryItem(int, int)
return codes, or 0.
Also used within this class to encode isKept
and isVP
over the network.
public final boolean isKept
PLAY
and CANNOT_PLAY
.
public final boolean isVP
PLAY
and CANNOT_PLAY
.
public final boolean canCancelPlay
SOCInventoryItem.canCancelPlay
.
This flag is sent for all actions except PLAY
and CANNOT_PLAY
.
Constructor Detail |
---|
public SOCInventoryItemAction(java.lang.String ga, int pn, int ac, int it)
If the action is to add a card with isKept
, isVP
, or canCancelPlay
, use
the SOCInventoryItemAction(String, int, int, int, boolean, boolean, boolean)
constructor instead.
If the action is the server replying with CANNOT_PLAY
with a reason code,
use the SOCInventoryItemAction(String, int, int, int, int)
constructor instead.
ga
- name of the gamepn
- the player number, or -1 for action type CANNOT_PLAY
ac
- the type of action, such as PLAY
it
- the item type code, from SOCInventoryItem.itype
public SOCInventoryItemAction(java.lang.String ga, int pn, int ac, int it, boolean kept, boolean vp, boolean canCancel)
reasonCode
will be 0.
ga
- name of the gamepn
- the player number, or -1 for action type CANNOT_PLAY
ac
- the type of action, such as ADD_PLAYABLE
or PLAYED
it
- the item type code, from SOCInventoryItem.itype
kept
- If true, this is an add or play message with the isKept
flag setvp
- If true, this is an add or play message with the isVP
flag setcanCancel
- If true, this is an add or play message with the canCancelPlay
flag setpublic SOCInventoryItemAction(java.lang.String ga, int pn, int ac, int it, int rc)
reasonCode
.
The isKept
, isVP
, and canCancelPlay
flags will be false.
ga
- name of the gamepn
- the player number, or -1 for action type CANNOT_PLAY
ac
- the type of action, such as ADD_PLAYABLE
it
- the item type code, from SOCInventoryItem.itype
rc
- reason code for reasonCode
, or 0Method Detail |
---|
public java.lang.String getGame()
SOCMessageForGame
null
if message is in per-game structures or code.
At the server, the message treater dispatches incoming SOCMessageForGame
s
based on their getGame()
:
null
: Message is ignored
SOCMessage.GAME_NONE
: Message is handled by SOCServer
itself
GameHandler
for that game's type. If no game with that name is found,
the message is ignored.
getGame
in interface SOCMessageForGame
SOCMessage.GAME_NONE
public java.lang.String toCmd()
toCmd
in class SOCMessage
public static java.lang.String toCmd(java.lang.String ga, int pn, int ac, int it, int rc)
ga
- the game namepn
- the player numberac
- the type of actionit
- the item type coderc
- the reason code if action == CANNOT_PLAY
public static SOCInventoryItemAction parseDataStr(java.lang.String s)
s
- the String to parse
public java.lang.String toString()
SOCMessage
toString
in class SOCMessage
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |