1 // Copyright (C) 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>
\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
7 // http://www.apache.org/licenses/LICENSE-2.0
\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
16 using System.Collections.Generic;
\r
17 using System.Xml.Serialization;
\r
19 namespace KancolleSniffer.Model
\r
21 public class Achievement : IHaveState
\r
23 private int _current;
\r
25 public int Start { get; set; }
\r
26 public int StartOfMonth { get; set; }
\r
27 public DateTime LastReset { get; set; }
\r
28 public DateTime LastResetOfMonth { get; set; }
\r
30 private const double ExpPerAch = 10000 / 7.0;
\r
31 public double Value => (_current - Start) / ExpPerAch;
\r
32 public double ValueOfMonth => (_current - StartOfMonth) / ExpPerAch;
\r
35 public List<int> ResetHours { private get; set; }
\r
38 public bool NeedSave { get; private set; }
\r
40 public Achievement()
\r
42 ResetHours = new List<int>();
\r
45 public void InspectBasic(dynamic json)
\r
47 var now = DateTime.Now;
\r
48 var today = DateTime.Today;
\r
49 _current = (int)json.api_experience;
\r
52 if (StartOfMonth == 0)
\r
53 ResetMonth(_current);
\r
54 foreach (var hour in ResetHours)
\r
56 var time = today.AddHours(hour);
\r
57 if (now >= time && LastReset < time)
\r
60 var limitTime = now.AddDays(1).Month != now.Month // 今日が今月末
\r
61 ? today.AddHours(22) // 今日22時
\r
62 : today.AddDays(-today.Day).AddHours(22); // 先月末22時
\r
63 if (now >= limitTime && LastResetOfMonth < limitTime)
\r
64 ResetMonth(_current);
\r
72 private void Reset(int current)
\r
75 LastReset = DateTime.Now;
\r
79 private void ResetMonth(int current)
\r
81 StartOfMonth = current;
\r
82 LastResetOfMonth = DateTime.Now;
\r
86 public void SaveState(Status status)
\r
89 status.Achievement = this;
\r
92 public void LoadState(Status status)
\r
94 var ac = status.Achievement;
\r
98 StartOfMonth = ac.StartOfMonth;
\r
99 LastReset = ac.LastReset;
\r
100 LastResetOfMonth = ac.LastResetOfMonth;
\r