Advertisement
Guest User

Untitled

a guest
Feb 27th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.19 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.*;
  4. import java.util.*;
  5.  
  6. import org.tribot.api.*;
  7. import org.tribot.api.input.*;
  8. import org.tribot.api2007.*;
  9. import org.tribot.api2007.Objects;
  10. import org.tribot.api2007.types.*;
  11. import org.tribot.script.interfaces.*;
  12. import org.tribot.script.*;
  13.  
  14. @ScriptManifest(authors = { "Deluxes" }, category = "Runecrafting", name = "DeluxesAIRMaster", description = "Takes essence from slaves and crafts into air runs. Start inside air altar.")
  15.  
  16.  
  17. public class DeluxeAIRMaster extends Script implements Painting
  18. {
  19.     RSObject altar;
  20.     public String[] slaveNames = new String[] { };
  21.     String state = "";
  22.     @Override
  23.     public void onPaint(Graphics g)
  24.     {
  25.         Graphics2D g1 = (Graphics2D)g;
  26.         g1.drawString("STATE: " + state, 236, 225);
  27.     }
  28.    
  29.     @Override
  30.     public void run()
  31.     {
  32.         while (true)
  33.             loop();
  34.     }
  35.    
  36.     void loop()
  37.     {
  38.         if (Login.getLoginState().equals(Login.STATE.INGAME))
  39.         {
  40.             int timeout = 0;
  41.             if (altar == null)
  42.             {
  43.                 RSObject[] objs = Objects.findNearest(10, "Altar");
  44.                 if (objs.length > 0)
  45.                 {
  46.                     altar = objs[0];
  47.                 }
  48.                 else
  49.                     General.println("No altar found?");
  50.             }
  51.            
  52.             if (Player.getRSPlayer().isInCombat())
  53.             {
  54.                 RSObject[] portal = Objects.findNearest(25, "Portal");
  55.                 if (portal.length > 0)
  56.                 {
  57.                     portal[0].click("Leave", "Exit", "Use", "Enter");
  58.                     do
  59.                     {
  60.                         General.sleep(100);
  61.                         if (!Player.isMoving())
  62.                             timeout++;
  63.                     } while (timeout < 25 && DeluxesAIRSlave.inAltar());
  64.                     timeout = 0;
  65.                 }
  66.             }
  67.            
  68.             if (Inventory.isFull() && altar != null)
  69.             {
  70.                 state = "Crafting runes";
  71.                 altar.click("Craft-rune");
  72.                 while (Inventory.isFull() && timeout < 25)
  73.                 {
  74.                     General.sleep(100);
  75.                     timeout++;
  76.                 }
  77.             }
  78.             else
  79.             {
  80.                 state = "Waiting for slaves";
  81.                 RSPlayer[] players = Players.getAll();
  82.                 boolean found = false;
  83.                 for (RSPlayer player : players)
  84.                 {
  85.                     if (!found)
  86.                     {
  87.                         for (String slave : slaveNames)
  88.                         {
  89.                             if (slave.equals(player.getName()))
  90.                             {
  91.                                 state = "Slave is here, trading";
  92.                                 player.hover();
  93.                                 Mouse.click(3);
  94.                                 while (!ChooseOption.isOpen() && timeout < 10)
  95.                                 {
  96.                                     General.sleep(100);
  97.                                     timeout++;
  98.                                 }
  99.                                 timeout = 0;
  100.                                 String[] choice = ChooseOption.getOptions();
  101.                                 if (choice.length > 0)
  102.                                 {
  103.                                     for (String trade : choice)
  104.                                     {
  105.                                         if (trade.contains("Trade") && trade.contains(slave))
  106.                                             ChooseOption.select(trade);
  107.                                     }
  108.                                    
  109.                                     while (ChooseOption.isOpen() && timeout < 10)
  110.                                     {
  111.                                         General.sleep(100);
  112.                                         timeout++;
  113.                                     }
  114.                                     timeout = 0;
  115.                                     while (Interfaces.get(335) == null && Interfaces.get(334) == null && timeout < 50)
  116.                                     {
  117.                                         General.sleep(100);
  118.                                         timeout++;
  119.                                     }
  120.                                     timeout = 0;
  121.                                     if (Interfaces.get(335) != null || Interfaces.get(334) != null)
  122.                                     {
  123.                                         state = "Waiting for items";
  124.                                         while ((Interfaces.get(335) != null || Interfaces.get(334) != null))
  125.                                         {
  126.                                             state = "Accepting trades.";
  127.                                             if(Interfaces.get(335) != null)  {
  128.                                                 Interfaces.get(335).getChild(17).click("Accept");
  129.                                             } else if(Interfaces.get(334) != null) {
  130.                                                 Interfaces.get(334).getChild(20).click("Accept");
  131.                                             }
  132.                                             General.sleep(1000);
  133.                                         }
  134.                                     }
  135.                                 }
  136.                             }
  137.                         }
  138.                     }
  139.                 }
  140.             General.sleep(500);
  141.             }
  142.         }
  143.     }
  144. }
  145.  
  146. //Start of Master Script
  147. package scripts;
  148.  
  149. import java.awt.*;
  150. import java.util.*;
  151.  
  152. import org.tribot.api.*;
  153. import org.tribot.api.input.*;
  154. import org.tribot.api2007.*;
  155. import org.tribot.api2007.Objects;
  156. import org.tribot.api2007.types.*;
  157. import org.tribot.script.interfaces.*;
  158. import org.tribot.script.*;
  159.  
  160. @ScriptManifest(authors = { "Deluxes" }, category = "Runecrafting", name = "DeluxesAIRSlave", description = "Runs essence to its master in the air altar. Start with air tiara in falador bank to begin.")
  161.  
  162. public class DeluxesAIRSlave extends Script implements Painting, MessageListening07
  163. {
  164.     public static RSTile[] path = DeluxeUtil.CreatePath(new RSTile(3012, 3357), new RSTile(3007, 3354), new RSTile(3007, 3343), new RSTile(3007, 3332), new RSTile(3007, 3322), new RSTile(3000, 3314), new RSTile(2997, 3305), new RSTile(2992, 3298), new RSTile(2988, 3292));
  165.     public static int ESS_TYPE = 7936; //7936, 1436
  166.     public static boolean gotTrade = false;
  167.     public static String masterName = "";
  168.     public static boolean endScript = false;
  169.     ArrayList<Node> nodes = new ArrayList<>();
  170.     public static String state = "";
  171.    
  172.     public DeluxeSlaveGUI gui = new DeluxeSlaveGUI();
  173.    
  174.     @Override
  175.     public void onPaint(Graphics g)
  176.     {
  177.         Graphics2D g1 = (Graphics2D)g;
  178.         g1.drawString("STATE: " + state, 236, 225);
  179.     }
  180.    
  181.     @Override
  182.     public void run()
  183.     {
  184.         gui.setVisible(true);
  185.         while (gui.isVisible())
  186.             sleep(500);
  187.        
  188.         General.println(masterName);
  189.         Collections.addAll(nodes, new DeluxesAIRSlaveBankNode(), new DeluxesAIRSlaveAltarNode());
  190.         Walking.setControlClick(true);
  191.         Walking.setWalkingTimeout(1000);
  192.         Mouse.setSpeed(175);
  193.        
  194.         loop(40, 50);
  195.     }
  196.    
  197.     public static boolean inAltar()
  198.     {
  199.         RSObject[] altar = Objects.findNearest(25, "Altar");
  200.         return altar.length > 0;
  201.     }
  202.    
  203.     public static boolean atEntrance()
  204.     {
  205.         return Player.getPosition().distanceTo(path[path.length - 1].getPosition()) < 5;
  206.     }
  207.    
  208.     public static boolean inBank()
  209.     {
  210.         //General.println(Player.getPosition().distanceTo(path[0].getPosition()));
  211.         return Player.getPosition().distanceTo(path[0].getPosition()) < 5;
  212.     }
  213.    
  214.     void loop(int min, int max)
  215.     {
  216.         while (true)
  217.         {
  218.             for (final Node node : nodes)
  219.             {
  220.                 if (endScript)
  221.                     return;
  222.                 if (node.validate())
  223.                 {
  224.                     node.execute();
  225.                     sleep(min, max);
  226.                 }
  227.             }
  228.         }
  229.     }
  230.  
  231.     @Override
  232.     public void clanMessageReceived(String arg0, String arg1) {
  233.         // TODO Auto-generated method stub
  234.        
  235.     }
  236.  
  237.     @Override
  238.     public void personalMessageReceived(String arg0, String arg1) {
  239.         // TODO Auto-generated method stub
  240.        
  241.     }
  242.  
  243.     @Override
  244.     public void playerMessageReceived(String arg0, String arg1) {
  245.         // TODO Auto-generated method stub
  246.        
  247.     }
  248.  
  249.     @Override
  250.     public void serverMessageReceived(String arg0) {
  251.         // TODO Auto-generated method stub
  252.        
  253.     }
  254.  
  255.     @Override
  256.     public void tradeRequestReceived(String arg0) {
  257.         // TODO Auto-generated method stub
  258.         if (arg0.equalsIgnoreCase(masterName))
  259.             gotTrade = true;
  260.     }
  261.    
  262.     class DeluxeSlaveGUI extends javax.swing.JFrame
  263.     {
  264.         private javax.swing.JButton jButton1;
  265.         private javax.swing.JLabel jLabel1;
  266.         public javax.swing.JTextField jTextField1;
  267.         /**
  268.          * Creates new form DeluxeSlaveGUI
  269.          */
  270.         public DeluxeSlaveGUI() {
  271.             initComponents();
  272.         }
  273.        
  274.         private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {                                        
  275.             DeluxesAIRSlave.masterName = jTextField1.getText();
  276.             super.dispose();
  277.         }
  278.  
  279.         /**
  280.          * This method is called from within the constructor to initialize the form.
  281.          * WARNING: Do NOT modify this code. The content of this method is always
  282.          * regenerated by the Form Editor.
  283.          */
  284.         @SuppressWarnings("unchecked")
  285.         // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  286.         private void initComponents() {
  287.  
  288.             jLabel1 = new javax.swing.JLabel();
  289.             jTextField1 = new javax.swing.JTextField();
  290.             jButton1 = new javax.swing.JButton();
  291.  
  292.             setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  293.  
  294.             jLabel1.setText("Master Name:");
  295.  
  296.             jTextField1.setName("masterName"); // NOI18N
  297.  
  298.             jButton1.setLabel("Start");
  299.            
  300.             jButton1.addActionListener(new java.awt.event.ActionListener() {
  301.                 public void actionPerformed(java.awt.event.ActionEvent evt) {
  302.                     startButtonActionPerformed(evt);
  303.                 }
  304.             });
  305.  
  306.             javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  307.             getContentPane().setLayout(layout);
  308.             layout.setHorizontalGroup(
  309.                 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  310.                 .addGroup(layout.createSequentialGroup()
  311.                     .addGap(120, 120, 120)
  312.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  313.                         .addComponent(jButton1)
  314.                         .addGroup(layout.createSequentialGroup()
  315.                             .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
  316.                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  317.                             .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))
  318.                     .addContainerGap(120, Short.MAX_VALUE))
  319.             );
  320.             layout.setVerticalGroup(
  321.                 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  322.                 .addGroup(layout.createSequentialGroup()
  323.                     .addGap(30, 30, 30)
  324.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  325.                         .addComponent(jLabel1)
  326.                         .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  327.                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
  328.                     .addComponent(jButton1))
  329.             );
  330.  
  331.             pack();
  332.         }
  333.     }
  334. }
  335.  
  336.  
  337. class DeluxesAIRSlaveBankNode extends Node
  338. {
  339.     @Override
  340.     public void execute()
  341.     {
  342.         int timeout = 0;
  343.         if (DeluxesAIRSlave.inAltar())
  344.         {
  345.             DeluxesAIRSlave.state = "Leaving altar.";
  346.             RSObject[] portal = Objects.findNearest(25, "Portal");
  347.             if (portal.length > 0)
  348.             {
  349.                 portal[0].click("Leave", "Exit", "Use", "Enter");
  350.                 do
  351.                 {
  352.                     General.sleep(100);
  353.                     if (!Player.isMoving())
  354.                         timeout++;
  355.                 } while (timeout < 25 && DeluxesAIRSlave.inAltar());
  356.                 timeout = 0;
  357.             }
  358.         }
  359.        
  360.         if (!DeluxesAIRSlave.inAltar() && !DeluxesAIRSlave.inBank())
  361.         {
  362.             DeluxesAIRSlave.state = "Left altar, walking to bank.";
  363.             boolean success = false;//DeluxeUtil.TraversePath(Walking.invertPath(DeluxesAIRSlave.path), 200);
  364.             if (!success)
  365.             {
  366.                 General.println("Walking path failed. Using webwalk");
  367.                 WebWalking.walkToBank();
  368.             }
  369.         }
  370.        
  371.         if (DeluxesAIRSlave.inBank())
  372.         {
  373.             DeluxesAIRSlave.state = "Inside Bank, opening booth.";
  374.             DeluxesESS.state = "Opening Bank";
  375.             Banking.openBankBooth();
  376.             if (Banking.isPinScreenOpen())
  377.             {
  378.                 Banking.inPin();
  379.             }
  380.             while (!Banking.isBankScreenOpen() && timeout < 10)
  381.             {
  382.                 General.sleep(100);
  383.                 timeout++;
  384.             }
  385.             timeout = 0;
  386.             DeluxesAIRSlave.state = "Withdrawing more ess.";
  387.             Banking.withdraw(0, DeluxesAIRSlave.ESS_TYPE);
  388.            
  389.             while (!Inventory.isFull() && timeout < 7.5)
  390.             {
  391.                 General.sleep(100);
  392.                 timeout++;
  393.             }
  394.             timeout = 0;
  395.         }
  396.     }
  397.     @Override
  398.     public boolean validate()
  399.     {
  400.         return (!Inventory.isFull());
  401.        
  402.     }
  403. }
  404.  
  405. class DeluxesAIRSlaveAltarNode extends Node
  406. {
  407.     @Override
  408.     public void execute()
  409.     {
  410.         int timeout = 0;
  411.         if (Inventory.isFull() && !DeluxesAIRSlave.inAltar())
  412.         {
  413.             DeluxesAIRSlave.state = "Inventory full, walking to altar.";
  414.             boolean success = false;//DeluxeUtil.TraversePath(DeluxesAIRSlave.path, 200);
  415.             General.println(success);
  416.             if (!DeluxesAIRSlave.atEntrance())
  417.             {
  418.                 if (!success)
  419.                 {
  420.                     WebWalking.walkTo(DeluxesAIRSlave.path[DeluxesAIRSlave.path.length - 1]);
  421.                 }
  422.             }
  423.         }
  424.        
  425.         if (DeluxesAIRSlave.atEntrance() && !Player.isMoving())
  426.         {
  427.             RSObject[] entrance = Objects.getAt(new RSTile(2984, 3291));
  428.            
  429.             if (entrance.length > 0)
  430.             {
  431.                 RSItem[] tally = Inventory.find("Air talisman");
  432.                 if (!entrance[0].isOnScreen())
  433.                 {
  434.                     Camera.turnToTile(entrance[0].getPosition());
  435.                     General.sleep(1000);
  436.                 }
  437.                 if (tally.length > 0)
  438.                 {
  439.                     tally[0].click("Use");
  440.                     entrance[0].click();
  441.                 }
  442.                 else
  443.                     entrance[0].click("Enter");
  444.                
  445.                 while (timeout < 20 && !DeluxesAIRSlave.inAltar())
  446.                 {
  447.                     General.sleep(100);
  448.                     if (!Player.isMoving())
  449.                         timeout++;
  450.                 }
  451.                 timeout = 0;
  452.             }
  453.         }
  454.        
  455.         if (DeluxesAIRSlave.inAltar())
  456.         {
  457.            
  458.             if (Inventory.isFull())
  459.             {
  460.                 DeluxesAIRSlave.state = "In altar, waiting for trade.";
  461.                 while (!DeluxesAIRSlave.gotTrade && timeout < 500)
  462.                 {
  463.                     General.sleep(100);
  464.                     timeout++;
  465.                 }
  466.                 if (timeout > 499)
  467.                 {
  468.                     DeluxesAIRSlave.endScript = true;
  469.                     return;
  470.                 }
  471.                 timeout = 0;
  472.                 General.sleep(1500);
  473.                
  474.                 RSPlayer[] master = Players.find(DeluxesAIRSlave.masterName);
  475.                 if (master.length > 0)
  476.                 {
  477.                     master[0].hover();
  478.                     Mouse.click(3);
  479.                     while (!ChooseOption.isOpen() && timeout < 10)
  480.                     {
  481.                         General.sleep(100);
  482.                         timeout++;
  483.                     }
  484.                     timeout = 0;
  485.                     String[] choice = ChooseOption.getOptions();
  486.                     if (choice.length > 0)
  487.                     {
  488.                         while (Interfaces.get(335) == null && Interfaces.get(334) == null)
  489.                         {
  490.                             for (String trade : choice)
  491.                             {
  492.                                 if (trade.contains("Trade") && trade.contains(DeluxesAIRSlave.masterName))
  493.                                     ChooseOption.select(trade);
  494.                             }
  495.                            
  496.                             while (ChooseOption.isOpen() && timeout < 10)
  497.                             {
  498.                                 General.sleep(100);
  499.                                 timeout++;
  500.                             }
  501.                             timeout = 0;
  502.                             General.sleep(1000);
  503.                         }
  504.                     }
  505.                     DeluxesAIRSlave.gotTrade = false;
  506.                     if (Interfaces.get(335) != null || Interfaces.get(334) != null)
  507.                     {
  508.                         RSItem[] ess = Inventory.find(DeluxesAIRSlave.ESS_TYPE);
  509.                         if (ess.length > 0)
  510.                         {
  511.                             while (Inventory.getCount(DeluxesAIRSlave.ESS_TYPE) > 0 && timeout < 30)
  512.                             {
  513.                                 ess[0].hover();
  514.                                 Mouse.click(3);
  515.                                 while (!ChooseOption.isOpen() && timeout < 10)
  516.                                 {
  517.                                     General.sleep(100);
  518.                                     timeout++;
  519.                                 }
  520.                                 timeout = 0;
  521.                                 String[] choices = ChooseOption.getOptions();
  522.                                 if (choices.length > 0)
  523.                                 {
  524.                                     for (String trade : choices)
  525.                                     {
  526.                                         if (trade.contains("Offer-All"))
  527.                                             ChooseOption.select(trade);
  528.                                     }
  529.                                    
  530.                                     while (ChooseOption.isOpen() && timeout < 10)
  531.                                     {
  532.                                         General.sleep(100);
  533.                                         timeout++;
  534.                                     }
  535.                                     timeout = 0;
  536.                                 }
  537.                                 General.sleep(2000);
  538.                             }
  539.                            
  540.                             if (Inventory.getCount(DeluxesAIRSlave.ESS_TYPE) == 0)
  541.                             {
  542.                                 while ((Interfaces.get(335) != null || Interfaces.get(334) != null))
  543.                                 {
  544.                                     if(Interfaces.get(335) != null)  {
  545.                                         Interfaces.get(335).getChild(17).click("Accept");
  546.                                     } else if(Interfaces.get(334) != null) {
  547.                                         Interfaces.get(334).getChild(20).click("Accept");
  548.                                     }
  549.                                     General.sleep(1000);
  550.                                 }
  551.                             }
  552.                         }
  553.                     }
  554.                 }
  555.             }
  556.         }
  557.     }
  558.     @Override
  559.     public boolean validate()
  560.     {
  561.         return true;
  562.     }
  563. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement