diff --git a/Subsurface/GameSession/GameSession.cs b/Subsurface/GameSession/GameSession.cs index 3ab85c9e7..b11ad8bb0 100644 --- a/Subsurface/GameSession/GameSession.cs +++ b/Subsurface/GameSession/GameSession.cs @@ -113,15 +113,15 @@ namespace Subsurface public void StartShift(TimeSpan duration, string levelSeed, int scriptedEventCount = 1) { + Level level = Level.CreateRandom(levelSeed); + StartShift(duration, level, scriptedEventCount); } public void StartShift(TimeSpan duration, Level level, int scriptedEventCount = 1) { //if (crewManager.characterInfos.Count == 0) return; - - this.level = level; if (Submarine.Loaded!=submarine) submarine.Load(); diff --git a/Subsurface/Map/Level.cs b/Subsurface/Map/Level.cs index fb9e100b2..19d70ac12 100644 --- a/Subsurface/Map/Level.cs +++ b/Subsurface/Map/Level.cs @@ -61,10 +61,9 @@ namespace Subsurface public static Level CreateRandom(string seed = "") { - if (seed == "") { - seed = Rand.Range(0, int.MaxValue).ToString(); + seed = Rand.Range(0, int.MaxValue, false).ToString(); } return new Level((string)seed, 100000, 40000, 2000); } diff --git a/Subsurface/Networking/GameClient.cs b/Subsurface/Networking/GameClient.cs index 836ee94e4..2174b4335 100644 --- a/Subsurface/Networking/GameClient.cs +++ b/Subsurface/Networking/GameClient.cs @@ -212,23 +212,20 @@ namespace Subsurface.Networking int seed = inc.ReadInt32(); Rand.SetSyncedSeed(seed); + string levelSeed = inc.ReadString(); + string mapName = inc.ReadString(); string mapHash = inc.ReadString(); Game1.NetLobbyScreen.TrySelectMap(mapName, mapHash); - - - //Map.Load(mapFile); - - - + double durationMinutes = inc.ReadDouble(); TimeSpan duration = new TimeSpan(0,(int)durationMinutes,0); //int gameModeIndex = inc.ReadInt32(); Game1.GameSession = new GameSession(Submarine.Loaded); - Game1.GameSession.StartShift(duration, "asdf"); + Game1.GameSession.StartShift(duration, levelSeed); myCharacter = ReadCharacterData(inc); Character.Controlled = myCharacter; diff --git a/Subsurface/Networking/GameServer.cs b/Subsurface/Networking/GameServer.cs index e0814099c..1b1e80d96 100644 --- a/Subsurface/Networking/GameServer.cs +++ b/Subsurface/Networking/GameServer.cs @@ -273,7 +273,7 @@ namespace Subsurface.Networking //selectedMap.Load(); Game1.GameSession = new GameSession(selectedMap, Game1.NetLobbyScreen.SelectedMode); - Game1.GameSession.StartShift(Game1.NetLobbyScreen.GameDuration, "asdf", 1); + Game1.GameSession.StartShift(Game1.NetLobbyScreen.GameDuration, Game1.NetLobbyScreen.LevelSeed, 1); //EventManager.SelectEvent(Game1.netLobbyScreen.SelectedEvent); foreach (Client client in connectedClients) @@ -304,6 +304,8 @@ namespace Subsurface.Networking msg.Write(seed); + msg.Write(Game1.NetLobbyScreen.LevelSeed); + msg.Write(Game1.NetLobbyScreen.SelectedMap.Name); msg.Write(Game1.NetLobbyScreen.SelectedMap.Hash.MD5Hash); diff --git a/Subsurface/Screens/NetLobbyScreen.cs b/Subsurface/Screens/NetLobbyScreen.cs index 3e5a5e8b5..85fe13758 100644 --- a/Subsurface/Screens/NetLobbyScreen.cs +++ b/Subsurface/Screens/NetLobbyScreen.cs @@ -180,6 +180,7 @@ namespace Subsurface GUI.style, 0.1f, infoFrame); durationBar.BarSize = 0.1f; durationBar.Enabled = (Game1.Server != null); + LevelSeed = ToolBox.RandomSeed(8); new GUITextBlock(new Rectangle((int)(modeList.Rect.Right + 20 - 80), 100, 100, 20), "Level Seed: ", GUI.style, Alignment.Left, Alignment.TopLeft, infoFrame); diff --git a/Subsurface/ToolBox.cs b/Subsurface/ToolBox.cs index 54a309dfe..d19d51758 100644 --- a/Subsurface/ToolBox.cs +++ b/Subsurface/ToolBox.cs @@ -247,6 +247,15 @@ namespace Subsurface return floatArray; } + public static string RandomSeed(int length) + { + var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + return new string( + Enumerable.Repeat(chars, length) + .Select(s => s[Rand.Int(s.Length)]) + .ToArray()); + } + public static int SeedToInt(string seed) { StringBuilder sb = new StringBuilder(); diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index a0ed447d0..87ea3e923 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