Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Bot with one branch of tree.

Joined
May 8, 2017
Messages
11
I wanna show you bot which need few class to work. One class which extends TreeBot class and create Root class - it's second class. The last class which extends LeafTask. If we have GUI we need one more - Controler class. It's all what you need to work. You don't need ever more many Leaf and BranchTask class.
Now i will show you my example:

TreeBot class:
Here we can implemets Interfaces like Inventory, Skill etc.
Code:
package com.matmadproject.bootv2.woodcutting2;

import com.matmadproject.bootv2.woodcutting2.gui.Controller;
import com.runemate.game.api.client.embeddable.EmbeddableUI;
import com.runemate.game.api.hybrid.util.Resources;
import com.runemate.game.api.script.framework.tree.LeafTask;
import com.runemate.game.api.script.framework.tree.TreeBot;
import com.runemate.game.api.script.framework.tree.TreeTask;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;

import java.io.IOException;

public class Boot extends TreeBot implements EmbeddableUI {
    
private SimpleObjectProperty<Node> botInterfaceProperty;
    Controller controller;
// this variabble this variable starts botting, we change it on Controller class by press e.g. ButtonStart which run method, which assigns new LeafTask "startAction"
    boolean start = false;
    LeafTask startAction;

    public Boot() {
        setEmbeddableUI(this);
    }
   // Here create next level
    private Root rootBranch = new Root(this);
   @Override
    public TreeTask createRootTask() {
        return rootBranch;
    }
   // init GUI
    @Override
    public ObjectProperty<? extends Node> botInterfaceProperty() {
        if (botInterfaceProperty == null) {
            FXMLLoader fxmlLoader = new FXMLLoader();
            fxmlLoader.setController(controller = new Controller(this));
            try {
                Node node = fxmlLoader.load(Resources.getAsStream("com/matmadproject/bootv2/woodcutting2/gui/WoodcuttingLiteInterface.fxml"));
                botInterfaceProperty = new SimpleObjectProperty<>(node);
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        return botInterfaceProperty;
    }

    // get state of variable start
    public boolean isStart() { return start; }
    
   // creating Task
    public void startTask(String tree, String location)
    {
            start = true;

            switch(tree)
            {
                   case "Tree":
                   switch (location)
                   {
                       case "Falador":
                           startAction = new TreeFaladorTask(tree, location);
                           break;
                       case "Port Sarim":
                           startAction = new TreePortSarimTask(tree,location);
                           break;
                       case "Varrock":
                           startAction = new TreeVarrockTask(tree,location);
                           break;
                   }
                   break;          
    }
    // stop booting
    public void stopTask()
    {
        start = false;
    }
}

Next level, class Root, the simplest of all class.

Code:
package com.matmadproject.bootv2.woodcutting2;

import com.matmadproject.bootv2.service.RunningTime;
import com.runemate.game.api.hybrid.GameEvents;
import com.runemate.game.api.hybrid.RuneScape;
import com.runemate.game.api.script.framework.tree.BranchTask;
import com.runemate.game.api.script.framework.tree.TreeTask;

public class Root extends BranchTask {

    private Boot boot;

    // We need boot here, becasue we are get from it the state of "start" and "startAction" - logic of boot.
    Root(Boot boot)
    {
        this.boot = boot;
    }
 
// start botting
    @Override
    public TreeTask successTask() { return boot.startAction; }

// checks that the button was pressed
    @Override
    public boolean validate()
    {
      
        return boot.start;
    }
// if button wasn't pressed
    @Override
    public TreeTask failureTask() { return new BeforeStart(){
         System.out.println("Choose task...");
} }

BootLogic
This class is based on "switch" and int methods, which return fail and success value. Thats value is gameState.
This is similar to jump to the next level from the TreeBot system.


Code:
public class TreePortSarimTask extends LeafTask
{
    private int gameState = 0;
    private String tree;
    private String location;
    private boolean searchTree = false;
    private boolean treeFinded = false;
    private int timerCase5 = 0;
    private int treeLocation = 0;

    private Teleport teleport;
    private Walking walking;
    private Inventory inventory;
    private Banking banking;
    private GameRoot gameRoot;
    private GameInteractablePoint gameInteractablePoint;
    private Coordinate playerPoistion;

    TreePortSarimTask(String tree, String location)
    {
        this.tree = tree;
        this.location = location;
    }
    @Override
    public void execute()
    {
        switch (gameState)
        {
            // Here we initialize all constructors and check e.g. where we are
            case 0:
                gameRoot = new GameRoot();
                gameInteractablePoint = new GameInteractablePoint(0,0);
                teleport = new Teleport(location);
                walking = new Walking(PortSarim.lodestone_TO_tree);
                inventory = new Inventory();
                banking = new Banking();
                gameState = walking.isClose(PortSarim.lodestone_TO_tree[0],5,4,1);
                if(gameState == 4)
                {
                    searchTree = true;
                    break;
                }

                gameState = walking.isClose(teleport.lodestoneCoordinate,5,3,1);
                break;
            case 1:
                gameState = teleport.isInterfaceOpened(2,1);
                break;
            case 2:
                gameState = teleport.teleport(3,2);
                break;
            case 3:
                gameState = walking.walk(4,3);
                break;
            case 4:
// finding trees
                if(treeFinded)
                {
                    gameInteractablePoint.getInteractablePoint().click();
                    treeFinded = false;
                    gameState = 5;
                }
                break;
            case 5:
                timerCase5++;
                gameState = inventory.isFull(7,5);
                if (Players.getLocal().getAnimationId() != -1 || timerCase5 > 2)
                {
                    timerCase5 = 0;
                    gameState = 6;
                }
                if(gameState == 7)
                    walking.setPath(PortSarim.tree_TO_bank);
                break;
            case 6:
                if(Players.getLocal().getAnimationId() == -1 && treeFinded)
                {
                    gameState = 4;
                    gameState = inventory.isFull(7,4);
                    if(gameState == 7)
                        walking.setPath(PortSarim.tree_TO_bank);
                }
                else
                {
                    searchTree = true;
                    gameState = 21;
                }

                break;
            case 7:
                gameState = walking.walk(8,7);
                break;
            case 8:
                gameState = banking.openDepositBox(9,8);
                break;
            case 9:
                gameState = banking.depositAllDepositBox(10,9);
                break;
            case 10:
                gameState = banking.closeDepositBox(3,10);
                if(gameState == 3)
                    walking.setPath(PortSarim.bank_TO_tree);
                break;
            case 20:
                walking.setPath(PortSarim.lodestone_TO_tree);
                gameState = 3;
                break;
            case 21:
                if(Players.getLocal().getAnimationId() == -1 && treeFinded)
                {
                    gameState = 4;
                    gameState = inventory.isFull(7,4);
                    if(gameState == 7)
                        walking.setPath(PortSarim.tree_TO_bank);
                }
                break;
        }

In this example i didn't show Controller class. There is no need to understand the action. I'm waiting for yours answers. What do you think about that?
 
Top