-// 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;\r
+using System.Collections.Generic;\r
+using System.Xml.Serialization;\r
\r
namespace KancolleSniffer\r
{\r
- public class Achievement\r
+ public class Achievement : IHaveState\r
{\r
- private int _start;\r
private int _current;\r
\r
- public double Value { get { return (_current - _start) / 1428.0; } }\r
+ public int Start { get; set; }\r
+ public int StartOfMonth { get; set; }\r
+ public DateTime LastReset { get; set; }\r
+ public DateTime LastResetOfMonth { get; set; }\r
+\r
+ private const double ExpPerAch = 10000 / 7.0;\r
+ public double Value => (_current - Start) / ExpPerAch;\r
+ public double ValueOfMonth => (_current - StartOfMonth) / ExpPerAch;\r
+\r
+ [XmlIgnore]\r
+ public List<int> ResetHours { private get; set; }\r
+\r
+ [XmlIgnore]\r
+ public bool NeedSave { get; private set; }\r
+\r
+ public Achievement()\r
+ {\r
+ ResetHours = new List<int>();\r
+ }\r
\r
public void InspectBasic(dynamic json)\r
{\r
+ var now = DateTime.Now;\r
+ var today = DateTime.Today;\r
_current = (int)json.api_experience;\r
- if (_start == 0)\r
- _start = _current;\r
+ if (Start == 0)\r
+ Reset(_current);\r
+ if (StartOfMonth == 0)\r
+ ResetMonth(_current);\r
+ foreach (var hour in ResetHours)\r
+ {\r
+ var time = today.AddHours(hour);\r
+ if (now >= time && LastReset < time)\r
+ Reset(_current);\r
+ }\r
+ var limitTime = now.AddDays(1).Month != now.Month // 今日が今月末\r
+ ? today.AddHours(22) // 今日22時\r
+ : today.AddDays(-today.Day).AddHours(22); // 先月末22時\r
+ if (now >= limitTime && LastResetOfMonth < limitTime)\r
+ ResetMonth(_current);\r
}\r
\r
public void Reset()\r
{\r
- _start = _current;\r
+ Reset(_current);\r
+ }\r
+\r
+ private void Reset(int current)\r
+ {\r
+ Start = current;\r
+ LastReset = DateTime.Now;\r
+ NeedSave = true;\r
+ }\r
+\r
+ private void ResetMonth(int current)\r
+ {\r
+ StartOfMonth = current;\r
+ LastResetOfMonth = DateTime.Now;\r
+ NeedSave = true;\r
}\r
\r
public void SaveState(Status status)\r
{\r
- status.ExperiencePoint = _start;\r
+ NeedSave = false;\r
+ status.Achievement = this;\r
}\r
\r
public void LoadState(Status status)\r
{\r
- _start = status.ExperiencePoint;\r
+ var ac = status.Achievement;\r
+ if (ac == null)\r
+ return;\r
+ Start = ac.Start;\r
+ StartOfMonth = ac.StartOfMonth;\r
+ LastReset = ac.LastReset;\r
+ LastResetOfMonth = ac.LastResetOfMonth;\r
}\r
}\r
}
\ No newline at end of file