1 // Copyright (C) 2019 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 System.Collections.Generic;
\r
18 namespace KancolleSniffer.Model
\r
20 public class AirBattleResult
\r
22 public List<AirBattleRecord> Result { get; } = new List<AirBattleRecord>();
\r
24 private readonly Func<int, string> _getShipName;
\r
25 private readonly Func<int[], string[]> _getItemNames;
\r
27 public AirBattleResult(Func<int, string> getShipName, Func<int[], string[]> getItemNames)
\r
29 _getShipName = getShipName;
\r
30 _getItemNames = getItemNames;
\r
33 public class AirBattleRecord
\r
35 public string PhaseName { get; set; }
\r
36 public int AirControlLevel { get; set; }
\r
37 public StageResult Stage1 { get; set; }
\r
38 public StageResult Stage2 { get; set; }
\r
39 public AirFireResult AirFire { get; set; }
\r
47 public class StageResult
\r
49 public int FriendCount { get; set; }
\r
50 public int FriendLost { get; set; }
\r
51 public int EnemyCount { get; set; }
\r
52 public int EnemyLost { get; set; }
\r
55 public class AirFireResult
\r
57 public string ShipName { get; set; }
\r
58 public int Kind { get; set; }
\r
59 public string[] Items { get; set; }
\r
62 public void Add(dynamic json, string phaseName)
\r
64 var stage1 = json.api_stage1;
\r
65 if (stage1 == null || (stage1.api_f_count == 0 && stage1.api_e_count == 0))
\r
67 var result = new AirBattleRecord
\r
69 PhaseName = phaseName,
\r
70 AirControlLevel = json.api_stage1.api_disp_seiku() ? (int)json.api_stage1.api_disp_seiku : 0,
\r
71 Stage1 = CreateStageResult(json.api_stage1),
\r
72 Stage2 = json.api_stage2 == null
\r
74 : CreateStageResult(json.api_stage2),
\r
75 AirFire = CreateAirFireResult(json)
\r
80 private StageResult CreateStageResult(dynamic stage)
\r
82 return new StageResult
\r
84 FriendCount = (int)stage.api_f_count,
\r
85 FriendLost = (int)stage.api_f_lostcount,
\r
86 EnemyCount = (int)stage.api_e_count,
\r
87 EnemyLost = (int)stage.api_e_lostcount
\r
91 private AirFireResult CreateAirFireResult(dynamic json)
\r
93 if (json.api_stage2 == null || !json.api_stage2.api_air_fire())
\r
95 var airFire = json.api_stage2.api_air_fire;
\r
96 var idx = (int)airFire.api_idx;
\r
97 return new AirFireResult
\r
99 ShipName = _getShipName(idx),
\r
100 Kind = (int)airFire.api_kind,
\r
101 Items = _getItemNames((int[])airFire.api_use_items)
\r