Unstable 0.17.0.0
This commit is contained in:
@@ -11,17 +11,17 @@ namespace Barotrauma.Networking
|
||||
public readonly Character TargetCharacter;
|
||||
|
||||
//which entity is this order referring to (hull, reactor, railgun controller, etc)
|
||||
public readonly ISpatialEntity TargetEntity;
|
||||
public ISpatialEntity TargetEntity => Order.TargetSpatialEntity;
|
||||
|
||||
//additional instructions (power up, fire at will, etc)
|
||||
public readonly string OrderOption;
|
||||
public Identifier OrderOption => Order.Option;
|
||||
|
||||
public readonly int OrderPriority;
|
||||
public int OrderPriority => Order.ManualPriority;
|
||||
|
||||
/// <summary>
|
||||
/// Used when the order targets a wall
|
||||
/// </summary>
|
||||
public int? WallSectionIndex { get; set; }
|
||||
public int? WallSectionIndex => Order.WallSectionIndex;
|
||||
|
||||
public bool IsNewOrder { get; }
|
||||
|
||||
@@ -29,55 +29,50 @@ namespace Barotrauma.Networking
|
||||
/// Same as calling <see cref="OrderChatMessage.OrderChatMessage(Order, string, int, string, ISpatialEntity, Character, Character)"/>,
|
||||
/// but the text parameter is set using <see cref="Order.GetChatMessage(string, string, bool, string)"/>
|
||||
/// </summary>
|
||||
public OrderChatMessage(Order order, string orderOption, int priority, ISpatialEntity targetEntity, Character targetCharacter, Character sender, bool isNewOrder = true)
|
||||
: this(order, orderOption, priority,
|
||||
order?.GetChatMessage(targetCharacter?.Name, sender?.CurrentHull?.DisplayName, targetCharacter == sender, orderOption, isNewOrder),
|
||||
targetEntity, targetCharacter, sender, isNewOrder)
|
||||
public OrderChatMessage(Order order, Character targetCharacter, Character sender, bool isNewOrder = true)
|
||||
: this(order,
|
||||
order?.GetChatMessage(targetCharacter?.Name, sender?.CurrentHull?.DisplayName?.Value, givingOrderToSelf: targetCharacter == sender, orderOption: order.Option, isNewOrder: isNewOrder),
|
||||
targetCharacter, sender, isNewOrder)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public OrderChatMessage(Order order, string orderOption, int priority, string text, ISpatialEntity targetEntity,
|
||||
Character targetCharacter, Character sender, bool isNewOrder = true)
|
||||
public OrderChatMessage(Order order, string text, Character targetCharacter, Character sender, bool isNewOrder = true)
|
||||
: base(sender?.Name, text, ChatMessageType.Order, sender, GameMain.NetworkMember.ConnectedClients.Find(c => c.Character == sender))
|
||||
{
|
||||
Order = order;
|
||||
OrderOption = orderOption;
|
||||
OrderPriority = priority;
|
||||
TargetCharacter = targetCharacter;
|
||||
TargetEntity = targetEntity;
|
||||
IsNewOrder = isNewOrder;
|
||||
}
|
||||
|
||||
public static void WriteOrder(IWriteMessage msg, Order order, Character targetCharacter, ISpatialEntity targetEntity,
|
||||
string orderOption, int orderPriority, int? wallSectionIndex, bool isNewOrder)
|
||||
public static void WriteOrder(IWriteMessage msg, Order order, Character targetCharacter, bool isNewOrder)
|
||||
{
|
||||
msg.Write((byte)Order.PrefabList.IndexOf(order.Prefab));
|
||||
msg.Write(order.Prefab.Identifier);
|
||||
msg.Write(targetCharacter == null ? (UInt16)0 : targetCharacter.ID);
|
||||
msg.Write(targetEntity is Entity ? (targetEntity as Entity).ID : (UInt16)0);
|
||||
msg.Write(order.TargetSpatialEntity is Entity ? (order.TargetEntity as Entity).ID : (UInt16)0);
|
||||
|
||||
// The option of a Dismiss order is written differently so we know what order we target
|
||||
// now that the game supports multiple current orders simultaneously
|
||||
if (order.Prefab.Identifier != "dismissed")
|
||||
if (!order.IsDismissal)
|
||||
{
|
||||
msg.Write((byte)Array.IndexOf(order.Prefab.Options, orderOption));
|
||||
msg.Write((byte)order.Options.IndexOf(order.Option));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(orderOption))
|
||||
if (order.Option != Identifier.Empty)
|
||||
{
|
||||
msg.Write(true);
|
||||
string[] dismissedOrder = orderOption.Split('.');
|
||||
string[] dismissedOrder = order.Option.Value.Split('.');
|
||||
msg.Write((byte)dismissedOrder.Length);
|
||||
if (dismissedOrder.Length > 0)
|
||||
{
|
||||
string dismissedOrderIdentifier = dismissedOrder[0];
|
||||
var orderPrefab = Order.GetPrefab(dismissedOrderIdentifier);
|
||||
msg.Write((byte)Order.PrefabList.IndexOf(orderPrefab));
|
||||
Identifier dismissedOrderIdentifier = dismissedOrder[0].ToIdentifier();
|
||||
var orderPrefab = OrderPrefab.Prefabs[dismissedOrderIdentifier];
|
||||
msg.Write(dismissedOrderIdentifier);
|
||||
if (dismissedOrder.Length > 1)
|
||||
{
|
||||
string dismissedOrderOption = dismissedOrder[1];
|
||||
msg.Write((byte)Array.IndexOf(orderPrefab.Options, dismissedOrderOption));
|
||||
Identifier dismissedOrderOption = dismissedOrder[1].ToIdentifier();
|
||||
msg.Write((byte)orderPrefab.Options.IndexOf(dismissedOrderOption));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,9 +84,9 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
msg.Write((byte)orderPriority);
|
||||
msg.Write((byte)order.ManualPriority);
|
||||
msg.Write((byte)order.TargetType);
|
||||
if (order.TargetType == Order.OrderTargetType.Position && targetEntity is OrderTarget orderTarget)
|
||||
if (order.TargetType == Order.OrderTargetType.Position && order.TargetSpatialEntity is OrderTarget orderTarget)
|
||||
{
|
||||
msg.Write(true);
|
||||
msg.Write(orderTarget.Position.X);
|
||||
@@ -103,7 +98,7 @@ namespace Barotrauma.Networking
|
||||
msg.Write(false);
|
||||
if (order.TargetType == Order.OrderTargetType.WallSection)
|
||||
{
|
||||
msg.Write((byte)(wallSectionIndex ?? order.WallSectionIndex ?? 0));
|
||||
msg.Write((byte)(order.WallSectionIndex ?? 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,14 +107,14 @@ namespace Barotrauma.Networking
|
||||
|
||||
private void WriteOrder(IWriteMessage msg)
|
||||
{
|
||||
WriteOrder(msg, Order, TargetCharacter, TargetEntity, OrderOption, OrderPriority, WallSectionIndex, IsNewOrder);
|
||||
WriteOrder(msg, Order, TargetCharacter, IsNewOrder);
|
||||
}
|
||||
|
||||
public struct OrderMessageInfo
|
||||
{
|
||||
public int OrderIndex { get; }
|
||||
public Order OrderPrefab { get; }
|
||||
public string OrderOption { get; }
|
||||
public Identifier OrderIdentifier { get; }
|
||||
public OrderPrefab OrderPrefab => OrderPrefab.Prefabs[OrderIdentifier];
|
||||
public Identifier OrderOption { get; }
|
||||
public int? OrderOptionIndex { get; }
|
||||
public Character TargetCharacter { get; }
|
||||
public Order.OrderTargetType TargetType { get; }
|
||||
@@ -129,11 +124,10 @@ namespace Barotrauma.Networking
|
||||
public int Priority { get; }
|
||||
public bool IsNewOrder { get; }
|
||||
|
||||
public OrderMessageInfo(int orderIndex, Order orderPrefab, string orderOption, int? orderOptionIndex, Character targetCharacter,
|
||||
public OrderMessageInfo(Identifier orderIdentifier, Identifier orderOption, int? orderOptionIndex, Character targetCharacter,
|
||||
Order.OrderTargetType targetType, Entity targetEntity, OrderTarget targetPosition, int? wallSectionIndex, int orderPriority, bool isNewOrder)
|
||||
{
|
||||
OrderIndex = orderIndex;
|
||||
OrderPrefab = orderPrefab;
|
||||
OrderIdentifier = orderIdentifier;
|
||||
OrderOption = orderOption;
|
||||
OrderOptionIndex = orderOptionIndex;
|
||||
TargetCharacter = targetCharacter;
|
||||
@@ -148,21 +142,20 @@ namespace Barotrauma.Networking
|
||||
|
||||
public static OrderMessageInfo ReadOrder(IReadMessage msg)
|
||||
{
|
||||
int orderIndex = msg.ReadByte();
|
||||
Identifier orderIdentifier = msg.ReadIdentifier();
|
||||
ushort targetCharacterId = msg.ReadUInt16();
|
||||
Character targetCharacter = targetCharacterId != Entity.NullEntityID ? Entity.FindEntityByID(targetCharacterId) as Character : null;
|
||||
ushort targetEntityId = msg.ReadUInt16();
|
||||
Entity targetEntity = targetEntityId != Entity.NullEntityID ? Entity.FindEntityByID(targetEntityId) : null;
|
||||
|
||||
Order orderPrefab = null;
|
||||
int? optionIndex = null;
|
||||
string orderOption = null;
|
||||
Identifier orderOption = Identifier.Empty;
|
||||
// The option of a Dismiss order is written differently so we know what order we target
|
||||
// now that the game supports multiple current orders simultaneously
|
||||
if (orderIndex >= 0 && orderIndex < Order.PrefabList.Count)
|
||||
if (orderIdentifier != Identifier.Empty)
|
||||
{
|
||||
orderPrefab = Order.PrefabList[orderIndex];
|
||||
if (orderPrefab.Identifier != "dismissed")
|
||||
var orderPrefab = OrderPrefab.Prefabs[orderIdentifier];
|
||||
if (!orderPrefab.IsDismissal)
|
||||
{
|
||||
optionIndex = msg.ReadByte();
|
||||
}
|
||||
@@ -172,11 +165,11 @@ namespace Barotrauma.Networking
|
||||
int identifierCount = msg.ReadByte();
|
||||
if (identifierCount > 0)
|
||||
{
|
||||
int dismissedOrderIndex = msg.ReadByte();
|
||||
Order dismissedOrderPrefab = null;
|
||||
if (dismissedOrderIndex >= 0 && dismissedOrderIndex < Order.PrefabList.Count)
|
||||
Identifier dismissedOrderIdentifier = msg.ReadIdentifier();
|
||||
OrderPrefab dismissedOrderPrefab = null;
|
||||
if (dismissedOrderIdentifier != Identifier.Empty)
|
||||
{
|
||||
dismissedOrderPrefab = Order.PrefabList[dismissedOrderIndex];
|
||||
dismissedOrderPrefab = OrderPrefab.Prefabs[dismissedOrderIdentifier];
|
||||
orderOption = dismissedOrderPrefab.Identifier;
|
||||
}
|
||||
if (identifierCount > 1)
|
||||
@@ -187,7 +180,7 @@ namespace Barotrauma.Networking
|
||||
var options = dismissedOrderPrefab.Options;
|
||||
if (options != null && dismissedOrderOptionIndex >= 0 && dismissedOrderOptionIndex < options.Length)
|
||||
{
|
||||
orderOption += $".{options[dismissedOrderOptionIndex]}";
|
||||
orderOption = $"{orderOption.Value}.{options[dismissedOrderOptionIndex]}".ToIdentifier();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,9 +210,8 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
bool isNewOrder = msg.ReadBoolean();
|
||||
|
||||
return new OrderMessageInfo(orderIndex, orderPrefab, orderOption, optionIndex, targetCharacter,
|
||||
orderTargetType, targetEntity, orderTargetPosition, wallSectionIndex, orderPriority, isNewOrder);
|
||||
return new OrderMessageInfo(orderIdentifier, orderOption, optionIndex, targetCharacter,
|
||||
orderTargetType, targetEntity, orderTargetPosition, wallSectionIndex, orderPriority, isNewOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user