Advertisement
Guest User

Untitled

a guest
Feb 27th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.25 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.*;
  4. import java.util.*;
  5.  
  6. import org.tribot.api.*;
  7. import org.tribot.api.input.*;
  8. import org.tribot.api2007.*;
  9. import org.tribot.api2007.Objects;
  10. import org.tribot.api2007.types.*;
  11. import org.tribot.script.interfaces.*;
  12. import org.tribot.script.*;
  13.  
  14. /**
  15.  * @author Spencer - Deluxes
  16.  */
  17. @ScriptManifest(authors = { "Deluxes" }, category = "Mining", name = "DeluxesESSENCE", description = "Start at Varrock East Bank, in the mine, or somewhere you may encounter on the way. Have a pickaxe equipped or in your inventory.")
  18. public class DeluxesESS  extends Script implements Painting
  19. {
  20.     ArrayList<Node> nodes = new ArrayList<>();
  21.    
  22.     public static RSTile[] path = DeluxeUtil.CreatePath(new RSTile(3253, 3422), new RSTile(3262, 3419), new RSTile(3258, 3408), new RSTile(3256, 3398), new RSTile(3253, 3402));
  23.     static Polygon bankArea = DeluxeUtil.CreateArea(new RSTile(3249, 3418), new RSTile(3257, 3425));
  24.    
  25.     long startTime = System.currentTimeMillis();
  26.    
  27.     public static String state = "";
  28.    
  29.     int essMined = 0;
  30.     int lastEss = 0;
  31.     int startExp = Skills.SKILLS.MINING.getXP();
  32.    
  33.     public static int[] PICK_AXE_IDS = new int[] {1275, 1271, 1273, 1269, 1267, 1265 };
  34.    
  35.     @Override
  36.     public void onPaint(Graphics g)
  37.     {
  38.        
  39.        
  40.         long timeRan = System.currentTimeMillis() - startTime;
  41.         int expGained = Skills.SKILLS.MINING.getXP() - startExp;
  42.         Graphics2D g1 = (Graphics2D)g;
  43.         g1.drawString("STATE: " + state, 236, 225);
  44.         g1.drawString("ESS MINED: " + expGained / 5, 236, 245);
  45.         g1.drawString("EXP Gained: " + expGained + "(" + (Skills.SKILLS.MINING.getCurrentLevel() - Skills.getLevelByXP(startExp)) + ")", 236, 265);
  46.         g1.drawString("TIME RAN: " + Timing.msToString(timeRan), 236, 285);
  47.         g1.drawString("ESS PER HOUR: " + DeluxeUtil.GetAmountPerHour(expGained / 5, startTime), 236, 305);
  48.     }
  49.    
  50.     public static boolean inVarrock()
  51.     {
  52.         return Player.getPosition().distanceTo(new RSTile(3253, 3401)) < 50;
  53.     }
  54.     public static boolean inBank()
  55.     {
  56.         return DeluxeUtil.inArea(bankArea, Player.getPosition());
  57.     }
  58.     public static boolean inMine()
  59.     {
  60.         RSObject[] ess = Objects.findNearest(150, "Rune Essence");
  61.         return ess.length > 0;
  62.     }
  63.    
  64.     @Override
  65.     public void run()
  66.     {
  67.        
  68.         Collections.addAll(nodes, new MineNode(), new BankNode(), new DeathNode());
  69.         Walking.setControlClick(true);
  70.         Walking.setWalkingTimeout(1000);
  71.         Mouse.setSpeed(175);
  72.        
  73.         loop(40, 50);
  74.     }
  75.    
  76.     void loop(int min, int max)
  77.     {
  78.         while (true)
  79.         {
  80.             for (final Node node : nodes)
  81.             {
  82.                 if (node.validate())
  83.                 {
  84.                     node.execute();
  85.                     sleep(min, max);
  86.                 }
  87.             }
  88.         }
  89.     }
  90. }
  91.  
  92. class MineNode extends Node
  93. {
  94.     @Override
  95.     public void execute()
  96.     {
  97.         int current = 0;
  98.         if ((DeluxesESS.inVarrock() || DeluxesESS.inBank()) && !DeluxesESS.inMine())
  99.         {
  100.             DeluxesESS.state = "Walking to Aubury";
  101.             RSNPC[] aubury = NPCs.find("Aubury");
  102.             if (DeluxesESS.inBank() || (aubury.length > 0 && Player.getPosition().distanceTo(aubury[0].getPosition()) > 10))
  103.             {
  104.                 //WebWalking.walkTo(new RSTile(3253, 3401));
  105.                
  106.                 boolean walkPath = DeluxeUtil.TraversePath(DeluxesESS.path, 8);
  107.                 if (!walkPath && Player.getPosition().distanceTo(DeluxesESS.path[DeluxesESS.path.length - 1].getPosition()) > 2 && Player.getPosition().distanceTo(DeluxesESS.path[DeluxesESS.path.length - 1].getPosition()) < 6)
  108.                 {
  109.                     General.println("Checking the door. Might be closed.");
  110.                     DeluxesESS.state = "Checking Door";
  111.                     RSObject[] door = Objects.getAt(new RSTile(3253, 3398));
  112.                     if (door.length > 0)
  113.                     {
  114.                         Walking.walkTo(door[0].getPosition());
  115.                         if (!door[0].isOnScreen())
  116.                         {
  117.                             Camera.turnToTile(door[0].getPosition());
  118.                         }
  119.                         DynamicClicking.clickRSObject(door[0], "Open");
  120.                         General.println("Doors needs to be opened.");
  121.                         do
  122.                         {
  123.                             General.sleep(100);
  124.                             current++;
  125.                         } while (Objects.getAt(new RSTile(3253, 3398)).length > 0 && current < 50);
  126.                         current = 0;
  127.                     }
  128.                 }
  129.                 else if (!walkPath)
  130.                 {
  131.                     General.println("Failed to walk path. Using webwalking to fix.");
  132.                     WebWalking.walkTo(new RSTile(3253, 3401));
  133.                 }
  134.             }
  135.             else
  136.             {
  137.                 /*DeluxesESS.state = "Checking Door";
  138.                 RSObject[] door = Objects.getAt(new RSTile(3253, 3398));
  139.                 if (door.length > 0)
  140.                 {
  141.                     DynamicClicking.clickRSObject(door[0], "Open");            
  142.                 }*/
  143.                
  144.                
  145.                 aubury = NPCs.find("Aubury");
  146.                 if (aubury.length > 0 && Player.getPosition().distanceTo(aubury[0].getPosition()) > 5)
  147.                 {
  148.                     Walking.walkTo(new RSTile(3253, 3401));
  149.                     while ((Player.isMoving() && current < 20) && Player.getPosition().distanceTo(aubury[0].getPosition()) > 5)
  150.                     {
  151.                         General.sleep(100);
  152.                         current++;
  153.                     }
  154.                     current = 0;
  155.                 }
  156.                 DeluxesESS.state = "Teleport via Aurbury";
  157.                 if (aubury.length > 0 && Player.getPosition().distanceTo(aubury[0].getPosition()) < 5)
  158.                 {
  159.                     if (!aubury[0].isOnScreen())
  160.                     {
  161.                         Camera.turnToTile(aubury[0].getPosition());
  162.                     }
  163.                    
  164.                     boolean success = false;
  165.                     while (!success)
  166.                      success = DynamicClicking.clickRSNPC(aubury[0], "Teleport");
  167.                     success = false;
  168.                     while (Player.isMoving() || (DeluxesESS.inVarrock() && current < 30))
  169.                     {
  170.                         General.sleep(100);
  171.                         if (!Player.isMoving())
  172.                             current++;
  173.                     }
  174.                     current = 0;
  175.                 }
  176.             }
  177.         }
  178.         else if (DeluxesESS.inMine())
  179.         {
  180.             DeluxesESS.state = "Looking for nearest Rune Essence Mine";
  181.             RSObject[] ess = Objects.findNearest(150, "Rune Essence");
  182.             if (ess.length > 0)
  183.             {
  184.                 if (Player.getPosition().distanceTo(ess[0].getPosition()) > 5)
  185.                 {
  186.                     Walking.walkPath(Walking.generateStraightPath(ess[0].getPosition()));
  187.                     General.sleep(500, 750);
  188.                     while (Player.isMoving() && (Player.getPosition().distanceTo(ess[0].getPosition()) > 5 || !ess[0].isOnScreen()) && current < 50)
  189.                     {
  190.                         General.sleep(100);
  191.                         current++;
  192.                     }
  193.                     current = 0;
  194.                 }
  195.                
  196.                 if (!ess[0].isOnScreen())
  197.                 {
  198.                     DeluxesESS.state = "Moving Camera";
  199.                     Camera.turnToTile(ess[0].getPosition());
  200.                     General.sleep(400, 700);
  201.                 }
  202.                
  203.                 DeluxesESS.state = "Mining Rune Essence";
  204.                 DynamicClicking.clickRSObject(ess[0], "Mine");
  205.                
  206.                 while ((Player.isMoving() && Player.getAnimation() == -1 && current < 30) || (Player.getAnimation() != -1 && !Inventory.isFull()))
  207.                 {
  208.                     General.sleep(100);
  209.                     current++;
  210.                 }
  211.                 current = 0;
  212.             }
  213.         }
  214.     }
  215.  
  216.     @Override
  217.     public boolean validate()
  218.     {
  219.         return !Inventory.isFull();
  220.     }
  221. }
  222.  
  223. class BankNode extends Node
  224. {
  225.     @Override
  226.     public void execute()
  227.     {
  228.         int current = 0;
  229.         RSNPC[] portal = NPCs.findNearest("null");
  230.         if (portal.length > 0 && !DeluxesESS.inVarrock())
  231.         {
  232.             if (Player.getPosition().distanceTo(portal[0].getPosition()) > 2)
  233.             {
  234.                 Walking.walkTo(portal[0].getPosition());
  235.             }
  236.            
  237.             while (Player.isMoving() && Player.getPosition().distanceTo(portal[0].getPosition()) > 2 && current < 50)
  238.             {
  239.                 General.sleep(100);
  240.                 current++;
  241.             }
  242.             current = 0;
  243.            
  244.             if (!portal[0].isOnScreen())
  245.             {
  246.                 DeluxesESS.state = "Moving Camera";
  247.                 Camera.turnToTile(portal[0].getPosition());
  248.                 General.sleep(400, 700);
  249.             }
  250.            
  251.             DeluxesESS.state = "Attempting to leave mine";
  252.             portal[0].click("Exit", "Use", "Leave");
  253.             while (!DeluxesESS.inVarrock() && current < 30)
  254.             {
  255.                 General.sleep(100);
  256.                 current++;
  257.             }
  258.             current = 0;
  259.         }
  260.        
  261.         if (DeluxesESS.inVarrock())
  262.         {
  263.             DeluxesESS.state = "Moving to bank";
  264.             WebWalking.walkToBank();
  265.             while (Player.isMoving() && !DeluxesESS.inBank() && current < 20)
  266.             {
  267.                 General.sleep(100);
  268.                 current++;
  269.             }
  270.             current = 0;
  271.             if (!DeluxesESS.inBank() && !Player.isMoving())
  272.             {
  273.                 Walking.walkTo(DeluxeUtil.getRandomTile(DeluxesESS.bankArea));
  274.             }  
  275.         }
  276.        
  277.         if (DeluxesESS.inBank())
  278.         {
  279.             DeluxesESS.state = "Opening Bank";
  280.             Banking.openBankBooth();
  281.             if (Banking.isPinScreenOpen())
  282.             {
  283.                 Banking.inPin();
  284.             }
  285.             while (!Banking.isBankScreenOpen() && current < 10)
  286.             {
  287.                 General.sleep(100);
  288.                 current++;
  289.             }
  290.             current = 0;
  291.            
  292.             if (Banking.isBankScreenOpen())
  293.                 Banking.depositAllExcept(DeluxesESS.PICK_AXE_IDS);
  294.            
  295.             while (Inventory.isFull() && current < 7.5)
  296.             {
  297.                 General.sleep(100);
  298.                 current++;
  299.             }
  300.             current = 0;
  301.         }
  302.     }
  303.  
  304.     @Override
  305.     public boolean validate()
  306.     {
  307.         return Inventory.isFull();
  308.     }
  309. }
  310.  
  311. class DeathNode extends Node
  312. {
  313.    
  314.     @Override
  315.     public void execute()
  316.     {
  317.         DeluxesESS.state = "Death Walk";
  318.         while (!DeluxesESS.inVarrock())
  319.         {
  320.             WebWalking.walkTo(new RSTile(3253, 3401));
  321.             General.sleep(100);
  322.         }
  323.     }
  324.    
  325.     @Override
  326.     public boolean validate()
  327.     {
  328.         return Player.getPosition().distanceTo(new RSTile(3222,3218)) < 100;
  329.     }
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement