Advertisement
Aleksander

AeroShield

May 3rd, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.76 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.*;
  4.  
  5. import org.tribot.api.Timing;
  6. import org.tribot.api.types.generic.Condition;
  7. import org.tribot.api2007.GameTab;
  8. import org.tribot.api2007.Interfaces;
  9. import org.tribot.api2007.Inventory;
  10. import org.tribot.api2007.Objects;
  11. import org.tribot.api2007.Player;
  12. import org.tribot.api2007.Walking;
  13. import org.tribot.api2007.GameTab.TABS;
  14. import org.tribot.api2007.types.RSInterfaceChild;
  15. import org.tribot.api2007.types.RSItem;
  16. import org.tribot.api2007.types.RSObject;
  17. import org.tribot.api2007.types.RSTile;
  18. import org.tribot.script.Script;
  19. import org.tribot.script.interfaces.Painting;
  20.  
  21. public class AeroShield extends Script implements Painting {
  22.    
  23.     public static SleepCondition Skip;
  24.     public static Double Version = 1.1;
  25.    
  26.     private int completed = 0;
  27.     private State currentState = null;
  28.    
  29.     public enum State {
  30.         Stab(15617, 1),
  31.         Blunt(15619, 2),
  32.         Slash(15620, 3),
  33.         Magic(15618, 4);
  34.        
  35.         private int Id, ChildId;
  36.        
  37.         State(int ObjectId, int Child) {
  38.             Id = ObjectId;
  39.             ChildId = Child;
  40.         }
  41.        
  42.         public int getObjectId() {
  43.             return Id;
  44.         }
  45.        
  46.         public int getChild() {
  47.             return ChildId;
  48.         }
  49.     }
  50.  
  51.     public class SleepCondition {
  52.         Condition C;
  53.         Integer Timeout;
  54.  
  55.         SleepCondition(Condition c, Integer timeout) {
  56.             C = c;
  57.             Timeout = timeout;
  58.         }
  59.     }
  60.  
  61.     private final Color color1 = new Color(0, 0, 0, 130);
  62.     private final Color color2 = new Color(0, 0, 0);
  63.     private final Color color3 = new Color(255, 255, 255);
  64.  
  65.     private final BasicStroke stroke1 = new BasicStroke(1);
  66.  
  67.     private final Font font1 = new Font("Arial", 0, 16);
  68.     private final Font font2 = new Font("Arial", 0, 11);
  69.    
  70.     @Override
  71.     public void onPaint(Graphics arg0) {
  72.         if (getRunningTime() == 0 || currentState == null)
  73.             return;
  74.         Integer hourRate = (int) (completed * 3600000 / (getRunningTime()));
  75.         String TimeRun = Timing.msToString(getRunningTime()),
  76.                 Completed = String.format("%d (%d/HR)", completed, hourRate),
  77.                 State = currentState.toString();
  78.         Graphics2D g = (Graphics2D)arg0;
  79.         g.setColor(color1);
  80.         g.fillRect(351, 350, 138, 95);
  81.         g.setColor(color2);
  82.         g.setStroke(stroke1);
  83.         g.drawRect(351, 350, 138, 95);
  84.         g.setFont(font1);
  85.         g.drawString("AeroShield", 380, 374);
  86.         g.setColor(color3);
  87.         g.drawString("AeroShield", 379, 373);
  88.         g.setFont(font2);
  89.         g.setColor(color2);
  90.         g.drawString(Completed, 417, 396);
  91.         g.setColor(color3);
  92.         g.drawString(Completed, 416, 395);
  93.         g.drawString("Completed:", 357, 395);
  94.         g.drawString("State:", 357, 413);
  95.         g.setColor(color2);
  96.         g.drawString(State, 391, 414);
  97.         g.setColor(color3);
  98.         g.drawString(State, 390, 413);
  99.         g.drawString("Run Time:", 357, 430);
  100.         g.setColor(color2);
  101.         g.drawString(TimeRun, 410, 431);
  102.         g.setColor(color3);
  103.         g.drawString(TimeRun, 409, 430);
  104.     }
  105.  
  106.     @Override
  107.     public void run() {
  108.         Skip = new SleepCondition(new Condition() {
  109.             @Override
  110.             public boolean active() {
  111.                 return true;
  112.             }
  113.         }, 1);
  114.         println("AeroShield, you are running version " + Version + ".");
  115.         println("Please remember to reguarly check for updates on the thread and post feedback.");
  116.         while (true) {
  117.             SleepCondition result = loop();
  118.             Timing.waitCondition(result.C, result.Timeout);
  119.         }
  120.     }
  121.  
  122.     public SleepCondition loop() {
  123.         SleepCondition resultCondition = Skip;
  124.         if (Player.getPosition().distanceTo(new RSTile(2842, 3545, 1)) > 0) {
  125.             Walking.walkTo(new RSTile(2842, 3545, 1));
  126.         } else if (!hasShield()) {
  127.             if (GameTab.getOpen() != TABS.INVENTORY) {
  128.                 GameTab.open(TABS.INVENTORY);
  129.             }
  130.             if (Inventory.find(8856)[0].click("Wield"))  {
  131.                 resultCondition = new SleepCondition(new Condition() {
  132.                     @Override
  133.                     public boolean active() {
  134.                         return Inventory.find(8856).length == 0;
  135.                     }
  136.                 }, 4000);
  137.             }
  138.         } else {
  139.             for (final State state : State.values()) {
  140.                 final RSObject[] objects = Objects.find(30, state.getObjectId());
  141.                 if (objects.length > 0) {
  142.                     RSInterfaceChild interfaceChild = Interfaces.get(411, state.getChild());
  143.                     if (interfaceChild != null) {
  144.                         if (interfaceChild.click("Ok")) {
  145.                             currentState = state;
  146.                             completed++;
  147.                             resultCondition = new SleepCondition(new Condition() {
  148.                                 @Override
  149.                                 public boolean active() {
  150.                                     return Objects.find(30, state.getObjectId()).length == 0;
  151.                                 }
  152.                             }, 4000);
  153.                         }
  154.                     }
  155.                     break;
  156.                 }
  157.             }
  158.         }
  159.         return resultCondition;
  160.     }
  161.  
  162.     private boolean hasShield() {
  163.         RSInterfaceChild equip = Interfaces.get(387, 28);
  164.         if(equip != null){
  165.             RSItem[] items = equip.getItems();
  166.             for(RSItem item : items) {
  167.                 if (item.getID() == 8856) {
  168.                     return true;
  169.                 }
  170.             }
  171.         }
  172.         return false;
  173.     }
  174.    
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement