- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs
r324 r325 3 3 4 4 namespace AllocsFixes.PersistentData { 5 6 7 8 9 5 [Serializable] 6 public class Inventory { 7 public List<InvItem> bag; 8 public List<InvItem> belt; 9 public InvItem[] equipment; 10 10 11 12 13 14 15 11 public Inventory () { 12 bag = new List<InvItem> (); 13 belt = new List<InvItem> (); 14 equipment = null; 15 } 16 16 17 18 19 20 21 22 23 24 17 public void Update (PlayerDataFile pdf) { 18 lock (this) { 19 //Log.Out ("Updating player inventory - player id: " + pdf.id); 20 ProcessInv (bag, pdf.bag, pdf.id); 21 ProcessInv (belt, pdf.inventory, pdf.id); 22 ProcessEqu (pdf.equipment, pdf.id); 23 } 24 } 25 25 26 27 28 29 30 31 32 26 private void ProcessInv (List<InvItem> target, ItemStack[] sourceFields, int id) { 27 target.Clear (); 28 for (int i = 0; i < sourceFields.Length; i++) { 29 InvItem item = CreateInvItem (sourceFields [i].itemValue, sourceFields [i].count, id); 30 if (item != null && sourceFields [i].itemValue.Modifications != null) { 31 ProcessParts (sourceFields [i].itemValue.Modifications, item, id); 32 } 33 33 34 35 36 34 target.Add (item); 35 } 36 } 37 37 38 39 40 41 42 43 38 private void ProcessEqu (Equipment sourceEquipment, int _playerId) { 39 equipment = new InvItem[sourceEquipment.GetSlotCount ()]; 40 for (int i = 0; i < sourceEquipment.GetSlotCount (); i++) { 41 equipment [i] = CreateInvItem (sourceEquipment.GetSlotItem (i), 1, _playerId); 42 } 43 } 44 44 45 46 47 48 49 50 51 45 private void ProcessParts (ItemValue[] _parts, InvItem _item, int _playerId) { 46 InvItem[] itemParts = new InvItem[_parts.Length]; 47 for (int i = 0; i < _parts.Length; i++) { 48 InvItem partItem = CreateInvItem (_parts [i], 1, _playerId); 49 if (partItem != null && _parts [i].Modifications != null) { 50 ProcessParts (_parts [i].Modifications, partItem, _playerId); 51 } 52 52 53 54 53 itemParts [i] = partItem; 54 } 55 55 56 57 56 _item.parts = itemParts; 57 } 58 58 59 60 61 62 63 59 private InvItem CreateInvItem (ItemValue _itemValue, int _count, int _playerId) { 60 if (_count > 0 && _itemValue != null && !_itemValue.Equals (ItemValue.None)) { 61 ItemClass itemClass = ItemClass.list [_itemValue.type]; 62 int maxAllowed = itemClass.Stacknumber.Value; 63 string name = itemClass.GetItemName (); 64 64 65 66 67 68 65 if (_count > maxAllowed) { 66 Log.Out ("Player with ID " + _playerId + " has stack for \"" + name + "\" greater than allowed (" + 67 _count + " > " + maxAllowed + ")"); 68 } 69 69 70 71 72 73 74 75 70 InvItem item = null; 71 if (_itemValue.HasQuality) { 72 item = new InvItem (name, _count, _itemValue.Quality, _itemValue.MaxUseTimes, _itemValue.UseTimes); 73 } else { 74 item = new InvItem (name, _count, -1, _itemValue.MaxUseTimes, _itemValue.UseTimes); 75 } 76 76 77 77 item.icon = itemClass.GetIconName (); 78 78 79 79 item.iconcolor = AllocsUtils.ColorToHex (itemClass.GetIconTint ()); 80 80 81 82 } else { 83 return null; 84 } 85 86 81 return item; 82 } 83 84 return null; 85 } 86 } 87 87 }
Note:
See TracChangeset
for help on using the changeset viewer.