blahs44

Untitled

Oct 4th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.31 KB | None | 0 0
  1. package BClayMiner;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7.  
  8. import org.osbot.script.MethodProvider;
  9. import org.osbot.script.Script;
  10. import org.osbot.script.ScriptManifest;
  11. import org.osbot.script.mouse.RectangleDestination;
  12. import org.osbot.script.rs2.map.Position;
  13. import org.osbot.script.rs2.model.Entity;
  14. import org.osbot.script.rs2.model.GroundItem;
  15. import org.osbot.script.rs2.model.Player;
  16. import org.osbot.script.rs2.skill.Skill;
  17. import org.osbot.script.rs2.skill.Skills;
  18. import org.osbot.script.rs2.ui.Inventory;
  19. import org.osbot.script.rs2.ui.Tab;
  20. import org.osbot.script.rs2.utility.Area;
  21.  
  22. @ScriptManifest(author = "Zappa", info = "Mines Clay v1.3", name = "BClayMiner", version = 1.3)
  23. public class BClayMiner extends Script {
  24.  
  25.     private State state;
  26.  
  27.     static Timer runTime = new Timer(0);
  28.  
  29.     private int[][] MinePos = { { 2964, 3224, 0 }, { 2971, 3228, 0 },
  30.             { 2976, 3235, 0 }, { 2986, 3240, 0 } };
  31.  
  32.     private Area Bank = new Area(2438, 3082, 2444, 3096);
  33.     private Area MineArea = new Area(2984, 3236, 2989, 3242);
  34.  
  35.     private static final int[] RockID = { 3032, 10778 };
  36.     private final int[] pickAxeHeadId = { 480, 481, 482, 483, 484, 485, 486,
  37.             487, 488, 489, 490, 491 };
  38.  
  39.     int claymined = 0;
  40.     int startEXP;
  41.     int startLevel;
  42.  
  43.     public int runes = 0;
  44.  
  45.     public void onStart() {
  46.  
  47.         if (this.client.getMyPlayer().isInArea(Bank)
  48.                 && (this.client.getInventory().contains(8013) && ((this.client
  49.                         .getInventory().contains(2554) || (this.client
  50.                         .getInventory().contains(2556) || (this.client
  51.                         .getInventory().contains(2558) || (this.client
  52.                         .getInventory().contains(2560) || (this.client
  53.                         .getInventory().contains(2562) || (this.client
  54.                         .getInventory().contains(2564) || (this.client
  55.                         .getInventory().contains(2566) || (this.client
  56.                         .getInventory().contains(2552)))))))))))) {
  57.             this.state = State.TELETOHOUSE;
  58.         } else if (this.client.getMyPlayer().isInArea(Bank)
  59.                 && (this.client.getInventory().contains(563) && (this.client
  60.                         .getInventory().contains(557) && ((this.client
  61.                         .getInventory().contains(2554) || (this.client
  62.                         .getInventory().contains(2556) || (this.client
  63.                         .getInventory().contains(2558) || (this.client
  64.                         .getInventory().contains(2560) || (this.client
  65.                         .getInventory().contains(2562) || (this.client
  66.                         .getInventory().contains(2564) || (this.client
  67.                         .getInventory().contains(2566) || (this.client
  68.                         .getInventory().contains(2552))))))))))))) {
  69.             runes = 1;
  70.             this.state = State.TELETOHOUSERUNES;
  71.         }
  72.  
  73.         runTime = new Timer(0);
  74.         startEXP = client.getSkills().getExperience(Skill.MINING);
  75.         startLevel = client.getSkills().getLevel(Skill.MINING);
  76.     }
  77.  
  78.     public boolean WalkAlongPath(int[][] path, boolean AscendThroughPath,
  79.             int distanceFromEnd) {
  80.         if (distanceToPoint(AscendThroughPath ? path[path.length - 1][0]
  81.                 : path[0][0], AscendThroughPath ? path[path.length - 1][1]
  82.                 : path[0][1]) <= distanceFromEnd)
  83.             return true;
  84.         else {
  85.             WalkAlongPath(path, AscendThroughPath);
  86.             return false;
  87.         }
  88.     }
  89.  
  90.     public void WalkAlongPath(int[][] path, boolean AscendThroughPath) {
  91.         int destination = 0;
  92.         for (int i = 0; i < path.length; i++)
  93.             if (distanceToPoint(path[i][0], path[i][1]) < distanceToPoint(
  94.                     path[destination][0], path[destination][1]))
  95.                 destination = i;
  96.         if (client.getMyPlayer().isMoving()
  97.                 && distanceToPoint(path[destination][0], path[destination][1]) > (isRunning() ? 3
  98.                         : 2))
  99.             return;
  100.         if (AscendThroughPath && destination != path.length - 1
  101.                 || !AscendThroughPath && destination != 0)
  102.             destination += (AscendThroughPath ? 1 : -1);
  103.         try {
  104.             log("Walking to node:" + destination);
  105.             walk(new Position(path[destination][0], path[destination][1], 0));
  106.             Thread.sleep(700 + MethodProvider.random(600));
  107.         } catch (InterruptedException e) {
  108.             e.printStackTrace();
  109.         }
  110.     }
  111.  
  112.     private int distanceToPoint(int pointX, int pointY) {
  113.         return (int) Math.sqrt(Math
  114.                 .pow(client.getMyPlayer().getX() - pointX, 2)
  115.                 + Math.pow(client.getMyPlayer().getY() - pointY, 2));
  116.     }
  117.  
  118.     public int onLoop() throws InterruptedException {
  119.  
  120.         if (((this.client.getRunEnergy() > 40) && (this.state != State.MINE) && (this.state != State.BANK))) {
  121.             try {
  122.                 setRunning(true);
  123.             } catch (Exception localException) {
  124.             }
  125.         }
  126.  
  127.         if (this.state == State.TELETOHOUSE) {
  128.             return teleToHouse();
  129.         } else if (this.state == State.LEAVEHOUSE) {
  130.             return leaveHouse();
  131.         } else if (this.state == State.WALKTOMINE) {
  132.             return walkToMine();
  133.         } else if (this.state == State.MINE) {
  134.             return mine();
  135.         } else if (this.state == State.TELETOBANK) {
  136.             return teleToBank();
  137.         } else if (this.state == State.BANK) {
  138.             return bank();
  139.         } else if (this.state == State.TELETOHOUSERUNES) {
  140.             return teleToHouseRunes();
  141.         }
  142.  
  143.         return 250 + (50);
  144.     }
  145.  
  146.     public int teleToHouse() throws InterruptedException {
  147.  
  148.         if (currentTab() != Tab.INVENTORY) {
  149.             openTab(Tab.INVENTORY);
  150.             sleep(110 + random(40, 50));
  151.         }
  152.  
  153.         if (this.client.getInventory().contains(8013)) {
  154.             selectInventoryOption(
  155.                     this.client.getInventory().getSlotForId(8013), "Break");
  156.             sleep(7000);
  157.         }
  158.  
  159.         this.state = State.LEAVEHOUSE;
  160.  
  161.         return 250;
  162.     }
  163.  
  164.     public int teleToHouseRunes() throws InterruptedException {
  165.  
  166.         Player player = client.getMyPlayer();
  167.  
  168.         if (!player.isAnimating()) {
  169.             if (currentTab() != Tab.MAGIC) {
  170.                 openTab(Tab.MAGIC);
  171.                 sleep(110 + random(40, 50));
  172.             }
  173.             client.moveMouseTo(new RectangleDestination(618, 309, 10, 10),
  174.                     false, true, false);
  175.             sleep(7000);
  176.         }
  177.  
  178.         this.state = State.LEAVEHOUSE;
  179.  
  180.         return 250;
  181.     }
  182.  
  183.     public int leaveHouse() throws InterruptedException {
  184.  
  185.         Entity portal = closestObject(4525);
  186.  
  187.         if (portal != null) {
  188.             log("Portal found!");
  189.             if (portal.isVisible()) {
  190.                 portal.interact("Enter");
  191.                 sleep(random(1000, 1200));
  192.             } else {
  193.                 client.moveCameraToEntity(portal);
  194.             }
  195.         } else {
  196.             log("Portal Not Found");
  197.         }
  198.  
  199.         this.state = State.WALKTOMINE;
  200.  
  201.         return 250;
  202.     }
  203.  
  204.     public int walkToMine() {
  205.  
  206.         try {
  207.             WalkAlongPath(MinePos, true);
  208.         } catch (Exception localException) {
  209.         }
  210.  
  211.         if (this.client.getMyPlayer().isInArea(MineArea)) {
  212.             this.state = State.MINE;
  213.         }
  214.  
  215.         return 250;
  216.     }
  217.  
  218.     public int mine() {
  219.  
  220.         try {
  221.             Player player = this.client.getMyPlayer();
  222.             Inventory inven = this.client.getInventory();
  223.             Entity rocks = closestObject(RockID);
  224.  
  225.             if (inven.isFull()) {
  226.                 this.state = State.TELETOBANK;
  227.                 return 250;
  228.             }
  229.  
  230.             if (!player.isAnimating() && (rocks != null)) {
  231.                 rocks.interact("Mine");
  232.                 getTheHead();
  233.                 checkForSmoker();
  234.                 sleep(random(600, 1100));
  235.             }
  236.         } catch (Exception localException) {
  237.         }
  238.  
  239.         return 250;
  240.     }
  241.  
  242.     public int teleToBank() throws InterruptedException {
  243.  
  244.         try {
  245.             if (currentTab() != Tab.INVENTORY) {
  246.                 openTab(Tab.INVENTORY);
  247.             }
  248.             if (this.client.getInventory().contains(2552))
  249.                 selectInventoryOption(
  250.                         this.client.getInventory().getSlotForId(2552), "Rub");
  251.             else if (this.client.getInventory().contains(2554))
  252.                 selectInventoryOption(
  253.                         this.client.getInventory().getSlotForId(2554), "Rub");
  254.             else if (this.client.getInventory().contains(2556))
  255.                 selectInventoryOption(
  256.                         this.client.getInventory().getSlotForId(2556), "Rub");
  257.             else if (this.client.getInventory().contains(2558))
  258.                 selectInventoryOption(
  259.                         this.client.getInventory().getSlotForId(2558), "Rub");
  260.             else if (this.client.getInventory().contains(2560))
  261.                 selectInventoryOption(
  262.                         this.client.getInventory().getSlotForId(2560), "Rub");
  263.             else if (this.client.getInventory().contains(2562))
  264.                 selectInventoryOption(
  265.                         this.client.getInventory().getSlotForId(2562), "Rub");
  266.             else if (this.client.getInventory().contains(2564))
  267.                 selectInventoryOption(
  268.                         this.client.getInventory().getSlotForId(2564), "Rub");
  269.             else if (this.client.getInventory().contains(2566)) {
  270.                 selectInventoryOption(
  271.                         this.client.getInventory().getSlotForId(2566), "Rub");
  272.  
  273.             }
  274.  
  275.             Thread.sleep(1000L);
  276.         } catch (Exception localException) {
  277.         }
  278.  
  279.         sleep(1000);
  280.         client.moveMouseTo(new RectangleDestination(255, 417, 10, 10), false,
  281.                 true, false);
  282.         sleep(5000);
  283.  
  284.         if (this.client.getMyPlayer().isInArea(Bank)) {
  285.  
  286.             walkExact(new Position(2443, 3083, 0));
  287.  
  288.             this.state = State.BANK;
  289.  
  290.         }
  291.  
  292.         return 250;
  293.     }
  294.  
  295.     public int bank() {
  296.  
  297.         try {
  298.             if (!this.client.getBank().isOpen()) {
  299.                 try {
  300.                     selectEntityOption(
  301.                             closestObjectForName(new String[] { "Bank Chest" }),
  302.                             true, "Use");
  303.                 } catch (InterruptedException e) {
  304.                     e.printStackTrace();
  305.                 }
  306.             } else {
  307.                 try {
  308.                     this.client.getBank().depositAllExcept(
  309.                             new int[] { 8013, 563, 556, 557, 2554, 2556, 2558,
  310.                                     2560, 2562, 2564, 2566, 2522 });
  311.                 } catch (InterruptedException e) {
  312.                     e.printStackTrace();
  313.                 }
  314.                 if (runes == 0) {
  315.                     if (this.client.getInventory().contains(8013)
  316.                             && ((this.client.getInventory().contains(2554) || (this.client
  317.                                     .getInventory().contains(2556) || (this.client
  318.                                     .getInventory().contains(2558) || (this.client
  319.                                     .getInventory().contains(2560) || (this.client
  320.                                     .getInventory().contains(2562) || (this.client
  321.                                     .getInventory().contains(2564) || (this.client
  322.                                     .getInventory().contains(2566) || (this.client
  323.                                     .getInventory().contains(2552))))))))))) {
  324.                         if (!client.getInventory().isFull()) {
  325.                             this.client.getBank().close();
  326.                             if (runes == 0) {
  327.                                 this.state = State.TELETOHOUSE;
  328.                             } else if (runes == 1) {
  329.                                 this.state = State.TELETOHOUSERUNES;
  330.                             }
  331.                         }
  332.                     } else {
  333.                         this.client.getBank().withdraw1(2552);
  334.                         this.client.getBank().close();
  335.                         if (runes == 0) {
  336.                             this.state = State.TELETOHOUSE;
  337.                         } else if (runes == 1) {
  338.                             this.state = State.TELETOHOUSERUNES;
  339.                         }
  340.                     }
  341.                 } else if (runes == 1) {
  342.                     if (this.client.getInventory().contains(563)
  343.                             && (this.client.getInventory().contains(557) && ((this.client
  344.                                     .getInventory().contains(2554) || (this.client
  345.                                     .getInventory().contains(2556) || (this.client
  346.                                     .getInventory().contains(2558) || (this.client
  347.                                     .getInventory().contains(2560) || (this.client
  348.                                     .getInventory().contains(2562) || (this.client
  349.                                     .getInventory().contains(2564) || (this.client
  350.                                     .getInventory().contains(2566) || (this.client
  351.                                     .getInventory().contains(2552)))))))))))) {
  352.                         if (!client.getInventory().isFull()) {
  353.                             this.client.getBank().close();
  354.                             if (runes == 0) {
  355.                                 this.state = State.TELETOHOUSE;
  356.                             } else if (runes == 1) {
  357.                                 this.state = State.TELETOHOUSERUNES;
  358.                             }
  359.                         }
  360.                     } else {
  361.                         this.client.getBank().withdraw1(2552);
  362.                         this.client.getBank().close();
  363.                         if (runes == 0) {
  364.                             this.state = State.TELETOHOUSE;
  365.                         } else if (runes == 1) {
  366.                             this.state = State.TELETOHOUSERUNES;
  367.                         }
  368.                     }
  369.                 }
  370.             }
  371.         } catch (InterruptedException localInterruptedException1) {
  372.         }
  373.  
  374.         return 1000;
  375.     }
  376.  
  377.     public void checkForSmoker() throws InterruptedException {
  378.         Position da = myPlayer().getPosition();
  379.         Entity rocks = closestObject(RockID);
  380.         while ((this.client.getMyPlayer().isAnimating())
  381.                 && (!rocks.isInArea(this.MineArea))) {
  382.             log("SmokinRocks");
  383.             da.interact(this.bot, "Walk here");
  384.             sleep(random(9000, 10000));
  385.         }
  386.     }
  387.  
  388.     public void getTheHead() throws InterruptedException {
  389.         GroundItem pickAxeHead = closestGroundItem(this.pickAxeHeadId);
  390.         if (pickAxeHead == null) {
  391.             return;
  392.         }
  393.         if (pickAxeHead.isVisible()) {
  394.             pickAxeHead.interact("Take");
  395.         } else {
  396.             this.client.moveCameraToEntity(pickAxeHead);
  397.             pickAxeHead.interact("Take");
  398.             stop();
  399.         }
  400.     }
  401.  
  402.     public void onPaint(Graphics g) {
  403.  
  404.         Graphics2D gr = (Graphics2D) g;
  405.  
  406.         gr.setColor(Color.WHITE);
  407.         gr.setFont(new Font("Arial", Font.PLAIN, 10));
  408.  
  409.         Skills skills = client.getSkills();
  410.  
  411.         gr.drawString("State: " + this.state, 25, 140);
  412.         gr.drawString("Clay Mined: " + claymined, 25, 50);
  413.         gr.drawString("Clay Mined/h: " + getPerHour(claymined), 25, 65);
  414.         gr.drawString("Exp gained: "
  415.                 + (skills.getExperience(Skill.MINING) - startEXP), 25, 80);
  416.         gr.drawString(
  417.                 "Exp gained/h: "
  418.                         + getPerHour(skills.getExperience(Skill.MINING)
  419.                                 - startEXP), 25, 95);
  420.         gr.drawString(
  421.                 "Level: " + (startLevel) + " + ("
  422.                         + (skills.getLevel(Skill.MINING) - startLevel + ")"),
  423.                 25, 110);
  424.         if (runTime != null) {
  425.             g.drawString("Runtime: " + Timer.format(runTime.getElapsed()), 25,
  426.                     125);
  427.         }
  428.         g.drawString("By Zappa", 443, 465);
  429.     }
  430.  
  431.     public static int getPerHour(int value) {
  432.         if (runTime != null && runTime.getElapsed() > 0) {
  433.             return (int) (value * 3600000d / runTime.getElapsed());
  434.  
  435.         } else {
  436.             return 0;
  437.         }
  438.     }
  439.  
  440.     public static long getPerHour(long value) {
  441.         if (runTime != null && runTime.getElapsed() > 0) {
  442.             return (long) (value * 3600000d / runTime.getElapsed());
  443.  
  444.         } else {
  445.             return 0;
  446.         }
  447.     }
  448.  
  449.     public void onMessage(String message) throws InterruptedException {
  450.  
  451.         if (message.contains("You manage to mine some clay")) {
  452.  
  453.             claymined++;
  454.  
  455.         }
  456.  
  457.     }
  458.  
  459.     static enum State {
  460.         TELETOHOUSE, LEAVEHOUSE, WALKTOMINE, MINE, TELETOBANK, BANK, TELETOHOUSERUNES;
  461.     }
  462.  
  463. }
Advertisement
Add Comment
Please, Sign In to add comment