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

Last change on this file since 242 was 238, checked in by alloc, 9 years ago

Server fixes for A12

File size: 1.2 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, pdf.id);
24 ProcessInv (belt, pdf.inventory, pdf.id);
25 }
26
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 ();
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);
42 }
43 }
44 }
45 }
46
47
48 }
49}
50
Note: See TracBrowser for help on using the repository browser.