-// Copyright (C) 2014 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\r
+// Copyright (C) 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
// \r
-// This program is part of KancolleSniffer.\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
//\r
-// KancolleSniffer is free software: you can redistribute it and/or modify\r
-// it under the terms of the GNU General Public License as published by\r
-// the Free Software Foundation, either version 3 of the License, or\r
-// (at your option) any later version.\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
//\r
-// This program is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-// GNU General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU General Public License\r
-// along with this program; if not, see <http://www.gnu.org/licenses/>.\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
\r
using System.Collections.Generic;\r
\r
{\r
public class ShipMaster\r
{\r
+ public const int NumSlots = 5;\r
private readonly Dictionary<int, ShipSpec> _shipSpecs = new Dictionary<int, ShipSpec>();\r
\r
- public void InspectShip(dynamic json)\r
+ public void Inspect(dynamic json)\r
{\r
- foreach (var entry in json)\r
- _shipSpecs[(int)entry.api_id] = new ShipSpec\r
+ var dict = new Dictionary<double, string>();\r
+ foreach (var entry in json.api_mst_stype)\r
+ dict[entry.api_id] = entry.api_name;\r
+ dict[8] = "高速戦艦";\r
+ foreach (var entry in json.api_mst_ship)\r
+ {\r
+ var shipSpec = _shipSpecs[(int)entry.api_id] = new ShipSpec\r
{\r
- Name = entry.api_name,\r
- FuelMax = (int)entry.api_fuel_max,\r
- BullMax = (int)entry.api_bull_max\r
+ Id = (int)entry.api_id,\r
+ SortNo = entry.api_sortno() ? (int)entry.api_sortno : 0,\r
+ Name = ShipName(entry),\r
+ FuelMax = entry.api_fuel_max() ? (int)entry.api_fuel_max : 0,\r
+ BullMax = entry.api_bull_max() ? (int)entry.api_bull_max : 0,\r
+ ShipType = (int)entry.api_stype,\r
+ ShipTypeName = dict[entry.api_stype]\r
};\r
+ if (entry.api_afterlv())\r
+ {\r
+ shipSpec.Remodel.Level = (int)entry.api_afterlv;\r
+ shipSpec.Remodel.After = int.Parse(entry.api_aftershipid);\r
+ }\r
+ int[] maxEq;\r
+ shipSpec.MaxEq = entry.api_maxeq()\r
+ ? entry.api_maxeq\r
+ : MissingData.MaxEq.TryGetValue(shipSpec.Id, out maxEq) ? maxEq : null;\r
+ }\r
+ _shipSpecs[-1] = new ShipSpec();\r
+ SetRemodelBaseAndStep();\r
}\r
\r
- public ShipSpec GetSpec(int id)\r
+ // 深海棲艦の名前にelite/flagshipを付ける\r
+ private string ShipName(dynamic json)\r
{\r
- ShipSpec spec;\r
- return _shipSpecs.TryGetValue(id, out spec) ? spec : new ShipSpec {Name = "不明"};\r
+ var name = json.api_name;\r
+ var flagship = json.api_yomi;\r
+ if ((int)json.api_id <= 500 || flagship == "-" || flagship == "")\r
+ return name;\r
+ return name + "(" + flagship + ")";\r
+ }\r
+\r
+ public ShipSpec this[int id] => _shipSpecs[id];\r
+\r
+ private void SetRemodelBaseAndStep()\r
+ {\r
+ // 改造後のデータをマーク\r
+ foreach (var spec in _shipSpecs.Values)\r
+ {\r
+ if (spec.Remodel.After == 0)\r
+ continue;\r
+ _shipSpecs[spec.Remodel.After].Remodel.Base = 1;\r
+ }\r
+ foreach (var spec in _shipSpecs.Values)\r
+ {\r
+ if (spec.Remodel.Base != 0)\r
+ continue;\r
+ var step = 0;\r
+ var hash = new HashSet<int> {spec.Id};\r
+ var s = spec;\r
+ s.Remodel.Base = spec.Id;\r
+ while (s.Remodel.After != 0)\r
+ {\r
+ s.Remodel.Step = ++step;\r
+ if (!hash.Add(s.Remodel.After))\r
+ break;\r
+ s = _shipSpecs[s.Remodel.After];\r
+ s.Remodel.Base = spec.Id;\r
+ }\r
+ }\r
}\r
}\r
\r
- public struct ShipSpec\r
+ public class ShipSpec\r
{\r
+ public int Id { get; set; }\r
+ public int SortNo { get; set; }\r
public string Name { get; set; }\r
public int FuelMax { get; set; }\r
public int BullMax { get; set; }\r
+ public int[] MaxEq { get; set; }\r
+ public int ShipType { get; set; }\r
+ public string ShipTypeName { get; set; }\r
+ public RemodelInfo Remodel { get; } = new RemodelInfo();\r
+\r
+ public class RemodelInfo\r
+ {\r
+ public int Level { get; set; }\r
+ public int After { get; set; }\r
+ public int Base { get; set; } // 艦隊晒しページ用\r
+ public int Step { get; set; } // 同上\r
+ }\r
+\r
+ public ShipSpec()\r
+ {\r
+ Id = -1;\r
+ Name = "";\r
+ MaxEq = new int[0];\r
+ }\r
+\r
+ public double RepairWeight\r
+ {\r
+ get\r
+ {\r
+ switch (ShipType)\r
+ {\r
+ case 13: // 潜水艦\r
+ return 0.5;\r
+ case 2: // 駆逐艦\r
+ case 3: // 軽巡洋艦\r
+ case 4: // 重雷装巡洋艦\r
+ case 14: // 潜水空母\r
+ case 16: // 水上機母艦\r
+ case 17: // 揚陸艦\r
+ case 21: // 練習巡洋艦\r
+ return 1.0;\r
+ case 5: // 重巡洋艦\r
+ case 6: // 航空巡洋艦\r
+ case 7: // 軽空母\r
+ case 8: // 高速戦艦\r
+ case 20: // 潜水母艦\r
+ return 1.5;\r
+ case 9: // 低速戦艦\r
+ case 10: // 航空戦艦\r
+ case 11: // 正規空母\r
+ case 18: // 装甲空母\r
+ case 19: // 工作艦\r
+ return 2.0;\r
+ }\r
+ return 1.0;\r
+ }\r
+ }\r
+\r
+ public double TransportPoint\r
+ {\r
+ get\r
+ {\r
+ switch (ShipType)\r
+ {\r
+ case 2:\r
+ return 5.0;\r
+ case 3:\r
+ return Id == 487 ? 10.0 : 2.0; // 鬼怒改二は大発分を加算\r
+ case 6:\r
+ return 4.0;\r
+ case 10:\r
+ return 7.0;\r
+ case 15:\r
+ return 15.0;\r
+ case 16:\r
+ return 9.0;\r
+ case 17:\r
+ return 12.0;\r
+ case 20:\r
+ return 7.0;\r
+ case 21:\r
+ return 6.0;\r
+ default:\r
+ return 0;\r
+ }\r
+ }\r
+ }\r
+\r
+ public bool IsSubmarine => ShipType == 13 || ShipType == 14;\r
+\r
+ public bool IsAircraftCarrier => ShipType == 7 || ShipType == 11 || ShipType == 18;\r
+\r
+ public bool IsAntiSubmarine\r
+ {\r
+ get\r
+ {\r
+ switch (ShipType)\r
+ {\r
+ case 2: // 駆逐\r
+ case 3: // 軽巡\r
+ case 4: // 雷巡\r
+ case 6: // 航巡\r
+ case 7: // 軽空\r
+ case 10: // 航戦\r
+ case 16: // 水母\r
+ case 17: // 揚陸艦\r
+ case 21: // 練巡\r
+ case 22: // 補給艦\r
+ return true;\r
+ }\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public bool IsRepairShip => ShipType == 19;\r
}\r
}
\ No newline at end of file