Unstable 0.17.5.0
This commit is contained in:
@@ -2,56 +2,42 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Barotrauma.Extensions;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class Voting
|
||||
{
|
||||
public bool AllowSubVoting
|
||||
{
|
||||
get { return allowSubVoting; }
|
||||
set
|
||||
{
|
||||
if (value == allowSubVoting) return;
|
||||
allowSubVoting = value;
|
||||
GameMain.NetLobbyScreen.SubList.Enabled = value ||
|
||||
(GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectSub));
|
||||
var subVotesLabel = GameMain.NetLobbyScreen.Frame.FindChild("subvotes", true) as GUITextBlock;
|
||||
subVotesLabel.Visible = value;
|
||||
var subVisButton = GameMain.NetLobbyScreen.SubVisibilityButton;
|
||||
subVisButton.RectTransform.AbsoluteOffset
|
||||
= new Point(value ? (int)(subVotesLabel.TextSize.X + subVisButton.Rect.Width) : 0, 0);
|
||||
private readonly Dictionary<VoteType, int>
|
||||
voteCountYes = new Dictionary<VoteType, int>(),
|
||||
voteCountNo = new Dictionary<VoteType, int>(),
|
||||
voteCountMax = new Dictionary<VoteType, int>();
|
||||
|
||||
UpdateVoteTexts(null, VoteType.Sub);
|
||||
GameMain.NetLobbyScreen.SubList.Deselect();
|
||||
}
|
||||
public int GetVoteCountYes(VoteType voteType)
|
||||
{
|
||||
voteCountYes.TryGetValue(voteType, out int value);
|
||||
return value;
|
||||
}
|
||||
public bool AllowModeVoting
|
||||
public int GetVoteCountNo(VoteType voteType)
|
||||
{
|
||||
get { return allowModeVoting; }
|
||||
set
|
||||
{
|
||||
if (value == allowModeVoting) return;
|
||||
allowModeVoting = value;
|
||||
GameMain.NetLobbyScreen.ModeList.Enabled =
|
||||
value ||
|
||||
(GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectMode));
|
||||
|
||||
GameMain.NetLobbyScreen.Frame.FindChild("modevotes", true).Visible = value;
|
||||
|
||||
// Disable modes that cannot be voted on
|
||||
foreach (var guiComponent in GameMain.NetLobbyScreen.ModeList.Content.Children)
|
||||
{
|
||||
if (guiComponent is GUIFrame frame)
|
||||
{
|
||||
frame.CanBeFocused = !allowModeVoting || ((GameModePreset) frame.UserData).Votable;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateVoteTexts(null, VoteType.Mode);
|
||||
GameMain.NetLobbyScreen.ModeList.Deselect();
|
||||
}
|
||||
voteCountNo.TryGetValue(voteType, out int value);
|
||||
return value;
|
||||
}
|
||||
public int GetVoteCountMax(VoteType voteType)
|
||||
{
|
||||
voteCountMax.TryGetValue(voteType, out int value);
|
||||
return value;
|
||||
}
|
||||
public void SetVoteCountYes(VoteType voteType, int value)
|
||||
{
|
||||
voteCountYes[voteType] = value;
|
||||
}
|
||||
public void SetVoteCountNo(VoteType voteType, int value)
|
||||
{
|
||||
voteCountNo[voteType] = value;
|
||||
}
|
||||
public void SetVoteCountMax(VoteType voteType, int value)
|
||||
{
|
||||
voteCountMax[voteType] = value;
|
||||
}
|
||||
|
||||
public void UpdateVoteTexts(List<Client> clients, VoteType voteType)
|
||||
@@ -139,17 +125,15 @@ namespace Barotrauma
|
||||
msg.Write(votedClient.ID);
|
||||
break;
|
||||
case VoteType.StartRound:
|
||||
if (!(data is bool)) return;
|
||||
if (!(data is bool)) { return; }
|
||||
msg.Write((bool)data);
|
||||
break;
|
||||
|
||||
case VoteType.PurchaseAndSwitchSub:
|
||||
case VoteType.PurchaseSub:
|
||||
case VoteType.SwitchSub:
|
||||
if (!VoteRunning)
|
||||
{
|
||||
SubmarineInfo voteSub = data as SubmarineInfo;
|
||||
if (voteSub == null) return;
|
||||
if (data is SubmarineInfo voteSub)
|
||||
{
|
||||
//initiate sub vote
|
||||
msg.Write(true);
|
||||
msg.Write(voteSub.Name);
|
||||
}
|
||||
@@ -159,7 +143,11 @@ namespace Barotrauma
|
||||
msg.Write(false);
|
||||
msg.Write((int)data);
|
||||
}
|
||||
|
||||
break;
|
||||
case VoteType.TransferMoney:
|
||||
if (!(data is int)) { return; }
|
||||
msg.Write(false); //not initiating a vote
|
||||
msg.Write((int)data);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -168,8 +156,8 @@ namespace Barotrauma
|
||||
|
||||
public void ClientRead(IReadMessage inc)
|
||||
{
|
||||
AllowSubVoting = inc.ReadBoolean();
|
||||
if (allowSubVoting)
|
||||
GameMain.Client.ServerSettings.AllowSubVoting = inc.ReadBoolean();
|
||||
if (GameMain.Client.ServerSettings.AllowSubVoting)
|
||||
{
|
||||
UpdateVoteTexts(null, VoteType.Sub);
|
||||
int votableCount = inc.ReadByte();
|
||||
@@ -186,8 +174,8 @@ namespace Barotrauma
|
||||
SetVoteText(GameMain.NetLobbyScreen.SubList, sub, votes);
|
||||
}
|
||||
}
|
||||
AllowModeVoting = inc.ReadBoolean();
|
||||
if (allowModeVoting)
|
||||
GameMain.Client.ServerSettings.AllowModeVoting = inc.ReadBoolean();
|
||||
if (GameMain.Client.ServerSettings.AllowModeVoting)
|
||||
{
|
||||
UpdateVoteTexts(null, VoteType.Mode);
|
||||
int votableCount = inc.ReadByte();
|
||||
@@ -199,135 +187,136 @@ namespace Barotrauma
|
||||
SetVoteText(GameMain.NetLobbyScreen.ModeList, mode, votes);
|
||||
}
|
||||
}
|
||||
AllowEndVoting = inc.ReadBoolean();
|
||||
if (AllowEndVoting)
|
||||
GameMain.Client.ServerSettings.AllowEndVoting = inc.ReadBoolean();
|
||||
if (GameMain.Client.ServerSettings.AllowEndVoting)
|
||||
{
|
||||
GameMain.NetworkMember.EndVoteCount = inc.ReadByte();
|
||||
GameMain.NetworkMember.EndVoteMax = inc.ReadByte();
|
||||
SetVoteCountYes(VoteType.EndRound, inc.ReadByte());
|
||||
SetVoteCountMax(VoteType.EndRound, inc.ReadByte());
|
||||
}
|
||||
AllowVoteKick = inc.ReadBoolean();
|
||||
GameMain.Client.ServerSettings.AllowVoteKick = inc.ReadBoolean();
|
||||
|
||||
byte subVoteStateByte = inc.ReadByte();
|
||||
VoteState subVoteState = VoteState.None;
|
||||
try
|
||||
{
|
||||
subVoteState = (VoteState)subVoteStateByte;
|
||||
}
|
||||
byte activeVoteStateByte = inc.ReadByte();
|
||||
|
||||
VoteState activeVoteState = VoteState.None;
|
||||
try { activeVoteState = (VoteState)activeVoteStateByte; }
|
||||
catch (System.Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to cast vote type \"" + subVoteStateByte + "\"", e);
|
||||
DebugConsole.ThrowError("Failed to cast vote type \"" + activeVoteStateByte + "\"", e);
|
||||
}
|
||||
|
||||
if (subVoteState != VoteState.None)
|
||||
if (activeVoteState != VoteState.None)
|
||||
{
|
||||
byte voteTypeByte = inc.ReadByte();
|
||||
VoteType voteType = VoteType.Unknown;
|
||||
|
||||
try
|
||||
{
|
||||
voteType = (VoteType)voteTypeByte;
|
||||
}
|
||||
try { voteType = (VoteType)voteTypeByte; }
|
||||
catch (System.Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to cast vote type \"" + voteTypeByte + "\"", e);
|
||||
}
|
||||
|
||||
if (voteType != VoteType.Unknown)
|
||||
byte yesClientCount = inc.ReadByte();
|
||||
for (int i = 0; i < yesClientCount; i++)
|
||||
{
|
||||
byte yesClientCount = inc.ReadByte();
|
||||
for (int i = 0; i < yesClientCount; i++)
|
||||
{
|
||||
byte clientID = inc.ReadByte();
|
||||
var matchingClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == clientID);
|
||||
matchingClient?.SetVote(voteType, 2);
|
||||
}
|
||||
|
||||
byte noClientCount = inc.ReadByte();
|
||||
for (int i = 0; i < noClientCount; i++)
|
||||
{
|
||||
byte clientID = inc.ReadByte();
|
||||
var matchingClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == clientID);
|
||||
matchingClient?.SetVote(voteType, 1);
|
||||
}
|
||||
|
||||
GameMain.NetworkMember.SubmarineVoteYesCount = yesClientCount;
|
||||
GameMain.NetworkMember.SubmarineVoteNoCount = noClientCount;
|
||||
GameMain.NetworkMember.SubmarineVoteMax = inc.ReadByte();
|
||||
|
||||
switch (subVoteState)
|
||||
{
|
||||
case VoteState.Started:
|
||||
Client myClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == GameMain.Client.ID);
|
||||
if (!myClient.InGame)
|
||||
{
|
||||
VoteRunning = true;
|
||||
return;
|
||||
}
|
||||
|
||||
string subName1 = inc.ReadString();
|
||||
SubmarineInfo info = GameMain.Client.ServerSubmarines.FirstOrDefault(s => s.Name == subName1);
|
||||
|
||||
if (info == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to find a matching submarine, vote aborted");
|
||||
return;
|
||||
}
|
||||
|
||||
VoteRunning = true;
|
||||
byte starterID = inc.ReadByte();
|
||||
Client starterClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == starterID);
|
||||
float timeOut = inc.ReadByte();
|
||||
GameMain.Client.ShowSubmarineChangeVoteInterface(starterClient, info, voteType, timeOut);
|
||||
break;
|
||||
case VoteState.Running:
|
||||
// Nothing specific
|
||||
break;
|
||||
case VoteState.Passed:
|
||||
case VoteState.Failed:
|
||||
VoteRunning = false;
|
||||
|
||||
bool passed = inc.ReadBoolean();
|
||||
string subName2 = inc.ReadString();
|
||||
SubmarineInfo subInfo = GameMain.Client.ServerSubmarines.FirstOrDefault(s => s.Name == subName2);
|
||||
|
||||
if (subInfo == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to find a matching submarine, vote aborted");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameMain.Client.VotingInterface != null)
|
||||
{
|
||||
GameMain.Client.VotingInterface.EndVote(passed, yesClientCount, noClientCount);
|
||||
}
|
||||
else if (GameMain.Client.ConnectedClients.Count > 1)
|
||||
{
|
||||
GameMain.NetworkMember.AddChatMessage(VotingInterface.GetSubmarineVoteResultMessage(subInfo, voteType, yesClientCount.ToString(), noClientCount.ToString(), passed).Value, ChatMessageType.Server);
|
||||
}
|
||||
|
||||
if (passed)
|
||||
{
|
||||
int deliveryFee = inc.ReadInt16();
|
||||
switch (voteType)
|
||||
{
|
||||
case VoteType.PurchaseAndSwitchSub:
|
||||
GameMain.GameSession.PurchaseSubmarine(subInfo);
|
||||
GameMain.GameSession.SwitchSubmarine(subInfo, 0);
|
||||
break;
|
||||
case VoteType.PurchaseSub:
|
||||
GameMain.GameSession.PurchaseSubmarine(subInfo);
|
||||
break;
|
||||
case VoteType.SwitchSub:
|
||||
GameMain.GameSession.SwitchSubmarine(subInfo, deliveryFee);
|
||||
break;
|
||||
}
|
||||
|
||||
SubmarineSelection.ContentRefreshRequired = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
byte clientID = inc.ReadByte();
|
||||
var matchingClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == clientID);
|
||||
matchingClient?.SetVote(voteType, 2);
|
||||
}
|
||||
}
|
||||
|
||||
byte noClientCount = inc.ReadByte();
|
||||
for (int i = 0; i < noClientCount; i++)
|
||||
{
|
||||
byte clientID = inc.ReadByte();
|
||||
var matchingClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == clientID);
|
||||
matchingClient?.SetVote(voteType, 1);
|
||||
}
|
||||
byte maxClientCount = inc.ReadByte();
|
||||
|
||||
SetVoteCountYes(voteType, yesClientCount);
|
||||
SetVoteCountNo(voteType, noClientCount);
|
||||
SetVoteCountMax(voteType, maxClientCount);
|
||||
|
||||
switch (activeVoteState)
|
||||
{
|
||||
case VoteState.Started:
|
||||
byte starterID = inc.ReadByte();
|
||||
Client starterClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == starterID);
|
||||
float timeOut = inc.ReadByte();
|
||||
|
||||
Client myClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == GameMain.Client.ID);
|
||||
if (!myClient.InGame) { return; }
|
||||
|
||||
switch (voteType)
|
||||
{
|
||||
case VoteType.PurchaseSub:
|
||||
case VoteType.PurchaseAndSwitchSub:
|
||||
case VoteType.SwitchSub:
|
||||
string subName1 = inc.ReadString();
|
||||
SubmarineInfo info = GameMain.Client.ServerSubmarines.FirstOrDefault(s => s.Name == subName1);
|
||||
if (info == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to find a matching submarine, vote aborted");
|
||||
return;
|
||||
}
|
||||
GameMain.Client.ShowSubmarineChangeVoteInterface(starterClient, info, voteType, timeOut);
|
||||
break;
|
||||
case VoteType.TransferMoney:
|
||||
byte fromClientId = inc.ReadByte();
|
||||
byte toClientId = inc.ReadByte();
|
||||
int transferAmount = inc.ReadInt32();
|
||||
|
||||
Client fromClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == fromClientId);
|
||||
Client toClient = GameMain.NetworkMember.ConnectedClients.Find(c => c.ID == toClientId);
|
||||
GameMain.Client.ShowMoneyTransferVoteInterface(starterClient, fromClient, transferAmount, toClient, timeOut);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case VoteState.Running:
|
||||
// Nothing specific
|
||||
break;
|
||||
case VoteState.Passed:
|
||||
case VoteState.Failed:
|
||||
bool passed = inc.ReadBoolean();
|
||||
|
||||
SubmarineInfo subInfo = null;
|
||||
switch (voteType)
|
||||
{
|
||||
case VoteType.PurchaseSub:
|
||||
case VoteType.PurchaseAndSwitchSub:
|
||||
case VoteType.SwitchSub:
|
||||
string subName2 = inc.ReadString();
|
||||
subInfo = GameMain.Client.ServerSubmarines.FirstOrDefault(s => s.Name == subName2);
|
||||
if (subInfo == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to find a matching submarine, vote aborted");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
GameMain.Client.VotingInterface?.EndVote(passed, yesClientCount, noClientCount);
|
||||
|
||||
if (passed && subInfo != null)
|
||||
{
|
||||
int deliveryFee = inc.ReadInt16();
|
||||
switch (voteType)
|
||||
{
|
||||
case VoteType.PurchaseAndSwitchSub:
|
||||
GameMain.GameSession.PurchaseSubmarine(subInfo);
|
||||
GameMain.GameSession.SwitchSubmarine(subInfo, 0);
|
||||
break;
|
||||
case VoteType.PurchaseSub:
|
||||
GameMain.GameSession.PurchaseSubmarine(subInfo);
|
||||
break;
|
||||
case VoteType.SwitchSub:
|
||||
GameMain.GameSession.SwitchSubmarine(subInfo, deliveryFee);
|
||||
break;
|
||||
}
|
||||
|
||||
SubmarineSelection.ContentRefreshRequired = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GameMain.NetworkMember.ConnectedClients.ForEach(c => c.SetVote(VoteType.StartRound, false));
|
||||
byte readyClientCount = inc.ReadByte();
|
||||
|
||||
Reference in New Issue
Block a user