OSDN Git Service

イベント海域の支援任務名の末尾にSを付ける
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Model / MissionInfo.cs
1 // Copyright (C) 2013, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 // \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
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\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
14 \r
15 using System.Collections.Generic;\r
16 \r
17 namespace KancolleSniffer.Model\r
18 {\r
19     public class MissionInfo\r
20     {\r
21         private readonly Dictionary<int, string> _missionNames = new Dictionary<int, string>();\r
22         private readonly NameAndTimer[] _missions = new NameAndTimer[3];\r
23 \r
24         public MissionInfo()\r
25         {\r
26             for (var i = 0; i < _missions.Length; i++)\r
27                 _missions[i] = new NameAndTimer();\r
28         }\r
29 \r
30         public void InspectMaster(dynamic json)\r
31         {\r
32             foreach (var entry in json)\r
33                 _missionNames[(int)entry.api_id] =\r
34                     (string)entry.api_name + (IsEventMap(entry) ? "S" : "");\r
35         }\r
36 \r
37         private bool IsEventMap(dynamic json) => json.api_disp_no() && json.api_disp_no.StartsWith("S");\r
38 \r
39         public void InspectDeck(dynamic json)\r
40         {\r
41             foreach (var entry in json)\r
42             {\r
43                 var id = (int)entry.api_id;\r
44                 if (id == 1)\r
45                     continue;\r
46                 id -= 2;\r
47                 var mission = entry.api_mission;\r
48                 if (mission[0] == 0)\r
49                 {\r
50                     _missions[id].Name = "";\r
51                     _missions[id].Timer.SetEndTime(0);\r
52                     continue;\r
53                 }\r
54                 _missions[id].Name = _missionNames.TryGetValue((int)mission[1], out var name) ? name : "不明";\r
55                 _missions[id].Timer.SetEndTime(mission[2]);\r
56             }\r
57         }\r
58 \r
59         public NameAndTimer[] Missions => _missions;\r
60     }\r
61 }