From 11876864491d442680b1e5d82b731eaaa2478ea2 Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Mon, 3 Oct 2016 22:27:32 -0300 Subject: [PATCH] Host can disable spawning of certain characters GUITickBox might not work very well because of the override of Rect, might want to look into that later --- Subsurface/Source/Events/MonsterEvent.cs | 9 +++ Subsurface/Source/GUI/GUITickBox.cs | 14 ++++ Subsurface/Source/GameSession/GameSession.cs | 2 + Subsurface/Source/Networking/GameServer.cs | 2 +- .../Source/Networking/GameServerSettings.cs | 66 ++++++++++++++++--- 5 files changed, 83 insertions(+), 10 deletions(-) diff --git a/Subsurface/Source/Events/MonsterEvent.cs b/Subsurface/Source/Events/MonsterEvent.cs index d84cf5e35..1d5f23f6c 100644 --- a/Subsurface/Source/Events/MonsterEvent.cs +++ b/Subsurface/Source/Events/MonsterEvent.cs @@ -47,6 +47,15 @@ namespace Barotrauma private void SpawnMonsters() { + if (GameMain.Server != null) + { + string tryKey = GameMain.Server.monsterNames.Find(s => characterFile.ToLower().Contains(s.ToLower())); + if (tryKey != null) + { + if (!GameMain.Server.monsterEnabled[tryKey]) return; //spawn was disallowed by host + } + } + float minDist = Math.Max(Submarine.MainSub.Borders.Width, Submarine.MainSub.Borders.Height); //find a random spawnpos that isn't too close to the main sub diff --git a/Subsurface/Source/GUI/GUITickBox.cs b/Subsurface/Source/GUI/GUITickBox.cs index e65d78c2a..6a4417250 100644 --- a/Subsurface/Source/GUI/GUITickBox.cs +++ b/Subsurface/Source/GUI/GUITickBox.cs @@ -40,6 +40,20 @@ namespace Barotrauma } } + public override Rectangle Rect + { + get + { + return rect; + } + set + { + box.Rect = new Rectangle(value.X,value.Y,box.Rect.Width,box.Rect.Height); + text.Rect = new Rectangle(box.Rect.Right + 10, box.Rect.Y + 2, 20, box.Rect.Height); + rect = value; + } + } + public GUITickBox(Rectangle rect, string label, Alignment alignment, GUIComponent parent) : this(rect, label, alignment, GUI.Font, parent) { diff --git a/Subsurface/Source/GameSession/GameSession.cs b/Subsurface/Source/GameSession/GameSession.cs index 329394163..d026098aa 100644 --- a/Subsurface/Source/GameSession/GameSession.cs +++ b/Subsurface/Source/GameSession/GameSession.cs @@ -164,6 +164,8 @@ namespace Barotrauma if (gameMode!=null) gameMode.Start(); + Items.Components.Radar.StartMarker = "Start"; + Items.Components.Radar.EndMarker = "End"; if (gameMode.Mission != null) Mission.Start(Level.Loaded); TaskManager.StartShift(level); diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 802ef7dfb..d8f64515c 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -302,7 +302,7 @@ namespace Barotrauma.Networking if (gameStarted) { - inGameHUD.Update((float)Physics.step); + //inGameHUD.Update((float)Physics.step); if (respawnManager != null) respawnManager.Update(deltaTime); diff --git a/Subsurface/Source/Networking/GameServerSettings.cs b/Subsurface/Source/Networking/GameServerSettings.cs index 7fc3f4d2c..7f1cd0110 100644 --- a/Subsurface/Source/Networking/GameServerSettings.cs +++ b/Subsurface/Source/Networking/GameServerSettings.cs @@ -46,6 +46,9 @@ namespace Barotrauma.Networking private set; } + public List monsterNames; + public Dictionary monsterEnabled; + public bool ShowNetStats; private TimeSpan refreshMasterInterval = new TimeSpan(0, 0, 30); @@ -254,6 +257,17 @@ namespace Barotrauma.Networking FileStreamSender.MaxTransferDuration = new TimeSpan(0,0,ToolBox.GetAttributeInt(doc.Root, "MaxFileTransferDuration", 150)); showLogButton.Visible = SaveServerLogs; + + monsterNames = Directory.GetDirectories("Content/Characters").ToList(); + for (int i=0;i(); + foreach (string s in monsterNames) + { + monsterEnabled.Add(s, true); + } } private void CreateSettingsFrame() @@ -290,6 +304,8 @@ namespace Barotrauma.Networking int y = 0; + settingsTabs[0].Padding = new Vector4(40.0f, 5.0f, 40.0f, 40.0f); + new GUITextBlock(new Rectangle(0, y, 100, 20), "Submarine selection:", GUI.Style, settingsTabs[0]); var selectionFrame = new GUIFrame(new Rectangle(0, y + 20, 300, 20), null, settingsTabs[0]); for (int i = 0; i < 3; i++) @@ -318,7 +334,7 @@ namespace Barotrauma.Networking endBox.Selected = EndRoundAtLevelEnd; endBox.OnSelected = (GUITickBox) => { EndRoundAtLevelEnd = GUITickBox.Selected; return true; }; - y += 30; + y += 25; var endVoteBox = new GUITickBox(new Rectangle(0, y, 20, 20), "End round by voting", Alignment.Left, settingsTabs[0]); endVoteBox.Selected = Voting.AllowEndVoting; @@ -346,7 +362,7 @@ namespace Barotrauma.Networking }; votesRequiredSlider.OnMoved(votesRequiredSlider, votesRequiredSlider.BarScroll); - y += 40; + y += 35; var respawnBox = new GUITickBox(new Rectangle(0, y, 20, 20), "Allow respawning", Alignment.Left, settingsTabs[0]); respawnBox.Selected = AllowRespawn; @@ -357,9 +373,9 @@ namespace Barotrauma.Networking }; - var respawnIntervalText = new GUITextBlock(new Rectangle(20, y + 20, 20, 20), "Respawn interval", GUI.Style, settingsTabs[0], GUI.SmallFont); + var respawnIntervalText = new GUITextBlock(new Rectangle(20, y + 18, 20, 20), "Respawn interval", GUI.Style, settingsTabs[0], GUI.SmallFont); - var respawnIntervalSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 10), GUI.Style, 0.1f, settingsTabs[0]); + var respawnIntervalSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 10), GUI.Style, 0.1f, settingsTabs[0]); respawnIntervalSlider.UserData = respawnIntervalText; respawnIntervalSlider.Step = 0.05f; respawnIntervalSlider.BarScroll = RespawnInterval / 600.0f; @@ -373,12 +389,12 @@ namespace Barotrauma.Networking }; respawnIntervalSlider.OnMoved(respawnIntervalSlider, respawnIntervalSlider.BarScroll); - y += 40; + y += 35; var minRespawnText = new GUITextBlock(new Rectangle(0, y, 200, 20), "Minimum players to respawn", GUI.Style, settingsTabs[0]); minRespawnText.ToolTip = "What percentage of players has to be dead/spectating until a respawn shuttle is dispatched"; - var minRespawnSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 10), GUI.Style, 0.1f, settingsTabs[0]); + var minRespawnSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 10), GUI.Style, 0.1f, settingsTabs[0]); minRespawnSlider.ToolTip = minRespawnText.ToolTip; minRespawnSlider.UserData = minRespawnText; minRespawnSlider.Step = 0.1f; @@ -393,13 +409,13 @@ namespace Barotrauma.Networking }; minRespawnSlider.OnMoved(minRespawnSlider, MinRespawnRatio); - y += 35; + y += 30; var respawnDurationText = new GUITextBlock(new Rectangle(0, y, 200, 20), "Duration of respawn transport", GUI.Style, settingsTabs[0]); respawnDurationText.ToolTip = "The amount of time respawned players have to navigate the respawn shuttle to the main submarine. " + "After the duration expires, the shuttle will automatically head back out of the level."; - var respawnDurationSlider = new GUIScrollBar(new Rectangle(150, y + 22, 100, 10), GUI.Style, 0.1f, settingsTabs[0]); + var respawnDurationSlider = new GUIScrollBar(new Rectangle(150, y + 20, 100, 10), GUI.Style, 0.1f, settingsTabs[0]); respawnDurationSlider.ToolTip = minRespawnText.ToolTip; respawnDurationSlider.UserData = respawnDurationText; respawnDurationSlider.Step = 0.1f; @@ -423,8 +439,40 @@ namespace Barotrauma.Networking }; respawnDurationSlider.OnMoved(respawnDurationSlider, respawnDurationSlider.BarScroll); - y += 40; + y += 35; + var monsterButton = new GUIButton(new Rectangle(0, y, 130, 20), "Monster Spawns", GUI.Style, settingsTabs[0]); + monsterButton.Enabled = !GameStarted; + var monsterFrame = new GUIListBox(new Rectangle(-290, 60, 280, 250), GUI.Style, settingsTabs[0]); + monsterFrame.Visible = false; + monsterButton.UserData = monsterFrame; + monsterButton.OnClicked = (button, obj) => + { + ((GUIComponent)obj).Visible = !((GUIComponent)obj).Visible; + return true; + }; + foreach (string s in monsterNames) + { + GUITextBlock textBlock = new GUITextBlock( + new Rectangle(0, 0, 260, 25), + s, + GUI.Style, + Alignment.Left, Alignment.Left, monsterFrame); + textBlock.Padding = new Vector4(35.0f, 3.0f, 0.0f, 0.0f); + textBlock.UserData = monsterFrame; + textBlock.CanBeFocused = false; + + var monsterEnabledBox = new GUITickBox(new Rectangle(-25, 0, 20, 20), "", Alignment.Left, textBlock); + monsterEnabledBox.Selected = monsterEnabled[s]; + monsterEnabledBox.OnSelected = (GUITickBox) => + { + monsterEnabled[s] = !monsterEnabled[s]; + return true; + }; + } + + var cargoButton = new GUIButton(new Rectangle(160, y, 130, 20), "Additional Cargo", GUI.Style, settingsTabs[0]); + cargoButton.Enabled = !GameStarted; //-------------------------------------------------------------------------------- // server settings