using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.Threading; namespace AllocsFixes.PersistentData { [Serializable] public class Inventory { public List bag; public List belt; public InvItem[] equipment; public Inventory () { bag = new List (); belt = new List (); equipment = null; } public void Update (PlayerDataFile pdf) { lock (this) { //Log.Out ("Updating player inventory - player id: " + pdf.id); ProcessInv (bag, pdf.bag, pdf.id); ProcessInv (belt, pdf.inventory, pdf.id); ProcessEqu (pdf.equipment); } } private void ProcessInv (List target, ItemStack[] sourceFields, int id) { target.Clear (); for (int i = 0; i < sourceFields.Length; i++) { if (sourceFields [i].count > 0) { int count = sourceFields [i].count; int maxAllowed = ItemClass.list [sourceFields [i].itemValue.type].Stacknumber.Value; string name = ItemClass.list [sourceFields [i].itemValue.type].GetItemName (); if (count > maxAllowed) { Log.Out ("Player with ID " + id + " has stack for \"" + name + "\" greater than allowed (" + count + " > " + maxAllowed + ")"); } target.Add (new InvItem (name, count)); } else { target.Add (null); } } } private void ProcessEqu (Equipment sourceEquipment) { equipment = new InvItem[sourceEquipment.GetSlotCount ()]; for (int i = 0; i < sourceEquipment.GetSlotCount (); i++) { if (sourceEquipment.GetSlotItem (i) != null && !sourceEquipment.GetSlotItem (i).Equals (ItemValue.None)) { int count = 1; string name = ItemClass.list [sourceEquipment.GetSlotItem (i).type].GetItemName (); equipment [i] = new InvItem (name, count); } else { equipment [i] = null; } } } } }