NissanNut

Superheater.java 0.3

Nov 29th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.10 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Graphics2D;
  4. import java.awt.Point;
  5. import java.awt.Rectangle;
  6. import java.util.ArrayList;
  7.  
  8. import org.veloxbot.api.ActiveScript;
  9. import org.veloxbot.api.Manifest;
  10. import org.veloxbot.api.Validatable;
  11. import org.veloxbot.api.methods.Bank;
  12. import org.veloxbot.api.methods.Bank.Slot;
  13. import org.veloxbot.api.methods.Game;
  14. import org.veloxbot.api.methods.Inventory;
  15. import org.veloxbot.api.methods.Keyboard;
  16. import org.veloxbot.api.methods.Log;
  17. import org.veloxbot.api.methods.Magic;
  18. import org.veloxbot.api.methods.Menu;
  19. import org.veloxbot.api.methods.Mouse;
  20. import org.veloxbot.api.methods.OCR;
  21. import org.veloxbot.api.utils.Random;
  22. import org.veloxbot.api.wrappers.DTM;
  23.  
  24. @Manifest(authors = { "Nissan Nut", "Velox" },
  25.     name = "Nissan's Superheater",
  26.     version = 0.3,
  27.     description= "BETA: Basic Superheater.")
  28.  
  29. /**
  30. * Simple Superheater Script
  31. * 11/10/2012 Dev Started
  32. * @author Tanner (Nissan Nut)
  33. */
  34.  
  35. public class Superheater extends ActiveScript{
  36.    
  37.     private ArrayList<Strategy> tasks = new ArrayList<Strategy>();
  38.     private SuperheaterUI UI = new SuperheaterUI();
  39.     private boolean antiban = true;
  40.     private int widthdraw = 0, angle, mouseSpeed, heats = 0, startExp, exp;
  41.     private long START_TIME;
  42.     private String status;
  43.    
  44.     private DTM ore, ore2, bar;
  45.     private final DTM NATURE_RUNE = DTM.fromString("17_123_20_5/103_99_98_-11_-5_5/74_71_71_-2_10_5/147_140_140_9_-3_5"),
  46.             COAL = DTM.fromString("38_38_29_5/92_74_52_-12_2_5/92_74_52_-3_8_5/38_38_29_8_5_5/105_84_59_10_-5_5"),
  47.             IRON_ORE = DTM.fromString("54_32_24_5/86_69_48_-13_3_5/94_76_53_-3_10_5/54_32_24_7_6_5/103_82_57_10_-4_5"),
  48.             MITHRIL_ORE = DTM.fromString("54_55_81_5/100_81_57_-11_3_5/90_72_51_-5_10_5/46_46_69_7_5_5/109_87_61_11_-6_5"),
  49.             ADAMANTITE_ORE = DTM.fromString("64_74_64_5/98_79_56_-11_2_5/92_74_52_-5_11_5/62_71_62_8_6_5/109_87_61_11_-5_5"),
  50.             RUNITE_ORE = DTM.fromString("71_85_92_5/87_70_49_-15_3_5/98_79_56_-5_10_5/55_66_71_7_5_5/105_84_59_9_-6_5"),
  51.             GOLD_ORE = DTM.fromString("190_151_28_5/98_79_56_-11_2_5/87_70_49_-7_10_5/172_137_25_7_6_5/100_81_57_11_-4_5"),
  52.             SILVER_ORE = DTM.fromString("126_127_132_5/95_76_52_-11_4_5/91_72_50_-3_11_5/103_82_57_12_-4_1"),
  53.             COPPER_ORE = DTM.fromString("189_108_57_5/97_77_54_-10_1_5/91_72_50_-4_7_5/105_84_58_10_-6_5"),
  54.             TIN_ORE = DTM.fromString("105_101_101_5/82_65_45_-14_4_5/97_77_54_-3_10_5/99_79_55_12_-4_5"),
  55.             BRONZE_BAR = DTM.fromString("79_59_35_5/59_45_26_-8_-2_5/33_25_14_-13_5_5/81_61_36_-1_6_5"),
  56.             IRON_BAR = DTM.fromString("83_80_80_5/39_38_38_-14_5_5/26_25_25_-14_11_5/86_82_82_-1_7_5"),
  57.             STEEL_BAR = DTM.fromString("128_123_123_5/99_95_94_-8_1_5/39_38_38_-15_11_5/132_127_126_-1_8_5"),
  58.             MITHRIL_BAR = DTM.fromString("66_66_99_5/49_50_74_-8_-3_5/28_29_43_-10_5_5/67_68_101_0_4_5"),
  59.             ADAMANT_BAR = DTM.fromString("72_83_72_5/53_62_54_-7_1_5/28_33_29_-13_6_5/72_83_72_-1_7_5"),
  60.             RUNE_BAR = DTM.fromString("81_97_105_5/62_75_81_-7_1_5/37_45_48_-11_7_5/82_99_107_0_6_5"),
  61.             SILVER_BAR = DTM.fromString("165_165_172_5/128_128_134_-9_-1_5/75_75_79_-15_3_5/168_168_176_-1_6_5"),
  62.             GOLD_BAR = DTM.fromString("207_165_29_5/159_126_22_-8_-2_5/90_72_13_-11_4_5/212_169_30_0_6_5");
  63.  
  64.     @Override
  65.     public boolean onStart(){
  66.         Log.log(this.manifest.name() + " v" + this.manifest.version() + " by " + this.manifest.authors()[0] + " + " + this.manifest.authors()[1]);
  67.         status = "Start-up";
  68.         UI.setVisible(true);
  69.        
  70.         while (UI.isVisible())
  71.             sleep(10);
  72.        
  73.         switch (UI.list.getSelectedIndex()){
  74.         case 0:
  75.             ore = TIN_ORE;
  76.             ore2 = COPPER_ORE;
  77.             bar = BRONZE_BAR;
  78.             widthdraw = 13;
  79.             break;
  80.         case 1:
  81.             ore = IRON_ORE;
  82.             bar = IRON_BAR;
  83.             break;
  84.         case 2:
  85.             ore = IRON_ORE;
  86.             ore2 = COAL;
  87.             bar = STEEL_BAR;
  88.             widthdraw = 9;
  89.             break;
  90.         case 3:
  91.             ore = SILVER_ORE;
  92.             bar = SILVER_BAR;
  93.             break;
  94.         case 4:
  95.             ore = GOLD_ORE;
  96.             bar = GOLD_BAR;
  97.             break;
  98.         case 5:
  99.             ore = MITHRIL_ORE;
  100.             ore2 = COAL;
  101.             bar = MITHRIL_BAR;
  102.             widthdraw = 6;
  103.             break;
  104.         case 6:
  105.             ore = ADAMANTITE_ORE;
  106.             ore2 = COAL;
  107.             bar = ADAMANT_BAR;
  108.             widthdraw = 5;
  109.             break;
  110.         case 7:
  111.             ore = RUNITE_ORE;
  112.             ore2 = COAL;
  113.             bar = RUNE_BAR;
  114.             widthdraw = 4;
  115.         }
  116.        
  117.         if (UI.boxNorth.isSelected())
  118.             angle = 0;
  119.         else if (UI.boxEast.isSelected())
  120.             angle = 90;
  121.         else if (UI.boxSouth.isSelected())
  122.             angle = 180;
  123.         else if (UI.boxWest.isSelected())
  124.             angle = 270;
  125.    
  126.         mouseSpeed = UI.slider.getValue();
  127.        
  128.         tasks.add(new Banking());
  129.         tasks.add(new Superheat());
  130.        
  131.         START_TIME = System.currentTimeMillis();
  132.         return UI.start;
  133.     }
  134.    
  135.     @Override
  136.     public long loop() {
  137.         if (antiban)
  138.             Mouse.setMultiplier(Random.nextDouble(mouseSpeed - 1, mouseSpeed + 1)*.1);
  139.        
  140.         for(Strategy s : tasks){
  141.             if (s.validate()){
  142.                 s.run();
  143.                 Log.log(s.getStatus());
  144.             }
  145.         }
  146.        
  147.         return 15;
  148.     }
  149.    
  150.  
  151.    
  152.     @Override
  153.     public void onRepaint(Graphics G){
  154.         Graphics2D g = (Graphics2D) G;
  155.    
  156.         g.setColor(Color.BLACK);
  157.         g.fillRect(0, 0, 765, 50);
  158.        
  159.         g.setColor(Color.WHITE);
  160.         g.drawString("Nissan's Superheater... Runtime: " + toString(getRuntime()) + "... Approx heats: " + heats, 15, 20);
  161.         g.drawString("Please post and describe all bugs on the forums, script is in testing stages, all feedback is appreciated.", 15, 40);
  162.  
  163.        
  164.        
  165.     }
  166.    
  167.     /**
  168.      * Credits to Velox
  169.      * @param angle
  170.      * @param distance
  171.      * @return the point
  172.      */
  173.     public static Point getPointNearPlayer(final int angle, final int distance) {
  174.          final double rads = Math.toRadians(angle + 90 - Game.getCompassAngle());
  175.          return new Point((int) (Game.VIEWPORT_CENTER.x - distance * Math.cos(rads)), (int) (Game.VIEWPORT_CENTER.y - distance * Math.sin(rads)));
  176.     }
  177.  
  178.    
  179.     private class Banking extends Strategy{
  180.         final Rectangle BOUNDS = new Rectangle(23, 135, 472, 208);
  181.        
  182.         public void run(){
  183.            
  184.             for (int i = 0; i < 5 && !Bank.isOpen(); i++){
  185.                 i++;
  186.                 final Point LOCATION =  getPointNearPlayer(angle + Random.nextInt(-5, 5), 30 + Random.nextInt(-2, 2));
  187.                 Mouse.click(LOCATION, false);
  188.                 sleep(750, 1500);
  189.                 Menu.clickIndex(0);
  190.                 sleep(1500, 2000);
  191.             }
  192.            
  193.             deposit(bar);
  194.             sleep(500, 800);
  195.            
  196.             if (Inventory.getCount() > 1){
  197.                 for (Inventory.Slot s : Inventory.Slot.values()){
  198.                     if (!s.isEmpty() && !s.contains(NATURE_RUNE)){
  199.                         deposit(s);
  200.                         sleep(500, 800);
  201.                     }
  202.                 }
  203.             }
  204.            
  205.             withdrawTemp(ore, widthdraw);
  206.            
  207.             if (ore2 != null){
  208.                 withdrawTemp(ore2, 0);
  209.                 sleep(1000, 1500);
  210.             }
  211.  
  212.             if (new Failsafe().validate()){
  213.                 new Failsafe().run();
  214.             }
  215.            
  216.             Bank.close();
  217.         }
  218.        
  219.         private void deposit(Inventory.Slot s) {
  220.             if (s != null){
  221.                 Mouse.click(new Point((int) s.getBounds().getCenterX(), (int) s.getBounds().getCenterY()), false);
  222.                 sleep(1000, 1500);
  223.                 if (Menu.isOpen()){
  224.                     Menu.clickIndex(5);
  225.                 }
  226.             }
  227.            
  228.         }
  229.  
  230.         private void deposit(DTM bar) {
  231.             deposit(Inventory.getSlotWith(bar));
  232.         }
  233.  
  234.         @Override
  235.         public boolean validate() {
  236.             if (Game.Tab.INVENTORY.isOpen())
  237.                 return Inventory.getCount(bar) >= widthdraw || Inventory.getCount() == 1;
  238.             return false;
  239.         }
  240.  
  241.         @Override
  242.         public String getStatus() {
  243.             return "Banking";
  244.         }
  245.        
  246.         public Bank.Slot[] getSlotsWithDTM(final DTM d){
  247.             ArrayList<Bank.Slot> slots = new ArrayList<Bank.Slot>();
  248.             for (Point p : d.getAll(BOUNDS)){
  249.                 for (Bank.Slot s : Bank.Slot.values()){
  250.                     if (s.getBounds().contains(p)){
  251.                         slots.add(s);
  252.                     }
  253.                 }  
  254.             }
  255.             return (Slot[]) slots.toArray();
  256.            
  257.         }
  258.        
  259.         public Bank.Slot getSlotWithDTM(final DTM d){
  260.             for (Point p : d.getAll(BOUNDS)){
  261.                 for (Bank.Slot s : Bank.Slot.values()){
  262.                     if (s.getBounds().contains(p)){
  263.                         return s;
  264.                     }
  265.                 }  
  266.             }
  267.             return null;
  268.            
  269.         }
  270.        
  271.         public void withdrawTemp(final DTM d, final Integer num){
  272.             Slot s = getSlotWithDTM(d);
  273.            
  274.             if (s != null){
  275.                 Mouse.click(s.getBounds(), false);
  276.                 sleep(1250, 1750);
  277.             }
  278.                
  279.             if (num == 0){
  280.                 Menu.clickIndex(Random.nextInt(5, 6));
  281.             } else{
  282.                 Menu.clickIndex(4);
  283.                 sleep(1250, 1750);
  284.                 Keyboard.sendString(num.toString());
  285.             }
  286.            
  287.         }
  288.        
  289.         public void withdraw(final DTM d, final Integer num){
  290.             Slot s = getSlotWithDTM(d);
  291.            
  292.             if (s != null){
  293.                 Mouse.click(s.getBounds(), false);
  294.                 sleep(1250, 1750);
  295.             }
  296.                
  297.             if (num == 0){
  298.                 Menu.interact("Withdraw-All");
  299.             } else{
  300.                 if (!Menu.interact("Withdraw-" + num)){
  301.                     Menu.interact("Withdraw-X", true);
  302.                     sleep(1250, 1750);
  303.                     Keyboard.sendString(num.toString());
  304.                 }
  305.             }
  306.            
  307.         }
  308.        
  309.         private class Failsafe extends Strategy{
  310.  
  311.             @Override
  312.             public boolean validate() {
  313.                 return !((Inventory.getCount(ore) == widthdraw || widthdraw == 0) && Inventory.isFull());
  314.             }
  315.  
  316.             @Override
  317.             public void run() {
  318.                 deposit(ore);
  319.                 if (ore2 != null)
  320.                     deposit(ore2);
  321.             }
  322.  
  323.             @Override
  324.             public String getStatus() {
  325.                 return "Checking Inventory";
  326.             }
  327.            
  328.         }
  329.        
  330.     }
  331.    
  332.     private class Superheat extends Strategy{
  333.         private final DTM SUPERHEAT_ITEM = DTM.fromString("232_117_45_5/250_180_71_-7_13_5/236_125_119_3_13_5");
  334.         private final DTM MAGIC = DTM.fromString("26_54_97_3/19_19_19_-1_-13_3/10_24_60_11_-14_3/46_59_75_17_-1_3");
  335.         private final DTM MAGIC_SELECTED = DTM.fromString("24_50_121_3/50_50_50_-3_-13_3/50_50_50_17_-12_3/54_26_85_16_0_3");
  336.         private final DTM SKILLS = DTM.fromString("180_144_42_3/201_151_42_0_19_3/32_101_50_13_17_3/99_114_132_13_2_3/18_18_18_7_6_3");
  337.         private final DTM SKILLS_SELECTED = DTM.fromString("201_151_42_3/201_151_42_0_18_3/32_101_50_14_15_3/101_112_126_14_0_3/20_184_253_23_-8_3/69_69_69_-8_21_3");
  338.         private String status = "Superheating";
  339.         private ArrayList<Strategy> tasks = new ArrayList<Strategy>();
  340.        
  341.        
  342.         public void run(){     
  343.             this.tasks.add(new Heat());
  344.             this.tasks.add(new ClickOre());
  345.            
  346.             for(Strategy s : this.tasks){
  347.                 if (s.validate()){
  348.                     s.run();
  349.                     status = s.getStatus();
  350.                 }
  351.             }
  352.         }
  353.  
  354.         @Override
  355.         public boolean validate() {
  356.             if (Game.Tab.INVENTORY.isOpen())
  357.                 return Inventory.getCount(bar) <= widthdraw;
  358.             return true;
  359.         }
  360.  
  361.         @Override
  362.         public String getStatus() {
  363.             return status;
  364.         }
  365.        
  366.         private class ClickOre extends Strategy{
  367.  
  368.             @Override
  369.             public boolean validate() {
  370.                 return Game.Tab.INVENTORY.isOpen();
  371.             }
  372.  
  373.             @Override
  374.             public void run() {
  375.                 String s = OCR.getUptext();
  376.                 if (s.contains("Cast") || s.contains("Super") || s.contains("Item")){
  377.                     Inventory.Slot s1 = Inventory.getSlotWith(ore);
  378.                     if (s1 != null){
  379.                         s1.click(true);
  380.                         heats++;
  381.                         sleep(500, 1000);
  382.                     } else if (Inventory.getCount(bar) >= widthdraw || Inventory.getCount(ore) <= 0){
  383.                         Mouse.click(Magic.BOUNDS, true);
  384.                         new Banking().run();
  385.                     }
  386.                    
  387.                 } else {
  388.                     Game.Tab.MAGIC.open(false);
  389.                     sleep(250, 750);
  390.                 }
  391.             }
  392.  
  393.             @Override
  394.             public String getStatus() {
  395.                 return "Clicking Ore";
  396.             }
  397.            
  398.         }
  399.        
  400.         private class Heat extends Strategy{
  401.  
  402.             @Override
  403.             public boolean validate() {
  404.                 return Game.Tab.MAGIC.isOpen();
  405.             }
  406.  
  407.             @Override
  408.             public void run() {
  409.                 Point p = SUPERHEAT_ITEM.getFirst(Magic.BOUNDS);
  410.                 if (p != null){
  411.                     Mouse.click(p, true);
  412.                 }else{
  413.                     Point p3 = MAGIC.getFirst(Magic.BOUNDS);
  414.                     if (p3 != null){
  415.                         Mouse.click(p3, true);
  416.                         sleep(250, 500);
  417.                     }
  418.                     Point p4 = SKILLS.getFirst(Magic.BOUNDS);
  419.                     if (p4!= null)
  420.                         Mouse.click(p4, true); 
  421.                 }
  422.                 sleep(250, 750);
  423.             }
  424.  
  425.             @Override
  426.             public String getStatus() {
  427.                 return "Clicking Superheat";
  428.             }
  429.            
  430.         }
  431.        
  432.     }
  433.    
  434.     abstract class Strategy implements Validatable{
  435.         public Strategy() {}
  436.    
  437.         public abstract void run();
  438.         public abstract String getStatus();
  439.     }
  440.    
  441.     private Long getRuntime(){
  442.         return System.currentTimeMillis() - START_TIME;
  443.     }
  444.    
  445.     /**
  446.      * Converts milliseconds to readable time in a string.
  447.      * @param ms The time in milliseconds.
  448.      * @return the time as a string <tt>0:0:0</tt>
  449.      */
  450.     public static String toString(final Long ms){
  451.         long s = ms/1000;
  452.         long sec = s % 60;
  453.         long min = (s % 3600) / 60;
  454.         long hrs = s / 3600;
  455.         return hrs + ":" + min + ":" + sec;
  456.     }
  457.  
  458. }
Advertisement
Add Comment
Please, Sign In to add comment