Skip to content

Commit

Permalink
Fix combat report breaking when not enough exp 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
waicool20 committed Dec 5, 2023
1 parent 1703176 commit 8c19a17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class Navigator(
logger.info("Detected daily login/event screen, dismissing...")
login.click()
}
region.subRegion(900, 720, 350, 185)
region.subRegion(780, 720, 350, 185)
.findBest(FT("close.png"))?.region?.click()
if (locations.getValue(LocationId.HOME).isInRegion(region)) {
logger.info("Logged in, waiting for 10s to see if anything happens")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ package com.waicool20.wai2k.script.modules

import com.waicool20.cvauto.core.template.FT
import com.waicool20.cvauto.core.template.FileTemplate
import com.waicool20.cvauto.core.util.countColor
import com.waicool20.cvauto.core.util.pipeline
import com.waicool20.wai2k.config.Wai2kProfile.CombatReport
import com.waicool20.wai2k.events.CombatReportWriteEvent
import com.waicool20.wai2k.events.EventBus
Expand All @@ -34,7 +32,6 @@ import com.waicool20.wai2k.util.formatted
import com.waicool20.wai2k.util.loggerFor
import com.waicool20.wai2k.util.readText
import kotlinx.coroutines.delay
import java.awt.Color
import java.time.Instant

@Suppress("unused")
Expand Down Expand Up @@ -73,10 +70,8 @@ class CombatReportModule(navigator: Navigator) : ScriptModule(navigator) {
region.subRegion(1389, 567, 277, 86).click()
delay(800)

val expCapture = region.subRegion(1346, 542, 116, 45)
.capture().img.pipeline().threshold(0.2)
.toBufferedImage()
if (expCapture.countColor(Color.WHITE) > 10) {

if (!hasSufficientExp()) {
logger.info("Not enough exp to write reports!")
region.subRegion(947, 699, 268, 102).click() // Cancel
delay(500)
Expand Down Expand Up @@ -136,6 +131,16 @@ class CombatReportModule(navigator: Navigator) : ScriptModule(navigator) {
return batts >= 240
}

private fun hasSufficientExp(): Boolean {
val expText = ocr.digitsOnly().readText(region.subRegion(1345, 542, 162, 45))
logger.info("Exp OCR: $expText")
val exp = expText.toIntOrNull() ?: run {
logger.warn("Could not read exp count, assuming not enough exp")
return false
}
return exp > 3000
}

private fun scheduleNextCheck() {
gameState.reportsNextCheck = Instant.now().plusSeconds(3600)
logger.info("Next combat report check is in one hour (${gameState.reportsNextCheck.formatted()})")
Expand Down

0 comments on commit 8c19a17

Please sign in to comment.