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 Inventory () { bag = new List (); belt = new List (); } public void Update (PlayerDataFile pdf) { //Log.Out ("Updating player inventory - player id: " + pdf.id); ProcessInv (bag, pdf.bag, pdf.id); ProcessInv (belt, pdf.inventory, pdf.id); } private void ProcessInv (List target, InventoryField[] sourceFields, int id) { lock (target) { target.Clear (); for (int i = 0; i < sourceFields.Length; i++) { if (sourceFields [i].count > 0) { int count = sourceFields [i].count; int maxAllowed = ItemBase.list [sourceFields [i].itemValue.type].StackNumber; string name = getInvFieldName (sourceFields [i]); 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 string getInvFieldName (InventoryField item) { ItemBase iBase = ItemBase.list [item.itemValue.type]; return iBase.GetItemName (item.itemValue); } } }