Item description & tags are only included in spawn network message if they differ from the prefab.
This commit is contained in:
@@ -1527,7 +1527,12 @@ namespace Barotrauma
|
|||||||
if (GameMain.Server == null) return;
|
if (GameMain.Server == null) return;
|
||||||
|
|
||||||
msg.Write(Prefab.Name);
|
msg.Write(Prefab.Name);
|
||||||
msg.Write(Description);
|
msg.Write(Description != prefab.Description);
|
||||||
|
if (Description != prefab.Description)
|
||||||
|
{
|
||||||
|
msg.Write(Description);
|
||||||
|
}
|
||||||
|
|
||||||
msg.Write(ID);
|
msg.Write(ID);
|
||||||
|
|
||||||
if (ParentInventory == null || ParentInventory.Owner == null)
|
if (ParentInventory == null || ParentInventory.Owner == null)
|
||||||
@@ -1545,20 +1550,29 @@ namespace Barotrauma
|
|||||||
int index = ParentInventory.FindIndex(this);
|
int index = ParentInventory.FindIndex(this);
|
||||||
msg.Write(index < 0 ? (byte)255 : (byte)index);
|
msg.Write(index < 0 ? (byte)255 : (byte)index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tagsChanged = tags.Count != prefab.Tags.Count || !tags.All(t => prefab.Tags.Contains(t));
|
||||||
|
msg.Write(tagsChanged);
|
||||||
|
if (tagsChanged)
|
||||||
|
{
|
||||||
|
msg.Write(Tags);
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: See if tags are different from their prefab before sending 'em
|
|
||||||
msg.Write(Tags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Item ReadSpawnData(NetBuffer msg, bool spawn = true)
|
public static Item ReadSpawnData(NetBuffer msg, bool spawn = true)
|
||||||
{
|
{
|
||||||
if (GameMain.Server != null) return null;
|
if (GameMain.Server != null) return null;
|
||||||
|
|
||||||
string itemName = msg.ReadString();
|
string itemName = msg.ReadString();
|
||||||
string itemDesc = msg.ReadString();
|
bool descriptionChanged = msg.ReadBoolean();
|
||||||
ushort itemId = msg.ReadUInt16();
|
string itemDesc = "";
|
||||||
|
if (descriptionChanged)
|
||||||
ushort inventoryId = msg.ReadUInt16();
|
{
|
||||||
|
itemDesc = msg.ReadString();
|
||||||
|
}
|
||||||
|
ushort itemId = msg.ReadUInt16();
|
||||||
|
ushort inventoryId = msg.ReadUInt16();
|
||||||
|
|
||||||
DebugConsole.Log("Received entity spawn message for item " + itemName + ".");
|
DebugConsole.Log("Received entity spawn message for item " + itemName + ".");
|
||||||
|
|
||||||
@@ -1581,8 +1595,13 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string tags = msg.ReadString();
|
bool tagsChanged = msg.ReadBoolean();
|
||||||
|
string tags = "";
|
||||||
|
if (tagsChanged)
|
||||||
|
{
|
||||||
|
tags = msg.ReadString();
|
||||||
|
}
|
||||||
|
|
||||||
if (!spawn) return null;
|
if (!spawn) return null;
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
@@ -1592,7 +1611,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
Inventory inventory = null;
|
Inventory inventory = null;
|
||||||
|
|
||||||
var inventoryOwner = Entity.FindEntityByID(inventoryId);
|
var inventoryOwner = FindEntityByID(inventoryId);
|
||||||
if (inventoryOwner != null)
|
if (inventoryOwner != null)
|
||||||
{
|
{
|
||||||
if (inventoryOwner is Character)
|
if (inventoryOwner is Character)
|
||||||
@@ -1610,17 +1629,16 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
var item = new Item(itemPrefab, pos, sub);
|
var item = new Item(itemPrefab, pos, sub);
|
||||||
|
|
||||||
item.Description = itemDesc;
|
|
||||||
item.ID = itemId;
|
item.ID = itemId;
|
||||||
|
if (descriptionChanged) item.Description = itemDesc;
|
||||||
|
if (tagsChanged) item.Tags = tags;
|
||||||
|
|
||||||
if (sub != null)
|
if (sub != null)
|
||||||
{
|
{
|
||||||
item.CurrentHull = Hull.FindHull(pos + sub.Position, null, true);
|
item.CurrentHull = Hull.FindHull(pos + sub.Position, null, true);
|
||||||
item.Submarine = item.CurrentHull == null ? null : item.CurrentHull.Submarine;
|
item.Submarine = item.CurrentHull == null ? null : item.CurrentHull.Submarine;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(tags)) item.Tags = tags;
|
|
||||||
|
|
||||||
if (inventory != null)
|
if (inventory != null)
|
||||||
{
|
{
|
||||||
if (inventorySlotIndex >= 0 && inventorySlotIndex < 255 &&
|
if (inventorySlotIndex >= 0 && inventorySlotIndex < 255 &&
|
||||||
|
|||||||
Reference in New Issue
Block a user