Unstable 0.15.15.0 (and the one before it I forgor)

This commit is contained in:
Markus Isberg
2021-11-18 21:34:30 +09:00
parent 10e5fd5f3e
commit 80f39cd2a3
257 changed files with 4916 additions and 2582 deletions
@@ -105,6 +105,15 @@ namespace Barotrauma
[Serialize(120.0f, true)]
public float AllowedRetaliationTime { get; set; }
[Serialize(5.0f, true)]
public float DangerousItemContainKarmaDecrease { get; set; }
[Serialize(defaultValue: true, true)]
public bool IsDangerousItemContainKarmaDecreaseIncremental { get; set; }
[Serialize(30.0f, true)]
public float MaxDangerousItemContainKarmaDecrease { get; set; }
private readonly AfflictionPrefab herpesAffliction;
public Dictionary<string, XElement> Presets = new Dictionary<string, XElement>();
@@ -27,7 +27,6 @@ namespace Barotrauma.Networking
{
WriteEvent(tempEventBuffer, e, recipient);
}
catch (Exception exception)
{
DebugConsole.ThrowError("Failed to write an event for the entity \"" + e.Entity + "\"", exception);
@@ -55,7 +54,7 @@ namespace Barotrauma.Networking
tempBuffer.WriteVariableUInt32((uint)tempEventBuffer.LengthBytes);
tempBuffer.Write(tempEventBuffer.Buffer, 0, tempEventBuffer.LengthBytes);
tempBuffer.WritePadBits();
sentEvents.Add(e);
sentEvents.Add(e);
eventCount++;
}
@@ -68,6 +67,32 @@ namespace Barotrauma.Networking
}
}
protected static bool ValidateEntity(INetSerializable entity)
{
void error(string reason)
=> DebugConsole.ThrowError($"Can't create an entity event for {entity} - {reason}.\n{Environment.StackTrace.CleanupStackTrace()}");
if (entity is Entity { Removed: var removed, IdFreed: var idFreed })
{
if (removed)
{
error("the entity has been removed");
return false;
}
if (idFreed)
{
error("the ID of the entity has been freed");
return false;
}
}
else
{
error($"input is not of type {nameof(Entity)}");
return false;
}
return true;
}
protected abstract void WriteEvent(IWriteMessage buffer, NetEntityEvent entityEvent, Client recipient = null);
}
}
@@ -196,7 +196,7 @@ namespace Barotrauma.Networking
partial void UpdateReturningProjSpecific(float deltaTime);
private IEnumerable<object> ForceShuttleToPos(Vector2 position, float speed)
private IEnumerable<CoroutineStatus> ForceShuttleToPos(Vector2 position, float speed)
{
if (RespawnShuttle == null)
{
@@ -42,6 +42,7 @@ namespace Barotrauma.Networking
ServerMessage,
ConsoleUsage,
Karma,
Talent,
Error,
}
@@ -56,6 +57,7 @@ namespace Barotrauma.Networking
{ MessageType.ServerMessage, new Color(157, 225, 160) },
{ MessageType.ConsoleUsage, new Color(0, 162, 232) },
{ MessageType.Karma, new Color(75, 88, 255) },
{ MessageType.Talent, new Color(125, 125, 255) },
{ MessageType.Error, Color.Red },
};
@@ -70,6 +72,7 @@ namespace Barotrauma.Networking
{ MessageType.ServerMessage, "ServerMessage" },
{ MessageType.ConsoleUsage, "ConsoleUsage" },
{ MessageType.Karma, "Karma" },
{ MessageType.Talent, "Talent" },
{ MessageType.Error, "Error" }
};
@@ -10,6 +10,7 @@ using System.Security.Cryptography;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Barotrauma.Extensions;
namespace Barotrauma.Networking
{
@@ -48,7 +49,8 @@ namespace Barotrauma.Networking
Message = 0x2,
Properties = 0x4,
Misc = 0x8,
LevelSeed = 0x10
LevelSeed = 0x10,
HiddenSubs = 0x20
}
public static readonly string PermissionPresetFile = "Data" + Path.DirectorySeparatorChar + "permissionpresets.xml";
@@ -284,6 +286,8 @@ namespace Barotrauma.Networking
ExtraCargo = new Dictionary<ItemPrefab, int>();
HiddenSubs = new HashSet<string>();
PermissionPreset.LoadAll(PermissionPresetFile);
InitProjSpecific();
@@ -369,6 +373,8 @@ namespace Barotrauma.Networking
public Dictionary<ItemPrefab, int> ExtraCargo { get; private set; }
public HashSet<string> HiddenSubs { get; private set; }
private float selectedLevelDifficulty;
private string password;
@@ -506,6 +512,13 @@ namespace Barotrauma.Networking
}
}
[Serialize(Barotrauma.LosMode.Opaque, true)]
public LosMode LosMode
{
get;
set;
}
[Serialize(800, true)]
public int LinesPerLogFile
{
@@ -1023,5 +1036,29 @@ namespace Barotrauma.Networking
msg.Write((byte)kvp.Value);
}
}
public void ReadHiddenSubs(IReadMessage msg)
{
HiddenSubs.Clear();
uint count = msg.ReadVariableUInt32();
for (int i = 0; i < count; i++)
{
string submarineName = msg.ReadString();
HiddenSubs.Add(submarineName);
}
#if SERVER
SelectNonHiddenSubmarine();
#endif
}
public void WriteHiddenSubs(IWriteMessage msg)
{
msg.WriteVariableUInt32((uint)HiddenSubs.Count);
foreach (string submarineName in HiddenSubs)
{
msg.Write(submarineName);
}
}
}
}
@@ -1,5 +1,6 @@
using Barotrauma.Networking;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
@@ -15,23 +16,22 @@ namespace Barotrauma
public enum VoteState { None = 0, Started = 1, Running = 2, Passed = 3, Failed = 4 };
private List<Pair<object, int>> GetVoteList(VoteType voteType, List<Client> voters)
private IReadOnlyDictionary<T, int> GetVoteCounts<T>(VoteType voteType, List<Client> voters)
{
List<Pair<object, int>> voteList = new List<Pair<object, int>>();
Dictionary<T, int> voteList = new Dictionary<T, int>();
foreach (Client voter in voters)
{
object vote = voter.GetVote<object>(voteType);
T vote = voter.GetVote<T>(voteType);
if (vote == null) continue;
var existingVotable = voteList.Find(v => v.First == vote || v.First.Equals(vote));
if (existingVotable == null)
if (!voteList.ContainsKey(vote))
{
voteList.Add(new Pair<object, int>(vote, 1));
voteList.Add(vote, 1);
}
else
{
existingVotable.Second++;
voteList[vote]++;
}
}
return voteList;
@@ -42,16 +42,23 @@ namespace Barotrauma
if (voteType == VoteType.Sub && !AllowSubVoting) return default(T);
if (voteType == VoteType.Mode && !AllowModeVoting) return default(T);
List<Pair<object, int>> voteList = GetVoteList(voteType, voters);
IReadOnlyDictionary<T, int> voteList = GetVoteCounts<T>(voteType, voters);
T selected = default(T);
int highestVotes = 0;
foreach (Pair<object, int> votable in voteList)
foreach (KeyValuePair<T, int> votable in voteList)
{
if (selected == null || votable.Second > highestVotes)
if (voteType == VoteType.Sub
&& votable.Key is SubmarineInfo subInfo
&& GameMain.NetworkMember.ServerSettings.HiddenSubs.Contains(subInfo.Name))
{
highestVotes = votable.Second;
selected = (T)votable.First;
//This sub is hidden so it can't be voted for, skip
continue;
}
if (selected == null || votable.Value > highestVotes)
{
highestVotes = votable.Value;
selected = votable.Key;
}
}