public BaseGameRoom(ClientTCP client, int playersCount, int mapIndex = 0) { // Total number of players that can be in one room PlayersCount = playersCount; expectant = new object(); RoomType(); // Create lists of Players (TCP, UDP and struct contains player's game parameters) playersTCP = new ClientTCP[playersCount]; playersUDP = new GamePlayerUDP[playersCount]; roomPlayers = new RoomPlayer[playersCount]; //Create list of dynamic objects dynamicObjectsList = new DynamicObjectList(this); //Create list of static objects staticObjectsList = new StaticObjectList(); //Randomize mapIndex if it's not specified _mapIndex = mapIndex == 0 ? new Random().Next(1, Constants.MAPS_COUNT) : mapIndex; //Default room status Status = RoomState.Searching; // Load indicators _loadedTCP = new bool[playersCount]; _loadedUDP = new bool[playersCount]; // Get Map map = Global.data.GetMap(_mapIndex); //Create randomizer randomer = new ArenaRandomGenerator(map); // Adds player to the room AddPlayer(client); }
public bool AddPlayer(ClientTCP client) { lock (expectant) { for (int i = 0; i < PlayersCount; i++) { if (playersTCP[i] == null) { playersTCP[i] = client; client.EnterRoom(this, playersUDP[i] = new GamePlayerUDP(client.ip, i, this), i); roomPlayers[i] = new RoomPlayer( i, ObjectType.player, 1000, 1000, new float[] { map.SpawnPoints.ToArray()[i].PositionX, 0.5f, map.SpawnPoints.ToArray()[i].PositionY, }, new float[] { map.SpawnPoints.ToArray()[i].RotationX, map.SpawnPoints.ToArray()[i].RotationY, map.SpawnPoints.ToArray()[i].RotationZ, map.SpawnPoints.ToArray()[i].RotationW } ); // You can create it when player starts queue using params from database if (PlayersCount == playersTCP.Count(c => c != null)) { StartLoad(); } return(true); } } return(false); } }