1 // Copyright (C) 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
19 namespace KancolleSniffer
\r
21 public class ExMapInfo : IHaveState
\r
23 public class ClearStatus
\r
25 public int Map { get; set; }
\r
26 public bool Cleared { get; set; }
\r
27 public int Rate { get; set; }
\r
30 private readonly Dictionary<int, ClearStatus> _clearStatus =
\r
31 new Dictionary<int, ClearStatus>
\r
33 {15, new ClearStatus {Map = 15, Cleared = false, Rate = 75}},
\r
34 {16, new ClearStatus {Map = 16, Cleared = false, Rate = 75}},
\r
35 {25, new ClearStatus {Map = 25, Cleared = false, Rate = 100}},
\r
36 {35, new ClearStatus {Map = 35, Cleared = false, Rate = 150}},
\r
37 {45, new ClearStatus {Map = 45, Cleared = false, Rate = 180}},
\r
38 {55, new ClearStatus {Map = 55, Cleared = false, Rate = 200}}
\r
41 private DateTime _lastReset;
\r
43 private int _currentMap;
\r
45 public bool NeedSave { get; private set; }
\r
47 public void InspectMapInfo(dynamic json)
\r
49 foreach (var entry in json)
\r
51 var map = (int)entry.api_id;
\r
55 if (!_clearStatus.TryGetValue(map, out stat))
\r
56 _clearStatus.Add(map, stat = new ClearStatus { Map = map});
\r
57 var prev = stat.Cleared;
\r
58 stat.Cleared = (int)entry.api_cleared == 1;
\r
59 if (prev != stat.Cleared)
\r
64 public void InspectMapStart(dynamic json)
\r
66 InspectMapNext(json);
\r
69 public void InspectMapNext(dynamic json)
\r
71 _currentMap = (int)json.api_maparea_id * 10 + (int)json.api_mapinfo_no;
\r
72 if (!json.api_get_eo_rate() || json.api_get_eo_rate == 0)
\r
75 if (!_clearStatus.TryGetValue(_currentMap, out stat))
\r
76 _clearStatus.Add(_currentMap, stat = new ClearStatus{Map = _currentMap});
\r
77 stat.Cleared = true;
\r
78 stat.Rate = (int)json.api_get_eo_rate;
\r
82 public void InspectBattleResult(dynamic json)
\r
84 if (!json.api_get_exmap_rate())
\r
86 var rate = json.api_get_exmap_rate is string
\r
87 ? int.Parse(json.api_get_exmap_rate)
\r
88 : (int)json.api_get_exmap_rate;
\r
92 if (!_clearStatus.TryGetValue(_currentMap, out stat))
\r
93 _clearStatus.Add(_currentMap, stat = new ClearStatus{Map = _currentMap});
\r
94 stat.Cleared = true;
\r
99 public int Achievement => _clearStatus.Values.Where(s => s.Cleared).Sum(s => s.Rate);
\r
101 public void ResetIfNeeded()
\r
103 var now = DateTime.Now;
\r
104 if (_lastReset.Month == now.Month)
\r
107 foreach (var e in _clearStatus.Values)
\r
112 public void ClearClearStatus()
\r
114 _clearStatus.Clear();
\r
117 public void SaveState(Status status)
\r
120 status.ExMapState = new ExMapState
\r
122 ClearStatusList = _clearStatus.Values.ToList(),
\r
123 LastReset = _lastReset
\r
127 public void LoadState(Status status)
\r
129 if (status.ExMapState == null)
\r
131 _lastReset = status.ExMapState.LastReset;
\r
132 foreach (var s in status.ExMapState.ClearStatusList)
\r
133 _clearStatus[s.Map] = s;
\r
136 public class ExMapState
\r
138 public List<ClearStatus> ClearStatusList { get; set; }
\r
139 public DateTime LastReset { get; set; }
\r