extracting duplicate and shared params into classes

This commit is contained in:
dtookey 2023-08-05 06:22:50 -04:00
parent 79f1e9e0ce
commit f919179c86
2 changed files with 77 additions and 199 deletions

View File

@ -1,4 +1,8 @@
import java.awt.Point
fun main() { fun main() {
Routines.fullRunIncense(1, 1, 1, 1) // Routines.fullRunIncense(0, 8916, 9462, 4808)
val params = RoutineParams(1000, 28, chest = Point(0, 0))
Routines.processInventoryAtFurnace(params)
} }

View File

@ -36,37 +36,42 @@ object Routines {
* Progress is printed after each step. Total elapsed time is printed at the end. * Progress is printed after each step. Total elapsed time is printed at the end.
* @deprecated Needs validation before using for real, as sawmill points are hardcoded * @deprecated Needs validation before using for real, as sawmill points are hardcoded
*/ */
@Deprecated("Needs validation before you use it for realsies")
fun fullRunIncense(volHerbs: Int, volLogs: Int, volAshes: Int, volCleanHerbs: Int) { fun fullRunIncense(volHerbs: Int, volLogs: Int, volAshes: Int, volCleanHerbs: Int) {
val agent = Agent()
val start = System.currentTimeMillis() val start = System.currentTimeMillis()
//initialize the shared agent and chest point
val agent = Agent()
val chest = agent.getBankPoint() val chest = agent.getBankPoint()
// Loop to clean grimy herbs: // Loop to clean grimy herbs:
// Withdraw herb preset, clean without dialog at bank // Withdraw herb preset, clean without dialog at bank
if (volHerbs > 0) { if (volHerbs > 0) {
cleanHerbs(volHerbs, agent = agent, chest = chest) val params = RoutineParams(volHerbs, CommonVolumesPerStep.FullInventory, agent, chest)
cleanHerbs(params)
} }
println("\rHerbs cleaned") println("\rHerbs cleaned")
// Loop to cut magic logs into sticks: // Loop to cut magic logs into sticks:
// Withdraw log preset, cut logs using hotkey at bank // Withdraw log preset, cut logs using hotkey at bank
if (volLogs > 0) { if (volLogs > 0) {
cutIncenseSticks(volLogs, agent = agent, chest = chest) val params = RoutineParams(volLogs, CommonVolumesPerStep.FullInventory, agent, chest)
cutIncenseSticks(params)
} }
println("\rLogs cut into sticks") println("\rLogs cut into sticks")
// Loop to coat sticks in ashes: // Loop to coat sticks in ashes:
// Withdraw ash preset, coat sticks using hotkey at bank // Withdraw ash preset, coat sticks using hotkey at bank
if (volAshes > 0) { if (volAshes > 0) {
coatIncenseSticks(volAshes, agent = agent, chest = chest) val params = RoutineParams(volAshes, CommonVolumesPerStep.CoatingIncenseWithAsh, agent, chest)
coatIncenseSticks(params)
} }
println("\rSticks coated in ashes") println("\rSticks coated in ashes")
// Loop to infuse clean herbs into sticks: // Loop to infuse clean herbs into sticks:
// Withdraw herb preset, infuse sticks using hotkey at bank // Withdraw herb preset, infuse sticks using hotkey at bank
if (volCleanHerbs > 0) { if (volCleanHerbs > 0) {
infuseIncenseSticks(volCleanHerbs, agent = agent, chest = chest) val params = RoutineParams(volCleanHerbs, CommonVolumesPerStep.InfusingIncenseWithHerb, agent, chest)
infuseIncenseSticks(params)
} }
println("\rClean herbs infused") println("\rClean herbs infused")
@ -75,217 +80,86 @@ object Routines {
println("Entire chain finished in ${agent.prettyTimeString(finish - start)}") println("Entire chain finished in ${agent.prettyTimeString(finish - start)}")
} }
/**
* Cleans a volume of grimy herbs at the bank.
*
* @param totalVolume The total number of grimy herbs to clean.
* @param volumePerStep The number of herbs to clean per loop iteration.
*
* This handles cleaning the given total volume of grimy herbs by looping
* and cleaning the volumePerStep amount each iteration at the bank.
*
* It gets the bank location point from the user with a prompt.
*
* Inside the loop, it withdraws the herb cleaning preset and activates
* the cleaning without additional dialog boxes.
* @deprecated Needs validation before using for real, as sawmill points are hardcoded
*/
@Deprecated("Needs validation before you use it for realsies") @Deprecated("Needs validation before you use it for realsies")
fun cleanHerbs(totalVolume: Int, volumePerStep: Int = 14, agent: Agent = Agent(), chest: Point = agent.getBankPoint()) { fun cleanHerbs(
agent.doLoop(totalVolume, volumePerStep) { params: RoutineParams
agent.bankStandWithoutDialog(chest, KeyEvent.VK_F1, KeyEvent.VK_1) ) {
params.agent.doLoop(params.totalVolume, params.volumePerStep) {
params.agent.bankStandWithoutDialog(params.chest, KeyEvent.VK_F1, KeyEvent.VK_1)
}
}
@Deprecated("Needs validation before you use it for realsies")
fun cutIncenseSticks(
params: RoutineParams
) {
params.agent.doLoop(params.totalVolume, params.volumePerStep) {
params.agent.bankStandForLoop(params.chest, KeyEvent.VK_F2, KeyEvent.VK_2, 26000, 1200)
} }
} }
/**
* Cuts a specified total volume of magic logs into incense sticks at the bank.
*
* @param totalVolume the total number of magic logs to cut into sticks
* @param volumePerStep the number of logs to cut per loop iteration. Default is 28.
*
* This handles cutting the given total volume of logs into sticks by looping
* and cutting the volumePerStep amount each iteration at the bank.
*
* It gets the bank location point by prompting the user.
*
* Inside the loop, it withdraws the log cutting preset and cuts the logs into
* sticks using the specified hotkeys.
* @deprecated Needs validation before using for real, as sawmill points are hardcoded
*/
@Deprecated("Needs validation before you use it for realsies") @Deprecated("Needs validation before you use it for realsies")
fun cutIncenseSticks(totalVolume: Int, volumePerStep: Int = 28, agent: Agent = Agent(), chest: Point = agent.getBankPoint()) { fun coatIncenseSticks(
val agent = Agent() params: RoutineParams
) {
val chest = agent.getBankPoint() params.agent.doLoop(params.totalVolume, params.volumePerStep) {
params.agent.bankStandForLoop(params.chest, KeyEvent.VK_F3, KeyEvent.VK_3, 21000, 600)
agent.doLoop(totalVolume, volumePerStep) {
agent.bankStandForLoop(chest, KeyEvent.VK_F2, KeyEvent.VK_2, 26000, 1200)
} }
} }
/**
* Coats a specified number of incense sticks in ashes at the bank.
*
* @param totalVolume the total number of sticks to coat in ashes
* @param volumePerStep the number of sticks to coat per loop iteration. Default is 26.
*
* This handles coating the given total number of sticks in ashes by looping
* and coating volumePerStep sticks each iteration at the bank.
*
* It gets the bank location point from the Agent.
*
* Inside the loop, it withdraws the ash coating preset and coats the sticks
* using the specified hotkeys.
* @deprecated Needs validation before using for real, as sawmill points are hardcoded
*/
@Deprecated("Needs validation before you use it for realsies") @Deprecated("Needs validation before you use it for realsies")
fun coatIncenseSticks(totalVolume: Int, volumePerStep: Int = 26, agent: Agent = Agent(), chest: Point = agent.getBankPoint()) { fun infuseIncenseSticks(
val agent = Agent() params: RoutineParams
) {
val chest = agent.getBankPoint() params.agent.doLoop(params.totalVolume, params.volumePerStep) {
params.agent.bankStandForLoop(params.chest, KeyEvent.VK_F4, KeyEvent.VK_4, 48600, 600)
agent.doLoop(totalVolume, volumePerStep) {
agent.bankStandForLoop(chest, KeyEvent.VK_F3, KeyEvent.VK_3, 21000, 600)
} }
} }
/**
* Infuses a specified number of incense sticks with clean herbs at the bank.
*
* @param totalVolume the total number of sticks to infuse with herbs
* @param volumePerStep the number of sticks to infuse per loop iteration. Default is 27.
*
* This handles infusing the given total number of sticks with clean herbs by looping
* and infusing volumePerStep sticks each iteration at the bank.
*
* It gets the bank location point from the Agent.
*
* Inside the loop, it withdraws the herb infusing preset and infuses the sticks
* using the specified hotkeys.
* @deprecated Needs validation before using for real, as sawmill points are hardcoded
*/
@Deprecated("Needs validation before you use it for realsies") @Deprecated("Needs validation before you use it for realsies")
fun infuseIncenseSticks(totalVolume: Int, volumePerStep: Int = 27, agent: Agent = Agent(), chest: Point = agent.getBankPoint()) { fun craftPotionAtBank(
val agent = Agent() params: RoutineParams
) {
params.agent.doLoop(params.totalVolume, params.volumePerStep) {
val chest = agent.getBankPoint() params.agent.bankStandForLoop(params.chest, Agent.F6, Agent.Minus, 19200, 600)
agent.doLoop(totalVolume, volumePerStep) {
agent.bankStandForLoop(chest, KeyEvent.VK_F4, KeyEvent.VK_4, 48600, 600)
} }
} }
/**
* Crafts potions at the bank in a loop.
*
* @param totalVolume the total number of potions to craft
* @param volumePerStep the number of potions to craft per loop iteration. Default is 14.
*
* This handles crafting the given total volume of potions by looping
* and crafting the volumePerStep amount each iteration at the bank.
*
* It gets the bank location point by prompting the user.
*
* Inside the loop, it withdraws the potion crafting preset and crafts
* using the crafting hotkey which doesn't produce a dialogue box.
* @deprecated Needs validation before using for real, as sawmill points are hardcoded
*/
@Deprecated("Needs validation before you use it for realsies") @Deprecated("Needs validation before you use it for realsies")
fun craftPotionAtBank(totalVolume: Int, volumePerStep: Int = 14, agent: Agent = Agent(), chest: Point = agent.getBankPoint()) { fun potionGrindWithWell(
val agent = Agent() params: RoutineParams,
travelDurationInMillis: Long
val chest = agent.getBankPoint() ) {
agent.doLoop(totalVolume, volumePerStep) {
agent.bankStandForLoop(chest, Agent.F6, Agent.Minus, 19200, 600)
}
}
/**
* Grinds a total volume of potions using a well near the bank.
*
* @param totalVolume the total number of potions to grind
* @param volumePerStep the number of potions to grind per loop iteration. Default is 14.
* @param travelDurationInMillis the time in milliseconds for the agent to travel between the bank and the well.
* Default is 0.
*
* This handles crafting the given total volume of potions by looping accounting for the crafting of volumePerStep
* potions amount each iteration using a well near the bank.
*
* It gets the bank location point and well location point by prompting the user.
*
* Inside the loop, it withdraws the potion grinding preset and creates potions using the well.
*
* After creating the potions, it banks again before the next iteration.
*
* The travelDurationInMillis parameter allows configuring the travel time between the bank and the well.
* @deprecated Needs validation before using for real, as sawmill points are hardcoded
*/
@Deprecated("Needs validation before you use it for realsies")
fun potionGrindWithWell(totalVolume: Int, volumePerStep: Int = 14, travelDurationInMillis: Long = 0, agent: Agent = Agent(), chest: Point = agent.getBankPoint()) {
val agent = Agent() val agent = Agent()
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...")
agent.doLoop(totalVolume, volumePerStep) { agent.doLoop(params.totalVolume, params.volumePerStep) {
agent.processAtStationNearBank(chest, well, Agent.F6, travelDurationInMillis, 0, 18600, 600) agent.processAtStationNearBank(chest, well, Agent.F6, travelDurationInMillis, 0, 18600, 600)
} }
} }
/**
* Grinds a total volume of supreme overload potions using a well near the bank.
*
* @param totalVolume the total number of potions to grind
* @param volumePerStep the number of potions to grind per loop iteration. Default is 4.
*
* This handles crafting the given total volume of supreme overload potions by looping
* and accounting for producing volumePerStep amount of potions each iteration using a well near the bank.
*
* It gets the bank location point and well location point by prompting the user.
*
* Inside the loop, it withdraws the potion grinding preset and grinds
* using the well.
*
* After crafting finishes, it banks again before the next iteration.
* @deprecated Needs validation before using for real, as sawmill points are hardcoded
*/
@Deprecated("Needs validation before you use it for realsies") @Deprecated("Needs validation before you use it for realsies")
fun supremeOverloadGrind(totalVolume: Int, volumePerStep: Int = 4, agent: Agent = Agent(), chest: Point = agent.getBankPoint()) { fun supremeOverloadGrind(
params: RoutineParams
) {
val agent = Agent() val agent = Agent()
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...")
agent.doLoop(totalVolume, volumePerStep) { agent.doLoop(params.totalVolume, params.volumePerStep) {
agent.processAtStationNearBank(chest, well, Agent.F6, 0, 0, 6500, 1000) agent.processAtStationNearBank(chest, well, Agent.F6, 0, 0, 6500, 1000)
} }
} }
/** fun processInventoryAtFurnace(
* Processes a total volume of inventory at a furnace near the bank. params: RoutineParams
* ) {
* @param totalVolume the total number of inventory items to process
* @param volumePerStep the number of items to process per loop iteration. Default is 28.
*
* This handles processing the given total volume of inventory by looping
* and processing volumePerStep items each iteration at a furnace near the bank.
*
* It uses pre-defined points for the furnace location relative to the bank chest.
*
* Inside the loop, it travels to the furnace, processes the items using the
* process hotkey, and travels back to the bank before the next iteration.
*
* The camera is reset before starting.
* @deprecated Needs validation before using for real, as sawmill points are hardcoded
*/
@Deprecated("Needs validation before you use it for realsies")
fun processInventoryAtFurnace(totalVolume: Int, volumePerStep: Int = 28, agent: Agent = Agent(), chest: Point = agent.getBankPoint()) {
val agent = Agent() val agent = Agent()
println("Reset the camera") println("Reset the camera")
agent.scrollOutToHeight(8) agent.scrollOutToHeight(8)
@ -293,36 +167,23 @@ object Routines {
val furnaceFromChest = Point(776, 321) val furnaceFromChest = Point(776, 321)
val chestFromFurance = Point(1713, 843) val chestFromFurance = Point(1713, 843)
agent.doLoop(totalVolume, volumePerStep) { agent.doLoop(params.totalVolume, params.volumePerStep) {
agent.processAtStationNearBank(chestFromFurance, furnaceFromChest, Agent.F6, 2500, 600, 53200, 600) agent.processAtStationNearBank(chestFromFurance, furnaceFromChest, Agent.F6, 2000, 600, 51000, 600)
} }
} }
/**
* Processes refined planks into frames at a sawmill near the bank.
*
* @param totalVolume the total number of planks to process into frames
* @param volumePerStep the number of planks to process per loop iteration
*
* This handles processing the given total volume of refined planks into frames
* by looping and processing volumePerStep planks each iteration at a sawmill near the bank.
*
* It uses pre-defined points for the sawmill location relative to the bank chest.
*
* Inside the loop, it travels to the sawmill, processes the planks into frames
* using the process hotkey, and travels back to the bank before the next iteration.
*
* @deprecated Needs validation before using for real, as sawmill points are hardcoded
*/
@Deprecated("Needs validation before you use it for realsies") @Deprecated("Needs validation before you use it for realsies")
fun processRefinedPlanksIntoFrames(totalVolume: Int, volumePerStep: Int, agent: Agent = Agent(), chest: Point = agent.getBankPoint()) { fun processRefinedPlanksIntoFrames(
params: RoutineParams
) {
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 = Agent() val agent = Agent()
agent.scrollOutToHeight(8) agent.scrollOutToHeight(8)
val sawFromChest = Point(1079, 907) val sawFromChest = Point(1079, 907)
val chestFromSaw = Point(1226, 180) val chestFromSaw = Point(1226, 180)
agent.doLoop(totalVolume, volumePerStep) { agent.doLoop(params.totalVolume, params.volumePerStep) {
// //standing at bank with full inv // //standing at bank with full inv
// d.mouseMove(sawFromChest) // d.mouseMove(sawFromChest)
// d.sleep(100, 50) // d.sleep(100, 50)
@ -345,5 +206,18 @@ object Routines {
agent.processAtStationNearBank(chestFromSaw, sawFromChest, Agent.F6, 2700, 500, 64000, 1000) agent.processAtStationNearBank(chestFromSaw, sawFromChest, Agent.F6, 2700, 500, 64000, 1000)
} }
} }
}
data class RoutineParams(
val totalVolume: Int,
val volumePerStep: Int,
val agent: Agent = Agent(),
val chest: Point = agent.getBankPoint()
)
object CommonVolumesPerStep {
const val FullInventory = 28
const val TwoReagentFullInventory = 14
const val CoatingIncenseWithAsh = 26
const val InfusingIncenseWithHerb = 27
} }