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
56 if (!_clearStatus.TryGetValue(map, out stat))
\r
57 _clearStatus.Add(map, stat = new ClearStatus { Map = map});
\r
58 var prev = stat.Cleared;
\r
59 stat.Cleared = (int)entry.api_cleared == 1;
\r
60 if (prev != stat.Cleared)
\r
65 public void InspectMapStart(dynamic json)
\r
67 InspectMapNext(json);
\r
70 public void InspectMapNext(dynamic json)
\r
72 _currentMap = (int)json.api_maparea_id * 10 + (int)json.api_mapinfo_no;
\r
73 if (!json.api_get_eo_rate() || json.api_get_eo_rate == 0)
\r
76 if (!_clearStatus.TryGetValue(_currentMap, out stat))
\r
77 _clearStatus.Add(_currentMap, stat = new ClearStatus{Map = _currentMap});
\r
78 stat.Cleared = true;
\r
79 stat.Rate = (int)json.api_get_eo_rate;
\r
83 public void InspectBattleResult(dynamic json)
\r
85 if (!json.api_get_exmap_rate())
\r
87 var rate = json.api_get_exmap_rate is string
\r
88 ? int.Parse(json.api_get_exmap_rate)
\r
89 : (int)json.api_get_exmap_rate;
\r
93 if (!_clearStatus.TryGetValue(_currentMap, out stat))
\r
94 _clearStatus.Add(_currentMap, stat = new ClearStatus{Map = _currentMap});
\r
95 stat.Cleared = true;
\r
100 public int Achievement => _clearStatus.Values.Where(s => s.Cleared).Sum(s => s.Rate);
\r
102 public void ResetIfNeeded()
\r
104 var now = DateTime.Now;
\r
105 if (_lastReset.Month == now.Month)
\r
108 foreach (var e in _clearStatus.Values)
\r
113 public void ClearClearStatus()
\r
115 _clearStatus.Clear();
\r
118 public void SaveState(Status status)
\r
121 status.ExMapState = new ExMapState
\r
123 ClearStatusList = _clearStatus.Values.ToList(),
\r
124 LastReset = _lastReset
\r
128 public void LoadState(Status status)
\r
130 if (status.ExMapState == null)
\r
132 _lastReset = status.ExMapState.LastReset;
\r
133 foreach (var s in status.ExMapState.ClearStatusList)
\r
134 _clearStatus[s.Map] = s;
\r
137 public class ExMapState
\r
139 public List<ClearStatus> ClearStatusList { get; set; }
\r
140 public DateTime LastReset { get; set; }
\r