even betterer documentation

This commit is contained in:
dtookey 2023-08-06 19:58:48 -04:00
parent c0739c0dd7
commit 2b4c5abc94
2 changed files with 79 additions and 65 deletions

View File

@ -3,37 +3,27 @@ import java.awt.event.InputEvent
import java.awt.event.KeyEvent import java.awt.event.KeyEvent
/** /**
* Interface for coordinating RuneScape automation routines. * Interface for coordinating RuneScape bot actions.
*
* This interface provides methods for common in-game workflows like:
*
* - Processing actions at the bank chest
* - Traveling between bank and crafting station
* - Bank standing without dialogue boxes
*
* Implementations would integrate with a desktop automation library
* to actually perform the in-game clicks and inputs.
*
* This interface allows the game-specific logic to be separated from
* the underlying automation library.
* *
* This interface defines methods for orchestrating RuneScape gameplay like banking,
* traveling, and crafting. It provides the core logic needed for automating
* RuneScape tasks.
*/ */
interface RSCoordinator { interface RSCoordinator {
/** /**
* Perform actions at the bank chest. * Handles the crafting process when standing at the bank.
* *
* This typically involves: * This method takes care of the workflow when standing at the bank:
* 1. Clicking the chest to open bank interface * - Opens the bank interface using the bank preset hotkey.
* 2. Pressing preset hotkey to withdraw items * - Waits for the crafting duration.
* 3. Pressing crafting hotkey to start crafting workflow * - Closes the bank interface.
* 4. Waiting for crafting duration
* *
* @param bankPoint Point location of bank chest to click * @param bankPoint The [Point] location of the bank on screen.
* @param bankPresetHotkey Key code for bank preset withdraw action * @param bankPresetHotkey The hotkey used to open the bank interface.
* @param craftingDialogueHotkey Key code to select crafting dialogue * @param craftingDialogueHotkey The hotkey used to open the crafting dialogue.
* @param waitDurationMillis Duration in ms to wait during crafting * @param waitDurationMillis The base duration in milliseconds to wait while crafting.
* @param waitDurationVariance Allowed variance in wait duration * @param waitDurationVarianceMillis Random variance in milliseconds to add to the wait duration.
*/ */
fun processAtBank( fun processAtBank(
bankPoint: Point, bankPoint: Point,
@ -44,22 +34,20 @@ interface RSCoordinator {
) )
/** /**
* Perform actions between bank and nearby station. * Handles the crafting process when at a station near the bank.
* *
* This involves: * This method takes care of the workflow when at the crafting station:
* 1. Traveling from bankPoint to stationPoint * - Travels from the bank to the station.
* 2. Clicking station to open interface * - Waits for the crafting duration.
* 3. Pressing dialogue key to start crafting * - Travels back to the bank when done.
* 4. Waiting for crafting duration
* 5. Waiting for crafting duration
* *
* @param bankPoint Point location of bank * @param bankPoint The [Point] location of the bank.
* @param craftingStationPoint Point location of crafting station * @param craftingStationPoint The [Point] location of the crafting station.
* @param bankPresetHotkey Key code to withdraw items * @param bankPresetHotkey The hotkey to open the bank interface.
* @param travelDurationMillis Time in ms to travel between points * @param travelDurationMillis The base travel time between bank and station.
* @param travelDurationVariance Allowed variance in travel time * @param travelDurationVarianceMillis Random variance to add to the travel time.
* @param waitDurationMillis Crafting duration * @param waitDurationMillis The base duration to wait while crafting.
* @param waitDurationVariance Variance in crafting duration * @param waitDurationVarianceMillis Random variance to add to the wait duration.
*/ */
fun processAtStationNearBank( fun processAtStationNearBank(
bankPoint: Point, bankPoint: Point,
@ -71,28 +59,31 @@ interface RSCoordinator {
waitDurationVarianceMillis: Long waitDurationVarianceMillis: Long
) )
/**
* Gets the bank location point.
*
* @return The [Point] representing the x,y screen coordinates of the bank location.
*/
fun getBankPoint(): Point fun getBankPoint(): Point
} }
/**
* Interface for orchestrating and coordinating RuneScape automation routines.
*
* This interface combines the orchestration capabilities from [Orchestrator]
* and the RuneScape coordination capabilities from [RSCoordinator].
*
* An implementation would use the orchestration methods like [doLoop] to
* define the overall workflow.
*
* It would use the RSCoordinator methods like [processAtBank] to
* encapsulate common in-game actions needed for that workflow.
*
* By combining both capabilities, this interface provides a simple
* way to implement full RuneScape automation routines.
*
*/
interface RSOrchestrator : Orchestrator, RSCoordinator{ interface RSOrchestrator : Orchestrator, RSCoordinator{
companion object { companion object {
/**
* Performs a standing crafting task loop at the bank.
*
* This handles a simple crafting loop where the player stands at the bank and crafts.
*
* It withdraws items from the bank, crafts a batch of items, deposits crafted items,
* and repeats.
*
* @param orchestrator The [RSOrchestrator] that will execute the actions.
* @param params The [StandingTaskParams] configuring the task details.
* @return Unit.
*/
fun doStandingTask(orchestrator: RSOrchestrator, params: StandingTaskParams) { fun doStandingTask(orchestrator: RSOrchestrator, params: StandingTaskParams) {
orchestrator.doLoop(params.totalVolume, params.volumePerStep) { orchestrator.doLoop(params.totalVolume, params.volumePerStep) {
orchestrator.processAtBank( orchestrator.processAtBank(
@ -105,6 +96,21 @@ interface RSOrchestrator : Orchestrator, RSCoordinator{
} }
} }
/**
* Performs a crafting workflow loop that involves traveling between a bank and crafting station.
*
* This handles the overall workflow orchestration of:
* 1. Withdrawing items from the bank.
* 2. Traveling to the crafting station.
* 3. Crafting items.
* 4. Traveling back to the bank when inventory is empty.
*
* It will repeat this loop for the specified total volume of items to craft, doing the given volume per loop iteration.
*
* @param orchestrator The [RSOrchestrator] instance that will execute the actual actions.
* @param params The [TravelTaskParams] configuring the crafting loop details.
* @return Unit.
*/
fun doTravelTask(orchestrator: RSOrchestrator, params: TravelTaskParams) { fun doTravelTask(orchestrator: RSOrchestrator, params: TravelTaskParams) {
orchestrator.doLoop(params.totalVolume, params.volumePerStep) { orchestrator.doLoop(params.totalVolume, params.volumePerStep) {
orchestrator.processAtStationNearBank( orchestrator.processAtStationNearBank(
@ -119,13 +125,21 @@ interface RSOrchestrator : Orchestrator, RSCoordinator{
} }
} }
fun getDefaultInstance(): RSOrchestrator{ fun getInstance(): RSOrchestrator{
return RSAgent() return RSAgent()
} }
} //end of companion object } //end of companion object
} }
/**
* Implementation of [RSOrchestrator] using a [RobotController].
*
* This class handles executing RuneScape automation tasks by controlling
* the game client via image recognition and input emulation.
*
* @param automaton The [Automaton] instance used to control the game. Defaults to [RobotController].
*/
private class RSAgent(override val automaton: Automaton = RobotController()) : RSOrchestrator { private class RSAgent(override val automaton: Automaton = RobotController()) : RSOrchestrator {
companion object{ companion object{

View File

@ -50,7 +50,7 @@ object Routines {
val start = System.currentTimeMillis() val start = System.currentTimeMillis()
//initialize the shared agent and chest point //initialize the shared agent and chest point
val agent = RSOrchestrator.getDefaultInstance() val agent = RSOrchestrator.getInstance()
val bankPoint = agent.getBankPoint() val bankPoint = agent.getBankPoint()
// Loop to clean grimy herbs: // Loop to clean grimy herbs:
@ -100,7 +100,7 @@ object Routines {
* *
* It performs the actions at the bank location using the provided agent. * It performs the actions at the bank location using the provided agent.
*/ */
fun cleanHerbs(volume: Int, agent: RSOrchestrator = RSOrchestrator.getDefaultInstance(), bankPoint: Point = agent.getBankPoint()) { fun cleanHerbs(volume: Int, agent: RSOrchestrator = RSOrchestrator.getInstance(), bankPoint: Point = agent.getBankPoint()) {
val params = StandingTaskParams( val params = StandingTaskParams(
volume, volume,
CommonVolumesPerStep.FullInventory, CommonVolumesPerStep.FullInventory,
@ -126,7 +126,7 @@ object Routines {
* - Cutting magic logs into incense sticks without dialog * - Cutting magic logs into incense sticks without dialog
* - Depositing incense sticks * - Depositing incense sticks
*/ */
fun cutIncenseSticks(volume: Int, agent: RSOrchestrator = RSOrchestrator.getDefaultInstance(), bankPoint: Point = agent.getBankPoint()) { fun cutIncenseSticks(volume: Int, agent: RSOrchestrator = RSOrchestrator.getInstance(), bankPoint: Point = agent.getBankPoint()) {
val params = StandingTaskParams( val params = StandingTaskParams(
volume, volume,
CommonVolumesPerStep.FullInventory, CommonVolumesPerStep.FullInventory,
@ -152,7 +152,7 @@ object Routines {
* - Coating incense sticks with ashes using hotkey * - Coating incense sticks with ashes using hotkey
* - Depositing coated sticks * - Depositing coated sticks
*/ */
fun coatIncenseSticks(volume: Int, agent: RSOrchestrator = RSOrchestrator.getDefaultInstance(), bankPoint: Point = agent.getBankPoint()) { fun coatIncenseSticks(volume: Int, agent: RSOrchestrator = RSOrchestrator.getInstance(), bankPoint: Point = agent.getBankPoint()) {
val params = StandingTaskParams( val params = StandingTaskParams(
volume, volume,
CommonVolumesPerStep.CoatingIncenseWithAsh, CommonVolumesPerStep.CoatingIncenseWithAsh,
@ -177,7 +177,7 @@ object Routines {
* - Infusing incense sticks with herbs using hotkey * - Infusing incense sticks with herbs using hotkey
* - Depositing infused incense sticks * - Depositing infused incense sticks
*/ */
fun infuseIncenseSticks(volume: Int, agent: RSOrchestrator = RSOrchestrator.getDefaultInstance(), bankPoint: Point = agent.getBankPoint()) { fun infuseIncenseSticks(volume: Int, agent: RSOrchestrator = RSOrchestrator.getInstance(), bankPoint: Point = agent.getBankPoint()) {
val params = StandingTaskParams( val params = StandingTaskParams(
volume, volume,
CommonVolumesPerStep.InfusingIncenseWithHerb, CommonVolumesPerStep.InfusingIncenseWithHerb,
@ -208,7 +208,7 @@ object Routines {
* @deprecated This method needs validation before use in production. * @deprecated This method needs validation before use in production.
*/ */
@Deprecated("Needs validation before you use it for realsies") @Deprecated("Needs validation before you use it for realsies")
fun craftPotionAtBank(volume: Int, agent: RSOrchestrator = RSOrchestrator.getDefaultInstance(), bankPoint: Point = agent.getBankPoint()) { fun craftPotionAtBank(volume: Int, agent: RSOrchestrator = RSOrchestrator.getInstance(), bankPoint: Point = agent.getBankPoint()) {
val params = StandingTaskParams( val params = StandingTaskParams(
volume, volume,
CommonVolumesPerStep.FullInventory, CommonVolumesPerStep.FullInventory,
@ -246,7 +246,7 @@ object Routines {
fun potionGrindWithWell( fun potionGrindWithWell(
volume: Int, volume: Int,
travelDurationInMillis: Long, travelDurationInMillis: Long,
agent: RSOrchestrator = RSOrchestrator.getDefaultInstance(), agent: RSOrchestrator = RSOrchestrator.getInstance(),
bankPoint: Point = agent.getBankPoint() bankPoint: Point = agent.getBankPoint()
) { ) {
val well = agent.promptUserForPoint("Put your mouse over the well...") val well = agent.promptUserForPoint("Put your mouse over the well...")
@ -288,7 +288,7 @@ object Routines {
*/ */
@Deprecated("Needs validation before you use it for realsies") @Deprecated("Needs validation before you use it for realsies")
fun supremeOverloadGrind(params: TaskParams) { fun supremeOverloadGrind(params: TaskParams) {
val agent = RSOrchestrator.getDefaultInstance() val agent = RSOrchestrator.getInstance()
val chest = agent.getBankPoint() val chest = agent.getBankPoint()
val well = agent.promptUserForPoint("Put your mouse over the well...") val well = agent.promptUserForPoint("Put your mouse over the well...")
@ -323,7 +323,7 @@ object Routines {
//these two points are specific to my computer. we need to export these into a file or something //these two points are specific to my computer. we need to export these into a file or something
val furnaceFromChest = Point(776, 321) val furnaceFromChest = Point(776, 321)
val chestFromFurnance = Point(1713, 843) val chestFromFurnance = Point(1713, 843)
val agent = RSOrchestrator.getDefaultInstance() val agent = RSOrchestrator.getInstance()
val params = TravelTaskParams( val params = TravelTaskParams(
volume, volume,
28, 28,
@ -361,7 +361,7 @@ object Routines {
@Deprecated("Needs validation before you use it for realsies") @Deprecated("Needs validation before you use it for realsies")
fun processRefinedPlanksIntoFrames(params: TaskParams) { fun processRefinedPlanksIntoFrames(params: TaskParams) {
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") 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 = RSOrchestrator.getDefaultInstance() val agent = RSOrchestrator.getInstance()
agent.scrollOutToHeight(8) agent.scrollOutToHeight(8)
//the following 2 points are magic numbers from *my* setup and resolution //the following 2 points are magic numbers from *my* setup and resolution