| [93] | 1 | using System;
 | 
|---|
 | 2 | using System.Collections.Generic;
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | public 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 |                                         this.belt.Add (getInvFieldName (item), item.count);
 | 
|---|
 | 16 |                                 }
 | 
|---|
 | 17 |                         }
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 |                         foreach (InventoryField item in bag) {
 | 
|---|
 | 20 |                                 if (item.count > 0) {
 | 
|---|
 | 21 |                                         this.bag.Add (getInvFieldName (item), item.count);
 | 
|---|
 | 22 |                                 }
 | 
|---|
 | 23 |                         }
 | 
|---|
 | 24 |                 }
 | 
|---|
 | 25 |         };
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 |         private static Dictionary<int, PlayerItems> itemsPerEntityId = new Dictionary<int, PlayerItems> ();
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 |         public static PlayerItems GetPlayerItems (int entityId)
 | 
|---|
 | 30 |         {
 | 
|---|
 | 31 |                 if (itemsPerEntityId.ContainsKey (entityId))
 | 
|---|
 | 32 |                         return itemsPerEntityId [entityId];
 | 
|---|
 | 33 |                 else
 | 
|---|
 | 34 |                         return null;
 | 
|---|
 | 35 |         }
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 |         public static void GM_SavePlayerData (GameManager manager, int _clientId, PlayerDataFile _playerDataFile)
 | 
|---|
 | 38 |         {
 | 
|---|
 | 39 |                 if (manager.connectionManager.mapClientToEntity.ContainsKey (_clientId)) {
 | 
|---|
 | 40 |                         int entityId = manager.connectionManager.mapClientToEntity [_clientId];
 | 
|---|
 | 41 |                         Log.Out ("Saving playerData for entity id: " + entityId);
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 |                         if (itemsPerEntityId.ContainsKey(entityId))
 | 
|---|
 | 44 |                                 itemsPerEntityId.Remove(entityId);
 | 
|---|
 | 45 |                         itemsPerEntityId.Add (entityId, new PlayerItems (_playerDataFile.inventory, _playerDataFile.bag));
 | 
|---|
 | 46 |                 }
 | 
|---|
 | 47 |                 /*
 | 
|---|
 | 48 |                 Log.Out ("Inventory of player:");
 | 
|---|
 | 49 |                 for (int i = 0; i < _playerDataFile.inventory.Length; i++) {
 | 
|---|
 | 50 |                         InventoryField item = _playerDataFile.inventory [i];
 | 
|---|
 | 51 |                         printItem (item, i);
 | 
|---|
 | 52 |                 }
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 |                 Log.Out ("Bag of player:");
 | 
|---|
 | 55 |                 for (int i = 0; i < _playerDataFile.bag.Length; i++) {
 | 
|---|
 | 56 |                         InventoryField item = _playerDataFile.bag [i];
 | 
|---|
 | 57 |                         printItem (item, i);
 | 
|---|
 | 58 |                 }*/
 | 
|---|
 | 59 |         }
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 |         private static string getInvFieldName (InventoryField item)
 | 
|---|
 | 62 |         {
 | 
|---|
 | 63 |                 ItemBase iBase = ItemBase.list [item.itemValue.type];
 | 
|---|
 | 64 |                 string name = iBase.name;
 | 
|---|
 | 65 |                 if (iBase.IsBlock ()) {
 | 
|---|
 | 66 |                         ItemBlock iBlock = (ItemBlock)iBase;
 | 
|---|
 | 67 |                         name = iBlock.GetItemName (item.itemValue);
 | 
|---|
 | 68 |                 }
 | 
|---|
 | 69 |                 return name;
 | 
|---|
 | 70 |         }
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 |         private static void printItem (InventoryField item, int slot)
 | 
|---|
 | 73 |         {
 | 
|---|
 | 74 |                 if (item.count > 0) {
 | 
|---|
 | 75 |                         ItemBase iBase = ItemBase.list [item.itemValue.type];
 | 
|---|
 | 76 |                         string name = iBase.name;
 | 
|---|
 | 77 |                         if (iBase.IsBlock ()) {
 | 
|---|
 | 78 |                                 ItemBlock iBlock = (ItemBlock)iBase;
 | 
|---|
 | 79 |                                 name = iBlock.GetItemName (item.itemValue);
 | 
|---|
 | 80 |                         }
 | 
|---|
 | 81 |                         Log.Out (string.Format ("Slot {0:00}: {1:00} * {2}", slot, item.count, name));
 | 
|---|
 | 82 |                 }
 | 
|---|
 | 83 |         }
 | 
|---|
 | 84 | }
 | 
|---|
 | 85 | 
 | 
|---|