OSDN Git Service

4月23日に行われたプロトコル変更に対応する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / MissionInfo.cs
1 // Copyright (C) 2013 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\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 MissionInfo\r
23     {\r
24         private readonly Dictionary<int, string> _missionNames = new Dictionary<int, string>();\r
25         private readonly NameAndTimer[] _missions = new NameAndTimer[3];\r
26 \r
27         public MissionInfo()\r
28         {\r
29             for (var i = 0; i < _missions.Length; i++)\r
30                 _missions[i] = new NameAndTimer();\r
31         }\r
32 \r
33         public void InspectMaster(dynamic json)\r
34         {\r
35             foreach (var entry in json)\r
36                 _missionNames[(int)entry.api_id] = (string)entry.api_name;\r
37         }\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                 string name;\r
55                 _missions[id].Name = _missionNames.TryGetValue((int)mission[1], out name) ? name : "不明";\r
56                 _missions[id].Timer.SetEndTime(mission[2]);\r
57             }\r
58         }\r
59 \r
60         public NameAndTimer[] Missions\r
61         {\r
62             get { return _missions; }\r
63         }\r
64     }\r
65 }