From a307028d742926a0b746f6cccda9fdddbef2c60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20R=C3=A4tzel?= Date: Tue, 21 Apr 2020 05:48:16 +0000 Subject: [PATCH] Implement idea from JongoFett Adapt for idea from JongoFett at https://github.com/Viir/bots/issues/7#issue-602415016 --- .../eve-online-mining-bot/src/Bot.elm | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/implement/applications/eve-online/eve-online-mining-bot/src/Bot.elm b/implement/applications/eve-online/eve-online-mining-bot/src/Bot.elm index c3016b4f..63f3492b 100644 --- a/implement/applications/eve-online/eve-online-mining-bot/src/Bot.elm +++ b/implement/applications/eve-online/eve-online-mining-bot/src/Bot.elm @@ -1,4 +1,5 @@ -{- EVE Online mining bot version 2020-04-18 +{- EVE Online mining bot version 2020-04-18 - 2020-04-21 JongoFett + 2020-04-21 adapted for idea from JongoFett at https://github.com/Viir/bots/issues/7#issue-602415016 The bot warps to an asteroid belt, mines there until the ore hold is full, and then docks at a station to unload the ore. It then repeats this cycle until you stop it. It remembers the station in which it was last docked, and docks again at the same station. @@ -473,7 +474,7 @@ travelToMiningSiteAndLaunchDronesAndTargetAsteroid context = |> Maybe.withDefault (DescribeBranch ("Choosing asteroid '" ++ (asteroidInOverview.objectName |> Maybe.withDefault "Nothing") ++ "'") - (lockTargetFromOverviewEntryAndEnsureIsInRange (min context.settings.targetingRange context.settings.miningModuleRange) asteroidInOverview) + (lockTargetFromOverviewEntryAndEnsureIsInRange context.parsedUserInterface (min context.settings.targetingRange context.settings.miningModuleRange) asteroidInOverview) ) @@ -530,8 +531,8 @@ ensureOreHoldIsSelectedInInventoryWindow parsedUserInterface continueWithInvento ) -lockTargetFromOverviewEntryAndEnsureIsInRange : Int -> OverviewWindowEntry -> DecisionPathNode -lockTargetFromOverviewEntryAndEnsureIsInRange rangeInMeters overviewEntry = +lockTargetFromOverviewEntryAndEnsureIsInRange : ParsedUserInterface -> Int -> OverviewWindowEntry -> DecisionPathNode +lockTargetFromOverviewEntryAndEnsureIsInRange parsedUserInterface rangeInMeters overviewEntry = case overviewEntry.objectDistanceInMeters of Ok distanceInMeters -> if distanceInMeters <= rangeInMeters then @@ -544,22 +545,37 @@ lockTargetFromOverviewEntryAndEnsureIsInRange rangeInMeters overviewEntry = else DescribeBranch ("Object is not in range (" ++ (distanceInMeters |> String.fromInt) ++ " meters away). Approach.") - (EndDecisionPath - (actStartingWithRightClickOnOverviewEntry - overviewEntry - [ ( "Click menu entry 'approach'." - , lastContextMenuOrSubmenu - >> Maybe.andThen (menuEntryContainingTextIgnoringCase "approach") - >> Maybe.map (.uiNode >> clickOnUIElement MouseButtonLeft >> List.singleton) - ) - ] - ) + (if isShipApproaching parsedUserInterface then + DescribeBranch "I see we already approach." (EndDecisionPath Wait) + + else + EndDecisionPath + (actStartingWithRightClickOnOverviewEntry + overviewEntry + [ ( "Click menu entry 'approach'." + , lastContextMenuOrSubmenu + >> Maybe.andThen (menuEntryContainingTextIgnoringCase "approach") + >> Maybe.map (.uiNode >> clickOnUIElement MouseButtonLeft >> List.singleton) + ) + ] + ) ) Err error -> DescribeBranch ("Failed to read the distance: " ++ error) (EndDecisionPath Wait) +isShipApproaching : ParsedUserInterface -> Bool +isShipApproaching = + .shipUI + >> maybeNothingFromCanNotSeeIt + >> Maybe.andThen (.indication >> maybeNothingFromCanNotSeeIt) + >> Maybe.andThen (.maneuverType >> maybeNothingFromCanNotSeeIt) + >> Maybe.map ((==) EveOnline.ParseUserInterface.ManeuverApproach) + -- If the ship is just floating in space, there might be no indication displayed. + >> Maybe.withDefault False + + lockTargetFromOverviewEntry : OverviewWindowEntry -> DecisionPathNode lockTargetFromOverviewEntry overviewEntry = DescribeBranch ("Lock target from overview entry '" ++ (overviewEntry.objectName |> Maybe.withDefault "") ++ "'")