Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Main
- import org.dreambot.api.script.AbstractScript;
- import org.dreambot.api.script.Category;
- import org.dreambot.api.script.ScriptManifest;
- import org.dreambot.api.Client;
- import org.dreambot.api.methods.map.Area;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import org.dreambot.api.wrappers.interactive.GameObject;
- import org.dreambot.api.wrappers.widgets.message.Message;
- import org.dreambot.api.script.listener.MessageListener;
- import org.dreambot.api.wrappers.widgets.chatbox.ChatboxMessage;
- import TreePatch.TreePatch;
- @ScriptManifest(
- author = "Liondedan",
- description = "Completes a farming tree run",
- category = Category.FARMING,
- version = 1.0,
- name = "Farming: Tree Run"
- )
- // TODO: (priority high --> low)
- // - Loop over farming tree locations and initiate TreePatch package
- // - Implement OnMessage within TreePatch package to fix inspecing of patch
- // - Navigate between patches using house teleport (no teleport needed between Falador & Taverly)
- // - Get all required equipment from bank for tree run
- // - Paint GUI
- // - Support selection of specific trees and locations
- public class Main extends AbstractScript {
- // trees
- String tree = "Willow Tree";
- List<TreePatch> locations = Arrays.asList(
- new TreePatch(this, tree, "Treznor", "Varrock", new Area (3226, 3461,3231, 3456)),
- new TreePatch(this, tree,"Alain", "Taverly", new Area (2933, 3441,2939, 3435)),
- new TreePatch(this, tree,"Heskel", "Falador", new Area (3001, 3376,3007, 3370)),
- new TreePatch(this, tree,"Prissy Scilla", "Stronghold", new Area (2433, 3418,2438, 3411)),
- new TreePatch(this, tree,"Fayeth", "Lumbridge", new Area (3190, 3233,3196, 3229)),
- new TreePatch(this, tree,"Heskel", "Falador", new Area (3001, 3376,3007, 3370))
- );
- // TODO: Need to implement within TreePatch package
- // @Override
- // public void onMessage(Message message) {
- // super.onMessage(message);
- //
- // // inspected an empty patch
- // if(message.getMessage() != null && (message.getMessage().toLowerCase().contains("patch is empty"))){
- // log("The patch is empty");
- // locationPlot.setTreePlanted(false);
- // }
- //
- // // Inspected a growing tree that has not been treated
- // if(message.getMessage() != null && message.getMessage().toLowerCase().contains("patch has something growing") & message.getMessage().toLowerCase().contains("not been treated")){
- // log("Tree is growing but needs to be looked after");
- // locationPlot.setTreePlanted(true);
- // locationPlot.setFarmerPaid(false);
- // }
- // }
- public boolean isBusy() {
- if(getLocalPlayer().isAnimating() || getLocalPlayer().isMoving()) {
- return true;
- } else {
- return false;
- }
- }
- @Override
- public int onLoop() {
- locations.forEach(location -> {
- if (isBusy() == false) {
- location.getToLocation();
- if (location.isCompleted()) {
- } else {
- if (location.isInLocation() == false) {
- location.getToLocation();
- } else {
- if (location.hasBeenHealthChecked() == false) {
- location.checkHealth();
- } else if (location.hasBeenChopped() == false) {
- location.chopTree();
- } else if (location.isTreePlanted() == false) {
- location.plantTree();
- } else if (location.isFarmerPaid() == false) {
- location.payFarmer();
- }
- }
- }
- }
- });
- return 1000;
- }
- }
- //TreePatch
- package TreePatch;
- import org.dreambot.api.methods.MethodContext;
- import org.dreambot.api.methods.map.Area;
- import org.dreambot.api.wrappers.interactive.GameObject;
- import org.dreambot.api.wrappers.interactive.NPC;
- public class TreePatch {
- private static MethodContext mc;
- String tree;
- String farmer;
- String city;
- Area location;
- Boolean atLocation = false;
- Boolean healthChecked = false;
- Boolean isChopped = false;
- Boolean treePlanted = false;
- Boolean farmerPaid = false;
- Boolean isComplete = false;
- // This is the constructor of the class Employee
- public TreePatch(MethodContext mc, String tree, String farmer, String city, Area location) {
- this.mc = mc;
- this.location = location;
- this.tree = tree;
- this.farmer = farmer;
- this.city = city;
- }
- public void getToLocation() {
- if (location.contains(mc.getLocalPlayer())) {
- mc.log("Already at " + city + " " + tree + " location");
- atLocation = true;
- } else {
- mc.log("Walking to " + city + " " + tree + " location");
- mc.getWalking().walk(location.getRandomTile());
- }
- }
- public void checkHealth() {
- if (!healthChecked == true) {
- mc.log(city + " " + tree + ": Needs Health Check");
- GameObject treeLocation = mc.getGameObjects().closest(tree);
- // If there is a tree nearby
- if (treeLocation != null && treeLocation.distance(mc.getPlayers().localPlayer().getTile()) <= 5) {
- // And it hasn't been chopped down
- if(treeLocation.hasAction("Chop down")) {
- healthChecked = true;
- } else if (treeLocation.hasAction("Check-health")) {
- if (treeLocation.interact("Check-health")) {
- mc.log("Checked health");
- mc.sleep(2000);
- healthChecked = true;
- }
- } else {
- isChopped = true;
- healthChecked = true;
- }
- } else {
- isChopped = true;
- healthChecked = true;
- }
- }
- }
- public void chopTree() {
- mc.log("Chopping " + tree + " ...");
- GameObject treePlot = mc.getGameObjects().closest(tree);
- // If tree exists
- if (treePlot != null && treePlot.distance(mc.getPlayers().localPlayer().getTile()) <= 5) {
- // And is able to be chopped down
- if (treePlot.hasAction("Chop down")) {
- // And there is an farmer nearby
- NPC npc = mc.getNpcs().closest(farmer);
- // And the farmer is able to be paid
- if (npc != null && npc.hasAction("Pay")) {
- if (npc.interact("Pay")) {
- mc.sleep(500);
- if(mc.getDialogues().inDialogue()) {
- mc.sleep(1000);
- mc.getDialogues().chooseOption(1);
- mc.sleep(1000);
- mc.getDialogues().spaceToContinue();
- mc.log("Paid " + farmer + " to chop down " + tree);
- isChopped = true;
- }
- }
- }
- }
- }
- }
- public void inspectPlot() {
- GameObject treePatch = mc.getGameObjects().closest("Tree patch");
- GameObject treePlot = mc.getGameObjects().closest(tree);
- // If there is a treePatch
- if (treePatch != null && treePatch.distance(mc.getPlayers().localPlayer().getTile()) <= 5) {
- mc.log("Need to inspect tree patch...");
- // And it doesn't need to be raked and can be inspected
- if (!treePatch.hasAction("Rake") & treePatch.hasAction("Inspect")) {
- if (treePatch.interact("Inspect")) {
- mc.log("Inspecting Plot...");
- mc.sleep(2000);
- }
- }
- }
- if (treePlot != null && treePlot.distance(mc.getPlayers().localPlayer().getTile()) <= 5) {
- mc.log("Need to inspect tree plot...");
- // And it can be inspected
- if (treePlot.hasAction("Inspect")) {
- if (treePlot.interact("Inspect")) {
- mc.log("Inspecting Plot...");
- mc.sleep(2000);
- }
- }
- }
- }
- public void plantTree() {
- inspectPlot();
- mc.log("Need to plant a tree");
- GameObject treePatch = mc.getGameObjects().closest("Tree patch");
- GameObject treePlot = mc.getGameObjects().closest(tree);
- // If there is a tree
- if (treePatch != null && treePatch.distance(mc.getPlayers().localPlayer().getTile()) <= 5) {
- // And is it needs to be raked
- if (treePatch.hasAction("Rake")) {
- treePatch.interact("Rake");
- mc.sleep(2000);
- mc.log("Ranked " + tree + " patch");
- } else {
- mc.getInventory().get(5371).useOn(treePatch);
- mc.log("Planted " + tree );
- mc.sleep(3000);
- treePlanted = true;
- }
- } else if (treePlot != null && treePlot.distance(mc.getPlayers().localPlayer().getTile()) <= 5) {
- mc.log("There is still a tree here - needs to be chopped or health checked");
- healthChecked = false;
- isChopped = false;
- }
- }
- public void payFarmer() {
- mc.log("Paying the farmer");
- NPC npc = mc.getNpcs().closest(farmer);
- if (npc != null) {
- // If farmer can be paid
- if (npc != null && npc.hasAction("Pay")) {
- if (npc.interact("Pay")) {
- mc.sleep(3000);
- if(mc.getDialogues().inDialogue()) {
- mc.sleep(3000);
- mc.getDialogues().chooseOption(1);
- mc.sleep(3000);
- mc.getDialogues().spaceToContinue();
- mc.log("Paid " + farmer + " to look after " + tree);
- farmerPaid = true;
- isComplete = true;
- }
- }
- }
- }
- }
- // Setters
- public void setTreePlanted(Boolean s){
- this.treePlanted = s;
- }
- public void setFarmerPaid(Boolean s){
- this.farmerPaid = s;
- }
- // Getters
- public boolean hasBeenChopped() {
- if (isChopped == true) {
- MethodContext.log("isChopped == true");
- return true;
- } else if(isChopped == false) {
- mc.log("isChopped == false");
- return false;
- }
- return false;
- }
- public boolean isInLocation() {
- if (atLocation == true) {
- MethodContext.log("atLocation == true");
- return true;
- } else if(atLocation == false) {
- mc.log("atLocation == false");
- return false;
- } else {
- return false;
- }
- }
- public boolean isTreePlanted() {
- if (treePlanted == true) {
- MethodContext.log("treePlanted == true");
- return true;
- } else if(treePlanted == false) {
- mc.log("treePlanted == false");
- return false;
- } else {
- return false;
- }
- }
- public boolean isFarmerPaid() {
- if (farmerPaid == true) {
- mc.log("farmerPaid == true");
- return true;
- } else if(farmerPaid == false) {
- mc.log("farmerPaid == false");
- return false;
- } else {
- return false;
- }
- }
- public boolean hasBeenHealthChecked() {
- if(healthChecked == true) {
- mc.log("healthChecked == true");
- return true;
- } else {
- mc.log("healthChecked == false");
- return false;
- }
- }
- public boolean isCompleted() {
- if(isComplete == true) {
- mc.log("isComplete == true");
- return true;
- } else {
- mc.log("isComplete == false");
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement