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
16 using static System.Math;
\r
18 namespace KancolleSniffer
\r
20 public class BaseAirCoprs
\r
22 private readonly ItemInfo _itemInfo;
\r
24 public BaseAirCoprs(ItemInfo item)
\r
29 public AirCorpsInfo[] AirCorps { get; set; }
\r
31 public class AirCorpsInfo
\r
33 public int Distance { get; set; }
\r
34 public int Action { get; set; }
\r
35 public PlaneInfo[] Planes { get; set; }
\r
37 public string ActionName
\r
59 public int[] FighterPower => Planes.Aggregate(new[] {0, 0}, (prev, plane) =>
\r
61 if (plane.State != 1)
\r
63 var slot = plane.Slot;
\r
64 var unskilled = (slot.Spec.AntiAir + slot.Spec.Interception * 1.5 + slot.FighterPowerLevelBonus) *
\r
68 prev[0] + (int)(unskilled + slot.AlvBonus[0]),
\r
69 prev[1] + (int)(unskilled + slot.AlvBonus[1])
\r
74 public class PlaneInfo
\r
76 public int State { get; set; }
\r
77 public ItemStatus Slot { get; set; }
\r
78 public int Count { get; set; }
\r
79 public int MaxCount { get; set; }
\r
81 public string StateName
\r
100 public void Inspect(dynamic json)
\r
102 AirCorps = (from entry in (dynamic[])json
\r
106 Distance = (int)entry.api_distance,
\r
107 Action = (int)entry.api_action_kind,
\r
108 Planes = (from plane in (dynamic[])entry.api_plane_info
\r
109 select new PlaneInfo
\r
111 Slot = _itemInfo.GetStatus((int)plane.api_slotid),
\r
112 State = (int)plane.api_state,
\r
113 Count = plane.api_count() ? (int)plane.api_count : 0,
\r
114 MaxCount = plane.api_max_count() ? (int)plane.api_max_count : 0,
\r
119 public void InspectSetPlane(string request, dynamic json)
\r
121 if (AirCorps == null)
\r
123 var values = HttpUtility.ParseQueryString(request);
\r
124 var planeInfo = json.api_plane_info[0];
\r
125 var airCorps = AirCorps[int.Parse(values["api_base_id"]) - 1];
\r
126 airCorps.Distance = (int)json.api_distance;
\r
127 airCorps.Planes[(int)planeInfo.api_squadron_id - 1] = new PlaneInfo
\r
129 Slot = _itemInfo.GetStatus((int)planeInfo.api_slotid),
\r
130 State = (int)planeInfo.api_state,
\r
131 Count = planeInfo.api_count() ? (int)planeInfo.api_count : 0,
\r
132 MaxCount = planeInfo.api_max_count() ? (int)planeInfo.api_max_count : 0,
\r
136 public void InspectSetAction(string request)
\r
138 if (AirCorps == null)
\r
140 var values = HttpUtility.ParseQueryString(request);
\r
141 foreach (var entry in
\r
142 values["api_base_id"].Split(',')
\r
143 .Zip(values["api_action_kind"].Split(','), (b, a) => new {baseId = b, action = a}))
\r
145 AirCorps[int.Parse(entry.baseId) - 1].Action = int.Parse(entry.action);
\r