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 DataLoader.LoadEnemySlot();
\r
31 foreach (var entry in json.api_mst_ship)
\r
33 var shipSpec = _shipSpecs[(int)entry.api_id] = new ShipSpec
\r
35 Id = (int)entry.api_id,
\r
36 SortNo = entry.api_sortno() ? (int)entry.api_sortno : 0,
\r
37 Name = ShipName(entry),
\r
38 FuelMax = entry.api_fuel_max() ? (int)entry.api_fuel_max : 0,
\r
39 BullMax = entry.api_bull_max() ? (int)entry.api_bull_max : 0,
\r
40 SlotNum = (int)entry.api_slot_num,
\r
41 ShipType = (int)entry.api_stype,
\r
42 ShipTypeName = dict[entry.api_stype]
\r
44 if (entry.api_afterlv())
\r
46 shipSpec.Remodel.Level = (int)entry.api_afterlv;
\r
47 shipSpec.Remodel.After = int.Parse(entry.api_aftershipid);
\r
49 shipSpec.MaxEq = entry.api_maxeq()
\r
51 : DataLoader.EnemySlot(shipSpec.Id);
\r
53 _shipSpecs[-1] = new ShipSpec();
\r
54 SetRemodelBaseAndStep();
\r
57 // 深海棲艦の名前にelite/flagshipを付ける
\r
58 private string ShipName(dynamic json)
\r
60 var name = json.api_name;
\r
61 var flagship = json.api_yomi;
\r
62 if ((int)json.api_id <= 1500 || flagship == "-" || flagship == "")
\r
64 return name + "(" + flagship + ")";
\r
67 public ShipSpec GetSpec(int id) => _shipSpecs.TryGetValue(id, out var spec) ? spec : new ShipSpec();
\r
69 private void SetRemodelBaseAndStep()
\r
72 foreach (var spec in _shipSpecs.Values)
\r
74 if (spec.Remodel.After == 0)
\r
76 _shipSpecs[spec.Remodel.After].Remodel.Base = 1;
\r
78 foreach (var spec in _shipSpecs.Values)
\r
80 if (spec.Remodel.Base != 0)
\r
83 var hash = new HashSet<int> {spec.Id};
\r
85 s.Remodel.Base = spec.Id;
\r
86 while (s.Remodel.After != 0)
\r
88 s.Remodel.Step = ++step;
\r
89 if (!hash.Add(s.Remodel.After))
\r
91 s = _shipSpecs[s.Remodel.After];
\r
92 s.Remodel.Base = spec.Id;
\r
100 /// <param name="id"></param>
\r
101 public void InjectSpec(int id) => _shipSpecs[id] = new ShipSpec {Id = id};
\r
104 public class ShipSpec
\r
106 public int Id { get; set; }
\r
107 public int SortNo { get; set; }
\r
108 public string Name { get; set; }
\r
109 public int FuelMax { get; set; }
\r
110 public int BullMax { get; set; }
\r
111 public int SlotNum { get; set; }
\r
112 public int[] MaxEq { get; set; }
\r
113 public int ShipType { get; set; }
\r
114 public string ShipTypeName { get; set; }
\r
115 public RemodelInfo Remodel { get; } = new RemodelInfo();
\r
117 public class RemodelInfo
\r
119 public int Level { get; set; }
\r
120 public int After { get; set; }
\r
121 public int Base { get; set; } // 艦隊晒しページ用
\r
122 public int Step { get; set; } // 同上
\r
129 MaxEq = new int[0];
\r
132 public double RepairWeight
\r
167 public double TransportPoint
\r
176 return Id == 487 ? 10.0 : 2.0; // 鬼怒改二は大発分を加算
\r
197 public bool IsSubmarine => ShipType == 13 || ShipType == 14;
\r
199 public bool IsAircraftCarrier => ShipType == 7 || ShipType == 11 || ShipType == 18;
\r
201 public bool IsAntiSubmarine
\r
224 public bool IsRepairShip => ShipType == 19;
\r