blahs44

Untitled

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