Ministry

MinistryOfTiaras v1.0

May 16th, 2011
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.60 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.awt.event.MouseListener;
  4. import java.awt.image.BufferedImage;
  5. import javax.imageio.ImageIO;
  6. import java.io.IOException;
  7. import java.net.URL;
  8. import java.lang.String.*;
  9.  
  10. import org.rsbot.event.events.MessageEvent;
  11. import org.rsbot.event.listeners.PaintListener;
  12. import org.rsbot.event.listeners.MessageListener;
  13.  
  14. import org.rsbot.script.*;
  15. import org.rsbot.script.wrappers.*;
  16. import org.rsbot.script.methods.*;
  17. import org.rsbot.script.wrappers.RSTilePath;
  18.  
  19. import org.rsbot.script.util.Timer;
  20.  
  21. @ScriptManifest (   authors = { "Ministry" },
  22.                     keywords = { "Crafting, Smelting, Tiara" },
  23.                     name = "<html><b>MinistryOfTiaras</b></html>",
  24.                     description = "Smelts Silver ore to bars and crafts Tiaras",
  25.                     version = 1.0 )
  26.  
  27. @SuppressWarnings("static-access")
  28. public class MinistryOfTiaras extends Script implements PaintListener, MouseListener, MessageListener {
  29.        
  30.         private static int tiaras, percentTNL,startLvlC, startLvlS, expHourC, expToLvlC,
  31.                            startExpC, startExpS, lvlsGainedC, currentLvlC, tiarasHr,
  32.                            expGainedC, expGainedS, currentExpC, currentExpS, lvldC;
  33.        
  34.         private final static int bar_ID = 2355, tiara_ID = 5525, mould_ID = 5523, ore_ID = 442, furnace_ID = 11666, booth_ID = 35647;
  35.         private final double tXP = 52.5;
  36.         private boolean showPaint = true;
  37.         private Timer idle;
  38.  
  39.         private long startTime, millis, hours, minutes, seconds, STL, MTL, HTL, currentSystemTime;
  40.         private float sXP, mXP, hXP;
  41.         private String status = "";
  42.        
  43.         private BufferedImage normal = null, clicked = null;
  44.         final ScriptManifest update = getClass().getAnnotation(ScriptManifest.class);
  45.  
  46.         private final RSArea bankArea    = new RSArea(new RSTile(3265, 3160), new RSTile(3273, 3175));
  47.         private final RSArea furnaceArea = new RSArea(new RSTile(3274, 3184), new RSTile(3279, 3188));
  48.  
  49.         private enum State { Deposit, Withdraw, To_Bank, To_Furnace, Smelt, Craft, Wait, Mould, antiBan }
  50.         private enum LocationStates { AT_BANK, AT_FURNACE }
  51.  
  52.         RSTile[] toBank = {new RSTile(3277, 3176), new RSTile(3271, 3167)};
  53.         RSTile[] toFurnace = {new RSTile(3278, 3177), new RSTile(3275, 3186)};
  54.         private RSTilePath pathToBank;
  55.         private RSTilePath pathToFurnace;
  56.  
  57.     @Override
  58.     public boolean onStart() {
  59.         status = "Loading...";
  60.         startTime = System.currentTimeMillis();
  61.  
  62.         startExpC = skills.getCurrentExp(skills.CRAFTING);
  63.         startExpS = skills.getCurrentExp(skills.SMITHING);
  64.         startLvlC = skills.getCurrentLevel(skills.CRAFTING);
  65.         startLvlS = skills.getCurrentLevel(skills.SMITHING);
  66.        
  67.         mouse.setSpeed(random(8, 11));
  68.  
  69.         idle = new Timer (6500);
  70.        
  71.         try {
  72.                 final URL cursorURL = new URL("http://i53.tinypic.com/28b7bf9.png");
  73.                 final URL clickedURL = new URL("http://i55.tinypic.com/30vkjz9.png");
  74.                 normal = ImageIO.read(cursorURL);
  75.                 clicked = ImageIO.read(clickedURL);
  76.             } catch (Exception e) {
  77.                 log.severe("Error obtaining custom cursor.");
  78.             }
  79.         log("Welcome to Ministry Of Tiaras v" + update.version());
  80.         return true;
  81.     }
  82.  
  83.     private void antiBan() {
  84.         int b = random(0, 24);
  85.         switch (b) {
  86.         case 1:
  87.             if (random(0, 10) == 5) {
  88.                 mouse.moveSlightly();
  89.                 sleep(200, 600);
  90.                 mouse.moveRandomly(150, 350);
  91.             }
  92.             break;
  93.         case 2:
  94.             if (random(0, 13) == 2) {
  95.                 camera.setAngle(random(30, 70));
  96.                 sleep(400, 1200);
  97.             }
  98.             break;
  99.         case 3:
  100.             if (random(0, 24) == 6) {
  101.                 mouse.moveOffScreen();
  102.                 sleep(1200, 2000);
  103.             }
  104.             break;
  105.         case 4:
  106.             if (random(0, 18) == 3) {
  107.                 game.openTab(1);
  108.                 skills.doHover(skills.INTERFACE_CRAFTING);
  109.                 sleep(1100, 2400);
  110.                 if (lvldC == 1) {
  111.                     mouse.click(true);
  112.                     lvldC = 0;
  113.                 }
  114.                 sleep(500, 750);
  115.             }
  116.             break;
  117.         case 5:
  118.             if (random(0, 15) == 4) {
  119.                 mouse.moveRandomly(8);
  120.                 sleep(1400, 2400);
  121.             }
  122.             break;
  123.         case 6:
  124.             if (random(0, 19) == 5) {
  125.                 game.openTab(random(random(4, 7), random(3, 5)));
  126.                 mouse.sleep(1500);
  127.                 sleep(400, 500);
  128.             }
  129.          case 7:
  130.          if(random(0,15) == 3){
  131.             mouse.move(535, 60);
  132.             mouse.click(true);
  133.             sleep(1000, 2500);
  134.         }
  135.             break;
  136.          case 8:
  137.              if(random(0, 19) == 8) {
  138.                  game.openTab(1);
  139.                  skills.doHover(skills.INTERFACE_SMITHING);
  140.                  sleep(1800, 3150);
  141.              }
  142.         default:
  143.             break;
  144.         }
  145.  
  146.     }
  147.  
  148.     private void runEnable() {
  149.         if(walking.isRunEnabled() == false && walking.getEnergy() >= random(45, 67)) {
  150.             walking.setRun(true);
  151.             }
  152.     }
  153.  
  154.     public void messageReceived(MessageEvent e) {
  155.         String x = e.getMessage().toLowerCase();
  156.         if (x.contains("gained a crafting")) {
  157.             lvldC = 1;
  158.                 }
  159.             }
  160.  
  161.     private boolean atBank(){
  162.             return bankArea.contains(getMyPlayer().getLocation());
  163.     }
  164.  
  165.     private boolean atFurnace() {
  166.             return furnaceArea.contains(getMyPlayer().getLocation());
  167.     }
  168.  
  169.     private void getMould() {
  170.                 RSTilePath pathToBank = walking.newTilePath(toBank);
  171.                 RSObject booth = objects.getNearest(booth_ID);
  172.                     status = "Getting Mould";
  173.                 if(!atBank() && inventory.getCount(mould_ID) == 0) {
  174.                     pathToBank.traverse();
  175.                     sleep(400);
  176.                 if(booth.isOnScreen()) {
  177.                     bank.open();
  178.                 if(bank.isOpen() && bank.getCount(mould_ID) == 0) {
  179.                     log.severe("Cannot find tiara mould!");
  180.                     stopScript(true);
  181.                     }
  182.                 if (bank.isOpen() && bank.getCount(mould_ID) >= 1 && !inventory.containsOneOf(mould_ID)) {
  183.                     bank.depositAll();
  184.                     sleep(random(460, 590));
  185.                     bank.withdraw(mould_ID, 1);
  186.                     sleep(random(200, 400));
  187.                     withdraw();
  188.                 }
  189.             }
  190.         }
  191.     }
  192.  
  193.     private void toBank() {
  194.             status = "Walking to Bank";
  195.         RSTilePath pathToBank = walking.newTilePath(toBank);
  196.         if (calc.distanceTo(pathToBank.getNext()) < 3)
  197.             pathToBank.randomize(2,2).traverse();
  198.         if (calc.distanceTo(pathToBank.getNext()) < 2)
  199.             pathToBank.randomize(2,2).traverse();
  200.             sleep(200);
  201.     }
  202.  
  203.     private void toFurnace() {
  204.         RSObject furnace = objects.getNearest(furnace_ID);
  205.         if (!furnace.isOnScreen()) {
  206.             status = "Walking to Furnace"; }
  207.         RSTilePath pathToFurnace = walking.newTilePath(toFurnace);
  208.         if (calc.distanceTo(pathToFurnace.getNext()) < 3)
  209.             pathToFurnace.randomize(2,2).traverse();
  210.         if (calc.distanceTo(pathToFurnace.getNext()) < 2)
  211.             pathToFurnace.randomize(2,2).traverse();
  212.             sleep(200);
  213.     }
  214.      
  215.     private boolean deposit() {
  216.             status = "Depositing...";
  217.         RSObject booth = objects.getNearest(booth_ID);
  218.                     camera.turnTo(booth);
  219.                     bank.open();
  220.                     sleep(320, 500);
  221.         if (bank.isOpen() && inventory.contains(tiara_ID)) {
  222.                     bank.depositAllExcept(mould_ID);
  223.                     mouse.moveOffScreen();
  224.                     sleep(400, 600);
  225.         }
  226.                return true;
  227.     }
  228.    
  229.     private void withdraw() {
  230.             status = "Withdrawing...";
  231.         RSObject booth = objects.getNearest(booth_ID);
  232.         int w = random(1, 2);
  233.                     camera.turnTo(booth);
  234.                     bank.open();
  235.         if (!inventory.contains(mould_ID)) {
  236.                     sleep(400);
  237.                     getMould();
  238.         } else {
  239.         if (bank.isOpen() && bank.getCount(ore_ID) < 27) {
  240.                     sleep(random(850, 1400));
  241.                     log.severe("We have ran out of ore! Stopping script.");
  242.                     stopScript(true);
  243.             } else {
  244.         if (bank.isOpen() && bank.getCount(ore_ID) >= 27 && !inventory.contains(ore_ID)) {
  245.                     sleep(400, 550);
  246.                     bank.withdraw(ore_ID, 27);
  247.                     mouse.moveRandomly(8);
  248.                     sleep(150, 400);
  249.               if (random(1,2) == 1) {
  250.                  bank.close(); }
  251.               else {
  252.                  toFurnace(); }
  253.                 }
  254.             }
  255.         }
  256.     }
  257.  
  258.     private void smelt() {
  259.             status = "Smelting";
  260.                     RSItem ore = inventory.getItem(ore_ID);
  261.                     RSObject furnace = objects.getNearest(furnace_ID);
  262.             if (!interfaces.getComponent(905, 14).isValid() && inventory.contains(ore_ID) && idle.getRemaining() < 200) {
  263.                     inventory.useItem(ore, furnace);
  264.                     sleep(random(2400, 2600));
  265.             }
  266.             if (interfaces.getComponent(905, 14).isValid() && idle.getRemaining() < 200) {
  267.                     idle.reset();
  268.                     interfaces.getComponent(905, 14).doAction("Make All");
  269.                     sleep(random(1800, 2200));
  270.                while(players.getMyPlayer().getAnimation() == 3243) {
  271.                     camera.moveRandomly(650);
  272.                     mouse.moveRandomly(4);
  273.                
  274.                }
  275.             }
  276.         }
  277.  
  278.     private void craft() {
  279.             status = "Crafting";
  280.                     RSItem bar = inventory.getItem(bar_ID);
  281.                     RSObject furnace = objects.getNearest(furnace_ID);
  282.             if (!interfaces.getComponent(438, 45).isValid() && idle.getRemaining() < 200) {
  283.                     idle.reset();
  284.                     inventory.useItem(bar, furnace);
  285.                     sleep(random(2400, 2600));
  286.             }
  287.             if (interfaces.getComponent(438, 45).isValid() && idle.getRemaining() < 200) {
  288.                     interfaces.getComponent(438, 45).doAction("Make All");
  289.                     sleep(random(1800, 2200));
  290.               while(players.getMyPlayer().getAnimation() == 3243) {
  291.                     camera.moveRandomly(650);
  292.                     mouse.moveRandomly(4);
  293.             }
  294.         }
  295.     }
  296.  
  297.         private State checkState() {
  298.       RSObject furnace = objects.getNearest(furnace_ID);
  299.       RSObject booth = objects.getNearest(booth_ID);
  300.         if (game.isLoggedIn()) {
  301.  
  302.         if (inventory.getCount(mould_ID) == 0) {
  303.             return State.Mould;
  304.         }
  305.         if (!atBank() && inventory.getCount(tiara_ID) == 27 && !inventory.contains(bar_ID)) {
  306.             return State.To_Bank;
  307.         }
  308.         if (booth.isOnScreen() && players.getMyPlayer().getAnimation() == -1 && !bank.isOpen() && inventory.getCount(tiara_ID) == 27) {
  309.             return State.Deposit;
  310.         }
  311.         if (booth.isOnScreen() && !inventory.contains(ore_ID) && !inventory.contains(bar_ID) && !inventory.contains(tiara_ID)) {
  312.             return State.Withdraw;
  313.         }
  314.         if (atFurnace() && furnace.isOnScreen() && !inventory.contains(ore_ID) && inventory.getCount(bar_ID) <= 27 && idle.getRemaining() < 200) {
  315.             return State.Craft;
  316.         }
  317.         if (furnace.isOnScreen() && inventory.getCount(ore_ID) <= 27 && idle.getRemaining() < 200) {
  318.             return State.Smelt;
  319.         }
  320.         if (!atFurnace() && inventory.getCount(ore_ID) >= 27 || inventory.getCount(bar_ID) <= 27) {
  321.             return State.To_Furnace;
  322.         } else {
  323.                 return State.antiBan;
  324.           }
  325.         }
  326.         return State.Wait;
  327.     }
  328.  
  329.     public int loop() {
  330.             if (interfaces.canContinue()) {
  331.                 interfaces.clickContinue();
  332.             }
  333.             if (!getMyPlayer().isIdle() || players.getMyPlayer().getAnimation() == 3243) {
  334.                 idle.reset();
  335.                     }
  336.  
  337.                     runEnable();
  338.                     antiBan();
  339.  
  340.             switch (checkState()) {
  341.                 case Mould:
  342.                     getMould();
  343.                     return random (150, 750);
  344.                 case Smelt:
  345.                     smelt();
  346.                     return random (150, 750);
  347.                 case Craft:
  348.                     craft();
  349.                     return random (150, 750);
  350.                 case To_Bank:
  351.                     toBank();
  352.                     return random (150, 750);
  353.                 case Deposit:
  354.                     deposit();
  355.                     return random (150, 750);
  356.                 case Withdraw:
  357.                     withdraw();
  358.                     return random (150, 750);
  359.                 case To_Furnace:
  360.                     toFurnace();
  361.                     return random (150, 750);
  362.                 case Wait:
  363.                     sleep(random(400, 500));
  364.                     return random (150, 750);
  365.                 case antiBan:
  366.                     antiBan();
  367.                     return random (150, 750);
  368.             }
  369.         return (random(150, 750));
  370.         }
  371.  
  372.     private Image getImage(String url) {
  373.         try {
  374.                     return ImageIO.read(new URL(url));
  375.         } catch(IOException e) {
  376.                     return null;
  377.         }
  378.     }
  379.  
  380.     private final Color color1 = new Color(255, 255, 255);
  381.     private final Color color2 = new Color(204, 0, 0, 135);
  382.     private final Color color3 = new Color(51, 204, 0, 135);
  383.     private final Color color4 = new Color(0, 0, 0, 150);
  384.  
  385.     private final BasicStroke stroke1 = new BasicStroke(1);
  386.  
  387.     private final Font font1 = new Font("Arial", 1, 14);
  388.     private final Font font2 = new Font("Arial", 1, 12);
  389.     private final Font font3 = new Font("Arial", 0, 10);
  390.    
  391.     Rectangle tab1 = new Rectangle(496, 345, 30, 30);
  392.    
  393.     private final Image Simg = getImage("http://i52.tinypic.com/21jaich.png");
  394.     private final Image Himg = getImage("http://i56.tinypic.com/2502r28.png");
  395.    
  396.      public void mouseClicked(MouseEvent e){
  397.         if(tab1.contains(e.getPoint())){
  398.            showPaint = !showPaint;
  399.             }
  400.         }
  401.         public void mouseEntered(MouseEvent e){
  402.         }
  403.         public void mouseExited(MouseEvent e){
  404.         }
  405.         public void mouseReleased(MouseEvent e){
  406.         }
  407.         public void mousePressed(MouseEvent e){
  408.         }
  409.  
  410.     public void onRepaint(Graphics g1) {
  411.        
  412.                     millis = System.currentTimeMillis() - startTime;
  413.                     hours = millis / (1000 * 60 * 60);
  414.                     millis -= hours * (1000 * 60 * 60);
  415.                     minutes = millis / (1000 * 60);
  416.                     millis -= minutes * (1000 * 60);
  417.                     seconds = millis / 1000;
  418.  
  419.        
  420.                     currentExpC = skills.getCurrentExp(skills.CRAFTING);
  421.                     currentExpS = skills.getCurrentExp(skills.SMITHING);
  422.                     currentLvlC = skills.getCurrentLevel(skills.CRAFTING);
  423.                     expToLvlC = skills.getExpToNextLevel(Skills.CRAFTING);
  424.                     percentTNL = skills.getPercentToNextLevel(skills.CRAFTING);
  425.                    
  426.                     currentSystemTime = System.currentTimeMillis();
  427.                    
  428.                     lvlsGainedC = currentLvlC-startLvlC;
  429.                     expGainedC = currentExpC-startExpC;
  430.                     expGainedS = currentExpS-startExpS;
  431.                     expHourC = (int) ((expGainedC) * 3600000D / (currentSystemTime - startTime));
  432.                     tiarasHr = (int) ((tiaras) * 3600000D/ (System.currentTimeMillis() - startTime));
  433.                     tiaras = (int) ((currentExpC - startExpC) / tXP);
  434.                    
  435.         final int percentBar = (int) (skills.getPercentToNextLevel(Skills.CRAFTING)*5.16);
  436.                    
  437.                 if (sXP > 0) {
  438.                     STL = (int) (expToLvlC / sXP);
  439.         }
  440.         if (STL >= 60) {
  441.                     MTL = STL / 60;
  442.                     STL -= MTL * 60;
  443.         } else {
  444.                     MTL = 0;
  445.                 }
  446.         if (MTL >= 60) {
  447.                     HTL = MTL / 60;
  448.                     MTL -= HTL * 60;
  449.         } else {
  450.                     HTL = 0;
  451.         }
  452.                    
  453.                    
  454.     if (game.isLoggedIn() && !game.isWelcomeScreen()) {
  455.         Graphics2D g = (Graphics2D)g1;
  456.  
  457.     if (showPaint == false) {
  458.         g.drawImage(Simg, 496, 345, null);
  459.         }
  460.     if (showPaint == true) {
  461.         g.drawImage(Himg, 496, 345, null);
  462.         g.setColor(color1);
  463.         g.setStroke(stroke1);
  464.         g.setColor(color2);
  465.         g.fillRect(0, 480, 516, 27);
  466.         g.setColor(color3);
  467.         g.fillRect(0, 480, percentBar, 27);
  468.         g.setColor(color4);
  469.         g.fillRect(549, 312, 183, 150);
  470.         g.drawRect(549, 312, 183, 150);
  471.         g.setFont(font1);
  472.         g.setColor(color1);
  473.         g.drawString("Ministry Of Tiaras", 564, 330);
  474.         g.drawString( percentTNL +"%", 258, 498);
  475.         g.setFont(font2);
  476.         g.drawString("v" +update.version(), 693, 330);
  477.         g.drawString("Status : " + status , 564, 456);
  478.         g.setFont(font3);
  479.         g.drawString("Tiaras Crafted :     " +tiaras, 564, 348);
  480.         g.drawString("Tiaras p/hr :     " +tiarasHr, 564, 363);
  481.         g.drawString("Crafting Exp :     " + expGainedC, 564, 378);
  482.         g.drawString("Craft Exp p/hr :     " + expHourC, 564, 393);
  483.         g.drawString("Smithing Exp :     " + expGainedS, 564, 408);
  484.         g.drawString("Current Level :     " +currentLvlC + "(+" +lvlsGainedC +")", 564, 423);
  485.         g.drawString("Runtime :     " +hours + ":" + minutes + ":" + seconds, 564, 438);
  486.             }
  487.     if (clicked != null) {
  488.                     final int mx = (int)mouse.getLocation().getX();
  489.                     final int my = (int)mouse.getLocation().getY();
  490.  
  491.                     final long mpt = System.currentTimeMillis() - mouse.getPressTime();
  492.                 if (mouse.getPressTime() == -1 || mpt >= 300)
  493.                     g.drawImage(normal, mx - 10, my - 6, null);
  494.                 if (mpt < 300)
  495.                     g.drawImage(clicked, mx - 10, my - 6, null);
  496.             }
  497.         }
  498.     }
  499. }
Advertisement
Add Comment
Please, Sign In to add comment