@@ -25,6 +25,8 @@ class AutoFriendGacha @Inject constructor(
2525 class ExitException (val reason : ExitReason ) : Exception()
2626
2727 private var count = 0
28+ private var isInLoop = false
29+ private var initialScreen = false
2830
2931 private fun countNext () {
3032 if (prefs.shouldLimitFP && count >= prefs.limitFP) {
@@ -35,35 +37,66 @@ class AutoFriendGacha @Inject constructor(
3537 }
3638
3739 override fun script (): Nothing {
38- val initialClickLocation: Location ? = if (images[Images .FriendSummon ] in locations.fp.initialSummonCheck) {
39- locations.fp.initialSummonClick
40- } else if (! isSummonButtonVisible()) {
41- locations.fp.first10SummonClick
42- } else null
40+ val screens: Map < () -> Boolean , () -> Unit > = mapOf (
41+ { isInventoryFull() } to {
42+ throw ExitException (ExitReason .InventoryFull )
43+ },
44+ { isFirstSummon() } to {
45+ // First 10x or 100x Summon
46+ locations.fp.first10SummonClick.click()
47+ 0.3 .seconds.wait()
48+ locations.fp.okClick.click()
4349
44- initialClickLocation?.let {
45- it.click()
46- 0.3 .seconds.wait()
47- locations.fp.okClick.click()
50+ initialScreen = true
51+ },
52+ { isDailyFree() } to {
53+ // Daily Free Summon
54+ locations.fp.initialSummonClick.click()
55+ 0.3 .seconds.wait()
56+ locations.fp.initialSummonContinueClick.click()
4857
49- countNext()
50- }
58+ initialScreen = true
59+ },
60+ { isSummonButtonVisible() } to { rollFPAgain() }
61+ )
5162
5263 while (true ) {
53- if (isInventoryFull()) {
54- throw ExitException (ExitReason .InventoryFull )
55- }
56-
57- if (isSummonButtonVisible()) {
58- countNext()
64+ val actor = useSameSnapIn {
65+ screens
66+ .asSequence()
67+ .filter { (validator, _) -> validator() }
68+ .map { (_, actor) -> actor }
69+ .firstOrNull()
70+ } ? : { locations.fp.skipRapidClick.click(15 ) }
71+ actor.invoke()
72+ 0.5 .seconds.wait()
73+ }
74+ }
5975
60- locations.fp.continueSummonClick.click()
61- 0.3 .seconds.wait()
62- locations.fp.okClick.click()
63- 3 .seconds.wait()
64- } else locations.fp.skipRapidClick.click(15 )
76+ private fun rollFPAgain () {
77+ if (! isInLoop && initialScreen) {
78+ countNext()
79+ isInLoop = true
6580 }
81+ countNext()
82+
83+ locations.fp.continueSummonClick.click()
84+ 0.3 .seconds.wait()
85+ locations.fp.okClick.click()
86+ 3 .seconds.wait()
6687 }
6788
6889 private fun isSummonButtonVisible () = findImage(locations.fp.continueSummonRegion, Images .FPSummonContinue )
90+
91+ private fun isFirstSummon (): Boolean {
92+ if (isInLoop) return false
93+
94+ return images[Images .FriendSummon ] in locations.fp.summonCheck
95+ }
96+
97+ private fun isDailyFree (): Boolean {
98+ if (isInLoop) return false
99+
100+ return images[Images .FriendSummon ] in locations.fp.initialSummonCheck
101+ }
69102}
0 commit comments