Ministry

Untitled

May 16th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.03 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 (3000);
  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.             pathToBank.traverse();
  197.             sleep(200);
  198.     }
  199.  
  200.     private void toFurnace() {
  201.             status = "Walking to Furnace";
  202.         RSTilePath pathToFurnace = walking.newTilePath(toFurnace);
  203.             pathToFurnace.traverse();
  204.             sleep(200);
  205.     }
  206.      
  207.     private boolean deposit() {
  208.             status = "Depositing...";
  209.         RSObject booth = objects.getNearest(booth_ID);
  210.                     camera.turnTo(booth);
  211.                     bank.open();
  212.                     sleep(320, 500);
  213.         if (bank.isOpen() && inventory.contains(tiara_ID)) {
  214.                     bank.depositAllExcept(mould_ID);
  215.                     mouse.moveOffScreen();
  216.                     sleep(400, 600);
  217.         }
  218.                return true;
  219.     }
  220.    
  221.     private void withdraw() {
  222.             status = "Withdrawing...";
  223.         RSObject booth = objects.getNearest(booth_ID);
  224.         int w = random(1, 2);
  225.                     camera.turnTo(booth);
  226.                     bank.open();
  227.         if (!inventory.contains(mould_ID)) {
  228.                     sleep(400);
  229.                     getMould();
  230.         } else {
  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.                     stopScript(true);
  235.             } else {
  236.         if (bank.isOpen() && bank.getCount(ore_ID) >= 27 && !inventory.contains(ore_ID)) {
  237.                     sleep(400, 550);
  238.                     bank.withdraw(ore_ID, 27);
  239.                     mouse.moveRandomly(8);
  240.                     sleep(150, 400);
  241.               if (random(1,2) == 1) {
  242.                  bank.close(); }
  243.               else {
  244.                  toFurnace(); }
  245.                 }
  246.             }
  247.         }
  248.     }
  249.  
  250.     private void smelt() {
  251.             status = "Smelting";
  252.                     RSItem ore = inventory.getItem(ore_ID);
  253.                     RSObject furnace = objects.getNearest(furnace_ID);
  254.             if (!interfaces.getComponent(905, 14).isValid() && inventory.contains(ore_ID) && idle.getRemaining() <= 500) {
  255.                     inventory.useItem(ore, furnace);
  256.                     sleep(random(2400, 2600));
  257.             }
  258.             if (interfaces.getComponent(905, 14).isValid() && idle.getRemaining() <= 500) {
  259.                     interfaces.getComponent(905, 14).doAction("Make All");
  260.                while(players.getMyPlayer().getAnimation() == 3243) {
  261.                     camera.moveRandomly(650);
  262.                     mouse.moveRandomly(4);
  263.                
  264.                }
  265.             }
  266.         }
  267.  
  268.     private void craft() {
  269.             status = "Crafting";
  270.                     RSItem bar = inventory.getItem(bar_ID);
  271.                     RSObject furnace = objects.getNearest(furnace_ID);
  272.             if (!interfaces.getComponent(438, 45).isValid() && idle.getRemaining() <= 500) {
  273.                     inventory.useItem(bar, furnace);
  274.                     sleep(random(2400, 2600));
  275.             }
  276.             if (interfaces.getComponent(438, 45).isValid() && idle.getRemaining() <= 500) {
  277.                     interfaces.getComponent(438, 45).doAction("Make All");
  278.                     sleep(random(400,600));
  279.               while(players.getMyPlayer().getAnimation() == 3243) {
  280.                     camera.moveRandomly(650);
  281.                     mouse.moveRandomly(4);
  282.             }
  283.         }
  284.     }
  285.  
  286.         private State checkState() {
  287.       RSObject furnace = objects.getNearest(furnace_ID);
  288.       RSObject booth = objects.getNearest(booth_ID);
  289.         if (game.isLoggedIn()) {
  290.  
  291.         if (inventory.getCount(mould_ID) == 0) {
  292.             return State.Mould;
  293.         }
  294.         if (!atBank() && inventory.getCount(tiara_ID) == 27 && !inventory.contains(bar_ID)) {
  295.             return State.To_Bank;
  296.         }
  297.         if (booth.isOnScreen() && players.getMyPlayer().getAnimation() == -1 && !bank.isOpen() && inventory.getCount(tiara_ID) == 27) {
  298.             return State.Deposit;
  299.         }
  300.         if (booth.isOnScreen() && !inventory.contains(ore_ID) && !inventory.contains(bar_ID) && !inventory.contains(tiara_ID)) {
  301.             return State.Withdraw;
  302.         }
  303.         if (atFurnace() && furnace.isOnScreen() && !inventory.contains(ore_ID) && inventory.getCount(bar_ID) >= 27 && idle.getRemaining() < 500) {
  304.             return State.Craft;
  305.         }
  306.         if (furnace.isOnScreen() && inventory.getCount(ore_ID) >= 27 && idle.getRemaining() < 500) {
  307.             return State.Smelt;
  308.         }
  309.         if (!atFurnace() && inventory.getCount(ore_ID) >= 27 || inventory.getCount(bar_ID) >= 27) {
  310.             return State.To_Furnace;
  311.         } else {
  312.                 return State.antiBan;
  313.           }
  314.         }
  315.         return State.Wait;
  316.     }
  317.  
  318.     public int loop() {
  319.             if (interfaces.canContinue()) {
  320.                 interfaces.clickContinue();
  321.             }
  322.             if (!getMyPlayer().isIdle() || players.getMyPlayer().getAnimation() == 3243) {
  323.                 idle.reset();
  324.                     }
  325.  
  326.                     runEnable();
  327.                     antiBan();
  328.  
  329.             switch (checkState()) {
  330.                 case Mould:
  331.                     getMould();
  332.                     return random (150, 750);
  333.                 case Smelt:
  334.                     smelt();
  335.                     return random (150, 750);
  336.                 case Craft:
  337.                     craft();
  338.                     return random (150, 750);
  339.                 case To_Bank:
  340.                     toBank();
  341.                     return random (150, 750);
  342.                 case Deposit:
  343.                     deposit();
  344.                     return random (150, 750);
  345.                 case Withdraw:
  346.                     withdraw();
  347.                     return random (150, 750);
  348.                 case To_Furnace:
  349.                     toFurnace();
  350.                     return random (150, 750);
  351.                 case Wait:
  352.                     sleep(random(400, 500));
  353.                     return random (150, 750);
  354.                 case antiBan:
  355.                     antiBan();
  356.                     return random (150, 750);
  357.             }
  358.         return (random(150, 750));
  359.         }
  360.  
  361.     private Image getImage(String url) {
  362.         try {
  363.                     return ImageIO.read(new URL(url));
  364.         } catch(IOException e) {
  365.                     return null;
  366.         }
  367.     }
  368.  
  369.     private final Color color1 = new Color(255, 255, 255);
  370.     private final Color color2 = new Color(204, 0, 0, 135);
  371.     private final Color color3 = new Color(51, 204, 0, 135);
  372.     private final Color color4 = new Color(0, 0, 0, 135);
  373.  
  374.     private final BasicStroke stroke1 = new BasicStroke(1);
  375.  
  376.     private final Font font1 = new Font("Arial", 1, 14);
  377.     private final Font font2 = new Font("Arial", 1, 12);
  378.     private final Font font3 = new Font("Arial", 0, 10);
  379.    
  380.     Rectangle tab1 = new Rectangle(496, 345, 30, 30);
  381.    
  382.     private final Image Simg = getImage("http://i52.tinypic.com/21jaich.png");
  383.     private final Image Himg = getImage("http://i56.tinypic.com/2502r28.png");
  384.    
  385.      public void mouseClicked(MouseEvent e){
  386.         if(tab1.contains(e.getPoint())){
  387.            showPaint = !showPaint;
  388.             }
  389.         }
  390.         public void mouseEntered(MouseEvent e){
  391.         }
  392.         public void mouseExited(MouseEvent e){
  393.         }
  394.         public void mouseReleased(MouseEvent e){
  395.         }
  396.         public void mousePressed(MouseEvent e){
  397.         }
  398.  
  399.     public void onRepaint(Graphics g1) {
  400.        
  401.                     millis = System.currentTimeMillis() - startTime;
  402.                     hours = millis / (1000 * 60 * 60);
  403.                     millis -= hours * (1000 * 60 * 60);
  404.                     minutes = millis / (1000 * 60);
  405.                     millis -= minutes * (1000 * 60);
  406.                     seconds = millis / 1000;
  407.  
  408.        
  409.                     currentExpC = skills.getCurrentExp(skills.CRAFTING);
  410.                     currentExpS = skills.getCurrentExp(skills.SMITHING);
  411.                     currentLvlC = skills.getCurrentLevel(skills.CRAFTING);
  412.                     expToLvlC = skills.getExpToNextLevel(Skills.CRAFTING);
  413.                     percentTNL = skills.getPercentToNextLevel(skills.CRAFTING);
  414.                    
  415.                     currentSystemTime = System.currentTimeMillis();
  416.                    
  417.                     lvlsGainedC = currentLvlC-startLvlC;
  418.                     expGainedC = currentExpC-startExpC;
  419.                     expGainedS = currentExpS-startExpS;
  420.                     expHourC = (int) ((expGainedC) * 3600000D / (currentSystemTime - startTime));
  421.                     tiarasHr = (int) ((tiarasHr) * 3600000D/ (System.currentTimeMillis() - startTime));
  422.                     tiaras = (int) ((currentExpC - startExpC) / tXP);
  423.                    
  424.         final int percentBar = (int) (skills.getPercentToNextLevel(Skills.CRAFTING)*5.16);
  425.                    
  426.                 if (sXP > 0) {
  427.                     STL = (int) (expToLvlC / sXP);
  428.         }
  429.         if (STL >= 60) {
  430.                     MTL = STL / 60;
  431.                     STL -= MTL * 60;
  432.         } else {
  433.                     MTL = 0;
  434.                 }
  435.         if (MTL >= 60) {
  436.                     HTL = MTL / 60;
  437.                     MTL -= HTL * 60;
  438.         } else {
  439.                     HTL = 0;
  440.         }
  441.                    
  442.                    
  443.     if (game.isLoggedIn() && !game.isWelcomeScreen()) {
  444.         Graphics2D g = (Graphics2D)g1;
  445.  
  446.     if (showPaint == false) {
  447.         g.drawImage(Simg, 496, 345, null);
  448.         }
  449.     if (showPaint == true) {
  450.         g.drawImage(Himg, 496, 345, null);
  451.         g.setColor(color1);
  452.         g.setStroke(stroke1);
  453.         g.setColor(color2);
  454.         g.fillRect(0, 480, 516, 27);
  455.         g.setColor(color3);
  456.         g.fillRect(0, 480, percentBar, 27);
  457.         g.setColor(color4);
  458.         g.fillRect(549, 312, 183, 150);
  459.         g.drawRect(549, 312, 183, 150);
  460.         g.setFont(font1);
  461.         g.setColor(color1);
  462.         g.drawString("Ministry Of Tiaras", 564, 330);
  463.         g.drawString( percentTNL +"%", 258, 498);
  464.         g.setFont(font2);
  465.         g.drawString("v" +update.version(), 693, 330);
  466.         g.drawString("Status : " + status , 564, 456);
  467.         g.setFont(font3);
  468.         g.drawString("Tiaras Crafted :     " +tiaras, 564, 348);
  469.         g.drawString("Tiaras p/hr :     " +tiarasHr, 564, 363);
  470.         g.drawString("Crafting Exp :     " + expGainedC, 564, 378);
  471.         g.drawString("Craft Exp p/hr :     " + expHourC, 564, 393);
  472.         g.drawString("Smithing Exp :     " + expGainedS, 564, 408);
  473.         g.drawString("Current Level :     " +currentLvlC + "(+" +lvlsGainedC +")", 564, 423);
  474.         g.drawString("Runtime :     " +hours + ":" + minutes + ":" + seconds, 564, 438);
  475.             }
  476.     if (clicked != null) {
  477.                     final int mx = (int)mouse.getLocation().getX();
  478.                     final int my = (int)mouse.getLocation().getY();
  479.  
  480.                     final long mpt = System.currentTimeMillis() - mouse.getPressTime();
  481.                 if (mouse.getPressTime() == -1 || mpt >= 300)
  482.                     g.drawImage(normal, mx - 10, my - 6, null);
  483.                 if (mpt < 300)
  484.                     g.drawImage(clicked, mx - 10, my - 6, null);
  485.             }
  486.         }
  487.     }
  488. }
Advertisement
Add Comment
Please, Sign In to add comment