1 // Copyright (C) 2016 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
15 using System.Collections.Generic;
\r
17 using static System.Math;
\r
19 namespace KancolleSniffer
\r
21 public class BaseAirCoprs
\r
23 private readonly ItemInfo _itemInfo;
\r
24 private List<int> _relocationgPlanes;
\r
26 public BaseAirCoprs(ItemInfo item)
\r
31 public AirCorpsInfo[] AirCorps { get; set; }
\r
33 public class AirCorpsInfo
\r
35 public int Distance { get; set; }
\r
36 public int Action { get; set; }
\r
37 public PlaneInfo[] Planes { get; set; }
\r
39 public string ActionName
\r
61 public int[] FighterPower => Planes.Aggregate(new[] {0, 0}, (prev, plane) =>
\r
63 if (plane.State != 1)
\r
65 var slot = plane.Slot;
\r
66 var unskilled = (slot.Spec.AntiAir + slot.Spec.Interception * 1.5 + slot.FighterPowerLevelBonus) *
\r
70 prev[0] + (int)(unskilled + slot.AlvBonus[0]),
\r
71 prev[1] + (int)(unskilled + slot.AlvBonus[1])
\r
76 public class PlaneInfo
\r
78 public int State { get; set; }
\r
79 public ItemStatus Slot { get; set; }
\r
80 public int Count { get; set; }
\r
81 public int MaxCount { get; set; }
\r
83 public string StateName
\r
102 public void Inspect(dynamic json)
\r
104 AirCorps = (from entry in (dynamic[])json
\r
108 Distance = (int)entry.api_distance,
\r
109 Action = (int)entry.api_action_kind,
\r
110 Planes = (from plane in (dynamic[])entry.api_plane_info
\r
111 select new PlaneInfo
\r
113 Slot = _itemInfo.GetStatus((int)plane.api_slotid),
\r
114 State = (int)plane.api_state,
\r
115 Count = plane.api_count() ? (int)plane.api_count : 0,
\r
116 MaxCount = plane.api_max_count() ? (int)plane.api_max_count : 0,
\r
121 public void InspectSetPlane(string request, dynamic json)
\r
123 if (AirCorps == null)
\r
125 var values = HttpUtility.ParseQueryString(request);
\r
126 var airCorps = AirCorps[int.Parse(values["api_base_id"]) - 1];
\r
127 if (json.api_distance()) // 2016春イベにはない
\r
128 airCorps.Distance = (int)json.api_distance;
\r
129 foreach (var planeInfo in json.api_plane_info)
\r
131 var planeId = (int)planeInfo.api_squadron_id - 1;
\r
132 var prev = airCorps.Planes[planeId];
\r
133 if (prev.Slot.Id != -1)
\r
134 _relocationgPlanes.Add(prev.Slot.Id);
\r
135 airCorps.Planes[planeId] = new PlaneInfo
\r
137 Slot = _itemInfo.GetStatus((int)planeInfo.api_slotid),
\r
138 State = (int)planeInfo.api_state,
\r
139 Count = planeInfo.api_count() ? (int)planeInfo.api_count : 0,
\r
140 MaxCount = planeInfo.api_max_count() ? (int)planeInfo.api_max_count : 0,
\r
145 public void InspectSupply(string request, dynamic json)
\r
147 InspectSetPlane(request, json);
\r
150 public void InspectSetAction(string request)
\r
152 if (AirCorps == null)
\r
154 var values = HttpUtility.ParseQueryString(request);
\r
155 foreach (var entry in
\r
156 values["api_base_id"].Split(',')
\r
157 .Zip(values["api_action_kind"].Split(','), (b, a) => new {baseId = b, action = a}))
\r
159 AirCorps[int.Parse(entry.baseId) - 1].Action = int.Parse(entry.action);
\r
163 public void InspectEventObject(dynamic json)
\r
165 _relocationgPlanes = json.api_base_convert_slot()
\r
166 ? new List<int>((int[])json.api_base_convert_slot)
\r
170 public void SetItemHolder()
\r
172 if (AirCorps == null)
\r
174 var name = new[] {"第一", "第二", "第三"};
\r
176 foreach (var airCorps in AirCorps)
\r
178 if (i >= name.Length)
\r
180 var ship = new ShipStatus {Id = 1000 + i, Spec = new ShipSpec {Name = name[i++] + "基地航空隊"}};
\r
181 foreach (var plane in airCorps.Planes)
\r
183 if (plane.State != 1)
\r
185 _itemInfo.GetStatus(plane.Slot.Id).Holder = ship;
\r
188 var relocating = new ShipStatus {Id = 1500, Spec = new ShipSpec {Name = "配置転換中"}};
\r
189 foreach (var id in _relocationgPlanes)
\r
190 _itemInfo.GetStatus(id).Holder = relocating;
\r