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

Last change on this file since 247 was 245, checked in by alloc, 9 years ago

Fixes

File size: 1.8 KB
RevLine 
[144]1using System;
2using System.Collections.Generic;
3using System.Runtime.Serialization;
4using System.Threading;
5
6namespace AllocsFixes.PersistentData
7{
8 [Serializable]
[245]9 public class Inventory {
[144]10 public List<InvItem> bag;
11 public List<InvItem> belt;
[245]12 public InvItem[] equipment;
[144]13
[245]14 public Inventory () {
[144]15 bag = new List<InvItem> ();
16 belt = new List<InvItem> ();
[245]17 equipment = null;
[144]18 }
19
[245]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 }
[144]27 }
28
[245]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 ();
[144]36
[245]37 if (count > maxAllowed) {
38 Log.Out ("Player with ID " + id + " has stack for \"" + name + "\" greater than allowed (" + count + " > " + maxAllowed + ")");
[144]39 }
[245]40 target.Add (new InvItem (name, count));
41 } else {
42 target.Add (null);
[144]43 }
44 }
45 }
46
[245]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 ();
[144]53
[245]54 equipment [i] = new InvItem (name, count);
55 } else {
56 equipment [i] = null;
57 }
58 }
59 }
60
61
[144]62 }
63}
64
Note: See TracBrowser for help on using the repository browser.