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
15 using System.Collections.Generic;
\r
17 using KancolleSniffer.Model;
\r
19 namespace KancolleSniffer.View
\r
21 public class RepairShipCount
\r
23 private const int Minor = (int)ShipStatus.Damage.Minor;
\r
24 private const int Small = (int)ShipStatus.Damage.Small;
\r
25 private const int Half = (int)ShipStatus.Damage.Half;
\r
26 private const int Badly = (int)ShipStatus.Damage.Badly;
\r
28 private readonly int[] _counts = new int[typeof(ShipStatus.Damage).GetEnumValues().Length];
\r
29 private readonly List<string> _result = new List<string>();
\r
31 public RepairShipCount(ShipStatus[] repairList)
\r
33 foreach (var ship in repairList)
\r
34 _counts[(int)ship.DamageLevel]++;
\r
37 public override string ToString()
\r
39 if (_counts.All(n => n == 0))
\r
41 CountTwoLevels(Minor);
\r
42 CountTwoLevels(Half);
\r
43 return string.Join("\r\n", _result);
\r
46 private void CountTwoLevels(int level)
\r
49 FormatCount(level + 1);
\r
50 if (EitherNonZero(_counts[level], _counts[level + 1]) && ShowSum)
\r
51 _result.Add($" 計 {_counts[level] + _counts[level + 1]}");
\r
54 private readonly string[] _damageString = {"軽微", "小破", "中破", "大破"};
\r
56 private void FormatCount(int level)
\r
58 if (_counts[level] > 0)
\r
59 _result.Add($"{_damageString[level]} {_counts[level]}");
\r
62 private bool ShowSum =>
\r
63 BothNonZero(_counts[Minor], _counts[Small]) || BothNonZero(_counts[Half], _counts[Badly]);
\r
65 private static bool BothNonZero(int a, int b) => a * b > 0;
\r
67 private static bool EitherNonZero(int a, int b) => a + b > 0;
\r