[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 |
|
---|
[98] | 11 | public PlayerItems (InventoryField[] _belt, InventoryField[] _bag)
|
---|
[93] | 12 | {
|
---|
[98] | 13 | foreach (InventoryField item in _belt) {
|
---|
[93] | 14 | if (item.count > 0) {
|
---|
[98] | 15 | string name = getInvFieldName(item);
|
---|
| 16 | if (belt.ContainsKey(name)) {
|
---|
| 17 | belt[name] += item.count;
|
---|
| 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) {
|
---|
[98] | 26 | string name = getInvFieldName(item);
|
---|
| 27 | if (bag.ContainsKey(name)) {
|
---|
| 28 | bag[name] += item.count;
|
---|
| 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 | {
|
---|
| 49 | if (manager.connectionManager.mapClientToEntity.ContainsKey (_clientId)) {
|
---|
| 50 | int entityId = manager.connectionManager.mapClientToEntity [_clientId];
|
---|
| 51 | Log.Out ("Saving playerData for entity id: " + entityId);
|
---|
| 52 |
|
---|
| 53 | if (itemsPerEntityId.ContainsKey(entityId))
|
---|
| 54 | itemsPerEntityId.Remove(entityId);
|
---|
| 55 | itemsPerEntityId.Add (entityId, new PlayerItems (_playerDataFile.inventory, _playerDataFile.bag));
|
---|
| 56 | }
|
---|
| 57 | /*
|
---|
| 58 | Log.Out ("Inventory of player:");
|
---|
| 59 | for (int i = 0; i < _playerDataFile.inventory.Length; i++) {
|
---|
| 60 | InventoryField item = _playerDataFile.inventory [i];
|
---|
| 61 | printItem (item, i);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | Log.Out ("Bag of player:");
|
---|
| 65 | for (int i = 0; i < _playerDataFile.bag.Length; i++) {
|
---|
| 66 | InventoryField item = _playerDataFile.bag [i];
|
---|
| 67 | printItem (item, i);
|
---|
| 68 | }*/
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | private static string getInvFieldName (InventoryField item)
|
---|
| 72 | {
|
---|
| 73 | ItemBase iBase = ItemBase.list [item.itemValue.type];
|
---|
| 74 | string name = iBase.name;
|
---|
| 75 | if (iBase.IsBlock ()) {
|
---|
| 76 | ItemBlock iBlock = (ItemBlock)iBase;
|
---|
| 77 | name = iBlock.GetItemName (item.itemValue);
|
---|
| 78 | }
|
---|
| 79 | return name;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | private static void printItem (InventoryField item, int slot)
|
---|
| 83 | {
|
---|
| 84 | if (item.count > 0) {
|
---|
| 85 | ItemBase iBase = ItemBase.list [item.itemValue.type];
|
---|
| 86 | string name = iBase.name;
|
---|
| 87 | if (iBase.IsBlock ()) {
|
---|
| 88 | ItemBlock iBlock = (ItemBlock)iBase;
|
---|
| 89 | name = iBlock.GetItemName (item.itemValue);
|
---|
| 90 | }
|
---|
| 91 | Log.Out (string.Format ("Slot {0:00}: {1:00} * {2}", slot, item.count, name));
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|