From f8d2bc936db8c5392579cd5725072e3351ad9938 Mon Sep 17 00:00:00 2001 From: dtookey Date: Sat, 29 Jul 2023 09:39:43 -0400 Subject: [PATCH] initial commit --- .gitignore | 3 + src/main/kotlin/Entry.kt | 330 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 333 insertions(+) create mode 100644 .gitignore create mode 100644 src/main/kotlin/Entry.kt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c3487e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +out/ +FallFinal.iml \ No newline at end of file diff --git a/src/main/kotlin/Entry.kt b/src/main/kotlin/Entry.kt new file mode 100644 index 0000000..ff035de --- /dev/null +++ b/src/main/kotlin/Entry.kt @@ -0,0 +1,330 @@ +import java.awt.MouseInfo +import java.awt.Point +import java.awt.Robot +import java.awt.event.InputEvent +import java.awt.event.KeyEvent +import java.util.concurrent.TimeUnit +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) +} + +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