diff --git a/src/main/kotlin/RSLogic.kt b/src/main/kotlin/RSLogic.kt index b6636ca..d03d494 100644 --- a/src/main/kotlin/RSLogic.kt +++ b/src/main/kotlin/RSLogic.kt @@ -159,6 +159,28 @@ private class RSAgent(override val automaton: Automaton = RobotController()) : R /*============================================================================================================== interface implementation ==============================================================================================================*/ + /** + * Performs actions at the bank chest. + * + * This method handles the workflow of: + * + * 1. Opening the bank interface by left-clicking near the provided bankPoint. + * 2. Withdrawing the desired inventory preset using the bankPresetHotkey. + * 3. Opening the crafting interface using the craftingDialogueHotkey. + * 4. Starting the crafting workflow by pressing the default "Accept" hotkey (space). + * 5. Waiting for the crafting duration with some random variance. + * + * Between steps, sleeps are added to match in-game server tick rate. + * + * The bank interface is opened by left-clicking near the bank point, using + * wiggle to introduce some variance. + * + * @param bankPoint The Point location of the bank chest. + * @param bankPresetHotkey The key code for the bank preset withdraw action. + * @param craftingDialogueHotkey The key code to open the crafting dialogue. + * @param waitDurationMillis The duration in ms to wait during crafting. + * @param waitDurationVariance Allowed variance in the wait duration. + */ override fun processAtBank( bankPoint: Point, bankPresetHotkey: Int, @@ -182,6 +204,35 @@ private class RSAgent(override val automaton: Automaton = RobotController()) : R automaton.sleepWithVariance(waitDurationMillis, waitDurationVariance) } + /** + * Performs actions at a station near the bank. + * + * This handles the workflow of: + * + * 1. Moving to the bank and opening the interface + * 2. Withdrawing the desired inventory loadout + * 3. Moving to the station and opening the crafting interface + * 4. Starting the crafting task + * 5. Waiting for the crafting duration + * + * Random variance is added to the travel and wait durations. + * + * The bank interface is opened by left clicking the bank point. + * + * The preset hotkey withdraws the loadout. + * + * The station interface is opened by left clicking the station point. + * + * The crafting task is started by pressing the spacebar. + * + * @param bankPoint The Point location of the bank + * @param craftingStationPoint The Point location of the crafting station + * @param bankPresetHotkey The hotkey to withdraw bank preset loadout + * @param travelDurationMillis The base travel time between bank and station + * @param travelDurationVarianceMillis The allowed variance in travel time + * @param waitDurationMillis The base crafting duration + * @param waitDurationVarianceMillis The allowed variance in crafting duration + */ override fun processAtStationNearBank( bankPoint: Point, craftingStationPoint: Point, @@ -212,12 +263,19 @@ private class RSAgent(override val automaton: Automaton = RobotController()) : R automaton.sleepWithVariance(waitDurationMillis, waitDurationVarianceMillis) } - - - - /*============================================================================================================== - cheater functions - ==============================================================================================================*/ + /** + * Prompts the user to position the mouse and returns that position. + * + * This method prints a prompt message, then waits for the user to position + * the mouse. + * + * It then returns the current mouse position as a Point after a slight delay. + * + * The delay allows the mouse to settle before sampling its position. + * + * @param prompt The message to display to prompt user to position mouse. + * @return The Point position of the mouse after user positions it. + */ override fun promptUserForPoint(prompt: String): Point { println(prompt) countDown(5) { @@ -230,11 +288,43 @@ private class RSAgent(override val automaton: Automaton = RobotController()) : R return automaton.getPointerLocation() } + + /*============================================================================================================== + cheater functions + ==============================================================================================================*/ + + + /** + * Prompts the user to position the mouse and returns that position. + * + * This method prints a prompt message, then waits for the user to position + * the mouse. + * + * It then returns the current mouse position as a Point after a slight delay. + * + * The delay allows the mouse to settle before sampling its position. + * + * @return The Point position of the mouse after user positions it. + */ override fun getBankPoint(): Point { return promptUserForPoint("Hold your mouse over the bank...") } + /** + * Performs a countdown loop announcing each step. + * + * This method counts down from a provided number of seconds to 0. + * + * It calls the provided [announceFn] function on each step, passing the current + * step number. + * A sleep of 1 second is added between each step. + + * Typical usage is to print a countdown message within [announceFn]. + + * @param nSeconds The number of seconds to count down. + * @param announceFn A callback function called each step, passed step number. + */ fun countDown(nSeconds: Int, announceFn: (step: Int) -> Unit) { for (i in nSeconds downTo 0) { announceFn(i) @@ -242,6 +332,21 @@ private class RSAgent(override val automaton: Automaton = RobotController()) : R } } + /** + * Gets the mouse pointer location after a delay. + * + * This method uses a countdown loop to wait for the specified number of + * seconds, printing a countdown as it goes. + * + * After the delay, it calls the automation library's getPointerLocation() + * method to retrieve the current mouse pointer coordinates. + * + * The delay helps ensure any prior mouse movements have settled before + * sampling the location. + * + * @param delayInSeconds The number of seconds to wait before sampling pointer location. + * @return The mouse pointer location after the delay as a Point. + */ fun getPointerLocationAfter(delayInSeconds: Int): Point { countDown(delayInSeconds) { print("\rtaking pointer snapshot in $it...") @@ -252,12 +357,45 @@ private class RSAgent(override val automaton: Automaton = RobotController()) : R return automaton.getPointerLocation() } + /** + * Gets the current mouse pointer location and returns it as a val declaration string. + * + * This method uses the [getPointerLocationAfter] method to get the current + * mouse pointer location after a small delay. + * + * It then formats this location into a string declaring a val with the provided + * variable name, like: + * + * ``` + * val myPoint = Point(123, 456) + * ``` + * + * The delay before getting the pointer location helps ensure the mouse has + * settled after any prior movements. + * + * @param varName The name to use for the variable in the declaration string. + * @return A string declaring a val with the pointer location. + */ fun getPointerLocationAsValDeclarationString(varName: String): String { val info = getPointerLocationAfter(5) return "val $varName = Point(${info.x}, ${info.y})" } - + /** + * Moves the mouse to a point, left clicks, and sleeps. + * + * This method moves the mouse to the provided point location, left clicks + * at that location, sleeps for the specified duration plus a random variance. + * + * Typical usage is to provide a point where something needs to be clicked, + * along with a sleep duration to wait after clicking. + * + * The random variance in sleep time helps match real human actions. + * + * @param p The point location to move the mouse and left click. + * @param dur The base duration in ms to sleep after clicking. + * @param durRange The allowed variance in the sleep duration. + */ fun moveMouseLeftClickAndSleep(p: Point, dur: Long, durRange: Long) { automaton.moveMouse(p) automaton.sleepWithVariance(100, 50) @@ -266,13 +404,34 @@ private class RSAgent(override val automaton: Automaton = RobotController()) : R automaton.sleepWithVariance(dur, durRange) } + /** + * Sleeps for a specified number of game ticks. + * + * This method calculates the total sleep duration based on the number of ticks + * and the tick duration constant. It then sleeps for that amount plus a small + * latency padding. + * + * A random variance is also added to the sleep duration to add some less-robotic behavior. + * + * @param n The number of game ticks to sleep for. + */ fun sleepForNTicks(n: Long) { val latencyPadding = LATENCY_PADDING_MS val baseWaitTime = n * TICK_DURATION_MS automaton.sleepWithVariance(latencyPadding + baseWaitTime, 150) } - + /** + * Draws a star shape by moving the mouse between points. + * + * This method takes in a center point and calculates offset points around it. + * It then moves the mouse between each point in sequence to draw a star shape. + * + * The offset points are calculated by moving left/right and up/down from the + * center point by a fixed offset amount. + * + * @param p The center point of the star. + */ override fun drawStar(p: Point) { val offset = 100 val top = Point(p.x, p.y - offset * 2) diff --git a/src/main/kotlin/Routines.kt b/src/main/kotlin/Routines.kt index 9e210f8..75df5de 100644 --- a/src/main/kotlin/Routines.kt +++ b/src/main/kotlin/Routines.kt @@ -190,6 +190,23 @@ object Routines { RSOrchestrator.doStandingTask(agent, params) } + /** + * Crafts potions at a bank location using hotkeys. + * + * @param volume The total number of potions to craft. + * @param agent The RSOrchestrator instance to use. Defaults to default instance. + * @param bankPoint The location of the bank. Defaults to agent's configured bank point. + * + * This method handles the workflow of crafting potions using hotkeys while standing at a bank: + * + * - It constructs a StandingTaskParams instance defining: + * - The volume, volume per trip, bank point, crafting hotkey, and other details + * - It calls the orchestrator's doStandingTask() method to execute the task. + * + * Progress is automatically printed during execution. + * + * @deprecated This method needs validation before use in production. + */ @Deprecated("Needs validation before you use it for realsies") fun craftPotionAtBank(volume: Int, agent: RSOrchestrator = RSOrchestrator.getDefaultInstance(), bankPoint: Point = agent.getBankPoint()) { val params = StandingTaskParams( @@ -204,6 +221,27 @@ object Routines { RSOrchestrator.doStandingTask(agent, params) } + /** + * Grinds potions using a well location for water. + * + * @param volume The total number of potions to make. + * @param travelDurationInMillis The time in ms for the agent to travel between the bank and the well. + * @param agent The RSOrchestrator instance to use. Defaults to the default instance. + * @param bankPoint The Point location of the bank. Defaults to the agent's configured bank point. + * + * This method handles the workflow of grinding potions using a well as the water source. + * + * It prompts the user to position the mouse over the well location to get its coordinates. + * + * It then constructs a TravelTaskParams instance to define: + * - The volume, volume per trip, bank point, well point, and other task details. + * + * It calls the orchestrator's doTravelTask() method to execute the grinding task. + * + * Progress is automatically printed during execution. + * + * @deprecated This method needs validation before use in production. + */ @Deprecated("Needs validation before you use it for realsies") fun potionGrindWithWell( volume: Int, @@ -227,7 +265,27 @@ object Routines { RSOrchestrator.doTravelTask(agent, params) } - + /** + * Handles the workflow to grind supreme overloads near a bank. + * + * @param params The parameters defining the grind details. + * + * This method handles the full process of: + * + * 1. Withdrawing overload supplies from the bank. + * 2. Going to the well location to make overloads. + * 3. Using the F6 hotkey to make overloads. + * 4. Sleeping between cycles to pace the actions. + * 5. Repeating for the total volume in steps of size volumePerStep. + * + * The well location is prompted from the user by moving the mouse over it. + * + * The agent handles the banking and inventory management. + * + * @param params TaskParams defining totalVolume, volumePerStep, and other details. + * + * @deprecated This method needs validation before use in production. + */ @Deprecated("Needs validation before you use it for realsies") fun supremeOverloadGrind(params: TaskParams) { val agent = RSOrchestrator.getDefaultInstance()