Fixed only the first inventory of an item being synced (e.g. clients wouldn't get notified when an item is contained in the "output inventory" of a fabricator or deconstructor).
This commit is contained in:
@@ -377,7 +377,8 @@ namespace Barotrauma
|
||||
(components[componentIndex] as IServerSerializable).ClientRead(type, msg, sendingTime);
|
||||
break;
|
||||
case NetEntityEvent.Type.InventoryState:
|
||||
ownInventory.ClientRead(type, msg, sendingTime);
|
||||
int containerIndex = msg.ReadRangedInteger(0, components.Count - 1);
|
||||
(components[containerIndex] as ItemContainer).Inventory.ClientRead(type, msg, sendingTime);
|
||||
break;
|
||||
case NetEntityEvent.Type.Status:
|
||||
condition = msg.ReadRangedSingle(0.0f, prefab.Health, 8);
|
||||
@@ -425,11 +426,12 @@ namespace Barotrauma
|
||||
case NetEntityEvent.Type.ComponentState:
|
||||
int componentIndex = (int)extraData[1];
|
||||
msg.WriteRangedInteger(0, components.Count - 1, componentIndex);
|
||||
|
||||
(components[componentIndex] as IClientSerializable).ClientWrite(msg, extraData);
|
||||
break;
|
||||
case NetEntityEvent.Type.InventoryState:
|
||||
ownInventory.ClientWrite(msg, extraData);
|
||||
int containerIndex = (int)extraData[1];
|
||||
msg.WriteRangedInteger(0, components.Count - 1, containerIndex);
|
||||
(components[containerIndex] as ItemContainer).Inventory.ClientWrite(msg, extraData);
|
||||
break;
|
||||
case NetEntityEvent.Type.Repair:
|
||||
if (FixRequirements.Count > 0)
|
||||
|
||||
@@ -1723,7 +1723,7 @@ namespace Barotrauma
|
||||
var itemContainer = item.GetComponent<ItemContainer>();
|
||||
if (itemContainer != null)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.InventoryState });
|
||||
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.InventoryState, 0 });
|
||||
}
|
||||
|
||||
GameMain.Server.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.Status });
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateNetworkEvent()
|
||||
protected virtual void CreateNetworkEvent()
|
||||
{
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
|
||||
@@ -1330,7 +1330,24 @@ namespace Barotrauma
|
||||
(components[componentIndex] as IServerSerializable).ServerWrite(msg, c, extraData);
|
||||
break;
|
||||
case NetEntityEvent.Type.InventoryState:
|
||||
ownInventory.ServerWrite(msg, c, extraData);
|
||||
if (extraData.Length < 2 || !(extraData[1] is int))
|
||||
{
|
||||
errorMsg = "Failed to write an inventory state event for the item \"" + Name + "\" - component index not given.";
|
||||
break;
|
||||
}
|
||||
int containerIndex = (int)extraData[1];
|
||||
if (containerIndex < 0 || containerIndex >= components.Count)
|
||||
{
|
||||
errorMsg = "Failed to write an inventory state event for the item \"" + Name + "\" - container index out of range (" + containerIndex + ").";
|
||||
break;
|
||||
}
|
||||
else if (!(components[containerIndex] is ItemContainer))
|
||||
{
|
||||
errorMsg = "Failed to write an inventory state event for the item \"" + Name + "\" - component \"" + components[containerIndex] + "\" is not server serializable.";
|
||||
break;
|
||||
}
|
||||
msg.WriteRangedInteger(0, components.Count - 1, containerIndex);
|
||||
(components[containerIndex] as ItemContainer).Inventory.ServerWrite(msg, c);
|
||||
break;
|
||||
case NetEntityEvent.Type.Status:
|
||||
//clamp to (MaxHealth / 255.0f) if condition > 0.0f
|
||||
@@ -1389,7 +1406,8 @@ namespace Barotrauma
|
||||
(components[componentIndex] as IClientSerializable).ServerRead(type, msg, c);
|
||||
break;
|
||||
case NetEntityEvent.Type.InventoryState:
|
||||
ownInventory.ServerRead(type, msg, c);
|
||||
int containerIndex = msg.ReadRangedInteger(0, components.Count - 1);
|
||||
(components[containerIndex] as ItemContainer).Inventory.ServerRead(type, msg, c);
|
||||
break;
|
||||
case NetEntityEvent.Type.Repair:
|
||||
if (FixRequirements.Count == 0) return;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Barotrauma.Items.Components;
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -84,6 +85,27 @@ namespace Barotrauma
|
||||
return wasPut;
|
||||
}
|
||||
|
||||
protected override void CreateNetworkEvent()
|
||||
{
|
||||
int componentIndex = container.Item.components.IndexOf(container);
|
||||
if (componentIndex == -1)
|
||||
{
|
||||
DebugConsole.Log("Creating a network event for the item \"" + container.Item + "\" failed, ItemContainer not found in components");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.CreateEntityEvent(Owner as IServerSerializable, new object[] { NetEntityEvent.Type.InventoryState, componentIndex });
|
||||
}
|
||||
#if CLIENT
|
||||
else if (GameMain.Client != null)
|
||||
{
|
||||
GameMain.Client.CreateEntityEvent(Owner as IClientSerializable, new object[] { NetEntityEvent.Type.InventoryState, componentIndex });
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void RemoveItem(Item item)
|
||||
{
|
||||
base.RemoveItem(item);
|
||||
|
||||
Reference in New Issue
Block a user