From 067db912f458b52d65c70c246f1b020e44059b69 Mon Sep 17 00:00:00 2001 From: Regalis Date: Fri, 24 Mar 2017 18:49:03 +0200 Subject: [PATCH] - EntitySpawner recursively deletes contained items when an item is deleted - items in the inventories of the characters inside the shuttle are deleted when resetting the respawn shuttle - fixed host's character not being taken into account when assigning jobs for respawning characters if the host is not respawning --- Subsurface/Source/GameSession/CrewManager.cs | 24 ++++--------------- Subsurface/Source/Networking/EntitySpawner.cs | 15 ++++++++++-- Subsurface/Source/Networking/GameServer.cs | 4 ++++ .../Source/Networking/RespawnManager.cs | 13 ++++++++-- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/Subsurface/Source/GameSession/CrewManager.cs b/Subsurface/Source/GameSession/CrewManager.cs index 4d2024d0c..62245a1b3 100644 --- a/Subsurface/Source/GameSession/CrewManager.cs +++ b/Subsurface/Source/GameSession/CrewManager.cs @@ -98,20 +98,20 @@ namespace Barotrauma img.Color = order.Color; img.CanBeFocused = false; - orderListBox.children[characterIndex].ToolTip = "Order: " + order.Name; + orderListBox.children[characterIndex].ToolTip = "Order: " + order.Name; } public bool SelectCharacterOrder(GUIComponent component, object selection) { - GameMain.GameSession.CrewManager.commander.ToggleGUIFrame(); + commander.ToggleGUIFrame(); int orderIndex = orderListBox.children.IndexOf(component); - if (orderIndex<0 || orderIndex >= listBox.children.Count) return false; + if (orderIndex < 0 || orderIndex >= listBox.children.Count) return false; var characterFrame = listBox.children[orderIndex]; if (characterFrame == null) return false; - GameMain.GameSession.CrewManager.commander.SelectCharacter(characterFrame.UserData as Character); + commander.SelectCharacter(characterFrame.UserData as Character); return false; } @@ -129,7 +129,6 @@ namespace Barotrauma commander.UpdateCharacters(); } - character.Info.CreateCharacterFrame(listBox, character.Info.Name.Replace(' ', '\n'), character); GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 40, 40), Color.Transparent, null, orderListBox); @@ -140,21 +139,6 @@ namespace Barotrauma var ai = character.AIController as HumanAIController; SetCharacterOrder(character, ai.CurrentOrder); - - - - //string name = character.Info.Name.Replace(' ', '\n'); - - //GUITextBlock textBlock = new GUITextBlock( - // new Rectangle(40, 0, 0, 25), - // name, - // Color.Transparent, Color.White, - // Alignment.Left, Alignment.Left, - // null, frame, false); - //textBlock.Font = GUI.SmallFont; - //textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f); - - //new GUIImage(new Rectangle(-10, -5, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame); } public void AddToGUIUpdateList() diff --git a/Subsurface/Source/Networking/EntitySpawner.cs b/Subsurface/Source/Networking/EntitySpawner.cs index ff8b29da0..873aa79f2 100644 --- a/Subsurface/Source/Networking/EntitySpawner.cs +++ b/Subsurface/Source/Networking/EntitySpawner.cs @@ -118,12 +118,23 @@ namespace Barotrauma removeQueue.Enqueue(entity); } - public void Update() + public void AddToRemoveQueue(Item item) { if (GameMain.Client != null) return; - if (!spawnQueue.Any()) return; + removeQueue.Enqueue(item); + if (item.ContainedItems == null) return; + foreach (Item containedItem in item.ContainedItems) + { + if (containedItem != null) AddToRemoveQueue(containedItem); + } + } + + public void Update() + { + if (GameMain.Client != null) return; + while (spawnQueue.Count>0) { var entitySpawnInfo = spawnQueue.Dequeue(); diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index bb3a10da3..64dca5769 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -1891,6 +1891,10 @@ namespace Barotrauma.Networking assignedClientCount[JobPrefab.List.IndexOf(myCharacter.Info.Job.Prefab)] = 1; } } + else if (myCharacter != null && !myCharacter.IsDead) + { + assignedClientCount[JobPrefab.List.IndexOf(myCharacter.Info.Job.Prefab)]++; + } //count the clients who already have characters with an assigned job foreach (Client c in connectedClients) diff --git a/Subsurface/Source/Networking/RespawnManager.cs b/Subsurface/Source/Networking/RespawnManager.cs index 90b3620cc..5835cc50b 100644 --- a/Subsurface/Source/Networking/RespawnManager.cs +++ b/Subsurface/Source/Networking/RespawnManager.cs @@ -324,7 +324,8 @@ namespace Barotrauma.Networking if (item.body != null && item.body.Enabled && item.ParentInventory == null) { - Item.Spawner.AddToRemoveQueue(item); + Entity.Spawner.AddToRemoveQueue(item); + continue; } item.Condition = 100.0f; @@ -362,9 +363,17 @@ namespace Barotrauma.Networking if (c.Submarine == respawnShuttle) { if (Character.Controlled == c) Character.Controlled = null; - //if (networkMember.Character == c) networkMember.Character = null; c.Enabled = false; + if (c.Inventory != null) + { + foreach (Item item in c.Inventory.Items) + { + if (item == null) continue; + Entity.Spawner.AddToRemoveQueue(item); + } + } + c.Kill(CauseOfDeath.Damage, true); } }