Skip to content

Commit

Permalink
Fixes for new client UI
Browse files Browse the repository at this point in the history
  • Loading branch information
waicool20 committed May 21, 2024
1 parent 36abbc1 commit 4d14bb3
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 88 deletions.
2 changes: 1 addition & 1 deletion deps/CVAuto
Binary file modified modules/assets/combat/battle/normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/assets/factory/ok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/assets/formation/clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/assets/locations/landmarks/formation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified modules/assets/locations/landmarks/home_status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 8 additions & 15 deletions modules/assets/locations/locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,10 @@
"landmarks": [
{
"path": "locations/landmarks/home_status.png",
"x": 45,
"y": 735,
"width": 40,
"height": 40
},
{
"path": "locations/landmarks/home_status.png",
"x": 45,
"y": 904,
"width": 40,
"height": 40
"x": 1121,
"y": 510,
"width": 45,
"height": 45
}
],
"links": [
Expand Down Expand Up @@ -239,10 +232,10 @@
"landmarks": [
{
"path": "locations/landmarks/formation.png",
"x": 1670,
"y": 880,
"width": 60,
"height": 60
"x": 1222,
"y": 52,
"width": 55,
"height": 55
}
],
"links": [
Expand Down
2 changes: 1 addition & 1 deletion modules/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dependencies {
implementation("org.controlsfx:controlsfx:11.2.0")
implementation("org.reflections:reflections:0.10.2")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("ai.djl.pytorch:pytorch-engine:0.21.0")
implementation("ai.djl.pytorch:pytorch-engine:0.28.0")
implementation("com.github.ajalt.clikt:clikt-jvm:4.2.1")

implementation("net.sourceforge.tess4j", "tess4j", "5.8.0") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ class DollFilterRegions(region: AndroidRegion) {
* Map of 1-5 star rating and their regions
*/
val starRegions = mapOf(
6 to region.subRegion(797, 215, 256, 117),
5 to region.subRegion(1068, 215, 256, 117),
4 to region.subRegion(1339, 215, 256, 117),
3 to region.subRegion(797, 349, 256, 117),
2 to region.subRegion(1068, 349, 256, 117),
1 to region.subRegion(1339, 349, 256, 117)
6 to region.subRegion(797, 243, 256, 117),
5 to region.subRegion(1068, 243, 256, 117),
4 to region.subRegion(1339, 243, 256, 117),
3 to region.subRegion(797, 378, 256, 117),
2 to region.subRegion(1068, 378, 256, 117),
1 to region.subRegion(1339, 378, 256, 117)
)

/**
* Map of individual gun types and their regions
*/
val typeRegions = mapOf(
Type.HG to region.subRegion(797, 537, 256, 117),
Type.SMG to region.subRegion(1068, 537, 256, 117),
Type.RF to region.subRegion(1339, 537, 256, 117),
Type.AR to region.subRegion(797, 672, 256, 117),
Type.MG to region.subRegion(1068, 672, 256, 117),
Type.SG to region.subRegion(1339, 672, 256, 117)
Type.HG to region.subRegion(797, 565, 256, 117),
Type.SMG to region.subRegion(1068, 565, 256, 117),
Type.RF to region.subRegion(1339, 565, 256, 117),
Type.AR to region.subRegion(797, 700, 256, 117),
Type.MG to region.subRegion(1068, 700, 256, 117),
Type.SG to region.subRegion(1339, 700, 256, 117)
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MapRunnerRegions(region: AndroidRegion) {
/**
* Button that toggles planning mode
*/
val planningMode = region.subRegion(0, 857, 214, 60)
val planningMode = region.subRegion(0, 916, 214, 60)

/**
* Button that executes planned path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ class FactoryModule(navigator: Navigator) : ScriptModule(navigator) {
}

private enum class Count(val keyword: String, val yLabel: Int, val yCount: Int) {
DOLL("capa", 790, 840),
DOLL_D("capa", 763, 815),
DOLL("capa", 840, 787),
DOLL_D("capa", 818, 763),
EQUIP("equip", 763, 815)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ package com.waicool20.wai2k.script.modules.combat
import com.waicool20.cvauto.core.input.ITouchInterface
import com.waicool20.cvauto.core.template.FT
import com.waicool20.cvauto.core.template.FileTemplate
import com.waicool20.cvauto.core.template.ImageTemplate
import com.waicool20.cvauto.core.util.countColor
import com.waicool20.cvauto.core.util.isSimilar
import com.waicool20.cvauto.core.util.pipeline
import com.waicool20.wai2k.game.CombatMap
import com.waicool20.wai2k.game.TDoll
Expand All @@ -35,7 +33,10 @@ import com.waicool20.wai2k.script.modules.ScriptModule
import com.waicool20.wai2k.util.disableDictionaries
import com.waicool20.wai2k.util.loggerFor
import com.waicool20.wai2k.util.readText
import kotlinx.coroutines.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.withTimeout
import kotlinx.coroutines.yield
import java.awt.Color
import java.awt.image.BufferedImage
import java.text.DecimalFormat
Expand Down Expand Up @@ -171,54 +172,34 @@ 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 + (slot - 1) * 273, 206, 247, 544).click(); yield()
region.waitHas(FileTemplate("doll-list/lock.png"), 5000)

applyFilters(tdoll, false)
var switchDoll = region.findBest(FileTemplate("doll-list/echelon2-captain.png"))?.region

val r1 = region.subRegion(910, 1038, 500, 20)
val r2 = r1.copy(y = r1.y - 325)
val checkRegion = region.subRegion(185, 360, 60, 60)
region.subRegion(237, 206, 247, 544).click(); yield()
region.waitHas(FT("doll-list/lock.png"), 5000)

// 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"))
// Type in text box
region.subRegion(562, 507, 723, 73).type(tdoll.name)

region.subRegion(964, 709, 454, 85).clickWhile(period = 1000) {
region.doesntHave(FT("doll-list/lock.png"))
}
delay(3000)

var scrollDown = true
var checkImg: BufferedImage
val switchDoll = region.findBest(FT("doll-list/echelon2-captain.png"))
?.region?.copy(width = 142)

try {
withTimeout(90_000) {
val r = region.subRegion(46, 146, 1542, 934)
while (coroutineContext.isActive) {
if (region.pickColor(0, 300).isSimilar(Color(21, 21, 21))) {
// Exit doll profile screen if entered accidentally when emu lags while swiping
region.subRegion(120, 597, 132, 88).click()
delay(500)
continue
}
// Trying this to improve search reliability, maybe put this upstream in cvauto
switchDoll =
r.findBest(FileTemplate("doll-list/echelon2-captain.png", 0.85), 5)
.maxByOrNull { it.score }?.region
if (switchDoll == null) {
checkImg = checkRegion.capture().img
if (scrollDown) {
r1.swipeTo(r2, 500)
} else {
r2.swipeTo(r1, 500)
}
delay(2000)
if (checkRegion.has(ImageTemplate(checkImg))) {
logger.info("Reached ${if (scrollDown) "bottom" else "top"} of the list")
scrollDown = !scrollDown
}
} else break
}
}
} catch (e: TimeoutCancellationException) {
throw ReplacementDollNotFoundException()
if (switchDoll == null) {
logger.warn("Couldn't find doll to switch!")
} else {
switchDoll.click()
delay(200)
// Click OK
region.subRegion(1649, 929, 245, 112).click()
logger.info("Switching dolls took ${System.currentTimeMillis() - startTime} ms")
}

switchDoll?.copy(width = 142)?.click()
logger.info("Switching dolls took ${System.currentTimeMillis() - startTime} ms")
delay(1250)
}

Expand Down Expand Up @@ -253,7 +234,7 @@ class CombatModule(navigator: Navigator) : ScriptModule(navigator) {
// Temporary convenience class for storing doll regions
class DollRegions(nameImage: BufferedImage, hpImage: BufferedImage) {
val tdollOcr = ocr.disableDictionaries()
.readText(nameImage, threshold = 0.72, invert = true, scale = 0.8)
.readText(nameImage, threshold = 0.72, invert = true, scale = 0.8)
val tdoll = TDoll.lookup(config, tdollOcr)
val percent = run {
val image = hpImage.pipeline().threshold().toBufferedImage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ abstract class HomographyMapRunner(scriptComponent: ScriptComponent) : MapRunner
logger.debug("Preprocess: ${metrics.latestMetric("Preprocess").value.toLong() / 1000} ms")
logger.debug("Inference: ${metrics.latestMetric("Inference").value.toLong() / 1000} ms")
logger.debug("Postprocess: ${metrics.latestMetric("Postprocess").value.toLong() / 1000} ms")
logger.debug("Total: ${metrics.latestMetric("Total").value.toLong() / 1000} ms")
logger.debug("Prediction: ${metrics.latestMetric("Prediction").value.toLong() / 1000} ms")
mapH = prediction
prediction
} catch (e: TranslateException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,14 @@ abstract class MapRunner(
val now = System.currentTimeMillis()
loop@ while (true) {
val cache = region.freeze()
val sample = cache.pickColor(50, 1050)
if (sample.isSimilar(Color(16, 16, 16)) &&
cache.pickColor(680, 580).isSimilar(Color(222, 223, 74))
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(247, 0, 74))) {
if (sample.isSimilar(Color(195, 44, 88))) {
logger.info("Clicked until map ($counter times)")
break@loop
}
Expand Down Expand Up @@ -747,7 +747,7 @@ abstract class MapRunner(
*/
protected suspend fun enterPlanningMode() {
while (coroutineContext.isActive) {
if (region.pickColor(125, 890).isSimilar(Color.WHITE)) {
if (region.pickColor(125, mapRunnerRegions.planningMode.y).isSimilar(Color.WHITE)) {
logger.info("Entering planning mode")
mapRunnerRegions.planningMode.click()
delay((3000 * gameState.delayCoefficient).roundToLong())
Expand All @@ -766,6 +766,7 @@ abstract class MapRunner(
for (i in indices) {
logger.info("Selecting node ${nodes[i]}")
nodes[i].findRegion().click()
delay(200)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class HomographyViewer(
logger.debug("Preprocess: ${metrics.latestMetric("Preprocess").value.toLong() / 1000} ms")
logger.debug("Inference: ${metrics.latestMetric("Inference").value.toLong() / 1000} ms")
logger.debug("Postprocess: ${metrics.latestMetric("Postprocess").value.toLong() / 1000} ms")
logger.debug("Total: ${metrics.latestMetric("Total").value.toLong() / 1000} ms")
logger.debug("Prediction: ${metrics.latestMetric("Prediction").value.toLong() / 1000} ms")
imageView.image =
SwingFXUtils.toFXImage(renderStitching(image, screenshot, h), null)
} catch (e: Exception) {
Expand Down

0 comments on commit 4d14bb3

Please sign in to comment.