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
/**
* Interface for coordinating RuneScape automation routines.
*
* 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.
* Interface for coordinating RuneScape bot actions.
*
* 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 {
/**
* Perform actions at the bank chest.
* Handles the crafting process when standing at the bank.
*
* This typically involves:
* 1. Clicking the chest to open bank interface
* 2. Pressing preset hotkey to withdraw items
* 3. Pressing crafting hotkey to start crafting workflow
* 4. Waiting for crafting duration
* This method takes care of the workflow when standing at the bank:
* - Opens the bank interface using the bank preset hotkey.
* - Waits for the crafting duration.
* - Closes the bank interface.
*
* @param bankPoint Point location of bank chest to click
* @param bankPresetHotkey Key code for bank preset withdraw action
* @param craftingDialogueHotkey Key code to select crafting dialogue
* @param waitDurationMillis Duration in ms to wait during crafting
* @param waitDurationVariance Allowed variance in wait duration
* @param bankPoint The [Point] location of the bank on screen.
* @param bankPresetHotkey The hotkey used to open the bank interface.
* @param craftingDialogueHotkey The hotkey used to open the crafting dialogue.
* @param waitDurationMillis The base duration in milliseconds to wait while crafting.
* @param waitDurationVarianceMillis Random variance in milliseconds to add to the wait duration.
*/
fun processAtBank(
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:
* 1. Traveling from bankPoint to stationPoint
* 2. Clicking station to open interface
* 3. Pressing dialogue key to start crafting
* 4. Waiting for crafting duration
* 5. Waiting for crafting duration
* This method takes care of the workflow when at the crafting station:
* - Travels from the bank to the station.
* - Waits for the crafting duration.
* - Travels back to the bank when done.
*
* @param bankPoint Point location of bank
* @param craftingStationPoint Point location of crafting station
* @param bankPresetHotkey Key code to withdraw items
* @param travelDurationMillis Time in ms to travel between points
* @param travelDurationVariance Allowed variance in travel time
* @param waitDurationMillis Crafting duration
* @param waitDurationVariance Variance in crafting duration
* @param bankPoint The [Point] location of the bank.
* @param craftingStationPoint The [Point] location of the crafting station.
* @param bankPresetHotkey The hotkey to open the bank interface.
* @param travelDurationMillis The base travel time between bank and station.
* @param travelDurationVarianceMillis Random variance to add to the travel time.
* @param waitDurationMillis The base duration to wait while crafting.
* @param waitDurationVarianceMillis Random variance to add to the wait duration.
*/
fun processAtStationNearBank(
bankPoint: Point,
@ -71,28 +59,31 @@ interface RSCoordinator {
waitDurationVarianceMillis: Long
)
/**
* Gets the bank location point.
*
* @return The [Point] representing the x,y screen coordinates of the bank location.
*/
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{
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) {
orchestrator.doLoop(params.totalVolume, params.volumePerStep) {
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) {
orchestrator.doLoop(params.totalVolume, params.volumePerStep) {
orchestrator.processAtStationNearBank(
@ -119,13 +125,21 @@ interface RSOrchestrator : Orchestrator, RSCoordinator{
}
}
fun getDefaultInstance(): RSOrchestrator{
fun getInstance(): RSOrchestrator{
return RSAgent()
}
} //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 {
companion object{

View File

@ -50,7 +50,7 @@ object Routines {
val start = System.currentTimeMillis()
//initialize the shared agent and chest point
val agent = RSOrchestrator.getDefaultInstance()
val agent = RSOrchestrator.getInstance()
val bankPoint = agent.getBankPoint()
// Loop to clean grimy herbs:
@ -100,7 +100,7 @@ object Routines {
*
* 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(
volume,
CommonVolumesPerStep.FullInventory,
@ -126,7 +126,7 @@ object Routines {
* - Cutting magic logs into incense sticks without dialog
* - 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(
volume,
CommonVolumesPerStep.FullInventory,
@ -152,7 +152,7 @@ object Routines {
* - Coating incense sticks with ashes using hotkey
* - 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(
volume,
CommonVolumesPerStep.CoatingIncenseWithAsh,
@ -177,7 +177,7 @@ object Routines {
* - Infusing incense sticks with herbs using hotkey
* - 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(
volume,
CommonVolumesPerStep.InfusingIncenseWithHerb,
@ -208,7 +208,7 @@ object Routines {
* @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()) {
fun craftPotionAtBank(volume: Int, agent: RSOrchestrator = RSOrchestrator.getInstance(), bankPoint: Point = agent.getBankPoint()) {
val params = StandingTaskParams(
volume,
CommonVolumesPerStep.FullInventory,
@ -246,7 +246,7 @@ object Routines {
fun potionGrindWithWell(
volume: Int,
travelDurationInMillis: Long,
agent: RSOrchestrator = RSOrchestrator.getDefaultInstance(),
agent: RSOrchestrator = RSOrchestrator.getInstance(),
bankPoint: Point = agent.getBankPoint()
) {
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")
fun supremeOverloadGrind(params: TaskParams) {
val agent = RSOrchestrator.getDefaultInstance()
val agent = RSOrchestrator.getInstance()
val chest = agent.getBankPoint()
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
val furnaceFromChest = Point(776, 321)
val chestFromFurnance = Point(1713, 843)
val agent = RSOrchestrator.getDefaultInstance()
val agent = RSOrchestrator.getInstance()
val params = TravelTaskParams(
volume,
28,
@ -361,7 +361,7 @@ object Routines {
@Deprecated("Needs validation before you use it for realsies")
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")
val agent = RSOrchestrator.getDefaultInstance()
val agent = RSOrchestrator.getInstance()
agent.scrollOutToHeight(8)
//the following 2 points are magic numbers from *my* setup and resolution