Was having an issue when the defined ore was not in the mining overview. Now if the predefined ore is not in the overview, selects an asteroid, even if no matches exist.
selectAsteroidsFromOverview : BotDecisionContext -> Result String SelectedAsteroidsFromOverview
selectAsteroidsFromOverview context =
let
clickableAsteroids =
clickableAsteroidsFromOverviewWindow context.readingFromGameClient
continueWithAsteroidMatchingSettings asteroidMatchingSettings =
Ok
{ clickableAsteroids = clickableAsteroids
, asteroidMatchingSettings = asteroidMatchingSettings
}
filteredAsteroids =
clickableAsteroids
|> List.filter (asteroidOverviewEntryMatchesSettings context.eventContext.botSettings)
selectedAsteroid =
case filteredAsteroids of
-- If matches are found, use the closest one
asteroid :: _ ->
Just asteroid
-- If no matches are found, fallback to any clickable asteroid
[] ->
clickableAsteroids |> List.head
in
selectedAsteroid
|> Maybe.map
(\overviewEntry ->
overviewEntry.objectDistanceInMeters
|> Result.mapError
((++)
("Failed to read the distance on overview entry "
++ (overviewEntry.objectName |> Maybe.withDefault "")
++ ": "
)
)
|> Result.andThen
(\distanceInMeters ->
( overviewEntry
, { closeEnoughForMining =
distanceInMeters
<= min context.eventContext.botSettings.targetingRange
context.eventContext.botSettings.miningModuleRange
}
)
|> Just
|> continueWithAsteroidMatchingSettings
)
)
|> Maybe.withDefault (continueWithAsteroidMatchingSettings Nothing)