From 4f0232da87c526f1fe2d5ccba5d3bf29ebfc6a42 Mon Sep 17 00:00:00 2001 From: MyAngelKamikaze Date: Fri, 27 Oct 2023 16:48:32 +0900 Subject: [PATCH] fix large searchlight logic --- .../Sortie/Battle/Phase/PhaseNightInitial.cs | 15 ++++++++++----- .../Extensions/ShipDataExtensions.cs | 12 ++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ElectronicObserver/Window/Tools/SortieRecordViewer/Sortie/Battle/Phase/PhaseNightInitial.cs b/ElectronicObserver/Window/Tools/SortieRecordViewer/Sortie/Battle/Phase/PhaseNightInitial.cs index 67bcd4ea5..713148860 100644 --- a/ElectronicObserver/Window/Tools/SortieRecordViewer/Sortie/Battle/Phase/PhaseNightInitial.cs +++ b/ElectronicObserver/Window/Tools/SortieRecordViewer/Sortie/Battle/Phase/PhaseNightInitial.cs @@ -139,15 +139,20 @@ public PhaseNightInitial(IKCDatabase kcDatabase, BattleFleets fleets, ICombinedN }; } - private static (IShipData? Ship, int Index) GetSearchlightShip(IFleetData? fleet) => fleet switch + private static (IShipData? Ship, int Index) GetSearchlightShip(IFleetData? fleet) { - null => (null, -1), + if (fleet is null) return (null, -1); - _ => fleet.MembersWithoutEscaped? + List<(IShipData? Ship, int Index)>? searchlightCandidates = fleet.MembersWithoutEscaped? .Select((s, i) => (Ship: s, Index: i)) .Where(t => t.Ship?.HPCurrent > 1) - .FirstOrDefault(t => t.Ship!.HasSearchlight(), (null, -1)) ?? (null, -1), - }; + .ToList()!; + + if (searchlightCandidates is null) return (null, -1); + + return searchlightCandidates.FirstOrDefault(t => t.Ship!.HasLargeSearchlight(), + searchlightCandidates.FirstOrDefault(t => t.Ship!.HasSearchlight(), (null, -1))); + } private IShipData? GetFlareFriend(bool isEscort, int index) => (isEscort, index) switch { diff --git a/ElectronicObserverTypes/Extensions/ShipDataExtensions.cs b/ElectronicObserverTypes/Extensions/ShipDataExtensions.cs index 285e92a1b..c68631732 100644 --- a/ElectronicObserverTypes/Extensions/ShipDataExtensions.cs +++ b/ElectronicObserverTypes/Extensions/ShipDataExtensions.cs @@ -193,12 +193,12 @@ public static bool HasStarShell(this IShipData ship) => ship.AllSlotInstance .Any(e => e?.MasterEquipment.CategoryType == EquipmentTypes.StarShell); public static bool HasSearchlight(this IShipData ship) => ship.AllSlotInstance - .Any(e => e?.MasterEquipment.CategoryType switch - { - EquipmentTypes.Searchlight => true, - EquipmentTypes.SearchlightLarge => true, - _ => false - }); + .Any(e => e?.MasterEquipment.CategoryType is + EquipmentTypes.Searchlight or + EquipmentTypes.SearchlightLarge); + + public static bool HasLargeSearchlight(this IShipData ship) => ship.AllSlotInstance + .Any(e => e?.MasterEquipment.CategoryType is EquipmentTypes.SearchlightLarge); public static int HighAngleGunCount(this IShipData ship) => ship.AllSlotInstance .Count(e => e?.MasterEquipment.IsHighAngleGun is true);