Class MMOItemVariable
- java.lang.Object
-
- com.smartfoxserver.v2.entities.variables.SFSUserVariable
-
- com.smartfoxserver.v2.mmo.MMOItemVariable
-
- All Implemented Interfaces:
UserVariable
,Variable
,IMMOItemVariable
,java.io.Serializable
,java.lang.Cloneable
public class MMOItemVariable extends SFSUserVariable implements IMMOItemVariable
MMOItem Variables allow to attach custom properties to MMOItems inside an MMORoom. MMOItems can represent bonuses, triggers, bullets or any other non-player entity inside an MMORoom that will be handled with the same Area Of Interest rules.This means that whenever one or more MMOItem fall within the AoI of a Player it will be notified to the User with a client side PROXIMITY_LIST_UPDATE. MMOItems are identified by unique ID and by all of their custom variables.
MMOItem Variables behave exactly like User Variables and can be updated or removed via server side code. This allows MMOItems to be highly dynamic within the context of the MMORoom.
Example of use:
// Prepare the variables List<IMMOItemVariables> vars = new LinkedList<IMMOItemVariables>(); vars.add(new MMOItemVariable("type", "1"); // identifies the type of bonus based on our game rules vars.add(new MMOitemVariable("val", 100); // the value of the bonus // Create the item MMOItem bonus = new MMOItem(vars); // Access the MMO API ISFSMMOApi mmoApi = SmartfoxServer.getInstance().getAPIManager().getMMOApi; // Set the Item in the room at specific coordinates mmoApi.setMMOItemPosition(bonus, new Vec3D(10, 20, 5), theMMORoom);
The final line of code assumes we already have an MMORoom object where the Item will be added. It might be an existing room or one that has just been created. After the Item is placed in the MMORoom a PROXIMITY_LIST_UPDATE will be sent to Users that are within range of the object.
Removing Variables: in order to remove one or more existing variables you will need to set those variables to NULL, using the
SFSUserVariable.setNull()
method;- Since:
- 2.8.x
- See Also:
MMOItemVariable
,MMORoom
,SFSMMOApi
, Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MMOItemVariable(java.lang.String name)
protected
MMOItemVariable(java.lang.String name, VariableType type, java.lang.String literal)
MMOItemVariable(java.lang.String name, java.lang.Object value)
Construct an MMOVariable with it's name and value.MMOItemVariable(java.lang.String name, java.lang.Object value, boolean isHidden)
Construct an MMOVariable with it's name and value.protected
MMOItemVariable(java.lang.String name, java.lang.String type, java.lang.String literal)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static MMOItemVariable
newFromSFSArray(ISFSArray array)
static MMOItemVariable
newFromStringLiteral(java.lang.String name, java.lang.String type, java.lang.String literal)
static MMOItemVariable
newInstance(java.lang.String name, java.lang.Object value)
-
Methods inherited from class com.smartfoxserver.v2.entities.variables.SFSUserVariable
clone, getBoolValue, getDoubleValue, getIntValue, getName, getSFSArrayValue, getSFSObjectValue, getStringValue, getType, getValue, isHidden, isNull, isPrivate, isStorable, newPrivateVariable, populateArrayWithValue, setHidden, setNull, setPrivate, setStorable, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueFromStringLiteral, toSFSArray, toString
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.smartfoxserver.v2.entities.variables.UserVariable
isHidden, isPrivate, isStorable, setHidden, setNull, setPrivate, setStorable
-
Methods inherited from interface com.smartfoxserver.v2.entities.variables.Variable
getBoolValue, getDoubleValue, getIntValue, getName, getSFSArrayValue, getSFSObjectValue, getStringValue, getType, getValue, isNull, toSFSArray
-
-
-
-
Constructor Detail
-
MMOItemVariable
public MMOItemVariable(java.lang.String name, java.lang.Object value)
Construct an MMOVariable with it's name and value.- Parameters:
name
- name of the variablevalue
- value of the variables (can be Bool, Int, Double, String, SFSArray, SFSObject)- See Also:
MMOItem
,MMORoom
,SFSMMOApi.setMMOItemVariables(BaseMMOItem, java.util.List)
-
MMOItemVariable
public MMOItemVariable(java.lang.String name, java.lang.Object value, boolean isHidden)
Construct an MMOVariable with it's name and value. The hidden flag allows to hide the variable to clients- Parameters:
name
- name of the variablevalue
- value of the variables (can be Bool, Int, Double, String, SFSArray, SFSObject)isHidden
- if true the variable will remain server side only- See Also:
MMOItem
,MMORoom
,SFSMMOApi.setMMOItemVariables(BaseMMOItem, java.util.List)
-
MMOItemVariable
protected MMOItemVariable(java.lang.String name)
-
MMOItemVariable
protected MMOItemVariable(java.lang.String name, VariableType type, java.lang.String literal)
-
MMOItemVariable
protected MMOItemVariable(java.lang.String name, java.lang.String type, java.lang.String literal)
-
-
Method Detail
-
newInstance
public static MMOItemVariable newInstance(java.lang.String name, java.lang.Object value)
-
newFromStringLiteral
public static MMOItemVariable newFromStringLiteral(java.lang.String name, java.lang.String type, java.lang.String literal)
-
newFromSFSArray
public static MMOItemVariable newFromSFSArray(ISFSArray array)
-
-