source: binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs@ 144

Last change on this file since 144 was 144, checked in by alloc, 11 years ago

Fixes

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Runtime.Serialization;
4using System.Threading;
5
6namespace AllocsFixes.PersistentData
7{
8 [Serializable]
9 public class Inventory
10 {
11 public List<InvItem> bag;
12 public List<InvItem> belt;
13
14 public Inventory ()
15 {
16 bag = new List<InvItem> ();
17 belt = new List<InvItem> ();
18 }
19
20 public void Update (PlayerDataFile pdf)
21 {
22 Log.Out ("Updating player inventory - player id: " + pdf.id);
23 ProcessInv (bag, pdf.bag);
24 ProcessInv (belt, pdf.inventory);
25 Log.Out ("Now: belt: " + belt.Count + " - bag: " + bag.Count);
26 }
27
28 private void ProcessInv (List<InvItem> target, InventoryField[] sourceFields)
29 {
30 Monitor.Enter (target);
31 try {
32 target.Clear ();
33 for (int i = 0; i < sourceFields.Length; i++) {
34 if (sourceFields [i].count > 0) {
35 int count = sourceFields [i].count;
36 string name = getInvFieldName (sourceFields [i]);
37
38 target.Add (new InvItem (name, count));
39 } else {
40 target.Add (null);
41 }
42 }
43 } finally {
44 Monitor.Exit (target);
45 }
46 }
47
48 private string getInvFieldName (InventoryField item)
49 {
50 ItemBase iBase = ItemBase.list [item.itemValue.type];
51 string name = iBase.name;
52 if (iBase.IsBlock ()) {
53 ItemBlock iBlock = (ItemBlock)iBase;
54 name = iBlock.GetItemName (item.itemValue);
55 }
56 return name;
57 }
58
59
60 }
61}
62
Note: See TracBrowser for help on using the repository browser.