Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
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
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
Expand Down Expand Up @@ -69,10 +72,12 @@ class Battle @Inject constructor(
prefs.waitBeforeTurn.wait()

onTurnStarted()

if (battleConfig.addRaidTurnDelay){
battleConfig.raidTurnDelaySeconds.seconds.wait()
}

waitForENSubtitleDisappear()

servantTracker.beginTurn()

Expand All @@ -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<ParsedCard>, npUsage: NPUsage): Boolean {
// Not this wave
if (state.stage != (battleConfig.shuffleCardsWave - 1)) {
Expand Down Expand Up @@ -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
}
}