1 // Copyright (C) 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // This program is part of KancolleSniffer.
\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify
\r
6 // it under the terms of the GNU General Public License as published by
\r
7 // the Free Software Foundation, either version 3 of the License, or
\r
8 // (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.
\r
19 using System.Collections.Generic;
\r
22 namespace KancolleSniffer
\r
24 public class ExMapInfo : IHaveState
\r
26 public class ClearStatus
\r
28 public int Map { get; set; }
\r
29 public bool Cleared { get; set; }
\r
30 public int Rate { get; set; }
\r
33 private readonly Dictionary<int, ClearStatus> _clearStatus =
\r
34 new Dictionary<int, ClearStatus>
\r
36 {15, new ClearStatus {Map = 15, Cleared = false, Rate = 75}},
\r
37 {16, new ClearStatus {Map = 16, Cleared = false, Rate = 75}},
\r
38 {25, new ClearStatus {Map = 25, Cleared = false, Rate = 100}},
\r
39 {35, new ClearStatus {Map = 35, Cleared = false, Rate = 150}},
\r
40 {45, new ClearStatus {Map = 45, Cleared = false, Rate = 180}},
\r
41 {55, new ClearStatus {Map = 55, Cleared = false, Rate = 200}}
\r
44 private DateTime _lastReset;
\r
46 private int _currentMap;
\r
48 public bool NeedSave { get; private set; }
\r
50 public void InspectMapInfo(dynamic json)
\r
52 foreach (var entry in json)
\r
54 var map = (int)entry.api_id;
\r
58 if (!_clearStatus.TryGetValue(map, out stat))
\r
59 _clearStatus.Add(map, stat = new ClearStatus { Map = map});
\r
60 var prev = stat.Cleared;
\r
61 stat.Cleared = (int)entry.api_cleared == 1;
\r
62 if (prev != stat.Cleared)
\r
67 public void InspectMapStart(dynamic json)
\r
69 InspectMapNext(json);
\r
72 public void InspectMapNext(dynamic json)
\r
74 _currentMap = (int)json.api_maparea_id * 10 + (int)json.api_mapinfo_no;
\r
75 if (!json.api_get_eo_rate() || json.api_get_eo_rate == 0)
\r
78 if (!_clearStatus.TryGetValue(_currentMap, out stat))
\r
79 _clearStatus.Add(_currentMap, stat = new ClearStatus{Map = _currentMap});
\r
80 stat.Cleared = true;
\r
81 stat.Rate = (int)json.api_get_eo_rate;
\r
85 public void InspectBattleResult(dynamic json)
\r
87 if (!json.api_get_exmap_rate())
\r
89 var rate = json.api_get_exmap_rate is string
\r
90 ? int.Parse(json.api_get_exmap_rate)
\r
91 : (int)json.api_get_exmap_rate;
\r
95 if (!_clearStatus.TryGetValue(_currentMap, out stat))
\r
96 _clearStatus.Add(_currentMap, stat = new ClearStatus{Map = _currentMap});
\r
97 stat.Cleared = true;
\r
102 public int Achievement => _clearStatus.Values.Where(s => s.Cleared).Sum(s => s.Rate);
\r
104 public void ResetIfNeeded()
\r
106 var now = DateTime.Now;
\r
107 if (_lastReset.Month == now.Month)
\r
110 foreach (var e in _clearStatus.Values)
\r
115 public void ClearClearStatus()
\r
117 _clearStatus.Clear();
\r
120 public void SaveState(Status status)
\r
123 status.ExMapState = new ExMapState
\r
125 ClearStatusList = _clearStatus.Values.ToArray(),
\r
126 LastReset = _lastReset
\r
130 public void LoadState(Status status)
\r
132 if (status.ExMapState == null)
\r
134 _lastReset = status.ExMapState.LastReset;
\r
135 foreach (var s in status.ExMapState.ClearStatusList)
\r
136 _clearStatus[s.Map] = s;
\r
139 public class ExMapState
\r
141 public ClearStatus[] ClearStatusList { get; set; }
\r
142 public DateTime LastReset { get; set; }
\r