Skip to content

Commit

Permalink
fix large searchlight logic
Browse files Browse the repository at this point in the history
  • Loading branch information
myangelkamikaze committed Oct 27, 2023
1 parent ab93a98 commit 4f0232d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
12 changes: 6 additions & 6 deletions ElectronicObserverTypes/Extensions/ShipDataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4f0232d

Please sign in to comment.