Package com.smartfoxserver.v2.mmo
Class MMOItem
- java.lang.Object
-
- com.smartfoxserver.v2.mmo.BaseMMOItem
-
- com.smartfoxserver.v2.mmo.MMOItem
-
- All Implemented Interfaces:
IMMOItem
public class MMOItem extends BaseMMOItem
An MMOItem represents a non-player entity inside an MMORoom. MMOItems can be used as bonuses, triggers, bullets etc... or any other non-player entity that will be handled using the MMORoom's rules of visibility.This means that whenever one or more MMOItem falls 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.
MMOItems also have Variables that behave just like User Variables, that can be used to attach any custom property to each Item.
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.
Tutorial
To learn more see also this introductory tutorial.- Since:
- 2.8.x
- See Also:
MMOItemVariable
,MMORoom
,SFSMMOApi
-
-
Constructor Summary
Constructors Constructor Description MMOItem()
Creates a new MMOItemMMOItem(java.util.List<IMMOItemVariable> variables)
Creates an MMOItem populated with custom variables
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getId()
The MMOItem IDMMORoom
getRoom()
IMMOItemVariable
getVariable(java.lang.String name)
Obtain a variable from the MMOItem via its namejava.util.List<IMMOItemVariable>
getVariables()
Get a list of all variables attached to the MMOItemvoid
removeVariable(java.lang.String varName)
Used internally.void
setVariable(IMMOItemVariable var)
Used internally.void
setVariables(java.util.List<IMMOItemVariable> varList)
Used internally.ISFSArray
toSFSArray()
Used internallyjava.lang.String
toString()
-
-
-
Constructor Detail
-
MMOItem
public MMOItem()
Creates a new MMOItem
-
MMOItem
public MMOItem(java.util.List<IMMOItemVariable> variables)
Creates an MMOItem populated with custom variables- Parameters:
variables
- the list of MMOVariables- See Also:
IMMOItemVariable
-
-
Method Detail
-
getId
public int getId()
The MMOItem ID- Returns:
- the unique Item ID
-
getVariable
public IMMOItemVariable getVariable(java.lang.String name)
Obtain a variable from the MMOItem via its name- Parameters:
name
- the variable name- Returns:
- the variable object
-
getVariables
public java.util.List<IMMOItemVariable> getVariables()
Get a list of all variables attached to the MMOItem- Returns:
- all variables attached to the MMOItem
-
setVariable
public void setVariable(IMMOItemVariable var)
Used internally. To set variables see below:
-
setVariables
public void setVariables(java.util.List<IMMOItemVariable> varList)
Used internally. To set variables see below:
-
removeVariable
public void removeVariable(java.lang.String varName)
Used internally. Removing an existing variables requires to set the variable to null To remove variables see below:
-
toSFSArray
public ISFSArray toSFSArray()
Used internally
-
getRoom
public MMORoom getRoom()
- Specified by:
getRoom
in classBaseMMOItem
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-