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

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

fixes

File size: 2.7 KB
RevLine 
[93]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
[98]11 public PlayerItems (InventoryField[] _belt, InventoryField[] _bag)
[93]12 {
[98]13 foreach (InventoryField item in _belt) {
[93]14 if (item.count > 0) {
[103]15 string name = getInvFieldName (item);
16 if (belt.ContainsKey (name)) {
17 belt [name] += item.count;
[98]18 } else {
19 belt.Add (name, item.count);
20 }
[93]21 }
22 }
23
[98]24 foreach (InventoryField item in _bag) {
[93]25 if (item.count > 0) {
[103]26 string name = getInvFieldName (item);
27 if (bag.ContainsKey (name)) {
28 bag [name] += item.count;
[98]29 } else {
30 bag.Add (name, item.count);
31 }
[93]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 {
[103]49 try {
50 int entityId = CommonMappingFunctions.GetEntityID (CommonMappingFunctions.GetClientInfoFromClientID (_clientId));
51 if (entityId >= 0) {
52 Log.Out ("Saving playerData for entity id: " + entityId);
[93]53
[103]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);
[93]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}", slot, item.count, name));
96 }
97 }
98}
99
Note: See TracBrowser for help on using the repository browser.