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 bool _updated;
\r
25 private readonly Func<int, string> _getShipName;
\r
26 private readonly Func<int[], string[]> _getItemNames;
\r
28 public AirBattleResult(Func<int, string> getShipName, Func<int[], string[]> getItemNames)
\r
30 _getShipName = getShipName;
\r
31 _getItemNames = getItemNames;
\r
34 public class AirBattleRecord
\r
36 public string PhaseName { get; set; }
\r
37 public int AirControlLevel { get; set; }
\r
38 public StageResult Stage1 { get; set; }
\r
39 public StageResult Stage2 { get; set; }
\r
40 public AirFireResult AirFire { get; set; }
\r
43 public bool CheckUpdate()
\r
57 public class StageResult
\r
59 public int FriendCount { get; set; }
\r
60 public int FriendLost { get; set; }
\r
61 public int EnemyCount { get; set; }
\r
62 public int EnemyLost { get; set; }
\r
65 public class AirFireResult
\r
67 public string ShipName { get; set; }
\r
68 public int Kind { get; set; }
\r
69 public string[] Items { get; set; }
\r
72 public void Add(dynamic json, string phaseName)
\r
74 var stage1 = json.api_stage1;
\r
75 if (stage1 == null || (stage1.api_f_count == 0 && stage1.api_e_count == 0))
\r
77 var result = new AirBattleRecord
\r
79 PhaseName = phaseName,
\r
80 AirControlLevel = json.api_stage1.api_disp_seiku() ? (int)json.api_stage1.api_disp_seiku : 0,
\r
81 Stage1 = CreateStageResult(json.api_stage1),
\r
82 Stage2 = json.api_stage2 == null
\r
84 : CreateStageResult(json.api_stage2),
\r
85 AirFire = CreateAirFireResult(json)
\r
90 private StageResult CreateStageResult(dynamic stage)
\r
92 return new StageResult
\r
94 FriendCount = (int)stage.api_f_count,
\r
95 FriendLost = (int)stage.api_f_lostcount,
\r
96 EnemyCount = (int)stage.api_e_count,
\r
97 EnemyLost = (int)stage.api_e_lostcount
\r
101 private AirFireResult CreateAirFireResult(dynamic json)
\r
103 if (json.api_stage2 == null || !json.api_stage2.api_air_fire())
\r
105 var airFire = json.api_stage2.api_air_fire;
\r
106 var idx = (int)airFire.api_idx;
\r
107 return new AirFireResult
\r
109 ShipName = _getShipName(idx),
\r
110 Kind = (int)airFire.api_kind,
\r
111 Items = _getItemNames((int[])airFire.api_use_items)
\r