Skip to content

Commit e8fc0fd

Browse files
ArthurKun21reconman
authored andcommitted
fix 100x summon
1 parent cc842fc commit e8fc0fd

File tree

2 files changed

+57
-23
lines changed

2 files changed

+57
-23
lines changed

scripts/src/main/java/io/github/fate_grand_automata/scripts/entrypoints/AutoFriendGacha.kt

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

scripts/src/main/java/io/github/fate_grand_automata/scripts/locations/FPLocations.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ class FPLocations @Inject constructor(
2323
Location(2, 977).xFromCenter()
2424
else
2525
Location(2, 1052).xFromCenter()
26+
val initialSummonContinueClick = Region(341, 1145, 120, 60).xFromCenter()
2627

2728
val continueSummonRegion = Region(-36, 1264, 580, 170).xFromCenter()
2829
val first10SummonClick = if (afterAnni9)
2930
// the old location is still valid but only for 10x FP
3031
Location(400, 1062).xFromCenter()
3132
else
32-
Location(120, 1062).xFromCenter()
33+
Location(170, 1062).xFromCenter()
3334

3435
val okClick = Location(320, 1120).xFromCenter()
3536
val continueSummonClick = Location(320, 1325).xFromCenter()

0 commit comments

Comments
 (0)