Infinite wall fixes, pressure damage to sub, sub/mode voting & randomization working now, better ui scaling

This commit is contained in:
Regalis
2015-10-31 00:29:51 +02:00
parent dc4b502248
commit bcc96cee97
33 changed files with 1068 additions and 151 deletions

View File

@@ -438,7 +438,12 @@ namespace Barotrauma.Networking
AddChatMessage(inc.ReadString(), ChatMessageType.Server);
Client disconnectedClient = otherClients.Find(c => c.ID == leavingID);
if (disconnectedClient != null) GameMain.NetLobbyScreen.RemovePlayer(disconnectedClient.name);
if (disconnectedClient != null)
{
otherClients.Remove(disconnectedClient);
GameMain.NetLobbyScreen.RemovePlayer(disconnectedClient.name);
}
if (!gameStarted) return;
@@ -487,6 +492,9 @@ namespace Barotrauma.Networking
case (byte)PacketTypes.LatestMessageID:
reliableChannel.HandleLatestMessageID(inc);
break;
case (byte)PacketTypes.VoteStatus:
Voting.ReadData(inc);
break;
}
}
}
@@ -512,7 +520,7 @@ namespace Barotrauma.Networking
yield return CoroutineStatus.Success;
}
if (!GameMain.NetLobbyScreen.TrySelectMap(mapName, mapHash))
if (!GameMain.NetLobbyScreen.TrySelectSub(mapName, mapHash))
{
yield return CoroutineStatus.Success;
}
@@ -522,7 +530,7 @@ namespace Barotrauma.Networking
Rand.SetSyncedSeed(seed);
//int gameModeIndex = inc.ReadInt32();
GameMain.GameSession = new GameSession(GameMain.NetLobbyScreen.SelectedMap, "", gameMode);
GameMain.GameSession = new GameSession(GameMain.NetLobbyScreen.SelectedSub, "", gameMode);
yield return CoroutineStatus.Running;
@@ -637,6 +645,25 @@ namespace Barotrauma.Networking
GameMain.NetworkMember = null;
}
public void Vote(VoteType voteType, object userData)
{
NetOutgoingMessage msg = client.CreateMessage();
msg.Write((byte)PacketTypes.Vote);
msg.Write((byte)voteType);
switch (voteType)
{
case VoteType.Sub:
msg.Write(((Submarine)userData).Name);
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
break;
case VoteType.Mode:
msg.Write(((GameModePreset)userData).Name);
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
break;
}
}
public void SendCharacterData()
{
if (characterInfo == null) return;

View File

@@ -223,7 +223,6 @@ namespace Barotrauma.Networking
connectedClients.Find(c => c.character != null && !c.character.IsDead)==null &&
(myCharacter == null || myCharacter.IsDead))
{
AutoRestartTimer = 20.0f;
EndButtonHit(null, null);
UpdateNetLobby(null,null);
return;
@@ -484,6 +483,9 @@ namespace Barotrauma.Networking
case (byte)PacketTypes.LatestMessageID:
dataSender.ReliableChannel.HandleLatestMessageID(inc);
break;
case (byte)PacketTypes.Vote:
Voting.RegisterVote(inc, connectedClients);
break;
}
break;
case NetIncomingMessageType.WarningMessage:
@@ -674,7 +676,8 @@ namespace Barotrauma.Networking
public bool StartGameClicked(GUIButton button, object obj)
{
Submarine selectedSub = GameMain.NetLobbyScreen.SelectedMap as Submarine;
Submarine selectedSub = Voting.AllowSubVoting ?
Voting.HighestVoted<Submarine>(VoteType.Sub, connectedClients) : GameMain.NetLobbyScreen.SelectedSub;
if (selectedSub == null)
{
@@ -695,7 +698,11 @@ namespace Barotrauma.Networking
int seed = DateTime.Now.Millisecond;
Rand.SetSyncedSeed(seed);
GameMain.GameSession = new GameSession(selectedSub, "", GameMain.NetLobbyScreen.SelectedMode);
GameModePreset selectedMode = Voting.HighestVoted<GameModePreset>(VoteType.Mode, connectedClients);
if (selectedMode==null) selectedMode=GameMain.NetLobbyScreen.SelectedMode;
GameMain.GameSession = new GameSession(selectedSub, "", selectedMode);
GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed);
yield return CoroutineStatus.Running;
@@ -747,10 +754,10 @@ namespace Barotrauma.Networking
msg.Write(GameMain.NetLobbyScreen.LevelSeed);
msg.Write(GameMain.NetLobbyScreen.SelectedMap.Name);
msg.Write(GameMain.NetLobbyScreen.SelectedMap.MD5Hash.Hash);
msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(GameMain.NetLobbyScreen.SelectedMode.Name);
msg.Write(selectedMode.Name);
//msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes);
@@ -788,6 +795,8 @@ namespace Barotrauma.Networking
{
GameMain.GameSession.gameMode.End("Server admin has ended the round");
if (autoRestart) AutoRestartTimer = 20.0f;
return true;
}
@@ -1044,6 +1053,27 @@ namespace Barotrauma.Networking
}
public void UpdateVoteStatus()
{
if (server.Connections.Count == 0) return;
try
{
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.VoteStatus);
Voting.WriteData(msg, connectedClients);
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0);
}
catch (Exception e)
{
#if DEBUG
DebugConsole.ThrowError("Failed to update vote status", e);
#endif
}
}
public bool UpdateNetLobby(object obj)
{
return UpdateNetLobby(null, obj);
@@ -1051,14 +1081,13 @@ namespace Barotrauma.Networking
public bool UpdateNetLobby(GUIComponent component, object obj)
{
if (server.Connections.Count == 0) return true;
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.UpdateNetLobby);
GameMain.NetLobbyScreen.WriteData(msg);
if (server.Connections.Count > 0)
{
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0);
}
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0);
return true;
}
@@ -1320,6 +1349,8 @@ namespace Barotrauma.Networking
public string version;
public bool inGame;
private object[] votes;
public List<JobPrefab> jobPreferences;
public JobPrefab assignedJob;
@@ -1337,8 +1368,20 @@ namespace Barotrauma.Networking
{
this.name = name;
this.ID = ID;
votes = new object[Enum.GetNames(typeof(VoteType)).Length];
jobPreferences = new List<JobPrefab>(JobPrefab.List.GetRange(0,3));
}
public object GetVote(VoteType voteType)
{
return votes[(int)voteType];
}
public void SetVote(VoteType voteType, object value)
{
votes[(int)voteType] = value;
}
}
}

