Ministry

MinistryOfTiaras v1.0

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