OSDN Git Service

戦果を集計時間(2時と14時)にリセットできるようにする
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Achievement.cs
1 // Copyright (C) 2014 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;\r
19 using System.Collections.Generic;\r
20 \r
21 namespace KancolleSniffer\r
22 {\r
23     public class Achievement\r
24     {\r
25         private int _start;\r
26         private int _current;\r
27         private DateTime _lastReset;\r
28 \r
29         public double Value { get { return (_current - _start) / 1428.0; } }\r
30         public List<int> ResetHours { get; set; }\r
31 \r
32         public void InspectBasic(dynamic json)\r
33         {\r
34             _current = (int)json.api_experience;\r
35             if (_start == 0)\r
36                 Reset(_current);\r
37             foreach (var hour in ResetHours)\r
38             {\r
39                 var time = DateTime.Today.AddHours(hour);\r
40                 if (DateTime.Now >= time && _lastReset < time)\r
41                     Reset(_current);\r
42             }\r
43         }\r
44 \r
45         public void Reset()\r
46         {\r
47             Reset(_current);\r
48         }\r
49 \r
50         private void Reset(int current)\r
51         {\r
52             _start = current;\r
53             _lastReset = DateTime.Now;\r
54         }\r
55 \r
56         public void SaveState(Status status)\r
57         {\r
58             status.ExperiencePoint = _start;\r
59             status.LastResetTime = _lastReset;\r
60         }\r
61 \r
62         public void LoadState(Status status)\r
63         {\r
64             _start = status.ExperiencePoint;\r
65             _lastReset = status.LastResetTime;\r
66             if (_lastReset == DateTime.MinValue)\r
67                 _lastReset = DateTime.Now;\r
68         }\r
69     }\r
70 }