OSDN Git Service

先制対潜の判定を最新の検証結果に合わせる
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Model / 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 \r
18 namespace KancolleSniffer.Model\r
19 {\r
20     public class MiscTextInfo\r
21     {\r
22         private readonly ShipInfo _shipInfo;\r
23         private readonly ItemInfo _itemInfo;\r
24         private bool _inSortie;\r
25         private readonly Dictionary<int, int> _gaugeCount = new Dictionary<int, int>();\r
26         private readonly Dictionary<int, string> _furniture = new Dictionary<int, string>();\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         public void InspectMaster(dynamic json)\r
51         {\r
52             if (json.api_mst_mapinfo())\r
53             {\r
54                 foreach (var entry in json.api_mst_mapinfo)\r
55                 {\r
56                     if (entry.api_required_defeat_count != null)\r
57                         _gaugeCount[(int)entry.api_id] = (int)entry.api_required_defeat_count;\r
58                 }\r
59             }\r
60             if (json.api_mst_furniture())\r
61             {\r
62                 foreach (var entry in json.api_mst_furniture)\r
63                     _furniture[(int)entry.api_id] = (string)entry.api_title;\r
64             }\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 eventMap = entry.api_eventmap;\r
76                     if (eventMap.api_now_maphp())\r
77                     {\r
78                         Text +=\r
79                             $"{map / 10}-{map % 10} : HP {(int)eventMap.api_now_maphp}/{(int)eventMap.api_max_maphp}\r\n";\r
80                     }\r
81                     continue;\r
82                 }\r
83                 if (!entry.api_defeat_count())\r
84                     continue;\r
85                 var max = entry.api_required_defeat_count()\r
86                     ? (int)entry.api_required_defeat_count\r
87                     : _gaugeCount[map];\r
88                 var count = $"{max - (int)entry.api_defeat_count}/{max}";\r
89                 Text += $"{map / 10}-{map % 10} : 残り {count}\r\n";\r
90             }\r
91         }\r
92 \r
93         public void InspectPracticeEnemyInfo(dynamic json)\r
94         {\r
95             Text = $"[演習情報]\r\n敵艦隊名 : {json.api_deckname}\r\n";\r
96             var ships = json.api_deck.api_ships;\r
97             var s1 = (int)ships[0].api_id != -1 ? (int)ships[0].api_level : 1;\r
98             var s2 = (int)ships[1].api_id != -1 ? (int)ships[1].api_level : 1;\r
99             var exp = PracticeExp.GetExp(s1, s2);\r
100             var bonus = PracticeExp.TrainingCruiserBonus(_shipInfo.Fleets[0].Ships);\r
101             Text += $"獲得経験値 : {(int)(exp * bonus)}\r\nS勝利 : {(int)((int)(exp * 1.2) * bonus)}";\r
102         }\r
103 \r
104         public void InspectMapNext(dynamic json)\r
105         {\r
106             if (json.api_airsearch() && (int)json.api_airsearch.api_result != 0)\r
107             {\r
108                 var item = json.api_itemget;\r
109                 AddItemCount((int)item.api_usemst + 100, (int)item.api_id, (int)item.api_getcount);\r
110                 return;\r
111             }\r
112             if (json.api_itemget())\r
113             {\r
114                 foreach (var item in json.api_itemget)\r
115                     AddItemCount((int)item.api_usemst, (int)item.api_id, (int)item.api_getcount);\r
116             }\r
117             if (json.api_itemget_eo_result())\r
118             {\r
119                 var eo = json.api_itemget_eo_result;\r
120                 AddItemCount((int)eo.api_usemst, (int)eo.api_id, (int)eo.api_getcount);\r
121             }\r
122             if (json.api_itemget_eo_comment())\r
123             {\r
124                 var eo = json.api_itemget_eo_comment;\r
125                 AddItemCount((int)eo.api_usemst, (int)eo.api_id, (int)eo.api_getcount);\r
126             }\r
127             if (json.api_eventmap() && json.api_eventmap.api_itemget())\r
128             {\r
129                 foreach (var item in json.api_eventmap.api_itemget)\r
130                 {\r
131                     var type = (int)item.api_type;\r
132                     type = type == 1 ? 5 :\r
133                         type == 5 ? 6 : type;\r
134                     AddItemCount(type, (int)item.api_id, (int)item.api_value);\r
135                 }\r
136             }\r
137         }\r
138 \r
139         public void InspectMapStart(dynamic json)\r
140         {\r
141             _inSortie = true;\r
142             InspectMapNext(json);\r
143         }\r
144 \r
145         public void InspectBattleResult(dynamic json)\r
146         {\r
147             if (json.api_get_eventitem())\r
148             {\r
149                 foreach (var item in json.api_get_eventitem)\r
150                 {\r
151                     var type = (int)item.api_type;\r
152                     type = type == 1 ? 5 :\r
153                         type == 5 ? 6 : type;\r
154                     var id = (int)item.api_id;\r
155                     AddItemCount(type, id, (int)item.api_value);\r
156                 }\r
157             }\r
158             if (json.api_mapcell_incentive() && (int)json.api_mapcell_incentive == 1)\r
159             {\r
160                 foreach (var type in _items.Keys.Where(type => type > 100).ToArray())\r
161                 {\r
162                     foreach (var id in _items[type])\r
163                         AddItemCount(type - 100, id.Key, id.Value);\r
164                 }\r
165             }\r
166         }\r
167 \r
168         private readonly Dictionary<int, SortedDictionary<int, int>> _items =\r
169             new Dictionary<int, SortedDictionary<int, int>>();\r
170 \r
171         private void AddItemCount(int type, int id, int count)\r
172         {\r
173             if (!_items.ContainsKey(type))\r
174                 _items[type] = new SortedDictionary<int, int>();\r
175             var dict = _items[type];\r
176             if (!dict.ContainsKey(id))\r
177                 dict[id] = 0;\r
178             dict[id] += count;\r
179         }\r
180 \r
181         private string GetName(int type, int id)\r
182         {\r
183             switch (type)\r
184             {\r
185                 case 2:\r
186                     return _shipInfo.GetSpec(id).Name;\r
187                 case 3:\r
188                     return _itemInfo.GetSpecByItemId(id).Name;\r
189                 case 4:\r
190                     return new[] {"燃料", "弾薬", "鋼材", "ボーキサイト", "高速建造材", "高速修復材", "開発資材", "改修資材"}[id - 1];\r
191                 case 5:\r
192                     return _itemInfo.GetUseItemName(id);\r
193                 case 6:\r
194                     return _furniture[id];\r
195                 default:\r
196                     return "";\r
197             }\r
198         }\r
199 \r
200         private string GenerateItemGetText()\r
201         {\r
202             return string.Join("\r\n",\r
203                 new[] {4, 5, 3, 6, 2}.Where(_items.ContainsKey).SelectMany(type =>\r
204                     _items[type].Select(pair => GetName(type, pair.Key) + ": " + pair.Value)));\r
205         }\r
206     }\r
207 }