using System;\r
using System.Collections.Generic;\r
using System.Linq;\r
-using KancolleSniffer.Util;\r
using static System.Math;\r
\r
namespace KancolleSniffer.Model\r
{\r
- public struct ChargeStatus\r
+ public class ChargeStatus\r
{\r
- public int Fuel { get; set; }\r
- public int Bull { get; set; }\r
+ public double FuelRatio { get; set; }\r
+ public int Fuel => CalcChargeState(FuelRatio) + (Others ? 5 : 0);\r
\r
- public ChargeStatus(ShipStatus status) : this()\r
+ public double BullRatio { get; set; }\r
+ public int Bull => CalcChargeState(BullRatio) + (Others ? 5 : 0);\r
+\r
+ public bool Others;\r
+\r
+ public ChargeStatus()\r
{\r
- Fuel = CalcChargeState(status.Fuel, status.Spec.FuelMax);\r
- Bull = CalcChargeState(status.Bull, status.Spec.BullMax);\r
}\r
\r
- public ChargeStatus(int fuel, int bull) : this()\r
+ public ChargeStatus(ShipStatus status)\r
{\r
- Fuel = fuel;\r
- Bull = bull;\r
+ FuelRatio = status.Spec.FuelMax == 0 ? 0 : (double)status.Fuel / status.Spec.FuelMax;\r
+ BullRatio = status.Spec.BullMax == 0 ? 0 : (double)status.Bull / status.Spec.BullMax;\r
}\r
\r
- private int CalcChargeState(int now, int full)\r
+ private int CalcChargeState(double ratio)\r
{\r
- if (full == 0 || now == full)\r
+ // ReSharper disable CompareOfFloatsByEqualityOperator\r
+ if (ratio == 0.0 || ratio == 1.0)\r
return 0;\r
- var ratio = (double)now / full;\r
+ // ReSharper restore CompareOfFloatsByEqualityOperator\r
if (ratio >= 7.0 / 9)\r
return 1;\r
if (ratio >= 3.0 / 9)\r
return 3;\r
return 4;\r
}\r
+\r
+ public static ChargeStatus Min(ChargeStatus a, ChargeStatus b)\r
+ {\r
+ return new ChargeStatus\r
+ {\r
+ FuelRatio = Math.Min(a.FuelRatio, b.FuelRatio),\r
+ BullRatio = Math.Min(a.BullRatio, b.BullRatio)\r
+ };\r
+ }\r
}\r
\r
public enum FleetState\r
get\r
{\r
var fs = new ChargeStatus(Ships[0]);\r
- var others = (from ship in Ships.Skip(1) select new ChargeStatus(ship)).Aggregate(\r
- (result, next) => new ChargeStatus(Max(result.Fuel, next.Fuel), Max(result.Bull, next.Bull)));\r
- return new ChargeStatus(fs.Fuel != 0 ? fs.Fuel : others.Fuel + 5,\r
- fs.Bull != 0 ? fs.Bull : others.Bull + 5);\r
+ var others = (from ship in Ships.Skip(1) select new ChargeStatus(ship)).Aggregate(ChargeStatus.Min);\r
+ others.Others = true;\r
+ return fs.Fuel != 0 ? fs : others;\r
}\r
}\r
\r