diff --git a/Barotrauma/BarotraumaClient/BarotraumaClient.csproj b/Barotrauma/BarotraumaClient/BarotraumaClient.csproj index e2b9c47b5..16b41b3b4 100644 --- a/Barotrauma/BarotraumaClient/BarotraumaClient.csproj +++ b/Barotrauma/BarotraumaClient/BarotraumaClient.csproj @@ -198,8 +198,8 @@ - - + + diff --git a/Barotrauma/BarotraumaClient/Source/Characters/AI/CrewCommander.cs b/Barotrauma/BarotraumaClient/Source/Characters/AI/CrewCommander.cs index 15463f1f9..b85f08e67 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/AI/CrewCommander.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/AI/CrewCommander.cs @@ -148,7 +148,7 @@ namespace Barotrauma frame.RemoveChild(child); } - List aliveCharacters = crewManager.characters.FindAll(c => !c.IsDead && c.AIController is HumanAIController); + List aliveCharacters = crewManager.GetCharacters().FindAll(c => !c.IsDead && c.AIController is HumanAIController); characterFrameBottom = 0; diff --git a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs index 4f5b4fcd8..8d54f0a0d 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/Character.cs @@ -192,9 +192,9 @@ namespace Barotrauma if (controlled == this) controlled = null; if (GameMain.GameSession?.CrewManager != null && - GameMain.GameSession.CrewManager.characters.Contains(this)) + GameMain.GameSession.CrewManager.GetCharacters().Contains(this)) { - GameMain.GameSession.CrewManager.characters.Remove(this); + GameMain.GameSession.CrewManager.RemoveCharacter(this); } if (GameMain.Client != null && GameMain.Client.Character == this) GameMain.Client.Character = null; diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs index 6a2a08c6c..2ca2c5f43 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs @@ -291,7 +291,7 @@ namespace Barotrauma if (configPath == Character.HumanConfigFile) { - GameMain.GameSession.CrewManager.characters.Add(character); + GameMain.GameSession.CrewManager.AddCharacter(character); } } diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs index 3aa555c95..6114b2e7a 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs @@ -9,8 +9,8 @@ namespace Barotrauma { class CrewManager { - public List characters; - public List CharacterInfos; + private List characterInfos; + private List characters; public int WinningTeam = 1; @@ -27,7 +27,7 @@ namespace Barotrauma public CrewManager() { characters = new List(); - CharacterInfos = new List(); + characterInfos = new List(); guiFrame = new GUIFrame(new Rectangle(0, 50, 150, 450), Color.Transparent); guiFrame.Padding = Vector4.One * 5.0f; @@ -50,10 +50,20 @@ namespace Barotrauma { if (subElement.Name.ToString().ToLowerInvariant() != "character") continue; - CharacterInfos.Add(new CharacterInfo(subElement)); + characterInfos.Add(new CharacterInfo(subElement)); } } + public List GetCharacters() + { + return characters; + } + + public List GetCharacterInfos() + { + return characterInfos; + } + public bool SelectCharacter(GUIComponent component, object selection) { //listBox.Select(selection); @@ -108,28 +118,44 @@ namespace Barotrauma public void AddCharacter(Character character) { characters.Add(character); - if (!CharacterInfos.Contains(character.Info)) + if (!characterInfos.Contains(character.Info)) { - CharacterInfos.Add(character.Info); + characterInfos.Add(character.Info); } if (character is AICharacter) { commander.UpdateCharacters(); + + character.Info.CreateCharacterFrame(listBox, character.Info.Name.Replace(' ', '\n'), character); + + GUIFrame orderFrame = new GUIFrame(new Rectangle(0, 0, 40, 40), Color.Transparent, "ListBoxElement", orderListBox); + orderFrame.UserData = character; + + var ai = character.AIController as HumanAIController; + if (ai == null) + { + DebugConsole.ThrowError("Error in crewmanager - attempted to give orders to a character with no HumanAIController"); + return; + } + SetCharacterOrder(character, ai.CurrentOrder); } + } - character.Info.CreateCharacterFrame(listBox, character.Info.Name.Replace(' ', '\n'), character); + public void RemoveCharacter(Character character) + { + characters.Remove(character); + } - GUIFrame orderFrame = new GUIFrame(new Rectangle(0, 0, 40, 40), Color.Transparent, "ListBoxElement", orderListBox); - orderFrame.UserData = character; - - var ai = character.AIController as HumanAIController; - if (ai == null) + public void AddCharacterInfo(CharacterInfo characterInfo) + { + if (characterInfos.Contains(characterInfo)) { - DebugConsole.ThrowError("Error in crewmanager - attempted to give orders to a character with no HumanAIController"); + DebugConsole.ThrowError("Tried to add the same character info to CrewManager twice.\n" +Environment.StackTrace); return; } - SetCharacterOrder(character, ai.CurrentOrder); + + characterInfos.Add(characterInfo); } public void AddToGUIUpdateList() @@ -180,11 +206,7 @@ namespace Barotrauma if (killedCharacter is AICharacter) { commander.UpdateCharacters(); - } - //if (characters.Find(c => !c.IsDead)==null) - //{ - // Game1.GameSession.EndShift(null, null); - //} + } } public void CreateCrewFrame(List crew, GUIFrame crewFrame) @@ -231,8 +253,6 @@ namespace Barotrauma y += crewList.Rect.Height + 30; } - - } protected virtual bool SelectCrewCharacter(Character character, GUIComponent crewList) @@ -254,35 +274,28 @@ namespace Barotrauma return true; } - - //private bool ToggleCrewFrame(GUIButton button, object obj) - //{ - // if (crewFrame == null) CreateCrewFrame(characters); - - // crewFrameOpen = !crewFrameOpen; - // return true; - //} + public void StartRound() { listBox.ClearChildren(); characters.Clear(); - WayPoint[] waypoints = WayPoint.SelectCrewSpawnPoints(CharacterInfos, Submarine.MainSub, false); + WayPoint[] waypoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSub, false); for (int i = 0; i < waypoints.Length; i++) { Character character; - if (CharacterInfos[i].HullID != null) + if (characterInfos[i].HullID != null) { - var hull = Entity.FindEntityByID((ushort)CharacterInfos[i].HullID) as Hull; + var hull = Entity.FindEntityByID((ushort)characterInfos[i].HullID) as Hull; if (hull == null) continue; - character = Character.Create(CharacterInfos[i], hull.WorldPosition); + character = Character.Create(characterInfos[i], hull.WorldPosition); } else { - character = Character.Create(CharacterInfos[i], waypoints[i].WorldPosition); + character = Character.Create(characterInfos[i], waypoints[i].WorldPosition); Character.Controlled = character; if (character.Info != null && !character.Info.StartItemsGiven) @@ -308,18 +321,26 @@ namespace Barotrauma continue; } - CharacterInfos.Remove(c.Info); + characterInfos.Remove(c.Info); } //remove characterinfos whose character doesn't exist anymore //(i.e. character was removed during the round) - CharacterInfos.RemoveAll(c => c.Character == null); + characterInfos.RemoveAll(c => c.Character == null); characters.Clear(); listBox.ClearChildren(); orderListBox.ClearChildren(); } + public void Reset() + { + characters.Clear(); + characterInfos.Clear(); + listBox.ClearChildren(); + orderListBox.ClearChildren(); + } + public void Draw(SpriteBatch spriteBatch) { if (commander.IsOpen) @@ -336,7 +357,7 @@ namespace Barotrauma { XElement element = new XElement("crew"); - foreach (CharacterInfo ci in CharacterInfos) + foreach (CharacterInfo ci in characterInfos) { ci.Save(element); } diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/SinglePlayerCampaign.cs b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/SinglePlayerCampaign.cs index 3ef0cef3f..f22fbae1a 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/SinglePlayerCampaign.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/GameModes/SinglePlayerCampaign.cs @@ -48,7 +48,7 @@ namespace Barotrauma break; } - CrewManager.CharacterInfos.Add(new CharacterInfo(Character.HumanConfigFile, "", Gender.None, jobPrefab)); + CrewManager.AddCharacterInfo(new CharacterInfo(Character.HumanConfigFile, "", Gender.None, jobPrefab)); } } @@ -74,7 +74,7 @@ namespace Barotrauma if (Money < characterInfo.Salary) return false; hireManager.availableCharacters.Remove(characterInfo); - CrewManager.CharacterInfos.Add(characterInfo); + CrewManager.AddCharacterInfo(characterInfo); Money -= characterInfo.Salary; return true; @@ -155,7 +155,7 @@ namespace Barotrauma if (!crewDead) { - if (!CrewManager.characters.Any(c => !c.IsDead)) crewDead = true; + if (!CrewManager.GetCharacters().Any(c => !c.IsDead)) crewDead = true; } else { @@ -169,7 +169,7 @@ namespace Barotrauma { isRunning = false; - bool success = CrewManager.characters.Any(c => !c.IsDead); + bool success = CrewManager.GetCharacters().Any(c => !c.IsDead); if (success) { @@ -290,7 +290,7 @@ namespace Barotrauma var cinematic = new TransitionCinematic(leavingSubs, GameMain.GameScreen.Cam, 5.0f); - SoundPlayer.OverrideMusicType = CrewManager.characters.Any(c => !c.IsDead) ? "endround" : "crewdead"; + SoundPlayer.OverrideMusicType = CrewManager.GetCharacters().Any(c => !c.IsDead) ? "endround" : "crewdead"; CoroutineManager.StartCoroutine(EndCinematic(cinematic), "EndCinematic"); diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/GameSession.cs b/Barotrauma/BarotraumaClient/Source/GameSession/GameSession.cs index 14f414a04..525f25859 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/GameSession.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/GameSession.cs @@ -77,7 +77,7 @@ namespace Barotrauma switch (selectedTab) { case InfoFrameTab.Crew: - CrewManager.CreateCrewFrame(CrewManager.characters, infoFrame.children[0] as GUIFrame); + CrewManager.CreateCrewFrame(CrewManager.GetCharacters(), infoFrame.children[0] as GUIFrame); break; case InfoFrameTab.Mission: CreateMissionInfo(infoFrame.children[0] as GUIFrame); diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/RoundSummary.cs b/Barotrauma/BarotraumaClient/Source/GameSession/RoundSummary.cs index c9aec3750..4e2228582 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/RoundSummary.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/RoundSummary.cs @@ -26,7 +26,7 @@ namespace Barotrauma { bool singleplayer = GameMain.NetworkMember == null; - bool gameOver = gameSession.CrewManager.characters.All(c => c.IsDead); + bool gameOver = gameSession.CrewManager.GetCharacters().All(c => c.IsDead); bool progress = Submarine.MainSub.AtEndPosition; GUIFrame frame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.8f, null); @@ -59,7 +59,7 @@ namespace Barotrauma GUIListBox listBox = new GUIListBox(new Rectangle(0,y,0,90), null, Alignment.TopLeft, "", innerFrame, true); int x = 0; - foreach (CharacterInfo characterInfo in gameSession.CrewManager.CharacterInfos) + foreach (CharacterInfo characterInfo in gameSession.CrewManager.GetCharacterInfos()) { if (GameMain.GameSession.Mission is CombatMission && characterInfo.TeamID != GameMain.GameSession.CrewManager.WinningTeam) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index adeec7143..7942fe4c2 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -718,6 +718,7 @@ namespace Barotrauma.Networking } else { + if (GameMain.GameSession?.CrewManager != null) GameMain.GameSession.CrewManager.Reset(); GameMain.GameSession.StartRound(campaign.Map.SelectedConnection.Level, true, false); } diff --git a/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs b/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs index 3f07ea7cf..4b49a3811 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/CampaignUI.cs @@ -181,7 +181,7 @@ namespace Barotrauma public void UpdateCharacterLists() { characterList.ClearChildren(); - foreach (CharacterInfo c in GameMain.GameSession.CrewManager.CharacterInfos) + foreach (CharacterInfo c in GameMain.GameSession.CrewManager.GetCharacterInfos()) { c.CreateCharacterFrame(characterList, c.Name + " (" + c.Job.Name + ") ", c); } diff --git a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs index 1f60618a8..7c671cd86 100644 --- a/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs +++ b/Barotrauma/BarotraumaShared/Source/GameSession/GameModes/MultiplayerCampaign.cs @@ -186,6 +186,9 @@ namespace Barotrauma if (GameMain.Client != null) { GameMain.GameSession.EndRound(""); +#if CLIENT + GameMain.GameSession.CrewManager.EndRound(); +#endif return; } @@ -221,6 +224,10 @@ namespace Barotrauma } } +#if CLIENT + GameMain.GameSession.CrewManager.EndRound(); +#endif + if (success) { bool atEndPosition = Submarine.MainSub.AtEndPosition; diff --git a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs index 0cf3eb2fd..9cdb67c42 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/GameServer.cs @@ -1189,6 +1189,9 @@ namespace Barotrauma.Networking if (campaign != null) { +#if CLIENT + if (GameMain.GameSession?.CrewManager != null) GameMain.GameSession.CrewManager.Reset(); +#endif GameMain.GameSession.StartRound(campaign.Map.SelectedConnection.Level, true, teamCount > 1); } else @@ -1258,7 +1261,7 @@ namespace Barotrauma.Networking teamClients[i].Character = spawnedCharacter; #if CLIENT - GameMain.GameSession.CrewManager.characters.Add(spawnedCharacter); + GameMain.GameSession.CrewManager.AddCharacter(spawnedCharacter); #endif } @@ -1271,7 +1274,7 @@ namespace Barotrauma.Networking Character.Controlled = myCharacter; - GameMain.GameSession.CrewManager.characters.Add(myCharacter); + GameMain.GameSession.CrewManager.AddCharacter(myCharacter); } #endif } diff --git a/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs b/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs index 0fe95edf1..5d2da8958 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs @@ -481,10 +481,10 @@ namespace Barotrauma.Networking if (scooterPrefab != null && batteryPrefab != null) { var scooter = new Item(scooterPrefab, pos, respawnShuttle); - Entity.Spawner.CreateNetworkEvent(scooter, false); + Spawner.CreateNetworkEvent(scooter, false); var battery = new Item(batteryPrefab, pos, respawnShuttle); - Entity.Spawner.CreateNetworkEvent(battery, false); + Spawner.CreateNetworkEvent(battery, false); scooter.Combine(battery); } @@ -502,7 +502,7 @@ namespace Barotrauma.Networking } } #if CLIENT - GameMain.GameSession.CrewManager.characters.Add(character); + GameMain.GameSession.CrewManager.AddCharacter(character); #endif }