Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.rsbuddy.event.events.MessageEvent;
- import com.rsbuddy.event.listeners.MessageListener;
- import com.rsbuddy.event.listeners.PaintListener;
- import com.rsbuddy.script.ActiveScript;
- import com.rsbuddy.script.Manifest;
- import com.rsbuddy.script.methods.*;
- import com.rsbuddy.script.util.Filter;
- import com.rsbuddy.script.util.Random;
- import com.rsbuddy.script.util.Timer;
- import com.rsbuddy.script.wrappers.*;
- import java.awt.*;
- import java.util.Comparator;
- @Manifest(name = "VarrockMiningChampion", version = 0.01, authors = "iCyrus")
- public class VarrockMiningChampion extends ActiveScript implements PaintListener, MessageListener {
- boolean developerMode = true;
- int failed = 0;
- boolean pickaxeEqupped = true;
- boolean multipleRocks = false;
- int oresMined = 0;
- int gemsMined = 0;
- private static final int[] miningAnimations = {
- -1, -1, 627, 629, 628, -1, -1};
- private static final int[] pickAxes = {
- -1, -1, 1269, 1273, 1271, 1275, -1};
- private static final int[] banker = {5912, 5913};
- private static final int[] copperRock = {11960, 11961, 11962};
- private static final int[] tinRock = {11957, 11958, 11959};
- //Mined copper rocks IDs: 11555, 11556, 11557
- private int[] rocksToMine;
- private Tile bankingTile = new Tile(3253, 3420);
- Tile[] eastBankToMine = {new Tile(3254, 3421), new Tile(3254, 3422),
- new Tile(3254, 3423), new Tile(3254, 3424), new Tile(3254, 3425),
- new Tile(3254, 3426), new Tile(3255, 3426), new Tile(3256, 3427),
- new Tile(3257, 3428), new Tile(3258, 3428), new Tile(3259, 3428),
- new Tile(3260, 3428), new Tile(3261, 3428), new Tile(3262, 3428),
- new Tile(3263, 3428), new Tile(3264, 3428), new Tile(3265, 3428),
- new Tile(3266, 3428), new Tile(3267, 3428), new Tile(3268, 3428),
- new Tile(3269, 3428), new Tile(3270, 3428), new Tile(3271, 3428),
- new Tile(3272, 3428), new Tile(3273, 3428), new Tile(3274, 3428),
- new Tile(3275, 3428), new Tile(3276, 3428), new Tile(3277, 3428),
- new Tile(3278, 3428), new Tile(3278, 3427), new Tile(3278, 3426),
- new Tile(3279, 3425), new Tile(3280, 3424), new Tile(3280, 3423),
- new Tile(3281, 3423), new Tile(3282, 3423), new Tile(3283, 3423),
- new Tile(3284, 3423), new Tile(3285, 3422), new Tile(3285, 3421),
- new Tile(3285, 3420), new Tile(3285, 3419), new Tile(3285, 3418),
- new Tile(3285, 3417), new Tile(3285, 3416), new Tile(3286, 3415),
- new Tile(3287, 3414), new Tile(3288, 3413), new Tile(3289, 3412),
- new Tile(3289, 3411), new Tile(3289, 3410), new Tile(3289, 3409),
- new Tile(3289, 3408), new Tile(3289, 3407), new Tile(3289, 3406),
- new Tile(3289, 3405), new Tile(3289, 3404), new Tile(3290, 3403),
- new Tile(3290, 3402), new Tile(3290, 3401), new Tile(3290, 3400),
- new Tile(3290, 3399), new Tile(3290, 3398), new Tile(3290, 3397),
- new Tile(3290, 3396), new Tile(3290, 3395), new Tile(3290, 3394),
- new Tile(3290, 3393), new Tile(3290, 3392), new Tile(3290, 3391),
- new Tile(3290, 3390), new Tile(3290, 3389), new Tile(3290, 3388),
- new Tile(3291, 3387), new Tile(3292, 3386), new Tile(3292, 3385),
- new Tile(3292, 3384), new Tile(3292, 3383), new Tile(3292, 3382),
- new Tile(3293, 3381), new Tile(3293, 3380), new Tile(3293, 3379),
- new Tile(3293, 3378), new Tile(3293, 3377), new Tile(3292, 3376),
- new Tile(3291, 3375), new Tile(3290, 3374), new Tile(3289, 3373),
- new Tile(3288, 3372), new Tile(3287, 3371), new Tile(3287, 3370),
- new Tile(3287, 3369), new Tile(3287, 3368), new Tile(3286, 3367),
- new Tile(3285, 3366)};
- private Tile[] pathFromBankToMine;
- private Area eastMiningArea = new Area(3277, 3358, 3292, 3372);
- private Area eastBankingArea = new Area(3250, 3419, 3257, 3423);
- private Area bankingArea;
- private Area miningArea;
- private int random(int min, int max) {
- return Random.nextInt(min, max);
- }
- private void dLog(String log) {
- if (developerMode) {
- log(log);
- }
- }
- private void setRocksToMine(int[] ids) {
- int i = 0;
- for (; i <= ids.length; i++) {
- rocksToMine[i] = ids[i];
- }
- }
- private void setRocksToMine(int[] ids, int[] secondIDs) {
- int i = 0;
- for (; i <= ids.length; i++) {
- rocksToMine[i] = ids[i];
- }
- for (; i < secondIDs.length + ids.length; i++) {
- rocksToMine[i] = secondIDs[i];
- }
- }
- private GameObject getRockToMine(int... ids) {
- return Objects.getNearest(ids);
- }
- //private Filter
- private boolean isMining() {
- if (currentRockToMine != null) {
- TileObject rock = new TileObject(currentRockToMine);
- if (rock != null) {
- if (rock.isValid() && playerIsSwinging(rock)) {
- sleep(30);
- }
- }
- }
- return false;
- }
- private boolean playerIsSwinging(TileObject rock) {
- Timer t = new Timer(random(600, 800));
- while (t.isRunning()) {
- if ((Players.getLocal().getAnimation() == 627 ||
- Players.getLocal().getAnimation() == 629 ||
- Players.getLocal().getAnimation() == 628) &&
- rock.isValid()) {
- return true;
- }
- }
- return false;
- }
- @Override
- public boolean onStart() {
- rocksToMine = tinRock;
- pathFromBankToMine = eastBankToMine.clone();
- bankingArea = eastBankingArea;
- miningArea = eastMiningArea;
- return super.onStart();
- }
- public boolean inventoryContainsExtra() {
- dLog("Inventory contains extra: " + String.valueOf(Inventory.getCountExcept(pickAxes)));
- return (Inventory.getCountExcept(pickAxes) > 1);
- }
- private boolean isValid(int value, int array[]) {
- for (int i = 0; i < array.length; i++) {
- if (array[i] == value)
- return true;
- }
- return false;
- }
- private GameObject getSecondNearest(int[] id) {
- final GameObject nearest = Objects.getNearest(rocksToMine);
- GameObject secondNearest = Objects.getNearest(new Filter<GameObject>() {
- public boolean accept(GameObject Object) {
- return isValid(Object.getId(), rocksToMine) && !nearest.equals(Object);
- }
- });
- return secondNearest;
- }
- private boolean hover(final Model model, boolean continueToHover) {
- if (currentRockToMine == null)
- loop();
- for (Polygon p : model.getTriangles()) {
- if (currentRockToMine == null) {
- dLog("currentRockToMine is null");
- loop();
- }
- if (p.contains(Mouse.getLocation()) && new TileObject(currentRockToMine).isValid()) {
- dLog("In first if statement");
- if (currentRockToMine == null) {
- return false;
- } else if (continueToHover && new TileObject(currentRockToMine).isValid()) {
- dLog("In if statement");
- Mouse.move(model.getNextPoint());
- }
- return true;
- }
- }
- if (new TileObject(currentRockToMine).isValid()) {
- Mouse.move(model.getNextPoint());
- }
- return false;
- }
- private GameObject currentRockToMine;
- private enum ScriptState {
- STARTUP, OPENING_BANK, DEPOSITING, WALKING_TO_MINE,
- WALKING_TO_BANK, CLICKING_ROCK, HOVERING_NEXT, UNKNOWN
- }
- private ScriptState getScriptState() {
- if (Bank.isOpen() && inventoryContainsExtra()) {
- return ScriptState.DEPOSITING;
- }
- if (Inventory.isFull()) {
- dLog("Inventory is full");
- if (!bankingArea.contains(Players.getLocal().getLocation())) {
- return ScriptState.WALKING_TO_BANK;
- }
- if (bankingArea.contains(Players.getLocal().getLocation()) &&
- Bank.isOpen()) {
- return ScriptState.DEPOSITING;
- }
- if (bankingArea.contains(Players.getLocal().getLocation()) &&
- !Bank.isOpen()) {
- return ScriptState.OPENING_BANK;
- }
- } else if (!Inventory.isFull()) {
- dLog("Inventory is not full");
- TileObject rock = new TileObject(currentRockToMine);
- if (rock.isValid()) {
- boolean isMining = playerIsSwinging(rock);
- if (!miningArea.contains(Players.getLocal().getLocation())) {
- return ScriptState.WALKING_TO_MINE;
- } else if (isMining && Objects.getNearest(rocksToMine) != null &&
- new TileObject(currentRockToMine).isValid()) {
- return ScriptState.HOVERING_NEXT;
- } else if (miningArea.contains(Players.getLocal().getLocation())) {
- if (isMining && new TileObject(currentRockToMine).isValid()) {
- return ScriptState.HOVERING_NEXT;
- } else {
- return ScriptState.CLICKING_ROCK;
- }
- }
- }
- }
- return ScriptState.UNKNOWN;
- }
- public int loop() {
- dLog("loop() started");
- switch (getScriptState()) {
- case OPENING_BANK:
- dLog("In OPENING_BANK");
- if (random(1, 2) == 1) {
- GameObject bankbooth = Objects.getNearest(11402);
- if (bankbooth != null && bankbooth.isOnScreen()) {
- bankbooth.interact("Use-quickly");
- }
- } else {
- Npc bankerToUse = Npcs.getNearest(banker);
- if (bankerToUse != null && bankerToUse.isOnScreen()) {
- bankerToUse.interact("Bank");
- }
- }
- sleep(random(800, 1000));
- while (Players.getLocal().isMoving()) {
- sleep(30);
- }
- return 0;
- case DEPOSITING:
- dLog("In DEPOSITING");
- Bank.depositAllExcept(pickAxes);
- sleep(random(500, 750));
- return 0;
- case CLICKING_ROCK:
- dLog("In CLICKING_ROCK");
- if (!isMining()) {
- GameObject rock = Objects.getNearest(rocksToMine);
- if (rock != null && rock.isOnScreen()) {
- currentRockToMine = rock;
- rock.interact("Mine");
- sleep(random(550, 750));
- } else if (rock != null && !rock.isOnScreen()) {
- Walking.findPath(rock.getLocation()).traverse();
- }
- while (Players.getLocal().isMoving()) {
- sleep(30);
- }
- } else
- return 0;
- case HOVERING_NEXT:
- dLog("In HOVERING_NEXT");
- GameObject newRock = getSecondNearest(rocksToMine);
- if (newRock != null) {
- dLog("newRock is not null");
- dLog(String.valueOf(newRock.getLocation()));
- dLog("Going into hover");
- hover(newRock.getModel(), false);
- dLog("Out of hover");
- }
- return 0;
- case WALKING_TO_BANK:
- dLog("In WALKING_TO_BANK");
- Walking.newTilePath(pathFromBankToMine).reverse().traverse();
- sleep(random(1000, 1500));
- return 0;
- case WALKING_TO_MINE:
- dLog("In WALKING_TO_MINE");
- Walking.newTilePath(pathFromBankToMine).traverse();
- return 0;
- default:
- dLog("In DEFAULT(" + String.valueOf(failed) + ") times");
- failed++;
- if (failed >= 5) {
- log("Failed 5 times, stopping script");
- stop();
- }
- }
- return 0;
- }
- private static class TileObject {
- final GameObject obj;
- final Tile tile;
- public TileObject(GameObject obj) {
- this.obj = obj;
- tile = obj.getLocation();
- }
- boolean isValid() {
- for (GameObject obj : Objects.getAllAt(tile)) {
- if (obj.equals(this.obj))
- return true;
- }
- return false;
- }
- }
- public void messageReceived(MessageEvent messageEvent) {
- String s = messageEvent.getMessage();
- if (s.contains("You just found a")) {
- gemsMined++;
- }
- if (s.contains("You manage to mine")) {
- oresMined++;
- }
- }
- public void onRepaint(Graphics graphics) {
- }
- @Override
- public void onFinish() {
- super.onFinish();
- }
- }
Add Comment
Please, Sign In to add comment