v0.11.0.9

This commit is contained in:
Joonas Rikkonen
2020-12-09 16:34:16 +02:00
parent bbf06f0984
commit f433a7ba10
325 changed files with 13947 additions and 3652 deletions
@@ -26,6 +26,8 @@ namespace Barotrauma
public readonly Submarine Submarine;
public readonly float Condition;
public bool SpawnIfInventoryFull = true;
private readonly Action<Item> onSpawned;
public ItemSpawnInfo(ItemPrefab prefab, Vector2 worldPosition, Action<Item> onSpawned, float? condition = null)
@@ -62,6 +64,10 @@ namespace Barotrauma
Item spawnedItem;
if (Inventory?.Owner != null)
{
if (!SpawnIfInventoryFull && !Inventory.Items.Any(it => it == null))
{
return null;
}
spawnedItem = new Item(Prefab, Vector2.Zero, null);
if (!Inventory.Owner.Removed && !Inventory.TryPutItem(spawnedItem, null, spawnedItem.AllowedSlots))
{
@@ -123,6 +129,36 @@ namespace Barotrauma
}
}
class SubmarineSpawnInfo : IEntitySpawnInfo
{
public readonly string Name;
public readonly Vector2 Position;
private readonly Action<Character> onSpawned;
public SubmarineSpawnInfo(string name, Vector2 worldPosition, Action<Character> onSpawn = null)
{
this.Name = name ?? throw new ArgumentException("ItemSpawnInfo prefab cannot be null.");
Position = worldPosition;
this.onSpawned = onSpawn;
}
public Entity Spawn()
{
var submarine = string.IsNullOrEmpty(Name) ? null :
new Submarine(SubmarineInfo.SavedSubmarines.First(s => s.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)));
return submarine;
}
public void OnSpawned(Entity spawnedCharacter)
{
if (!(spawnedCharacter is Character character)) { throw new ArgumentException($"The entity passed to CharacterSpawnInfo.OnSpawned must be a Character (value was {spawnedCharacter?.ToString() ?? "null"})."); }
onSpawned?.Invoke(character);
}
}
private readonly Queue<IEntitySpawnInfo> spawnQueue;
private readonly Queue<Entity> removeQueue;
@@ -136,6 +172,14 @@ namespace Barotrauma
public readonly bool Remove = false;
public override string ToString()
{
return
(Remove ? "Remove" : "Spawn") + "(" +
((Entity as MapEntity)?.Name ?? "[NULL]") +
$", {OriginalID}, {OriginalInventoryID})";
}
public SpawnOrRemove(Entity entity, bool remove)
{
Entity = entity;
@@ -163,7 +207,7 @@ namespace Barotrauma
}
public EntitySpawner()
: base(null)
: base(null, Entity.EntitySpawnerID)
{
spawnQueue = new Queue<IEntitySpawnInfo>();
removeQueue = new Queue<Entity>();
@@ -200,7 +244,7 @@ namespace Barotrauma
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, position, sub, onSpawned, condition));
}
public void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, float? condition = null, Action<Item> onSpawned = null)
public void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, float? condition = null, Action<Item> onSpawned = null, bool spawnIfInventoryFull = true)
{
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; }
if (itemPrefab == null)
@@ -210,7 +254,7 @@ namespace Barotrauma
GameAnalyticsManager.AddErrorEventOnce("EntitySpawner.AddToSpawnQueue3:ItemPrefabNull", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
return;
}
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, inventory, onSpawned, condition));
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, inventory, onSpawned, condition) { SpawnIfInventoryFull = spawnIfInventoryFull });
}
public void AddToSpawnQueue(string speciesName, Vector2 worldPosition, Action<Character> onSpawn = null)
@@ -253,7 +297,7 @@ namespace Barotrauma
if (client != null) GameMain.Server.SetClientCharacter(client, null);
}
#endif
}
}
removeQueue.Enqueue(entity);
}
@@ -32,8 +32,10 @@ namespace Barotrauma
[Serialize(0.05f, true)]
public float StructureRepairKarmaIncrease { get; set; }
[Serialize(0.1f, true)]
public float StructureDamageKarmaDecrease { get; set; }
[Serialize(30.0f, true)]
public float MaxStructureDamageKarmaDecreasePerSecond { get; set; }
@@ -67,6 +69,9 @@ namespace Barotrauma
[Serialize(defaultValue: false, true)]
public bool DangerousItemStealBots { get; set; }
[Serialize(defaultValue: 0.05f, true)]
public float BallastFloraKarmaIncrease { get; set; }
private int allowedWireDisconnectionsPerMinute;
[Serialize(5, true)]
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma.Networking
{
@@ -42,21 +43,6 @@ namespace Barotrauma.Networking
eventCount++;
continue;
}
//the length of the data is written as a byte, so the data needs to be less than 255 bytes long
if (tempEventBuffer.LengthBytes > 255)
{
DebugConsole.ThrowError("Too much data in network event for entity \"" + e.Entity.ToString() + "\" (" + tempEventBuffer.LengthBytes + " bytes, event ID " + e.ID + ")");
GameAnalyticsManager.AddErrorEventOnce("NetEntityEventManager.Write:TooLong" + e.Entity.ToString(),
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
"Too much data in network event for entity \"" + e.Entity.ToString() + "\" (" + tempEventBuffer.LengthBytes + " bytes, event ID " + e.ID + ")");
//write an empty event to prevent breaking the event syncing
tempBuffer.Write(Entity.NullEntityID);
tempBuffer.WritePadBits();
eventCount++;
continue;
}
if (msg.LengthBytes + tempBuffer.LengthBytes + tempEventBuffer.LengthBytes > MaxEventBufferLength)
{
@@ -65,7 +51,7 @@ namespace Barotrauma.Networking
}
tempBuffer.Write(e.EntityID);
tempBuffer.Write((byte)tempEventBuffer.LengthBytes);
tempBuffer.WriteVariableUInt32((uint)tempEventBuffer.LengthBytes);
tempBuffer.Write(tempEventBuffer.Buffer, 0, tempEventBuffer.LengthBytes);
tempBuffer.WritePadBits();
sentEvents.Add(e);
@@ -29,7 +29,8 @@ namespace Barotrauma.Networking
REQUEST_STARTGAMEFINALIZE, //tell the server you're ready to finalize round initialization
ERROR, //tell the server that an error occurred
CREW
CREW,
READY_CHECK
}
enum ClientNetObject
@@ -78,7 +79,8 @@ namespace Barotrauma.Networking
MISSION,
EVENTACTION,
RESET_UPGRADES, //inform the clients that the upgrades on the submarine have been reset
CREW //anything related to managing bots in multiplayer
CREW, //anything related to managing bots in multiplayer
READY_CHECK //start, end and update a ready check
}
enum ServerNetObject
{
@@ -113,6 +115,13 @@ namespace Barotrauma.Networking
SwitchSub
}
public enum ReadyCheckState
{
Start,
Update,
End
}
enum DisconnectReason
{
Unknown,
@@ -13,6 +13,11 @@
//additional instructions (power up, fire at will, etc)
public readonly string OrderOption;
/// <summary>
/// Used when the order targets a wall
/// </summary>
public int? WallSectionIndex { get; set; }
public OrderChatMessage(Order order, string orderOption, ISpatialEntity targetEntity, Character targetCharacter, Character sender)
: this(order, orderOption,
order?.GetChatMessage(targetCharacter?.Name, sender?.CurrentHull?.DisplayName, givingOrderToSelf: targetCharacter == sender, orderOption: orderOption),
@@ -34,6 +34,13 @@ namespace Barotrauma.Networking
EndPointString = IPString;
}
public override bool SetSteamIDIfUnknown(UInt64 id)
{
if (SteamID != 0) { return false; } //do not allow the SteamID to be set multiple times
SteamID = id;
return true;
}
public override bool EndpointMatches(string endPoint)
{
if (IPEndPoint?.Address == null) { return false; }
@@ -35,5 +35,14 @@ namespace Barotrauma.Networking
public abstract bool EndpointMatches(string endPoint);
public NetworkConnectionStatus Status = NetworkConnectionStatus.Disconnected;
public virtual bool SetSteamIDIfUnknown(UInt64 id)
{
//by default, don't allow setting the ID, this is only done
//with Lidgren connections since those are initialized before
//the SteamID can be known; it's set once the Steam auth ticket
//is received by the server.
return false;
}
}
}
@@ -62,7 +62,7 @@ namespace Barotrauma.Networking
public Submarine RespawnShuttle { get; private set; }
public RespawnManager(NetworkMember networkMember, SubmarineInfo shuttleInfo)
: base(null)
: base(null, Entity.RespawnManagerID)
{
this.networkMember = networkMember;
@@ -265,7 +265,7 @@ namespace Barotrauma.Networking
#endif
c.Kill(CauseOfDeathType.Unknown, null, true);
c.Enabled = false;
Spawner.AddToRemoveQueue(c);
if (c.Inventory != null)
{
@@ -787,7 +787,7 @@ namespace Barotrauma.Networking
private set;
}
[Serialize(120.0f, true)]
[Serialize(300.0f, true)]
public float KillDisconnectedTime
{
get;