Class MMORoom
- All Implemented Interfaces:
Room
Overview
The MMORoom extends the functionalities of a regular Room by adding an Area Of Interest (AOI) to determine the range of the events that should be received by Users. The AOI parameter represents the area within which Users will affect each other, for example when sending public messages, updating User Variables etc...By default the MMORoom does not trigger any USER_ENTER or USER_EXIT events when other users enter or leave the Room, instead the client's user list is updated via the PROXIMITY_LIST_UPDATE event which provides a delta of the current user list, within the AOI.
In other words the 'proximity list' replaces the regular user list on the client side, optimizing the number of updates that the User will receive. On the server side, however, the full Room's user list is always available.
Intended use
As suggested by the name of the class, MMORoom objects are useful to create very large, virtually unlimited, areas that are able to host thousands of players without overloading the clients with massive amounts of updates. The MMORoom can be configured to throttle the PROXIMITY_LIST_UPDATE events in order to optimize the network traffic.Joining and Setting a User position
In contrast to regular Rooms, the MMORoom needs to know where each user is located in 2D or 3D space. The Room uses a generic coordinate system that allows to use any type of units (pixels, inches, meters, miles etc...) represented as either integers or floating point values (32bit).When a User joins an MMORoom its position in the world is still undefined and therefore it will be in a state of limbo until the first SetUserPosition request is received. In order to avoid Users spending too much time in this invisible state each MMORoom can be configured to allow a timeout value after which the User is removed from the Room.
As mentioned in the overview there are no USER_ENTER/EXIT events triggered like in regular Rooms. The way in which players are notified about other Users in their proximity is via the PROXIMITY_LIST_UPDATE. All other Room events work similarly, including the USER_COUNT_CHANGE which keeps Users in the same Room group updated about the total number of clients in each Room.
User Variables and Room Variables
UserVariables work normally, affecting only those Users who are in the AOI of the sender. RoomVariables instead need to be used with parsimony to avoid generating heavy traffic towards the clients. Since RoomVariables contain data that interest all users in the MMORoom, updating them very often will generate large updates and thus consume significant network resources. the server bandwidth. What is critical here is the rate at which they are updated more than the number of variables used.Map limits
The MMORoom accepts a pair of Vec3D parameters that represent the limits of the virtual map on the three axis (x, y, z). It is highly recommended to set these limits to restrain the User movement within the range of your virtual world. This way illegal movements can be detected on the server side and denied by the system. Without setting map limits there's a potential risk that malicious Users could exhaust the system memory by trying to fill very large number of spaces for extreme coordinate values.Obtain the entry point of other Users
It is usually helpful to know at which coordinates a new User has entered the Player's AOI. Typically the client code will need to know this position to render a sprite/avatar in that spot. By default the MMORoom always sends the entry position of each new User. If this bit of information is not necessary in your application it can be turned off to save extra traffic.MMOItems
MMOitems are an extra feature available in MMORooms to add non-player entities in the virtual map. MMOItems can be defined with custom variables (MMOItemVariables) to represent all sorts of objects such as collectible bonuses, triggers, bullets, non-player entities etc...Tutorial
For more info see the tutorials in our online documentation- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleancontainsMMOItem(int id) Check if the provided MMOItem id is managed by this RoombooleancontainsMMOItem(BaseMMOItem item) Check if the provided MMOItem is managed by this Roomvoiddestroy()voidcom.smartfoxserver.mmo.P3DfindItemLocation(BaseMMOItem item) com.smartfoxserver.mmo.P3DfindUserLocation(User user) Obtain a list of all MMOItems managed by this RoomObtain the default Area Of Interest (AOI) of this room.com.smartfoxserver.mmo.IMMOItemManagerGet the map higher limitGet the map lower limitgetMMOItemById(int itemId) Obtain an MMOItem managed by this Room via its idFor Game Rooms: get all Players in the Room (same as all User without the Spectators)getProximityItems(User target) Get the list of MMOItems falling within the User's AoIgetProximityItems(User target, Vec3D aoi) Get the list of MMOItems falling within a custom AoIgetProximityItems(Vec3D pos) Get the list of MMOItems falling within the MMORoom's AoI at a specific locationgetProximityItems(Vec3D pos, Vec3D aoi) Get the list of MMOItems at a specific location, falling within a custom AoIgetProximityList(User target) Returns the List of Users falling within the target's AOIgetProximityList(User target, Vec3D aoi) Returns the List of Users falling within the a custom AOI around the targetgetProximityList(Vec3D position) Returns the List of Users falling within the AOI of the target positiongetProximityList(Vec3D position, Vec3D aoi) Returns the List of Users falling within the custom AOI around the target positionintcom.smartfoxserver.mmo.IProximityManagerFor Game Rooms: get all Spectators in the Room (same as all User without the Players)getUserByPlayerId(int playerId) Get the User currently having the specified playerId (Game Room only)intbooleanisGame()Checks if this is a Game RoombooleanbooleanvoidremoveMMOItem(BaseMMOItem item) voidremoveUser(User user) voidsetGame(boolean game) voidsetGame(boolean game, Class<? extends IPlayerIdGenerator> customPlayerIdGeneratorClass) voidsetMapLimits(Vec3D lowLimit, Vec3D highLimit) voidsetSendAOIEntryPoint(boolean sendAOIEntryPoint) voidsetSuppressUserList(boolean value) voidsetUserLimboMaxSeconds(int userLimboMaxSeconds) toSFSArray(boolean globalRoomVarsOnly) toString()voidupdateItem(BaseMMOItem item, Vec3D pos) voidupdateUser(User user) Methods inherited from class com.smartfoxserver.entities.SFSRoom
addUser, banUser, containsProperty, containsUser, containsUser, containsVariable, equals, getAdminHelper, getAudioManager, getAutoRemoveMode, getBannedUserIds, getCapacity, getDump, getExtension, getGroupId, getId, getLifeTime, getMaxRoomVariablesAllowed, getMaxSpectators, getMaxUsers, getName, getOwner, getOwnerName, getPassword, getPlayerIdGeneratorClassName, getProperties, getProperty, getRoomVariablesData, getSessionList, getSize, getUserById, getUserByName, getUserBySession, getUserList, getUserListData, getUserManager, getVariable, getVariables, getVariablesCount, getVariablesCreatedByUser, getZone, isActive, isAllowOwnerInvitations, isAudioStreamingAllowed, isDynamic, isEmpty, isFlagSet, isFull, isHidden, isJoinAllowed, isOwnedBy, isPasswordProtected, isPublic, isUseWordsFilter, removeProperty, removeVariable, removeVariablesCreatedByUser, removeVariablesCreatedByUser, setActive, setAdminHelper, setAllowOwnerInvitations, setAutoRemoveMode, setCapacity, setDynamic, setExtension, setFlag, setFlags, setGroupId, setHidden, setMaxRoomVariablesAllowed, setMaxSpectators, setMaxUsers, setName, setOwner, setPassword, setProperties, setProperty, setUserManager, setUseWordsFilter, setVariable, setVariable, setVariables, setVariables, setZone, switchPlayerToSpectator, switchSpectatorToPlayer, unbanUser
-
Constructor Details
-
MMORoom
-
-
Method Details
-
addUser
Description copied from class:SFSRoom- Specified by:
addUserin interfaceRoom- Overrides:
addUserin classSFSRoom- Throws:
SFSJoinRoomException- Internal
- Instead use
SFSApi.joinRoom(User, com.smartfoxserver.entities.Room)
-
removeUser
Description copied from class:SFSRoom- Specified by:
removeUserin interfaceRoom- Overrides:
removeUserin classSFSRoom- Internal
- Instead use
SFSApi.leaveRoom(User, com.smartfoxserver.entities.Room)
-
isSuppressUserList
public boolean isSuppressUserList()- Specified by:
isSuppressUserListin interfaceRoom- Overrides:
isSuppressUserListin classSFSRoom- Internal
-
setSuppressUserList
public void setSuppressUserList(boolean value) - Specified by:
setSuppressUserListin interfaceRoom- Overrides:
setSuppressUserListin classSFSRoom- Internal
-
enableAudioManager
public void enableAudioManager()- Specified by:
enableAudioManagerin interfaceRoom- Overrides:
enableAudioManagerin classSFSRoom- Internal
-
removeMMOItem
- Internal
-
getDefaultAOI
Obtain the default Area Of Interest (AOI) of this room.- Returns:
- the default Area Of Interest (AOI) of this room
-
getProximityList
Returns the List of Users falling within the target's AOI- Parameters:
target- the target user- Returns:
- the list of users within the target's AOI, returns null if the target User is not present in the Room
-
getProximityList
Returns the List of Users falling within the a custom AOI around the target- Parameters:
target- the target useraoi- a custom AOI which must less than or equal the default Room's AOI- Returns:
- the list of users within the requested target's AOI, returns null if the target User is not present in the Room
-
getProximityList
Returns the List of Users falling within the AOI of the target position- Parameters:
position- a 2D/3D position in the virtual world- Returns:
- the list of users within the target position AOI
-
getProximityList
Returns the List of Users falling within the custom AOI around the target position- Parameters:
position- a 2D/3D position in the virtual worldaoi- a custom AOI which must be less than or equal the default Room's AOI- Returns:
- the list of users within the requested target's AOI
-
getMMOItemById
Obtain an MMOItem managed by this Room via its id- Parameters:
itemId- the id of the MMOItem- Returns:
- the MMOItem or null if no MMOItem is managed by this Room with the provided Id
-
getAllMMOItems
Obtain a list of all MMOItems managed by this Room- Returns:
- the list of all MMOItems managed by this Room
-
containsMMOItem
public boolean containsMMOItem(int id) Check if the provided MMOItem id is managed by this Room- Parameters:
id- the MMOItem id- Returns:
- true if the MMOItem is managed by this Room, false otherwise
-
containsMMOItem
Check if the provided MMOItem is managed by this Room- Parameters:
item- the MMOItem- Returns:
- true if the MMOItem is managed by this Room, false otherwise
-
getProximityItems
Get the list of MMOItems falling within the User's AoI- Parameters:
target- A user joined in the same Room- Returns:
- The list of MMOItems. Null if the User is not present in the Room.
-
getProximityItems
Get the list of MMOItems falling within a custom AoI- Parameters:
target- A user joined in the same Roomaoi- A custom AoI, must be less than or equal than the default MMORoom AoI- Returns:
- The list of MMOItems. Null if the User is not present in the Room.
-
getProximityItems
Get the list of MMOItems falling within the MMORoom's AoI at a specific location- Parameters:
pos- The location in the MMORoom's "map"- Returns:
- The list of MMOItems.
-
getProximityItems
Get the list of MMOItems at a specific location, falling within a custom AoI- Parameters:
pos- The location in the MMORoom's "map"aoi- A custom AoI, must be less than or equal than the default MMORoom AoI- Returns:
- The list of MMOItems.
-
getSectorSize
- Internal
-
getProximityManager
public com.smartfoxserver.mmo.IProximityManager getProximityManager()- Internal
-
getItemsManager
public com.smartfoxserver.mmo.IMMOItemManager getItemsManager()- Internal
-
findUserLocation
- Internal
-
findItemLocation
- Internal
-
updateUser
- Internal
-
updateItem
- Internal
-
getMapLowerLimit
Get the map lower limit- Returns:
- get the map lower limit
-
getMapHigherLimit
Get the map higher limit- Returns:
- get the map higher limit
-
setMapLimits
- Internal
-
getUserLimboMaxSeconds
public int getUserLimboMaxSeconds()- Internal
-
setUserLimboMaxSeconds
public void setUserLimboMaxSeconds(int userLimboMaxSeconds) - Internal
-
destroy
public void destroy() -
isSendAOIEntryPoint
public boolean isSendAOIEntryPoint()- Internal
-
setSendAOIEntryPoint
public void setSendAOIEntryPoint(boolean sendAOIEntryPoint) - Internal
-
getProximityListUpdateMillis
public int getProximityListUpdateMillis()- Internal
-
getUserByPlayerId
Description copied from class:SFSRoomGet the User currently having the specified playerId (Game Room only)- Specified by:
getUserByPlayerIdin interfaceRoom- Overrides:
getUserByPlayerIdin classSFSRoom- Parameters:
playerId- the player id- Returns:
- the User, null if no User exists with that player id
-
isGame
public boolean isGame()Description copied from class:SFSRoomChecks if this is a Game Room -
toString
-
getPlayersList
Description copied from class:SFSRoomFor Game Rooms: get all Players in the Room (same as all User without the Spectators)- Specified by:
getPlayersListin interfaceRoom- Overrides:
getPlayersListin classSFSRoom- Returns:
- all Players in the Room
-
getSpectatorsList
Description copied from class:SFSRoomFor Game Rooms: get all Spectators in the Room (same as all User without the Players)- Specified by:
getSpectatorsListin interfaceRoom- Overrides:
getSpectatorsListin classSFSRoom- Returns:
- all Spectators in the Room
-
setGame
public void setGame(boolean game) Description copied from class:SFSRoom -
setGame
Description copied from class:SFSRoom -
toSFSArray
- Specified by:
toSFSArrayin interfaceRoom- Overrides:
toSFSArrayin classSFSRoom- Internal
-