I have a problem and i need someone can help me.
I have a game in which I need some bots add to room,
The problem is,when i used to matchmaking expression to find players
and this is code block i used to create room:
Code: Select all
public class StartGameHandler extends BaseClientRequestHandler
{
@Override
public void handleClientRequest(User player, ISFSObject params) {
Racing3dExtension parentExt = (Racing3dExtension) getParentExtension();
parentExt.trace("Matchmaking");
// MatchExpression retrieve all the Game Rooms still waiting for players to join them
MatchExpression exp = new MatchExpression(RoomProperties.IS_GAME, BoolMatch.EQUALS, true)
.and(RoomProperties.HAS_FREE_PLAYER_SLOTS, BoolMatch.EQUALS, true)
.and("isGameStarted", BoolMatch.EQUALS, false);
// Search Rooms from MatchExpression on above
List<Room> availableRooms = parentExt.getApi().findRooms(parentExt.getParentZone().getRoomList(), exp, 0);
if (availableRooms.size() > 0) {
Room room = (Room) availableRooms.get(0);
parentExt.trace("Room found:" + room.getName());
int totalUserList = room.getUserList().size(); //Get total number of user joining in the game
int totalMaxUsers = room.getMaxUsers(); // Check total Max Users allow to play game in the room
try {
if (totalUserList < totalMaxUsers) // if the room is not full,add player to room
{
room.addUser(player);
}
//Refresh size() of totalUserList again
totalUserList = room.getUserList().size();
if (totalUserList == totalMaxUsers) //if the room is full,stop add player to room and will start game
{
CreateRoomSettings settings = new CreateRoomSettings();
settings.setName("TestRoom");
settings.setMaxUsers(5);
settings.setMaxSpectators(10);
settings.setExtension(new CreateRoomSettings.RoomExtensionSettings("RacingDemo", "com.LExtension.RaceExtension"));
// settings.setExtension(new RoomExtensionSettings("3dRacingDemo", "com.LExtension.Racing3dExtension"));
settings.setAutoRemoveMode(SFSRoomRemoveMode.DEFAULT);
try
{
//Create room
parentExt.getParentZone().createRoom(settings);
} catch (SFSCreateRoomException e)
{
e.printStackTrace();
}
parentExt.trace("Room members count after join:" + room.getUserList().size());
ISFSObject obj = new SFSObject();
obj.putUtfString("status", "Game Starting in... ");
} else
{
ISFSObject obj = new SFSObject();
obj.putUtfString("status", "need more than one Player to start");
}
} catch (Exception e) {
trace(ExtensionLogLevel.WARN, "Message Failed : " + e.toString());
}
}
}
}
If after the process does not find matching players in room
and there are insufficient players in the room I will be adding bots to the room and game will start.
Matching requirements are as follows:
1.Player starts with 1000 points
2.At each rank level, players are only allowed to use the required Vehicle Class as shown in the image link below.
https://ibb.co/c3VLBGK
How can i do it? Or does anyone have a sample code to handle this, if so, can you share it with me?
Thank you very much.