Advertisement
airevent

RCHost 1.7

Oct 25th, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.65 KB | None | 0 0
  1. import org.rsbot.script.Script;
  2. import org.rsbot.script.ScriptManifest;
  3. import org.rsbot.script.wrappers.RSArea;
  4. import org.rsbot.script.wrappers.RSTile;
  5. import org.rsbot.script.wrappers.RSItem;
  6. import org.rsbot.script.wrappers.RSNPC;
  7. import org.rsbot.script.wrappers.RSObject;
  8. import org.rsbot.script.wrappers.RSPlayer;
  9. import org.rsbot.script.wrappers.RSInterface;
  10. import org.rsbot.script.wrappers.RSComponent;
  11. import org.rsbot.event.listeners.PaintListener;
  12. import org.rsbot.event.listeners.MessageListener;
  13. import org.rsbot.event.events.MessageEvent;
  14.  
  15. import java.awt.Graphics;
  16. import java.awt.Graphics2D;
  17. import java.util.Formatter;
  18.  
  19.  
  20.  
  21. @ScriptManifest (
  22.     name = "RCHost",
  23.     version = 1.7,
  24.     description = "Runecrafting host",
  25.     keywords = { "runecrafting", "rune", "host", "multi" },
  26.     authors = { "airevent" },
  27.     website = ""
  28. )
  29. public class RCHost extends Script implements MessageListener, PaintListener {
  30.     private int startAirs;
  31.     private int startExp;
  32.     private double startTime;
  33.     private String tradeText = "wishes to trade with you.";
  34.     private int runeEssenceID = 1436;
  35.     private int runeEssenceCertID = 1437;
  36.     private int airRuneID = 556;
  37.     private int airTiaraID = 5527;
  38.     private int airAltarID = 2478;
  39.     private int airAltarExitID = 2465; // or 7389
  40.     private int airAltarEnterID = 2452;
  41.     private RSArea airAltarInners = new RSArea(2837, 4826, 2850, 4841);
  42.     private int tradeOffered = 0;
  43.     private boolean tradeRequest = false;
  44.    
  45.     private int POS_UNKNOWN = 0;
  46.     private int POS_INNERS  = 1;
  47.    
  48.    
  49.    
  50.     private String dateFormat( int seconds ) {
  51.         Formatter f = new Formatter();
  52.         return f.format("%02d:%02d:%02d",
  53.             (int)(seconds/60/60),
  54.             (int)(seconds/60%60),
  55.             (int)(seconds%60)
  56.         ).toString();
  57.     }
  58.    
  59.    
  60.    
  61.     private boolean fail( String msg ) {
  62.         log.severe("Fatal error: " + msg);
  63.         stopScript();
  64.         return false;
  65.     }
  66.    
  67.    
  68.    
  69.     private int pos() {
  70.         RSTile player = getMyPlayer().getLocation();
  71.        
  72.         if ( this.airAltarInners.contains(player) ) {
  73.             return POS_INNERS;
  74.         } else {
  75.             return POS_UNKNOWN;
  76.         }
  77.     }
  78.    
  79.    
  80.    
  81.     private String progress() {
  82.         int time = (int)((System.currentTimeMillis() - this.startTime) / 1000);
  83.         if ( time == 0 ) return "initialising ... ";
  84.        
  85.         int crafted = inventory.getCount(true, this.airRuneID) - this.startAirs;
  86.         int exp = skills.getCurrentExp(skills.RUNECRAFTING) - this.startExp;
  87.        
  88.         return "HOST" +
  89.             "; time: " + this.dateFormat(time) +
  90.             "; airs: " + crafted +
  91.             "; exp: " + exp;
  92.     }
  93.    
  94.    
  95.    
  96.     private boolean isTrading() {
  97.         return ( interfaces.get(334).isValid() || interfaces.get(335).isValid() );
  98.     }
  99.    
  100.    
  101.    
  102.     private boolean isAssistMenu() {
  103.         return ( interfaces.get(301).isValid() );
  104.     }
  105.    
  106.    
  107.    
  108.     public void onRepaint( Graphics g1 ) {
  109.         Graphics2D g = (Graphics2D)g1;
  110.         g.drawString(this.progress(), 10, 330);
  111.     }
  112.    
  113.    
  114.    
  115.     public void onFinish() {
  116.         log(this.progress());
  117.     }
  118.    
  119.    
  120.    
  121.     public boolean onStart() {
  122.         /*if ( this.pos() == POS_UNKNOWN ) {
  123.             log.severe("unknown player position; go to air altar");
  124.             return false;
  125.         }
  126.        
  127.         if ( !equipment.containsAll(this.airTiaraID) ) {
  128.             log.severe("no air tiara equipped");
  129.             return false;
  130.         }
  131.        
  132.         if ( !inventory.contains(this.runeEssenceCertID) ) {
  133.             log.severe("no rune essence certificates in inventory");
  134.             return false;
  135.         }
  136.        
  137.         if ( !inventory.contains(this.airRuneID) ) {
  138.             log.severe("no air runes in inventory");
  139.             return false;
  140.         }
  141.        
  142.         if ( inventory.getCount(false, this.runeEssenceID) + 2 != inventory.getCount() ) {
  143.             log.severe("unknown items in inventory");
  144.             return false;
  145.         }*/
  146.        
  147.         this.startAirs = inventory.getCount(true, this.airRuneID);
  148.         this.startExp = skills.getCurrentExp(skills.RUNECRAFTING);
  149.         this.startTime = System.currentTimeMillis();
  150.        
  151.         camera.setPitch(90);
  152.         return true;
  153.     }
  154.    
  155.    
  156.    
  157.     public void messageReceived( MessageEvent e ) {
  158.         String who = e.getSender();
  159.         String msg = e.getMessage();
  160.         RSPlayer carrier = players.getNearest(who);
  161.        
  162.         sleep(20);
  163.        
  164.         if ( this.isTrading() ) return;
  165.         if ( !msg.contains(this.tradeText) ) return;
  166.         if ( carrier == null ) return;
  167.        
  168.         if ( inventory.getCount(false, this.runeEssenceID) == 0 ) {
  169.             this.tradeRequest = true;
  170.         }
  171.     }
  172.    
  173.    
  174.    
  175.     private void tradeAccept() {
  176.         RSComponent chat = interfaces.get(137).getComponent(58);
  177.         RSComponent row;
  178.        
  179.         if ( chat == null ) return;
  180.        
  181.         for ( int i=0; i<100; ++i ) {
  182.             row = chat.getComponent(i);
  183.             if ( row == null ) break;
  184.             if ( !row.getText().contains(this.tradeText) ) continue;
  185.             this.tradeRequest = false;
  186.             this.tradeOffered = 0;
  187.             mouse.click(row.getCenter(), true);
  188.             break;
  189.         }
  190.     }
  191.    
  192.    
  193.    
  194.     private void trade() {
  195.         if ( trade.inTradeMain() ) {
  196.             int count = trade.getNumberOfItemsOffered();
  197.            
  198.             if ( count == 0 ) return;
  199.            
  200.             if ( count > 26 ) {
  201.                 trade.declineTrade();
  202.                 return;
  203.             }
  204.            
  205.             if ( inventory.getCount(false, this.runeEssenceID) > 0 ) {
  206.                 trade.declineTrade();
  207.                 return;
  208.             }
  209.            
  210.             RSItem ess[] = trade.getItemsOffered();
  211.            
  212.             for ( int i=0; i<ess.length; ++i ) {
  213.                 if ( ess[i].getID() != this.runeEssenceID ) {
  214.                     trade.declineTrade();
  215.                     return;
  216.                 }
  217.             }
  218.            
  219.             if ( this.tradeOffered != count ) {
  220.                 if ( this.tradeOffered > count ) {
  221.                     trade.declineTrade();
  222.                     return;
  223.                 }
  224.                
  225.                 if ( trade.offer(this.runeEssenceCertID, count-this.tradeOffered) ) {
  226.                     sleep(1000,1100);
  227.                    
  228.                     if ( trade.isWealthOffered() ) {
  229.                         this.tradeOffered = count;
  230.                     }
  231.                 }
  232.             }
  233.            
  234.             if ( count == this.tradeOffered ) {
  235.                 trade.acceptTrade();
  236.             }
  237.         } else if ( trade.inTradeSecond() ) {
  238.             this.tradeOffered = 0;
  239.             trade.acceptTrade();
  240.             sleep(900,1100);
  241.         }
  242.     }
  243.    
  244.    
  245.    
  246.     public int loop() {
  247.         if ( interfaces.canContinue() ) {
  248.             camera.moveRandomly(random(500,700));
  249.             interfaces.clickContinue();
  250.             return random(50,90);
  251.         }
  252.        
  253.         if ( this.isAssistMenu() ) {
  254.             walking.walkTileMM(getMyPlayer().getLocation().randomize(1,1));
  255.             return random(500,900);
  256.         }
  257.        
  258.         if ( this.isTrading() ) {
  259.             try { this.trade(); } catch ( Exception e ) {}
  260.             return random(50,90);
  261.         }
  262.        
  263.         if ( this.tradeRequest ) {
  264.             this.tradeAccept();
  265.             return random(50,90);
  266.         }
  267.        
  268.         if ( inventory.getCount(false, this.runeEssenceID) > 0 ) {
  269.             RSObject altar = objects.getNearest(this.airAltarID);
  270.            
  271.             if ( altar != null ) {
  272.                 camera.moveRandomly(random(500,700));
  273.                 camera.turnTo(altar);
  274.                 altar.doClick();
  275.                 return random(900,1100);
  276.             } else {
  277.                 this.fail("cant find air altar");
  278.             }
  279.         }
  280.        
  281.         /*if ( inventory.getCount(true, this.runeEssenceCertID) < 26 ) {
  282.             this.fail("ran out of ess; stopping");
  283.             return 0;
  284.         }*/
  285.        
  286.         return random(50,90);
  287.     }
  288. }
  289.  
  290.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement