Class: MMOApi

MMOApi

The MMOApi class provides specialized API calls for advanced MMO-related functionalities. All the methods are targeted at an MMORoom and take its Area of Interest into account in order to dispatch events to the clients.

Notes

  • Whenever a Vec3D object must be passed to a method of this API, use the Vectors.newVec3D helper method to generate it. The reason is that this class is not available in JavaScript due to constructor overloading in the corresponding Vec3D class.

See also

Constructor


new MMOApi()

Developers never istantiate the MMOApi class: this is done internally by the SmartFoxServer 2X API; get a reference to it using the Extension's getMMOApi method.

Methods


removeMMOItem(item)

Removes an MMOItem from an MMORoom.

The target MMORoom is not required by this method because the system already keeps track of which MMOItem belongs to which MMORoom.

Parameters:
Name Type Description
item MMOItem The MMOItem object representing the MMOItem to be removed from the MMORoom where it is located.

sendObjectMessage(targetRoom, sender, message [, aoi])

Sends a data object from a user to all the other users in his Area of Interest (AOI).

This method sends a custom SFSObject that can contain any data. Typically this is used to send game moves to players or other game/app related updates.
The difference with the regular version of this method (see SFSApi#sendObjectMessage method) is that it works with the AOI set for the target MMORoom. Also, instead of using the default AOI, a custom AOI can be provided. This must be smaller than the default one; attempting to use a larger AOI is not possible.
The sender must be joined in the target MMORoom too.

Parameters:
Name Type Argument Description
targetRoom MMORoom The MMORoom object representing the MMORoom to send the data to.
sender SFSUser The SFSUser object representing the user sending the data to the target MMORoom.
message SFSObject The data object to send.
aoi Vec3D <optional>
A Vec3D instance representing a custom AOI.
Read the notes in the MMOApi class description.

sendPublicMessage(targetRoom, sender, message [, params] [, aoi])

Sends a public chat message from user to all the other users in his Area of Interest (AOI).

The difference with the regular version of this method (see SFSApi#sendPublicMessage method) is that it works with the AOI set for the target MMORoom. Also, instead of using the default AOI, a custom AOI can be provided. This must be smaller than the default one; attempting to use a larger AOI is not possible.
The sender must be joined in the target MMORoom too.

Parameters:
Name Type Argument Description
targetRoom MMORoom The MMORoom object representing the MMORoom to send the message to.
sender SFSUser The SFSUser object representing the user sending the message to the target MMORoom.
message string The chat message to send.
params SFSObject <optional>
A SFSObject containing custom parameters to be attached to the message (e.g. text color, font size, etc).
aoi Vec3D <optional>
A Vec3D instance representing a custom AOI.
Read the notes in the MMOApi class description.

setMMOItemPosition(item, pos, targetRoom)

Sets the position of an MMOItem inside an MMORoom.
Parameters:
Name Type Description
item MMOItem The MMOItem object representing the MMOItem to set the position of.
pos Vec3D A Vec3D instance representing the MMOItem position in the target MMORoom.
Read the notes in the MMOApi class description.
targetRoom MMORoom The MMORoom object representing the MMORoom where to set the MMOItem position.

setMMOItemVariables(item, variables [, fireClientEvent])

Sets the MMOItem Variables for the passed MMOItem.

Only new/updated variables are broadcast to the users that are within the range defined by the MOORoom's Area of Interest from the target MMOItem. A variable can also be deleted by setting it to null.

Parameters:
Name Type Argument Default Description
item MMOItem The MMOItem object representing the MMOItem for which the MMOItem Variables are set.
variables Array.<MMOItemVariable> An array of MMOItemVariable objects to set.
fireClientEvent boolean <optional>
false If true, a client-side MMOITEM_VARIABLES_UPDATE event will be fired to notify the MMOItem Variables creation/update.

setUserPosition(user, pos, targetRoom)

Sets the position of a user inside an MMORoom.
Parameters:
Name Type Description
user SFSuser The SFSUser object representing the user to set the position of.
pos Vec3D A Vec3D instance representing the user position in the target MMORoom.
Read the notes in the MMOApi class description.
targetRoom MMORoom The MMORoom object representing the MMORoom where to set the user position.