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 void Inspect(dynamic json)
\r
26 var dict = new Dictionary<double, string>();
\r
27 foreach (var entry in json.api_mst_stype)
\r
28 dict[entry.api_id] = entry.api_name;
\r
30 foreach (var entry in json.api_mst_ship)
\r
32 var shipSpec = _shipSpecs[(int)entry.api_id] = new ShipSpec
\r
34 Id = (int)entry.api_id,
\r
35 SortNo = entry.api_sortno() ? (int)entry.api_sortno : 0,
\r
36 Name = ShipName(entry),
\r
37 FuelMax = entry.api_fuel_max() ? (int)entry.api_fuel_max : 0,
\r
38 BullMax = entry.api_bull_max() ? (int)entry.api_bull_max : 0,
\r
39 ShipType = (int)entry.api_stype,
\r
40 ShipTypeName = dict[entry.api_stype]
\r
42 if (entry.api_afterlv())
\r
44 shipSpec.Remodel.Level = (int)entry.api_afterlv;
\r
45 shipSpec.Remodel.After = int.Parse(entry.api_aftershipid);
\r
48 shipSpec.MaxEq = entry.api_maxeq()
\r
50 : MissingData.MaxEq.TryGetValue(shipSpec.Id, out maxEq) ? maxEq : null;
\r
52 _shipSpecs[-1] = new ShipSpec();
\r
53 SetRemodelBaseAndStep();
\r
56 // 深海棲艦の名前にelite/flagshipを付ける
\r
57 private string ShipName(dynamic json)
\r
59 var name = json.api_name;
\r
60 var flagship = json.api_yomi;
\r
61 if ((int)json.api_id <= 500 || flagship == "-" || flagship == "")
\r
63 return name + "(" + flagship + ")";
\r
66 public ShipSpec this[int id] => _shipSpecs[id];
\r
68 private void SetRemodelBaseAndStep()
\r
71 foreach (var spec in _shipSpecs.Values)
\r
73 if (spec.Remodel.After == 0)
\r
75 _shipSpecs[spec.Remodel.After].Remodel.Base = 1;
\r
77 foreach (var spec in _shipSpecs.Values)
\r
79 if (spec.Remodel.Base != 0)
\r
82 var hash = new HashSet<int> {spec.Id};
\r
84 s.Remodel.Base = spec.Id;
\r
85 while (s.Remodel.After != 0)
\r
87 s.Remodel.Step = ++step;
\r
88 if (!hash.Add(s.Remodel.After))
\r
90 s = _shipSpecs[s.Remodel.After];
\r
91 s.Remodel.Base = spec.Id;
\r
97 public class ShipSpec
\r
99 public int Id { get; set; }
\r
100 public int SortNo { get; set; }
\r
101 public string Name { get; set; }
\r
102 public int FuelMax { get; set; }
\r
103 public int BullMax { get; set; }
\r
104 public int[] MaxEq { get; set; }
\r
105 public int ShipType { get; set; }
\r
106 public string ShipTypeName { get; set; }
\r
107 public RemodelInfo Remodel { get; } = new RemodelInfo();
\r
109 public class RemodelInfo
\r
111 public int Level { get; set; }
\r
112 public int After { get; set; }
\r
113 public int Base { get; set; } // 艦隊晒しページ用
\r
114 public int Step { get; set; } // 同上
\r
121 MaxEq = new int[0];
\r
124 public double RepairWeight
\r
157 public double TransportPoint
\r
166 return Id == 487 ? 10.0 : 2.0; // 鬼怒改二は大発分を加算
\r
187 public bool IsSubmarine => ShipType == 13 || ShipType == 14;
\r
189 public bool IsAircraftCarrier => ShipType == 7 || ShipType == 11 || ShipType == 18;
\r
191 public bool IsAntiSubmarine
\r
213 public bool IsRepairShip => ShipType == 19;
\r