412 lines
14 KiB
Kotlin
412 lines
14 KiB
Kotlin
import java.awt.Point
|
|
import java.awt.event.KeyEvent
|
|
|
|
/**
|
|
* Routines object containing reusable workflows for common scripts.
|
|
*
|
|
* This object encapsulates reusable routines for common botting workflows.
|
|
* It provides an easy way to invoke these flows without having to reimplement
|
|
* the lower-level actions each time.
|
|
*
|
|
* The routines are structured as standalone methods that accept the necessary
|
|
* parameters. This allows them to be called independently and composed in
|
|
* different combinations.
|
|
*
|
|
* For example, the fullRunIncense routine orchestrates the entire incense
|
|
* stick crafting workflow by invoking the individual steps:
|
|
*
|
|
* - cleanHerbs
|
|
* - cutIncenseSticks
|
|
* - coatIncenseSticks
|
|
* - infuseIncenseSticks
|
|
*
|
|
* The individual steps can also be called independently as needed.
|
|
*
|
|
* This structure makes the routines reusable, customizable, and composable.
|
|
* Scripts can invoke the routines directly rather than reimplementing the
|
|
* underlying actions. Parameters allow customizing volumes, locations etc.
|
|
*/
|
|
object Routines {
|
|
/**
|
|
* The duration in milliseconds of one game tick.
|
|
*
|
|
* This defines the amount of time that passes during one server game tick.
|
|
*
|
|
* All timing and delays should be multiples of this tick duration to align with the
|
|
* server ticks and avoid timing issues.
|
|
*/
|
|
const val TICK_DURATION_MS = 600L
|
|
|
|
/**
|
|
* Performs the full incense stick crafting process from start to finish.
|
|
*
|
|
* @param volHerbs The number of grimy herbs to clean.
|
|
* @param volLogs The number of magic logs to cut into sticks.
|
|
* @param volAshes The number of sticks to coat in ashes.
|
|
* @param volCleanHerbs The number of clean herbs to infuse into sticks.
|
|
*
|
|
* This handles the entire incense stick crafting process:
|
|
* - Cleaning grimy herbs
|
|
* - Cutting magic logs into sticks
|
|
* - Coating sticks in ashes
|
|
* - Infusing clean herbs into sticks
|
|
*
|
|
* It loops through each step based on the provided volumes, performing the
|
|
* actions at the bank.
|
|
*
|
|
* Usage example:
|
|
*
|
|
* ```
|
|
* val herbs = 1000
|
|
* val logs = 2000
|
|
* val ashes = 1500
|
|
* val cleanHerbs = herbs + 150
|
|
*
|
|
* Routines.fullRunIncense(herbs, logs, ashes, cleanHerbs)
|
|
* ```
|
|
*
|
|
* Progress is printed after each step. Total elapsed time is printed at the end.
|
|
*/
|
|
fun fullRunIncense(volHerbs: Int, volLogs: Int, volAshes: Int, volCleanHerbs: Int) {
|
|
val start = System.currentTimeMillis()
|
|
|
|
//initialize the shared agent and chest point
|
|
val agent = RSOrchestrator.getInstance()
|
|
val bankPoint = agent.getBankPoint()
|
|
|
|
// Loop to clean grimy herbs:
|
|
// Withdraw herb preset, clean without dialog at bank
|
|
if (volHerbs > 0) {
|
|
cleanHerbs(volHerbs, agent, bankPoint)
|
|
}
|
|
println("\rHerbs cleaned")
|
|
|
|
// Loop to cut magic logs into sticks:
|
|
// Withdraw log preset, cut logs using hotkey at bank
|
|
if (volLogs > 0) {
|
|
cutIncenseSticks(volLogs, agent, bankPoint)
|
|
}
|
|
println("\rLogs cut into sticks")
|
|
|
|
// Loop to coat sticks in ashes:
|
|
// Withdraw ash preset, coat sticks using hotkey at bank
|
|
if (volAshes > 0) {
|
|
coatIncenseSticks(volAshes, agent, bankPoint)
|
|
}
|
|
println("\rSticks coated in ashes")
|
|
|
|
// Loop to infuse clean herbs into sticks:
|
|
// Withdraw herb preset, infuse sticks using hotkey at bank
|
|
if (volCleanHerbs > 0) {
|
|
infuseIncenseSticks(volCleanHerbs, agent, bankPoint)
|
|
}
|
|
println("\rClean herbs infused")
|
|
|
|
val finish = System.currentTimeMillis()
|
|
agent.drawStar()
|
|
println("Entire chain finished in ${HelperFunctions.prettyTimeString(finish - start)}")
|
|
}
|
|
|
|
/**
|
|
* Cleans a specified volume of grimy herbs into clean herbs.
|
|
*
|
|
* @param volume The number of grimy herbs to clean.
|
|
* @param agent Optional. The Agent instance to use for banking actions.
|
|
* @param bankPoint Optional. The Point location of the bank to use.
|
|
*
|
|
* This handles the workflow of:
|
|
* - Withdrawing grimy herb preset
|
|
* - Cleaning grimy herbs without dialog
|
|
* - Depositing clean herbs
|
|
*
|
|
* It performs the actions at the bank location using the provided agent.
|
|
*
|
|
* Usage examples:
|
|
* ```
|
|
* val volume = 1000
|
|
* val bankPoint = Point(100, 200)
|
|
* val agent = RSAgent.getInstance()
|
|
* Routines.cleanHerbs(volume, agent, bankPoint)
|
|
* ```
|
|
* Can also omit agent and bankPoint to use defaults:
|
|
* ```
|
|
* Routines.cleanHerbs(1000)
|
|
* ```
|
|
*/
|
|
fun cleanHerbs(volume: Int, agent: RSOrchestrator = RSOrchestrator.getInstance(), bankPoint: Point = agent.getBankPoint()) {
|
|
val params = StandingTaskParams(
|
|
volume,
|
|
CommonVolumesPerStep.FullInventory,
|
|
bankPoint,
|
|
KeyEvent.VK_F1,
|
|
KeyEvent.VK_1,
|
|
0,
|
|
0
|
|
)
|
|
RSOrchestrator.doStandingTask(agent, params)
|
|
}
|
|
|
|
|
|
/**
|
|
* Cuts a specified volume of magic logs into incense sticks.
|
|
*
|
|
* @param volume The number of magic logs to cut into sticks.
|
|
* @param agent Optional. The Agent instance to use for banking actions.
|
|
* @param bankPoint Optional. The Point location of the bank to use.
|
|
*
|
|
* This handles the workflow of:
|
|
* - Withdrawing magic log preset
|
|
* - Cutting magic logs into incense sticks without dialog
|
|
* - Depositing incense sticks
|
|
*
|
|
* Usage examples:
|
|
* ```
|
|
* val logs = 1000
|
|
* val bankPoint = Point(100, 200)
|
|
* val agent = RSAgent.getInstance()
|
|
*
|
|
* Routines.cutIncenseSticks(logs, agent, bankPoint)
|
|
* ```
|
|
* Can also omit agent and bankPoint to use defaults:
|
|
* ```
|
|
* Routines.cutIncenseSticks(1000)
|
|
* ```
|
|
*/
|
|
fun cutIncenseSticks(volume: Int, agent: RSOrchestrator = RSOrchestrator.getInstance(), bankPoint: Point = agent.getBankPoint()) {
|
|
val params = StandingTaskParams(
|
|
volume,
|
|
CommonVolumesPerStep.FullInventory,
|
|
bankPoint,
|
|
KeyEvent.VK_F2,
|
|
KeyEvent.VK_2,
|
|
26000,
|
|
TICK_DURATION_MS,
|
|
)
|
|
RSOrchestrator.doStandingTask(agent, params)
|
|
}
|
|
|
|
|
|
/**
|
|
* Coats a specified volume of incense sticks with ashes.
|
|
*
|
|
* @param volume The number of incense sticks to coat with ashes.
|
|
* @param agent Optional Agent instance to use for banking actions.
|
|
* @param bankPoint Optional Point location of the bank to use.
|
|
*
|
|
* This handles the workflow of:
|
|
* - Withdrawing incense stick preset
|
|
* - Coating incense sticks with ashes using hotkey
|
|
* - Depositing coated sticks
|
|
*
|
|
* Usage examples:
|
|
* ```
|
|
* val sticks = 1000
|
|
* val bankPoint = Point(100, 200)
|
|
* val agent = RSAgent.getInstance()
|
|
*
|
|
* Routines.coatIncenseSticks(sticks, agent, bankPoint)
|
|
* ```
|
|
* Can also omit agent and bankPoint to use defaults:
|
|
*
|
|
* ```
|
|
* Routines.coatIncenseSticks(1000)
|
|
* ```
|
|
*/
|
|
fun coatIncenseSticks(volume: Int, agent: RSOrchestrator = RSOrchestrator.getInstance(), bankPoint: Point = agent.getBankPoint()) {
|
|
val params = StandingTaskParams(
|
|
volume,
|
|
CommonVolumesPerStep.CoatingIncenseWithAsh,
|
|
bankPoint,
|
|
KeyEvent.VK_F3,
|
|
KeyEvent.VK_3,
|
|
17000,
|
|
TICK_DURATION_MS,
|
|
)
|
|
RSOrchestrator.doStandingTask(agent, params)
|
|
}
|
|
|
|
/**
|
|
* Infuses a specified volume of incense sticks with clean herbs.
|
|
*
|
|
* @param volume The number of incense sticks to infuse with herbs.
|
|
* @param agent Optional Agent instance to use for banking actions.
|
|
* @param bankPoint Optional Point location of the bank to use.
|
|
*
|
|
* This handles the workflow of:
|
|
* - Withdrawing incense stick preset
|
|
* - Infusing incense sticks with herbs using hotkey
|
|
* - Depositing infused incense sticks
|
|
*
|
|
* Usage examples:
|
|
* ```
|
|
* val sticks = 1000
|
|
* val bankPoint = Point(100, 200)
|
|
* val agent = RSAgent.getInstance()
|
|
*
|
|
* Routines.infuseIncenseSticks(sticks, agent, bankPoint)
|
|
* ```
|
|
* Can also omit agent and bankPoint to use defaults:
|
|
* ```
|
|
* Routines.infuseIncenseSticks(1000)
|
|
* ```
|
|
*/
|
|
fun infuseIncenseSticks(volume: Int, agent: RSOrchestrator = RSOrchestrator.getInstance(), bankPoint: Point = agent.getBankPoint()) {
|
|
val params = StandingTaskParams(
|
|
volume,
|
|
CommonVolumesPerStep.InfusingIncenseWithHerb,
|
|
bankPoint,
|
|
KeyEvent.VK_F4,
|
|
KeyEvent.VK_4,
|
|
48600,
|
|
TICK_DURATION_MS,
|
|
)
|
|
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.
|
|
*
|
|
* Usage example:
|
|
* ```
|
|
* val volume = 1000
|
|
* val bankPoint = Point(100, 200)
|
|
* val agent = RSAgent.getInstance()
|
|
* Routines.craftPotionsAtBank(volume, agent, bankPoint)
|
|
* ```
|
|
*
|
|
* 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.getInstance(), bankPoint: Point = agent.getBankPoint()) {
|
|
val params = StandingTaskParams(
|
|
volume,
|
|
CommonVolumesPerStep.FullInventory,
|
|
bankPoint,
|
|
KeyEvent.VK_F6,
|
|
KeyEvent.VK_MINUS,
|
|
19200,
|
|
TICK_DURATION_MS,
|
|
)
|
|
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.
|
|
*
|
|
* Usage example:
|
|
* ```
|
|
* val volume = 1000
|
|
* val travelDuration = 5000 // 5 seconds
|
|
* val bankPoint = Point(100, 200)
|
|
* val wellPoint = Point(300, 400) // Prompted from user
|
|
* Routines.potionGrindWithWell(volume, travelDuration, bankPoint, wellPoint)
|
|
* ```
|
|
*
|
|
* 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,
|
|
travelDurationInMillis: Long,
|
|
agent: RSOrchestrator = RSOrchestrator.getInstance(),
|
|
bankPoint: Point = agent.getBankPoint()
|
|
) {
|
|
val well = agent.promptUserForPoint("Put your mouse over the well...")
|
|
val params = TravelTaskParams(
|
|
volume,
|
|
CommonVolumesPerStep.FullInventory,
|
|
bankPoint,
|
|
well,
|
|
KeyEvent.VK_F6,
|
|
-1, //since the travel point is also the dialogue creator, we can omit the hotkey
|
|
19200,
|
|
TICK_DURATION_MS,
|
|
travelDurationInMillis,
|
|
TICK_DURATION_MS
|
|
)
|
|
RSOrchestrator.doTravelTask(agent, params)
|
|
}
|
|
|
|
/**
|
|
* Processes a volume of inventory at a furnace near the bank.
|
|
*
|
|
* @param volume The number of inventory slots to process at the furnace.
|
|
*
|
|
* The following 2 values are hard coded from my own personal setup
|
|
* furnaceFromChest The Point location of the furnace from the bank chest.
|
|
* chestFromFurnace The Point location of the bank chest from the furnace.
|
|
*
|
|
* Uses an Agent instance for banking and traveling.
|
|
*
|
|
* This handles the workflow of:
|
|
* - Withdrawing bars at bank chest
|
|
* - Walking to furnace and processing bars into items
|
|
* - Walking back to bank and depositing processed items
|
|
*
|
|
* The furnace and bank locations are passed in as specific Point locations.
|
|
* The agent handles the navigation and banking actions.
|
|
*
|
|
* Usage example:
|
|
*
|
|
* ```
|
|
* val volume = 28
|
|
* val bankPoint = Point(100, 200)
|
|
* val furnacePoint = Point(300, 400)
|
|
* val agent = RSAgent.getInstance()
|
|
*
|
|
* Routines.processAtFurnaceNearBank(volume, agent, bankPoint, furnacePoint)
|
|
* ```
|
|
*
|
|
* Before processing, the camera is reset to align points.
|
|
*/
|
|
fun processInventoryAtFurnace(volume: Int) {
|
|
//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.getInstance()
|
|
val params = TravelTaskParams(
|
|
volume,
|
|
28,
|
|
chestFromFurnance,
|
|
furnaceFromChest,
|
|
KeyEvent.VK_F6,
|
|
-1, //since the travel point is also the dialogue creator, we can omit the hotkey
|
|
51000,
|
|
TICK_DURATION_MS,
|
|
2000,
|
|
TICK_DURATION_MS
|
|
)
|
|
println("Resetting the camera. We need to define the reset to compass button...")
|
|
agent.scrollOutToHeight(8)
|
|
|
|
RSOrchestrator.doTravelTask(agent, params)
|
|
}
|
|
} |