OSDN Git Service

Model、View、Net、Utilの名前空間にクラスを分類する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / 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 KancolleSniffer.Model;\r
18 using static System.Math;\r
19 \r
20 namespace KancolleSniffer.View\r
21 {\r
22     public class MiscTextInfo\r
23     {\r
24         private readonly ShipInfo _shipInfo;\r
25         private readonly ItemInfo _itemInfo;\r
26         private bool _inSortie;\r
27 \r
28         private const string GuideText =\r
29             "[海域ゲージ情報]\r\n 海域選択画面に進むと表示します。\r\n[演習情報]\r\n 演習相手を選ぶと表示します。\r\n[獲得アイテム]\r\n 帰投したときに表示します。";\r
30 \r
31         public string Text { get; private set; } = GuideText;\r
32 \r
33         public MiscTextInfo(ShipInfo shipInfo, ItemInfo itemInfo)\r
34         {\r
35             _shipInfo = shipInfo;\r
36             _itemInfo = itemInfo;\r
37         }\r
38 \r
39         public void Port()\r
40         {\r
41             if (_inSortie)\r
42             {\r
43                 _inSortie = false;\r
44                 var text = GenerateItemGetText();\r
45                 Text = text == "" ? GuideText : "[獲得アイテム]\r\n" + text;\r
46             }\r
47             _items.Clear();\r
48         }\r
49 \r
50         private readonly Dictionary<int, int> _required = new Dictionary<int, int>\r
51         {\r
52             {15, 4},\r
53             {16, 7},\r
54             {25, 4},\r
55             {35, 4},\r
56             {44, 4},\r
57             {45, 5},\r
58             {52, 4},\r
59             {53, 5},\r
60             {54, 5},\r
61             {55, 5},\r
62             {62, 3},\r
63             {63, 4},\r
64             {64, 5},\r
65             {65, 6}\r
66         };\r
67 \r
68         public void InspectMapInfo(dynamic json)\r
69         {\r
70             Text = "[海域ゲージ]\r\n";\r
71             foreach (var entry in json.api_map_info() ? json.api_map_info : json)\r
72             {\r
73                 var map = (int)entry.api_id;\r
74                 if (entry.api_eventmap())\r
75                 {\r
76                     var evmap = entry.api_eventmap;\r
77                     Text += $"{map / 10}-{map % 10} : HP {(int)evmap.api_now_maphp}/{(int)evmap.api_max_maphp}\r\n";\r
78                     continue;\r
79                 }\r
80                 if (!entry.api_defeat_count())\r
81                     continue;\r
82                 var reqStr = _required.TryGetValue(map, out var req) ? req.ToString() : "?";\r
83                 Text += $"{map / 10}-{map % 10} : 撃破 {(int)entry.api_defeat_count}/{reqStr}\r\n";\r
84             }\r
85         }\r
86 \r
87         private readonly int[] _expTable =\r
88         {\r
89             0, 100, 300, 600, 1000, 1500, 2100, 2800, 3600, 4500,\r
90             5500, 6600, 7800, 9100, 10500, 12000, 13600, 15300, 17100, 19000,\r
91             21000, 23100, 25300, 27600, 30000, 32500, 35100, 37800, 40600, 43500,\r
92             46500, 49600, 52800, 56100, 59500, 63000, 66600, 70300, 74100, 78000,\r
93             82000, 86100, 90300, 94600, 99000, 103500, 108100, 112800, 117600, 122500,\r
94             127500, 132700, 138100, 143700, 149500, 155500, 161700, 168100, 174700, 181500,\r
95             188500, 195800, 203400, 211300, 219500, 228000, 236800, 245900, 255300, 265000,\r
96             275000, 285400, 296200, 307400, 319000, 331000, 343400, 356200, 369400, 383000,\r
97             397000, 411500, 426500, 442000, 458000, 474500, 491500, 509000, 527000, 545500,\r
98             564500, 584500, 606500, 631500, 661500, 701500, 761500, 851500, 1000000, 1000000,\r
99             1010000, 1011000, 1013000, 1016000, 1020000, 1025000, 1031000, 1038000, 1046000, 1055000,\r
100             1065000, 1077000, 1091000, 1107000, 1125000, 1145000, 1168000, 1194000, 1223000, 1255000,\r
101             1290000, 1329000, 1372000, 1419000, 1470000, 1525000, 1584000, 1647000, 1714000, 1785000,\r
102             1860000, 1940000, 2025000, 2115000, 2210000, 2310000, 2415000, 2525000, 2640000, 2760000,\r
103             2887000, 3021000, 3162000, 3310000, 3465000, 3628000, 3799000, 3978000, 4165000, 4360000,\r
104             4564000, 4777000, 4999000, 5230000, 5470000, 5720000, 5780000, 5860000, 5970000, 6120000,\r
105             6320000, 6580000, 6910000, 7320000, 7820000\r
106         };\r
107 \r
108         public void InspectPracticeEnemyInfo(dynamic json)\r
109         {\r
110             Text = $"[演習情報]\r\n敵艦隊名 : {json.api_deckname}\r\n";\r
111             var ships = json.api_deck.api_ships;\r
112             var s1 = (int)ships[0].api_id != -1 ? (int)ships[0].api_level : 1;\r
113             var s2 = (int)ships[1].api_id != -1 ? (int)ships[1].api_level : 1;\r
114             var raw = _expTable[Min(s1, _expTable.Length) - 1] / 100.0 +\r
115                       _expTable[Min(s2, _expTable.Length) - 1] / 300.0;\r
116             var exp = raw >= 500 ? 500 + (int)Sqrt(raw - 500) : (int)raw;\r
117             var bonus = 1 + TrainingCruiserBonus(_shipInfo.Fleets[0].Ships);\r
118             Text += $"獲得経験値 : {(int)(exp * bonus)}\r\nS勝利 : {(int)((int)(exp * 1.2) * bonus)}";\r
119         }\r
120 \r
121         private double TrainingCruiserBonus(ShipStatus[] fleet)\r
122         {\r
123             if (fleet[0].Spec.IsTrainingCruiser)\r
124             {\r
125                 var fsLevel = fleet[0].Level;\r
126                 if (fleet.Skip(1).Any(s => s.Spec.IsTrainingCruiser))\r
127                 {\r
128                     if (fsLevel < 10)\r
129                         return 0.10;\r
130                     if (fsLevel < 30)\r
131                         return 0.13;\r
132                     if (fsLevel < 60)\r
133                         return 0.16;\r
134                     if (fsLevel < 100)\r
135                         return 0.20;\r
136                     return 0.25;\r
137                 }\r
138                 if (fsLevel < 10)\r
139                     return 0.05;\r
140                 if (fsLevel < 30)\r
141                     return 0.08;\r
142                 if (fsLevel < 60)\r
143                     return 0.12;\r
144                 if (fsLevel < 100)\r
145                     return 0.15;\r
146                 return 0.20;\r
147             }\r
148             var tc = fleet.Count(s => s.Spec.IsTrainingCruiser);\r
149             if (tc == 0)\r
150                 return 0;\r
151             var level = fleet.Where(s => s.Spec.IsTrainingCruiser).Max(s => s.Level);\r
152             if (tc == 1)\r
153             {\r
154                 if (level < 10)\r
155                     return 0.03;\r
156                 if (level < 30)\r
157                     return 0.05;\r
158                 if (level < 60)\r
159                     return 0.07;\r
160                 if (level < 100)\r
161                     return 0.10;\r
162                 return 0.15;\r
163             }\r
164             if (level < 10)\r
165                 return 0.04;\r
166             if (level < 30)\r
167                 return 0.06;\r
168             if (level < 60)\r
169                 return 0.08;\r
170             if (level < 100)\r
171                 return 0.12;\r
172             return 0.175;\r
173         }\r
174 \r
175         public void InspectMapNext(dynamic json)\r
176         {\r
177             if (json.api_airsearch() && (int)json.api_airsearch.api_result != 0)\r
178             {\r
179                 var item = json.api_itemget;\r
180                 AddItemCount((int)item.api_usemst + 100, (int)item.api_id, (int)item.api_getcount);\r
181                 return;\r
182             }\r
183             if (json.api_itemget())\r
184             {\r
185                 foreach (var item in json.api_itemget)\r
186                     AddItemCount((int)item.api_usemst, (int)item.api_id, (int)item.api_getcount);\r
187             }\r
188             if (json.api_itemget_eo_result())\r
189             {\r
190                 var eo = json.api_itemget_eo_result;\r
191                 AddItemCount((int)eo.api_usemst, (int)eo.api_id, (int)eo.api_getcount);\r
192             }\r
193             if (json.api_itemget_eo_comment())\r
194             {\r
195                 var eo = json.api_itemget_eo_comment;\r
196                 AddItemCount((int)eo.api_usemst, (int)eo.api_id, (int)eo.api_getcount);\r
197             }\r
198             if (json.api_eventmap() && json.api_eventmap.api_itemget())\r
199             {\r
200                 foreach (var item in json.api_eventmap.api_itemget)\r
201                 {\r
202                     var type = (int)item.api_type;\r
203                     type = type == 1 ? 5 :\r
204                         type == 5 ? 6 : type;\r
205                     AddItemCount(type, (int)item.api_id, (int)item.api_value);\r
206                 }\r
207             }\r
208         }\r
209 \r
210         public void InspectMapStart(dynamic json)\r
211         {\r
212             _inSortie = true;\r
213             InspectMapNext(json);\r
214         }\r
215 \r
216         public void InspectBattleResult(dynamic json)\r
217         {\r
218             if (json.api_get_eventitem())\r
219             {\r
220                 foreach (var item in json.api_get_eventitem)\r
221                 {\r
222                     var type = (int)item.api_type;\r
223                     type = type == 1 ? 5 :\r
224                         type == 5 ? 6 : type;\r
225                     var id = (int)item.api_id;\r
226                     AddItemCount(type, id, (int)item.api_value);\r
227                 }\r
228             }\r
229             if (json.api_mapcell_incentive() && (int)json.api_mapcell_incentive == 1)\r
230             {\r
231                 foreach (var type in _items.Keys.Where(type => type > 100).ToArray())\r
232                 {\r
233                     foreach (var id in _items[type])\r
234                         AddItemCount(type - 100, id.Key, id.Value);\r
235                 }\r
236             }\r
237         }\r
238 \r
239         private readonly Dictionary<int, SortedDictionary<int, int>> _items =\r
240             new Dictionary<int, SortedDictionary<int, int>>();\r
241 \r
242         private void AddItemCount(int type, int id, int count)\r
243         {\r
244             if (!_items.ContainsKey(type))\r
245                 _items[type] = new SortedDictionary<int, int>();\r
246             var dict = _items[type];\r
247             if (!dict.ContainsKey(id))\r
248                 dict[id] = 0;\r
249             dict[id] += count;\r
250         }\r
251 \r
252         private readonly Dictionary<int, string> _furniture = new Dictionary<int, string>();\r
253 \r
254         public void InspectMaster(dynamic json)\r
255         {\r
256             if (!json.api_mst_furniture())\r
257                 return;\r
258             foreach (var entry in json.api_mst_furniture)\r
259                 _furniture[(int)entry.api_id] = (string)entry.api_title;\r
260         }\r
261 \r
262         private string GetName(int type, int id)\r
263         {\r
264             switch (type)\r
265             {\r
266                 case 2:\r
267                     return _shipInfo.GetSpec(id).Name;\r
268                 case 3:\r
269                     return _itemInfo.GetSpecByItemId(id).Name;\r
270                 case 4:\r
271                     return new[] {"燃料", "弾薬", "鋼材", "ボーキサイト", "高速建造材", "高速修復材", "開発資材", "改修資材"}[id - 1];\r
272                 case 5:\r
273                     return _itemInfo.GetUseItemName(id);\r
274                 case 6:\r
275                     return _furniture[id];\r
276                 default:\r
277                     return "";\r
278             }\r
279         }\r
280 \r
281         private string GenerateItemGetText()\r
282         {\r
283             return string.Join("\r\n",\r
284                 new[] {4, 5, 3, 6, 2}.Where(_items.ContainsKey).SelectMany(type =>\r
285                     _items[type].Select(pair => GetName(type, pair.Key) + ": " + pair.Value)));\r
286         }\r
287     }\r
288 }