OSDN Git Service

エラーメッセージのword wrapを止める
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / ShipMaster.cs
1 // Copyright (C) 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 // \r
3 // This program is part of KancolleSniffer.\r
4 //\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify\r
6 // it under the terms of the GNU General Public License as published by\r
7 // the Free Software Foundation, either version 3 of the License, or\r
8 // (at your option) any later version.\r
9 //\r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 //\r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.\r
17 \r
18 using System.Collections.Generic;\r
19 \r
20 namespace KancolleSniffer\r
21 {\r
22     public class ShipMaster\r
23     {\r
24         public const int NumSlots = 5;\r
25         private readonly Dictionary<int, ShipSpec> _shipSpecs = new Dictionary<int, ShipSpec>();\r
26 \r
27         public void Inspect(dynamic json)\r
28         {\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
32             dict[8] = "高速戦艦" ;\r
33             foreach (var entry in json.api_mst_ship)\r
34             {\r
35                 var shipSpec = _shipSpecs[(int)entry.api_id] = new ShipSpec\r
36                 {\r
37                     Id = (int)entry.api_id,\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                     ShipType = (int)entry.api_stype,\r
42                     ShipTypeName = dict[entry.api_stype]\r
43                 };\r
44                 int[] maxEq;\r
45                 shipSpec.MaxEq = entry.api_maxeq()\r
46                     ? entry.api_maxeq\r
47                     : MissingData.MaxEq.TryGetValue(shipSpec.Id, out maxEq) ? maxEq : null;\r
48             }\r
49             _shipSpecs[-1] = new ShipSpec();\r
50         }\r
51 \r
52         // 深海棲艦の名前にelite/flagshipを付ける\r
53         private string ShipName(dynamic json)\r
54         {\r
55             var name = json.api_name;\r
56             var flagship = json.api_yomi;\r
57             if ((int)json.api_id <= 500 || flagship == "-" || flagship == "")\r
58                 return name;\r
59             return name + "(" + flagship + ")";\r
60         }\r
61 \r
62         public ShipSpec this[int id] => _shipSpecs[id];\r
63     }\r
64 \r
65     public class ShipSpec\r
66     {\r
67         public int Id { get; set; }\r
68         public string Name { get; set; }\r
69         public int FuelMax { get; set; }\r
70         public int BullMax { get; set; }\r
71         public int[] MaxEq { get; set; }\r
72         public int ShipType { get; set; }\r
73         public string ShipTypeName { get; set; }\r
74 \r
75         public ShipSpec()\r
76         {\r
77             Id = -1;\r
78             Name = "";\r
79             MaxEq = new int[0];\r
80         }\r
81 \r
82         public double RepairWeight\r
83         {\r
84             get\r
85             {\r
86                 switch (ShipType)\r
87                 {\r
88                     case 13: // 潜水艦\r
89                         return 0.5;\r
90                     case 2: // 駆逐艦\r
91                     case 3: // 軽巡洋艦\r
92                     case 4: // 重雷装巡洋艦\r
93                     case 14: // 潜水空母\r
94                     case 16: // 水上機母艦\r
95                     case 17: // 揚陸艦\r
96                     case 21: // 練習巡洋艦\r
97                         return 1.0;\r
98                     case 5: // 重巡洋艦\r
99                     case 6: // 航空巡洋艦\r
100                     case 7: // 軽空母\r
101                     case 8: // 高速戦艦\r
102                     case 20: // 潜水母艦\r
103                         return 1.5;\r
104                     case 9: // 低速戦艦\r
105                     case 10: // 航空戦艦\r
106                     case 11: // 正規空母\r
107                     case 18: // 装甲空母\r
108                     case 19: // 工作艦\r
109                         return 2.0;\r
110                 }\r
111                 return 1.0;\r
112             }\r
113         }\r
114 \r
115         public bool IsSubmarine => ShipType == 13 || ShipType == 14;\r
116 \r
117         public bool IsAircraftCarrier => ShipType == 7 || ShipType == 11 || ShipType == 18;\r
118 \r
119         public bool IsAntiSubmarine\r
120         {\r
121             get\r
122             {\r
123                 switch (ShipType)\r
124                 {\r
125                     case 2: // 駆逐\r
126                     case 3: // 軽巡\r
127                     case 4: // 雷巡\r
128                     case 6: // 航巡\r
129                     case 7: // 軽空\r
130                     case 10: // 航戦\r
131                     case 16: // 水母\r
132                     case 17: // 揚陸艦\r
133                     case 21: // 練巡\r
134                     case 22: // 補給艦\r
135                         return true;\r
136                 }\r
137                 return false;\r
138             }\r
139         }\r
140     }\r
141 }