Jump to content

[Open Source] Cannonball Smither


Alias
 Share

Recommended Posts

package cannonballer;

import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.entity.SceneObject;
import com.epicbot.api.shared.model.Area;
import com.epicbot.api.shared.script.LoopScript;
import com.epicbot.api.shared.script.ScriptManifest;
import com.epicbot.api.shared.util.time.Time;

@ScriptManifest(name = "CB Smither", gameType = GameType.OS)
public class AliasCannonballer extends LoopScript {

    private final static Area SMITH_AREA = new Area(3109, 3501, 3105, 3497);
    private final static Area EDGE_BANK = new Area(3098, 3499, 3092, 3493);

    private long animationTime = 0;

    @Override
    public boolean onStart(String... strings) {
        return true;
    }

    @Override
    protected int loop() {
        if (canSmith()) {
            smith();
        } else {
            bank();
        }
        return 100;
    }

    private boolean canSmith() {
        return getAPIContext().inventory().contains("Steel bar") && getAPIContext().inventory().contains("Ammo mould");
    }

    private boolean smithInterfaceOpen() {
        return !getAPIContext().widgets().query().group(270).textContains("How many bars").results().isEmpty();
    }

    private void smith() {
        SceneObject furnace = getAPIContext().objects().query().nameContains("Furnace").results().nearest();
        if (furnace != null) {
            if (getAPIContext().calculations().distanceTo(furnace.getLocation()) > 5) {
                getAPIContext().walking().walkOnMap(SMITH_AREA.getCentralTile());
            } else if (getAPIContext().localPlayer().isAnimating()) {
                this.animationTime = System.currentTimeMillis();
            } else if (smithInterfaceOpen()) {
                getAPIContext().keyboard().sendText("1", false);
                Time.sleep(5_000, () -> getAPIContext().localPlayer().isAnimating());
            } else if (System.currentTimeMillis() > animationTime + 3_000) {
                if (furnace.interact("Smelt")) {
                    Time.sleep(5_000, this::smithInterfaceOpen);
                }
            }
        }
    }

    private void bank() {
        if (getAPIContext().calculations().distanceTo(EDGE_BANK.getCentralTile()) > 5) {
            getAPIContext().walking().walkTo(EDGE_BANK.getCentralTile());
        } else if (!getAPIContext().bank().isOpen()) {
            if (getAPIContext().bank().open()) {
                Time.sleep(5_000, () -> getAPIContext().bank().isOpen(), 5_000);
            }
        } else if (!getAPIContext().inventory().contains("Ammo mould")) {
            withdrawItem(1, "Ammo mould");
        } else if (!getAPIContext().inventory().contains("Steel bar")) {
            withdrawItem(27, "Steel bar");
        }
    }

    private void withdrawItem(final int amount, final String item) {
        if (!getAPIContext().bank().contains(item)) {
            stop("No " + item + "...cannot run script.");
        } else if (getAPIContext().bank().withdraw(amount, item)) {
            Time.sleep(5_000, () -> getAPIContext().inventory().contains(item));
        }
    }
}
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...