OSDN Git Service

モデルとビューの分離
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / ItemInfo.cs
1 // Copyright (C) 2013 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\r
2 // \r
3 // This program is part of KancolleSniffer.\r
4 //\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
9 //\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
14 //\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
17 \r
18 namespace KancolleSniffer\r
19 {\r
20     public class ItemInfo\r
21     {\r
22         private int _nowShips;\r
23 \r
24         public int NowShips\r
25         {\r
26             get { return _nowShips; }\r
27             set\r
28             {\r
29                 if (MaxShips != 0)\r
30                 {\r
31                     var limit = MaxShips - MarginShips;\r
32                     NeedRing = _nowShips < limit && value >= limit;\r
33                 }\r
34                 _nowShips = value;\r
35             }\r
36         }\r
37 \r
38         public int MaxShips { get; set; }\r
39         public int MarginShips { get; set; }\r
40         public bool NeedRing { get; set; }\r
41         public int NowItems { get; set; }\r
42         public int MaxItems { get; set; }\r
43         public int NumBuckets { get; set; }\r
44 \r
45         public bool TooManyShips\r
46         {\r
47             get { return MaxShips != 0 && NowShips >= MaxShips - MarginShips; }\r
48         }\r
49 \r
50         public ItemInfo()\r
51         {\r
52             MarginShips = 4;\r
53         }\r
54 \r
55         public void InspectBasic(dynamic json)\r
56         {\r
57             MaxShips = (int)json.api_max_chara;\r
58             MaxItems = (int)json.api_max_slotitem;\r
59         }\r
60         public void InspectRecord(dynamic json)\r
61         {\r
62             NowShips = (int)json.api_ship[0];\r
63             MaxShips = (int)json.api_ship[1];\r
64             NowItems = (int)json.api_slotitem[0];\r
65             MaxItems = (int)json.api_slotitem[1];\r
66         }\r
67 \r
68         public void InspectMaterial(dynamic json)\r
69         {\r
70             foreach (var entry in json)\r
71             {\r
72                 if ((int)entry.api_id != 6)\r
73                     continue;\r
74                 NumBuckets = (int)entry.api_value;\r
75             }\r
76         }\r
77 \r
78         public void InspectSlotItem(dynamic json)\r
79         {\r
80             NowItems = ((object[])json).Length;\r
81         }\r
82     }\r
83 }