Added an option to respawn directly in the main sub

This commit is contained in:
juanjp600
2017-12-05 03:03:37 -03:00
parent e69e316f6b
commit c6ca3572ba
6 changed files with 121 additions and 52 deletions
@@ -528,12 +528,14 @@ namespace Barotrauma.Networking
string subName = inc.ReadString(); string subName = inc.ReadString();
string subHash = inc.ReadString(); string subHash = inc.ReadString();
bool usingShuttle = inc.ReadBoolean();
string shuttleName = inc.ReadString(); string shuttleName = inc.ReadString();
string shuttleHash = inc.ReadString(); string shuttleHash = inc.ReadString();
NetOutgoingMessage readyToStartMsg = client.CreateMessage(); NetOutgoingMessage readyToStartMsg = client.CreateMessage();
readyToStartMsg.Write((byte)ClientPacketHeader.RESPONSE_STARTGAME); readyToStartMsg.Write((byte)ClientPacketHeader.RESPONSE_STARTGAME);
GameMain.NetLobbyScreen.UsingShuttle = usingShuttle;
readyToStartMsg.Write( readyToStartMsg.Write(
GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList) && GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList) &&
GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox)); GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox));
@@ -654,6 +656,7 @@ namespace Barotrauma.Networking
string subName = inc.ReadString(); string subName = inc.ReadString();
string subHash = inc.ReadString(); string subHash = inc.ReadString();
bool usingShuttle = inc.ReadBoolean();
string shuttleName = inc.ReadString(); string shuttleName = inc.ReadString();
string shuttleHash = inc.ReadString(); string shuttleHash = inc.ReadString();
@@ -697,6 +700,8 @@ namespace Barotrauma.Networking
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
} }
GameMain.NetLobbyScreen.UsingShuttle = usingShuttle;
if (campaign == null) if (campaign == null)
{ {
if (!GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList)) if (!GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList))
@@ -723,7 +728,7 @@ namespace Barotrauma.Networking
GameMain.GameSession.StartRound(campaign.Map.SelectedConnection.Level, true, false); GameMain.GameSession.StartRound(campaign.Map.SelectedConnection.Level, true, false);
} }
if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.SelectedShuttle); if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.UsingShuttle ? GameMain.NetLobbyScreen.SelectedShuttle : null);
if (isTraitor) if (isTraitor)
{ {
@@ -842,6 +847,7 @@ namespace Barotrauma.Networking
string selectSubName = inc.ReadString(); string selectSubName = inc.ReadString();
string selectSubHash = inc.ReadString(); string selectSubHash = inc.ReadString();
bool usingShuttle = inc.ReadBoolean();
string selectShuttleName = inc.ReadString(); string selectShuttleName = inc.ReadString();
string selectShuttleHash = inc.ReadString(); string selectShuttleHash = inc.ReadString();
@@ -878,6 +884,8 @@ namespace Barotrauma.Networking
GameMain.NetLobbyScreen.ServerName = serverName; GameMain.NetLobbyScreen.ServerName = serverName;
GameMain.NetLobbyScreen.ServerMessage.Text = serverText; GameMain.NetLobbyScreen.ServerMessage.Text = serverText;
GameMain.NetLobbyScreen.UsingShuttle = usingShuttle;
if (!allowSubVoting) if (!allowSubVoting)
{ {
GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList); GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList);
@@ -137,8 +137,8 @@ namespace Barotrauma.Networking
if (respawnManager.CurrentState == RespawnManager.State.Waiting && if (respawnManager.CurrentState == RespawnManager.State.Waiting &&
respawnManager.CountdownStarted) respawnManager.CountdownStarted)
{ {
respawnInfo = respawnManager.RespawnTimer <= 0.0f ? "" : "Respawn Shuttle dispatching in " + ToolBox.SecondsToReadableTime(respawnManager.RespawnTimer); respawnInfo = respawnManager.UsingShuttle ? "Respawn Shuttle dispatching in " : "Respawning players in ";
respawnInfo = respawnManager.RespawnTimer <= 0.0f ? "" : respawnInfo + ToolBox.SecondsToReadableTime(respawnManager.RespawnTimer);
} }
else if (respawnManager.CurrentState == RespawnManager.State.Transporting) else if (respawnManager.CurrentState == RespawnManager.State.Transporting)
{ {
@@ -47,6 +47,7 @@ namespace Barotrauma
private GUITickBox autoRestartBox; private GUITickBox autoRestartBox;
private GUIDropDown shuttleList; private GUIDropDown shuttleList;
private GUITickBox shuttleTickBox;
private CampaignUI campaignUI; private CampaignUI campaignUI;
@@ -77,6 +78,11 @@ namespace Barotrauma
get { return shuttleList; } get { return shuttleList; }
} }
public GUITickBox ShuttleTickBox
{
get { return shuttleTickBox; }
}
public GUIListBox ModeList public GUIListBox ModeList
{ {
get { return modeList; } get { return modeList; }
@@ -120,6 +126,12 @@ namespace Barotrauma
get { return shuttleList.SelectedData as Submarine; } get { return shuttleList.SelectedData as Submarine; }
} }
public bool UsingShuttle
{
get { return shuttleTickBox.Selected; }
set { shuttleTickBox.Selected = value; if (GameMain.Client != null) shuttleTickBox.Enabled = false; }
}
public GameModePreset SelectedMode public GameModePreset SelectedMode
{ {
get { return modeList.SelectedData as GameModePreset; } get { return modeList.SelectedData as GameModePreset; }
@@ -245,9 +257,15 @@ namespace Barotrauma
//respawn shuttle ------------------------------------------------------------------ //respawn shuttle ------------------------------------------------------------------
new GUITextBlock(new Rectangle(columnX, 110, 20, 20), "Respawn shuttle:", "", defaultModeContainer); shuttleTickBox = new GUITickBox(new Rectangle(columnX, 110, 20, 20), "Respawn shuttle:",Alignment.Left, defaultModeContainer);
shuttleList = new GUIDropDown(new Rectangle(columnX, 140, 200, 20), "", "", defaultModeContainer); shuttleList = new GUIDropDown(new Rectangle(columnX, 140, 200, 20), "", "", defaultModeContainer);
shuttleTickBox.Selected = true;
shuttleTickBox.OnSelected = (GUITickBox box) =>
{
shuttleList.Enabled = box.Selected;
if (GameMain.Server != null) lastUpdateID++;
return true;
};
//gamemode ------------------------------------------------------------------ //gamemode ------------------------------------------------------------------
@@ -9,6 +9,7 @@ namespace Barotrauma
{ {
private Submarine selectedSub; private Submarine selectedSub;
private Submarine selectedShuttle; private Submarine selectedShuttle;
private bool usingShuttle = true;
public Submarine SelectedSub public Submarine SelectedSub
{ {
@@ -20,6 +21,11 @@ namespace Barotrauma
get { return selectedShuttle; } get { return selectedShuttle; }
set { selectedShuttle = value; lastUpdateID++; } set { selectedShuttle = value; lastUpdateID++; }
} }
public bool UsingShuttle
{
get { return usingShuttle; }
set { usingShuttle = value; lastUpdateID++; }
}
private GameModePreset[] gameModes; private GameModePreset[] gameModes;
public GameModePreset[] GameModes public GameModePreset[] GameModes
@@ -957,6 +957,7 @@ namespace Barotrauma.Networking
} }
outmsg.Write(GameMain.NetLobbyScreen.SelectedSub.Name); outmsg.Write(GameMain.NetLobbyScreen.SelectedSub.Name);
outmsg.Write(GameMain.NetLobbyScreen.SelectedSub.MD5Hash.ToString()); outmsg.Write(GameMain.NetLobbyScreen.SelectedSub.MD5Hash.ToString());
outmsg.Write(GameMain.NetLobbyScreen.UsingShuttle);
outmsg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name); outmsg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name);
outmsg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.ToString()); outmsg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.ToString());
@@ -1062,6 +1063,7 @@ namespace Barotrauma.Networking
{ {
Submarine selectedSub = null; Submarine selectedSub = null;
Submarine selectedShuttle = GameMain.NetLobbyScreen.SelectedShuttle; Submarine selectedShuttle = GameMain.NetLobbyScreen.SelectedShuttle;
bool usingShuttle = GameMain.NetLobbyScreen.UsingShuttle;
if (Voting.AllowSubVoting) if (Voting.AllowSubVoting)
{ {
@@ -1100,12 +1102,12 @@ namespace Barotrauma.Networking
return false; return false;
} }
CoroutineManager.StartCoroutine(InitiateStartGame(selectedSub, selectedShuttle, selectedMode), "InitiateStartGame"); CoroutineManager.StartCoroutine(InitiateStartGame(selectedSub, selectedShuttle, usingShuttle, selectedMode), "InitiateStartGame");
return true; return true;
} }
private IEnumerable<object> InitiateStartGame(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode) private IEnumerable<object> InitiateStartGame(Submarine selectedSub, Submarine selectedShuttle, bool usingShuttle, GameModePreset selectedMode)
{ {
initiatedStartGame = true; initiatedStartGame = true;
GameMain.NetLobbyScreen.StartButtonEnabled = false; GameMain.NetLobbyScreen.StartButtonEnabled = false;
@@ -1118,6 +1120,7 @@ namespace Barotrauma.Networking
msg.Write(selectedSub.Name); msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash); msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(usingShuttle);
msg.Write(selectedShuttle.Name); msg.Write(selectedShuttle.Name);
msg.Write(selectedShuttle.MD5Hash.Hash); msg.Write(selectedShuttle.MD5Hash.Hash);
@@ -1158,12 +1161,12 @@ namespace Barotrauma.Networking
} }
} }
startGameCoroutine = GameMain.Instance.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode), false); startGameCoroutine = GameMain.Instance.ShowLoading(StartGame(selectedSub, selectedShuttle, usingShuttle, selectedMode), false);
yield return CoroutineStatus.Success; yield return CoroutineStatus.Success;
} }
private IEnumerable<object> StartGame(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode) private IEnumerable<object> StartGame(Submarine selectedSub, Submarine selectedShuttle, bool usingShuttle, GameModePreset selectedMode)
{ {
entityEventManager.Clear(); entityEventManager.Clear();
@@ -1219,7 +1222,7 @@ namespace Barotrauma.Networking
(!(GameMain.GameSession.GameMode is MissionMode) || (!(GameMain.GameSession.GameMode is MissionMode) ||
((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn); ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn);
if (AllowRespawn && missionAllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle); if (AllowRespawn && missionAllowRespawn) respawnManager = new RespawnManager(this, usingShuttle ? selectedShuttle : null);
//assign jobs and spawnpoints separately for each team //assign jobs and spawnpoints separately for each team
for (int teamID = 1; teamID <= teamCount; teamID++) for (int teamID = 1; teamID <= teamCount; teamID++)
@@ -1371,7 +1374,7 @@ namespace Barotrauma.Networking
msg.Write(selectedSub.Name); msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash); msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(GameMain.NetLobbyScreen.UsingShuttle);
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name); msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name);
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.Hash); msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.Hash);
@@ -28,6 +28,11 @@ namespace Barotrauma.Networking
private Steering shuttleSteering; private Steering shuttleSteering;
private List<Door> shuttleDoors; private List<Door> shuttleDoors;
public bool UsingShuttle
{
get { return respawnShuttle != null; }
}
/// <summary> /// <summary>
/// How long until the shuttle is dispatched with respawned characters /// How long until the shuttle is dispatched with respawned characters
/// </summary> /// </summary>
@@ -69,34 +74,41 @@ namespace Barotrauma.Networking
{ {
this.networkMember = networkMember; this.networkMember = networkMember;
respawnShuttle = new Submarine(shuttle.FilePath, shuttle.MD5Hash.Hash, true); if (shuttle != null)
respawnShuttle.Load(false);
ResetShuttle();
//respawnShuttle.GodMode = true;
shuttleDoors = new List<Door>();
foreach (Item item in Item.ItemList)
{ {
if (item.Submarine != respawnShuttle) continue; respawnShuttle = new Submarine(shuttle.FilePath, shuttle.MD5Hash.Hash, true);
respawnShuttle.Load(false);
var steering = item.GetComponent<Steering>(); ResetShuttle();
if (steering != null) shuttleSteering = steering;
var door = item.GetComponent<Door>(); //respawnShuttle.GodMode = true;
if (door != null) shuttleDoors.Add(door);
//lock all wires to prevent the players from messing up the electronics shuttleDoors = new List<Door>();
var connectionPanel = item.GetComponent<ConnectionPanel>(); foreach (Item item in Item.ItemList)
if (connectionPanel != null)
{ {
foreach (Connection connection in connectionPanel.Connections) if (item.Submarine != respawnShuttle) continue;
var steering = item.GetComponent<Steering>();
if (steering != null) shuttleSteering = steering;
var door = item.GetComponent<Door>();
if (door != null) shuttleDoors.Add(door);
//lock all wires to prevent the players from messing up the electronics
var connectionPanel = item.GetComponent<ConnectionPanel>();
if (connectionPanel != null)
{ {
Array.ForEach(connection.Wires, w => { if (w != null) w.Locked = true; }); foreach (Connection connection in connectionPanel.Connections)
{
Array.ForEach(connection.Wires, w => { if (w != null) w.Locked = true; });
}
} }
} }
} }
else
{
respawnShuttle = null;
}
var server = networkMember as GameServer; var server = networkMember as GameServer;
if (server != null) if (server != null)
@@ -118,6 +130,14 @@ namespace Barotrauma.Networking
public void Update(float deltaTime) public void Update(float deltaTime)
{ {
if (respawnShuttle == null)
{
if (state != State.Waiting)
{
state = State.Waiting;
}
}
switch (state) switch (state)
{ {
case State.Waiting: case State.Waiting:
@@ -144,11 +164,6 @@ namespace Barotrauma.Networking
return; return;
} }
respawnShuttle.Velocity = Vector2.Zero;
shuttleSteering.AutoPilot = false;
shuttleSteering.MaintainPos = false;
int characterToRespawnCount = GetClientsToRespawn().Count; int characterToRespawnCount = GetClientsToRespawn().Count;
int totalCharacterCount = server.ConnectedClients.Count; int totalCharacterCount = server.ConnectedClients.Count;
if (server.Character != null) if (server.Character != null)
@@ -180,6 +195,13 @@ namespace Barotrauma.Networking
DispatchShuttle(); DispatchShuttle();
} }
if (respawnShuttle == null) return;
respawnShuttle.Velocity = Vector2.Zero;
shuttleSteering.AutoPilot = false;
shuttleSteering.MaintainPos = false;
} }
private void UpdateTransporting(float deltaTime) private void UpdateTransporting(float deltaTime)
@@ -290,19 +312,30 @@ namespace Barotrauma.Networking
var server = networkMember as GameServer; var server = networkMember as GameServer;
if (server == null) return; if (server == null) return;
state = State.Transporting; if (respawnShuttle != null)
server.CreateEntityEvent(this); {
state = State.Transporting;
server.CreateEntityEvent(this);
ResetShuttle(); ResetShuttle();
shuttleSteering.TargetVelocity = Vector2.Zero; shuttleSteering.TargetVelocity = Vector2.Zero;
GameServer.Log("Dispatching the respawn shuttle.", ServerLog.MessageType.Spawning); GameServer.Log("Dispatching the respawn shuttle.", ServerLog.MessageType.Spawning);
RespawnCharacters(); RespawnCharacters();
CoroutineManager.StopCoroutines("forcepos"); CoroutineManager.StopCoroutines("forcepos");
CoroutineManager.StartCoroutine(ForceShuttleToPos(Level.Loaded.StartPosition - Vector2.UnitY * Level.ShaftHeight, 100.0f), "forcepos"); CoroutineManager.StartCoroutine(ForceShuttleToPos(Level.Loaded.StartPosition - Vector2.UnitY * Level.ShaftHeight, 100.0f), "forcepos");
}
else
{
state = State.Waiting;
GameServer.Log("Respawning everyone in main sub.", ServerLog.MessageType.Spawning);
server.CreateEntityEvent(this);
RespawnCharacters();
}
} }
private IEnumerable<object> ForceShuttleToPos(Vector2 position, float speed) private IEnumerable<object> ForceShuttleToPos(Vector2 position, float speed)
@@ -401,6 +434,7 @@ namespace Barotrauma.Networking
var server = networkMember as GameServer; var server = networkMember as GameServer;
if (server == null) return; if (server == null) return;
var respawnSub = respawnShuttle != null ? respawnShuttle : Submarine.MainSub;
var clients = GetClientsToRespawn(); var clients = GetClientsToRespawn();
foreach (Client c in clients) foreach (Client c in clients)
@@ -424,7 +458,7 @@ namespace Barotrauma.Networking
} }
//the spawnpoints where the characters will spawn //the spawnpoints where the characters will spawn
var shuttleSpawnPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, respawnShuttle); var shuttleSpawnPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, respawnSub);
//the spawnpoints where they would spawn if they were spawned inside the main sub //the spawnpoints where they would spawn if they were spawned inside the main sub
//(in order to give them appropriate ID card tags) //(in order to give them appropriate ID card tags)
var mainSubSpawnPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSub); var mainSubSpawnPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSub);
@@ -434,7 +468,7 @@ namespace Barotrauma.Networking
ItemPrefab scooterPrefab = MapEntityPrefab.Find("Underwater Scooter") as ItemPrefab; ItemPrefab scooterPrefab = MapEntityPrefab.Find("Underwater Scooter") as ItemPrefab;
ItemPrefab batteryPrefab = MapEntityPrefab.Find("Battery Cell") as ItemPrefab; ItemPrefab batteryPrefab = MapEntityPrefab.Find("Battery Cell") as ItemPrefab;
var cargoSp = WayPoint.WayPointList.Find(wp => wp.Submarine == respawnShuttle && wp.SpawnType == SpawnType.Cargo); var cargoSp = WayPoint.WayPointList.Find(wp => wp.Submarine == respawnSub && wp.SpawnType == SpawnType.Cargo);
for (int i = 0; i < characterInfos.Count; i++) for (int i = 0; i < characterInfos.Count; i++)
{ {
@@ -470,20 +504,20 @@ namespace Barotrauma.Networking
if (divingSuitPrefab != null && oxyPrefab != null) if (divingSuitPrefab != null && oxyPrefab != null)
{ {
var divingSuit = new Item(divingSuitPrefab, pos, respawnShuttle); var divingSuit = new Item(divingSuitPrefab, pos, respawnSub);
Entity.Spawner.CreateNetworkEvent(divingSuit, false); Entity.Spawner.CreateNetworkEvent(divingSuit, false);
var oxyTank = new Item(oxyPrefab, pos, respawnShuttle); var oxyTank = new Item(oxyPrefab, pos, respawnSub);
Entity.Spawner.CreateNetworkEvent(oxyTank, false); Entity.Spawner.CreateNetworkEvent(oxyTank, false);
divingSuit.Combine(oxyTank); divingSuit.Combine(oxyTank);
} }
if (scooterPrefab != null && batteryPrefab != null) if (scooterPrefab != null && batteryPrefab != null)
{ {
var scooter = new Item(scooterPrefab, pos, respawnShuttle); var scooter = new Item(scooterPrefab, pos, respawnSub);
Spawner.CreateNetworkEvent(scooter, false); Spawner.CreateNetworkEvent(scooter, false);
var battery = new Item(batteryPrefab, pos, respawnShuttle); var battery = new Item(batteryPrefab, pos, respawnSub);
Spawner.CreateNetworkEvent(battery, false); Spawner.CreateNetworkEvent(battery, false);
scooter.Combine(battery); scooter.Combine(battery);