Skip to content

Commit

Permalink
More log scraping enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
waicool20 committed Jul 31, 2024
1 parent e1a3a23 commit 03275d3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ interface ScriptComponent {
*/
suspend fun waitForLog(
str: String,
period: Long = -1,
timeout: Long = Long.MAX_VALUE,
fnMaxIter: Int = Int.MAX_VALUE,
fn: suspend () -> Unit = {}
): Boolean {
val job = scriptRunner.sessionScope.launch {
delay(250)
while (coroutineContext.isActive) fn()
delay(300)
var i = 0
while (coroutineContext.isActive && i++ < fnMaxIter) {
fn()
if (period > 0) delay(period)
}
}
try {
withTimeout(timeout) {
Expand All @@ -73,12 +79,18 @@ interface ScriptComponent {
*/
suspend fun waitForLog(
regex: Regex,
period: Long = -1,
timeout: Long = Long.MAX_VALUE,
fnMaxIter: Int = Int.MAX_VALUE,
fn: suspend () -> Unit = {}
): Boolean {
val job = scriptRunner.sessionScope.launch {
delay(250)
while (coroutineContext.isActive) fn()
var i = 0
while (coroutineContext.isActive && i++ < fnMaxIter) {
fn()
if (period > 0) delay(period)
}
}
try {
withTimeout(timeout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,16 @@ class CombatModule(navigator: Navigator) : ScriptModule(navigator) {
val startTime = System.currentTimeMillis()
logger.info("Switching doll $slot of echelon 1")
// Dragger region ( excludes stuff below name/type )
region.subRegion(237, 206, 247, 544).click(); yield()
region.waitHas(FT("doll-list/lock.png"), 5000)
waitForLog("CommonCharacterMemberSelection", fnMaxIter = 1) {
region.subRegion(237, 206, 247, 544).click()
}

// Click doll
region.subRegion(64 + (slot - 1) * 297, 917, 133, 131).click()
// Click search
region.subRegion(1648, 820, 262, 46).click()
region.waitHas(FT("formation/clear.png"))
waitForLog("SearchCharacterController", fnMaxIter = 1) {
region.subRegion(1648, 820, 262, 46).click()
}
// Type in text box
region.subRegion(562, 507, 723, 73).click()
delay(750)
Expand All @@ -194,10 +196,11 @@ class CombatModule(navigator: Navigator) : ScriptModule(navigator) {
delay(500)

// Click search
region.subRegion(964, 709, 454, 85).clickWhile(period = 1000) {
region.doesntHave(FT("doll-list/lock.png"))
waitForLog("异步获取对象DaBao", fnMaxIter = 1) {
region.subRegion(964, 709, 454, 85).click()
}
delay(3000)

delay(1000)

val switchDoll = region.findBest(FT("doll-list/echelon2-captain.png"))
?.region?.copy(width = 142)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import com.waicool20.wai2k.game.MapRunnerRegions
import com.waicool20.wai2k.script.ScriptComponent
import com.waicool20.wai2k.script.ScriptTimeOutException
import com.waicool20.wai2k.util.*
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
Expand Down Expand Up @@ -554,7 +553,7 @@ abstract class MapRunner(
}
delay(500)
}
delay(5000)
delay(1000)
EventBus.publish(
SortieDoneEvent(
profile.combat.map,
Expand Down Expand Up @@ -628,62 +627,22 @@ abstract class MapRunner(
private suspend fun clickThroughBattle() {
logger.info("Entered battle $_battles")
onEnterBattleListener()
// Delay to stop COOL Beach fairy BG change from triggering battle counter
delay(4000)
// Wait until it disappears
while (coroutineContext.isActive && isInBattle()) delay(500)
waitForLog("异步获取对象DaBao")
logger.info("Battle ${_battles++} complete, clicking through battle results")
// Animation and load wheel until you can click through results/drops
delay(Random.nextLong(1100, 1300))
val l = mapRunnerRegions.battleEndClick.randomPoint()
var counter = 0
val now = System.currentTimeMillis()
loop@ while (true) {
val cache = region.freeze()
val sample = cache.pickColor(30, 1037)
if (sample.isSimilar(Color(18, 18, 15)) &&
cache.pickColor(680, 480).isSimilar(Color(221, 220, 72))
) {
logger.info("Clicked until transition ($counter times)")
break@loop
}
if (sample.isSimilar(Color(195, 44, 88))) {
logger.info("Clicked until map ($counter times)")
break@loop
}
if (config.scriptConfig.maxPostBattleClick != -1) {
if (counter >= config.scriptConfig.maxPostBattleClick) {
logger.info("Clicked max times ($counter times)")
break@loop
}
}
if (System.currentTimeMillis() - now > 10000) {
logger.info("Clicked until timeout ($counter times)")
break@loop
}
waitForLog("跳转场景Deployment") {
region.subRegion(l.x, l.y, 20, 20).click()
region.findBest(FT("combat/battle/cancel.png"))?.region?.click()
++counter
}
region.findBest(FT("combat/battle/cancel.png"))?.region?.click()
onFinishBattleListener()
}

private fun isInBattle() =
mapRunnerRegions.pauseButton.has(FT("combat/battle/pause.png", 0.9))

protected suspend fun openEchelon(node: MapNode) {
val r = node.findRegion()
val sr = region.subRegion(1234, 900, 640, 130)

try {
r.clickWhile(period = 2500, timeout = 30000) {
sr.doesntHave(FT("cancel-deploy.png"))
}
} catch (e: TimeoutCancellationException) {
throw ScriptTimeOutException("Opening echelon", e)
waitForLog("异步获取对象DaBao", 1000) {
node.findRegion().click()
}

if (node.type == MapNode.Type.HeavyHeliport && gameState.requiresMapInit) {
mapRunnerRegions.chooseEchelon.click(); delay(2000)
}
Expand Down

0 comments on commit 03275d3

Please sign in to comment.