Skip to content

Instantly share code, notes, and snippets.

@its-jackson
Created February 23, 2024 20:26
Show Gist options
  • Save its-jackson/c4444f0c460805e5029bd1a23062bf0e to your computer and use it in GitHub Desktop.
Save its-jackson/c4444f0c460805e5029bd1a23062bf0e to your computer and use it in GitHub Desktop.
Src
package scripts.nexus.sdk.routine.api.mort.myre.fungus
import org.tribot.script.sdk.*
import org.tribot.script.sdk.antiban.Antiban
import org.tribot.script.sdk.painting.Painting
import org.tribot.script.sdk.painting.template.basic.BasicPaintTemplate
import org.tribot.script.sdk.pricing.Pricing
import org.tribot.script.sdk.query.Query
import org.tribot.script.sdk.tasks.BankTask
import org.tribot.script.sdk.types.GameObject
import org.tribot.script.sdk.types.WorldTile
import org.tribot.script.sdk.util.TribotRandom
import org.tribot.script.sdk.walking.LocalWalking
import scripts.nexus.sdk.BankLocation
import scripts.nexus.sdk.antiban.DistributionParameters
import scripts.nexus.sdk.antiban.PlayerBehaviorProfile
import scripts.nexus.sdk.canReach
import scripts.nexus.sdk.preciseLocalWalkTo
import scripts.nexus.sdk.routine.*
import scripts.nexus.sdk.routine.api.*
import scripts.nexus.sdk.routine.api.interfaces.*
import kotlin.jvm.optionals.getOrNull
class MortMyreFungusPickerRoutine(
name: String,
metrics: Metrics,
failurePolicy: FailurePolicy,
status: RoutineStatus,
nexusBankTask: NexusBankTask?,
nexusBankTaskManager: NexusBankTaskManager,
bankTask: BankTask?,
bankTaskManager: TribotBankTaskManager,
authenticationManager: TribotAuthenticationManager,
serverManager: TribotServerManager,
consumableManager: TribotConsumableManager?,
foodManager: TribotFoodManager?,
threadExecutionManager: TribotThreadExecutionManager,
) : TribotRoutine(
name,
metrics,
failurePolicy,
status,
nexusBankTask,
nexusBankTaskManager,
bankTask,
bankTaskManager,
authenticationManager,
serverManager,
consumableManager,
foodManager,
threadExecutionManager
) {
private var target: GameObject? = null
private val silverSickleBId = 2963
private val ivandisFlailId = 22398
private val shroomsId = 2970
private val drakansId = TeleportableRegistry.DRAKANS_MEDALLION.teleportable.getIdsForTeleportableItem()[0]
private val fungusRegionId = 14642
private val verSinhazaBankTile = WorldTile(3650, 3210, 0)
private val tileOne = WorldTile(3667, 3255, 0)
private val tileTwo = WorldTile(3672, 3256, 0)
private val tileOnePath = listOf(
WorldTile(3650, 3210, 0),
WorldTile(3650, 3210, 0),
WorldTile(3651, 3211, 0),
WorldTile(3651, 3212, 0),
WorldTile(3652, 3213, 0),
WorldTile(3653, 3214, 0),
WorldTile(3654, 3214, 0),
WorldTile(3654, 3214, 0),
WorldTile(3654, 3215, 0),
WorldTile(3654, 3216, 0),
WorldTile(3654, 3217, 0),
WorldTile(3654, 3218, 0),
WorldTile(3654, 3219, 0),
WorldTile(3654, 3219, 0),
WorldTile(3654, 3220, 0),
WorldTile(3654, 3221, 0),
WorldTile(3654, 3222, 0),
WorldTile(3654, 3222, 0),
WorldTile(3654, 3223, 0),
WorldTile(3654, 3224, 0),
WorldTile(3654, 3224, 0),
WorldTile(3653, 3224, 0),
WorldTile(3653, 3225, 0),
WorldTile(3653, 3226, 0),
WorldTile(3653, 3227, 0),
WorldTile(3654, 3227, 0),
WorldTile(3654, 3227, 0),
WorldTile(3654, 3228, 0),
WorldTile(3654, 3229, 0),
WorldTile(3654, 3230, 0),
WorldTile(3653, 3231, 0),
WorldTile(3653, 3231, 0),
WorldTile(3654, 3232, 0),
WorldTile(3655, 3232, 0),
WorldTile(3656, 3232, 0),
WorldTile(3657, 3232, 0),
WorldTile(3658, 3232, 0),
WorldTile(3659, 3232, 0),
WorldTile(3660, 3232, 0),
WorldTile(3661, 3231, 0),
WorldTile(3662, 3231, 0),
WorldTile(3662, 3231, 0),
WorldTile(3662, 3232, 0),
WorldTile(3662, 3233, 0),
WorldTile(3662, 3234, 0),
WorldTile(3662, 3235, 0),
WorldTile(3662, 3236, 0),
WorldTile(3662, 3237, 0),
WorldTile(3662, 3238, 0),
WorldTile(3662, 3239, 0),
WorldTile(3662, 3240, 0),
WorldTile(3662, 3241, 0),
WorldTile(3661, 3241, 0),
WorldTile(3660, 3241, 0),
WorldTile(3660, 3242, 0),
WorldTile(3660, 3243, 0),
WorldTile(3660, 3244, 0),
WorldTile(3660, 3245, 0),
WorldTile(3660, 3245, 0),
WorldTile(3660, 3246, 0),
WorldTile(3660, 3247, 0),
WorldTile(3660, 3248, 0),
WorldTile(3660, 3249, 0),
WorldTile(3660, 3250, 0),
WorldTile(3660, 3251, 0),
WorldTile(3660, 3252, 0),
WorldTile(3660, 3253, 0),
WorldTile(3660, 3253, 0),
WorldTile(3660, 3254, 0),
WorldTile(3660, 3255, 0),
WorldTile(3660, 3256, 0),
WorldTile(3660, 3257, 0),
WorldTile(3661, 3258, 0),
WorldTile(3662, 3258, 0),
WorldTile(3663, 3258, 0),
WorldTile(3664, 3258, 0),
WorldTile(3665, 3258, 0),
WorldTile(3666, 3258, 0)
)
private val antibanManager = AntibanManager(AntibanTaskProfileManager)
private val gameSettingManager = GameSettingManager()
private val silverSickleNexusBankTask: NexusDefaultBankTask =
NexusDefaultBankTask.builder()
.addEquipmentItem(EquipmentReq.slot(Equipment.Slot.WEAPON).item(silverSickleBId, Amount.of(1)))
.addEquipmentItem(EquipmentReq.slot(Equipment.Slot.NECK).item(drakansId, Amount.of(1)))
.addEquipmentItem(
EquipmentReq.slot(Equipment.Slot.RING).chargedItem(
TeleportableRegistry.RING_OF_DUELING.teleportable.baseName,
TeleportableRegistry.RING_OF_DUELING.teleportable.getMinChargeForChargeableItem())
)
.build()
private val ivandisFlailNexusBankTask: NexusDefaultBankTask =
NexusDefaultBankTask.builder()
.addEquipmentItem(EquipmentReq.slot(Equipment.Slot.WEAPON).item(ivandisFlailId, Amount.of(1)))
.addEquipmentItem(EquipmentReq.slot(Equipment.Slot.NECK).item(drakansId, Amount.of(1)))
.addEquipmentItem(
EquipmentReq.slot(Equipment.Slot.RING).chargedItem(
TeleportableRegistry.RING_OF_DUELING.teleportable.baseName,
TeleportableRegistry.RING_OF_DUELING.teleportable.getMinChargeForChargeableItem())
)
.build()
private val shroomsPrice = Pricing.lookupPrice(shroomsId).getOrNull() ?: 0
private var shroomsPicked = 0
private var bloomCasted = 0
private var goldGained = 0
private val waitBeforeNextPickActionProfile = PlayerBehaviorProfile(
variable1Parameters = DistributionParameters(500.0, 50.0),
variable2Parameters = DistributionParameters(35.0, 5.0)
)
private val waitBeforeNextCastActionProfile = PlayerBehaviorProfile(
variable1Parameters = DistributionParameters(300.00, 25.00),
variable2Parameters = DistributionParameters(15.00, 4.0)
)
private val waitBeforeNextRestoreActionProfile = PlayerBehaviorProfile(
variable1Parameters = DistributionParameters(750.00, 10.00),
variable2Parameters = DistributionParameters(6.0, 1.0)
)
private fun waitBeforeNextPickAction() {
val delay = TribotRandom.normal(
waitBeforeNextPickActionProfile.variable1,
waitBeforeNextPickActionProfile.variable2
).coerceIn(0.0, 1000.0)
.toInt()
logger.debug("Waiting before next picking action: $delay")
Waiting.wait(delay)
}
private fun waitBeforeNextCastAction() {
val delay = TribotRandom.normal(
waitBeforeNextCastActionProfile.variable1,
waitBeforeNextCastActionProfile.variable2
).coerceIn(0.0, 750.0)
.toInt()
logger.debug("Waiting before next casting action: $delay")
Waiting.wait(delay)
}
private fun waitBeforeNextRegenerateAction() {
val delay = TribotRandom.normal(
waitBeforeNextRestoreActionProfile.variable1,
waitBeforeNextRestoreActionProfile.variable2
).coerceIn(0.0, 800.0)
.toInt()
logger.debug("Waiting before next regenerate action: $delay")
Waiting.wait(delay)
}
private val mainScriptPaint: BasicPaintTemplate = scriptPaint.templateBuilder
.row(
scriptPaint.tagLine.toBuilder()
.label { "Routine" }
.value { this.name }
.build()
)
.row(
scriptPaint.tagLine.toBuilder()
.label { "Routine status" }
.value { this.status }
.build()
)
.row(
scriptPaint.tagLine.toBuilder()
.label("Gold/hr")
.value { "${this.goldGained} (${calculatePerHour(this.goldGained, this.startTime)}/hr)" }
.build()
)
.row(
scriptPaint.tagLine.toBuilder()
.label("Shrooms picked/hr")
.value { "${this.shroomsPicked} (${calculatePerHour(this.shroomsPicked, this.startTime)}/hr)" }
.build()
)
.row(
scriptPaint.tagLine.toBuilder()
.label("Bloom casts/hr")
.value { "${this.bloomCasted} (${calculatePerHour(this.bloomCasted, this.startTime)}/hr)" }
.build()
)
.build()
private fun isPrayerPointsDepleted() = Prayer.getPrayerPoints() == 0
private fun getFungiLogQuery() =
Query.gameObjects()
.maxDistance(10.0)
.isReachable
.nameContains("Fungi on log")
private fun isAnyFungiOnLog() = getFungiLogQuery().isAny
private fun findBestFungiOnLog() = getFungiLogQuery().findBestInteractable().getOrNull()
private fun pickAnyFungiOnLog(fungi: GameObject) = fungi.interact("Pick")
private fun castBloom(): Boolean {
val items = Query.equipment().actionContains("Bloom").toList() +
Query.inventory().actionContains("Bloom").toList()
val first = items.firstOrNull() ?: return false
Widgets.closeAll()
if (!Waiting.waitUntil(TribotRandom.uniform(1200, 3200)) { first.click("Bloom") }) {
return false
}
return true
}
private fun isAtFeroxEnclave() =
canReach(BankLocation.FEROX_ENCLAVE.position)
private fun ensurePlayerInFeroxEnclave(): Boolean {
if (isAtFeroxEnclave()) {
return true
}
if (!TeleportableRegistry.RING_OF_DUELING.teleportable.executeTeleport("ferox enclave")) {
Waiting.waitNormal(750, 67)
return false
}
Waiting.waitNormal(250, 67)
return Waiting.waitUntil(2500) { isAtFeroxEnclave() }
}
private fun restorePlayerState() =
Query.gameObjects()
.nameEquals("Pool of Refreshment")
.findBestInteractable()
.getOrNull()
?.interact("Drink") ?: false
private fun waitUntilPlayerStateRestored() =
Waiting.waitUntil { Skill.PRAYER.actualLevel == Skill.PRAYER.currentLevel }
private fun completePlayerStateRestoreSequence() =
RetryLoopWorker("Regenerate Player State", DefaultFailurePolicy(3)) {
if (!ensurePlayerInFeroxEnclave()) {
return@RetryLoopWorker false
}
if (!restorePlayerState()) {
return@RetryLoopWorker false
}
if (!waitUntilPlayerStateRestored()) {
return@RetryLoopWorker false
}
waitBeforeNextRegenerateAction()
true
}.tryAction()
private fun completeWalkToTileOneSequence() =
RetryLoopWorker("Ensure At Rotting Logs", DefaultFailurePolicy(3)) {
if (MyPlayer.getTile().regionId != fungusRegionId && !TeleportableRegistry.DRAKANS_MEDALLION.teleportable.executeTeleport("ver sinhaza")) {
return@RetryLoopWorker false
}
if (tileOne.distance() > 10 && !LocalWalking.walkPath(tileOnePath)) {
return@RetryLoopWorker false
}
if (tileOne.distance() in 1..10 && !preciseLocalWalkTo(tileOne, 0)) {
return@RetryLoopWorker false
}
true
}.tryAction()
override fun configureTribot(setAntibanEnabled: Boolean, setMouseSpeed: Int?) {
super.configureTribot(false, null)
}
override fun setup(context: RoutineContext): RoutineStatus {
Painting.addPaint { mainScriptPaint.render(it) }
Painting.addPaint {
target?.let { gameObject: GameObject ->
gameObject.model
.flatMap { model -> model.bounds }
.ifPresent { bounds -> it.draw(bounds) }
}
}
Painting.addPaint {
tileOne.bounds
.getOrNull()
?.let { b -> it.draw(b) }
}
if (!authenticationManager.login()) {
return RoutineStatus.KILL
}
gameSettingManager.executeTasks(
MuteAllAudioTask(),
SetCameraZoomTask(SetCameraZoomTask.CameraZoomSetting.ZOOM_MID),
EnableShiftClickDroppingTask(),
SetFixedScreenModeTask()
)
if (MyPlayer.getTile().regionId == fungusRegionId && LocalWalking.walkPath(tileOnePath.reversed())) {
if (!ensureOpenBank()) {
return RoutineStatus.FAILURE
}
Bank.depositInventory()
Waiting.waitNormal(550, 25)
}
val flailRes = nexusBankTaskManager.executeUnsatisfiedTask(ivandisFlailNexusBankTask)
nexusBankTask = if (flailRes == null) {
ivandisFlailNexusBankTask
}
else {
silverSickleNexusBankTask
}
if (nexusBankTaskManager.executeUnsatisfiedTask(nexusBankTask!!) != null) {
logger.error("Have items Silver sickle (b) or Ivandis fail")
logger.error("Drakan's medallion and Ring of dueling.")
return RoutineStatus.FAILURE
}
return RoutineStatus.SUCCESS
}
override fun executeLogic(
context: RoutineContext,
stop: List<RoutineStopCondition>
): RoutineStatus {
return when {
target !== null -> {
target = null
RoutineStatus.SUCCESS
}
Antiban.shouldTurnOnRun() && !Options.isRunEnabled() -> condition { Options.setRunEnabled(true) }
shouldExecuteCameraRotationTask() -> condition { executeCameraRotationTask(gameSettingManager) }
shouldExecuteCameraAngleTask() -> condition { executeCameraAngleTask(gameSettingManager) }
isAtFeroxEnclave() -> condition {
if (nexusBankTaskManager.executeForceTask(nexusBankTask!!, BankLocation.FEROX_ENCLAVE.position) != null) {
return@condition false
}
if (Skill.PRAYER.currentLevel != Skill.PRAYER.actualLevel && !completePlayerStateRestoreSequence()) {
return@condition false
}
completeWalkToTileOneSequence()
}
MyPlayer.getAccountType().isIronman || MyPlayer.getAccountType().isGroupIronman && Inventory.isFull() -> condition {
if (MyPlayer.getTile().regionId == fungusRegionId && LocalWalking.walkPath(tileOnePath.reversed())) {
if (!ensureOpenBank()) {
return@condition false
}
if (nexusBankTaskManager.executeForceTask(nexusBankTask!!, verSinhazaBankTile) != null) {
return@condition false
}
Waiting.waitNormal(550, 25)
return@condition true
}
false
}
!MyPlayer.getAccountType().isIronman && !MyPlayer.getAccountType().isGroupIronman && Inventory.isFull() -> condition { ensurePlayerInFeroxEnclave() }
isPrayerPointsDepleted() -> condition { ensurePlayerInFeroxEnclave() }
tileOne.distance() >= 10 -> condition { completeWalkToTileOneSequence() }
isAnyFungiOnLog() -> condition(RoutineStatus.RETRY) {
val fungi = findBestFungiOnLog() ?: return@condition false
target = fungi
val shroomsBefore = Inventory.getCount(shroomsId)
if (!pickAnyFungiOnLog(fungi)) {
return@condition false
}
if (!Waiting.waitUntil { Inventory.getCount(shroomsId) > shroomsBefore }) {
return@condition false
}
val shroomsCollected = Inventory.getCount(shroomsId) - shroomsBefore
if (shroomsCollected > 0) {
shroomsPicked += shroomsCollected
goldGained += shroomsPrice * shroomsCollected
}
target = null
waitBeforeNextPickAction()
true
}
else -> {
antibanManager.executeRandomMouseMoveTask()
antibanManager.executeEntityHoverTask()
if (tileOne.distance() > 0 && !preciseLocalWalkTo(tileOne, 0)) {
return RoutineStatus.RETRY
}
if (castBloom() && Waiting.waitUntil(2200) { isAnyFungiOnLog() }) {
bloomCasted++
waitBeforeNextCastAction()
return RoutineStatus.SUCCESS
}
RoutineStatus.FAILURE
}
}
}
override fun cleanup(context: RoutineContext): RoutineStatus {
if (!threadExecutionManager.shutdownTasks()) {
return RoutineStatus.KILL
}
return RoutineStatus.SUCCESS
}
override fun updateSharedContext(context: RoutineContext) {
//
}
override fun updateRoutineScopeContext(context: RoutineContext) {
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment