1 // Copyright (C) 2014, 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
22 namespace KancolleSniffer
\r
24 public class DockInfo
\r
26 public const int DockCount = 4;
\r
27 private readonly ShipInfo _shipInfo;
\r
28 private readonly MaterialInfo _materialInfo;
\r
29 private readonly int[] _ndoc = new int[DockCount];
\r
30 private readonly RingTimer[] _ndocTimers = new RingTimer[DockCount];
\r
31 private readonly RingTimer[] _kdocTimers = new RingTimer[DockCount];
\r
33 public DockInfo(ShipInfo ship, MaterialInfo material)
\r
36 _materialInfo = material;
\r
37 for (var i = 0; i < _ndocTimers.Length; i++)
\r
38 _ndocTimers[i] = new RingTimer();
\r
39 for (var i = 0; i < _kdocTimers.Length; i++)
\r
40 _kdocTimers[i] = new RingTimer(0);
\r
43 public void InspectNDock(dynamic json)
\r
45 foreach (var entry in json)
\r
47 var id = (int)entry.api_id - 1;
\r
48 _ndocTimers[id].SetEndTime(entry.api_complete_time);
\r
49 var prev = _ndoc[id];
\r
50 _ndoc[id] = (int)entry.api_ship_id;
\r
51 if (prev != 0 && _ndoc[id] == 0) // 修復完了
\r
52 _shipInfo.RepairShip(prev);
\r
56 public void InspectNyukyo(string request)
\r
58 var values = HttpUtility.ParseQueryString(request);
\r
59 var id = int.Parse(values["api_ship_id"]);
\r
61 _shipInfo.GetStatus(id).CalcMaterialsToRepair(out fuel, out steal);
\r
62 _materialInfo.SubMaterial(Material.Fuel, fuel);
\r
63 _materialInfo.SubMaterial(Material.Steal, steal);
\r
64 if (int.Parse(values["api_highspeed"]) == 0)
\r
66 _shipInfo.RepairShip(id);
\r
67 _materialInfo.SubMaterial(Material.Bucket, 1);
\r
70 public void InspectSpeedChange(string request)
\r
72 var values = HttpUtility.ParseQueryString(request);
\r
73 var dock = int.Parse(values["api_ndock_id"]) - 1;
\r
74 _shipInfo.RepairShip(_ndoc[dock]);
\r
76 _ndocTimers[dock].SetEndTime(0);
\r
77 _materialInfo.SubMaterial(Material.Bucket, 1);
\r
80 public NameAndTimer[] NDock
\r
81 => _ndoc.Zip(_ndocTimers,
\r
82 (id, timer) => new NameAndTimer {Name = id == 0 ? "" : _shipInfo.GetStatus(id).Name, Timer = timer}).ToArray();
\r
84 public bool InNDock(int id) => _ndoc.Any(n => n == id); // 空のドックのidは0
\r
86 public void InspectKDock(dynamic json)
\r
88 foreach (var entry in json)
\r
90 var timer = _kdocTimers[(int)entry.api_id - 1];
\r
91 var complete = (double)entry.api_complete_time;
\r
92 if ((int)complete == 0 && (int)entry.api_created_ship_id != 0)
\r
93 timer.SetEndTime(DateTime.Now.AddHours(-1)); // 過去の時刻を設定する
\r
95 timer.SetEndTime(complete);
\r
99 public void InspectCreateShipSpeedChange(string request)
\r
101 var values = HttpUtility.ParseQueryString(request);
\r
102 var dock = int.Parse(values["api_kdock_id"]) - 1;
\r
103 _kdocTimers[dock].SetEndTime(DateTime.Now.AddHours(-1));
\r
106 public RingTimer[] KDock => _kdocTimers;
\r