1 // Copyright (C) 2013 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>
\r
3 // This program is part of KancolleSniffer.
\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify
\r
6 // it under the terms of the GNU General Public License as published by
\r
7 // the Free Software Foundation, either version 3 of the License, or
\r
8 // (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.
\r
18 using System.Collections.Generic;
\r
21 namespace KancolleSniffer
\r
23 public struct ItemSpec
\r
29 public class ItemInfo
\r
31 private int _nowShips;
\r
32 private readonly Dictionary<int, ItemSpec> _itemSpecs = new Dictionary<int, ItemSpec>();
\r
33 private readonly Dictionary<int, int> _itemIds = new Dictionary<int, int>();
\r
35 public int MaxShips { get; private set; }
\r
36 public int MarginShips { get; set; }
\r
37 public bool NeedRing { get; set; }
\r
38 public int NowItems { get; set; }
\r
39 public int MaxItems { get; private set; }
\r
40 public int NumBuckets { get; set; }
\r
44 get { return _nowShips; }
\r
49 var limit = MaxShips - MarginShips;
\r
50 NeedRing = _nowShips < limit && value >= limit;
\r
56 public bool TooManyShips
\r
58 get { return MaxShips != 0 && NowShips >= MaxShips - MarginShips; }
\r
66 public void InspectBasic(dynamic json)
\r
68 MaxShips = (int)json.api_max_chara;
\r
69 MaxItems = (int)json.api_max_slotitem;
\r
72 public void InspectMaterial(dynamic json)
\r
74 foreach (var entry in json)
\r
76 if ((int)entry.api_id != 6)
\r
78 NumBuckets = (int)entry.api_value;
\r
82 public void InspectMaster(dynamic json)
\r
84 foreach (var entry in json)
\r
86 _itemSpecs[(int)entry.api_id] = new ItemSpec
\r
88 Name = (string)entry.api_name,
\r
89 TyKu = (int)entry.api_type[0] == 3 ? (int)entry.api_tyku : 0 // 艦載機のみ
\r
94 public void InspectSlotItem(dynamic json, bool full = false)
\r
97 json = new[] {json};
\r
99 NowItems = ((object[])json).Length;
\r
100 foreach (var entry in json)
\r
101 _itemIds[(int)entry.api_id] = (int)entry.api_slotitem_id;
\r
104 public void InspectCreateItem(dynamic json)
\r
106 if (!json.IsDefined("api_slot_item"))
\r
108 InspectSlotItem(json.api_slot_item);
\r
112 public void InspectGetShip(dynamic json)
\r
114 InspectSlotItem(json.api_slotitem);
\r
115 NowItems += ((object[])json.api_slotitem).Length;
\r
119 public void InspectDestroyItem(string request)
\r
121 var values = HttpUtility.ParseQueryString(request);
\r
122 NowItems -= values["api_slotitem_ids"].Split(',').Length;
\r
125 public ItemSpec this[int id]
\r
131 if (_itemIds.TryGetValue(id, out itemId) && _itemSpecs.TryGetValue(itemId, out spec))
\r
133 return new ItemSpec();
\r