Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to wait for AP at the last run #1906

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
Expand Up @@ -531,6 +531,11 @@ class AutoBattle @Inject constructor(
inventoryFull -> throw BattleExitException(ExitReason.InventoryFull)
}

refill.refill()
val isLastRun = prefs.selectedServerConfigPref.shouldLimitRuns &&
(prefs.selectedServerConfigPref.limitRuns - state.runs) <= 1

refill.refill(
isLastRun = isLastRun
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.github.fate_grand_automata.scripts.IFgoAutomataApi
import io.github.fate_grand_automata.scripts.Images
import io.github.fate_grand_automata.scripts.ScriptNotify
import io.github.fate_grand_automata.scripts.entrypoints.AutoBattle
import io.github.fate_grand_automata.scripts.prefs.IPerServerConfigPrefs
import io.github.lib_automata.dagger.ScriptScope
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds
Expand All @@ -19,34 +20,61 @@ class Refill @Inject constructor(
* Refills the AP with apples depending on preferences.
* If needed, loops and wait for AP regeneration
*/
private fun refillOnce() {
private fun refillOnce(
isLastRun: Boolean = false
) {
val perServerConfigPref = prefs.selectedServerConfigPref

if (perServerConfigPref.resources.isNotEmpty()
&& timesRefilled < perServerConfigPref.currentAppleCount
) {
//TODO check for OK image between each resource
perServerConfigPref.resources
.flatMap { locations.locate(it) }
.forEach { it.click() }
when {
/**
* If the user has resources to refill and has the wait for AP regen option enabled
* and this is the last run, wait for AP regen instead of refilling.
*/
perServerConfigPref.waitForAPRegen && isLastRun -> waitForAPRegen()
/**
* If the user has resources to refill and has not reached the current apple count,
*/
perServerConfigPref.resources.isNotEmpty() && timesRefilled < perServerConfigPref.currentAppleCount -> {
refillAP(perServerConfigPref = perServerConfigPref)
}
/**
* wait for AP regen if the user has the wait for AP regen option enabled
*/

1.seconds.wait()
locations.staminaOkClick.click()
++timesRefilled
perServerConfigPref.waitForAPRegen -> waitForAPRegen()

3.seconds.wait()
} else if (perServerConfigPref.waitForAPRegen) {
locations.staminaCloseClick.click()
else -> throw AutoBattle.BattleExitException(AutoBattle.ExitReason.APRanOut)
}
}

private fun refillAP(perServerConfigPref: IPerServerConfigPrefs) {
//TODO check for OK image between each resource
perServerConfigPref.resources
.flatMap { locations.locate(it) }
.forEach { it.click() }

1.seconds.wait()
locations.staminaOkClick.click()
++timesRefilled

3.seconds.wait()
}

private fun waitForAPRegen() {
locations.staminaCloseClick.click()

messages.notify(ScriptNotify.WaitForAPRegen())
messages.notify(ScriptNotify.WaitForAPRegen())

60.seconds.wait()
} else throw AutoBattle.BattleExitException(AutoBattle.ExitReason.APRanOut)
60.seconds.wait()
}

fun refill() {
fun refill(
isLastRun: Boolean = false
) {
if (images[Images.Stamina] in locations.staminaScreenRegion) {
refillOnce()
refillOnce(
isLastRun = isLastRun
)
}
}

Expand Down