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 class ItemInfo
\r
25 private int _nowShips;
\r
26 private readonly Dictionary<int,int> _itemSpecs = new Dictionary<int, int>();
\r
27 private readonly Dictionary<int, int> _itemIds = new Dictionary<int, int>();
\r
29 public int MaxShips { get; private set; }
\r
30 public int MarginShips { get; set; }
\r
31 public bool NeedRing { get; set; }
\r
32 public int NowItems { get; set; }
\r
33 public int MaxItems { get; private set; }
\r
34 public int NumBuckets { get; set; }
\r
38 get { return _nowShips; }
\r
43 var limit = MaxShips - MarginShips;
\r
44 NeedRing = _nowShips < limit && value >= limit;
\r
50 public bool TooManyShips
\r
52 get { return MaxShips != 0 && NowShips >= MaxShips - MarginShips; }
\r
60 public void InspectBasic(dynamic json)
\r
62 MaxShips = (int)json.api_max_chara;
\r
63 MaxItems = (int)json.api_max_slotitem;
\r
66 public void InspectMaterial(dynamic json)
\r
68 foreach (var entry in json)
\r
70 if ((int)entry.api_id != 6)
\r
72 NumBuckets = (int)entry.api_value;
\r
76 public void InspectMaster(dynamic json)
\r
78 foreach (var entry in json)
\r
80 if ((int)entry.api_type[0] == 3) // 艦載機
\r
81 _itemSpecs[(int)entry.api_id] = (int)entry.api_tyku;
\r
85 public void InspectSlotItem(dynamic json, bool full = false)
\r
88 json = new[] {json};
\r
90 NowItems = ((object[])json).Length;
\r
91 foreach (var entry in json)
\r
92 _itemIds[(int)entry.api_id] = (int)entry.api_slotitem_id;
\r
95 public void InspectCreateItem(dynamic json)
\r
97 if (!json.IsDefined("api_slot_item"))
\r
99 InspectSlotItem(json.api_slot_item);
\r
103 public void InspectGetShip(dynamic json)
\r
105 InspectSlotItem(json.api_slotitem);
\r
106 NowItems += ((object[])json.api_slotitem).Length;
\r
110 public void InspectDestroyItem(string request)
\r
112 var values = HttpUtility.ParseQueryString(request);
\r
113 NowItems -= values["api_slotitem_ids"].Split(',').Length;
\r
116 public int GetTyKu(int id)
\r
120 return _itemIds.TryGetValue(id, out item) ? _itemSpecs.TryGetValue(item, out tyku) ? tyku : 0 : 0;
\r