- Timestamp:
- Aug 12, 2015, 6:10:28 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r245 r250 35 35 result.Add ("equipment", equipment); 36 36 37 for (int i = 0; i < inv.belt.Count; i++) { 38 JSONObject item = new JSONObject (); 39 if (inv.belt [i] != null) { 40 item.Add ("count", new JSONNumber (inv.belt [i].count)); 41 item.Add ("name", new JSONString (inv.belt [i].itemName)); 42 } else { 43 item.Add ("count", new JSONNumber (0)); 44 item.Add ("name", new JSONString (string.Empty)); 45 } 46 belt.Add (item); 47 } 48 for (int i = 0; i < inv.bag.Count; i++) { 49 JSONObject item = new JSONObject (); 50 if (inv.bag [i] != null) { 51 item.Add ("count", new JSONNumber (inv.bag [i].count)); 52 item.Add ("name", new JSONString (inv.bag [i].itemName)); 53 } else { 54 item.Add ("count", new JSONNumber (0)); 55 item.Add ("name", new JSONString (string.Empty)); 56 } 57 bag.Add (item); 58 } 37 DoInventory (belt, inv.belt); 38 DoInventory (bag, inv.bag); 59 39 60 40 AddEquipment (equipment, "head", inv.equipment, XMLData.Item.EnumEquipmentSlot.Head, NGuiInvGridEquipment.EnumClothingLayer.Middle); … … 76 56 } 77 57 58 private void DoInventory (JSONArray _jsonRes, List<InvItem> _inv) { 59 for (int i = 0; i < _inv.Count; i++) { 60 _jsonRes.Add (GetJsonForItem (_inv [i])); 61 } 62 } 63 78 64 private void AddEquipment (JSONObject _eq, string _slotname, InvItem[] _items, XMLData.Item.EnumEquipmentSlot _slot, NGuiInvGridEquipment.EnumClothingLayer _layer) { 79 65 int index = (int)_slot + (int)_layer * (int)XMLData.Item.EnumEquipmentSlot.Count; 80 if (_items != null && _items [index] != null) {81 _eq.Add (_slotname, new JSONString (_items [index].itemName));66 if (_items != null) { 67 _eq.Add (_slotname, GetJsonForItem (_items [index])); 82 68 } else { 83 _eq.Add (_slotname, new JSONBoolean (false)); 69 _eq.Add (_slotname, new JSONNull ()); 70 } 71 } 72 73 private JSONNode GetJsonForItem (InvItem _item) { 74 if (_item != null) { 75 JSONObject jsonItem = new JSONObject (); 76 jsonItem.Add ("count", new JSONNumber (_item.count)); 77 jsonItem.Add ("name", new JSONString (_item.itemName)); 78 jsonItem.Add ("quality", new JSONNumber (_item.quality)); 79 if (_item.quality >= 0) { 80 jsonItem.Add ("qualitycolor", new JSONString (QualityInfo.GetQualityColorHex (_item.quality))); 81 } 82 return jsonItem; 83 } else { 84 return new JSONNull (); 84 85 } 85 86 }
Note:
See TracChangeset
for help on using the changeset viewer.