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
16 using System.Collections.Generic;
\r
18 namespace KancolleSniffer.Model
\r
20 public class ShipMaster
\r
22 private readonly Dictionary<int, ShipSpec> _shipSpecs = new Dictionary<int, ShipSpec>();
\r
23 public AdditionalData AdditionalData { get; set; }
\r
25 public static bool IsEnemyId(int id) => id > 1500;
\r
27 public void Inspect(dynamic json)
\r
29 var dict = new Dictionary<double, string>();
\r
30 foreach (var entry in json.api_mst_stype)
\r
31 dict[entry.api_id] = entry.api_name;
\r
33 AdditionalData.LoadEnemySlot();
\r
34 AdditionalData.LoadNumEquips();
\r
35 foreach (var entry in json.api_mst_ship)
\r
37 var shipSpec = _shipSpecs[(int)entry.api_id] = new ShipSpec
\r
39 Id = (int)entry.api_id,
\r
40 SortId = entry.api_sort_id() ? (int)entry.api_sort_id : 0,
\r
41 Name = ShipName(entry),
\r
42 Yomi = entry.api_yomi,
\r
43 FuelMax = entry.api_fuel_max() ? (int)entry.api_fuel_max : 0,
\r
44 BullMax = entry.api_bull_max() ? (int)entry.api_bull_max : 0,
\r
45 SlotNum = (int)entry.api_slot_num,
\r
46 ShipType = (int)entry.api_stype,
\r
47 ShipTypeName = dict[entry.api_stype],
\r
48 ShipClass = entry.api_ctype() ? (int)entry.api_ctype : 0
\r
50 if (entry.api_afterlv())
\r
52 shipSpec.Remodel.Level = (int)entry.api_afterlv;
\r
53 shipSpec.Remodel.After = int.Parse(entry.api_aftershipid);
\r
55 shipSpec.GetMaxEq = entry.api_maxeq()
\r
56 ? (Func<int[]>)(() => entry.api_maxeq)
\r
57 : () => AdditionalData.EnemySlot(shipSpec.Id);
\r
58 shipSpec.GetNumEquips = () => AdditionalData.NumEquips(shipSpec.Id);
\r
59 shipSpec.SetNumEquips = num => AdditionalData.RecordNumEquips(shipSpec.Id, shipSpec.Name,num);
\r
61 _shipSpecs[-1] = new ShipSpec();
\r
62 SetRemodelBaseAndStep();
\r
65 // 深海棲艦の名前にelite/flagshipを付ける
\r
66 private string ShipName(dynamic json)
\r
68 var name = json.api_name;
\r
69 var flagship = json.api_yomi;
\r
70 if (!IsEnemyId((int)json.api_id) || flagship == "-" || flagship == "")
\r
72 return name + "(" + flagship + ")";
\r
75 public ShipSpec GetSpec(int id) => _shipSpecs.TryGetValue(id, out var spec) ? spec : new ShipSpec();
\r
77 private void SetRemodelBaseAndStep()
\r
80 foreach (var spec in _shipSpecs.Values)
\r
82 if (spec.Remodel.After == 0)
\r
84 _shipSpecs[spec.Remodel.After].Remodel.Base = 1;
\r
86 foreach (var spec in _shipSpecs.Values)
\r
88 if (spec.Remodel.Base != 0)
\r
91 var hash = new HashSet<int> {spec.Id};
\r
93 s.Remodel.Base = spec.Id;
\r
94 while (s.Remodel.After != 0)
\r
96 s.Remodel.Step = ++step;
\r
97 if (!hash.Add(s.Remodel.After))
\r
99 s = _shipSpecs[s.Remodel.After];
\r
100 s.Remodel.Base = spec.Id;
\r
108 /// <param name="id"></param>
\r
109 public void InjectSpec(int id) => _shipSpecs[id] = new ShipSpec {Id = id};
\r