Advertisement
joedezzy1

AutoAlcher

Jul 21st, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.03 KB | None | 0 0
  1. package scripts.autoAlcherPro;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.Rectangle;
  5.  
  6. import org.tribot.api.Clicking;
  7. import org.tribot.api.General;
  8. import org.tribot.api.Timing;
  9. import org.tribot.api2007.Skills;
  10. import org.tribot.api2007.Skills.SKILLS;
  11. import org.tribot.api.types.generic.Condition;
  12. import org.tribot.api2007.Game;
  13. import org.tribot.api2007.GameTab;
  14. import org.tribot.api2007.Magic;
  15. import org.tribot.api2007.Player;
  16. import org.tribot.api2007.GameTab.TABS;
  17. import org.tribot.api2007.Inventory;
  18. import org.tribot.api2007.WebWalking;
  19. import org.tribot.api2007.types.RSArea;
  20. import org.tribot.api2007.types.RSTile;
  21. import org.tribot.script.Script;
  22. import org.tribot.script.ScriptManifest;
  23. import org.tribot.script.interfaces.Painting;
  24.  
  25. @ScriptManifest(authors = { "JoeDezzy" }, category = "Magic", name = "AIO Walking Alcher")
  26. public class AutoAlcher extends Script implements Painting {
  27.    
  28.     public static boolean running = true; //main loop boolean
  29.    
  30.     public boolean canWalk = false; //user wants to walk or not
  31.     public boolean GUI_COMPLETE = false;
  32.        
  33.     public String ITEM_NAME; //item to alch
  34.    
  35.     public int walkTimeMin; //minimum amount of time to walk before alching
  36.     public int walkTimeMax; //maximum time
  37.  
  38.     private long nextWalkTime; //next valid walking time
  39.    
  40.     private BotState state;
  41.     private RSTile queuedCity; //city the bot is currently walking to
  42.     private AntiBan aban;
  43.        
  44.     public AutoAlcher(){}
  45.    
  46.     enum BotState {
  47.         CLICK_ALCH,
  48.         CLICK_ITEM,
  49.         OPEN_MAGEBOOK,
  50.         KILL,
  51.         NULL,
  52.         WALK
  53.     }
  54.    
  55.     @Override
  56.     public void run() {    
  57.         new GUI();     
  58.         while (!GUI_COMPLETE) sleep(200);                  
  59.         aban = new AntiBan();      
  60.         println("Welcome to JoeDezzy's walking autoAlcher!");
  61.        
  62.         while(running) {
  63.             state = getState();
  64.             aban.start();
  65.            
  66.             switch(state) {                                
  67.             case WALK:
  68.                 if (successfulWalk())
  69.                 nextWalkTime = System.currentTimeMillis()
  70.                     + (General.random(walkTimeMin, walkTimeMax) * 1000);
  71.                 break;             
  72.             case CLICK_ALCH:
  73.                 clickAlch();
  74.                 break;             
  75.             case OPEN_MAGEBOOK:
  76.                 GameTab.open(TABS.MAGIC);
  77.                 break;             
  78.             case CLICK_ITEM:
  79.                 clickItem();
  80.                 break;             
  81.             case KILL:
  82.                 running = false;               
  83.             case NULL:
  84.                 sleep(300);            
  85.             }          
  86.             sleep(400, 900);
  87.         }      
  88.     }
  89.  
  90.     private void setQuedCity() {   
  91.         //*
  92.         /* Sets a city to walk to if not
  93.          * already walking to a certain city.
  94.          * Using a static variable because the walker times
  95.          * out to alch in-between walking.
  96.          */
  97.         RSArea VARROCK_AREA = new RSArea(new RSTile(3179, 3449, 0), new RSTile(3282, 3382, 0));
  98.         RSArea FALADOR_AREA = new RSArea(new RSTile(2943, 3389, 0), new RSTile(3039, 3327, 0));
  99.         RSArea LUMBRIDGE_AREA = new RSArea(new RSTile(3200, 3244, 0), new RSTile(3264, 3197, 0));
  100.  
  101.         if (VARROCK_AREA.contains(Player.getPosition())) { 
  102.             println("Queded falador as next destination");
  103.             queuedCity = new RSTile(3004, 3358, 0);        
  104.         }  
  105.         else if (FALADOR_AREA.contains(Player.getPosition())) {
  106.             println("Queded lumbridge as next destination");
  107.             queuedCity = new RSTile(3248, 3234, 0);        
  108.         }
  109.         else if (LUMBRIDGE_AREA.contains(Player.getPosition())) {
  110.             println("Queded varrock as next destination");
  111.             queuedCity = new RSTile(3207, 3425, 0);        
  112.         }
  113.     }
  114.  
  115.     private boolean successfulWalk() {     
  116.         final long walkKill = System.currentTimeMillis() +  General.random(5000, 15000);       
  117.         setQuedCity();
  118.         return WebWalking.walkTo(queuedCity, new Condition() {     
  119.             @Override
  120.             public boolean active() {          
  121.                 return System.currentTimeMillis() > walkKill;
  122.             }          
  123.         }, 400);               
  124.     }
  125.    
  126.     private void clickItem() {             
  127.         if (Clicking.click(Inventory.find(ITEM_NAME))) {
  128.             Timing.waitCondition(new Condition(){
  129.                 @Override
  130.                 public boolean active() {
  131.                     return GameTab.getOpen().equals(TABS.MAGIC);
  132.                 }              
  133.             }, General.random(1200, 2200));    
  134.         }
  135.     }
  136.  
  137.     private void clickAlch() {     
  138.         if (Magic.selectSpell(Skills.getActualLevel(SKILLS.MAGIC) < 55 ? "Low Level Alchemy" : "High Level Alchemy")) {
  139.             Timing.waitCondition(new Condition(){
  140.                 @Override
  141.                 public boolean active() {
  142.                     return GameTab.getOpen().equals(TABS.INVENTORY);
  143.                 }          
  144.             }, General.random(1800, 2300));        
  145.         }
  146.     }
  147.  
  148.     private BotState getState() {      
  149.         if (canWalk && Player.getRSPlayer().getAnimation() <= -1 && System.currentTimeMillis() > nextWalkTime) {
  150.             //canWalk is if the user wants to walk
  151.             return BotState.WALK;
  152.         }
  153.         else if (Inventory.find(ITEM_NAME).length <= 0 || Inventory.find("Nature rune").length <= 0) {
  154.             //out of items
  155.             return BotState.KILL;
  156.         }
  157.         else if (!GameTab.getOpen().equals(TABS.MAGIC) && !Game.getUptext().contains("Cast")) {
  158.             return BotState.OPEN_MAGEBOOK;
  159.         }
  160.         else if (GameTab.getOpen().equals(TABS.MAGIC) && !Magic.isSpellSelected()) {
  161.             return BotState.CLICK_ALCH;
  162.         }
  163.         else if (GameTab.getOpen().equals(TABS.INVENTORY) && Game.getUptext().contains("Cast")) {
  164.             return BotState.CLICK_ITEM;
  165.         }      
  166.         return BotState.NULL;
  167.     }
  168.    
  169.     private long xpPerHour = 0;
  170.     private long timeRunning = 0;
  171.     private int alchsPerHour = 0;
  172.     private int startXp = 0;
  173.     private long startTime = 0;
  174.    
  175.     @Override
  176.     public void onPaint(Graphics g) {      
  177.         xpPerHour = (Skills.getXP(SKILLS.MAGIC) - startXp) / (timeRunning * 1000);
  178.         timeRunning = System.currentTimeMillis() - startTime;      
  179.         int seconds = (int) (timeRunning / 1000) % 60 ;
  180.         int minutes = (int) ((timeRunning / (1000*60)) % 60);
  181.         int hours   = (int) ((timeRunning / (1000*60*60)) % 24);       
  182.         Rectangle r = new Rectangle(300, 300);     
  183.         g.draw3DRect(50, 50, 200, 100, true);      
  184.         g.drawString("Time ran: " + (hours < 10  ? "0" : "") + hours
  185.                 + ":"  + (minutes < 10  ? "0" : "") + minutes
  186.                 + ":"  + (seconds < 10  ? "0" : "") + seconds,
  187.                 r.x + 20, r.y - 20);   
  188.         g.drawString("Alchs p/h: " + alchsPerHour, r.x + 20, r.y - 40);
  189.         g.drawString("Xp p/h: " + xpPerHour, r.x + 20, r.y - 60);      
  190.     }
  191.  
  192.     public void sendValues(boolean walking, int min, int max, String item) {
  193.         this.canWalk = walking;
  194.         this.walkTimeMin = min;
  195.         this.walkTimeMax = max;
  196.         this.ITEM_NAME = item;     
  197.     }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement