source: binary-improvements/7dtd-server-fixes/src/PlayerDataStuff.cs@ 128

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

Fixes

File size: 2.9 KB
Line 
1using System;
2using System.Collections.Generic;
3
4public class PlayerDataStuff
5{
6 public class PlayerItems
7 {
8 public SortedList<string, int> belt = new SortedList<string, int> ();
9 public SortedList<string, int> bag = new SortedList<string, int> ();
10
11 public PlayerItems (InventoryField[] _belt, InventoryField[] _bag)
12 {
13 foreach (InventoryField item in _belt) {
14 if (item.count > 0) {
15 string name = getInvFieldName (item);
16 if (belt.ContainsKey (name)) {
17 belt [name] += item.count;
18 } else {
19 belt.Add (name, item.count);
20 }
21 }
22 }
23
24 foreach (InventoryField item in _bag) {
25 if (item.count > 0) {
26 string name = getInvFieldName (item);
27 if (bag.ContainsKey (name)) {
28 bag [name] += item.count;
29 } else {
30 bag.Add (name, item.count);
31 }
32 }
33 }
34 }
35 };
36
37 private static Dictionary<int, PlayerItems> itemsPerEntityId = new Dictionary<int, PlayerItems> ();
38
39 public static PlayerItems GetPlayerItems (int entityId)
40 {
41 if (itemsPerEntityId.ContainsKey (entityId))
42 return itemsPerEntityId [entityId];
43 else
44 return null;
45 }
46
47 public static void GM_SavePlayerData (GameManager manager, int _clientId, PlayerDataFile _playerDataFile)
48 {
49 try {
50 int entityId = CommonMappingFunctions.GetEntityID (CommonMappingFunctions.GetClientInfoFromClientID (_clientId));
51 if (entityId >= 0) {
52 Log.Out ("Saving playerData for entity id: " + entityId);
53
54 if (itemsPerEntityId.ContainsKey (entityId))
55 itemsPerEntityId.Remove (entityId);
56 itemsPerEntityId.Add (entityId, new PlayerItems (_playerDataFile.inventory, _playerDataFile.bag));
57 }
58 } catch (Exception e) {
59 Log.Out ("Error in GM_SavePlayerData: " + e);
60 }
61
62// Log.Out ("Inventory of player:");
63// for (int i = 0; i < _playerDataFile.inventory.Length; i++) {
64// InventoryField item = _playerDataFile.inventory [i];
65// printItem (item, i);
66// }
67//
68// Log.Out ("Bag of player:");
69// for (int i = 0; i < _playerDataFile.bag.Length; i++) {
70// InventoryField item = _playerDataFile.bag [i];
71// printItem (item, i);
72// }
73 }
74
75 private static string getInvFieldName (InventoryField item)
76 {
77 ItemBase iBase = ItemBase.list [item.itemValue.type];
78 string name = iBase.name;
79 if (iBase.IsBlock ()) {
80 ItemBlock iBlock = (ItemBlock)iBase;
81 name = iBlock.GetItemName (item.itemValue);
82 }
83 return name;
84 }
85
86 private static void printItem (InventoryField item, int slot)
87 {
88 if (item.count > 0) {
89 ItemBase iBase = ItemBase.list [item.itemValue.type];
90 string name = iBase.name;
91 if (iBase.IsBlock ()) {
92 ItemBlock iBlock = (ItemBlock)iBase;
93 name = iBlock.GetItemName (item.itemValue);
94 }
95 Log.Out (string.Format ("Slot {0:00}: {1:00} * {2}, blockinst={3}, meta={4}, type={5}, usetimes={6}",
96 slot, item.count, name, item.itemValue.blockinst, item.itemValue.meta, item.itemValue.type, item.itemValue.usetimes));
97 }
98 }
99}
100
Note: See TracBrowser for help on using the repository browser.