1 // Copyright (C) 2018 Kazuhiro Fujieda <fujieda@users.osdn.me>
\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
7 // http://www.apache.org/licenses/LICENSE-2.0
\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
15 using System.Collections.Generic;
\r
17 namespace KancolleSniffer.Model
\r
19 public class ItemMaster
\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
24 public const int EmergencyRepairId = 91;
\r
25 public const int EmergencyRepairSpecId = 10091;
\r
27 public AdditionalData AdditionalData { get; set; }
\r
29 public void InspectMaster(dynamic json)
\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
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
42 Name = (string)entry.api_name,
\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
58 _itemSpecs[-1] = _itemSpecs[0] = new ItemSpec();
\r
59 foreach (var entry in json.api_mst_useitem)
\r
61 var id = (int)entry.api_id;
\r
62 _useItemName[id] = entry.api_name;
\r
64 if (_useItemName.ContainsKey(EmergencyRepairId))
\r
66 _itemSpecs[EmergencyRepairSpecId] = new ItemSpec
\r
69 Id = EmergencyRepairSpecId,
\r
70 Name = _useItemName[EmergencyRepairId]
\r
75 public ItemSpec this[int id]
\r
77 get => _itemSpecs.TryGetValue(id, out var spec) ? spec : new ItemSpec();
\r
78 set => _itemSpecs[id] = value;
\r
81 public string GetUseItemName(int id) => _useItemName.TryGetValue(id, out var name) ? name : "";
\r