Created
September 11, 2023 19:39
-
-
Save its-jackson/c7074e01841663d3191f0c6e3d17cda0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scripts.kotlin.api.framework.routine.api.woodcutting | |
import org.tribot.script.sdk.MyPlayer | |
import org.tribot.script.sdk.painting.Painting | |
import org.tribot.script.sdk.tasks.BankTask | |
import org.tribot.script.sdk.types.WorldTile | |
import scripts.kotlin.api.DepositBoxManager | |
import scripts.kotlin.api.agents.woodcutting.AutomaticAxe | |
import scripts.kotlin.api.canReach | |
import scripts.kotlin.api.framework.routine.* | |
import scripts.kotlin.api.framework.routine.api.* | |
import scripts.kotlin.api.framework.routine.api.binary.tree.* | |
import scripts.kotlin.api.framework.routine.api.interfaces.* | |
import scripts.kotlin.api.globalWalkTo | |
import scripts.kotlin.api.preciseLocalWalkTo | |
class RegularChoppingRoutine( | |
name: String, | |
metrics: Metrics, | |
failurePolicy: FailurePolicy, | |
status: RoutineStatus, | |
woodcuttingData: WoodcuttingData, | |
automaticAxe: AutomaticAxe, | |
axeManager: AxeManager, | |
birdNestManager: BirdNestManager, | |
depositBoxManager: DepositBoxManager, | |
inventoryManager: TribotInventoryManager, | |
gameSettingManager: GameSettingManager, | |
antibanManager: AntibanManager, | |
authenticationManager: TribotAuthenticationManager, | |
serverManager: TribotServerManager, | |
consumableManager: TribotConsumableManager?, | |
foodManager: TribotFoodManager?, | |
bankTaskManager: TribotBankTaskManager, | |
threadExecutionManager: TribotThreadExecutionManager, | |
preferredBankTask: BankTask? = null, | |
nexusBankTask: NexusBotBankTask? = null, | |
nexusBankTaskManager: NexusBotBankTaskManager, | |
) : TribotWoodcuttingRoutine( | |
name, | |
metrics, | |
failurePolicy, | |
status, | |
nexusBankTask, | |
nexusBankTaskManager, | |
preferredBankTask, | |
bankTaskManager, | |
authenticationManager, | |
serverManager, | |
consumableManager, | |
foodManager, | |
threadExecutionManager, | |
woodcuttingData, | |
automaticAxe, | |
axeManager, | |
birdNestManager, | |
depositBoxManager, | |
inventoryManager, | |
gameSettingManager, | |
antibanManager | |
) { | |
private var nextTreeSpawnTile: WorldTile? = null | |
override fun configureTribot( | |
setAntibanEnabled: Boolean, | |
setMouseSpeed: Int? | |
) { | |
super.configureTribot(false, null) | |
} | |
override fun executeLogic(context: RoutineContext, stop: List<RoutineStopCondition>) = forest.executeAllTrees() | |
override fun setup(context: RoutineContext): RoutineStatus { | |
if (MyPlayer.getCombatLevel() < 14 && woodcuttingData.treeType === TreeType.WILLOW_TREE_AT_DRAYNOR) { | |
logger.error("Combat level is not sufficient enough for this routine.") | |
logger.error("Required combat level: 14.") | |
logger.error("Routine type: ${woodcuttingData.treeType}.") | |
return RoutineStatus.FAILURE | |
} | |
addSetupPaint() | |
addTreeObjectPaint() | |
addNextTreeSpawnPaint() | |
if (!authenticationManager.login()) { | |
removeSetupPaint() | |
return RoutineStatus.KILL | |
} | |
gameSettingManager.executeTasks( | |
MuteAllAudioTask(), | |
SetCameraZoomTask(SetCameraZoomTask.CameraZoomSetting.ZOOM_MID), | |
EnableShiftClickDroppingTask(), | |
SetFixedScreenModeTask() | |
) | |
if (!ensureSetupNexusBankTask()) { | |
removeSetupPaint() | |
return RoutineStatus.FAILURE | |
} | |
forest.addTree(generateMainBinaryTree()) | |
forest.logAllTrees() | |
removeSetupPaint() | |
addMainPaint() | |
threadExecutionManager.launchTasks() | |
return RoutineStatus.SUCCESS | |
} | |
private fun addNextTreeSpawnPaint() { | |
Painting.addPaint { | |
val nextTreeSpawnPaintObject = nextTreeSpawnTile ?: return@addPaint | |
nextTreeSpawnPaintObject.bounds.ifPresent { bounds -> it.draw(bounds) } | |
} | |
} | |
private fun waitAtSpawnTile(tile: WorldTile) = condition { | |
tile.let { spawnTile -> | |
if (spawnTile.distance() < 4) { | |
return@let true | |
} | |
val walkTile = woodcuttingData.treeType.tree.multiArea.areas | |
.firstOrNull { it.contains(spawnTile) } | |
?.allTiles | |
?.filter { it.toLocalTile().isWalkable } | |
?.randomOrNull() ?: return@let false | |
if (canReach(walkTile)) { | |
preciseLocalWalkTo(walkTile) | |
} | |
else { | |
globalWalkTo(walkTile) | |
} | |
} | |
} | |
private fun generateWoodcuttingOperationsBinaryTree(): BinaryTree { | |
val nodeCheckAreaDone = IsAreaDoneDecisionNode( | |
treeAction, | |
{ threadExecutionManager.treeTracker.getNextArea() }, | |
{ threadExecutionManager.treeTracker.isAreaDone(treeAction.getCurrentArea()) }, | |
null | |
) | |
val nodeSetAndWaitSpawnTile = SetAndWaitAtSpawnTileEffectNode( | |
{ threadExecutionManager.treeTracker.getNextSpawnTile() }, | |
{ nextTreeSpawnTile = it }, | |
::waitAtSpawnTile | |
) | |
val nodeCheckSpawnTile = IsObjectNotNullDecisionNode( | |
{ threadExecutionManager.treeTracker.getNextSpawnTile() }, | |
nodeSetAndWaitSpawnTile, | |
nodeCheckAreaDone | |
) | |
val nodeSetAndInteract = SetAndInteractWithTreeEffectNode( | |
{ threadExecutionManager.treeTracker.getNextTreeObject() }, | |
{ currentTreeObject = it }, | |
::interactTreeObject | |
) | |
val nodeCheckNextTree = IsObjectNotNullDecisionNode( | |
{ threadExecutionManager.treeTracker.getNextTreeObject() }, | |
nodeSetAndInteract, | |
nodeCheckSpawnTile | |
) | |
val refTreeObject = FieldReference(::currentTreeObject) | |
val nodeSetToNullTree = SetToNullPerformNode(refTreeObject) | |
val nodeCheckCurrentTree = IsObjectNotNullDecisionNode({ refTreeObject.value }, nodeSetToNullTree, nodeCheckNextTree) | |
return BinaryTree(nodeCheckCurrentTree) | |
} | |
private fun generateMainBinaryTree(): BinaryTree { | |
val node12 = generateWoodcuttingOperationsBinaryTree() | |
val node11 = IsChoppingDecisionNode(treeAction, antibanManager, node12) | |
val node10 = ShouldUseAxeSpecialDecisionNode( | |
axeManager, | |
::shouldWaitForDelayUsingSpecialAttack, | |
::waitBeforeSpecialAttackUsage, | |
node11 | |
) | |
val node9 = ShouldTakeBirdNestDecisionNode( | |
woodcuttingData.logDisposal, birdNestManager, | |
::shouldWaitForDelayPickingUpBirdNest, ::waitBeforeBirdNestPickUp, | |
node10 | |
) | |
val node8 = ShouldMoveToAreaDecisionNode(treeAction, node9) | |
val node7 = ShouldBankLogsDecisionNode( | |
treeAction, woodcuttingData, | |
depositBoxManager, axeManager, | |
nexusBankTaskManager, nexusBankTask!!, | |
::shouldOpenDepositBox, ::waitAfterBanking, | |
node8 | |
) | |
val node6 = ShouldDropLogsDecisionNode(woodcuttingData.logDisposal, treeAction, inventoryManager, node7) | |
val node5 = ShouldGetOptimalAxeDecisionNode( | |
nexusBankTask!!, | |
nexusBankTaskManager, | |
axeManager, | |
woodcuttingData.treeType.tree.bankPosition, | |
node6 | |
) | |
val node4 = UpdateNexusBankTaskAndAxeManagerEffectNode(axeManager, automaticAxe) { nexusBankTask = it } | |
val node3 = ShouldChangeAxesDecisionNode(woodcuttingData, axeManager, automaticAxe, node4, node5) | |
val node2 = generateCameraTasksBinaryTree(gameSettingManager = gameSettingManager, falseNode = node3) | |
val node1 = ShouldTurnOnRunDecisionNode(falseNode = node2) | |
val root = ShouldSwapToNonForestryServerDecisionNode(serverManager = serverManager, falseNode = node1) | |
return BinaryTree(root) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment