1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bot with one branch of tree.

Discussion in 'Projects' started by MatMad, Feb 17, 2019.

  1. MatMad

    Joined:
    May 8, 2017
    Messages:
    11
    Likes Received:
    1
    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 (Text):
    1.  
    2. package com.matmadproject.bootv2.woodcutting2;
    3.  
    4. import com.matmadproject.bootv2.woodcutting2.gui.Controller;
    5. import com.runemate.game.api.client.embeddable.EmbeddableUI;
    6. import com.runemate.game.api.hybrid.util.Resources;
    7. import com.runemate.game.api.script.framework.tree.LeafTask;
    8. import com.runemate.game.api.script.framework.tree.TreeBot;
    9. import com.runemate.game.api.script.framework.tree.TreeTask;
    10. import javafx.beans.property.ObjectProperty;
    11. import javafx.beans.property.SimpleObjectProperty;
    12. import javafx.fxml.FXMLLoader;
    13. import javafx.scene.Node;
    14.  
    15. import java.io.IOException;
    16.  
    17. public class Boot extends TreeBot implements EmbeddableUI {
    18.    
    19. private SimpleObjectProperty<Node> botInterfaceProperty;
    20.     Controller controller;
    21. // 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"
    22.     boolean start = false;
    23.     LeafTask startAction;
    24.  
    25.     public Boot() {
    26.         setEmbeddableUI(this);
    27.     }
    28.    // Here create next level
    29.     private Root rootBranch = new Root(this);
    30.    @Override
    31.     public TreeTask createRootTask() {
    32.         return rootBranch;
    33.     }
    34.    // init GUI
    35.     @Override
    36.     public ObjectProperty<? extends Node> botInterfaceProperty() {
    37.         if (botInterfaceProperty == null) {
    38.             FXMLLoader fxmlLoader = new FXMLLoader();
    39.             fxmlLoader.setController(controller = new Controller(this));
    40.             try {
    41.                 Node node = fxmlLoader.load(Resources.getAsStream("com/matmadproject/bootv2/woodcutting2/gui/WoodcuttingLiteInterface.fxml"));
    42.                 botInterfaceProperty = new SimpleObjectProperty<>(node);
    43.             } catch (IOException e) {
    44.                 e.printStackTrace();
    45.             }
    46.  
    47.         }
    48.         return botInterfaceProperty;
    49.     }
    50.  
    51.     // get state of variable start
    52.     public boolean isStart() { return start; }
    53.    
    54.    // creating Task
    55.     public void startTask(String tree, String location)
    56.     {
    57.             start = true;
    58.  
    59.             switch(tree)
    60.             {
    61.                    case "Tree":
    62.                    switch (location)
    63.                    {
    64.                        case "Falador":
    65.                            startAction = new TreeFaladorTask(tree, location);
    66.                            break;
    67.                        case "Port Sarim":
    68.                            startAction = new TreePortSarimTask(tree,location);
    69.                            break;
    70.                        case "Varrock":
    71.                            startAction = new TreeVarrockTask(tree,location);
    72.                            break;
    73.                    }
    74.                    break;          
    75.     }
    76.     // stop booting
    77.     public void stopTask()
    78.     {
    79.         start = false;
    80.     }
    81. }
    Next level, class Root, the simplest of all class.

    Code (Text):
    1. package com.matmadproject.bootv2.woodcutting2;
    2.  
    3. import com.matmadproject.bootv2.service.RunningTime;
    4. import com.runemate.game.api.hybrid.GameEvents;
    5. import com.runemate.game.api.hybrid.RuneScape;
    6. import com.runemate.game.api.script.framework.tree.BranchTask;
    7. import com.runemate.game.api.script.framework.tree.TreeTask;
    8.  
    9. public class Root extends BranchTask {
    10.  
    11.     private Boot boot;
    12.  
    13.     // We need boot here, becasue we are get from it the state of "start" and "startAction" - logic of boot.
    14.     Root(Boot boot)
    15.     {
    16.         this.boot = boot;
    17.     }
    18.  
    19. // start botting
    20.     @Override
    21.     public TreeTask successTask() { return boot.startAction; }
    22.  
    23. // checks that the button was pressed
    24.     @Override
    25.     public boolean validate()
    26.     {
    27.      
    28.         return boot.start;
    29.     }
    30. // if button wasn't pressed
    31.     @Override
    32.     public TreeTask failureTask() { return new BeforeStart(){
    33.          System.out.println("Choose task...");
    34. } }
    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 (Text):
    1. public class TreePortSarimTask extends LeafTask
    2. {
    3.     private int gameState = 0;
    4.     private String tree;
    5.     private String location;
    6.     private boolean searchTree = false;
    7.     private boolean treeFinded = false;
    8.     private int timerCase5 = 0;
    9.     private int treeLocation = 0;
    10.  
    11.     private Teleport teleport;
    12.     private Walking walking;
    13.     private Inventory inventory;
    14.     private Banking banking;
    15.     private GameRoot gameRoot;
    16.     private GameInteractablePoint gameInteractablePoint;
    17.     private Coordinate playerPoistion;
    18.  
    19.     TreePortSarimTask(String tree, String location)
    20.     {
    21.         this.tree = tree;
    22.         this.location = location;
    23.     }
    24.     @Override
    25.     public void execute()
    26.     {
    27.         switch (gameState)
    28.         {
    29.             // Here we initialize all constructors and check e.g. where we are
    30.             case 0:
    31.                 gameRoot = new GameRoot();
    32.                 gameInteractablePoint = new GameInteractablePoint(0,0);
    33.                 teleport = new Teleport(location);
    34.                 walking = new Walking(PortSarim.lodestone_TO_tree);
    35.                 inventory = new Inventory();
    36.                 banking = new Banking();
    37.                 gameState = walking.isClose(PortSarim.lodestone_TO_tree[0],5,4,1);
    38.                 if(gameState == 4)
    39.                 {
    40.                     searchTree = true;
    41.                     break;
    42.                 }
    43.  
    44.                 gameState = walking.isClose(teleport.lodestoneCoordinate,5,3,1);
    45.                 break;
    46.             case 1:
    47.                 gameState = teleport.isInterfaceOpened(2,1);
    48.                 break;
    49.             case 2:
    50.                 gameState = teleport.teleport(3,2);
    51.                 break;
    52.             case 3:
    53.                 gameState = walking.walk(4,3);
    54.                 break;
    55.             case 4:
    56. // finding trees
    57.                 if(treeFinded)
    58.                 {
    59.                     gameInteractablePoint.getInteractablePoint().click();
    60.                     treeFinded = false;
    61.                     gameState = 5;
    62.                 }
    63.                 break;
    64.             case 5:
    65.                 timerCase5++;
    66.                 gameState = inventory.isFull(7,5);
    67.                 if (Players.getLocal().getAnimationId() != -1 || timerCase5 > 2)
    68.                 {
    69.                     timerCase5 = 0;
    70.                     gameState = 6;
    71.                 }
    72.                 if(gameState == 7)
    73.                     walking.setPath(PortSarim.tree_TO_bank);
    74.                 break;
    75.             case 6:
    76.                 if(Players.getLocal().getAnimationId() == -1 && treeFinded)
    77.                 {
    78.                     gameState = 4;
    79.                     gameState = inventory.isFull(7,4);
    80.                     if(gameState == 7)
    81.                         walking.setPath(PortSarim.tree_TO_bank);
    82.                 }
    83.                 else
    84.                 {
    85.                     searchTree = true;
    86.                     gameState = 21;
    87.                 }
    88.  
    89.                 break;
    90.             case 7:
    91.                 gameState = walking.walk(8,7);
    92.                 break;
    93.             case 8:
    94.                 gameState = banking.openDepositBox(9,8);
    95.                 break;
    96.             case 9:
    97.                 gameState = banking.depositAllDepositBox(10,9);
    98.                 break;
    99.             case 10:
    100.                 gameState = banking.closeDepositBox(3,10);
    101.                 if(gameState == 3)
    102.                     walking.setPath(PortSarim.bank_TO_tree);
    103.                 break;
    104.             case 20:
    105.                 walking.setPath(PortSarim.lodestone_TO_tree);
    106.                 gameState = 3;
    107.                 break;
    108.             case 21:
    109.                 if(Players.getLocal().getAnimationId() == -1 && treeFinded)
    110.                 {
    111.                     gameState = 4;
    112.                     gameState = inventory.isFull(7,4);
    113.                     if(gameState == 7)
    114.                         walking.setPath(PortSarim.tree_TO_bank);
    115.                 }
    116.                 break;
    117.         }
    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?
     

Share This Page

Loading...