diff --git a/scripts/src/main/java/io/github/fate_grand_automata/scripts/modules/Battle.kt b/scripts/src/main/java/io/github/fate_grand_automata/scripts/modules/Battle.kt index 4882c3fd7..7d162f1bb 100644 --- a/scripts/src/main/java/io/github/fate_grand_automata/scripts/modules/Battle.kt +++ b/scripts/src/main/java/io/github/fate_grand_automata/scripts/modules/Battle.kt @@ -1,8 +1,10 @@ package io.github.fate_grand_automata.scripts.modules +import io.github.fate_grand_automata.scripts.enums.GameServer import io.github.fate_grand_automata.scripts.IFgoAutomataApi import io.github.fate_grand_automata.scripts.Images import io.github.fate_grand_automata.scripts.entrypoints.AutoBattle +import io.github.fate_grand_automata.scripts.models.FieldSlot import io.github.fate_grand_automata.scripts.models.NPUsage import io.github.fate_grand_automata.scripts.models.ParsedCard import io.github.fate_grand_automata.scripts.models.Skill @@ -10,6 +12,7 @@ import io.github.fate_grand_automata.scripts.models.battle.BattleState import io.github.fate_grand_automata.scripts.prefs.IBattleConfig import io.github.lib_automata.dagger.ScriptScope import javax.inject.Inject +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @ScriptScope @@ -69,10 +72,12 @@ class Battle @Inject constructor( prefs.waitBeforeTurn.wait() onTurnStarted() - + if (battleConfig.addRaidTurnDelay){ battleConfig.raidTurnDelaySeconds.seconds.wait() } + + waitForENSubtitleDisappear() servantTracker.beginTurn() @@ -88,6 +93,25 @@ class Battle @Inject constructor( 0.5.seconds.wait() } + /** + * Waits up to 1.2 seconds for the English subtitle to disappear by checking if the 2nd servant slot becomes visible. + * If visible, adds a 250ms buffer delay before proceeding with servant tracking + * The subtitle usually blocks the 2nd servant [FieldSlot] + */ + private fun waitForENSubtitleDisappear() { + if (prefs.gameServer !is GameServer.En) { + return // only for EN servers + } + val exist = locations.battle.servantPresentRegion(FieldSlot.B).exists( + images[Images.ServantExist], + timeout = SUBTITLE_WAIT_TIMEOUT, + similarity = 0.70 + ) + if (exist) { + SUBTITLE_FIXED_DELAY.wait() + } + } + private fun shouldShuffle(cards: List, npUsage: NPUsage): Boolean { // Not this wave if (state.stage != (battleConfig.shuffleCardsWave - 1)) { @@ -124,4 +148,9 @@ class Battle @Inject constructor( autoChooseTarget.choose() } } + + companion object { + private val SUBTITLE_WAIT_TIMEOUT = 1.2.seconds + private val SUBTITLE_FIXED_DELAY = 250.milliseconds + } }