View File

@@ -0,0 +1,161 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Barotrauma.Networking
{
enum SelectionMode
{
Manual = 0, Random = 1, Vote = 2
}
partial class GameServer : NetworkMember
{
public bool ShowNetStats;
private TimeSpan refreshMasterInterval = new TimeSpan(0, 0, 40);
private TimeSpan sparseUpdateInterval = new TimeSpan(0, 0, 0, 3);
private SelectionMode subSelectionMode, modeSelectionMode;
private bool randomizeSeed = true;
private bool registeredToMaster;
private BanList banList;
private string password;
private GUIFrame settingsFrame;
public float AutoRestartTimer;
private bool autoRestart;
public bool AutoRestart
{
get { return (connectedClients.Count == 0) ? false : autoRestart; }
set
{
autoRestart = value;
AutoRestartTimer = autoRestart ? 20.0f : 0.0f;
}
}
public SelectionMode SubSelectionMode
{
get { return subSelectionMode; }
}
public SelectionMode ModeSelectionMode
{
get { return modeSelectionMode; }
}
public bool RandomizeSeed
{
get { return randomizeSeed; }
}
public BanList BanList
{
get { return banList; }
}
private void CreateSettingsFrame()
{
settingsFrame = new GUIFrame(new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsHeight), Color.Black*0.5f);
GUIFrame innerFrame = new GUIFrame(new Rectangle(0,0,400,400), null, Alignment.Center, GUI.Style, settingsFrame);
var randomizeLevelBox = new GUITickBox(new Rectangle(0, 0, 20, 20), "Randomize level seed", Alignment.Left, innerFrame);
randomizeLevelBox.OnSelected = ToggleRandomizeSeed;
new GUITextBlock(new Rectangle(0, 35, 100, 20), "Submarine selection:", GUI.Style, innerFrame);
var selectionFrame = new GUIFrame(new Rectangle(0, 60, 300, 20), null, innerFrame);
for (int i = 0; i<3; i++)
{
var selectionTick = new GUITickBox(new Rectangle(i * 100, 00, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame);
selectionTick.Selected = i == (int)subSelectionMode;
selectionTick.OnSelected = SwitchSubSelection;
selectionTick.UserData = (SelectionMode)i;
}
new GUITextBlock(new Rectangle(0, 85, 100, 20), "Mode selection:", GUI.Style, innerFrame);
selectionFrame = new GUIFrame(new Rectangle(0, 110, 300, 20), null, innerFrame);
for (int i = 0; i<3; i++)
{
var selectionTick = new GUITickBox(new Rectangle(i*100, 0, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame);
selectionTick.Selected = i == (int)modeSelectionMode;
selectionTick.OnSelected = SwitchModeSelection;
selectionTick.UserData = (SelectionMode)i;
}
var closeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Close", Alignment.BottomRight, GUI.Style, innerFrame);
closeButton.OnClicked = ToggleSettingsFrame;
}
private bool SwitchSubSelection(GUITickBox tickBox)
{
subSelectionMode = (SelectionMode)tickBox.UserData;
foreach (GUIComponent otherTickBox in tickBox.Parent.children)
{
if (otherTickBox == tickBox) continue;
((GUITickBox)otherTickBox).Selected = false;
}
Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;
if (subSelectionMode==SelectionMode.Random)
{
GameMain.NetLobbyScreen.SubList.Select(Rand.Range(0, GameMain.NetLobbyScreen.SubList.CountChildren));
}
return true;
}
private bool SwitchModeSelection(GUITickBox tickBox)
{
modeSelectionMode = (SelectionMode)tickBox.UserData;
foreach (GUIComponent otherTickBox in tickBox.Parent.children)
{
if (otherTickBox == tickBox) continue;
((GUITickBox)otherTickBox).Selected = false;
}
Voting.AllowModeVoting = modeSelectionMode == SelectionMode.Vote;
if (modeSelectionMode == SelectionMode.Random)
{
GameMain.NetLobbyScreen.ModeList.Select(Rand.Range(0, GameMain.NetLobbyScreen.ModeList.CountChildren));
}
return true;
}
private bool ToggleRandomizeSeed(GUITickBox tickBox)
{
randomizeSeed = tickBox.Selected;
return true;
}
public bool ToggleSettingsFrame(GUIButton button, object obj)
{
if (settingsFrame==null)
{
CreateSettingsFrame();
}
else
{
settingsFrame = null;
}
return true;
}
}
}

View File

@@ -30,10 +30,20 @@ namespace Barotrauma.Networking
Traitor,
Vote,
VoteStatus,
ResendRequest,
ReliableMessage,
LatestMessageID
LatestMessageID
}
enum VoteType
{
Unknown,
Sub,
Mode,
EndRound
}
class NetworkMember
@@ -61,6 +71,8 @@ namespace Barotrauma.Networking
protected Character myCharacter;
protected CharacterInfo characterInfo;
public Voting Voting;
public Character Character
{
get { return myCharacter; }
@@ -113,6 +125,8 @@ namespace Barotrauma.Networking
crewButton = new GUIButton(new Rectangle(chatBox.Rect.Right-80, chatBox.Rect.Y-30, 80, 20), "Crew", GUI.Style, inGameHUD);
crewButton.OnClicked = ToggleCrewFrame;
Voting = new Voting();
}
protected void CreateCrewFrame(List<Character> crew)