Skip to content

Commit

Permalink
Improved out of lotto currency detection (#1792)
Browse files Browse the repository at this point in the history
Co-authored-by: arthur <[email protected]>
  • Loading branch information
ArthurKun21 and ArthurKun21 authored Apr 5, 2024
1 parent 54cb493 commit bf36219
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 35 deletions.
Binary file removed app/src/main/assets/En/lottery_lineup_updated.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class ImageLoader @Inject constructor(
Images.Retry -> "retry.png"
Images.Withdraw -> "withdraw.png"
Images.LotteryBoxFinished -> "lottery.png"
Images.LotteryLineupUpdated -> "lottery_lineup_updated.png"
Images.LotteryTransition -> "lottery_transition.png"
Images.PresentBoxFull -> "StopGifts.png"
Images.MasterExp -> "master_exp.png"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ enum class Images {
Retry,
Withdraw,
LotteryBoxFinished,
LotteryLineupUpdated,
LotteryTransition,
PresentBoxFull,
MasterExp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,13 @@ class AutoLottery @Inject constructor(

moveToPresentBox?.region?.click()

1.seconds.wait()
3.seconds.wait()
giftBox.script()
}

throw ExitException(ExitReason.PresentBoxFull)
}

private fun isOutOfCurrency() = images[Images.LotteryBoxFinished] in locations.lottery.finishedRegion

private fun ranOutOfCurrency() {
// this can also be triggered before the notification about a new box happens
// tap any dialog away, then check for the message
spin()
if (isNewLineup()) {
confirmNewLineup()
} else if (isOutOfCurrency()) {
throw ExitException(ExitReason.RanOutOfCurrency)
}
}

private fun isNewLineup() =
images[Images.LotteryLineupUpdated] in locations.lottery.lineupUpdatedRegion

private fun confirmNewLineup() {
locations.lottery.confirmNewLineupClick.click()
}

private fun isTransition() = images[Images.LotteryTransition] in locations.lottery.transitionRegion


Expand All @@ -75,18 +55,30 @@ class AutoLottery @Inject constructor(
)

private fun confirmIfLotteryDone() {
spin()

val exist = isLotteryDone()
if (exist) {
throw ExitException(ExitReason.RanOutOfCurrency)
run verify@{
repeat(2) {
if (connectionRetry.needsToRetry()) {
connectionRetry.retry()
}
spin()
val falseDetection = locations.lottery.doneRegion.waitVanish(
images[Images.LotteryBoxFinished],
timeout = 5.seconds,
similarity = 0.85
)
if (falseDetection) {
return@verify
}
}
val exist = isLotteryDone()
if (exist) {
throw ExitException(ExitReason.RanOutOfCurrency)
}
}
}

override fun script(): Nothing {
val screens: Map<() -> Boolean, () -> Unit> = mapOf(
{ isNewLineup() } to { confirmNewLineup() },
{ isOutOfCurrency() } to { ranOutOfCurrency() },
{ connectionRetry.needsToRetry() } to { connectionRetry.retry() },
{ images[Images.PresentBoxFull] in locations.lottery.fullPresentBoxRegion } to { presentBoxFull() },
{ isLotteryDone() } to { confirmIfLotteryDone() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ class LotteryLocations @Inject constructor(
) : IScriptAreaTransforms by scriptAreaTransforms {
val finishedRegion = Region(-510, 700, 55, 100).xFromCenter()
val checkRegion = Region(-1130, 700, 675, 330).xFromCenter()
val spinClick = Location(-446, 860).xFromCenter()
val spinClick = Location(-646, 860).xFromCenter()
val fullPresentBoxRegion = Region(20, 860, 1000, 500).xFromCenter()
val lineupUpdatedRegion = Region(-320, 360, 640, 100).xFromCenter()

// center of screen
val confirmNewLineupClick = Location(1280, 720)

val doneRegion = Region(-510, 700, 60, 90).xFromCenter()

Expand Down

0 comments on commit bf36219

Please sign in to comment.