blahs44

Untitled

Sep 28th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.05 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5.  
  6. import org.osbot.script.MethodProvider;
  7. import org.osbot.script.Script;
  8. import org.osbot.script.ScriptManifest;
  9. import org.osbot.script.mouse.RectangleDestination;
  10. import org.osbot.script.rs2.map.Position;
  11. import org.osbot.script.rs2.model.Entity;
  12. import org.osbot.script.rs2.model.NPC;
  13. import org.osbot.script.rs2.model.Player;
  14. import org.osbot.script.rs2.utility.Area;
  15.  
  16. @ScriptManifest(author = "Zappa", info = "Tans hides in Al Kharid v1.1", name = "BTanner", version = 1.1)
  17. public class BHideTanner extends Script {
  18.  
  19.     private State state;
  20.  
  21.     static Timer runTime = new Timer(0);
  22.  
  23.     private int[][] TannerPos = { { 3275, 3169, 0 }, { 3278, 3178, 0 },
  24.             { 3281, 3185, 0 }, { 3278, 3191, 0 } };
  25.     private int[][] BankPos = { { 3281, 3189, 0 }, { 3280, 3182, 0 },
  26.             { 3278, 3175, 0 }, { 3275, 3170, 0 }, { 3270, 3167, 0 } };
  27.  
  28.     private Area TanArea = new Area(3273, 3189, 3276, 3194);
  29.     private Area BankArea = new Area(3269, 3161, 3272, 3173);
  30.  
  31.     private final int[] hides = { 1739, 1747, 1749, 1751, 1753 };
  32.  
  33.     int cowHide = 0;
  34.     int greenD = 0;
  35.     int blueD = 0;
  36.     int redD = 0;
  37.     int blackD = 0;
  38.  
  39.     int hidesTanned = 0;
  40.     int coins = 995;
  41.     int npcID = 5808;
  42.     int hideWithdraw;
  43.  
  44.     public void onStart() {
  45.  
  46.         if (this.client.getInventory().contains(1739)) {
  47.             cowHide = 1;
  48.             hideWithdraw = 1739;
  49.  
  50.         } else if (this.client.getInventory().contains(1747)) {
  51.  
  52.             blackD = 1;
  53.             hideWithdraw = 1747;
  54.  
  55.         } else if (this.client.getInventory().contains(1749)) {
  56.  
  57.             redD = 1;
  58.             hideWithdraw = 1749;
  59.  
  60.         } else if (this.client.getInventory().contains(1751)) {
  61.  
  62.             blueD = 1;
  63.             hideWithdraw = 1751;
  64.  
  65.         } else if (this.client.getInventory().contains(1753)) {
  66.  
  67.             greenD = 1;
  68.             hideWithdraw = 1753;
  69.         }
  70.  
  71.         if (this.client.getMyPlayer().isInArea(this.BankArea)) {
  72.             this.state = State.TOTANNER;
  73.         }
  74.  
  75.         if (this.client.getMyPlayer().isInArea(this.TanArea)) {
  76.             this.state = State.TAN;
  77.         }
  78.  
  79.         runTime = new Timer(0);
  80.  
  81.     }
  82.  
  83.     public boolean WalkAlongPath(int[][] path, boolean AscendThroughPath,
  84.             int distanceFromEnd) {
  85.         if (distanceToPoint(AscendThroughPath ? path[path.length - 1][0]
  86.                 : path[0][0], AscendThroughPath ? path[path.length - 1][1]
  87.                 : path[0][1]) <= distanceFromEnd)
  88.             return true;
  89.         else {
  90.             WalkAlongPath(path, AscendThroughPath);
  91.             return false;
  92.         }
  93.     }
  94.  
  95.     public void WalkAlongPath(int[][] path, boolean AscendThroughPath) {
  96.         int destination = 0;
  97.         for (int i = 0; i < path.length; i++)
  98.             if (distanceToPoint(path[i][0], path[i][1]) < distanceToPoint(
  99.                     path[destination][0], path[destination][1]))
  100.                 destination = i;
  101.         if (client.getMyPlayer().isMoving()
  102.                 && distanceToPoint(path[destination][0], path[destination][1]) > (isRunning() ? 3
  103.                         : 2))
  104.             return;
  105.         if (AscendThroughPath && destination != path.length - 1
  106.                 || !AscendThroughPath && destination != 0)
  107.             destination += (AscendThroughPath ? 1 : -1);
  108.         try {
  109.             log("Walking to node:" + destination);
  110.             walk(new Position(path[destination][0], path[destination][1], 0));
  111.             Thread.sleep(700 + MethodProvider.random(600));
  112.         } catch (InterruptedException e) {
  113.             e.printStackTrace();
  114.         }
  115.     }
  116.  
  117.     private int distanceToPoint(int pointX, int pointY) {
  118.         return (int) Math.sqrt(Math
  119.                 .pow(client.getMyPlayer().getX() - pointX, 2)
  120.                 + Math.pow(client.getMyPlayer().getY() - pointY, 2));
  121.     }
  122.  
  123.     public int onLoop() throws InterruptedException {
  124.  
  125.         if ((this.client.getRunEnergy() > 40) && (this.state != State.TAN)
  126.                 && (this.state != State.BANK)) {
  127.             try {
  128.                 setRunning(true);
  129.             } catch (Exception localException) {
  130.             }
  131.         }
  132.  
  133.         if (this.state == State.TOBANK) {
  134.             return toBank();
  135.         } else if (this.state == State.TOTANNER) {
  136.             return toTan();
  137.         } else if (this.state == State.TAN) {
  138.             return tan();
  139.         } else if (this.state == State.BANK) {
  140.             return bank();
  141.         } else if (this.state == State.ENTERSHOP) {
  142.             return enterShop();
  143.         }
  144.  
  145.         return 250 + random(50);
  146.  
  147.     }
  148.  
  149.     public int toTan() throws InterruptedException {
  150.  
  151.         try {
  152.             WalkAlongPath(TannerPos, true);
  153.         } catch (Exception localException) {
  154.         }
  155.  
  156.         sleep(2000);
  157.         this.state = State.ENTERSHOP;
  158.  
  159.         return 250;
  160.  
  161.     }
  162.  
  163.     public int enterShop() throws InterruptedException {
  164.  
  165.         walkExact(new Position(3276, 3191, 0));
  166.  
  167.         if (this.client.getMyPlayer().isInArea(this.TanArea))
  168.             this.state = State.TAN;
  169.  
  170.         return 250;
  171.     }
  172.  
  173.     public int tan() throws InterruptedException {
  174.  
  175.         if (this.client.getOpenInterface() == null) {
  176.             NPC localNPC = closestNPCForName("Ellis");
  177.             if (localNPC == null) {
  178.                 log("Cannot find shop keeper: " + this.npcID + " !");
  179.                 return 0;
  180.             }
  181.  
  182.             if (localNPC != null) {
  183.                 if (localNPC.isVisible()) {
  184.                     localNPC.interact("Trade");
  185.                 } else {
  186.                     client.moveCameraToEntity(localNPC);
  187.                 }
  188.             }
  189.  
  190.             return 1000;
  191.         }
  192.  
  193.         if (greenD != 0) {
  194.             client.moveMouseTo(new RectangleDestination(91, 235, 10, 10),
  195.                     false, true, true);
  196.             client.moveMouseTo(new RectangleDestination(60, 307, 10, 10),
  197.                     false, true, false);
  198.  
  199.         } else if (cowHide != 0) {
  200.  
  201.             client.moveMouseTo(new RectangleDestination(91, 101, 10, 10),
  202.                     false, true, true);
  203.             client.moveMouseTo(new RectangleDestination(64, 172, 10, 10),
  204.                     false, true, false);
  205.  
  206.         } else if (blackD != 0) {
  207.  
  208.             client.moveMouseTo(new RectangleDestination(431, 234, 10, 10),
  209.                     false, true, true);
  210.             client.moveMouseTo(new RectangleDestination(401, 306, 10, 10),
  211.                     false, true, false);
  212.  
  213.         } else if (redD != 0) {
  214.  
  215.             client.moveMouseTo(new RectangleDestination(323, 231, 10, 10),
  216.                     false, true, true);
  217.             client.moveMouseTo(new RectangleDestination(291, 302, 10, 10),
  218.                     false, true, false);
  219.  
  220.         } else if (blueD != 0) {
  221.  
  222.             client.moveMouseTo(new RectangleDestination(210, 235, 10, 10),
  223.                     false, true, true);
  224.             client.moveMouseTo(new RectangleDestination(179, 306, 10, 10),
  225.                     false, true, false);
  226.  
  227.         }
  228.        
  229.         walkExact(new Position(3277, 3191, 0));
  230.         sleep(200);
  231.         this.state = State.TOBANK;
  232.  
  233.         return 250;
  234.     }
  235.  
  236.     public int toBank() {
  237.  
  238.         try {
  239.             WalkAlongPath(BankPos, true);
  240.         } catch (Exception localException) {
  241.         }
  242.  
  243.         if (this.client.getMyPlayer().isInArea(this.BankArea))
  244.             this.state = State.BANK;
  245.  
  246.         return 250;
  247.     }
  248.  
  249.     public int bank() {
  250.  
  251.         try {
  252.             if (!this.client.getBank().isOpen()) {
  253.                 try {
  254.                     selectEntityOption(
  255.                             closestObjectForName(new String[] { "Bank booth" }),
  256.                             true, "Bank");
  257.                 } catch (InterruptedException e) {
  258.                     e.printStackTrace();
  259.                 }
  260.             } else {
  261.                 try {
  262.                     this.client.getBank().depositAllExcept(this.coins);
  263.                     this.client.getBank().withdrawAll(hideWithdraw);
  264.                 } catch (InterruptedException e) {
  265.                     e.printStackTrace();
  266.                 }
  267.                 if (client.getInventory().isFull()) {
  268.                     this.client.getBank().close();
  269.                     this.state = State.TOTANNER;
  270.                 }
  271.             }
  272.         } catch (InterruptedException localInterruptedException1) {
  273.         }
  274.  
  275.         return 1000;
  276.  
  277.     }
  278.  
  279.     public void onPaint(Graphics g) {
  280.  
  281.         Graphics2D gr = (Graphics2D) g;
  282.  
  283.         gr.setColor(Color.WHITE);
  284.         gr.setFont(new Font("Arial", Font.PLAIN, 10));
  285.  
  286.         gr.drawString("State: " + this.state, 25, 95);
  287.         gr.drawString("Hides Tanned: " + hidesTanned, 25, 50);
  288.         gr.drawString("Hides Tanned/h: " + getPerHour(hidesTanned), 25, 65);
  289.         if (runTime != null) {
  290.             g.drawString("Runtime: " + Timer.format(runTime.getElapsed()), 25,
  291.                     80);
  292.         }
  293.         g.drawString("By Zappa", 443, 465);
  294.     }
  295.  
  296.     public static int getPerHour(int value) {
  297.         if (runTime != null && runTime.getElapsed() > 0) {
  298.             return (int) (value * 3600000d / runTime.getElapsed());
  299.  
  300.         } else {
  301.             return 0;
  302.         }
  303.     }
  304.  
  305.     public static long getPerHour(long value) {
  306.         if (runTime != null && runTime.getElapsed() > 0) {
  307.             return (long) (value * 3600000d / runTime.getElapsed());
  308.  
  309.         } else {
  310.             return 0;
  311.         }
  312.     }
  313.  
  314.     public void onMessage(String message) throws InterruptedException {
  315.  
  316.         if (message.contains("The tanner tans")) {
  317.  
  318.             hidesTanned = hidesTanned + 27;
  319.  
  320.         }
  321.  
  322.     }
  323.  
  324.     static enum State {
  325.         TOTANNER, TAN, TOBANK, BANK, ENTERSHOP;
  326.     }
  327.  
  328. }
Advertisement
Add Comment
Please, Sign In to add comment