1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Runtime.Serialization;
|
---|
4 | using System.Threading;
|
---|
5 |
|
---|
6 | namespace AllocsFixes.PersistentData
|
---|
7 | {
|
---|
8 | [Serializable]
|
---|
9 | public class Inventory {
|
---|
10 | public List<InvItem> bag;
|
---|
11 | public List<InvItem> belt;
|
---|
12 | public InvItem[] equipment;
|
---|
13 |
|
---|
14 | public Inventory () {
|
---|
15 | bag = new List<InvItem> ();
|
---|
16 | belt = new List<InvItem> ();
|
---|
17 | equipment = null;
|
---|
18 | }
|
---|
19 |
|
---|
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 | }
|
---|
27 | }
|
---|
28 |
|
---|
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 |
|
---|
37 | if (count > maxAllowed) {
|
---|
38 | Log.Out ("Player with ID " + id + " has stack for \"" + name + "\" greater than allowed (" + count + " > " + maxAllowed + ")");
|
---|
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;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|