From 430c9a34ac1b5686bfca7cbcc8cdd279ce6794d8 Mon Sep 17 00:00:00 2001 From: dtookey Date: Sun, 6 Aug 2023 20:40:44 -0400 Subject: [PATCH] cleaned up some call sites --- src/main/kotlin/RSLogic.kt | 72 ++++++++++---------------------------- 1 file changed, 19 insertions(+), 53 deletions(-) diff --git a/src/main/kotlin/RSLogic.kt b/src/main/kotlin/RSLogic.kt index b622649..9cd71cb 100644 --- a/src/main/kotlin/RSLogic.kt +++ b/src/main/kotlin/RSLogic.kt @@ -10,7 +10,7 @@ import java.awt.event.KeyEvent * Implementations will contain the game-specific logic to interact with the * RuneScape client and APIs to carry out the actions. */ -interface RSOrchestrator : Orchestrator{ +interface RSOrchestrator : Orchestrator { companion object { /** @@ -27,13 +27,7 @@ interface RSOrchestrator : Orchestrator{ */ fun doStandingTask(orchestrator: RSOrchestrator, params: StandingTaskParams) { orchestrator.doLoop(params.totalVolume, params.volumePerStep) { - orchestrator.processAtBank( - params.bankPoint, - params.bankPresetHotkey, - params.craftingDialogHotkey, - params.craftingWaitDurationMillis, - params.craftingWaitDurationVarianceMillis - ) + orchestrator.processAtBank(params) } } @@ -54,15 +48,7 @@ interface RSOrchestrator : Orchestrator{ */ fun doTravelTask(orchestrator: RSOrchestrator, params: TravelTaskParams) { orchestrator.doLoop(params.totalVolume, params.volumePerStep) { - orchestrator.processAtStationNearBank( - params.bankPoint, - params.travelPoint, - params.bankPresetHotkey, - params.travelDurationMillis, - params.travelDurationVarianceMillis, - params.craftingWaitDurationMillis, - params.craftingWaitDurationVarianceMillis - ) + orchestrator.processAtStationNearBank(params) } } @@ -74,7 +60,7 @@ interface RSOrchestrator : Orchestrator{ * * @return The [RSOrchestrator] instance. */ - fun getInstance(): RSOrchestrator{ + fun getInstance(): RSOrchestrator { return RSAgent() } } //end of companion object @@ -95,11 +81,7 @@ interface RSOrchestrator : Orchestrator{ * @param waitDurationVarianceMillis Random variance in milliseconds to add to the wait duration. */ fun processAtBank( - bankPoint: Point, - bankPresetHotkey: Int, - craftingDialogueHotkey: Int, - waitDurationMillis: Long, - waitDurationVariance: Long + taskParams: StandingTaskParams ) /** @@ -119,13 +101,7 @@ interface RSOrchestrator : Orchestrator{ * @param waitDurationVarianceMillis Random variance to add to the wait duration. */ fun processAtStationNearBank( - bankPoint: Point, - craftingStationPoint: Point, - bankPresetHotkey: Int, - travelDurationMillis: Long, - travelDurationVarianceMillis: Long, - waitDurationMillis: Long, - waitDurationVarianceMillis: Long + taskParams: TravelTaskParams ) /** @@ -146,7 +122,7 @@ interface RSOrchestrator : Orchestrator{ */ private class RSAgent(override val automaton: Automaton = RobotController()) : RSOrchestrator { - companion object{ + companion object { /** * Extra padding in milliseconds added before actions to account for latency. 500ms is entirely arbitrary. It is * simply a value that works well during high-load periods. Better to be conservative than lossy. @@ -200,26 +176,22 @@ private class RSAgent(override val automaton: Automaton = RobotController()) : R * @param waitDurationVariance Allowed variance in the wait duration. */ override fun processAtBank( - bankPoint: Point, - bankPresetHotkey: Int, - craftingDialogueHotkey: Int, - waitDurationMillis: Long, - waitDurationVariance: Long + taskParams: StandingTaskParams ) { //open the bank located by the chest parameter - moveMouseLeftClickAndSleep(automaton.getAlmostPoint(bankPoint, WiggleParams()), 900, 400) + moveMouseLeftClickAndSleep(automaton.getAlmostPoint(taskParams.bankPoint, WiggleParams()), 900, 400) //withdraw the desired inventory preset - automaton.keyPress(bankPresetHotkey) + automaton.keyPress(taskParams.bankPresetHotkey) //sleep for a server tick sleepForNTicks(1) //open the crafting dialog with the correct hotkey - automaton.keyPress(craftingDialogueHotkey) + automaton.keyPress(taskParams.craftingDialogHotkey) //sleep for a server tick sleepForNTicks(1) //press the "accept" default hotkey automaton.keyPress(KeyEvent.VK_SPACE) //wait for the desired time to finish - automaton.sleepWithVariance(waitDurationMillis, waitDurationVariance) + automaton.sleepWithVariance(taskParams.craftingWaitDurationMillis, taskParams.craftingWaitDurationVarianceMillis) } /** @@ -252,33 +224,27 @@ private class RSAgent(override val automaton: Automaton = RobotController()) : R * @param waitDurationVarianceMillis The allowed variance in crafting duration */ override fun processAtStationNearBank( - bankPoint: Point, - craftingStationPoint: Point, - bankPresetHotkey: Int, - travelDurationMillis: Long, - travelDurationVarianceMillis: Long, - waitDurationMillis: Long, - waitDurationVarianceMillis: Long + taskParams: TravelTaskParams ) { //move to the bank and open the interface moveMouseLeftClickAndSleep( - automaton.getAlmostPoint(bankPoint, WiggleParams()), - travelDurationMillis, - travelDurationVarianceMillis + automaton.getAlmostPoint(taskParams.bankPoint, WiggleParams()), + taskParams.travelDurationMillis, + taskParams.travelDurationVarianceMillis ) //withdraw desired loadout - automaton.keyPress(bankPresetHotkey) + automaton.keyPress(taskParams.bankPresetHotkey) sleepForNTicks(1) //move to station and open the crafting dialog - moveMouseLeftClickAndSleep(craftingStationPoint, travelDurationMillis, travelDurationVarianceMillis) + moveMouseLeftClickAndSleep(taskParams.travelPoint, taskParams.travelDurationMillis, taskParams.travelDurationVarianceMillis) //start the crafting task automaton.keyPress(KeyEvent.VK_SPACE) //wait for it to complete - automaton.sleepWithVariance(waitDurationMillis, waitDurationVarianceMillis) + automaton.sleepWithVariance(taskParams.craftingWaitDurationMillis, taskParams.craftingWaitDurationVarianceMillis) }