Syncing game mode, mission type, traitor setting, level seed & autorestart

This commit is contained in:
Regalis
2016-09-07 19:17:31 +03:00
parent a02931054a
commit ccf6e6d544
3 changed files with 46 additions and 25 deletions
+14 -1
View File
@@ -562,7 +562,20 @@ namespace Barotrauma.Networking
GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList); GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList);
string selectShuttleName = inc.ReadString(); string selectShuttleName = inc.ReadString();
string selectShuttleHash = inc.ReadString(); string selectShuttleHash = inc.ReadString();
GameMain.NetLobbyScreen.TrySelectSub(selectShuttleName, selectShuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox); GameMain.NetLobbyScreen.TrySelectSub(selectShuttleName, selectShuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox);
GameMain.NetLobbyScreen.SetTraitorsEnabled((YesNoMaybe)inc.ReadRangedInteger(0, 2));
GameMain.NetLobbyScreen.SetMissionType(inc.ReadRangedInteger(0, Mission.MissionTypes.Count - 1));
GameMain.NetLobbyScreen.SelectMode(inc.ReadByte());
GameMain.NetLobbyScreen.LevelSeed = inc.ReadString();
bool autoRestartEnabled = inc.ReadBoolean();
float autoRestartTimer = autoRestartEnabled ? inc.ReadFloat() : 0.0f;
GameMain.NetLobbyScreen.SetAutoRestart(autoRestartEnabled, autoRestartTimer);
} }
lastRecvChatMsgID = inc.ReadUInt32(); lastRecvChatMsgID = inc.ReadUInt32();
break; break;
@@ -640,6 +640,19 @@ namespace Barotrauma.Networking
outmsg.Write((GameMain.NetLobbyScreen.SubList.SelectedData as Submarine).MD5Hash.ToString()); outmsg.Write((GameMain.NetLobbyScreen.SubList.SelectedData as Submarine).MD5Hash.ToString());
outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).Name); outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).Name);
outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).MD5Hash.ToString()); outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).MD5Hash.ToString());
outmsg.WriteRangedInteger(0, 2, (int)TraitorsEnabled);
outmsg.WriteRangedInteger(0, Mission.MissionTypes.Count - 1, (GameMain.NetLobbyScreen.MissionTypeIndex));
outmsg.Write((byte)GameMain.NetLobbyScreen.ModeList.SelectedIndex);
outmsg.Write(GameMain.NetLobbyScreen.LevelSeed);
outmsg.Write(AutoRestart);
if (autoRestart)
{
outmsg.Write(AutoRestartTimer);
}
} }
else else
{ {
+19 -24
View File
@@ -53,7 +53,6 @@ namespace Barotrauma
public string ServerName; public string ServerName;
const float NetworkUpdateInterval = 1.0f; const float NetworkUpdateInterval = 1.0f;
private float networkUpdateTimer;
private UInt32 lastUpdateID; private UInt32 lastUpdateID;
public UInt32 LastUpdateID public UInt32 LastUpdateID
{ {
@@ -151,7 +150,7 @@ namespace Barotrauma
{ {
return levelSeed; return levelSeed;
} }
private set set
{ {
if (levelSeed == value) return; if (levelSeed == value) return;
@@ -569,6 +568,12 @@ namespace Barotrauma
return false; return false;
} }
public void SetAutoRestart(bool enabled, float timer = 0.0f)
{
autoRestartBox.Selected = enabled;
autoRestartTimer = timer;
}
private bool ToggleAutoRestart(GUITickBox tickBox) private bool ToggleAutoRestart(GUITickBox tickBox)
{ {
if (GameMain.Server == null) return false; if (GameMain.Server == null) return false;
@@ -580,7 +585,7 @@ namespace Barotrauma
return true; return true;
} }
private void SetMissionType(int missionTypeIndex) public void SetMissionType(int missionTypeIndex)
{ {
if (missionTypeIndex < 0 || missionTypeIndex >= Mission.MissionTypes.Count) return; if (missionTypeIndex < 0 || missionTypeIndex >= Mission.MissionTypes.Count) return;
@@ -609,6 +614,8 @@ namespace Barotrauma
{ {
if (GameMain.Server == null) return false; if (GameMain.Server == null) return false;
lastUpdateID++;
int dir = (int)userData; int dir = (int)userData;
int index = (int)GameMain.Server.TraitorsEnabled + dir; int index = (int)GameMain.Server.TraitorsEnabled + dir;
@@ -622,9 +629,8 @@ namespace Barotrauma
return true; return true;
} }
private void SetTraitorsEnabled(YesNoMaybe enabled) public void SetTraitorsEnabled(YesNoMaybe enabled)
{ {
if (GameMain.Server != null) GameMain.Server.TraitorsEnabled = enabled; if (GameMain.Server != null) GameMain.Server.TraitorsEnabled = enabled;
(traitorProbabilityText as GUITextBlock).Text = enabled.ToString(); (traitorProbabilityText as GUITextBlock).Text = enabled.ToString();
} }
@@ -942,20 +948,6 @@ namespace Barotrauma
{ {
base.Update(deltaTime); base.Update(deltaTime);
//Vector2 pos = new Vector2(
// Submarine.Borders.X + Submarine.Borders.Width / 2,
// Submarine.Borders.Y - Submarine.Borders.Height / 2);
//camAngle += (float)deltaTime / 10.0f;
//Vector2 offset = (new Vector2(
// (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f),
// (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f)));
//pos += offset * 0.8f;
//GameMain.GameScreen.Cam.TargetPos = pos;
//GameMain.GameScreen.Cam.MoveCamera((float)deltaTime);
if (jobInfoFrame != null) if (jobInfoFrame != null)
{ {
jobInfoFrame.Update((float)deltaTime); jobInfoFrame.Update((float)deltaTime);
@@ -966,17 +958,13 @@ namespace Barotrauma
} }
else else
{ {
menu.Update((float)deltaTime);
menu.Update((float)deltaTime);
} }
if (autoRestartTimer != 0.0f && autoRestartBox.Selected) if (autoRestartTimer != 0.0f && autoRestartBox.Selected)
{ {
autoRestartTimer = Math.Max(autoRestartTimer - (float)deltaTime, 0.0f); autoRestartTimer = Math.Max(autoRestartTimer - (float)deltaTime, 0.0f);
} }
//durationBar.BarScroll = Math.Max(durationBar.BarScroll, 1.0f / 60.0f);
} }
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
@@ -1059,6 +1047,13 @@ namespace Barotrauma
return true; return true;
} }
public void SelectMode(int modeIndex)
{
modeList.Select(modeIndex, true);
missionTypeBlock.Visible = SelectedMode != null && SelectedMode.Name == "Mission";
}
private bool SelectMode(GUIComponent component, object obj) private bool SelectMode(GUIComponent component, object obj)
{ {
if (GameMain.NetworkMember == null) return false; if (GameMain.NetworkMember == null) return false;