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

Bug Mining Bot, Problem with changing mining area at startup.

Discussion in 'Developer Support' started by kronosqc, Jun 13, 2019.

Tags:
  1. kronosqc

    Joined:
    Aug 23, 2016
    Messages:
    20
    Likes Received:
    3
    As the title say it all, i'm currently making a mining bot, that allow me to switch ''ore to be mined at bot startup''.
    This does works.

    Well, the only problem is i cant seems to do the same with the Mining Area location depending on which ore i choose. if someone could help me a bit, thanks you a lot !
     
  2. TrippyToad

    Joined:
    Jun 5, 2019
    Messages:
    7
    Likes Received:
    2
  3. kronosqc

    Joined:
    Aug 23, 2016
    Messages:
    20
    Likes Received:
    3
    package com.kronosqc.bots.bots;

    import com.runemate.game.api.hybrid.Environment;
    import com.runemate.game.api.hybrid.entities.GameObject;
    import com.runemate.game.api.hybrid.local.Camera;
    import com.runemate.game.api.hybrid.local.hud.interfaces.Bank;
    import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
    import com.runemate.game.api.hybrid.location.Area;
    import com.runemate.game.api.hybrid.location.Coordinate;
    import com.runemate.game.api.hybrid.location.navigation.Traversal;
    import com.runemate.game.api.hybrid.location.navigation.web.WebPath;
    import com.runemate.game.api.hybrid.queries.results.LocatableEntityQueryResults;
    import com.runemate.game.api.hybrid.region.GameObjects;
    import com.runemate.game.api.hybrid.region.Players;
    import com.runemate.game.api.script bot.Execution;
    import com.runemate.game.api.script bot.framework.LoopingBot;
    import com.runemate.game.api.script bot.framework.core.LoopingThread;
    import com.runemate.game.api.script bot.framework.task.TaskBot;
    import com.runemate.game.api.script bot.framework.tree.BranchTask;
    import com.runemate.game.api.script bot.framework.tree.LeafTask;
    import com.runemate.game.api.script bot.framework.tree.TreeTask;

    public class Root extends LeafTask {
    private RuniteMiner bot;

    public Root(RuniteMiner bot) {
    this.bot = bot;
    }

    final Area bankArea = new Area.Rectangular(new Coordinate(3014, 3355, 0), new Coordinate(3014, 3355, 0));
    final Area miningArea = new Area.Rectangular(new Coordinate(3690, 3399, 0), new Coordinate(3690, 3399, 0));
    final Area miningArea2 = new Area.Rectangular(new Coordinate(3690, 3399, 0), new Coordinate(3690, 3399, 0));

    public Area treeArea;
    public final Area YEW_TREE_AREA = new Area.Rectangular(new Coordinate(3029, 9735, 0), new Coordinate(3029, 9735, 0)),
    MAGIC_TREE_AREA = new Area.Rectangular(new Coordinate(1577, 3494, 0), new Coordinate(1582, 3481, 0));



    @Override
    public void execute() {
    setLoopDelay(400, 800);
    switch(botState()) {
    case walkToBank:
    Environment.getLogger().debug("[botState] walking to bank area");
    walkToArea(bankArea);
    break;
    case walkToMine:
    Environment.getLogger().debug("[botState] walking to mining area");
    walkToArea(miningArea);
    break;
    case bank:
    if (Bank.isOpen()) {
    if (!Inventory.isFull()) {
    Environment.getLogger().debug("[botState] closing bank");
    Bank.close();
    Execution.delayUntil(() -> !Bank.isOpen(),1000, 2000);
    } else {
    Environment.getLogger().debug("[botState] depositing inventory");
    Bank.depositInventory();
    Execution.delayUntil(() -> !Inventory.isFull(), 2000, 4000);
    }
    } else {
    Environment.getLogger().debug("[botState] opening bank");
    Bank.open();
    Execution.delayUntil(() -> Bank.isOpen(), () -> Players.getLocal().isMoving(), 250, 2000, 4000);
    }
    break;
    case mine:
    final GameObject adamantiteRock = GameObjects.getLoaded(bot.treeName).nearest();
    if (adamantiteRock.isValid()) {
    if (!adamantiteRock.isVisible()) Camera.turnTo(adamantiteRock);
    Environment.getLogger().debug("[botState] Mining Runite ore");
    adamantiteRock.interact("Mine");

    int loopCount = 0;
    GameObject hover = null;
    while (adamantiteRock.isValid()) {
    if (loopCount > 10) break;
    if (Players.getLocal().isMoving()) loopCount = 0;
    if (Players.getLocal().getAnimationId() != -1) loopCount = 0;
    Execution.delay(200, 400);
    loopCount++;
    hover = hoverNextMiningRock(adamantiteRock, hover);
    }
    }
    break;
    }





    }

    private void setLoopDelay(int i, int i1) {
    }


    public GameObject hoverNextMiningRock(GameObject currentlyMining, GameObject currentlyHovering) {
    final LocatableEntityQueryResults adamantiteRock = GameObjects.getLoaded(bot.treeName).sortByDistance();
    for (int i = 0; i < adamantiteRock.size(); i++) {
    final GameObject rock = (GameObject) adamantiteRock.get(i);
    if (rock.equals(currentlyMining)) continue;
    if (rock.equals(currentlyHovering)) return currentlyHovering;
    if (!rock.isVisible()) Camera.turnTo(rock);
    Environment.getLogger().debug("[botState] found next rock to hover");
    rock.hover();
    return rock;
    }
    return null;
    }


    public void walkToArea(Area area) {
    final Coordinate randomCoordinate = area.getRandomCoordinate();
    final WebPath path = Traversal.getDefaultWeb().getPathBuilder().buildTo(randomCoordinate);
    if (path == null) {
    Environment.getLogger().severe("[walkToArea] could not find a path.");
    return;
    }
    while (Players.getLocal().getPosition().distanceTo(randomCoordinate) > 12) {
    Execution.delay(1000, 2000);
    final Coordinate dest = Traversal.getDestination();
    if (dest != null && dest.distanceTo(Players.getLocal().getPosition()) > 12) continue;
    Environment.getLogger().debug("[walkToArea] making next step.");
    path.step();
    }
    }


    public RuniteMiner.State botState() {
    if (Bank.isOpen()) {
    return RuniteMiner.State.bank;
    }
    if (Inventory.isFull()) {
    final GameObject bankBooth = GameObjects.getLoaded("Bank booth").nearest();
    if (bankBooth == null || bankBooth.distanceTo(Players.getLocal().getPosition()) > 12) {
    return RuniteMiner.State.walkToBank;
    } else {
    return RuniteMiner.State.bank;
    }
    } else {
    final GameObject adamantiteRock = GameObjects.getLoaded(bot.treeName).nearest();
    if (adamantiteRock == null || adamantiteRock.distanceTo(Players.getLocal().getPosition()) > 12) {
    return RuniteMiner.State.walkToMine;
    } else {

    return RuniteMiner.State.mine;




    }}}

    }
    --- Double Post Merged, Jun 13, 2019, Original Post Date: Jun 13, 2019 ---
    This Works, for changing my ore at start..
    --- Double Post Merged, Jun 13, 2019 ---
    package com.kronosqc.bots.bots;


    import javafx.application.Platform;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.fxml.FXML;
    import javafx.fxml.Initializable;
    import javafx.scene.control.Button;
    import javafx.scene.control.ComboBox;

    import java.net.URL;
    import java.util.ResourceBundle;

    public class sample implements Initializable {

    private RuniteMiner bot;

    @FXML
    private ComboBox Rockbox;

    @FXML
    private Button StartButton;

    public sample(RuniteMiner bot) {
    this.bot = bot;
    }


    @Override
    public void initialize(URL location, ResourceBundle resources) {
    Rockbox.getItems().addAll("Phasmatite rock", "Luminite rock");
    StartButton.setOnAction(getStartButtonAction());

    Rockbox.setOnAction(getWoodToCutEvent());
    }

    public EventHandler<ActionEvent> getStartButtonAction() {
    return event -> {
    try {
    bot.guiWait = false;

    switch (Rockbox.getValue().toString()) {
    case "Phasmatite rock":
    bot.treeArea = bot.YEW_TREE_AREA;
    bot.treeName = bot.YEW_TREE_NAME;
    bot.logName = bot.YEW_LOG_NAME;
    break;
    case "Luminite rock":
    bot.treeArea = bot.MAGIC_TREE_AREA;
    bot.treeName = bot.MAGIC_TREE_NAME;
    bot.logName = bot.MAGIC_LOG_NAME;
    break;
    }

    Platform.runLater(() -> bot.setToInfoProperty());

    } catch (Exception e) {
    e.printStackTrace();
    }
    };
    }

    public EventHandler<ActionEvent> getWoodToCutEvent() {
    return event -> {
    if (Rockbox.getSelectionModel().getSelectedItem() != null) {
    StartButton.setDisable(false);
    } else {
    StartButton.setDisable(true);
    }
    };
    }
    }
    --- Double Post Merged, Jun 13, 2019 ---
    The last part, Works Without the bot.treeArea = bot...
    if i use
    bot.treeArea = bot.YEW_TREE_AREA;
    Seems to make it crash at start
     

Share This Page

Loading...