From 70f7ba96c28916155eb875af897f4c149952b8c2 Mon Sep 17 00:00:00 2001 From: phil lips Date: Sun, 27 Jun 2021 15:21:47 +0000 Subject: [PATCH] Player script fixes, and bankAll scriptAPI function added --- .../kotlin/rs09/game/ai/general/ScriptAPI.kt | 20 +++++++++++++++++++ .../ai/general/scriptrepository/CoalMiner.kt | 20 +++++++++++-------- .../scriptrepository/DraynorWillows.kt | 3 ++- .../scriptrepository/LobsterCatcher.kt | 9 +++++---- .../scriptrepository/SeersMagicTrees.kt | 4 +++- .../general/scriptrepository/SharkCatcher.kt | 1 + .../scriptrepository/VarrockEssenceMiner.kt | 1 + 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/Server/src/main/kotlin/rs09/game/ai/general/ScriptAPI.kt b/Server/src/main/kotlin/rs09/game/ai/general/ScriptAPI.kt index 567aca3b3..18226073b 100644 --- a/Server/src/main/kotlin/rs09/game/ai/general/ScriptAPI.kt +++ b/Server/src/main/kotlin/rs09/game/ai/general/ScriptAPI.kt @@ -550,6 +550,26 @@ class ScriptAPI(private val bot: Player) { bot.pulseManager.run(BankingPulse()) } + /** + * Takes every item out of the bots inventory and places it into the bank. + * @param none + * @author cfunnyman joe + */ + fun bankAll(){ + class BankingPulse() : Pulse(20){ + override fun pulse(): Boolean { + for(item in bot.inventory.toArray()){ + var itemAmount = bot.inventory.getAmount(item) + + bot.inventory.remove(item) + bot.bank.add(item) + } + return true + } + } + bot.pulseManager.run(BankingPulse()) + } + /** * Function that makes the bot eat the food item in their inventory if their HP is below 2/3. * @author Ceikry diff --git a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/CoalMiner.kt b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/CoalMiner.kt index 9fc4b307b..1d3a533ed 100644 --- a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/CoalMiner.kt +++ b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/CoalMiner.kt @@ -1,5 +1,6 @@ package rs09.game.ai.general.scriptrepository + import core.game.interaction.DestinationFlag import core.game.interaction.MovementPulse import core.game.node.Node @@ -11,21 +12,24 @@ import rs09.game.ai.general.ScriptAPI import rs09.game.ai.skillingbot.SkillingBotAssembler import rs09.game.interaction.InteractionListener import rs09.game.interaction.InteractionListeners +import api.ContentAPI +import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking +import java.util.logging.Handler @PlayerCompatible @ScriptName("Falador Coal Miner") @ScriptDescription("Start in Falador East Bank with a pick equipped","or in your inventory.") @ScriptIdentifier("fally_coal") -class CoalMiner() : Script() { +class CoalMiner : Script() { var state = State.INIT var ladderSwitch = false - val bottomLadder = ZoneBorders(3016,9736,3024,9742) val topLadder = ZoneBorders(3016,3336,3022,3342) val mine = ZoneBorders(3027,9733,3054,9743) val bank = ZoneBorders(3009,3355,3018,3358) var overlay: ScriptAPI.BottingOverlay? = null - var coalAmount = 0 + var coalAmount = 0 override fun tick() { when(state){ @@ -47,6 +51,7 @@ class CoalMiner() : Script() { } State.MINING -> { + bot.interfaceManager.close() if(bot.inventory.freeSlots() == 0){ state = State.TO_BANK } @@ -56,7 +61,7 @@ class CoalMiner() : Script() { val rock = scriptAPI.getNearestNode("rocks",true) rock?.let { InteractionListeners.run(rock.id, InteractionListener.OBJECT,"mine",bot,rock) } } - overlay!!.setAmount(bot.inventory.getAmount(Items.COAL_453) + coalAmount) + overlay!!.setAmount(ContentAPI.amountInInventory(bot, Items.COAL_453) + coalAmount) } State.TO_BANK -> { @@ -83,13 +88,14 @@ class CoalMiner() : Script() { } State.BANKING -> { - coalAmount += bot.inventory.getAmount(Items.COAL_453) - scriptAPI.bankItem(Items.COAL_453) + coalAmount += bot.inventory.getAmount(Items.COAL_453) + scriptAPI.bankAll() state = State.TO_MINE } State.TO_MINE -> { if(ladderSwitch){ + bot.interfaceManager.close() if(!topLadder.insideBorder(bot.location)){ scriptAPI.walkTo(topLadder.randomLoc) } else { @@ -124,7 +130,6 @@ class CoalMiner() : Script() { scriptAPI.teleport(bank.randomLoc) state = State.TO_MINE } - } } @@ -156,5 +161,4 @@ class CoalMiner() : Script() { equipment.add(Item(Items.IRON_PICKAXE_1267)) skills.put(Skills.MINING,75) } - } \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/DraynorWillows.kt b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/DraynorWillows.kt index b9195bb2e..c7051f8e3 100644 --- a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/DraynorWillows.kt +++ b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/DraynorWillows.kt @@ -41,8 +41,9 @@ class DraynorWillows : Script(){ scriptAPI.walkTo(willowZone.randomLoc) else { val willowtree = scriptAPI.getNearestNode("willow", true) + bot.interfaceManager.close() willowtree?.let { InteractionListeners.run(willowtree.id, - InteractionListener.OBJECT,"chop",bot,willowtree) } + InteractionListener.OBJECT,"Chop down",bot,willowtree) } if (bot.inventory.isFull) state = State.BANKING } diff --git a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/LobsterCatcher.kt b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/LobsterCatcher.kt index 6863f20dd..d8364100c 100644 --- a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/LobsterCatcher.kt +++ b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/LobsterCatcher.kt @@ -69,6 +69,7 @@ class LobsterCatcher : Script() { State.FISHING -> { + bot.interfaceManager.close() val spot = scriptAPI.getNearestNode(333, false) if(spot == null){ state = State.IDLE @@ -163,10 +164,10 @@ class LobsterCatcher : Script() { init { - val setUp = RandomFunction.random(Sets.values().size) - equipment.addAll(Sets.values()[setUp].equipment) - inventory.add(Item(301)) - skills[Skills.FISHING] = 40 + val setUp = RandomFunction.random(Sets.values().size) + equipment.addAll(Sets.values()[setUp].equipment) + inventory.add(Item(301)) + skills[Skills.FISHING] = 40 } enum class State{ diff --git a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/SeersMagicTrees.kt b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/SeersMagicTrees.kt index 48b7b45c3..313ad1561 100644 --- a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/SeersMagicTrees.kt +++ b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/SeersMagicTrees.kt @@ -39,7 +39,8 @@ class SeersMagicTrees : Script(){ State.CHOPPING -> { val tree = scriptAPI.getNearestNode(1306,true) - tree?.let { InteractionListeners.run(tree.id, InteractionListener.OBJECT,"chop",bot,tree) } + bot.interfaceManager.close() + tree?.let { InteractionListeners.run(tree.id, InteractionListener.OBJECT,"Chop down",bot,tree) } if(bot.inventory.isFull){ state = State.FIND_BANK } @@ -69,6 +70,7 @@ class SeersMagicTrees : Script(){ } State.RETURN_TO_TREES -> { + bot.interfaceManager.close() if(!magicsZone.insideBorder(bot)){ scriptAPI.walkTo(magicsZone.randomLoc) } else { diff --git a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/SharkCatcher.kt b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/SharkCatcher.kt index 2d78e48a0..f1a909d53 100644 --- a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/SharkCatcher.kt +++ b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/SharkCatcher.kt @@ -114,6 +114,7 @@ class SharkCatcher : Script() { } State.FISHING -> { + bot.interfaceManager.close() if (Random.nextBoolean()) { tick = 0 val spot = scriptAPI.getNearestNode(334, false) diff --git a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/VarrockEssenceMiner.kt b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/VarrockEssenceMiner.kt index d429713c4..5054b98e0 100644 --- a/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/VarrockEssenceMiner.kt +++ b/Server/src/main/kotlin/rs09/game/ai/general/scriptrepository/VarrockEssenceMiner.kt @@ -22,6 +22,7 @@ class VarrockEssenceMiner : Script(){ when(state){ State.TO_ESSENCE -> { + bot.interfaceManager.close() if(!auburyZone.insideBorder(bot)) scriptAPI.walkTo(auburyZone.randomLoc) else {