1 // Copyright (C) 2014, 2015 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
\r
19 public class ShipMaster
\r
21 public const int NumSlots = 5;
\r
22 private readonly Dictionary<int, ShipSpec> _shipSpecs = new Dictionary<int, ShipSpec>();
\r
24 public bool UseOldEnemyId { get; set; }
\r
26 public void Inspect(dynamic json)
\r
28 var dict = new Dictionary<double, string>();
\r
29 foreach (var entry in json.api_mst_stype)
\r
30 dict[entry.api_id] = entry.api_name;
\r
32 foreach (var entry in json.api_mst_ship)
\r
34 var shipSpec = _shipSpecs[(int)entry.api_id] = new ShipSpec
\r
36 Id = (int)entry.api_id,
\r
37 SortNo = entry.api_sortno() ? (int)entry.api_sortno : 0,
\r
38 Name = ShipName(entry),
\r
39 FuelMax = entry.api_fuel_max() ? (int)entry.api_fuel_max : 0,
\r
40 BullMax = entry.api_bull_max() ? (int)entry.api_bull_max : 0,
\r
41 SlotNum = (int)entry.api_slot_num,
\r
42 ShipType = (int)entry.api_stype,
\r
43 ShipTypeName = dict[entry.api_stype]
\r
45 if (entry.api_afterlv())
\r
47 shipSpec.Remodel.Level = (int)entry.api_afterlv;
\r
48 shipSpec.Remodel.After = int.Parse(entry.api_aftershipid);
\r
50 shipSpec.MaxEq = entry.api_maxeq()
\r
52 : MissingData.MaxEq.TryGetValue(shipSpec.Id + (UseOldEnemyId ? 1000 : 0), out var maxEq)
\r
56 _shipSpecs[-1] = new ShipSpec();
\r
57 SetRemodelBaseAndStep();
\r
60 // 深海棲艦の名前にelite/flagshipを付ける
\r
61 private string ShipName(dynamic json)
\r
63 var name = json.api_name;
\r
64 var flagship = json.api_yomi;
\r
65 if ((int)json.api_id <= (UseOldEnemyId ? 500 : 1500) || flagship == "-" || flagship == "")
\r
67 return name + "(" + flagship + ")";
\r
70 public ShipSpec GetSpec(int id) => _shipSpecs.TryGetValue(id, out var spec) ? spec : new ShipSpec();
\r
72 private void SetRemodelBaseAndStep()
\r
75 foreach (var spec in _shipSpecs.Values)
\r
77 if (spec.Remodel.After == 0)
\r
79 _shipSpecs[spec.Remodel.After].Remodel.Base = 1;
\r
81 foreach (var spec in _shipSpecs.Values)
\r
83 if (spec.Remodel.Base != 0)
\r
86 var hash = new HashSet<int> {spec.Id};
\r
88 s.Remodel.Base = spec.Id;
\r
89 while (s.Remodel.After != 0)
\r
91 s.Remodel.Step = ++step;
\r
92 if (!hash.Add(s.Remodel.After))
\r
94 s = _shipSpecs[s.Remodel.After];
\r
95 s.Remodel.Base = spec.Id;
\r
103 /// <param name="id"></param>
\r
104 public void InjectSpec(int id) => _shipSpecs[id] = new ShipSpec {Id = id};
\r
107 public class ShipSpec
\r
109 public int Id { get; set; }
\r
110 public int SortNo { get; set; }
\r
111 public string Name { get; set; }
\r
112 public int FuelMax { get; set; }
\r
113 public int BullMax { get; set; }
\r
114 public int SlotNum { get; set; }
\r
115 public int[] MaxEq { get; set; }
\r
116 public int ShipType { get; set; }
\r
117 public string ShipTypeName { get; set; }
\r
118 public RemodelInfo Remodel { get; } = new RemodelInfo();
\r
120 public class RemodelInfo
\r
122 public int Level { get; set; }
\r
123 public int After { get; set; }
\r
124 public int Base { get; set; } // 艦隊晒しページ用
\r
125 public int Step { get; set; } // 同上
\r
132 MaxEq = new int[0];
\r
135 public double RepairWeight
\r
169 public double TransportPoint
\r
178 return Id == 487 ? 10.0 : 2.0; // 鬼怒改二は大発分を加算
\r
199 public bool IsSubmarine => ShipType == 13 || ShipType == 14;
\r
201 public bool IsAircraftCarrier => ShipType == 7 || ShipType == 11 || ShipType == 18;
\r
203 public bool IsAntiSubmarine
\r
226 public bool IsRepairShip => ShipType == 19;
\r