|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.message.SOCMessage soc.message.SOCSetSpecialItem
public class SOCSetSpecialItem
This message is to pick, set, or clear a SOCSpecialItem
in the game and/or owning player's Special Item list.
Within the game data, items are held in per-game and/or per-player Special Item lists.
The message conveys which object is affected (typeKey
, gameItemIndex
, playerItemIndex
)
and the object data fields (playerNumber
, coord
, level
, sv
).
When a Special Item is held in the game's list and also its owning player's list,
the message can update both lists at once.
A client player can request that a player or game Special Item list index be picked, set, or cleared.
The server can decline that request, or announce a change or pick to all members of the game.
The server can also send a SOCSetSpecialItem
message when anything happens in-game that causes a change.
If the special item change has also caused a change to game state, the server will announce that
after sending the special item message(s).
In some scenarios, there may be a resource or other cost for picking, setting, or clearing an item. If so,
the server will check whether the requesting player can pay, and if so, the SOCSetSpecialItem
response
message(s) from the server will be preceded by SOCPlayerElement
messages reporting the player's losses to
pay the cost.
If client joins the game after it starts, these messages will be sent after the SOCBoardLayout2
message.
So, SOCGame.updateAtBoardLayout()
will have been called at the client and created Special Item objects
before any SOCSetSpecialItem
is received.
For message traffic/protocol details see OP_SET
, OP_CLEAR
, OP_PICK
and
OP_DECLINE
javadocs; client requests typically use OP_PICK
. For game details see
the SOCSpecialItem
class javadoc.
Field Summary | |
---|---|
int |
coord
Optional coordinates on the board for this item, or -1. |
static java.lang.String |
EMPTYSTR
Symbol to represent a null or empty string value, because empty pa[] elements can't be parsed over the network
with the current tokenizer. |
java.lang.String |
game
Name of game. |
int |
gameItemIndex
Index in the game's Special Item list, or -1. |
int |
level
Optional level of construction or strength, or 0. |
int |
op
The operation code: OP_SET , OP_CLEAR , OP_PICK or OP_DECLINE . |
static int |
OP_CLEAR
If sent from client to server, a request to clear an item in the game and/or owning player's Special Item list. |
static int |
OP_DECLINE
Sent from server as reply to a requesting client's OP_SET , OP_CLEAR , or OP_PICK :
The client's request is declined. |
static int |
OP_PICK
If sent from client to server, a request to pick or choose an item for some action. |
static int |
OP_SET
If sent from client to server, a request to set an item in the game and/or owning player's Special Item list. |
private static java.lang.String[] |
OPS_STRS
OP_* constant strings for toString() |
int |
playerItemIndex
Index in the owning player's Special Item list, or -1. |
int |
playerNumber
Owning player number, or -1. |
private static long |
serialVersionUID
|
java.lang.String |
sv
Optional string value from SOCSpecialItem.getStringValue() , or null . |
java.lang.String |
typeKey
Special item type key; see the SOCSpecialItem class javadoc for details. |
Constructor Summary | |
---|---|
SOCSetSpecialItem(SOCGame game,
int op,
java.lang.String typeKey,
int gi,
int pi,
SOCSpecialItem item)
Create a SOCSetSpecialItem message with data fields from an item object. |
|
SOCSetSpecialItem(java.lang.String ga,
int op,
java.lang.String typeKey,
int gi,
int pi,
int pn)
Create a SOCSetSpecialItem message, specifying all field values except coordinate (-1), level (0), stringValue ( null ). |
|
SOCSetSpecialItem(java.lang.String ga,
int op,
java.lang.String typeKey,
int gi,
int pi,
int pn,
int co,
int lv,
java.lang.String sv)
Create a SOCSetSpecialItem message, specifying all field values. |
Method Summary | |
---|---|
java.lang.String |
getGame()
Name of game this message is for. |
int |
getMinimumVersion()
Minimum version where this message type is used. |
static SOCSetSpecialItem |
parseDataStr(java.lang.String s)
Parse the command String into a SOCSetSpecialItem message. |
java.lang.String |
toCmd()
SETSPECIALITEM sep game sep2 operation sep2 typeKey sep2 gameItemIndex sep2 playerItemIndex sep2 playerNumber sep2 coord sep2 level sep2 sv |
java.lang.String |
toString()
Simple human-readable representation, used for debug purposes. |
Methods inherited from class soc.message.SOCMessage |
---|
arrayIntoStringBuf, enumIntoStringBuf, getClassNameShort, getMaximumVersion, 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 java.lang.String EMPTYSTR
pa[]
elements can't be parsed over the network
with the current tokenizer.
public static final int OP_SET
If sent from server to client(s) because of something in game or responding to a client request, this item will be set.
If gameItemIndex
!= -1, sets the special item's SOCSpecialItem.getGameIndex()
,
otherwise will not clear or change that field.
If setting for both the game and the owning player (gameItemIndex
!= -1 and
playerItemIndex
!= -1), the client will check the game for an existing object before checking the player.
That is: If the game and player previously had different objects (not null) at the specified special item indices,
now they will both have a reference to the game's object. If the game's list item at this index was null,
the player's object will now also be referenced in the game's Special Item list.
OP_SET
is the lowest-numbered operation.
public static final int OP_CLEAR
If sent from server to client(s) because of something in game or in response to a client request, this item will be cleared.
public static final int OP_PICK
If sent from server to client(s), this item has been picked for some action. The server isn't required to
announce the pick to all players, only to the requesting player. Depending on the situation in which the
item is being picked, it may or may not make sense to announce it. For clarity, any change to the contents
of a Special Item list must be done with OP_SET
or OP_CLEAR
, never implied by sending
only OP_PICK
.
Alternately, the server will respond to the requesting player with OP_DECLINE
.
The sequence of messages sent from the server for a player's successful PICK are:
SOCPlayerElement
message(s) to pay the cost, if any
OP_SET
or OP_CLEAR
message(s) resulting from the pick
OP_PICK
itself
SOCGameState
and related messages, if the state changed or the game is now over
For convenience, the server's PICK message includes the coord
, level
, and sv
field
values of the special item being picked. Different scenarios might change picked objects in different ways,
so these fields are filled by:
null
and be cleared, the values before the pick
as retrieved by SOCGame.getSpecialItem(String, int, int, int)
gameItemIndex
and playerItemIndex
, and afterwards
these are two different SOCSpecialItem
objects, then the values are taken from
gameItemIndex
's item if not null
, otherwise from playerItemIndex
's item.
SOCGame.getSpecialItem(String, int)
or SOCPlayer.getSpecialItem(String, int)
,
because the SET or CLEAR messages are sent out before the PICK.
OP_PICK
is currently the highest-numbered operation that a client can send as a request.
public static final int OP_DECLINE
OP_SET
, OP_CLEAR
, or OP_PICK
:
The client's request is declined.
The reply's data fields (typeKey
, gameItemIndex
, etc) will have the same values as the request.
public final java.lang.String game
public final java.lang.String typeKey
SOCSpecialItem
class javadoc for details.
public final int op
OP_SET
, OP_CLEAR
, OP_PICK
or OP_DECLINE
.
public final int gameItemIndex
public final int playerItemIndex
playerNumber
must be != -1.
public final int playerNumber
playerItemIndex
.
A player can only request with their own playerNumber, server ignores this field.
public final int coord
public final int level
public final java.lang.String sv
SOCSpecialItem.getStringValue()
, or null
.
private static final java.lang.String[] OPS_STRS
toString()
Constructor Detail |
---|
public SOCSetSpecialItem(SOCGame game, int op, java.lang.String typeKey, int gi, int pi, SOCSpecialItem item) throws java.lang.IllegalArgumentException, java.lang.NullPointerException
game
- game; only its name is used in this messageop
- Operation code: see op
for valuestypeKey
- Special item type key; see the SOCSpecialItem
class javadoc for detailsgi
- Game item index, or -1pi
- Player item index (requires item.getPlayer()
!= null), or -1item
- Item for owning player, coordinate on board, and level/strength
java.lang.IllegalArgumentException
- if typeKey is null, or pi != -1 but item.getPlayer() is null,
or gi == -1 and pi == -1
java.lang.NullPointerException
- if game or item is nullpublic SOCSetSpecialItem(java.lang.String ga, int op, java.lang.String typeKey, int gi, int pi, int pn) throws java.lang.IllegalArgumentException, java.lang.NullPointerException
null
).
ga
- Name of the gameop
- Operation code: see op
for valuestypeKey
- Special item type key; see the SOCSpecialItem
class javadoc for detailsgi
- Game item index, or -1pi
- Player item index (requires pn != -1), or -1pn
- Currently owning player number, or -1
java.lang.IllegalArgumentException
java.lang.NullPointerException
public SOCSetSpecialItem(java.lang.String ga, int op, java.lang.String typeKey, int gi, int pi, int pn, int co, int lv, java.lang.String sv) throws java.lang.IllegalArgumentException
ga
- Name of the gameop
- Operation code: see op
for valuestypeKey
- Special item type key; see the SOCSpecialItem
class javadoc for detailsgi
- Game item index, or -1pi
- Player item index (requires pn != -1), or -1pn
- Currently owning player number, or -1co
- Optional coordinate on board, or -1lv
- Optional built level/strength, or 0sv
- Optional stringValue from SOCSpecialItem.getStringValue()
, or null
java.lang.IllegalArgumentException
- if ga or typeKey is null, or pn != -1 but pi == -1,
or gi == -1 and pi == -1,
or sv fails SOCMessage.isSingleLineAndSafe(String)
Method 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 static SOCSetSpecialItem parseDataStr(java.lang.String s)
s
- the String to parse, from toCmd()
null
if the data is garbledpublic int getMinimumVersion()
getMinimumVersion
in class SOCMessage
public java.lang.String toCmd()
If sv
is null
, it's sent as EMPTYSTR
.
toCmd
in class SOCMessage
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 |