From 99e050822d1990db391e439914c4398b619e5511 Mon Sep 17 00:00:00 2001 From: dtookey Date: Thu, 3 Aug 2023 08:36:58 -0400 Subject: [PATCH] structure overhaul --- src/main/kotlin/Agent.kt | 102 +++++++++++++++++++++++++++++ src/main/kotlin/Doer.kt | 56 ++++++---------- src/main/kotlin/Entry.kt | 11 +--- src/main/kotlin/Routines.kt | 126 +++++++++++++++++++++++++----------- src/main/kotlin/Tasks.kt | 108 ------------------------------- 5 files changed, 210 insertions(+), 193 deletions(-) create mode 100644 src/main/kotlin/Agent.kt delete mode 100644 src/main/kotlin/Tasks.kt diff --git a/src/main/kotlin/Agent.kt b/src/main/kotlin/Agent.kt new file mode 100644 index 0000000..1621a0d --- /dev/null +++ b/src/main/kotlin/Agent.kt @@ -0,0 +1,102 @@ +import java.awt.Point +import java.awt.Robot +import java.awt.event.InputEvent +import java.awt.event.KeyEvent +import kotlin.math.ceil + +class Agent { + + companion object{ + const val F6 = KeyEvent.VK_F6 + const val Space = KeyEvent.VK_SPACE + const val Minus = KeyEvent.VK_MINUS + const val LeftClick = InputEvent.BUTTON1_DOWN_MASK + } + + val doer= Doer(Robot()) + + + fun doLoop(volume: Int, step: Int, task: (Agent)->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) + } + println() + val finish = System.currentTimeMillis() + println("Finished everything in ${prettyTimeString(finish - start)}") + r.drawStar(doer.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 bankStandForLoop( + chest: Point, + invHotkey: Int, + hotbarHotkey: Int, + waitDurationMillis: Long, + waitDurationVariance: Long + ) { + doer.moveMouseLeftClickAndSleep(doer.getAlmostPoint(chest), 900, 400) + doer.keypress(invHotkey) + doer.sleepForNTicks(1) + doer.keypress(hotbarHotkey) + doer.sleepForNTicks(1) + doer.keypress(Space) + doer.sleep(waitDurationMillis, waitDurationVariance) + } + + fun bankStandWithoutDialog(chest: Point){ + doer.mouseMove(chest) + doer.moveMouseLeftClickAndSleep(doer.getAlmostPoint(chest), 900, 400) + doer.keypress(F6) + doer.sleepForNTicks(1) + doer.keypress(Minus) + doer.sleepForNTicks(1) + } + + fun processAtStationNearBank( + chest: Point, + station: Point, + invHotkey: Int, + travelDurationMillis: Long, + travelDurationVariance: Long, + waitDurationMillis: Long, + waitDurationVariance: Long + ) { + //click on chest + doer.moveMouseLeftClickAndSleep(doer.getAlmostPoint(chest), travelDurationMillis, travelDurationVariance) + + //select pre-stored inventory + doer.keypress(invHotkey) + doer.sleepForNTicks(1) + + //move to newLocation + doer.moveMouseLeftClickAndSleep(station, travelDurationMillis, travelDurationVariance) + doer.keypress(KeyEvent.VK_SPACE) + + doer.sleep(waitDurationMillis, waitDurationVariance) + } +} \ No newline at end of file diff --git a/src/main/kotlin/Doer.kt b/src/main/kotlin/Doer.kt index de84949..8e48449 100644 --- a/src/main/kotlin/Doer.kt +++ b/src/main/kotlin/Doer.kt @@ -1,6 +1,7 @@ import java.awt.MouseInfo import java.awt.Point import java.awt.Robot +import java.awt.event.InputEvent import java.util.concurrent.TimeUnit import kotlin.math.ceil import kotlin.random.Random @@ -12,41 +13,6 @@ class Doer(val r: Robot) { val yWiggle = 15; } - 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) - } - println() - 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) @@ -64,6 +30,20 @@ class Doer(val r: Robot) { r.keyRelease(buttons) } + fun moveMouseLeftClickAndSleep(p: Point, dur: Long, durRange: Long){ + mouseMove(p) + sleep(100, 50) + click(InputEvent.BUTTON1_DOWN_MASK) + sleep(dur, durRange) + } + + + fun sleepForNTicks(n: Long){ + val latencyPadding = 500L + val baseWaitTime = n * 600L + sleep(latencyPadding+baseWaitTime, 150) + } + fun getAlmostPoint(p: Point): Point { val xDel = Random.nextInt(0, xWiggle) val yDel = Random.nextInt(0, yWiggle) @@ -84,8 +64,8 @@ class Doer(val r: Robot) { TimeUnit.MILLISECONDS.sleep(dur) } - fun sleep(dur: Long, min: Long, max: Long) { - val dSize = (max-min)/2 + fun sleep(dur: Long,variance: Long) { + val dSize = (variance)/2 val r1 = Random.nextLong(dSize) val r2 = Random.nextLong(dSize) TimeUnit.MILLISECONDS.sleep(dur+r1+r2) @@ -93,7 +73,7 @@ class Doer(val r: Robot) { fun scrollOut(){ r.mouseWheel(1) - sleep(100, 50, 100) + sleep(25, 26) } fun getPointerLocationAsValDeclarationString(varName: String) { diff --git a/src/main/kotlin/Entry.kt b/src/main/kotlin/Entry.kt index e25fce0..ca27ae9 100644 --- a/src/main/kotlin/Entry.kt +++ b/src/main/kotlin/Entry.kt @@ -1,13 +1,4 @@ -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() { - Routines.potionGrindWithWell(2000) + Routines.processInventoryAtFurnace(28) } diff --git a/src/main/kotlin/Routines.kt b/src/main/kotlin/Routines.kt index 68b1ea3..263e349 100644 --- a/src/main/kotlin/Routines.kt +++ b/src/main/kotlin/Routines.kt @@ -4,81 +4,133 @@ import java.awt.Robot object Routines { fun cleanHerbs(volume: Int, step: Int = 14){ + val agent = Agent() + val step = 28; val r = Doer(Robot()) println("Put your mouse over the bank...") val chest = r.getPointerLocationAfter(3000L) - r.doLoop(volume, step){ - Tasks.cleanHerbs(it, chest) + agent.doLoop(volume, step){ + agent.bankStandWithoutDialog(chest) } + } + fun cutIncenseSticks(volume: Int, step: Int = 26){ + val agent = Agent() + println("Put your mouse over the bank...") + val chest = agent.doer.getPointerLocationAfter(3000L) + agent.doLoop(volume, step){ + agent.bankStandForLoop(chest, Agent.F6, Agent.Minus, 26000, 1200) + } + } + fun coatIncenseSticks(volume: Int, step: Int = 26){ + val agent = Agent() + + println("Put your mouse over the bank...") + val chest = agent.doer.getPointerLocationAfter(3000L) + agent.doLoop(volume, step){ + agent.bankStandForLoop(chest, Agent.F6, Agent.Minus, 21000, 600) + + } + } + fun infuseIncenseSticks(volume: Int, step: Int = 27 ){ + val agent = Agent() + + println("Put your mouse over the bank...") + val chest = agent.doer.getPointerLocationAfter(3000L) + agent.doLoop(volume, step){ + + agent.bankStandForLoop(chest, Agent.F6, Agent.Minus, 48600, 600) + } } fun potionGrind(volume: Int, step: Int = 14){ - val r = Doer(Robot()) + val agent = Agent() + println("Put your mouse over the bank...") - val chest = r.getPointerLocationAfter(3000L) - r.doLoop(volume, step){ - Tasks.makePotions(it, chest) + val chest = agent.doer.getPointerLocationAfter(3000L) + agent.doLoop(volume, step){ + agent.bankStandForLoop(chest, Agent.F6, Agent.Minus, 19200, 600) } } fun potionGrindWithWell(volume: Int, step: Int = 14){ - val r = Doer(Robot()) + val agent = Agent() println("Put your mouse over the bank...") - val chest = r.getPointerLocationAfter(3000L) + val chest = agent.doer.getPointerLocationAfter(3000L) println("Put your mouse over the well...") - val well = r.getPointerLocationAfter(3000L) - r.doLoop(volume, step){ - Tasks.makePotions(it, chest, well) + val well = agent.doer.getPointerLocationAfter(3000L) + + agent.doLoop(volume, step){ + agent.processAtStationNearBank(chest, well, Agent.F6, 0, 0, 18600, 600) } } - fun furnaceGrind(volume: Int, step: Int = 28){ - val r = Doer(Robot()) + fun supremeOverloadGrind(volume: Int, step: Int = 4){ + val agent = Agent() + println("Place mouse over chest") + val chestPoint = agent.doer.getPointerLocationAfter(3000L) + println("Place mouse over well") + val wellPoint = agent.doer.getPointerLocationAfter(3000L) + + agent.doLoop(volume, step){ + agent.processAtStationNearBank(chestPoint, wellPoint, Agent.F6, 0, 0, 6500, 1000) + } + + } + + fun processInventoryAtFurnace(volume: Int, step: Int = 28){ + val agent = Agent() println("Reset the camera and zoom in") - r.sleep(1000) + agent.doer.sleep(1000) for(i in 0 until 8){ - r.scrollOut() + agent.doer.scrollOut() } val furnaceFromChest = Point(776, 321) val chestFromFurance = Point(1713, 843) - r.doLoop(volume, step){ - Tasks.doFurnaceRun(it, furnaceFromChest, chestFromFurance) + agent.doLoop(volume, step){ + agent.processAtStationNearBank(chestFromFurance, furnaceFromChest, Agent.F6, 2500, 600, 53200, 600) } } - 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) + @Deprecated("Needs validation before you use it for realsies") + fun processRefinedPlanksIntoFrames(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\n you must also be standing at the touch point on the saw") + val agent = Agent() + agent.doer.sleep(1000) for(i in 0 until 8){ - r.scrollOut() + agent.doer.scrollOut() } val sawFromChest = Point(1079, 907) val chestFromSaw = Point(1226, 180) - r.doLoop(volume, step){ - Tasks.makeFrame(it, sawFromChest, chestFromSaw) + agent.doLoop(volume, step){ +// //standing at bank with full inv +// d.mouseMove(sawFromChest) +// d.sleep(100, 50) +// //run to saw +// d.click(LeftClick) +// d.sleep(2700, 500) +// //start cutting frames +// d.keypress(Space) +// //waiting +// d.sleep(64000, 1000) +// d.mouseMove(chestFromSaw) +// d.sleep(100, 50) +// //running to bank +// d.click(LeftClick) +// d.sleep(2700, 500) +// d.keypress(F6) +// d.sleep(1200, 500) +// //full inv + + agent.processAtStationNearBank(chestFromSaw, sawFromChest, Agent.F6, 2700, 500, 64000, 1000) } } - fun supremeOverloadGrind(volume: Int, step: Int = 4){ - 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 deleted file mode 100644 index 3f43a33..0000000 --- a/src/main/kotlin/Tasks.kt +++ /dev/null @@ -1,108 +0,0 @@ -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(800, 100, 500) - d.keypress(KeyEvent.VK_F6) - d.sleep(800, 100, 500) - d.keypress(KeyEvent.VK_MINUS) - d.sleep(800, 0, 500) - } - - fun makePotions(d: Doer, chest: Point) { - d.mouseMove(d.getAlmostPoint(chest)) - d.click(InputEvent.BUTTON1_DOWN_MASK) - d.sleep(1200, 100, 500) - - d.keypress(KeyEvent.VK_F6) - d.sleep(1200, 100, 500) - - d.keypress(KeyEvent.VK_MINUS) - d.sleep(1200, 100, 500) - - d.keypress(KeyEvent.VK_SPACE) - d.sleep(18600L, 600, 1200) - } - - fun makePotions(d: Doer, chest: Point, well: Point) { - d.mouseMove(d.getAlmostPoint(chest)) - d.click(InputEvent.BUTTON1_DOWN_MASK) - d.sleep(800, 100, 500) - - d.keypress(KeyEvent.VK_F6) - d.sleep(800, 100, 500) - - d.mouseMove(well) - d.sleep(100, 0, 50) - - d.click(InputEvent.BUTTON1_DOWN_MASK) - d.sleep(800, 100, 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