- Timestamp:
- Jul 26, 2015, 4:47:49 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs
r238 r245 7 7 { 8 8 [Serializable] 9 public class Inventory 10 { 9 public class Inventory { 11 10 public List<InvItem> bag; 12 11 public List<InvItem> belt; 12 public InvItem[] equipment; 13 13 14 public Inventory () 15 { 14 public Inventory () { 16 15 bag = new List<InvItem> (); 17 16 belt = new List<InvItem> (); 17 equipment = null; 18 18 } 19 19 20 public void Update (PlayerDataFile pdf) 21 { 22 //Log.Out ("Updating player inventory - player id: " + pdf.id); 23 ProcessInv (bag, pdf.bag, pdf.id); 24 ProcessInv (belt, pdf.inventory, pdf.id); 20 public void Update (PlayerDataFile pdf) { 21 lock (this) { 22 //Log.Out ("Updating player inventory - player id: " + pdf.id); 23 ProcessInv (bag, pdf.bag, pdf.id); 24 ProcessInv (belt, pdf.inventory, pdf.id); 25 ProcessEqu (pdf.equipment); 26 } 25 27 } 26 28 27 private void ProcessInv (List<InvItem> target, ItemStack[] sourceFields, int id) 28 { 29 lock (target) { 30 target.Clear (); 31 for (int i = 0; i < sourceFields.Length; i++) { 32 if (sourceFields [i].count > 0) { 33 int count = sourceFields [i].count; 34 int maxAllowed = ItemClass.list [sourceFields [i].itemValue.type].Stacknumber.Value; 35 string name = ItemClass.list [sourceFields [i].itemValue.type].GetItemName (); 29 private void ProcessInv (List<InvItem> target, ItemStack[] sourceFields, int id) { 30 target.Clear (); 31 for (int i = 0; i < sourceFields.Length; i++) { 32 if (sourceFields [i].count > 0) { 33 int count = sourceFields [i].count; 34 int maxAllowed = ItemClass.list [sourceFields [i].itemValue.type].Stacknumber.Value; 35 string name = ItemClass.list [sourceFields [i].itemValue.type].GetItemName (); 36 36 37 if (count > maxAllowed) 38 Log.Out ("Player with ID " + id + " has stack for \"" + name + "\" greater than allowed (" + count + " > " + maxAllowed + ")"); 39 target.Add (new InvItem (name, count)); 40 } else { 41 target.Add (null); 37 if (count > maxAllowed) { 38 Log.Out ("Player with ID " + id + " has stack for \"" + name + "\" greater than allowed (" + count + " > " + maxAllowed + ")"); 42 39 } 40 target.Add (new InvItem (name, count)); 41 } else { 42 target.Add (null); 43 } 44 } 45 } 46 47 private void ProcessEqu (Equipment sourceEquipment) { 48 equipment = new InvItem[sourceEquipment.GetSlotCount ()]; 49 for (int i = 0; i < sourceEquipment.GetSlotCount (); i++) { 50 if (sourceEquipment.GetSlotItem (i) != null && !sourceEquipment.GetSlotItem (i).Equals (ItemValue.None)) { 51 int count = 1; 52 string name = ItemClass.list [sourceEquipment.GetSlotItem (i).type].GetItemName (); 53 54 equipment [i] = new InvItem (name, count); 55 } else { 56 equipment [i] = null; 43 57 } 44 58 }
Note:
See TracChangeset
for help on using the changeset viewer.