-
Notifications
You must be signed in to change notification settings - Fork 134
/
Bot.elm
1309 lines (1105 loc) · 56.2 KB
/
Bot.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{- EVE Online combat anomaly bot version 2023-04-18
This bot uses the probe scanner to find combat anomalies and kills rats using drones and weapon modules.
## Features
+ Automatically detects if another pilot is in an anomaly on arrival and switches to another anomaly if necessary.
+ Filtering for specific anomalies using bot settings.
+ Avoiding dangerous or too-powerful rats using bot settings.
+ Remembers observed properties of anomalies, like other pilots or dangerous rats, to inform the selection of anomalies in the future.
## Setting up the Game Client
Despite being quite robust, this bot is less intelligent than a human. For example, its perception is more limited than ours, so we need to set up the game to ensure that the bot can see everything it needs. Following is the list of setup instructions for the EVE Online client:
+ Set the UI language to English.
+ Undock, open probe scanner, overview window and drones window.
+ Set the Overview window to sort objects in space by distance with the nearest entry at the top.
+ In the ship UI, arrange the modules:
+ Place the modules to use in combat (to activate on targets) in the top row.
+ Hide passive modules by disabling the check-box `Display Passive Modules`.
+ Configure the keyboard key 'W' to make the ship orbit.
## Configuration Settings
All settings are optional; you only need them in case the defaults don't fit your use-case.
+ `anomaly-name` : Choose the name of anomalies to take. You can use this setting multiple times to select multiple names.
+ `hide-when-neutral-in-local` : Set this to 'yes' to make the bot dock in a station or structure when a neutral or hostile appears in the 'local' chat.
+ `avoid-rat` : Name of a rat to avoid, as it appears in the overview. You can use this setting multiple times to select multiple names.
+ `activate-module-always` : Text found in tooltips of ship modules that should always be active. For example: "shield hardener".
+ `anomaly-wait-time`: Minimum time to wait after arriving in an anomaly before considering it finished. Use this if you see anomalies in which rats arrive later than you arrive on grid.
+ `warp-to-anomaly-distance`: Defaults to 'Within 0 m'
When using more than one setting, start a new line for each setting in the text input field.
Here is an example of a complete settings string:
```
anomaly-name = Drone Patrol
anomaly-name = Drone Horde
hide-when-neutral-in-local = yes
avoid-rat = Infested Carrier
activate-module-always = shield hardener
```
To learn more about the anomaly bot, see <https://to.botlab.org/guide/app/eve-online-combat-anomaly-bot>
-}
{-
catalog-tags:eve-online,anomaly,ratting
authors-forum-usernames:viir
-}
module Bot exposing
( State
, botMain
)
import BotLab.BotInterface_To_Host_2023_02_06 as InterfaceToHost
import Common.AppSettings as AppSettings
import Common.Basics exposing (listElementAtWrappedIndex, resultFirstSuccessOrFirstError, stringContainsIgnoringCase)
import Common.DecisionPath exposing (describeBranch)
import Common.EffectOnWindow as EffectOnWindow exposing (MouseButton(..))
import Dict
import EveOnline.BotFramework
exposing
( ModuleButtonTooltipMemory
, ReadingFromGameClient
, SeeUndockingComplete
, ShipModulesMemory
, UseContextMenuCascadeNode(..)
, localChatWindowFromUserInterface
, menuCascadeCompleted
, mouseClickOnUIElement
, pickEntryFromLastContextMenuInCascade
, shipUIIndicatesShipIsWarpingOrJumping
, uiNodeVisibleRegionLargeEnoughForClicking
, useMenuEntryWithTextContaining
, useMenuEntryWithTextContainingFirstOf
, useMenuEntryWithTextEqual
)
import EveOnline.BotFrameworkSeparatingMemory
exposing
( DecisionPathNode
, UpdateMemoryContext
, askForHelpToGetUnstuck
, branchDependingOnDockedOrInSpace
, clickModuleButtonButWaitIfClickedInPreviousStep
, decideActionForCurrentStep
, ensureInfoPanelLocationInfoIsExpanded
, useContextMenuCascade
, useContextMenuCascadeOnListSurroundingsButton
, useContextMenuCascadeOnOverviewEntry
, waitForProgressInGame
)
import EveOnline.ParseUserInterface
exposing
( OverviewWindowEntry
, ShipUI
, ShipUIModuleButton
)
import Result.Extra
import Set
defaultBotSettings : BotSettings
defaultBotSettings =
{ hideWhenNeutralInLocal = AppSettings.No
, anomalyNames = []
, avoidRats = []
, activateModulesAlways = []
, maxTargetCount = 3
, botStepDelayMilliseconds = 1400
, anomalyWaitTimeSeconds = 15
, orbitInCombat = AppSettings.Yes
, warpToAnomalyDistance = "Within 0 m"
}
parseBotSettings : String -> Result String BotSettings
parseBotSettings =
AppSettings.parseSimpleListOfAssignmentsSeparatedByNewlines
([ ( "hide-when-neutral-in-local"
, { description = "Set this to 'yes' to make the bot dock in a station or structure when a neutral or hostile appears in the 'local' chat."
, valueParser =
AppSettings.valueTypeYesOrNo
(\hide settings -> { settings | hideWhenNeutralInLocal = hide })
}
)
, ( "anomaly-name"
, { description = "Choose the name of anomalies to take. You can use this setting multiple times to select multiple names."
, valueParser =
AppSettings.valueTypeString
(\anomalyName settings ->
{ settings | anomalyNames = String.trim anomalyName :: settings.anomalyNames }
)
}
)
, ( "avoid-rat"
, { description = "Name of a rat to avoid, as it appears in the overview. You can use this setting multiple times to select multiple names."
, valueParser =
AppSettings.valueTypeString
(\ratToAvoid settings ->
{ settings | avoidRats = String.trim ratToAvoid :: settings.avoidRats }
)
}
)
, ( "activate-module-always"
, { description = "Text found in tooltips of ship modules that should always be active. For example: 'shield hardener'."
, valueParser =
AppSettings.valueTypeString
(\moduleName settings ->
{ settings | activateModulesAlways = moduleName :: settings.activateModulesAlways }
)
}
)
, ( "anomaly-wait-time"
, { description = "Minimum time to wait after arriving in an anomaly before considering it finished. Use this if you see anomalies in which rats arrive later than you arrive on grid."
, valueParser =
AppSettings.valueTypeInteger
(\anomalyWaitTimeSeconds settings ->
{ settings | anomalyWaitTimeSeconds = anomalyWaitTimeSeconds }
)
}
)
, ( "orbit-in-combat"
, { description = "Whether to keep the ship orbiting during combat"
, valueParser =
AppSettings.valueTypeYesOrNo
(\orbitInCombat settings ->
{ settings | orbitInCombat = orbitInCombat }
)
}
)
, ( "warp-to-anomaly-distance"
, { description = "Defaults to 'Within 0 m'"
, valueParser =
AppSettings.valueTypeString
(\warpToAnomalyDistance settings ->
{ settings | warpToAnomalyDistance = warpToAnomalyDistance }
)
}
)
, ( "bot-step-delay"
, { description = "Minimum time between starting bot steps in milliseconds"
, valueParser =
AppSettings.valueTypeInteger
(\delay settings ->
{ settings | botStepDelayMilliseconds = delay }
)
}
)
]
|> Dict.fromList
)
defaultBotSettings
goodStandingPatterns : List String
goodStandingPatterns =
[ "good standing", "excellent standing", "is in your" ]
type alias BotSettings =
{ hideWhenNeutralInLocal : AppSettings.YesOrNo
, anomalyNames : List String
, avoidRats : List String
, activateModulesAlways : List String
, maxTargetCount : Int
, anomalyWaitTimeSeconds : Int
, botStepDelayMilliseconds : Int
, orbitInCombat : AppSettings.YesOrNo
, warpToAnomalyDistance : String
}
type alias State =
EveOnline.BotFrameworkSeparatingMemory.StateIncludingFramework BotSettings BotMemory
type alias BotMemory =
{ lastDockedStationNameFromInfoPanel : Maybe String
, shipModules : ShipModulesMemory
, shipWarpingInLastReading : Maybe Bool
, visitedAnomalies : Dict.Dict String MemoryOfAnomaly
, notEnoughBandwidthToLaunchDrone : Bool
, droneBandwidthLimitatatinEvents : List { timeMilliseconds : Int, dronesInSpaceCount : Int }
}
type alias MemoryOfAnomaly =
{ arrivalTime : { milliseconds : Int }
, otherPilotsFoundOnArrival : List String
, ratsSeen : Set.Set String
}
type alias BotDecisionContext =
EveOnline.BotFrameworkSeparatingMemory.StepDecisionContext BotSettings BotMemory
type ReasonToIgnoreProbeScanResult
= ScanResultHasNoID
| AvoidAnomaly ReasonToAvoidAnomaly
type ReasonToAvoidAnomaly
= IsNoCombatAnomaly
| DoesNotMatchAnomalyNameFromSettings
| FoundOtherPilotOnArrival String
| FoundRatToAvoid String
describeReasonToAvoidAnomaly : ReasonToAvoidAnomaly -> String
describeReasonToAvoidAnomaly reason =
case reason of
IsNoCombatAnomaly ->
"Is not a combat anomaly"
DoesNotMatchAnomalyNameFromSettings ->
"Does not match an anomaly name from the settings"
FoundOtherPilotOnArrival otherPilot ->
"Found another pilot on arrival: " ++ otherPilot
FoundRatToAvoid rat ->
"Found a rat to avoid: " ++ rat
findReasonToIgnoreProbeScanResult : BotDecisionContext -> EveOnline.ParseUserInterface.ProbeScanResult -> Maybe ReasonToIgnoreProbeScanResult
findReasonToIgnoreProbeScanResult context probeScanResult =
case probeScanResult.cellsTexts |> Dict.get "ID" of
Nothing ->
Just ScanResultHasNoID
Just scanResultID ->
let
isCombatAnomaly =
probeScanResult.cellsTexts
|> Dict.get "Group"
|> Maybe.map (stringContainsIgnoringCase "combat")
|> Maybe.withDefault False
matchesAnomalyNameFromSettings =
(context.eventContext.botSettings.anomalyNames |> List.isEmpty)
|| (context.eventContext.botSettings.anomalyNames
|> List.any
(\anomalyName ->
probeScanResult.cellsTexts
|> Dict.get "Name"
|> Maybe.map (String.toLower >> (==) (anomalyName |> String.toLower |> String.trim))
|> Maybe.withDefault False
)
)
in
if not isCombatAnomaly then
Just (AvoidAnomaly IsNoCombatAnomaly)
else if not matchesAnomalyNameFromSettings then
Just (AvoidAnomaly DoesNotMatchAnomalyNameFromSettings)
else
findReasonToAvoidAnomalyFromMemory context { anomalyID = scanResultID }
|> Maybe.map AvoidAnomaly
findReasonToAvoidAnomalyFromMemory : BotDecisionContext -> { anomalyID : String } -> Maybe ReasonToAvoidAnomaly
findReasonToAvoidAnomalyFromMemory context { anomalyID } =
case memoryOfAnomalyWithID anomalyID context.memory of
Nothing ->
Nothing
Just memoryOfAnomaly ->
case memoryOfAnomaly.otherPilotsFoundOnArrival of
otherPilotFoundOnArrival :: _ ->
Just (FoundOtherPilotOnArrival otherPilotFoundOnArrival)
[] ->
let
ratsToAvoidSeen =
getRatsToAvoidSeenInAnomaly context.eventContext.botSettings memoryOfAnomaly
in
case ratsToAvoidSeen |> Set.toList of
ratToAvoid :: _ ->
Just (FoundRatToAvoid ratToAvoid)
[] ->
Nothing
getRatsToAvoidSeenInAnomaly : BotSettings -> MemoryOfAnomaly -> Set.Set String
getRatsToAvoidSeenInAnomaly settings =
.ratsSeen >> Set.filter (shouldAvoidRatAccordingToSettings settings)
shouldAvoidRatAccordingToSettings : BotSettings -> String -> Bool
shouldAvoidRatAccordingToSettings settings ratName =
settings.avoidRats |> List.map String.toLower |> List.member (ratName |> String.toLower)
memoryOfAnomalyWithID : String -> BotMemory -> Maybe MemoryOfAnomaly
memoryOfAnomalyWithID anomalyID =
.visitedAnomalies >> Dict.get anomalyID
anomalyBotDecisionRoot : BotDecisionContext -> DecisionPathNode
anomalyBotDecisionRoot context =
anomalyBotDecisionRootBeforeApplyingSettings context
|> EveOnline.BotFrameworkSeparatingMemory.setMillisecondsToNextReadingFromGameBase
context.eventContext.botSettings.botStepDelayMilliseconds
anomalyBotDecisionRootBeforeApplyingSettings : BotDecisionContext -> DecisionPathNode
anomalyBotDecisionRootBeforeApplyingSettings context =
generalSetupInUserInterface context.readingFromGameClient
|> Maybe.withDefault
(branchDependingOnDockedOrInSpace
{ ifDocked =
continueIfShouldHide
{ ifShouldHide =
describeBranch "Stay docked." waitForProgressInGame
}
context
|> Maybe.withDefault
(undockUsingStationWindow context
{ ifCannotReachButton = describeBranch "No alternative for undocking" askForHelpToGetUnstuck }
)
, ifSeeShipUI =
always
(continueIfShouldHide
{ ifShouldHide =
returnDronesToBay context
|> Maybe.withDefault
(describeBranch
"Dock to station or structure."
(dockAtRandomStationOrStructure context)
)
}
context
)
, ifUndockingComplete = decideNextActionWhenInSpace context
}
context.readingFromGameClient
)
generalSetupInUserInterface : ReadingFromGameClient -> Maybe DecisionPathNode
generalSetupInUserInterface readingFromGameClient =
[ closeMessageBox, ensureInfoPanelLocationInfoIsExpanded ]
|> List.filterMap
(\maybeSetupDecisionFromGameReading ->
maybeSetupDecisionFromGameReading readingFromGameClient
)
|> List.head
closeMessageBox : ReadingFromGameClient -> Maybe DecisionPathNode
closeMessageBox readingFromGameClient =
readingFromGameClient.messageBoxes
|> List.head
|> Maybe.map
(\messageBox ->
describeBranch "I see a message box to close."
(let
buttonCanBeUsedToClose =
.mainText
>> Maybe.map (String.trim >> String.toLower >> (\buttonText -> [ "close", "ok" ] |> List.member buttonText))
>> Maybe.withDefault False
in
case messageBox.buttons |> List.filter buttonCanBeUsedToClose |> List.head of
Nothing ->
describeBranch "I see no way to close this message box." askForHelpToGetUnstuck
Just buttonToUse ->
describeBranch
("Click on button '" ++ (buttonToUse.mainText |> Maybe.withDefault "") ++ "'.")
(mouseClickOnUIElement MouseButtonLeft buttonToUse.uiNode
|> Result.Extra.unpack
(always (describeBranch "Failed to click" askForHelpToGetUnstuck))
decideActionForCurrentStep
)
)
)
continueIfShouldHide : { ifShouldHide : DecisionPathNode } -> BotDecisionContext -> Maybe DecisionPathNode
continueIfShouldHide config context =
case
context.eventContext |> EveOnline.BotFramework.secondsToSessionEnd |> Maybe.andThen (nothingFromIntIfGreaterThan 200)
of
Just secondsToSessionEnd ->
Just
(describeBranch ("Session ends in " ++ (secondsToSessionEnd |> String.fromInt) ++ " seconds.")
config.ifShouldHide
)
Nothing ->
if context.eventContext.botSettings.hideWhenNeutralInLocal /= AppSettings.Yes then
Nothing
else
case context.readingFromGameClient |> localChatWindowFromUserInterface of
Nothing ->
Just (describeBranch "I don't see the local chat window." askForHelpToGetUnstuck)
Just localChatWindow ->
let
chatUserHasGoodStanding chatUser =
goodStandingPatterns
|> List.any
(\goodStandingPattern ->
chatUser.standingIconHint
|> Maybe.map (stringContainsIgnoringCase goodStandingPattern)
|> Maybe.withDefault False
)
subsetOfUsersWithNoGoodStanding =
localChatWindow.userlist
|> Maybe.map .visibleUsers
|> Maybe.withDefault []
|> List.filter (chatUserHasGoodStanding >> not)
in
if 1 < (subsetOfUsersWithNoGoodStanding |> List.length) then
Just (describeBranch "There is an enemy or neutral in local chat." config.ifShouldHide)
else
Nothing
{-| 2020-07-11 Discovery by Viktor:
The entries for structures in the menu from the SurroundingsButton can be nested one level deeper than the ones for stations.
In other words, not all structures appear directly under the "structures" entry.
-}
dockAtRandomStationOrStructure : BotDecisionContext -> DecisionPathNode
dockAtRandomStationOrStructure context =
let
withTextContainingIgnoringCase textToSearch =
List.filter (.text >> String.toLower >> (==) (textToSearch |> String.toLower)) >> List.head
menuEntryIsSuitable menuEntry =
[ "cyno beacon", "jump gate" ]
|> List.any (\toAvoid -> menuEntry.text |> stringContainsIgnoringCase toAvoid)
|> not
chooseNextMenuEntry =
{ describeChoice = "Use 'Dock' if available or a random entry."
, chooseEntry =
pickEntryFromLastContextMenuInCascade
(\menuEntries ->
let
suitableMenuEntries =
List.filter menuEntryIsSuitable menuEntries
in
[ withTextContainingIgnoringCase "dock"
, List.filter (.text >> stringContainsIgnoringCase "station")
>> Common.Basics.listElementAtWrappedIndex
(context.randomIntegers |> List.head |> Maybe.withDefault 0)
, Common.Basics.listElementAtWrappedIndex
(context.randomIntegers |> List.head |> Maybe.withDefault 0)
]
|> List.filterMap (\priority -> suitableMenuEntries |> priority)
|> List.head
)
}
in
useContextMenuCascadeOnListSurroundingsButton
(useMenuEntryWithTextContainingFirstOf [ "stations", "structures" ]
(MenuEntryWithCustomChoice chooseNextMenuEntry
(MenuEntryWithCustomChoice chooseNextMenuEntry
(MenuEntryWithCustomChoice chooseNextMenuEntry MenuCascadeCompleted)
)
)
)
context
decideNextActionWhenInSpace : BotDecisionContext -> SeeUndockingComplete -> DecisionPathNode
decideNextActionWhenInSpace context seeUndockingComplete =
if seeUndockingComplete.shipUI |> shipUIIndicatesShipIsWarpingOrJumping then
describeBranch "I see we are warping."
([ returnDronesToBay context
, readShipUIModuleButtonTooltips context
]
|> List.filterMap identity
|> List.head
|> Maybe.withDefault waitForProgressInGame
)
else
case context |> knownModulesToActivateAlways |> List.filter (Tuple.second >> moduleIsActiveOrReloading >> not) |> List.head of
Just ( inactiveModuleMatchingText, inactiveModule ) ->
describeBranch ("I see inactive module '" ++ inactiveModuleMatchingText ++ "' to activate always. Activate it.")
(clickModuleButtonButWaitIfClickedInPreviousStep context inactiveModule)
Nothing ->
let
returnDronesAndEnterAnomaly { ifNoAcceptableAnomalyAvailable } =
returnDronesToBay context
|> Maybe.withDefault
(describeBranch "No drones to return."
(enterAnomaly { ifNoAcceptableAnomalyAvailable = ifNoAcceptableAnomalyAvailable } context)
)
returnDronesAndEnterAnomalyOrWait =
returnDronesAndEnterAnomaly
{ ifNoAcceptableAnomalyAvailable =
describeBranch "Wait for a matching anomaly to appear." waitForProgressInGame
}
in
case context.readingFromGameClient |> getCurrentAnomalyIDAsSeenInProbeScanner of
Nothing ->
describeBranch "Looks like we are not in an anomaly." returnDronesAndEnterAnomalyOrWait
Just anomalyID ->
case memoryOfAnomalyWithID anomalyID context.memory of
Nothing ->
describeBranch
("Program error: Did not find memory of anomaly " ++ anomalyID)
waitForProgressInGame
Just memoryOfAnomaly ->
let
arrivalInAnomalyAgeSeconds =
(context.eventContext.timeInMilliseconds - memoryOfAnomaly.arrivalTime.milliseconds) // 1000
in
describeBranch ("We are in anomaly '" ++ anomalyID ++ "' since " ++ String.fromInt arrivalInAnomalyAgeSeconds ++ " seconds.")
(case findReasonToAvoidAnomalyFromMemory context { anomalyID = anomalyID } of
Just reasonToAvoidAnomaly ->
describeBranch
("Found a reason to avoid this anomaly: "
++ describeReasonToAvoidAnomaly reasonToAvoidAnomaly
)
(returnDronesAndEnterAnomaly
{ ifNoAcceptableAnomalyAvailable =
describeBranch "Get out of this anomaly."
(dockAtRandomStationOrStructure context)
}
)
Nothing ->
decideActionInAnomaly
{ arrivalInAnomalyAgeSeconds = arrivalInAnomalyAgeSeconds }
context
seeUndockingComplete
returnDronesAndEnterAnomalyOrWait
)
undockUsingStationWindow :
BotDecisionContext
-> { ifCannotReachButton : DecisionPathNode }
-> DecisionPathNode
undockUsingStationWindow context { ifCannotReachButton } =
case context.readingFromGameClient.stationWindow of
Nothing ->
describeBranch "I do not see the station window." ifCannotReachButton
Just stationWindow ->
case stationWindow.undockButton of
Nothing ->
case stationWindow.abortUndockButton of
Nothing ->
describeBranch "I do not see the undock button." ifCannotReachButton
Just _ ->
describeBranch "I see we are already undocking." waitForProgressInGame
Just undockButton ->
describeBranch "Click on the button to undock."
(mouseClickOnUIElement MouseButtonLeft undockButton
|> Result.Extra.unpack
(always ifCannotReachButton)
decideActionForCurrentStep
)
decideActionInAnomaly :
{ arrivalInAnomalyAgeSeconds : Int }
-> BotDecisionContext
-> SeeUndockingComplete
-> DecisionPathNode
-> DecisionPathNode
decideActionInAnomaly { arrivalInAnomalyAgeSeconds } context seeUndockingComplete continueIfCombatComplete =
let
overviewEntriesToAttack =
seeUndockingComplete.overviewWindows
|> List.concatMap .entries
{-
2023-03-30
Change to sort by display location after Wombat shared his experience in EVE Online at https://forum.botlab.org/t/eve-online-anomaly-ratting-bot-release/87/340
|> List.sortBy (.objectDistanceInMeters >> Result.withDefault 999999)
-}
|> List.sortBy (.uiNode >> .totalDisplayRegion >> .y)
|> List.filter shouldAttackOverviewEntry
overviewEntriesToLock =
overviewEntriesToAttack
|> List.filter (overviewEntryIsTargetedOrTargeting >> not)
|> List.map (lockTargetFromOverviewEntry context)
targetsToUnlock =
if overviewEntriesToAttack |> List.any overviewEntryIsActiveTarget then
[]
else
context.readingFromGameClient.targets |> List.filter .isActiveTarget
ensureShipIsOrbitingDecision =
overviewEntriesToAttack
|> List.reverse
|> List.head
|> Maybe.andThen (\overviewEntryToAttack -> ensureShipIsOrbiting seeUndockingComplete.shipUI overviewEntryToAttack)
waitTimeRemainingSeconds =
context.eventContext.botSettings.anomalyWaitTimeSeconds - arrivalInAnomalyAgeSeconds
decisionIfNoEnemyToAttack =
if overviewEntriesToAttack |> List.isEmpty then
if waitTimeRemainingSeconds <= 0 then
returnDronesToBay context
|> Maybe.withDefault
(describeBranch "No drones to return." continueIfCombatComplete)
else
describeBranch
("Wait before considering the anomaly finished: " ++ String.fromInt waitTimeRemainingSeconds ++ " seconds")
waitForProgressInGame
else
describeBranch "Wait for target locking to complete." waitForProgressInGame
continueLockOverviewEntries { ifNoEntryToLock } =
case resultFirstSuccessOrFirstError overviewEntriesToLock of
Nothing ->
describeBranch "I see no more overview entries to lock."
ifNoEntryToLock
Just nextOverviewEntryToLockResult ->
describeBranch "I see an overview entry to lock."
(nextOverviewEntryToLockResult
|> Result.Extra.unpack
(describeBranch >> (|>) askForHelpToGetUnstuck)
identity
)
decisionToKillRats =
case targetsToUnlock |> List.head of
Just targetToUnlock ->
describeBranch "I see a target to unlock."
(useContextMenuCascade
( "locked target", targetToUnlock.barAndImageCont |> Maybe.withDefault targetToUnlock.uiNode )
(useMenuEntryWithTextContaining "unlock" menuCascadeCompleted)
context
)
Nothing ->
case context.readingFromGameClient.targets |> List.head of
Nothing ->
describeBranch "I see no locked target."
(continueLockOverviewEntries { ifNoEntryToLock = decisionIfNoEnemyToAttack })
Just _ ->
describeBranch "I see a locked target."
(case seeUndockingComplete |> shipUIModulesToActivateOnTarget |> List.filter (.isActive >> Maybe.withDefault False >> not) |> List.head of
Nothing ->
describeBranch "All attack modules are active."
(launchAndEngageDrones context
|> Maybe.withDefault
(describeBranch "No idling drones."
(if context.eventContext.botSettings.maxTargetCount <= (context.readingFromGameClient.targets |> List.length) then
describeBranch "Enough locked targets." waitForProgressInGame
else
continueLockOverviewEntries
{ ifNoEntryToLock = waitForProgressInGame }
)
)
)
Just inactiveModule ->
describeBranch "I see an inactive module to activate on targets. Activate it."
(clickModuleButtonButWaitIfClickedInPreviousStep context inactiveModule)
)
in
if context.eventContext.botSettings.orbitInCombat == AppSettings.Yes then
ensureShipIsOrbitingDecision
|> Maybe.withDefault (Ok decisionToKillRats)
|> Result.Extra.unpack
(describeBranch >> (|>) decisionToKillRats)
identity
else
decisionToKillRats
enterAnomaly : { ifNoAcceptableAnomalyAvailable : DecisionPathNode } -> BotDecisionContext -> DecisionPathNode
enterAnomaly { ifNoAcceptableAnomalyAvailable } context =
case context.readingFromGameClient.probeScannerWindow of
Nothing ->
describeBranch "I do not see the probe scanner window." askForHelpToGetUnstuck
Just probeScannerWindow ->
let
scanResultsWithReasonToIgnore =
probeScannerWindow.scanResults
|> List.map
(\scanResult ->
( scanResult
, findReasonToIgnoreProbeScanResult context scanResult
)
)
in
case
scanResultsWithReasonToIgnore
|> List.filter (Tuple.second >> (==) Nothing)
|> List.map Tuple.first
|> listElementAtWrappedIndex (context.randomIntegers |> List.head |> Maybe.withDefault 0)
of
Nothing ->
describeBranch
("I see "
++ (probeScannerWindow.scanResults |> List.length |> String.fromInt)
++ " scan results, and no matching anomaly. Wait for a matching anomaly to appear."
)
ifNoAcceptableAnomalyAvailable
Just anomalyScanResult ->
describeBranch "Warp to anomaly."
(useContextMenuCascade
( "Scan result", anomalyScanResult.uiNode )
(useMenuEntryWithTextContaining "Warp to Within"
(useMenuEntryWithTextContaining
context.eventContext.botSettings.warpToAnomalyDistance
menuCascadeCompleted
)
)
context
)
ensureShipIsOrbiting : ShipUI -> OverviewWindowEntry -> Maybe (Result String DecisionPathNode)
ensureShipIsOrbiting shipUI overviewEntryToOrbit =
if (shipUI.indication |> Maybe.andThen .maneuverType) == Just EveOnline.ParseUserInterface.ManeuverOrbit then
Nothing
else
Just
(case mouseClickOnUIElement MouseButtonLeft overviewEntryToOrbit.uiNode of
Err _ ->
Err "Failed to click"
Ok effectToClick ->
Ok
(describeBranch "Press the 'W' key and click on the overview entry."
(decideActionForCurrentStep
([ [ EffectOnWindow.KeyDown EffectOnWindow.vkey_W ]
, effectToClick
, [ EffectOnWindow.KeyUp EffectOnWindow.vkey_W ]
]
|> List.concat
)
)
)
)
launchAndEngageDrones : BotDecisionContext -> Maybe DecisionPathNode
launchAndEngageDrones context =
context.readingFromGameClient.dronesWindow
|> Maybe.andThen
(\dronesWindow ->
case ( dronesWindow.droneGroupInBay, dronesWindow.droneGroupInSpace ) of
( Just droneGroupInBay, Just droneGroupInSpace ) ->
let
idlingDrones =
droneGroupInSpace
|> EveOnline.ParseUserInterface.enumerateAllDronesFromDronesGroup
|> List.filter
(.uiNode
>> .uiNode
>> EveOnline.ParseUserInterface.getAllContainedDisplayTexts
>> List.any (stringContainsIgnoringCase "idle")
)
dronesInBayQuantity =
droneGroupInBay.header.quantityFromTitle
|> Maybe.map .current
|> Maybe.withDefault 0
dronesInSpaceQuantityCurrent =
droneGroupInSpace.header.quantityFromTitle
|> Maybe.map .current
|> Maybe.withDefault 0
dronesInSpaceQuantityLimit =
droneGroupInSpace.header.quantityFromTitle
|> Maybe.andThen .maximum
|> Maybe.withDefault 2
in
if 0 < (idlingDrones |> List.length) then
Just
(describeBranch "Engage idling drone(s)"
(useContextMenuCascade
( "drones group", droneGroupInSpace.header.uiNode )
(useMenuEntryWithTextContaining "engage target" menuCascadeCompleted)
context
)
)
else if 0 < dronesInBayQuantity && dronesInSpaceQuantityCurrent < dronesInSpaceQuantityLimit then
if assumeNotEnoughBandwidthToLaunchDrone context then
Nothing
else
Just
(describeBranch "Launch drones"
(useContextMenuCascade
( "drones group", droneGroupInBay.header.uiNode )
(useMenuEntryWithTextContaining "Launch drone" menuCascadeCompleted)
context
)
)
else
Nothing
_ ->
Nothing
)
assumeNotEnoughBandwidthToLaunchDrone : BotDecisionContext -> Bool
assumeNotEnoughBandwidthToLaunchDrone context =
case
context.readingFromGameClient.dronesWindow
|> Maybe.andThen .droneGroupInSpace
|> Maybe.andThen (.header >> .quantityFromTitle)
of
Nothing ->
True
Just inSpaceQuantity ->
let
limitsFromPreviousEvents =
context.memory.droneBandwidthLimitatatinEvents
|> List.filter
(\limitEvent ->
context.eventContext.timeInMilliseconds < limitEvent.timeMilliseconds + 300 * 1000
)
|> List.map .dronesInSpaceCount
limitFromPreviousEvents =
limitsFromPreviousEvents
|> List.sort
-- Require confirmation via multiple observations
|> List.drop 1
|> List.head
|> Maybe.withDefault 999
in
context.memory.notEnoughBandwidthToLaunchDrone
|| (limitFromPreviousEvents <= inSpaceQuantity.current)
returnDronesToBay : BotDecisionContext -> Maybe DecisionPathNode
returnDronesToBay context =
context.readingFromGameClient.dronesWindow
|> Maybe.andThen .droneGroupInSpace
|> Maybe.andThen
(\droneGroupInLocalSpace ->
if
(droneGroupInLocalSpace.header.quantityFromTitle
|> Maybe.map .current
|> Maybe.withDefault 0
)
< 1
then
Nothing
else
Just
(describeBranch "I see there are drones in space. Return those to bay."
(useContextMenuCascade
( "drones group", droneGroupInLocalSpace.header.uiNode )
(useMenuEntryWithTextContaining "Return to drone bay" menuCascadeCompleted)
context
)
)
)
lockTargetFromOverviewEntry :
BotDecisionContext
-> OverviewWindowEntry
-> Result String DecisionPathNode
lockTargetFromOverviewEntry context overviewEntry =
if uiNodeVisibleRegionLargeEnoughForClicking overviewEntry.uiNode then
Ok
(describeBranch ("Lock target from overview entry '" ++ (overviewEntry.objectName |> Maybe.withDefault "") ++ "'")
(useContextMenuCascadeOnOverviewEntry
(useMenuEntryWithTextEqual "Lock target" menuCascadeCompleted)
overviewEntry
context
)
)
else
Err "Unable to click this overview entry because more of it needs to be visible."
readShipUIModuleButtonTooltips : BotDecisionContext -> Maybe DecisionPathNode
readShipUIModuleButtonTooltips =
EveOnline.BotFrameworkSeparatingMemory.readShipUIModuleButtonTooltipWhereNotYetInMemory
knownModulesToActivateAlways : BotDecisionContext -> List ( String, EveOnline.ParseUserInterface.ShipUIModuleButton )
knownModulesToActivateAlways context =
context.readingFromGameClient.shipUI
|> Maybe.map .moduleButtons
|> Maybe.withDefault []
|> List.filterMap
(\moduleButton ->
moduleButton
|> EveOnline.BotFramework.getModuleButtonTooltipFromModuleButton context.memory.shipModules
|> Maybe.andThen (tooltipLooksLikeModuleToActivateAlways context)
|> Maybe.map (\moduleName -> ( moduleName, moduleButton ))
)
tooltipLooksLikeModuleToActivateAlways : BotDecisionContext -> ModuleButtonTooltipMemory -> Maybe String
tooltipLooksLikeModuleToActivateAlways context =
.allContainedDisplayTextsWithRegion
>> List.filterMap
(\( tooltipText, _ ) ->
context.eventContext.botSettings.activateModulesAlways
|> List.filterMap
(\moduleToActivateAlways ->
if tooltipText |> stringContainsIgnoringCase moduleToActivateAlways then
Just tooltipText
else
Nothing
)
|> List.head
)
>> List.head
botMain : InterfaceToHost.BotConfig State
botMain =
{ init = EveOnline.BotFrameworkSeparatingMemory.initState initBotMemory
, processEvent =
EveOnline.BotFrameworkSeparatingMemory.processEvent
{ parseBotSettings = parseBotSettings
, selectGameClientInstance = always EveOnline.BotFramework.selectGameClientInstanceWithTopmostWindow
, updateMemoryForNewReadingFromGame = updateMemoryForNewReadingFromGame
, statusTextFromDecisionContext = statusTextFromState
, decideNextStep = anomalyBotDecisionRoot
}
}