1 // Copyright (C) 2013, 2014 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>
\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 ItemSpec
\r
28 public string TypeName;
\r
37 public bool CanAirCombat()
\r
50 // http://ch.nicovideo.jp/biikame/blomaga/ar663428
\r
51 public double LoSScaleFactor()
\r
76 public class ItemStatus
\r
78 public ItemSpec Spec { get; set; }
\r
79 public int Level { get; set; }
\r
83 Spec = new ItemSpec();
\r
87 public class ItemInfo
\r
89 private int _nowShips, _nowEquips;
\r
90 private readonly Dictionary<int, ItemSpec> _itemSpecs = new Dictionary<int, ItemSpec>();
\r
91 private readonly Dictionary<int, ItemStatus> _itemInfo = new Dictionary<int, ItemStatus>();
\r
93 public int MaxShips { get; private set; }
\r
94 public int MarginShips { get; set; }
\r
95 public bool RingShips { get; set; }
\r
96 public int MaxEquips { get; private set; }
\r
97 public int MarginEquips { get; set; }
\r
98 public bool RingEquips { get; set; }
\r
99 public MaterialCount[] MaterialHistory { get; private set; }
\r
101 public int NowShips
\r
103 get { return _nowShips; }
\r
108 var limit = MaxShips - MarginShips;
\r
109 RingShips = _nowShips < limit && value >= limit;
\r
115 public bool TooManyShips
\r
117 get { return MaxShips != 0 && NowShips >= MaxShips - MarginShips; }
\r
120 public int NowEquips
\r
122 get { return _nowEquips; }
\r
125 if (MaxEquips != 0)
\r
127 var limit = MaxEquips - MarginEquips;
\r
128 RingEquips = _nowEquips < limit && value >= limit;
\r
130 _nowEquips = value;
\r
134 public bool TooManyEquips
\r
136 get { return MaxEquips != 0 && NowEquips >= MaxEquips - MarginEquips; }
\r
141 MaterialHistory = new MaterialCount[Enum.GetValues(typeof (Material)).Length];
\r
142 foreach (Material m in Enum.GetValues(typeof (Material)))
\r
143 MaterialHistory[(int)m] = new MaterialCount();
\r
148 public void InspectBasic(dynamic json)
\r
150 MaxShips = (int)json.api_max_chara;
\r
151 MaxEquips = (int)json.api_max_slotitem;
\r
154 public void InspectMaterial(dynamic json)
\r
156 foreach (var entry in json)
\r
157 MaterialHistory[(int)entry.api_id - 1].Now = (int)entry.api_value;
\r
160 public void InspectMaster(dynamic json)
\r
162 var dict = new Dictionary<int, string>();
\r
163 foreach (var entry in json.api_mst_slotitem_equiptype)
\r
164 dict[(int)entry.api_id] = entry.api_name;
\r
165 foreach (var entry in json.api_mst_slotitem)
\r
167 _itemSpecs[(int)entry.api_id] = new ItemSpec
\r
169 Name = (string)entry.api_name,
\r
170 Type = (int)entry.api_type[2],
\r
171 TypeName = dict[(int)entry.api_type[2]],
\r
172 AntiAir = (int)entry.api_tyku,
\r
173 LoS = (int)entry.api_saku
\r
176 _itemSpecs[-1] = new ItemSpec();
\r
179 public void InspectSlotItem(dynamic json, bool full = false)
\r
182 json = new[] {json};
\r
186 _itemInfo[-1] = new ItemStatus();
\r
188 foreach (var entry in json)
\r
190 _itemInfo[(int)entry.api_id] = new ItemStatus
\r
192 Spec = _itemSpecs[(int)entry.api_slotitem_id],
\r
193 Level = entry.api_level() ? (int)entry.api_level : 0
\r
196 NowEquips = _itemInfo.Count - 1;
\r
199 public void InspectCreateItem(dynamic json)
\r
201 var m = (dynamic[])json.api_material;
\r
202 for (var i = 0; i < m.Length; i++)
\r
203 MaterialHistory[i].Now = (int)m[i];
\r
204 if (!json.IsDefined("api_slot_item"))
\r
206 InspectSlotItem(json.api_slot_item);
\r
210 public void InspectGetShip(dynamic json)
\r
213 if (json.api_slotitem == null) // まるゆにはスロットがない
\r
215 InspectSlotItem(json.api_slotitem);
\r
216 NowEquips += ((object[])json.api_slotitem).Length;
\r
219 public void InspectDestroyItem(string request, dynamic json)
\r
221 var values = HttpUtility.ParseQueryString(request);
\r
222 NowEquips -= values["api_slotitem_ids"].Split(',').Length;
\r
223 var get = (int[])json.api_get_material;
\r
224 for (var i = 0; i < get.Length; i++)
\r
225 MaterialHistory[i].Now += get[i];
\r
228 public void InspectRemodelSlot(dynamic json)
\r
230 if (!json.api_use_slot_id())
\r
232 NowEquips -= ((object[])json.api_use_slot_id).Length;
\r
235 public void InspectMissionResult(dynamic json)
\r
237 if ((int)json.api_clear_result == 0) // 失敗
\r
239 var get = (int[])json.api_get_material;
\r
240 for (var i = 0; i < get.Length; i++)
\r
241 MaterialHistory[i].Now += get[i];
\r
244 public ItemSpec this[int id]
\r
246 get { return GetSpecById(id); }
\r
249 public ItemSpec GetSpecById(int id)
\r
251 return _itemInfo[id].Spec;
\r
254 public ItemSpec GetSpecByItemId(int id)
\r
256 return _itemSpecs[id];
\r
259 public void SaveState(Status status)
\r
261 status.MatreialHistory = MaterialHistory;
\r
264 public void LoadSate(Status status)
\r
266 if (status.MatreialHistory != null)
\r
267 status.MatreialHistory.CopyTo(MaterialHistory, 0);
\r
271 public enum Material
\r
283 public class MaterialCount
\r
287 public int BegOfDay { get; set; }
\r
288 public int BegOfWeek { get; set; }
\r
289 public DateTime LastSet { get; set; }
\r
293 get { return _now; }
\r
296 if (!Status.Restoring) // JSONから値を復旧するときは履歴に触らない
\r
298 UpdateHistory(value, _now);
\r
299 LastSet = DateTime.Now;
\r
305 private void UpdateHistory(int now, int prev)
\r
307 if (LastSet == DateTime.MinValue)
\r
309 BegOfDay = BegOfWeek = now;
\r
312 var morning = DateTime.Today.AddHours(5);
\r
313 var dow = (int)morning.DayOfWeek;
\r
314 var monday = morning.AddDays(dow == 0 ? -6 : -dow + 1);
\r
315 if (DateTime.Now >= morning && LastSet < morning)
\r
317 if (DateTime.Now >= monday && LastSet < monday)
\r