Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.kbotpro.scriptsystem.events.PaintEventListener;
- import com.kbotpro.scriptsystem.interfaces.Looped;
- import com.kbotpro.scriptsystem.runnable.Script;
- import com.kbotpro.scriptsystem.runnable.Worker;
- import com.kbotpro.scriptsystem.wrappers.PhysicalObject;
- import com.kbotpro.scriptsystem.wrappers.Tile;
- import com.kbotpro.scriptsystem.wrappers.Interface;
- import com.kbotpro.scriptsystem.wrappers.IComponent;
- import com.kbotpro.scriptsystem.fetch.Bank;
- import com.kbotpro.scriptsystem.fetch.Skills;
- import java.awt.*;
- import java.text.DecimalFormat;
- import java.text.DecimalFormatSymbols;
- public class DeviantWoodcutter extends Script implements PaintEventListener {
- public String getName() {
- return "Deviant Woodcutter";
- }
- public boolean canStart() {
- return true;
- }
- public void onStart() {
- startTime = System.currentTimeMillis();
- startExp = skills.getExperience(Skills.SKILL_WOODCUTTING);
- lastExp = skills.getExperience(Skills.SKILL_WOODCUTTING);
- startLevel = skills.getLevel(Skills.SKILL_WOODCUTTING);
- if (inventory.contains(hatchet)) {
- wieldable = false;
- }
- }
- public void pause() {
- }
- public void stop() {
- }
- private final Tile[] bankToTrees = new Tile[]{new Tile(3093, 3244),
- new Tile(3086, 3234)};
- private final int[] treeIDs = new int[]{5553, 5551, 5552}, hatchet = new int[]{1351, 1349, 1353, 1361, 1355, 1357, 1359, 6739, 13470};
- ;
- private int treeID = 5553, bankID = 2213, logID = 1519, startExp, startLevel, lastExp, chopped;
- public Color BG = new Color(59, 52, 39, 100);
- private boolean chopping = false, wieldable = true;
- private long startTime;
- public enum Action {
- CHOP, BANK, WALKTOTREE, WALKTOTREES, WALKTOBANK, NOTHING, ANTIBAN
- }
- public void registerWorkers() {
- createWorker(new Looped() {
- public int loop() {
- try {
- /*if(game.getCurrentTab() > -1)
- closeTab(game.getCurrentTab());
- */
- Action action = getAction();
- if (action != null) {
- switch (action) {
- case CHOP:
- if (!objectOnScreen(Object(treeIDs))) {
- camera.setAngle(camera.getAngleTo(Object(treeIDs).getLocation()));
- }
- Object(treeIDs).doAction("chop");
- sleep(1200, 1300);
- break;
- case BANK:
- if (inventory.isFull() & isInZone(3095, 3087, 3240, 3247)) {
- if (!bank.isOpen()) {
- if (!objectOnScreen(Object(bankID))) {
- camera.setAngle(camera.getAngleTo(Object(bankID).getLocation()));
- }
- Object(bankID).doAction("use-quickly");
- if (!bank.isOpen()) {
- sleep(2000, 2200);
- }
- }
- if (bank.isOpen()) {
- if (inventory.isFull()) {
- if (wieldable)
- bank.depositAll();
- else
- bank.depositAllExcept(hatchet);
- }
- close();
- }
- }
- break;
- case WALKTOBANK:
- if (inventory.isFull() & !isInZone(3095, 3087, 3240, 3247) & !getMyPlayer().isMoving()) {
- walkPathMM(reversePath(bankToTrees), 16);
- }
- break;
- case WALKTOTREE:
- walking.walkToMM(Object(treeIDs).getLocation());
- break;
- case WALKTOTREES:
- walkPathMM(bankToTrees, 16);
- break;
- case ANTIBAN:
- int random = random(1, 20);
- switch (random) {
- case 1:
- mouse.moveMouseRandomly(300);
- break;
- case 2:
- mouse.moveMouseRandomly(100);
- break;
- case 3:
- break;
- }
- break;
- }
- }
- } catch (NullPointerException e) {
- }
- return random(200, 300);
- }
- });
- }
- Worker cameraAnti = startWorker(new Looped() {
- public int loop() {
- int random = random(1, 50);
- if (camera != null)
- switch (random) {
- case 1:
- camera.setAngle((int) camera.getAngle() + random(-20, 20));
- break;
- case 2:
- camera.setAngle((int) camera.getAngle() + random(-50, 150));
- break;
- }
- return random(300, 400);
- }
- });
- public Action getAction() {
- chopping = getMyPlayer().getAnimation() != -1;
- if (!inventory.isFull() & !getMyPlayer().isMoving() & farFromTree(Object(treeIDs))) {
- return Action.WALKTOTREE;
- }
- if (!inventory.isFull() & !getMyPlayer().isMoving() & !getMyPlayer().isMoving() & farFromTrees(Object(treeIDs))) {
- return Action.WALKTOTREES;
- }
- if (inventory.isFull() & !isInZone(3095, 3087, 3240, 3247)) {
- return Action.WALKTOBANK;
- }
- if (inventory.isFull() & isInZone(3095, 3087, 3240, 3247)) {
- return Action.BANK;
- }
- if (!inventory.isFull() & !chopping & closeToTree(Object(treeIDs))) {
- return Action.CHOP;
- }
- if (!inventory.isFull() & (chopping || Object(treeID) == null)) {
- return Action.ANTIBAN;
- } else return Action.NOTHING;
- }
- public void onRepaint(Graphics g) {
- long millis = System.currentTimeMillis() - startTime;
- final long hours = millis / (1000 * 60 * 60);
- millis -= hours * 1000 * 60 * 60;
- final long minutes = millis / (1000 * 60);
- millis -= minutes * 1000 * 60;
- final long seconds = millis / 1000;
- DecimalFormat df = new DecimalFormat();
- DecimalFormatSymbols dfs = new DecimalFormatSymbols();
- df.setDecimalFormatSymbols(dfs);
- DecimalFormat digit = new DecimalFormat("00");
- if (skills.getExperience(skills.SKILL_WOODCUTTING) > lastExp) {
- lastExp = skills.getExperience(skills.SKILL_WOODCUTTING);
- chopped++;
- }
- g.setColor(BG);
- int w = 150, x = upperLeftX() - w, y = upperLeftY();
- g.fill3DRect(x, y, 150, 52, true);
- g.setColor(new Color(0, 0, 0, 200));
- g.setFont(new Font("Default", Font.BOLD, 12));
- g.drawString("" + getName(), x + 5, y += 10);
- g.setFont(new Font("Default", Font.PLAIN, 12));
- g.drawString("Runtime: " + digit.format(hours) + ":" + digit.format(minutes) + ":" + digit.format(seconds), x + 5, y += 10);
- g.drawString("Willows Chopped: " + chopped, x + 5, y += 10);
- g.drawString("Levels Gained: " + (skills.getLevel(skills.SKILL_WOODCUTTING) - startLevel), x + 5, y += 10);
- g.drawString("Exp Gained: " + df.format(skills.getExperience(skills.SKILL_WOODCUTTING) - startExp), x + 5, y += 10);
- g.setColor(new Color(59, 52, 39, 125));
- g.fillRect(x + (w - 16), y += (height() - 167), 16, 100);
- g.setColor(new Color(0, 0, 0));
- g.drawRect(x + (w - 16), y, 16, 100);
- g.setColor(new Color(59, 52, 39, 50));
- g.drawRect(x + (w - 14), y, 14, 98);
- g.setColor(new Color(255, 18, 0, 125));
- g.fillRoundRect(x + (w - 12), y + 96 - (int) (96 * (getPercent(skills.SKILL_WOODCUTTING)) / 100.0), 12, (int) (96 * (getPercent(skills.SKILL_WOODCUTTING)) / 100.0), 4, 4);
- g.setColor(new Color(0, 0, 0));
- g.drawRoundRect(x + (w - 12), y + 96 - (int) (96 * (getPercent(skills.SKILL_WOODCUTTING)) / 100.0), 12, (int) (96 * (getPercent(skills.SKILL_WOODCUTTING)) / 100.0), 4, 4);
- g.setColor(new Color(59, 52, 39, 125));
- g.fillRect(x + (w - 30), y += 100, 30, 16);
- g.setColor(new Color(0, 0, 0));
- g.drawRect(x + (w - 30), y, 30, 16);
- g.setColor(new Color(59, 52, 39, 50));
- g.drawRect(x + (w - 30), y, 28, 14);
- g.setColor(Color.WHITE);
- g.drawString(getPercent(skills.SKILL_WOODCUTTING) + "%", x + (w - 24), y += 12);
- }
- private static int[] xpTable = {0, 0, 83, 174, 276, 388, 512, 650, 801,
- 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973,
- 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031,
- 13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408,
- 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127,
- 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636,
- 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599,
- 407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445,
- 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200,
- 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594,
- 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253,
- 7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431};
- public int getPercent(final int index) {
- final int lvl = skills.getLevel(index);
- if (lvl == 99) {
- return 0;
- }
- final int xpTotal = xpTable[lvl + 1] - xpTable[lvl];
- if (xpTotal == 0) {
- return 0;
- }
- final int xpDone = skills.getExperience(index) - xpTable[lvl];
- return 100 * xpDone / xpTotal;
- }
- public boolean objectOnScreen(PhysicalObject object) {
- if (object != null) {
- if (calculations.onScreen(calculations.tileToScreen(object.getLocation()))) {
- return true;
- }
- }
- return false;
- }
- public PhysicalObject Object(int... ids) {
- PhysicalObject object = objects.getClosestObject(20, ids);
- if (object != null) {
- return object;
- } else
- return null;
- }
- public boolean isInZone(int x1, int x2, int y1, int y2) {
- int currentX = getMyPlayer().getLocation().getX();
- int currentY = getMyPlayer().getLocation().getY();
- if ((currentY >= y1) && (currentY <= y2) && (currentX <= x1) && (currentX >= x2)) {
- return true;
- }
- return false;
- }
- public Tile[] reversePath(final Tile[] other) {
- final Tile[] t = new Tile[other.length];
- for (int i = 0; i < t.length; i++) {
- t[i] = other[other.length - i - 1];
- }
- return t;
- }
- public Tile nextTile(final Tile path[], final int maxDist,
- final boolean enableMaxDist) {
- final int randomdis = random(3, 5);
- int closest = -1, sDist = -1;
- if (players.distanceTo(path[path.length - 1]) <= randomdis) {
- return null;
- }
- for (int i = path.length - 1; i >= 0; i--) {
- final int dist = players.distanceTo(path[i]);
- if (sDist == -1 || dist < sDist) {
- sDist = dist;
- closest = i;
- }
- if (enableMaxDist && dist <= maxDist) {
- return path[i];
- }
- }
- return path[closest];
- }
- public boolean walkPathMM(final Tile[] path, final int maxDist) {
- try {
- final Tile next = nextTile(path, maxDist, true);
- return next != null && walkTileMM(next);
- } catch (final Exception e) {
- return false;
- }
- }
- /* Close tab by ampzz*/
- public boolean closeTab(int id) {
- if (id < 0 || id > 15) return false;
- IComponent currTab = interfaces.getComponent(746, (124 + id));
- return (currTab != null && currTab.doClick());
- }
- public boolean walkTileMM(final Tile t) {
- final Point p = calculations.tileToMinimap(t);
- if (p.x == -1 || p.y == -1) {
- return false;
- }
- mouse.moveMouse(p, true);
- return true;
- }
- /* Closes the bank interface
- * @return whether the bank is open (or successfully clicks "Close")
- * @author Ampzz
- */
- public boolean close() {
- if (!bank.isOpen()) return true;
- Interface bankIFace = interfaces.getInterface(Bank.BANK_INTERFACE_ID);
- if (bankIFace != null && bankIFace.isValid()) {
- IComponent closeButton = interfaces.getComponent(Bank.BANK_INTERFACE_ID, Bank.BANK_BUTTON_CLOSE);
- try {
- mouse.moveMouse(new Point((int) closeButton.getUpperLeftScreenPos().getX() + random(0, (int) closeButton.getBounds().getWidth()), (int) closeButton.getUpperLeftScreenPos().getY() + random(0, (int) closeButton.getBounds().getHeight())));
- sleep(10, 20);
- if (menu.atMenu("Close"))
- return true;
- } catch (Exception e) {
- }
- }
- return false;
- }
- public int width() {
- IComponent inventoryComponent = interfaces.getComponent(746, 25);
- return (int) inventoryComponent.getBounds().getWidth();
- }
- public int height() {
- IComponent inventoryComponent = interfaces.getComponent(746, 25);
- return (int) inventoryComponent.getBounds().getHeight();
- }
- public int upperLeftX() {
- IComponent inventoryComponent = interfaces.getComponent(746, 25);
- return ((int) inventoryComponent.getUpperLeftScreenPos().getX() / 2);
- }
- public int upperLeftY() {
- IComponent inventoryComponent = interfaces.getComponent(746, 25);
- return ((int) inventoryComponent.getUpperLeftScreenPos().getY() / 2);
- }
- public boolean closeToTree(PhysicalObject object) {
- if (object != null) {
- if (players.distanceTo(object) <= 8) {
- return true;
- }
- }
- return false;
- }
- public boolean farFromTree(PhysicalObject object) {
- if (object != null) {
- if (players.distanceTo(object) > 8 & players.distanceTo(object) < 15) {
- return true;
- }
- }
- return false;
- }
- public boolean farFromTrees(PhysicalObject object) {
- if (object != null) {
- if (players.distanceTo(object) >= 15) {
- return true;
- }
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment