Fixed host's character spawning twice, some cleanup (LINQ <3)
This commit is contained in:
@@ -4,6 +4,7 @@ using Barotrauma;
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -17,7 +18,7 @@ namespace Barotrauma
|
||||
public List<Character> TeamBCrew = new List<Character>();
|
||||
|
||||
int state = 0;
|
||||
string winner; string loser;
|
||||
string winner, loser;
|
||||
|
||||
public override string SuccessMessage
|
||||
{
|
||||
@@ -30,7 +31,7 @@ namespace Barotrauma
|
||||
|
||||
}
|
||||
|
||||
public override bool AssignClientIDs(List<Client> clients)
|
||||
public override bool AssignTeamIDs(List<Client> clients)
|
||||
{
|
||||
List<Client> randList = new List<Client>(clients);
|
||||
for (int i = 0; i < randList.Count; i++)
|
||||
@@ -105,22 +106,8 @@ namespace Barotrauma
|
||||
GameMain.Server.AllowRespawn = false;
|
||||
}
|
||||
|
||||
bool ADead = true;
|
||||
foreach (Character c in TeamACrew)
|
||||
{
|
||||
if (!c.IsDead)
|
||||
{
|
||||
ADead = false; break;
|
||||
}
|
||||
}
|
||||
bool BDead = true;
|
||||
foreach (Character c in TeamBCrew)
|
||||
{
|
||||
if (!c.IsDead)
|
||||
{
|
||||
BDead = false; break;
|
||||
}
|
||||
}
|
||||
bool ADead = TeamACrew.All(c => c.IsDead);
|
||||
bool BDead = TeamBCrew.All(c => c.IsDead);
|
||||
|
||||
if (BDead && !ADead)
|
||||
{
|
||||
@@ -164,22 +151,8 @@ namespace Barotrauma
|
||||
|
||||
public override void End()
|
||||
{
|
||||
bool ADead = true;
|
||||
foreach (Character c in TeamACrew)
|
||||
{
|
||||
if (!c.IsDead && !c.IsUnconscious)
|
||||
{
|
||||
ADead = false; break;
|
||||
}
|
||||
}
|
||||
bool BDead = true;
|
||||
foreach (Character c in TeamBCrew)
|
||||
{
|
||||
if (!c.IsDead && !c.IsUnconscious)
|
||||
{
|
||||
BDead = false; break;
|
||||
}
|
||||
}
|
||||
bool ADead = TeamACrew.All(c => c.IsDead || c.IsUnconscious);
|
||||
bool BDead = TeamBCrew.All(c => c.IsDead || c.IsUnconscious);
|
||||
|
||||
if (BDead && !ADead)
|
||||
{
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace Barotrauma
|
||||
|
||||
public virtual void Update(float deltaTime) { }
|
||||
|
||||
public virtual bool AssignClientIDs(List<Networking.Client> clients) { return false; }
|
||||
public virtual bool AssignTeamIDs(List<Networking.Client> clients) { return false; }
|
||||
|
||||
public void ShowMessage(int index)
|
||||
{
|
||||
|
||||
@@ -890,10 +890,14 @@ namespace Barotrauma.Networking
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
bool hasTwoTeams = false;
|
||||
if (GameMain.GameSession.gameMode.Mission != null) hasTwoTeams = GameMain.GameSession.gameMode.Mission.AssignClientIDs(connectedClients);
|
||||
int teamCount = 1;
|
||||
if (GameMain.GameSession.gameMode.Mission != null &&
|
||||
GameMain.GameSession.gameMode.Mission.AssignTeamIDs(connectedClients))
|
||||
{
|
||||
teamCount = 2;
|
||||
}
|
||||
|
||||
GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed,hasTwoTeams);
|
||||
GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed, teamCount > 1);
|
||||
|
||||
GameServer.Log("Starting a new round...", Color.Cyan);
|
||||
GameServer.Log("Submarine: " + selectedSub.Name, Color.Cyan);
|
||||
@@ -902,13 +906,16 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (AllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle);
|
||||
|
||||
if (!hasTwoTeams)
|
||||
for (int j = 0; j < teamCount; j++)
|
||||
{
|
||||
AssignJobs(connectedClients);
|
||||
List<Client> teamClients = connectedClients.FindAll(c => c.TeamID == j).ToList();
|
||||
if (teamClients == null) continue;
|
||||
|
||||
AssignJobs(teamClients);
|
||||
|
||||
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
||||
|
||||
foreach (Client client in connectedClients)
|
||||
foreach (Client client in teamClients)
|
||||
{
|
||||
client.inGame = true;
|
||||
|
||||
@@ -927,18 +934,21 @@ namespace Barotrauma.Networking
|
||||
characterInfos.Add(characterInfo);
|
||||
}
|
||||
|
||||
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSub);
|
||||
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSubs[j]);
|
||||
|
||||
for (int i = 0; i < connectedClients.Count; i++)
|
||||
for (int i = 0; i < teamClients.Count; i++)
|
||||
{
|
||||
connectedClients[i].Character = Character.Create(
|
||||
connectedClients[i].characterInfo, assignedWayPoints[i].WorldPosition, true, false);
|
||||
connectedClients[i].Character.GiveJobItems(assignedWayPoints[i]);
|
||||
teamClients[i].Character = Character.Create(
|
||||
teamClients[i].characterInfo, assignedWayPoints[i].WorldPosition, true, false);
|
||||
teamClients[i].Character.GiveJobItems(assignedWayPoints[i]);
|
||||
|
||||
GameMain.GameSession.CrewManager.characters.Add(connectedClients[i].Character);
|
||||
GameMain.GameSession.CrewManager.characters.Add(teamClients[i].Character);
|
||||
|
||||
teamClients[i].Character.TeamID = teamClients[i].TeamID;
|
||||
}
|
||||
|
||||
if (characterInfo != null)
|
||||
//host plays in team 0
|
||||
if (characterInfo != null && j == 0)
|
||||
{
|
||||
myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false);
|
||||
Character.Controlled = myCharacter;
|
||||
@@ -948,59 +958,7 @@ namespace Barotrauma.Networking
|
||||
GameMain.GameSession.CrewManager.characters.Add(myCharacter);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int j=0;j<2;j++)
|
||||
{
|
||||
List<Client> teamClients = connectedClients.FindAll(c => c.TeamID == j).ToList();
|
||||
if (teamClients == null) continue;
|
||||
AssignJobs(teamClients);
|
||||
|
||||
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
||||
|
||||
foreach (Client client in teamClients)
|
||||
{
|
||||
client.inGame = true;
|
||||
|
||||
if (client.characterInfo == null)
|
||||
{
|
||||
client.characterInfo = new CharacterInfo(Character.HumanConfigFile, client.name);
|
||||
}
|
||||
characterInfos.Add(client.characterInfo);
|
||||
|
||||
client.characterInfo.Job = new Job(client.assignedJob);
|
||||
}
|
||||
|
||||
if (characterInfo != null)
|
||||
{
|
||||
characterInfo.Job = new Job(GameMain.NetLobbyScreen.JobPreferences[0]);
|
||||
characterInfos.Add(characterInfo);
|
||||
}
|
||||
|
||||
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSubs[j]);
|
||||
|
||||
for (int i = 0; i < teamClients.Count; i++)
|
||||
{
|
||||
teamClients[i].Character = Character.Create(
|
||||
teamClients[i].characterInfo, assignedWayPoints[i].WorldPosition, true, false);
|
||||
teamClients[i].Character.GiveJobItems(assignedWayPoints[i]);
|
||||
|
||||
GameMain.GameSession.CrewManager.characters.Add(teamClients[i].Character);
|
||||
|
||||
teamClients[i].Character.TeamID = teamClients[i].TeamID;
|
||||
}
|
||||
|
||||
if (characterInfo != null)
|
||||
{
|
||||
myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false);
|
||||
Character.Controlled = myCharacter;
|
||||
|
||||
myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]);
|
||||
|
||||
GameMain.GameSession.CrewManager.characters.Add(myCharacter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user