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

View File

@@ -528,12 +528,14 @@ namespace Barotrauma.Networking
string subName = inc.ReadString();
string subHash = inc.ReadString();
bool usingShuttle = inc.ReadBoolean();
string shuttleName = inc.ReadString();
string shuttleHash = inc.ReadString();
NetOutgoingMessage readyToStartMsg = client.CreateMessage();
readyToStartMsg.Write((byte)ClientPacketHeader.RESPONSE_STARTGAME);
GameMain.NetLobbyScreen.UsingShuttle = usingShuttle;
readyToStartMsg.Write(
GameMain.NetLobbyScreen.TrySelectSub(subName, subHash, GameMain.NetLobbyScreen.SubList) &&
GameMain.NetLobbyScreen.TrySelectSub(shuttleName, shuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox));
@@ -654,6 +656,7 @@ namespace Barotrauma.Networking
string subName = inc.ReadString();
string subHash = inc.ReadString();
bool usingShuttle = inc.ReadBoolean();
string shuttleName = inc.ReadString();
string shuttleHash = inc.ReadString();
@@ -697,6 +700,8 @@ namespace Barotrauma.Networking
yield return CoroutineStatus.Success;
}
GameMain.NetLobbyScreen.UsingShuttle = usingShuttle;
if (campaign == null)
{
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);
}
if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.SelectedShuttle);
if (respawnAllowed) respawnManager = new RespawnManager(this, GameMain.NetLobbyScreen.UsingShuttle ? GameMain.NetLobbyScreen.SelectedShuttle : null);
if (isTraitor)
{
@@ -842,6 +847,7 @@ namespace Barotrauma.Networking
string selectSubName = inc.ReadString();
string selectSubHash = inc.ReadString();
bool usingShuttle = inc.ReadBoolean();
string selectShuttleName = inc.ReadString();
string selectShuttleHash = inc.ReadString();
@@ -878,6 +884,8 @@ namespace Barotrauma.Networking
GameMain.NetLobbyScreen.ServerName = serverName;
GameMain.NetLobbyScreen.ServerMessage.Text = serverText;
GameMain.NetLobbyScreen.UsingShuttle = usingShuttle;
if (!allowSubVoting)
{
GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList);

View File

@@ -137,8 +137,8 @@ namespace Barotrauma.Networking
if (respawnManager.CurrentState == RespawnManager.State.Waiting &&
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)
{

View File

@@ -47,6 +47,7 @@ namespace Barotrauma
private GUITickBox autoRestartBox;
private GUIDropDown shuttleList;
private GUITickBox shuttleTickBox;
private CampaignUI campaignUI;
@@ -77,6 +78,11 @@ namespace Barotrauma
get { return shuttleList; }
}
public GUITickBox ShuttleTickBox
{
get { return shuttleTickBox; }
}
public GUIListBox ModeList
{
get { return modeList; }
@@ -120,6 +126,12 @@ namespace Barotrauma
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
{
get { return modeList.SelectedData as GameModePreset; }
@@ -245,9 +257,15 @@ namespace Barotrauma
//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);
shuttleTickBox.Selected = true;
shuttleTickBox.OnSelected = (GUITickBox box) =>
{
shuttleList.Enabled = box.Selected;
if (GameMain.Server != null) lastUpdateID++;
return true;
};
//gamemode ------------------------------------------------------------------

View File

@@ -9,6 +9,7 @@ namespace Barotrauma
{
private Submarine selectedSub;
private Submarine selectedShuttle;
private bool usingShuttle = true;
public Submarine SelectedSub
{
@@ -20,6 +21,11 @@ namespace Barotrauma
get { return selectedShuttle; }
set { selectedShuttle = value; lastUpdateID++; }
}
public bool UsingShuttle
{
get { return usingShuttle; }
set { usingShuttle = value; lastUpdateID++; }
}
private GameModePreset[] gameModes;
public GameModePreset[] GameModes

View File

@@ -957,6 +957,7 @@ namespace Barotrauma.Networking
}
outmsg.Write(GameMain.NetLobbyScreen.SelectedSub.Name);
outmsg.Write(GameMain.NetLobbyScreen.SelectedSub.MD5Hash.ToString());
outmsg.Write(GameMain.NetLobbyScreen.UsingShuttle);
outmsg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name);
outmsg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.ToString());
@@ -1062,6 +1063,7 @@ namespace Barotrauma.Networking
{
Submarine selectedSub = null;
Submarine selectedShuttle = GameMain.NetLobbyScreen.SelectedShuttle;
bool usingShuttle = GameMain.NetLobbyScreen.UsingShuttle;
if (Voting.AllowSubVoting)
{
@@ -1100,12 +1102,12 @@ namespace Barotrauma.Networking
return false;
}
CoroutineManager.StartCoroutine(InitiateStartGame(selectedSub, selectedShuttle, selectedMode), "InitiateStartGame");
CoroutineManager.StartCoroutine(InitiateStartGame(selectedSub, selectedShuttle, usingShuttle, selectedMode), "InitiateStartGame");
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;
GameMain.NetLobbyScreen.StartButtonEnabled = false;
@@ -1118,6 +1120,7 @@ namespace Barotrauma.Networking
msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(usingShuttle);
msg.Write(selectedShuttle.Name);
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;
}
private IEnumerable<object> StartGame(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode)
private IEnumerable<object> StartGame(Submarine selectedSub, Submarine selectedShuttle, bool usingShuttle, GameModePreset selectedMode)
{
entityEventManager.Clear();
@@ -1219,7 +1222,7 @@ namespace Barotrauma.Networking
(!(GameMain.GameSession.GameMode is MissionMode) ||
((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
for (int teamID = 1; teamID <= teamCount; teamID++)
@@ -1371,7 +1374,7 @@ namespace Barotrauma.Networking
msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(GameMain.NetLobbyScreen.UsingShuttle);
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name);
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.Hash);

View File

@@ -27,6 +27,11 @@ namespace Barotrauma.Networking
private Submarine respawnShuttle;
private Steering shuttleSteering;
private List<Door> shuttleDoors;
public bool UsingShuttle
{
get { return respawnShuttle != null; }
}
/// <summary>
/// How long until the shuttle is dispatched with respawned characters
@@ -69,41 +74,48 @@ namespace Barotrauma.Networking
{
this.networkMember = networkMember;
respawnShuttle = new Submarine(shuttle.FilePath, shuttle.MD5Hash.Hash, true);
respawnShuttle.Load(false);
ResetShuttle();
//respawnShuttle.GodMode = true;
shuttleDoors = new List<Door>();
foreach (Item item in Item.ItemList)
if (shuttle != null)
{
if (item.Submarine != respawnShuttle) continue;
respawnShuttle = new Submarine(shuttle.FilePath, shuttle.MD5Hash.Hash, true);
respawnShuttle.Load(false);
var steering = item.GetComponent<Steering>();
if (steering != null) shuttleSteering = steering;
ResetShuttle();
//respawnShuttle.GodMode = true;
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)
shuttleDoors = new List<Door>();
foreach (Item item in Item.ItemList)
{
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;
if (server != null)
{
respawnInterval = server.RespawnInterval;
maxTransportTime = server.MaxTransportTime;
}
}
respawnTimer = respawnInterval;
}
@@ -118,6 +130,14 @@ namespace Barotrauma.Networking
public void Update(float deltaTime)
{
if (respawnShuttle == null)
{
if (state != State.Waiting)
{
state = State.Waiting;
}
}
switch (state)
{
case State.Waiting:
@@ -144,11 +164,6 @@ namespace Barotrauma.Networking
return;
}
respawnShuttle.Velocity = Vector2.Zero;
shuttleSteering.AutoPilot = false;
shuttleSteering.MaintainPos = false;
int characterToRespawnCount = GetClientsToRespawn().Count;
int totalCharacterCount = server.ConnectedClients.Count;
if (server.Character != null)
@@ -180,6 +195,13 @@ namespace Barotrauma.Networking
DispatchShuttle();
}
if (respawnShuttle == null) return;
respawnShuttle.Velocity = Vector2.Zero;
shuttleSteering.AutoPilot = false;
shuttleSteering.MaintainPos = false;
}
private void UpdateTransporting(float deltaTime)
@@ -290,19 +312,30 @@ namespace Barotrauma.Networking
var server = networkMember as GameServer;
if (server == null) return;
state = State.Transporting;
server.CreateEntityEvent(this);
if (respawnShuttle != null)
{
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.StartCoroutine(ForceShuttleToPos(Level.Loaded.StartPosition - Vector2.UnitY * Level.ShaftHeight, 100.0f), "forcepos");
CoroutineManager.StopCoroutines("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)
@@ -401,6 +434,7 @@ namespace Barotrauma.Networking
var server = networkMember as GameServer;
if (server == null) return;
var respawnSub = respawnShuttle != null ? respawnShuttle : Submarine.MainSub;
var clients = GetClientsToRespawn();
foreach (Client c in clients)
@@ -424,7 +458,7 @@ namespace Barotrauma.Networking
}
//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
//(in order to give them appropriate ID card tags)
var mainSubSpawnPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSub);
@@ -434,7 +468,7 @@ namespace Barotrauma.Networking
ItemPrefab scooterPrefab = MapEntityPrefab.Find("Underwater Scooter") 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++)
{
@@ -470,20 +504,20 @@ namespace Barotrauma.Networking
if (divingSuitPrefab != null && oxyPrefab != null)
{
var divingSuit = new Item(divingSuitPrefab, pos, respawnShuttle);
var divingSuit = new Item(divingSuitPrefab, pos, respawnSub);
Entity.Spawner.CreateNetworkEvent(divingSuit, false);
var oxyTank = new Item(oxyPrefab, pos, respawnShuttle);
var oxyTank = new Item(oxyPrefab, pos, respawnSub);
Entity.Spawner.CreateNetworkEvent(oxyTank, false);
divingSuit.Combine(oxyTank);
}
if (scooterPrefab != null && batteryPrefab != null)
{
var scooter = new Item(scooterPrefab, pos, respawnShuttle);
var scooter = new Item(scooterPrefab, pos, respawnSub);
Spawner.CreateNetworkEvent(scooter, false);
var battery = new Item(batteryPrefab, pos, respawnShuttle);
var battery = new Item(batteryPrefab, pos, respawnSub);
Spawner.CreateNetworkEvent(battery, false);
scooter.Combine(battery);