private static IWorldCreationParams GenerateWorldCreationParams(IGameState gameState) { var result = new WorldCreationParams { seed = Random.Range(int.MinValue, int.MaxValue), worldData = Main.StaticData.Game.Worlds.RandomValue }; return(result); }
public bool HasGame() { if (worldCreationParams != null) { return(true); } if (!listener.Pending()) { return(false); } proxyConnection = listener.AcceptTcpClient(); GameSettings gameSettings; JObject worldStateObj; if (!proxyConnection.TryReadJson(TimeSpan.FromSeconds(1), out gameSettings) || !proxyConnection.TryReadJson(TimeSpan.FromSeconds(1), out worldStateObj)) { proxyConnection.Close(); Debug.Log("Failed"); return(false); } Debugger.Log("Requested game " + gameSettings.LoadingData.AssemblyName + "." + gameSettings.LoadingData.Level); var competitions = Dispatcher.Loader.GetCompetitions(gameSettings.LoadingData); Debugger.Log("Game found in loader"); var worldState = (WorldState)worldStateObj.ToObject(competitions.Logic.WorldStateType); var players = new Dictionary <string, TcpClient>(); if (worldState.Undefined) { Debug.Log("default"); worldState = DefaultWorldInfoCreator.GetDefaultWorldState(gameSettings.LoadingData); } foreach (var settings in gameSettings.ActorSettings.Where(x => !x.IsBot)) { players[settings.ControllerId] = listener.AcceptTcpClient(); Debugger.Log("Accepted client " + settings.ControllerId); } Debugger.Log("Accepted " + players.Count + " connections"); DefaultWorldInfoCreator.AddDefaultLogSettings(gameSettings); worldCreationParams = new WorldCreationParams(gameSettings, new PlayControllerFactory(players), worldState); return(true); }
public GameSession StartGame() { if (worldCreationParams == null) { throw new Exception("Game was not ready!"); } if (worldCreationParams.GameSettings.SpeedUp) { Dispatcher.SetTimeScale(Constants.TimeScale * 2); } var world = Dispatcher.Loader.CreateWorld( worldCreationParams.GameSettings, worldCreationParams.ControllerFactory, worldCreationParams.WorldState); worldCreationParams = null; return(new GameSession(world, proxyConnection)); }