OSDN Git Service

装備一覧が何も変化がなくても更新されるのを直す
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Model / ItemMaster.cs
1 // Copyright (C) 2018 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 \r
17 namespace KancolleSniffer.Model\r
18 {\r
19     public class ItemMaster\r
20     {\r
21         private readonly Dictionary<int, ItemSpec> _itemSpecs = new Dictionary<int, ItemSpec>();\r
22         private readonly Dictionary<int, string> _useItemName = new Dictionary<int, string>();\r
23 \r
24         public const int EmergencyRepairId = 91;\r
25         public const int EmergencyRepairSpecId = 10091;\r
26 \r
27         public AdditionalData AdditionalData { get; set; }\r
28 \r
29         public void InspectMaster(dynamic json)\r
30         {\r
31             var dict = new Dictionary<int, string>();\r
32             foreach (var entry in json.api_mst_slotitem_equiptype)\r
33                 dict[(int)entry.api_id] = entry.api_name;\r
34             AdditionalData.LoadTpSpec();\r
35             foreach (var entry in json.api_mst_slotitem)\r
36             {\r
37                 var type = (int)entry.api_type[2];\r
38                 var id = (int)entry.api_id;\r
39                 _itemSpecs[(int)entry.api_id] = new ItemSpec\r
40                 {\r
41                     Id = id,\r
42                     Name = (string)entry.api_name,\r
43                     Type = type,\r
44                     TypeName = dict.TryGetValue(type, out var typeName) ? typeName : "不明",\r
45                     IconType = (int)entry.api_type[3],\r
46                     Firepower = (int)entry.api_houg,\r
47                     AntiAir = (int)entry.api_tyku,\r
48                     LoS = (int)entry.api_saku,\r
49                     AntiSubmarine = (int)entry.api_tais,\r
50                     Torpedo = (int)entry.api_raig,\r
51                     Bomber = (int)entry.api_baku,\r
52                     Interception = type == 48 ? (int)entry.api_houk : 0, // 局地戦闘機は回避の値が迎撃\r
53                     AntiBomber = type == 48 ? (int)entry.api_houm : 0, // 〃命中の値が対爆\r
54                     Distance = entry.api_distance() ? (int)entry.api_distance : 0,\r
55                     GetItemTp = () => AdditionalData.ItemTp(id)\r
56                 };\r
57             }\r
58             _itemSpecs[-1] = _itemSpecs[0] = new ItemSpec();\r
59             foreach (var entry in json.api_mst_useitem)\r
60             {\r
61                 var id = (int)entry.api_id;\r
62                 _useItemName[id] = entry.api_name;\r
63             }\r
64             if (_useItemName.ContainsKey(EmergencyRepairId))\r
65             {\r
66                 _itemSpecs[EmergencyRepairSpecId] = new ItemSpec\r
67                 {\r
68                     Type = 31,\r
69                     Id = EmergencyRepairSpecId,\r
70                     Name = _useItemName[EmergencyRepairId]\r
71                 };\r
72             }\r
73         }\r
74 \r
75         public ItemSpec this[int id]\r
76         {\r
77             get => _itemSpecs.TryGetValue(id, out var spec) ? spec : new ItemSpec();\r
78             set => _itemSpecs[id] = value;\r
79         }\r
80 \r
81         public string GetUseItemName(int id) => _useItemName.TryGetValue(id, out var name) ? name : "";\r
82     }\r
83 }