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
39 {65, new ClearStatus {Map = 65, Cleared = false, Rate = 250}}
\r
42 private DateTime _lastReset;
\r
44 private int _currentMap;
\r
46 public bool NeedSave { get; private set; }
\r
48 public void InspectMapInfo(dynamic json)
\r
50 foreach (var entry in json.api_map_info() ? json.api_map_info : json)
\r
52 var map = (int)entry.api_id;
\r
55 if (!_clearStatus.TryGetValue(map, out var stat))
\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
74 if (!_clearStatus.TryGetValue(_currentMap, out var stat))
\r
75 _clearStatus.Add(_currentMap, stat = new ClearStatus {Map = _currentMap});
\r
76 stat.Cleared = true;
\r
77 stat.Rate = (int)json.api_get_eo_rate;
\r
81 public void InspectBattleResult(dynamic json)
\r
83 if (!json.api_get_exmap_rate())
\r
85 var rate = json.api_get_exmap_rate is string
\r
86 ? int.Parse(json.api_get_exmap_rate)
\r
87 : (int)json.api_get_exmap_rate;
\r
90 if (!_clearStatus.TryGetValue(_currentMap, out var stat))
\r
91 _clearStatus.Add(_currentMap, stat = new ClearStatus {Map = _currentMap});
\r
92 stat.Cleared = true;
\r
97 public int Achievement => _clearStatus.Values.Where(s => s.Cleared).Sum(s => s.Rate);
\r
99 public void ResetIfNeeded()
\r
101 var now = DateTime.Now;
\r
102 if (_lastReset.Month == now.Month)
\r
105 foreach (var e in _clearStatus.Values)
\r
110 public void ClearClearStatus()
\r
112 _clearStatus.Clear();
\r
115 public void SaveState(Status status)
\r
118 status.ExMapState = new ExMapState
\r
120 ClearStatusList = _clearStatus.Values.ToList(),
\r
121 LastReset = _lastReset
\r
125 public void LoadState(Status status)
\r
127 if (status.ExMapState == null)
\r
129 _lastReset = status.ExMapState.LastReset;
\r
130 foreach (var s in status.ExMapState.ClearStatusList)
\r
134 _clearStatus[s.Map] = s;
\r
138 public class ExMapState
\r
140 public List<ClearStatus> ClearStatusList { get; set; }
\r
141 public DateTime LastReset { get; set; }
\r