From 1122205220efe87e7fb2277e455f61875a2f612e Mon Sep 17 00:00:00 2001 From: Yuri Moens Date: Wed, 27 Oct 2021 10:18:20 +0200 Subject: [PATCH] Add CAshMiner, CPlanker and CThiever scripts --- .idea/artifacts/CAshMiner_jar.xml | 9 +++ .idea/artifacts/CPlanker_jar.xml | 9 +++ .idea/artifacts/CThiever_jar.xml | 9 +++ .idea/modules.xml | 3 + CAshMiner/CAshMiner.iml | 13 ++++ .../reisub/dreambot/cashminer/CAshMiner.java | 19 ++++++ .../reisub/dreambot/cashminer/tasks/Drop.java | 21 ++++++ .../reisub/dreambot/cashminer/tasks/Mine.java | 53 +++++++++++++++ CPlanker/CPlanker.iml | 13 ++++ .../io/reisub/dreambot/cplanker/CPlanker.java | 39 +++++++++++ .../dreambot/cplanker/tasks/BuyPlanks.java | 58 ++++++++++++++++ .../reisub/dreambot/cplanker/tasks/Chop.java | 44 ++++++++++++ .../dreambot/cplanker/tasks/Deposit.java | 39 +++++++++++ .../dreambot/cplanker/tasks/GoToSawmill.java | 67 +++++++++++++++++++ .../dreambot/cplanker/tasks/OpenBank.java | 28 ++++++++ .../dreambot/cplanker/tasks/Teleport.java | 25 +++++++ CThiever/CThiever.iml | 13 ++++ .../io/reisub/dreambot/cthiever/CThiever.java | 19 ++++++ .../reisub/dreambot/cthiever/tasks/Bank.java | 6 ++ .../dreambot/cthiever/tasks/Pickpocket.java | 54 +++++++++++++++ 20 files changed, 541 insertions(+) create mode 100644 .idea/artifacts/CAshMiner_jar.xml create mode 100644 .idea/artifacts/CPlanker_jar.xml create mode 100644 .idea/artifacts/CThiever_jar.xml create mode 100644 CAshMiner/CAshMiner.iml create mode 100644 CAshMiner/src/io/reisub/dreambot/cashminer/CAshMiner.java create mode 100644 CAshMiner/src/io/reisub/dreambot/cashminer/tasks/Drop.java create mode 100644 CAshMiner/src/io/reisub/dreambot/cashminer/tasks/Mine.java create mode 100644 CPlanker/CPlanker.iml create mode 100644 CPlanker/src/io/reisub/dreambot/cplanker/CPlanker.java create mode 100644 CPlanker/src/io/reisub/dreambot/cplanker/tasks/BuyPlanks.java create mode 100644 CPlanker/src/io/reisub/dreambot/cplanker/tasks/Chop.java create mode 100644 CPlanker/src/io/reisub/dreambot/cplanker/tasks/Deposit.java create mode 100644 CPlanker/src/io/reisub/dreambot/cplanker/tasks/GoToSawmill.java create mode 100644 CPlanker/src/io/reisub/dreambot/cplanker/tasks/OpenBank.java create mode 100644 CPlanker/src/io/reisub/dreambot/cplanker/tasks/Teleport.java create mode 100644 CThiever/CThiever.iml create mode 100644 CThiever/src/io/reisub/dreambot/cthiever/CThiever.java create mode 100644 CThiever/src/io/reisub/dreambot/cthiever/tasks/Bank.java create mode 100644 CThiever/src/io/reisub/dreambot/cthiever/tasks/Pickpocket.java diff --git a/.idea/artifacts/CAshMiner_jar.xml b/.idea/artifacts/CAshMiner_jar.xml new file mode 100644 index 0000000..32cf96c --- /dev/null +++ b/.idea/artifacts/CAshMiner_jar.xml @@ -0,0 +1,9 @@ + + + $USER_HOME$/DreamBot/Scripts + + + + + + \ No newline at end of file diff --git a/.idea/artifacts/CPlanker_jar.xml b/.idea/artifacts/CPlanker_jar.xml new file mode 100644 index 0000000..6732cb1 --- /dev/null +++ b/.idea/artifacts/CPlanker_jar.xml @@ -0,0 +1,9 @@ + + + $USER_HOME$/DreamBot/Scripts + + + + + + \ No newline at end of file diff --git a/.idea/artifacts/CThiever_jar.xml b/.idea/artifacts/CThiever_jar.xml new file mode 100644 index 0000000..fc9d929 --- /dev/null +++ b/.idea/artifacts/CThiever_jar.xml @@ -0,0 +1,9 @@ + + + $USER_HOME$/DreamBot/Scripts + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 3513e40..0e1952a 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,11 +3,14 @@ + + + diff --git a/CAshMiner/CAshMiner.iml b/CAshMiner/CAshMiner.iml new file mode 100644 index 0000000..ac9e1f0 --- /dev/null +++ b/CAshMiner/CAshMiner.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/CAshMiner/src/io/reisub/dreambot/cashminer/CAshMiner.java b/CAshMiner/src/io/reisub/dreambot/cashminer/CAshMiner.java new file mode 100644 index 0000000..ac0cbd3 --- /dev/null +++ b/CAshMiner/src/io/reisub/dreambot/cashminer/CAshMiner.java @@ -0,0 +1,19 @@ +package io.reisub.dreambot.cashminer; + +import io.reisub.dreambot.cashminer.tasks.Drop; +import io.reisub.dreambot.cashminer.tasks.Mine; +import io.reisub.dreambot.util.CTaskScript; +import io.reisub.dreambot.util.Constants; +import org.dreambot.api.script.Category; +import org.dreambot.api.script.ScriptManifest; + +@ScriptManifest(category = Category.MINING, name = "CAshMiner", author = Constants.AUTHOR, version = 1.0) +public class CAshMiner extends CTaskScript { + @Override + public void onStart() { + addNodes( + new Mine(), + new Drop() + ); + } +} diff --git a/CAshMiner/src/io/reisub/dreambot/cashminer/tasks/Drop.java b/CAshMiner/src/io/reisub/dreambot/cashminer/tasks/Drop.java new file mode 100644 index 0000000..5e7b58f --- /dev/null +++ b/CAshMiner/src/io/reisub/dreambot/cashminer/tasks/Drop.java @@ -0,0 +1,21 @@ +package io.reisub.dreambot.cashminer.tasks; + +import io.reisub.dreambot.util.CInventory; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.script.TaskNode; + +public class Drop extends TaskNode { + @Override + public boolean accept() { + return Inventory.isFull(); + } + + @Override + public int execute() { + Inventory.setDropPattern(CInventory.verticalSnakeDropPattern); + Inventory.dropAll("Soda ash"); + + return Calculations.random(250, 400); + } +} diff --git a/CAshMiner/src/io/reisub/dreambot/cashminer/tasks/Mine.java b/CAshMiner/src/io/reisub/dreambot/cashminer/tasks/Mine.java new file mode 100644 index 0000000..ef9c6e7 --- /dev/null +++ b/CAshMiner/src/io/reisub/dreambot/cashminer/tasks/Mine.java @@ -0,0 +1,53 @@ +package io.reisub.dreambot.cashminer.tasks; + +import io.reisub.dreambot.util.Constants; +import io.reisub.dreambot.util.Util; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.filter.Filter; +import org.dreambot.api.methods.interactive.GameObjects; +import org.dreambot.api.methods.map.Area; +import org.dreambot.api.methods.map.Tile; +import org.dreambot.api.methods.walking.impl.Walking; +import org.dreambot.api.script.TaskNode; +import org.dreambot.api.wrappers.interactive.GameObject; + +public class Mine extends TaskNode { + private final Area AREA = new Area( + new Tile(3787, 3767, 0), + new Tile(3787, 3775, 0), + new Tile(3803, 3775, 0), + new Tile(3802, 3765, 0)); + + @Override + public boolean accept() { + GameObject pile = GameObjects.closest(gameObject -> AREA.contains(gameObject) && gameObject.getName().equals("Ash pile")); + if (pile != null && pile.distance() < 3) { + return !Inventory.isFull() + && Util.playerIsIdle(1200); + } else { + return !Inventory.isFull() + && Util.playerIsIdle(); + } + } + + @Override + public int execute() { + GameObject pile = GameObjects.closest(gameObject -> AREA.contains(gameObject) && gameObject.getName().equals("Ash pile")); + if (pile == null) return Calculations.random(250, 400); + + if (!pile.isOnScreen()) { + if (Walking.shouldWalk(Calculations.random(4, 6))) { + Walking.walk(pile); + } + + Util.sleepUntilMoving(); + return Calculations.random(250, 400); + } + + pile.interactForceLeft(Constants.MINE); + Util.sleepUntilMovingAndAnimating(); + + return Calculations.random(250, 400); + } +} diff --git a/CPlanker/CPlanker.iml b/CPlanker/CPlanker.iml new file mode 100644 index 0000000..ac9e1f0 --- /dev/null +++ b/CPlanker/CPlanker.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/CPlanker/src/io/reisub/dreambot/cplanker/CPlanker.java b/CPlanker/src/io/reisub/dreambot/cplanker/CPlanker.java new file mode 100644 index 0000000..3f9389c --- /dev/null +++ b/CPlanker/src/io/reisub/dreambot/cplanker/CPlanker.java @@ -0,0 +1,39 @@ +package io.reisub.dreambot.cplanker; + +import io.reisub.dreambot.cplanker.tasks.*; +import io.reisub.dreambot.util.CTaskScript; +import io.reisub.dreambot.util.Constants; +import io.reisub.dreambot.util.randomevents.GenieSolver; +import org.dreambot.api.methods.skills.Skill; +import org.dreambot.api.script.Category; +import org.dreambot.api.script.ScriptManifest; + +import java.awt.*; + +@ScriptManifest(category = Category.MISC, name = "CPlanker", description = "Chops oaks at sawmill, planks and banks at CW.", author = Constants.AUTHOR, version = 1.0) +public class CPlanker extends CTaskScript { + @Override + public void onStart() { + getRandomManager().registerSolver(new GenieSolver(GenieSolver.Skill.HERBLORE)); + + getUI().addSkills(Skill.WOODCUTTING); + getUI().setCustomLines(1); + + addNodes( + new Chop(), + new BuyPlanks(), + new Teleport(), + new OpenBank(), + new Deposit(), + new GoToSawmill() + ); + } + + @Override + public void onPaint(Graphics g) { + super.onPaint(g); + + int planks = BuyPlanks.planksMade; + getUI().drawString("Planks made: " + planks + " (" + getUI().getHourlyRate(planks) + " per hour)"); + } +} diff --git a/CPlanker/src/io/reisub/dreambot/cplanker/tasks/BuyPlanks.java b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/BuyPlanks.java new file mode 100644 index 0000000..7e72df0 --- /dev/null +++ b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/BuyPlanks.java @@ -0,0 +1,58 @@ +package io.reisub.dreambot.cplanker.tasks; + +import io.reisub.dreambot.util.Util; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.input.Keyboard; +import org.dreambot.api.methods.interactive.NPCs; +import org.dreambot.api.methods.widget.Widgets; +import org.dreambot.api.script.TaskNode; +import org.dreambot.api.wrappers.interactive.NPC; +import org.dreambot.api.wrappers.widgets.WidgetChild; + +public class BuyPlanks extends TaskNode { + private boolean madePlanks; + public static int planksMade = 0; + + @Override + public boolean accept() { + return Inventory.isFull() + && Inventory.contains("Oak logs"); + } + + @Override + public int execute() { + NPC operator = NPCs.closest("Sawmill operator"); + if (operator == null) return Calculations.random(250, 400); + + operator.interact("Buy-plank"); + if (!Util.sleepUntilMoving()) return Calculations.random(250, 400); + + MethodProvider.sleepUntil(() -> operator.distance() < Calculations.random(4, 7), Calculations.random(3000, 3500)); + + if (madePlanks) { + Keyboard.holdSpace(() -> { + WidgetChild w = Widgets.getChildWidget(270, 15); + return w != null && w.isVisible(); + }, Calculations.random(3000, 3500)); + } else { + MethodProvider.sleepUntil(() -> { + WidgetChild w = Widgets.getChildWidget(270, 15); + return w != null && w.isVisible(); + }, Calculations.random(5000, 5500)); + + WidgetChild w = Widgets.getChildWidget(270, 15); + if (w != null && w.isVisible()) { + Keyboard.type("2", false); + } + } + + if (MethodProvider.sleepUntil(() -> Inventory.contains("Oak plank"), Calculations.random(5000, 5500))) { + madePlanks = true; + planksMade += Inventory.count("Oak plank"); + } + + return Calculations.random(250, 400); + } +} diff --git a/CPlanker/src/io/reisub/dreambot/cplanker/tasks/Chop.java b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/Chop.java new file mode 100644 index 0000000..9629e08 --- /dev/null +++ b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/Chop.java @@ -0,0 +1,44 @@ +package io.reisub.dreambot.cplanker.tasks; + +import io.reisub.dreambot.util.Constants; +import io.reisub.dreambot.util.Util; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.filter.Filter; +import org.dreambot.api.methods.interactive.GameObjects; +import org.dreambot.api.methods.map.Area; +import org.dreambot.api.methods.map.Tile; +import org.dreambot.api.script.TaskNode; +import org.dreambot.api.wrappers.interactive.GameObject; + +public class Chop extends TaskNode { + private final Area AREA = new Area( + new Tile(3288, 3498, 0), + new Tile(3288, 3486, 0), + new Tile(3295, 3481, 0), + new Tile(3298, 3492, 0), + new Tile(3293, 3499, 0)); + + @Override + public boolean accept() { + return !Inventory.isFull() + && findTree() != null + && Util.playerIsIdle(); + } + + @Override + public int execute() { + GameObject tree = findTree(); + if (tree == null) return Calculations.random(250, 400); + + tree.interact("Chop down"); + Util.sleepUntilMovingAndAnimating(); + + return Calculations.random(250, 400); + } + + private GameObject findTree() { + return GameObjects.closest(gameObject -> AREA.contains(gameObject) && gameObject.getName().equals("Oak")); + } +} diff --git a/CPlanker/src/io/reisub/dreambot/cplanker/tasks/Deposit.java b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/Deposit.java new file mode 100644 index 0000000..44af5dd --- /dev/null +++ b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/Deposit.java @@ -0,0 +1,39 @@ +package io.reisub.dreambot.cplanker.tasks; + +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.container.impl.bank.Bank; +import org.dreambot.api.methods.container.impl.equipment.Equipment; +import org.dreambot.api.methods.container.impl.equipment.EquipmentSlot; +import org.dreambot.api.methods.filter.Filter; +import org.dreambot.api.script.TaskNode; +import org.dreambot.api.wrappers.items.Item; + +public class Deposit extends TaskNode { + @Override + public boolean accept() { + return Bank.isOpen() + && Inventory.isFull(); + } + + @Override + public int execute() { + Bank.depositAllExcept("Coins"); + MethodProvider.sleepUntil(() -> Inventory.onlyContains("Coins"), Calculations.random(2000, 3000)); + + if (Equipment.getItemInSlot(EquipmentSlot.RING) == null) { + Filter ringFilter = item -> item.getName().startsWith("Ring of dueling"); + + while (!Inventory.contains(ringFilter)) { + Bank.withdraw(ringFilter, 1); + MethodProvider.sleepUntil(() -> Inventory.contains(ringFilter), Calculations.random(3000, 3500)); + } + } + + Bank.close(); + MethodProvider.sleepUntil(() -> !Bank.isOpen(), Calculations.random(2000, 3000)); + + return Calculations.random(250, 400); + } +} diff --git a/CPlanker/src/io/reisub/dreambot/cplanker/tasks/GoToSawmill.java b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/GoToSawmill.java new file mode 100644 index 0000000..eaea8cf --- /dev/null +++ b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/GoToSawmill.java @@ -0,0 +1,67 @@ +package io.reisub.dreambot.cplanker.tasks; + +import io.reisub.dreambot.util.Constants; +import io.reisub.dreambot.util.Util; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.filter.Filter; +import org.dreambot.api.methods.interactive.GameObjects; +import org.dreambot.api.methods.interactive.NPCs; +import org.dreambot.api.methods.interactive.Players; +import org.dreambot.api.methods.map.Tile; +import org.dreambot.api.methods.walking.impl.Walking; +import org.dreambot.api.methods.widget.Widgets; +import org.dreambot.api.script.TaskNode; +import org.dreambot.api.wrappers.interactive.GameObject; +import org.dreambot.api.wrappers.items.Item; +import org.dreambot.api.wrappers.widgets.WidgetChild; + +public class GoToSawmill extends TaskNode { + private final Tile NEAR_BALLOON = new Tile(2457, 3106, 0); + + @Override + public boolean accept() { + return Inventory.onlyContains(item -> item.getName().equals("Coins") || item.getName().startsWith("Ring of dueling")) + && NEAR_BALLOON.distance() < 50; + } + + @Override + public int execute() { + GameObject basket = GameObjects.closest("Basket"); + if (basket == null || basket.distance() > Calculations.random(6, 9)) { + if (Walking.shouldWalk(Calculations.random(4, 6))) { + Walking.walk(NEAR_BALLOON); + } + + Filter ringFilter = item -> item.getName().startsWith("Ring of dueling"); + if (Inventory.contains(ringFilter)) { + Item ring = Inventory.get(ringFilter); + ring.interact(); + MethodProvider.sleepUntil(() -> !Inventory.contains(ringFilter), Calculations.random(2000, 3000)); + } + + Util.sleepUntilMoving(); + } else { + basket.interactForceLeft(Constants.USE); + if (Util.sleepUntilMoving()) { + MethodProvider.sleepWhile(() -> Players.localPlayer().isMoving(), Calculations.random(4000, 4500)); + } else { + return Calculations.random(250, 400); + } + + MethodProvider.sleepUntil(() -> { + WidgetChild w = Widgets.getChildWidget(469, 18); + return w != null && w.isVisible(); + }, Calculations.random(4000, 4500)); + } + + WidgetChild w = Widgets.getChildWidget(469, 18); + if (w != null && w.isVisible()) { + w.interact(); + MethodProvider.sleepUntil(() -> NEAR_BALLOON.distance() > 50, Calculations.random(5000, 5500)); + } + + return Calculations.random(250, 400); + } +} diff --git a/CPlanker/src/io/reisub/dreambot/cplanker/tasks/OpenBank.java b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/OpenBank.java new file mode 100644 index 0000000..3c7995a --- /dev/null +++ b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/OpenBank.java @@ -0,0 +1,28 @@ +package io.reisub.dreambot.cplanker.tasks; + +import io.reisub.dreambot.util.Util; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.container.impl.bank.Bank; +import org.dreambot.api.methods.interactive.NPCs; +import org.dreambot.api.script.TaskNode; + +public class OpenBank extends TaskNode { + @Override + public boolean accept() { + return Inventory.contains("Oak plank") + && !Bank.isOpen() + && NPCs.closest("Sawmill operator") == null; + } + + @Override + public int execute() { + Bank.openClosest(); + if (!Util.sleepUntilMoving()) return Calculations.random(250, 400); + + MethodProvider.sleepUntil(Bank::isOpen, Calculations.random(4000, 4500)); + + return Calculations.random(250, 400); + } +} diff --git a/CPlanker/src/io/reisub/dreambot/cplanker/tasks/Teleport.java b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/Teleport.java new file mode 100644 index 0000000..cbebc34 --- /dev/null +++ b/CPlanker/src/io/reisub/dreambot/cplanker/tasks/Teleport.java @@ -0,0 +1,25 @@ +package io.reisub.dreambot.cplanker.tasks; + +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.container.impl.equipment.Equipment; +import org.dreambot.api.methods.container.impl.equipment.EquipmentSlot; +import org.dreambot.api.methods.interactive.NPCs; +import org.dreambot.api.script.TaskNode; + +public class Teleport extends TaskNode { + @Override + public boolean accept() { + return Inventory.contains("Oak plank") + && NPCs.closest("Sawmill operator") != null; + } + + @Override + public int execute() { + Equipment.interact(EquipmentSlot.RING, "Castle Wars"); + MethodProvider.sleepUntil(() -> NPCs.closest("Sawmill operator") == null, Calculations.random(2000, 3000)); + + return Calculations.random(250, 400); + } +} diff --git a/CThiever/CThiever.iml b/CThiever/CThiever.iml new file mode 100644 index 0000000..ac9e1f0 --- /dev/null +++ b/CThiever/CThiever.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/CThiever/src/io/reisub/dreambot/cthiever/CThiever.java b/CThiever/src/io/reisub/dreambot/cthiever/CThiever.java new file mode 100644 index 0000000..ccf67f1 --- /dev/null +++ b/CThiever/src/io/reisub/dreambot/cthiever/CThiever.java @@ -0,0 +1,19 @@ +package io.reisub.dreambot.cthiever; + +import io.reisub.dreambot.cthiever.tasks.Pickpocket; +import io.reisub.dreambot.util.CTaskScript; +import io.reisub.dreambot.util.Constants; +import io.reisub.dreambot.util.tasks.Eat; +import org.dreambot.api.script.Category; +import org.dreambot.api.script.ScriptManifest; + +@ScriptManifest(category = Category.THIEVING, name = "CThiever", description = "Steals like a black man", author = Constants.AUTHOR, version = 1.0) +public class CThiever extends CTaskScript { + @Override + public void onStart() { + addNodes( + new Eat(), + new Pickpocket() + ); + } +} diff --git a/CThiever/src/io/reisub/dreambot/cthiever/tasks/Bank.java b/CThiever/src/io/reisub/dreambot/cthiever/tasks/Bank.java new file mode 100644 index 0000000..898da95 --- /dev/null +++ b/CThiever/src/io/reisub/dreambot/cthiever/tasks/Bank.java @@ -0,0 +1,6 @@ +package io.reisub.dreambot.cthiever.tasks; + +import io.reisub.dreambot.util.TaskNodeParent; + +public class Bank extends TaskNodeParent { +} diff --git a/CThiever/src/io/reisub/dreambot/cthiever/tasks/Pickpocket.java b/CThiever/src/io/reisub/dreambot/cthiever/tasks/Pickpocket.java new file mode 100644 index 0000000..81522b8 --- /dev/null +++ b/CThiever/src/io/reisub/dreambot/cthiever/tasks/Pickpocket.java @@ -0,0 +1,54 @@ +package io.reisub.dreambot.cthiever.tasks; + +import io.reisub.dreambot.util.Util; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.interactive.NPCs; +import org.dreambot.api.methods.interactive.Players; +import org.dreambot.api.script.ScriptManager; +import org.dreambot.api.script.TaskNode; +import org.dreambot.api.script.listener.ChatListener; +import org.dreambot.api.wrappers.interactive.Character; +import org.dreambot.api.wrappers.interactive.NPC; +import org.dreambot.api.wrappers.widgets.message.Message; + +public class Pickpocket extends TaskNode { + private boolean attempt, failed, stole; + + public Pickpocket() { + ScriptManager.getScriptManager().addListener(new ChatListener() { + @Override + public void onMessage(Message message) { + if (message.getMessage().startsWith("You attempt")) { + attempt = true; + stole = false; + } else if (message.getMessage().startsWith("You fail")) { + failed = true; + } else if (message.getMessage().startsWith("You steal")) { + stole = true; + } + } + }); + } + + @Override + public boolean accept() { + NPC target = NPCs.closest("Master farmer"); + return (Util.playerIsIdle() || stole) + && !(Players.localPlayer().isInCombat() && Players.localPlayer().getInteractingCharacter() != null) + && Players.localPlayer().getRenderableHeight() != 1000 + && target != null + && target.isOnScreen(); + } + + @Override + public int execute() { + NPC target = NPCs.closest("Master farmer"); + if (target == null) return Calculations.random(250, 400); + + target.interact("Pickpocket"); + Util.sleepUntilMovingOrAnimating(); + + return Calculations.random(250, 400); + } +}