Advertisement
airevent

RCRunner 1.8

Oct 25th, 2011
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.00 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 = "RCRunner",
  23.     version = 1.8,
  24.     description = "Runecrafting runner",
  25.     keywords = { "runecrafting", "rune", "host", "multi" },
  26.     authors = { "airevent" },
  27.     website = ""
  28. )
  29. public class RCRunner extends Script implements MessageListener, PaintListener {
  30.     private String hostPlayerName = "ENTER YOUR HOST CHARACTER NAME HERE"; // master crafter
  31.     private int transoported = 0;
  32.     private double startTime;
  33.     private int runeEssenceID = 1436;
  34.     private int runeEssenceCertID = 1437;
  35.     private int airTiaraID = 5527;
  36.     private int airAltarExitID = 2465; // or 7389
  37.     private int airAltarEnterID = 2452;
  38.     private int musicianID = 8699;
  39.     private RSArea a_wildy = new RSArea(3040, 3500, 3117, 3520);
  40.     private RSArea a_bank = new RSArea(3182, 3432, 3186, 3438);
  41.     private RSArea a_music = new RSArea(3151, 3420, 3155, 3424);
  42.     private RSArea a_altar = new RSArea(3124, 3402, 3131, 3408);
  43.     private RSArea airAltarInners = new RSArea(2837, 4826, 2850, 4841);
  44.     private RSArea airAltarRCZone = new RSArea(2842, 4832, 2846, 4836);
  45.     private OsakaRoute route = null;
  46.     private boolean mustRest = false;
  47.     private boolean mustTrade = false;
  48.    
  49.     private final int POS_UNKNOWN = 0;
  50.     private final int POS_BANK    = 1;
  51.     private final int POS_MUSIC   = 2;
  52.     private final int POS_ALTAR   = 3;
  53.     private final int POS_RCZONE  = 4;
  54.     private final int POS_INNERS  = 5;
  55.     private final int POS_WILDY   = 6; // stucking near wilderness
  56.    
  57.    
  58.    
  59.     private String dateFormat( int seconds ) {
  60.         Formatter f = new Formatter();
  61.         return f.format("%02d:%02d:%02d",
  62.             (int)(seconds/60/60),
  63.             (int)(seconds/60%60),
  64.             (int)(seconds%60)
  65.         ).toString();
  66.     }
  67.    
  68.    
  69.    
  70.     // changes player position
  71.     private class OsakaRoute {
  72.         public int type; // external type of the route
  73.         private RSTile from; // go from here
  74.         private RSTile to; // go to here
  75.         private RSTile next; // next nearest to destination
  76.         private RSTile checkmove; // if dest is unreachable, this will help
  77.        
  78.         public OsakaRoute( RSTile to, int type ) {
  79.             this.type = type;
  80.             this.from = getMyPlayer().getLocation();
  81.             this.to = to;
  82.             this.next = null;
  83.             this.checkmove = null;
  84.         }
  85.        
  86.         private boolean eqTiles( RSTile t1, RSTile t2 ) {
  87.             return ( t1.getX() == t2.getX() && t1.getY() == t2.getY() );
  88.         }
  89.        
  90.         private boolean dvTiles( RSTile t1, RSTile t2, int deviation ) {
  91.             int diffX = Math.abs(t1.getX() - t2.getX());
  92.             int diffY = Math.abs(t1.getY() - t2.getY());
  93.             return ( diffX < deviation && diffY < deviation );
  94.         }
  95.        
  96.         public boolean step() {
  97.             RSTile pos = getMyPlayer().getLocation();
  98.             boolean moves = getMyPlayer().isMoving();
  99.            
  100.             // came
  101.             if ( this.eqTiles(pos, this.to) ) {
  102.                 return true;
  103.             }
  104.            
  105.             // check if unreachable
  106.             if ( this.checkmove != null ) {
  107.                 if ( this.eqTiles(pos, this.checkmove) ) {
  108.                     return true;
  109.                 } else {
  110.                     this.checkmove = null;
  111.                 }
  112.             }
  113.            
  114.             // just start move
  115.             if ( this.next == null ) {
  116.                 this.next = walking.getClosestTileOnMap(this.to);
  117.                 walking.walkTileMM(this.next);
  118.                 return false;
  119.             }
  120.            
  121.             // already in progress
  122.             if ( moves ) {
  123.                 if ( this.dvTiles(pos, this.next, 7) ) {
  124.                     if ( this.eqTiles(this.next, this.to) ) {
  125.                         return true;
  126.                     }
  127.                    
  128.                     this.next = walking.getClosestTileOnMap(this.to);
  129.                     walking.walkTileMM(this.next);
  130.                 }
  131.                
  132.                 camera.moveRandomly(random(500,700));
  133.                 sleep(400,700);
  134.             } else {
  135.                 this.next = walking.getClosestTileOnMap(this.to);
  136.                 walking.walkTileMM(this.next);
  137.                 this.checkmove = pos;
  138.                 sleep(1900, 2100);
  139.             }
  140.            
  141.             return false;
  142.         }
  143.     }
  144.    
  145.    
  146.    
  147.     private boolean fail( String msg ) {
  148.         log.severe("Fatal error: " + msg);
  149.         stopScript();
  150.         return false;
  151.     }
  152.    
  153.    
  154.    
  155.     private int pos() {
  156.         RSTile player = getMyPlayer().getLocation();
  157.        
  158.         if ( this.a_wildy.contains(player) ) {
  159.             return POS_WILDY;
  160.         } else if ( this.a_bank.contains(player) ) {
  161.             return POS_BANK;
  162.         } else if ( this.a_music.contains(player) ) {
  163.             return POS_MUSIC;
  164.         } else if ( this.a_altar.contains(player) ) {
  165.             return POS_ALTAR;
  166.         } else if ( this.airAltarRCZone.contains(player) ) {
  167.             return POS_RCZONE;
  168.         } else if ( this.airAltarInners.contains(player) ) {
  169.             return POS_INNERS;
  170.         } else {
  171.             return POS_UNKNOWN;
  172.         }
  173.     }
  174.    
  175.    
  176.    
  177.     private String progress() {
  178.         int time = (int)((System.currentTimeMillis() - this.startTime) / 1000);
  179.         if ( time == 0 ) return "initialising ... ";
  180.        
  181.         return "RUNNER" +
  182.             "; time: " + this.dateFormat(time) +
  183.             "; transoported: " + this.transoported;
  184.     }
  185.    
  186.    
  187.    
  188.     private boolean isTrading() {
  189.         return ( interfaces.get(334).isValid() || interfaces.get(335).isValid() );
  190.     }
  191.    
  192.    
  193.    
  194.     private boolean isCollectBox() {
  195.         return ( interfaces.get(109).isValid() );
  196.     }
  197.    
  198.    
  199.    
  200.     public void onRepaint( Graphics g1 ) {
  201.         Graphics2D g = (Graphics2D)g1;
  202.         g.drawString(this.progress(), 10, 330);
  203.     }
  204.    
  205.    
  206.    
  207.     public void messageReceived( MessageEvent e ) {
  208.         String who = e.getSender();
  209.         String msg = e.getMessage();
  210.        
  211.         if ( msg.equals(getMyPlayer().getName()) ) {
  212.             walking.walkTileMM(getMyPlayer().getLocation().randomize(1,1));
  213.             return;
  214.         }
  215.        
  216.         if ( msg.contains("other player is busy") ||
  217.          msg.contains("assistance request") ) {
  218.             this.mustTrade = true;
  219.             return;
  220.         }
  221.        
  222.         if ( msg.contains("energy left to run!") ) {
  223.             this.mustRest = true;
  224.             return;
  225.         }
  226.     }
  227.    
  228.    
  229.    
  230.     public void onFinish() {
  231.         log(this.progress());
  232.     }
  233.    
  234.    
  235.    
  236.     public boolean onStart() {
  237.         /*if ( this.pos() == POS_UNKNOWN ) {
  238.             log.severe("unknown player position; go to Varrock west bank");
  239.             return false;
  240.         }
  241.        
  242.         if ( !equipment.containsAll(this.airTiaraID) ) {
  243.             log.severe("no air tiara equipped");
  244.             return false;
  245.         }*/
  246.        
  247.         this.startTime = System.currentTimeMillis();
  248.        
  249.         camera.setPitch(90);
  250.         return true;
  251.     }
  252.    
  253.    
  254.    
  255.     private void trade() {
  256.         if ( !trade.getTradingWith().equals(this.hostPlayerName) ) {
  257.             trade.declineTrade();
  258.             return;
  259.         }
  260.        
  261.         if ( trade.inTradeMain() ) {
  262.             int ess = inventory.getCount(false, this.runeEssenceID);
  263.             if ( ess > 26 ) ess = 26;
  264.            
  265.             if ( ess > 0 ) {
  266.                 trade.offer(this.runeEssenceID, ess);
  267.             }
  268.            
  269.             if ( trade.getNumberOfItemsOffered() > 0 ) {
  270.                 trade.acceptTrade();
  271.             }
  272.         } else if ( trade.inTradeSecond() ) {
  273.             this.transoported += 26;
  274.             trade.acceptTrade();
  275.             sleep(900,1100);
  276.         }
  277.     }
  278.    
  279.    
  280.    
  281.     private boolean resting() {
  282.         if ( walking.getEnergy() < 30 ) {
  283.             RSNPC musician = npcs.getNearest(this.musicianID);
  284.            
  285.             if ( musician != null ) {
  286.                 musician.interact("Listen-to");
  287.             }
  288.            
  289.             walking.rest(90);
  290.            
  291.             return true;
  292.         } else {
  293.             return false;
  294.         }
  295.     }
  296.    
  297.    
  298.    
  299.     private void newRun( RSArea where, int type ) {
  300.         if ( this.route == null || this.route.type != type ) {
  301.             RSTile dest = where.getCentralTile().randomize(1,1);
  302.             this.route = new OsakaRoute(dest, type);
  303.         }
  304.         this.route.step();
  305.     }
  306.    
  307.    
  308.    
  309.     private void goBank() {
  310.         switch ( this.pos() ) {
  311.             case POS_WILDY:
  312.                 this.route = null;
  313.                 this.newRun(this.a_altar, POS_ALTAR);
  314.                 break;
  315.             case POS_UNKNOWN:
  316.                 if ( this.route != null ) {
  317.                     this.route.step();
  318.                 } else {
  319.                     this.newRun(this.a_bank, POS_BANK);
  320.                 }
  321.                 break;
  322.             case POS_BANK:
  323.                 if ( !bank.open() ) {
  324.                     sleep(900,1100);
  325.                 } else {
  326.                     if ( inventory.getCount() > 0 ) {
  327.                         bank.depositAll();
  328.                         sleep(900,1100);
  329.                         return;
  330.                     }
  331.                    
  332.                     /*if ( bank.getCount(this.runeEssenceID) == 0 &&
  333.                      !inventory.contains(this.runeEssenceID) ) {
  334.                         this.fail("no rune essence in bank");
  335.                         return;
  336.                     }*/
  337.                    
  338.                     if ( !inventory.contains(this.runeEssenceID) ) {
  339.                         bank.withdraw(this.runeEssenceID, 26);
  340.                         sleep(400,600);
  341.                         return;
  342.                     }
  343.                 }
  344.                 break;
  345.             case POS_MUSIC:
  346.                 if ( this.resting() ) return;
  347.                 this.newRun(this.a_bank, POS_BANK);
  348.                 break;
  349.             case POS_ALTAR:
  350.                 this.newRun(this.a_music, POS_MUSIC);
  351.                 break;
  352.             case POS_INNERS:
  353.                 this.newRun(this.airAltarRCZone, POS_RCZONE);
  354.                 break;
  355.             case POS_RCZONE:
  356.                 RSObject exit = objects.getNearest(this.airAltarExitID);
  357.                 if ( exit != null ) {
  358.                     camera.setPitch(0);
  359.                     camera.moveRandomly(random(500,700));
  360.                     camera.turnTo(exit);
  361.                     exit.doClick();
  362.                     sleep(900,1100);
  363.                 }
  364.                 break;
  365.         }
  366.     }
  367.    
  368.    
  369.    
  370.     private void goAltar() {
  371.         switch ( this.pos() ) {
  372.             case POS_WILDY:
  373.                 this.route = null;
  374.                 this.newRun(this.a_altar, POS_ALTAR);
  375.                 break;
  376.             case POS_UNKNOWN:
  377.                 if ( this.route != null ) {
  378.                     this.route.step();
  379.                 } else {
  380.                     this.newRun(this.a_altar, POS_ALTAR);
  381.                 }
  382.                 break;
  383.             case POS_BANK:
  384.                 this.newRun(this.a_music, POS_MUSIC);
  385.                 break;
  386.             case POS_MUSIC:
  387.                 if ( this.resting() ) return;
  388.                 this.newRun(this.a_altar, POS_ALTAR);
  389.                 break;
  390.             case POS_ALTAR:
  391.                 RSObject enter = objects.getNearest(this.airAltarEnterID);
  392.                 if ( enter != null ) {
  393.                     camera.moveRandomly(random(500,700));
  394.                     camera.turnTo(enter);
  395.                     enter.doClick();
  396.                     sleep(900,1100);
  397.                 }
  398.                 break;
  399.             case POS_INNERS:
  400.                 this.newRun(this.airAltarRCZone, POS_RCZONE);
  401.                 break;
  402.             case POS_RCZONE:
  403.                 camera.setPitch(90);
  404.                
  405.                 RSPlayer host = players.getNearest(this.hostPlayerName);
  406.                
  407.                 if ( host != null ) {
  408.                     if ( !host.isOnScreen() ) {
  409.                         camera.moveRandomly(random(500,700));
  410.                         camera.turnTo(host);
  411.                     }
  412.                    
  413.                     trade.tradePlayer(this.hostPlayerName, 2100);
  414.                 }
  415.                 break;
  416.         }
  417.     }
  418.    
  419.    
  420.    
  421.     public int loop() {
  422.         int ess = inventory.getCount(false, this.runeEssenceID);
  423.         int cert = inventory.getCount(true, this.runeEssenceCertID);
  424.        
  425.         if ( interfaces.canContinue() ) {
  426.             camera.moveRandomly(random(500,700));
  427.             interfaces.clickContinue();
  428.             return random(50,90);
  429.         }
  430.        
  431.         if ( this.mustRest ) {
  432.             this.mustRest = false;
  433.             this.resting();
  434.             return random(2300, 2500);
  435.         }
  436.        
  437.         if ( this.mustTrade ) {
  438.             this.mustTrade = false;
  439.             trade.tradePlayer(this.hostPlayerName, 2100);
  440.             return 0;
  441.         }
  442.        
  443.         if ( this.isCollectBox() ) {
  444.             walking.walkTileMM(this.a_bank.getCentralTile().randomize(1,1));
  445.             return random(500,900);
  446.         }
  447.        
  448.         if ( !walking.isRunEnabled() ) {
  449.             walking.setRun(true);
  450.         }
  451.        
  452.         if ( this.isTrading() ) {
  453.             try { this.trade(); } catch ( Exception e ) {}
  454.             return random(50,90);
  455.         }
  456.        
  457.         if ( ess != 26 ) {
  458.             this.goBank();
  459.         } else {
  460.             this.goAltar();
  461.         }
  462.        
  463.         return random(50,90);
  464.     }
  465. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement