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