Fixed characters not appearing in the round summary in mp, minor CrewManager refactoring
This commit is contained in:
@@ -198,8 +198,8 @@
|
||||
<Compile Include="Source\Screens\BlurEffect.cs" />
|
||||
<Compile Include="Source\Screens\CampaignSetupUI.cs" />
|
||||
<Compile Include="Source\Screens\CampaignUI.cs" />
|
||||
<Compile Include="Source\Screens\EditCharacterScreen.cs" />
|
||||
<Compile Include="Source\Screens\EditMapScreen.cs" />
|
||||
<Compile Include="Source\Screens\CharacterEditorScreen.cs" />
|
||||
<Compile Include="Source\Screens\SubEditorScreen.cs" />
|
||||
<Compile Include="Source\Screens\GameScreen.cs" />
|
||||
<Compile Include="Source\Screens\LobbyScreen.cs" />
|
||||
<Compile Include="Source\Screens\MainMenuScreen.cs" />
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace Barotrauma
|
||||
frame.RemoveChild(child);
|
||||
}
|
||||
|
||||
List<Character> aliveCharacters = crewManager.characters.FindAll(c => !c.IsDead && c.AIController is HumanAIController);
|
||||
List<Character> aliveCharacters = crewManager.GetCharacters().FindAll(c => !c.IsDead && c.AIController is HumanAIController);
|
||||
|
||||
characterFrameBottom = 0;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -291,7 +291,7 @@ namespace Barotrauma
|
||||
|
||||
if (configPath == Character.HumanConfigFile)
|
||||
{
|
||||
GameMain.GameSession.CrewManager.characters.Add(character);
|
||||
GameMain.GameSession.CrewManager.AddCharacter(character);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace Barotrauma
|
||||
{
|
||||
class CrewManager
|
||||
{
|
||||
public List<Character> characters;
|
||||
public List<CharacterInfo> CharacterInfos;
|
||||
private List<CharacterInfo> characterInfos;
|
||||
private List<Character> characters;
|
||||
|
||||
public int WinningTeam = 1;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Barotrauma
|
||||
public CrewManager()
|
||||
{
|
||||
characters = new List<Character>();
|
||||
CharacterInfos = new List<CharacterInfo>();
|
||||
characterInfos = new List<CharacterInfo>();
|
||||
|
||||
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<Character> GetCharacters()
|
||||
{
|
||||
return characters;
|
||||
}
|
||||
|
||||
public List<CharacterInfo> 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<Character> 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);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user