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

Last change on this file since 145 was 145, checked in by alloc, 10 years ago

Fixes

File size: 1.3 KB
RevLine 
[144]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 }
26
27 private void ProcessInv (List<InvItem> target, InventoryField[] sourceFields)
28 {
29 Monitor.Enter (target);
30 try {
31 target.Clear ();
32 for (int i = 0; i < sourceFields.Length; i++) {
33 if (sourceFields [i].count > 0) {
34 int count = sourceFields [i].count;
35 string name = getInvFieldName (sourceFields [i]);
36
37 target.Add (new InvItem (name, count));
38 } else {
39 target.Add (null);
40 }
41 }
42 } finally {
43 Monitor.Exit (target);
44 }
45 }
46
47 private string getInvFieldName (InventoryField item)
48 {
49 ItemBase iBase = ItemBase.list [item.itemValue.type];
50 string name = iBase.name;
51 if (iBase.IsBlock ()) {
52 ItemBlock iBlock = (ItemBlock)iBase;
53 name = iBlock.GetItemName (item.itemValue);
54 }
55 return name;
56 }
57
58
59 }
60}
61
Note: See TracBrowser for help on using the repository browser.