Package com.smartfoxserver.mmo
Class MMOItem
java.lang.Object
com.smartfoxserver.mmo.BaseMMOItem
com.smartfoxserver.mmo.MMOItem
- All Implemented Interfaces:
IMMOItem
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 ArrayList<>();
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);
// Set the Item in the room at specific coordinates
getMMOApi().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 this introductory tutorial.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMMOItem()Creates a new MMOItemMMOItem(List<IMMOItemVariable> variables) Creates an MMOItem populated with custom variables -
Method Summary
Modifier and TypeMethodDescriptionintgetId()The MMOItem IDgetRoom()Get the Room associated with this MMOItemgetVariable(String name) Obtain a variable from the MMOItem via its nameGet a list of all variables attached to the MMOItemvoidremoveVariable(String varName) voidvoidsetVariables(List<IMMOItemVariable> varList) toString()
-
Constructor Details
-
MMOItem
public MMOItem()Creates a new MMOItem -
MMOItem
Creates an MMOItem populated with custom variables- Parameters:
variables- the list of MMOVariables- See Also:
-
-
Method Details
-
getId
public int getId()Description copied from interface:IMMOItemThe MMOItem ID- Returns:
- the unique Item ID
-
getVariable
Description copied from interface:IMMOItemObtain a variable from the MMOItem via its name- Parameters:
name- the variable name- Returns:
- the variable object
-
getVariables
Description copied from interface:IMMOItemGet a list of all variables attached to the MMOItem- Returns:
- all variables attached to the MMOItem
-
setVariable
- See Also:
- Internal
-
setVariables
- Internal
-
removeVariable
- Internal
-
toSFSArray
- Internal
-
getRoom
Description copied from class:BaseMMOItemGet the Room associated with this MMOItem- Specified by:
getRoomin classBaseMMOItem- Returns:
- the Room associated with the MMOItem
-
getLastLocation
-
toString
-