From bf71b3a66e2a3e15643199a2232809a838b0a278 Mon Sep 17 00:00:00 2001 From: dtookey Date: Sat, 29 Jul 2023 10:30:14 -0400 Subject: [PATCH] reorg --- src/main/kotlin/Doer.kt | 125 ++++++++++++++ src/main/kotlin/Entry.kt | 319 +----------------------------------- src/main/kotlin/Routines.kt | 84 ++++++++++ src/main/kotlin/Tasks.kt | 113 +++++++++++++ 4 files changed, 323 insertions(+), 318 deletions(-) create mode 100644 src/main/kotlin/Doer.kt create mode 100644 src/main/kotlin/Routines.kt create mode 100644 src/main/kotlin/Tasks.kt diff --git a/src/main/kotlin/Doer.kt b/src/main/kotlin/Doer.kt new file mode 100644 index 0000000..92dd786 --- /dev/null +++ b/src/main/kotlin/Doer.kt @@ -0,0 +1,125 @@ +import java.awt.MouseInfo +import java.awt.Point +import java.awt.Robot +import java.util.concurrent.TimeUnit +import kotlin.math.ceil +import kotlin.random.Random + +class Doer(val r: Robot) { + + companion object { + val xWiggle = 15; + val yWiggle = 15; + } + + public fun doLoop(volume: Int, step: Int, task: (Doer)->Unit){ + val r = Doer(Robot()) + val totalSteps =(ceil((volume/step).toDouble()) +1).toInt() + + val start = System.currentTimeMillis() + for(i in 0 until totalSteps){ + report(i+1, totalSteps, System.currentTimeMillis() - start) + task(this) + } + + val finish = System.currentTimeMillis() + println("Finished everything in ${prettyTimeString(finish - start)}") + r.drawStar(getPointerLocationAfter(0)) + } + + fun report (step: Int, of: Int, dur:Long){ + val remaining = (dur/step) * (of-step) + print("\rStep $step of $of (${prettyTimeString(dur)} complete\t|\t~${prettyTimeString(remaining)} remaining) ") + } + + private fun prettyTimeString(remaining: Long): String{ + if (remaining == 0L){ + return "No time data yet" + } + val sec = 1000L + val min = 60L * sec + val hour = 60L * min + return if(remaining>hour){ + return "${remaining/hour}h${(remaining%hour)/min}m${(remaining%min)/sec}s" + }else if (remaining > min){ + return "${(remaining%hour)/min}m${(remaining%min)/sec}s" + }else{ + "${(remaining%min)/sec}s" + } + } + + fun mouseMove(p: Point){ + r.mouseMove(p.x, p.y) + } + + fun click(buttons: Int) { + r.mousePress(buttons) + sleep(Random.nextInt(4, 8).toLong()) + r.mouseRelease(buttons) + } + + fun keypress(buttons: Int) { + r.keyPress(buttons) + sleep(Random.nextInt(4, 8).toLong()) + r.keyRelease(buttons) + } + + fun getAlmostPoint(p: Point): Point { + val xDel = Random.nextInt(0, xWiggle) + val yDel = Random.nextInt(0, yWiggle) + val xDir = if (Random.nextDouble() > 0.5) { + 1 + } else { + -1 + } + val yDir = if (Random.nextDouble() > 0.5) { + 1 + } else { + -1 + } + return Point(p.x + (xDel * xDir), p.y + (yDel + yDir)) + } + + fun sleep(dur: Long) { + TimeUnit.MILLISECONDS.sleep(dur) + } + + fun sleep(dur: Long, min: Long, max: Long) { + val dSize = (max-min)/2 + val r1 = Random.nextLong(dSize) + val r2 = Random.nextLong(dSize) + TimeUnit.MILLISECONDS.sleep(dur+r1+r2) + } + + fun scrollOut(){ + r.mouseWheel(1) + sleep(100, 50, 100) + } + + fun getPointerLocationAsValDeclarationString(varName: String) { + TimeUnit.SECONDS.sleep(5) + val info = MouseInfo.getPointerInfo().location + println("val ${varName} = Point(${info.x}, ${info.y})") + } + + fun getPointerLocationAfter(delay: Long): Point { + sleep(delay) + return MouseInfo.getPointerInfo().location + } + + fun drawStar(p: Point){ + val offset = 100 + val top = Point(p.x, p.y - offset*2) + val topright = Point(p.x+offset, p.y + offset) + val bottomright = Point(p.x+offset, p.y) + val topleft = Point(p.x-offset, p.y + offset) + val bottomleft = Point(p.x-offset, p.y) + val points = arrayListOf(top, bottomleft, topright, topleft, bottomright) + for(i in 0 until 3){ + for(point in points){ + mouseMove(point) + sleep(200) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/Entry.kt b/src/main/kotlin/Entry.kt index ff035de..f29feef 100644 --- a/src/main/kotlin/Entry.kt +++ b/src/main/kotlin/Entry.kt @@ -8,323 +8,6 @@ import kotlin.math.ceil import kotlin.random.Random fun main() { -// cleanHerbs(638, 28) - potionGrind(1580, 14) -// potionGrindWithWell(110, 14) -// supremeOverloadGrind(24, 4) - -// furnaceGrind(1100, 28) -// planks() -// frames(329, 27) + Routines.potionGrindWithWell(5100, 14) } -fun potionGrind(volume: Int, step: Int){ - val r = Doer(Robot()) - val totalSteps =(ceil((volume/step).toDouble()) +1).toInt() -// r.getPointerLocation() -// val chest = Point(1039, 511) - val chest = r.getPointerLocationAfter(3000L) - val start = System.currentTimeMillis() - for(i in 0 until totalSteps){ - r.report(i+1, totalSteps, System.currentTimeMillis() - start) - r.makePotions(chest) - } - - val finish = System.currentTimeMillis() - println("Finished everything in ${(finish.toDouble() - start.toDouble())/1000.00}s") - r.drawStar(chest) -} - -fun cleanHerbs(volume: Int, step: Int){ - val r = Doer(Robot()) - val totalSteps =(ceil((volume/step).toDouble()) +1).toInt() - println("Put your mouse over the chest...") - val chest = r.getPointerLocationAfter(3000L) - val start = System.currentTimeMillis() - for(i in 0 until totalSteps){ - r.report(i+1, totalSteps, System.currentTimeMillis() - start) - r.cleanHerbs(chest) - } - - val finish = System.currentTimeMillis() - println("Finished everything in ${(finish.toDouble() - start.toDouble())/1000.00}s") - r.drawStar(chest) -} - -fun potionGrindWithWell(volume: Int, step: Int){ - val r = Doer(Robot()) - val totalSteps =(ceil((volume/step).toDouble()) +1).toInt() - println("Put your mouse over the chest...") - val chest = r.getPointerLocationAfter(3000L) - println("Put your mouse over the Well...") - val well = r.getPointerLocationAfter(3000L) - val start = System.currentTimeMillis() - for(i in 0 until totalSteps){ - r.report(i+1, totalSteps, System.currentTimeMillis() - start) - r.makePotions(chest, well) - } - - val finish = System.currentTimeMillis() - println("Finished everything in ${(finish.toDouble() - start.toDouble())/1000.00}s") - r.drawStar(chest) -} - -fun furnaceGrind(volume: Int, step: Int){ - val r = Doer(Robot()) - val totalSteps =(ceil((volume/step).toDouble()) +1).toInt() - for(i in 0 until 8){ - r.scrollOut() - } - //i think this is a zoom of 6? -// r.getPointerLocation("furnaceFromChest") -// r.getPointerLocation("chestFromFurance") - - val start = System.currentTimeMillis() - - val furnaceFromChest = Point(776, 321) - val chestFromFurance = Point(1713, 843) - for(i in 0 until totalSteps){ - r.report(i+1, totalSteps, System.currentTimeMillis() - start) - r.doFurnaceRun(furnaceFromChest, chestFromFurance) - } -} - -fun frames(volume: Int, step: Int){ - val r = Doer(Robot()) - val totalSteps =(ceil((volume/step).toDouble()) +1).toInt() - r.sleep(1000) - for(i in 0 until 8){ - r.scrollOut() - } - //i think this is a zoom of 6? -// r.getPointerLocation("sawFromChest") -// r.getPointerLocation("chestFromSaw") - - val start = System.currentTimeMillis() - - val sawFromChest = Point(1079, 907) - val chestFromSaw = Point(1226, 180) - for(i in 0 until totalSteps){ - r.report(i+1, totalSteps, System.currentTimeMillis() - start) - r.makeFrame(sawFromChest, chestFromSaw) - } -} - -fun supremeOverloadGrind(volume: Int, step: Int){ - val r = Doer(Robot()) - val totalSteps =(ceil((volume/step).toDouble()) +1).toInt() -// r.getPointerLocation() -// r.getPointerLocation() - val wellPoint = Point(1151, 676) - val chestPoint = Point(1067, 443) - val start = System.currentTimeMillis() - for(i in 0 until totalSteps){ - r.report(i+1, totalSteps, System.currentTimeMillis() - start) - r.makeSupremeOverload(wellPoint, chestPoint) - } -} - -class Doer(val r: Robot) { - - companion object { - val xWiggle = 5; - val yWiggle = 5; - } - - fun report (step: Int, of: Int, dur:Long){ - val remaining = (dur/step) * (of-step) - print("\rStep $step of $of (${prettyTimeString(dur)} complete\t|\t~${prettyTimeString(remaining)} remaining) ") - } - - private fun prettyTimeString(remaining: Long): String{ - if (remaining == 0L){ - return "No time data yet" - } - val sec = 1000L - val min = 60L * sec - val hour = 60L * min - return if(remaining>hour){ - return "${remaining/hour}h${(remaining%hour)/min}m${(remaining%min)/sec}s" - }else if (remaining > min){ - return "${(remaining%hour)/min}m${(remaining%min)/sec}s" - }else{ - "${(remaining%min)/sec}s" - } - } - - fun doFurnaceRun(furnaceFromChest: Point, chestFromFurnace: Point){ - val fur = getAlmostPoint(furnaceFromChest) - val bank = getAlmostPoint(chestFromFurnace) - r.mouseMove(fur.x, fur.y) - - click(InputEvent.BUTTON1_DOWN_MASK) - sleep(2800, 200, 800) - keypress(KeyEvent.VK_SPACE) - sleep(53000,200, 800) - r.mouseMove(bank.x, bank.y) - sleep(100, 10, 200) - click(InputEvent.BUTTON1_DOWN_MASK) - sleep(2800, 200, 1200) - keypress(KeyEvent.VK_F6) - sleep(600, 200, 600) - } - - fun cleanHerbs(chest: Point) { - mouseMove(chest) - sleep(100, 0, 100) - click(InputEvent.BUTTON1_DOWN_MASK) - sleep(600, 0, 800) - keypress(KeyEvent.VK_F6) - sleep(600, 0, 800) - keypress(KeyEvent.VK_EQUALS) - sleep(600, 0, 800) - } - - fun makePotions(chest: Point) { - val duration = 17000L - val firstClickPoint = getAlmostPoint(chest) - r.mouseMove(firstClickPoint.x, firstClickPoint.y) - click(InputEvent.BUTTON1_DOWN_MASK) - sleep(Random.nextInt(1300, 1600).toLong()) - keypress(KeyEvent.VK_F6) - sleep(Random.nextInt(1000, 1500).toLong()) - keypress(KeyEvent.VK_EQUALS) - val sleepDur = Random.nextInt(1000, 1500).toLong() - sleep(sleepDur) - keypress(KeyEvent.VK_SPACE) - if (sleepDur < 1200) { - sleep(Random.nextInt(600, 1200).toLong()) - keypress(KeyEvent.VK_SPACE) - } - sleep(duration + Random.nextInt(1000).toLong()) - } - - fun makePotions(chest: Point, well: Point) { - val duration = 17000L - val firstClickPoint = getAlmostPoint(chest) - r.mouseMove(firstClickPoint.x, firstClickPoint.y) - click(InputEvent.BUTTON1_DOWN_MASK) - sleep(Random.nextInt(1300, 1600).toLong()) - keypress(KeyEvent.VK_F6) - sleep(Random.nextInt(1000, 1500).toLong()) - - mouseMove(well) - sleep(100, 0, 50) - click(InputEvent.BUTTON1_DOWN_MASK) - - sleep(1500, 0, 1000) - - keypress(KeyEvent.VK_SPACE) - - sleep(duration + Random.nextInt(1000).toLong()) - } - - fun makeSupremeOverload(well: Point, chest: Point){ - //going to chest - mouseMove(getAlmostPoint(chest)) - sleep(100) - click(InputEvent.BUTTON1_DOWN_MASK) - sleep(1500, 1000, 2000) - //selecting setup - keypress(KeyEvent.VK_F6) - sleep(1000, 1500, 2000) - //going to well - mouseMove(getAlmostPoint(well)) - sleep(100) - click(InputEvent.BUTTON1_DOWN_MASK) - sleep(1600, 1000, 1800) - //combining potions - keypress(KeyEvent.VK_SPACE) - sleep(5500, 1000, 2000) - } - - fun makeFrame(sawFromChest: Point, chestFromSaw: Point){ - mouseMove(sawFromChest) - sleep(100, 0, 50) - click(InputEvent.BUTTON1_DOWN_MASK) - sleep(2200, 500, 1000) - keypress(KeyEvent.VK_SPACE) - sleep(63000, 1000, 2000) - mouseMove(chestFromSaw) - sleep(100, 0, 50) - click(InputEvent.BUTTON1_DOWN_MASK) - sleep(2200, 500, 1000) - keypress(KeyEvent.VK_F6) - sleep(1200, 0, 500) - } - - fun mouseMove(p: Point){ - r.mouseMove(p.x, p.y) - } - - private fun click(buttons: Int) { - r.mousePress(buttons) - sleep(Random.nextInt(4, 8).toLong()) - r.mouseRelease(buttons) - } - - private fun keypress(buttons: Int) { - r.keyPress(buttons) - sleep(Random.nextInt(4, 8).toLong()) - r.keyRelease(buttons) - } - - private fun getAlmostPoint(p: Point): Point { - val xDel = Random.nextInt(0, xWiggle) - val yDel = Random.nextInt(0, yWiggle) - val xDir = if (Random.nextDouble() > 0.5) { - 1 - } else { - -1 - } - val yDir = if (Random.nextDouble() > 0.5) { - 1 - } else { - -1 - } - return Point(p.x + (xDel * xDir), p.y + (yDel + yDir)) - } - - fun sleep(dur: Long) { - TimeUnit.MILLISECONDS.sleep(dur) - } - - fun sleep(dur: Long, min: Long, max: Long) { - val dSize = (max-min)/2 - val r1 = Random.nextLong(dSize) - val r2 = Random.nextLong(dSize) - TimeUnit.MILLISECONDS.sleep(dur+r1+r2) - } - - fun scrollOut(){ - r.mouseWheel(1) - sleep(100, 50, 100) - } - - fun getPointerLocation(varName: String) { - TimeUnit.SECONDS.sleep(5) - val info = MouseInfo.getPointerInfo().location - println("val ${varName} = Point(${info.x}, ${info.y})") - } - - fun getPointerLocationAfter(delay: Long): Point{ - sleep(delay) - return MouseInfo.getPointerInfo().location - } - - fun drawStar(p: Point){ - val offset = 100 - val top = Point(p.x, p.y - offset*2) - val topright = Point(p.x+offset, p.y + offset) - val bottomright = Point(p.x+offset, p.y) - val topleft = Point(p.x-offset, p.y + offset) - val bottomleft = Point(p.x-offset, p.y) - val points = arrayListOf(top, bottomleft, topright, topleft, bottomright) - for(i in 0 until 3){ - for(point in points){ - r.mouseMove(point.x, point.y) - sleep(200) - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/Routines.kt b/src/main/kotlin/Routines.kt new file mode 100644 index 0000000..46482e7 --- /dev/null +++ b/src/main/kotlin/Routines.kt @@ -0,0 +1,84 @@ +import java.awt.Point +import java.awt.Robot + +object Routines { + + fun cleanHerbs(volume: Int, step: Int){ + val r = Doer(Robot()) + println("Put your mouse over the bank...") + val chest = r.getPointerLocationAfter(3000L) + r.doLoop(volume, step){ + Tasks.cleanHerbs(it, chest) + } + + } + + fun potionGrind(volume: Int, step: Int){ + val r = Doer(Robot()) + println("Put your mouse over the bank...") + val chest = r.getPointerLocationAfter(3000L) + r.doLoop(volume, step){ + Tasks.makePotions(it, chest) + } + } + + fun potionGrindWithWell(volume: Int, step: Int){ + val r = Doer(Robot()) + + println("Put your mouse over the bank...") + val chest = r.getPointerLocationAfter(3000L) + println("Put your mouse over the well...") + val well = r.getPointerLocationAfter(3000L) + r.doLoop(volume, step){ + Tasks.makePotions(it, chest, well) + } + } + + fun furnaceGrind(volume: Int, step: Int){ + val r = Doer(Robot()) + println("Reset the camera and zoom in") + r.sleep(1000) + + for(i in 0 until 8){ + r.scrollOut() + } + + val furnaceFromChest = Point(776, 321) + val chestFromFurance = Point(1713, 843) + + r.doLoop(volume, step){ + Tasks.doFurnaceRun(it, furnaceFromChest, chestFromFurance) + } + + + } + + fun frames(volume: Int, step: Int){ + println("You must zoom in all the way and have the compass pointing straight N with a completely top-down view") + val r = Doer(Robot()) + r.sleep(1000) + for(i in 0 until 8){ + r.scrollOut() + } + + val sawFromChest = Point(1079, 907) + val chestFromSaw = Point(1226, 180) + r.doLoop(volume, step){ + Tasks.makeFrame(it, sawFromChest, chestFromSaw) + } + } + + fun supremeOverloadGrind(volume: Int, step: Int){ + val r = Doer(Robot()) + println("Place mouse over chest") + val chestPoint = r.getPointerLocationAfter(3000L) + println("Place mouse over well") + val wellPoint = r.getPointerLocationAfter(3000L) + + r.doLoop(volume, step){ + Tasks.makeSupremeOverload(it, wellPoint, chestPoint) + } + + } + +} \ No newline at end of file diff --git a/src/main/kotlin/Tasks.kt b/src/main/kotlin/Tasks.kt new file mode 100644 index 0000000..3fd36a3 --- /dev/null +++ b/src/main/kotlin/Tasks.kt @@ -0,0 +1,113 @@ +import java.awt.Point +import java.awt.event.InputEvent +import java.awt.event.KeyEvent +import kotlin.random.Random + +object Tasks { + fun doFurnaceRun(d: Doer, furnaceFromChest: Point, chestFromFurnace: Point){ + d.mouseMove(d.getAlmostPoint(furnaceFromChest)) + + d.click(InputEvent.BUTTON1_DOWN_MASK) + d.sleep(2800, 200, 800) + d.keypress(KeyEvent.VK_SPACE) + d.sleep(53000,200, 800) + d.mouseMove(d.getAlmostPoint(chestFromFurnace)) + d.sleep(100, 10, 200) + d.click(InputEvent.BUTTON1_DOWN_MASK) + d.sleep(2800, 200, 1200) + d.keypress(KeyEvent.VK_F6) + d.sleep(600, 200, 600) + } + + fun cleanHerbs(d: Doer, chest: Point) { + d.mouseMove(chest) + d.sleep(100, 0, 100) + d.click(InputEvent.BUTTON1_DOWN_MASK) + d.sleep(600, 0, 800) + d.keypress(KeyEvent.VK_F6) + d.sleep(600, 0, 800) + d.keypress(KeyEvent.VK_EQUALS) + d.sleep(600, 0, 800) + } + + fun makePotions(d: Doer, chest: Point) { + d.mouseMove(d.getAlmostPoint(chest)) + d.click(InputEvent.BUTTON1_DOWN_MASK) + d.sleep(Random.nextInt(1300, 1600).toLong()) + + d.keypress(KeyEvent.VK_F6) + d.sleep(Random.nextInt(1000, 1500).toLong()) + + d.keypress(KeyEvent.VK_EQUALS) + val sleepDur = Random.nextInt(1000, 1500).toLong() + d.sleep(sleepDur) + + d.keypress(KeyEvent.VK_SPACE) + if (sleepDur < 1200) { + d.sleep(Random.nextInt(600, 1200).toLong()) + d.keypress(KeyEvent.VK_SPACE) + } + d.sleep(17000L, 500, 1000) + } + + fun makePotions(d: Doer, chest: Point, well: Point) { + d.mouseMove(d.getAlmostPoint(chest)) + d.click(InputEvent.BUTTON1_DOWN_MASK) + d.sleep(1000, 600, 1000) + + d.keypress(KeyEvent.VK_F6) + d.sleep(1000, 50, 500) + + d.mouseMove(well) + d.sleep(100, 0, 50) + + d.click(InputEvent.BUTTON1_DOWN_MASK) + d.sleep(1500, 0, 500) + + d.keypress(KeyEvent.VK_SPACE) + + d.sleep(18000L, 600, 1200) + } + + fun makeSupremeOverload(d: Doer, well: Point, chest: Point){ + //going to chest + d.mouseMove(d.getAlmostPoint(chest)) + d.sleep(100) + d.click(InputEvent.BUTTON1_DOWN_MASK) + d.sleep(1500, 1000, 2000) + //selecting setup + d.keypress(KeyEvent.VK_F6) + d.sleep(1000, 1500, 2000) + //going to well + d.mouseMove(d.getAlmostPoint(well)) + d.sleep(100) + d.click(InputEvent.BUTTON1_DOWN_MASK) + d.sleep(1600, 1000, 1800) + //combining potions + d.keypress(KeyEvent.VK_SPACE) + d.sleep(5500, 1000, 2000) + } + + fun makeFrame(d: Doer, sawFromChest: Point, chestFromSaw: Point){ + //standing at bank with full inv + d.mouseMove(sawFromChest) + d.sleep(100, 0, 50) + //run to saw + d.click(InputEvent.BUTTON1_DOWN_MASK) + d.sleep(2200, 500, 1000) + //start cutting frames + d.keypress(KeyEvent.VK_SPACE) + //waiting + d.sleep(63000, 1000, 2000) + d.mouseMove(chestFromSaw) + d.sleep(100, 0, 50) + //running to bank + d.click(InputEvent.BUTTON1_DOWN_MASK) + d.sleep(2200, 500, 1000) + d.keypress(KeyEvent.VK_F6) + d.sleep(1200, 0, 500) + //full inv + } + + +} \ No newline at end of file