Changed entity ids from int to ushort, inventory sync bugfixes

This commit is contained in:
Regalis
2015-10-21 18:58:36 +03:00
parent 0233579e37
commit 313d16d886
20 changed files with 155 additions and 78 deletions
@@ -228,7 +228,7 @@ namespace Barotrauma.Items.Components
{
if (itemIds == null) return;
for (int i = 0; i < itemIds.Length; i++)
for (ushort i = 0; i < itemIds.Length; i++)
{
Item item = MapEntity.FindEntityByID(itemIds[i]) as Item;
if (item == null) continue;
@@ -247,17 +247,17 @@ namespace Barotrauma.Items.Components
string[] itemIdStrings = containedString.Split(',');
itemIds = new int[itemIdStrings.Length];
itemIds = new ushort[itemIdStrings.Length];
for (int i = 0; i < itemIdStrings.Length; i++)
{
int id = -1;
if (!int.TryParse(itemIdStrings[i], out id)) continue;
ushort id = 0;
if (!ushort.TryParse(itemIdStrings[i], out id)) continue;
itemIds[i] = id;
}
}
int[] itemIds;
ushort[] itemIds;
public override XElement Save(XElement parentElement)
{
@@ -266,7 +266,7 @@ namespace Barotrauma.Items.Components
string[] itemIdStrings = new string[inventory.items.Length];
for (int i = 0; i < inventory.items.Length; i++)
{
itemIdStrings[i] = (inventory.items[i]==null) ? "-1" : inventory.items[i].ID.ToString();
itemIdStrings[i] = (inventory.items[i]==null) ? "0" : inventory.items[i].ID.ToString();
}
componentElement.Add(new XAttribute("contained", string.Join(",",itemIdStrings)));
@@ -28,7 +28,7 @@ namespace Barotrauma.Items.Components
private List<StatusEffect> effects;
public readonly int[] wireId;
public readonly ushort[] wireId;
public bool IsPower
{
@@ -79,7 +79,7 @@ namespace Barotrauma.Items.Components
effects = new List<StatusEffect>();
wireId = new int[MaxLinked];
wireId = new ushort[MaxLinked];
foreach (XElement subElement in element.Elements())
{
@@ -93,7 +93,9 @@ namespace Barotrauma.Items.Components
}
if (index == -1) break;
wireId[index] = ToolBox.GetAttributeInt(subElement, "w", -1);
int id = ToolBox.GetAttributeInt(subElement, "w", 0);
if (id<0) id = 0;
wireId[index] = (ushort)id;
break;
@@ -441,7 +443,7 @@ namespace Barotrauma.Items.Components
for (int i = 0; i < MaxLinked; i++)
{
if (wireId[i] == -1) continue;
if (wireId[i] == 0) continue;
Item wireItem = MapEntity.FindEntityByID(wireId[i]) as Item;
@@ -146,7 +146,7 @@ namespace Barotrauma.Items.Components
for (int i = 0; i < wireCount; i++)
{
int wireId = message.ReadInt32();
ushort wireId = message.ReadUInt16();
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
if (wireItem == null) continue;