Class MMORoom
- java.lang.Object
-
- com.smartfoxserver.v2.entities.SFSRoom
-
- com.smartfoxserver.v2.mmo.MMORoom
-
- All Implemented Interfaces:
Room
public class MMORoom extends SFSRoom
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 fire any USER_ENTER or USER_EXIT events when other users enter or leave the Room, instead the client 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 substitutes 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 will always be accessible.
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 contain thousands of players without overloading each client with useless updates. The MMORoom can be configured also 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 coordinates system is abstracted and generic, allowing developers to use all sorts of units (pixels, inches, meters, miles etc...) using either integers or floating point values (32bit).When a User joins an MMORoom his position in the world is still undefined and therefore he will be in a state of limbo until the first SetUserPosition request will be 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 will be removed from the Room.
As mentioned in the overview there are no USER_ENTER/EXIT events fired to other Users, as in regular Rooms. The way in which players are updated about other User changes in their proximity is via the client PROXIMITY_LIST_UPDATE. All other Room events will 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 will work normally, affecting only those Users who are in the AOI of the request 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 very large broadcast messages with the risk of saturating 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 object accept a pair of Vec3D parameters representing 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
To learn more see also this introductory tutorial.- Since:
- 2.8.0
- See Also:
CreateMMORoomSettings
,Vec3D
,MMOItem
,SFSMMOApi
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MMORoom.PreviousMMORoomState
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addUser(User user, boolean asSpectator)
privateboolean
containsMMOItem(int id)
Check if the provided MMOItem id is managed by this Roomboolean
containsMMOItem(BaseMMOItem item)
Check if the provided MMOItem is managed by this Roomvoid
destroy()
privatecom.smartfoxserver.v2.mmo.P3D
findItemLocation(BaseMMOItem item)
privatecom.smartfoxserver.v2.mmo.P3D
findUserLocation(User user)
privatejava.util.List<BaseMMOItem>
getAllMMOItems()
Obtain a list of all MMOItems managed by this RoomVec3D
getDefaultAOI()
Obtain the default Area Of Interest (AOI) of this room.com.smartfoxserver.v2.mmo.IMMOItemManager
getItemsManager()
privateVec3D
getMapHigherLimit()
Get the map higher limitVec3D
getMapLowerLimit()
Get the map lower limitBaseMMOItem
getMMOItemById(int itemId)
Obtain an MMOItem managed by this Room via its idjava.util.List<User>
getPlayersList()
For Game Rooms: get all Players in the Room (same as all User without the Spectators)java.util.List<BaseMMOItem>
getProximityItems(User target)
Get the list of MMOItems falling within the User's AoIjava.util.List<BaseMMOItem>
getProximityItems(User target, Vec3D aoi)
Get the list of MMOItems falling within a custom AoIjava.util.List<BaseMMOItem>
getProximityItems(Vec3D pos)
Get the list of MMOItems falling within the MMORoom's AoI at a specific locationjava.util.List<BaseMMOItem>
getProximityItems(Vec3D pos, Vec3D aoi)
Get the list of MMOItems at a specific location, falling within a custom AoIjava.util.List<User>
getProximityList(User target)
Returns the List of Users falling within the target's AOIjava.util.List<User>
getProximityList(User target, Vec3D aoi)
Returns the List of Users falling within the a custom AOI around the targetjava.util.List<User>
getProximityList(Vec3D position)
Returns the List of Users falling within the AOI of the target positionjava.util.List<User>
getProximityList(Vec3D position, Vec3D aoi)
Returns the List of Users falling within the custom AOI around the target positionint
getProximityListUpdateMillis()
privatecom.smartfoxserver.v2.mmo.IProximityManager
getProximityManager()
privateVec3D
getSectorSize()
privatejava.util.List<User>
getSpectatorsList()
For Game Rooms: get all Spectators in the Room (same as all User without the Players)User
getUserByPlayerId(int playerId)
Get the User currently having the specified playerId (Game Room only)int
getUserLimboMaxSeconds()
privateboolean
isGame()
Checks if this is a Game Roomboolean
isSendAOIEntryPoint()
privateboolean
isSuppressUserList()
void
removeMMOItem(BaseMMOItem item)
privatevoid
removeUser(User user)
privatevoid
setGame(boolean game)
void
setGame(boolean game, java.lang.Class<? extends IPlayerIdGenerator> customPlayerIdGeneratorClass)
void
setMapLimits(Vec3D lowLimit, Vec3D highLimit)
Private setter.void
setSendAOIEntryPoint(boolean sendAOIEntryPoint)
Private setter.void
setSuppressUserList(boolean value)
void
setUserLimboMaxSeconds(int userLimboMaxSeconds)
Private setter.ISFSArray
toSFSArray(boolean globalRoomVarsOnly)
java.lang.String
toString()
void
updateItem(BaseMMOItem item, Vec3D pos)
void
updateUser(User user)
private-
Methods inherited from class com.smartfoxserver.v2.entities.SFSRoom
addUser, containsProperty, containsUser, containsUser, containsVariable, equals, getAdminHelper, getAutoRemoveMode, getCapacity, getDump, getExtension, getGroupId, getId, getLifeTime, getMaxRoomVariablesAllowed, getMaxSpectators, getMaxUsers, getName, getOwner, getPassword, getPlayerIdGeneratorClassName, getProperties, getProperty, getRoomVariablesData, getSessionList, getSize, getUserById, getUserByName, getUserBySession, getUserList, getUserListData, getUserManager, getVariable, getVariables, getVariablesCount, getVariablesCreatedByUser, getZone, isActive, isAllowOwnerInvitations, isDynamic, isEmpty, isFlagSet, isFull, isHidden, 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
-
-
-
-
Constructor Detail
-
MMORoom
public MMORoom(java.lang.String name, Vec3D aoi, int updateMillis)
Private constructor
-
-
Method Detail
-
addUser
public void addUser(User user, boolean asSpectator) throws SFSJoinRoomException
private- Specified by:
addUser
in interfaceRoom
- Overrides:
addUser
in classSFSRoom
- Throws:
SFSJoinRoomException
-
removeUser
public void removeUser(User user)
private- Specified by:
removeUser
in interfaceRoom
- Overrides:
removeUser
in classSFSRoom
-
isSuppressUserList
public boolean isSuppressUserList()
- Specified by:
isSuppressUserList
in interfaceRoom
- Overrides:
isSuppressUserList
in classSFSRoom
-
setSuppressUserList
public void setSuppressUserList(boolean value)
- Specified by:
setSuppressUserList
in interfaceRoom
- Overrides:
setSuppressUserList
in classSFSRoom
-
removeMMOItem
public void removeMMOItem(BaseMMOItem item)
private
-
getDefaultAOI
public Vec3D getDefaultAOI()
Obtain the default Area Of Interest (AOI) of this room.- Returns:
- the default Area Of Interest (AOI) of this room
-
getProximityList
public java.util.List<User> getProximityList(User target)
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
public java.util.List<User> getProximityList(User target, Vec3D aoi)
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
public java.util.List<User> getProximityList(Vec3D position)
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
public java.util.List<User> getProximityList(Vec3D position, Vec3D aoi)
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
public BaseMMOItem getMMOItemById(int itemId)
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
public java.util.List<BaseMMOItem> 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
public boolean containsMMOItem(BaseMMOItem item)
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
public java.util.List<BaseMMOItem> getProximityItems(User target)
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
public java.util.List<BaseMMOItem> getProximityItems(User target, Vec3D aoi)
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
public java.util.List<BaseMMOItem> getProximityItems(Vec3D pos)
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
public java.util.List<BaseMMOItem> getProximityItems(Vec3D pos, Vec3D aoi)
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
public Vec3D getSectorSize()
private
-
getProximityManager
public com.smartfoxserver.v2.mmo.IProximityManager getProximityManager()
private
-
getItemsManager
public com.smartfoxserver.v2.mmo.IMMOItemManager getItemsManager()
private
-
findUserLocation
public com.smartfoxserver.v2.mmo.P3D findUserLocation(User user)
private
-
findItemLocation
public com.smartfoxserver.v2.mmo.P3D findItemLocation(BaseMMOItem item)
private
-
updateUser
public void updateUser(User user)
private
-
updateItem
public void updateItem(BaseMMOItem item, Vec3D pos)
-
getMapLowerLimit
public Vec3D getMapLowerLimit()
Get the map lower limit- Returns:
- get the map lower limit
-
getMapHigherLimit
public Vec3D getMapHigherLimit()
Get the map higher limit- Returns:
- get the map higher limit
-
getUserLimboMaxSeconds
public int getUserLimboMaxSeconds()
private
-
setUserLimboMaxSeconds
public void setUserLimboMaxSeconds(int userLimboMaxSeconds)
Private setter.
-
destroy
public void destroy()
private
-
isSendAOIEntryPoint
public boolean isSendAOIEntryPoint()
private
-
setSendAOIEntryPoint
public void setSendAOIEntryPoint(boolean sendAOIEntryPoint)
Private setter.
-
getProximityListUpdateMillis
public int getProximityListUpdateMillis()
private
-
getUserByPlayerId
public User getUserByPlayerId(int playerId)
Description copied from class:SFSRoom
Get the User currently having the specified playerId (Game Room only)- Specified by:
getUserByPlayerId
in interfaceRoom
- Overrides:
getUserByPlayerId
in 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:SFSRoom
Checks if this is a Game Room
-
getPlayersList
public java.util.List<User> getPlayersList()
Description copied from class:SFSRoom
For Game Rooms: get all Players in the Room (same as all User without the Spectators)- Specified by:
getPlayersList
in interfaceRoom
- Overrides:
getPlayersList
in classSFSRoom
- Returns:
- all Players in the Room
-
getSpectatorsList
public java.util.List<User> getSpectatorsList()
Description copied from class:SFSRoom
For Game Rooms: get all Spectators in the Room (same as all User without the Players)- Specified by:
getSpectatorsList
in interfaceRoom
- Overrides:
getSpectatorsList
in classSFSRoom
- Returns:
- all Spectators in the Room
-
setGame
public void setGame(boolean game)
Description copied from class:SFSRoom
-
setGame
public void setGame(boolean game, java.lang.Class<? extends IPlayerIdGenerator> customPlayerIdGeneratorClass)
Description copied from class:SFSRoom
-
toSFSArray
public ISFSArray toSFSArray(boolean globalRoomVarsOnly)
- Specified by:
toSFSArray
in interfaceRoom
- Overrides:
toSFSArray
in classSFSRoom
-
-