OSDN Git Service

「対空兵装の整備拡充」のカウンタを実装する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / MiscTextInfo.cs
1 // Copyright (C) 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\r
3 // Licensed under the Apache License, Version 2.0 (the "License");\r
4 // you may not use this file except in compliance with the License.\r
5 // You may obtain a copy of the License at\r
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\r
9 // Unless required by applicable law or agreed to in writing, software\r
10 // distributed under the License is distributed on an "AS IS" BASIS,\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 // See the License for the specific language governing permissions and\r
13 // limitations under the License.\r
14 \r
15 using System.Collections.Generic;\r
16 using System.Linq;\r
17 using static System.Math;\r
18 \r
19 namespace KancolleSniffer\r
20 {\r
21     public class MiscTextInfo\r
22     {\r
23         private readonly ShipInfo _shipInfo;\r
24         private readonly ItemInfo _itemInfo;\r
25 \r
26         private const string GuideText =\r
27             "[海域ゲージ情報]\r\n 海域選択画面に進むと表示します。\r\n[演習情報]\r\n 演習相手を選ぶと表示します。\r\n[獲得アイテム]\r\n 帰投したときに表示します。";\r
28 \r
29         public string Text { get; private set; } = GuideText;\r
30         public bool SortieStarted { private get; set; }\r
31 \r
32         public MiscTextInfo(ShipInfo shipInfo, ItemInfo itemInfo)\r
33         {\r
34             _shipInfo = shipInfo;\r
35             _itemInfo = itemInfo;\r
36         }\r
37 \r
38         public void Port()\r
39         {\r
40             if (SortieStarted)\r
41             {\r
42                 SortieStarted = false;\r
43                 var text = GenerateItemGetText();\r
44                 Text = text == "" ? GuideText : "[獲得アイテム]\r\n" + text;\r
45             }\r
46             _items.Clear();\r
47         }\r
48 \r
49         private readonly Dictionary<int, int> _required = new Dictionary<int, int>\r
50         {\r
51             {15, 4},\r
52             {16, 7},\r
53             {25, 4},\r
54             {35, 4},\r
55             {44, 4},\r
56             {45, 5},\r
57             {52, 4},\r
58             {53, 5},\r
59             {54, 5},\r
60             {55, 5},\r
61             {62, 3},\r
62             {63, 4},\r
63             {64, 5},\r
64             {65, 6}\r
65         };\r
66 \r
67         public void InspectMapInfo(dynamic json)\r
68         {\r
69             Text = "[海域ゲージ]\r\n";\r
70             foreach (var entry in json.api_map_info() ? json.api_map_info : json)\r
71             {\r
72                 var map = (int)entry.api_id;\r
73                 if (entry.api_eventmap())\r
74                 {\r
75                     var evmap = entry.api_eventmap;\r
76                     Text += $"{map / 10}-{map % 10} : HP {(int)evmap.api_now_maphp}/{(int)evmap.api_max_maphp}\r\n";\r
77                     continue;\r
78                 }\r
79                 if (!entry.api_defeat_count())\r
80                     continue;\r
81                 var reqStr = _required.TryGetValue(map, out var req) ? req.ToString() : "?";\r
82                 Text += $"{map / 10}-{map % 10} : 撃破 {(int)entry.api_defeat_count}/{reqStr}\r\n";\r
83             }\r
84         }\r
85 \r
86         private readonly int[] _expTable =\r
87         {\r
88             0, 100, 300, 600, 1000, 1500, 2100, 2800, 3600, 4500,\r
89             5500, 6600, 7800, 9100, 10500, 12000, 13600, 15300, 17100, 19000,\r
90             21000, 23100, 25300, 27600, 30000, 32500, 35100, 37800, 40600, 43500,\r
91             46500, 49600, 52800, 56100, 59500, 63000, 66600, 70300, 74100, 78000,\r
92             82000, 86100, 90300, 94600, 99000, 103500, 108100, 112800, 117600, 122500,\r
93             127500, 132700, 138100, 143700, 149500, 155500, 161700, 168100, 174700, 181500,\r
94             188500, 195800, 203400, 211300, 219500, 228000, 236800, 245900, 255300, 265000,\r
95             275000, 285400, 296200, 307400, 319000, 331000, 343400, 356200, 369400, 383000,\r
96             397000, 411500, 426500, 442000, 458000, 474500, 491500, 509000, 527000, 545500,\r
97             564500, 584500, 606500, 631500, 661500, 701500, 761500, 851500, 1000000, 1000000,\r
98             1010000, 1011000, 1013000, 1016000, 1020000, 1025000, 1031000, 1038000, 1046000, 1055000,\r
99             1065000, 1077000, 1091000, 1107000, 1125000, 1145000, 1168000, 1194000, 1223000, 1255000,\r
100             1290000, 1329000, 1372000, 1419000, 1470000, 1525000, 1584000, 1647000, 1714000, 1785000,\r
101             1860000, 1940000, 2025000, 2115000, 2210000, 2310000, 2415000, 2525000, 2640000, 2760000,\r
102             2887000, 3021000, 3162000, 3310000, 3465000, 3628000, 3799000, 3978000, 4165000, 4360000,\r
103             4564000, 4777000, 4999000, 5230000, 5470000, 5720000, 5780000, 5860000, 5970000, 6120000,\r
104             6320000, 6580000, 6910000, 7320000, 7820000\r
105         };\r
106 \r
107         public void InspectPracticeEnemyInfo(dynamic json)\r
108         {\r
109             Text = $"[演習情報]\r\n敵艦隊名 : {json.api_deckname}\r\n";\r
110             var ships = json.api_deck.api_ships;\r
111             var s1 = (int)ships[0].api_id != -1 ? (int)ships[0].api_level : 1;\r
112             var s2 = (int)ships[1].api_id != -1 ? (int)ships[1].api_level : 1;\r
113             var raw = _expTable[Min(s1, _expTable.Length) - 1] / 100.0 +\r
114                       _expTable[Min(s2, _expTable.Length) - 1] / 300.0;\r
115             var exp = raw >= 500 ? 500 + (int)Sqrt(raw - 500) : (int)raw;\r
116             Text += $"獲得経験値 : {exp}\r\nS勝利 : {(int)(exp * 1.2)}";\r
117         }\r
118 \r
119         public void InspectMapNext(dynamic json)\r
120         {\r
121             if (json.api_airsearch() && (int)json.api_airsearch.api_result != 0)\r
122             {\r
123                 var item = json.api_itemget;\r
124                 AddItemCount((int)item.api_usemst + 100, (int)item.api_id, (int)item.api_getcount);\r
125                 return;\r
126             }\r
127             if (json.api_itemget())\r
128             {\r
129                 foreach (var item in json.api_itemget)\r
130                     AddItemCount((int)item.api_usemst, (int)item.api_id, (int)item.api_getcount);\r
131             }\r
132             if (json.api_itemget_eo_result())\r
133             {\r
134                 var eo = json.api_itemget_eo_result;\r
135                 AddItemCount((int)eo.api_usemst, (int)eo.api_id, (int)eo.api_getcount);\r
136             }\r
137             if (json.api_itemget_eo_comment())\r
138             {\r
139                 var eo = json.api_itemget_eo_comment;\r
140                 AddItemCount((int)eo.api_usemst, (int)eo.api_id, (int)eo.api_getcount);\r
141             }\r
142             if (json.api_eventmap() && json.api_eventmap.api_itemget())\r
143             {\r
144                 foreach (var item in json.api_eventmap.api_itemget)\r
145                 {\r
146                     var type = (int)item.api_type;\r
147                     type = type == 1 ? 5 :\r
148                         type == 5 ? 6 : type;\r
149                     AddItemCount(type, (int)item.api_id, (int)item.api_value);\r
150                 }\r
151             }\r
152         }\r
153 \r
154         public void InspectMapStart(dynamic json)\r
155         {\r
156             InspectMapNext(json);\r
157         }\r
158 \r
159         public void InspectBattleResult(dynamic json)\r
160         {\r
161             if (json.api_get_eventitem())\r
162             {\r
163                 foreach (var item in json.api_get_eventitem)\r
164                 {\r
165                     var type = (int)item.api_type;\r
166                     type = type == 1 ? 5 :\r
167                         type == 5 ? 6 : type;\r
168                     var id = (int)item.api_id;\r
169                     AddItemCount(type, id, (int)item.api_value);\r
170                 }\r
171             }\r
172             if (json.api_mapcell_incentive() && (int)json.api_mapcell_incentive == 1)\r
173             {\r
174                 foreach (var type in _items.Keys.Where(type => type > 100).ToArray())\r
175                 {\r
176                     foreach (var id in _items[type])\r
177                         AddItemCount(type - 100, id.Key, id.Value);\r
178                 }\r
179             }\r
180         }\r
181 \r
182         private readonly Dictionary<int, SortedDictionary<int, int>> _items =\r
183             new Dictionary<int, SortedDictionary<int, int>>();\r
184 \r
185         private void AddItemCount(int type, int id, int count)\r
186         {\r
187             if (!_items.ContainsKey(type))\r
188                 _items[type] = new SortedDictionary<int, int>();\r
189             var dict = _items[type];\r
190             if (!dict.ContainsKey(id))\r
191                 dict[id] = 0;\r
192             dict[id] += count;\r
193         }\r
194 \r
195         private readonly Dictionary<int, string> _furniture = new Dictionary<int, string>();\r
196 \r
197         public void InspectMaster(dynamic json)\r
198         {\r
199             if (!json.api_mst_furniture())\r
200                 return;\r
201             foreach (var entry in json.api_mst_furniture)\r
202                 _furniture[(int)entry.api_id] = (string)entry.api_title;\r
203         }\r
204 \r
205         private string GetName(int type, int id)\r
206         {\r
207             switch (type)\r
208             {\r
209                 case 2:\r
210                     return _shipInfo.GetSpec(id).Name;\r
211                 case 3:\r
212                     return _itemInfo.GetSpecByItemId(id).Name;\r
213                 case 4:\r
214                     return new[] {"燃料", "弾薬", "鋼材", "ボーキサイト", "高速建造材", "高速修復材", "開発資材", "改修資材"}[id - 1];\r
215                 case 5:\r
216                     return _itemInfo.GetUseItemName(id);\r
217                 case 6:\r
218                     return _furniture[id];\r
219                 default:\r
220                     return "";\r
221             }\r
222         }\r
223 \r
224         private string GenerateItemGetText()\r
225         {\r
226             return string.Join("\r\n",\r
227                 new[] {4, 5, 3, 6, 2}.Where(_items.ContainsKey).SelectMany(type =>\r
228                     _items[type].Select(pair => GetName(type, pair.Key) + ": " + pair.Value)));\r
229         }\r
230     }\r
231 }