Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 14.08 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.IOException;
  4. import javax.imageio.ImageIO;
  5.  
  6. import java.net.URL;
  7.  
  8. import java.text.NumberFormat;
  9. import java.util.LinkedList;
  10.  
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13.  
  14. import org.rsbot.event.events.MessageEvent;
  15. import org.rsbot.event.listeners.MessageListener;
  16. import org.rsbot.event.listeners.PaintListener;
  17. import org.rsbot.script.methods.*;
  18. import org.rsbot.script.wrappers.*;
  19. import org.rsbot.script.Script;
  20. import org.rsbot.script.ScriptManifest;
  21.  
  22. @ScriptManifest(authors = "Algol", name = "Fally Soft Clay", version = 0.01, description = "Softclay @ Fally")
  23. public class FallySoftClay extends Script implements MessageListener, PaintListener, MouseListener, MouseMotionListener{
  24. /*
  25. Previous versions:
  26. v0.1       
  27. */
  28.     //Version of script
  29.     public final double VERSION = getClass().getAnnotation(ScriptManifest.class).version();
  30.    
  31.     //Number formatter
  32.     public final NumberFormat nf = NumberFormat.getInstance();
  33.    
  34.     //Variables
  35.     public String serverMsg = "";
  36.     public String status = "";
  37.     public String program = ".:: Falador Soft Clay, by Algol ::.";
  38.     public RSTile atWaterPumpTile = new RSTile(2949, 3382);
  39.     public RSTile waterPumpTile = new RSTile(2947, 3383);
  40.     public RSArea bankArea = new RSArea(new RSTile(2943, 3368), new RSTile(2947, 3373));
  41.     public int totalSCMade = 0;
  42.     public int scInBank = 0;
  43.     public int totalSCInBank = 0;
  44.     public int totalCInBank = 0;
  45.     public int clayID = 434;
  46.     public int softClayID = 1761;
  47.     public int bucketID = 1925;
  48.     public int wBucketID = 1929;
  49.     public int waterPumpID = 11661;
  50.     public int bankBoothID = 11758;
  51.     public int bankerID = 6200;
  52.  
  53.    
  54.     //Timer variables
  55.     public long startTime = System.currentTimeMillis();
  56.     public long runTime = 0;
  57.     public long endTime = 0;
  58.    
  59.     //GUI stuff
  60.     private final RenderingHints rh = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
  61.                                           RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  62.     Font textFont = new Font("Allerta", Font.PLAIN, 10);
  63.     Font textFontB = new Font("Allerta", Font.BOLD, 10);
  64.     Color BLACK = new Color(0, 0, 0, 255);
  65.     Color TXTBLUE = new Color(50, 161, 226, 255);
  66.     Color TXTCOLOR = new Color(255, 255, 255, 191);
  67.     Color TXTBLUE2 = new Color(50, 112, 226, 255);
  68.     Color WHITE = new Color(255, 250, 255);
  69.     Color TRANSPARRENT = new Color(0, 0, 0, 175);
  70.     Color TRANSPARRENT2 = new Color(0, 0, 0, 145);
  71.    
  72.     private final LinkedList<MousePathPoint> mousePath = new LinkedList<MousePathPoint>();
  73.     Color myColor = new Color(122, 25, 17, 150);
  74.     Point p;
  75.    
  76.     //private enum st = { GOBANK, GORANGE, ATBANK, ATRANGE, COOKING };
  77. /*___________________________________________________________________________*/
  78.  
  79.     public boolean onStart(){
  80.         nf.setMinimumIntegerDigits(2);
  81.         mouse.setSpeed(random(6,9));
  82.         camera.setPitch(true);
  83.         return true;
  84.     }
  85.  
  86. /*___________________________________________________________________________*/
  87.    
  88.     public void onFinish(){
  89.         log("Thank you for using Fallador Soft Clay, by Algol");
  90.         log("Script ran for " + formatTime(runTime));
  91.         log("You've made " + totalSCMade + " clay into soft clay");
  92.     }
  93.  
  94. /*___________________________________________________________________________*/
  95.  
  96.     public void banking() {
  97.         int fail = 0;
  98.         sleep(300,400);
  99.         int curCountSC = inventory.getCount(softClayID);
  100.         int curCountWBuckets = inventory.getCount(wBucketID);
  101.         int curCountBuckets = inventory.getCount(bucketID);
  102.         int curCountClay = inventory.getCount(clayID);
  103.         int curInventoryCount = inventory.getCount();
  104.         if (curInventoryCount == 0) {
  105.             int bankCountWBucket = bank.getCount(wBucketID);
  106.             int bankCountBucket = bank.getCount(bucketID);
  107.             if (bankCountWBucket >= 14) {
  108.                 bank.withdraw(wBucketID, 14);
  109.             } else if (bankCountWBucket < 14 && bankCountWBucket > 0) {
  110.                 bank.withdraw(wBucketID, bankCountWBucket);
  111.             } else if (bankCountBucket >= 14) {
  112.                 bank.withdraw(bucketID, 14);
  113.             } else if (bankCountBucket < 14 && bankCountBucket > 0) {
  114.                 bank.withdraw(bucketID, bankCountBucket);
  115.             } else {
  116.                 log("No buckets with or without water found!!!");
  117.                 stopScript();
  118.             }
  119.         }
  120.         if (curCountSC > 0) {
  121.             bank.deposit(softClayID, 0);
  122.             sleep(300,500);
  123.         }
  124.         if (curCountClay == 0) {
  125.             if (bank.getCount(clayID) == 0) {
  126.                 log("Out of clay!!!");
  127.                 stopScript();
  128.             }
  129.             if (random(0,10) == 1) {
  130.                 bank.withdraw(clayID, 0);
  131.             } else {
  132.                 bank.withdraw(clayID, 28 - inventory.getCount());
  133.             }
  134.         }
  135.         sleep(100,200);
  136.         scInBank = bank.getCount(softClayID);
  137.         totalCInBank = bank.getCount(clayID);
  138.     }
  139.    
  140.     public boolean atWaterPump() {
  141.         double dist = calc.distanceBetween(players.getMyPlayer().getLocation(), atWaterPumpTile);
  142.         return (dist < 3) ? true : false;
  143.     }
  144.    
  145.     public boolean atBank() {
  146.         return bankArea.contains(players.getMyPlayer().getLocation()) ? true : false;
  147.     }
  148.    
  149.     public boolean madeAllSC() {
  150.         if (inventory.getCount() == 0) {
  151.             return true;
  152.         } else if (inventory.getCount(clayID) == 0) {
  153.             return true;
  154.         }
  155.         return ( (inventory.getCount(softClayID) > 0) && (inventory.getCount(clayID) == 0) ) ? true : false;
  156.     }
  157.    
  158.     public boolean doRest() {
  159.         int energy = walking.getEnergy();
  160.         status = "Resting";
  161.         for (int d = 0; d < 5; d++) {
  162.             interfaces.getComponent(750, 6).doAction("Rest");
  163.             sleep(random(1000, 1400));
  164.             if (getMyPlayer().getAnimation() == 12108 || getMyPlayer().getAnimation() == 2033 || getMyPlayer().getAnimation() == 2716 || getMyPlayer().getAnimation() == 11786 || getMyPlayer().getAnimation() == 5713) {
  165.                 break;
  166.             }
  167.             if (d == 4) {
  168.                 log("Rest failed!");
  169.                 return false;
  170.             }
  171.         }
  172.         energy = walking.getEnergy();
  173.         int maxWait = 0;
  174.         int targetEnergy = random(90,95);
  175.         while (energy < targetEnergy && maxWait++ <= 111) {
  176.             sleep(random(250, 300));
  177.             energy = walking.getEnergy();
  178.         }
  179.         return true;
  180.     }
  181.    
  182.     private void antiban() {
  183.         int rng = random(1, 10);
  184.         switch (rng) {
  185.         case 1:
  186.             if (random(1, 57) != 1)
  187.                 return;
  188.             mouse.move(random(10, 75), random(10, 85));
  189.             status = "Antiban";
  190.             return;
  191.         case 2:
  192.             if (random(1, 30) != 1)
  193.                 return;
  194.             int angle = camera.getAngle() + random(-30, 30);
  195.             if (angle < 0) {
  196.                 angle = random(0, 10);
  197.                 status = "Antiban";
  198.             }
  199.             if (angle > 359) {
  200.                 angle = random(0, 10);
  201.                 status = "Antiban";
  202.             }
  203.             camera.setAngle(angle);
  204.             status = "Antiban";
  205.             return;
  206.         case 3:
  207.             if (random(1, 15) != 1)
  208.                 return;
  209.             try {
  210.                 mouse.moveSlightly();
  211.                 status = "Antiban";
  212.             } catch (Exception e) {
  213.                  
  214.             }          
  215.             return;
  216.         default:
  217.             return;        
  218.         }      
  219.     }  
  220.  
  221.    
  222.     @Override
  223.     public int loop() {
  224.         int fail = 0;
  225.         if (!game.isLoggedIn()) {
  226.             status = "not logged in";
  227.             return random(100,200);
  228.         }
  229.         antiban();
  230.         if(walking.getEnergy() < 10) {
  231.             doRest();
  232.         }
  233.         antiban();
  234.         if (!atBank() && madeAllSC()) {
  235.             status = "Walking to Bank";
  236.             walking.walkTileMM(new RSTile(2946, 3369)); // walk to bank
  237.             sleep(800,1100);
  238.         } else if (atBank() && ( madeAllSC() || inventory.getCount() == 0 ) ) {
  239.             status = "Banking";
  240.             RSObject booth = objects.getNearest(bankBoothID);
  241.             if (booth.isOnScreen()) {
  242.                 boolean bankClicked = false;
  243.                 if (bank.isOpen()) {
  244.                     banking();
  245.                 } else {
  246.                     fail = 0;
  247.                     while (fail++<50 && !bankClicked) {
  248.                         sleep(25,50);
  249.                         if (booth.doAction("use-quickly")) {
  250.                             bankClicked = true;
  251.                         }
  252.                     }
  253.                     fail = 0;
  254.                     while (fail++<50 &&!bank.isOpen()) {
  255.                         sleep(25,50);
  256.                     }
  257.                     if (bank.isOpen()) {
  258.                         banking();
  259.                     } else {
  260.                         status = "Failed to click the banker. Please wait";
  261.                     }
  262.                 }
  263.             }
  264.         } else if (!atWaterPump() && !madeAllSC()) {
  265.             status = "Walking to Waterpump";
  266.             walking.walkTileMM(atWaterPumpTile); // walk to waterpump
  267.             sleep(800,1100);
  268.         } else if (atWaterPump() && !madeAllSC() && !players.getMyPlayer().isMoving()) {
  269.             if (inventory.getCount(wBucketID) == 0) { //no buckets with water in inventory
  270.                 if (inventory.getCount(bucketID) == 0) {//no buckets in inventory, so stop script
  271.                     log("No buckets!!!");
  272.                     stopScript();
  273.                 }
  274.                 inventory.getItem(bucketID).doClick(true);
  275.                 mouse.moveRandomly(random(0,40));
  276.                 sleep(300,400);
  277.                 if (inventory.isItemSelected()) {
  278.                     status = "Using Bucket on the Waterpump";
  279.                     int countBuckets = inventory.getCount(bucketID);
  280.                     fail = 0;
  281. //                  if (tiles.doAction(waterPumpTile, "Use Bucket -> Waterpump")) {
  282.                     if (objects.getNearest(waterPumpID).doClick(true)) {
  283.                         mouse.moveRandomly(random(0,40));
  284.                         boolean isFilling = false;
  285.                         antiban();
  286.                         while (fail++ < 200 && countBuckets > 0) {
  287.                             sleep(100,200);
  288.                             antiban();
  289.                             status = "Filling Buckets. " + countBuckets + " left";
  290.                             countBuckets = inventory.getCount(bucketID);
  291.                             if (players.getMyPlayer().getAnimation() == 832) {
  292.                                 isFilling = true;
  293.                             }
  294.                             if (fail > 8 && !isFilling) {
  295.                                 break;
  296.                             }
  297.                         }
  298.                         sleep(300,500);
  299.                     }
  300.                 } else {
  301.                     return random(100,200);
  302.                 }
  303.             }
  304.             if (inventory.getCount(clayID) > 0 && inventory.getCount(wBucketID) > 0) {
  305.                 status = "Making soft clay";
  306.                 inventory.getItem(wBucketID).doClick(true);
  307.                 sleep(200, 400);
  308.                 inventory.getItem(clayID).doClick(true);
  309.                 fail = 0;
  310.                 while (fail++ < 200 && !interfaces.getComponent(905, 14).isValid()) {
  311.                     sleep(100, 300);
  312.                     antiban();
  313.                 }
  314.                 if (interfaces.getComponent(905, 14).isValid()) {
  315.                     interfaces.getComponent(905, 14).doClick();
  316.                     fail = 0;
  317.                     while (fail++ < 200 && inventory.getCount(clayID) != 0) {
  318.                         sleep(100,200);
  319.                         antiban();
  320.                     }
  321.                     if (totalCInBank == 0) {
  322.                         if (inventory.getCount(bucketID) > 0) {
  323.                             int countBuckets = inventory.getCount(bucketID);
  324.                             fail = 0;
  325.                             if (objects.getNearest(waterPumpID).doClick(true)) {
  326.                                 mouse.moveRandomly(random(0,40));
  327.                                 boolean isFilling = false;
  328.                                 antiban();
  329.                                 while (fail++ < 200 && countBuckets > 0) {
  330.                                     sleep(100,200);
  331.                                     antiban();
  332.                                     status = "Filling Buckets. " + countBuckets + " left";
  333.                                     countBuckets = inventory.getCount(bucketID);
  334.                                     if (players.getMyPlayer().getAnimation() == 832) {
  335.                                         isFilling = true;
  336.                                     }
  337.                                     if (fail > 8 && !isFilling) {
  338.                                         break;
  339.                                     }
  340.                                 }
  341.                                 sleep(300,500);
  342.                             }
  343.                         }
  344.                         log("Out of clay!!!");
  345.                         log("Walking to bank.");
  346.                         walking.walkTileMM(new RSTile(2946, 3369)); // walk to bank
  347.                         sleep(2500,4100);
  348.                         stopScript();
  349.                     }
  350.                 }
  351.             }
  352.            
  353.         }
  354.         if (interfaces.canContinue()) {
  355.             sleep(400,600);
  356.             interfaces.clickContinue();
  357.         }
  358.         antiban();
  359.         return random(100,200);
  360.     }
  361.    
  362. /*___________________________________________________________________________*/
  363.  
  364.     public String formatTime(final long milliseconds) {
  365.         final long t_seconds = milliseconds / 1000;
  366.         final long t_minutes = t_seconds / 60;
  367.         final long t_hours = t_minutes / 60;
  368.         final long t_days = t_hours / 24;
  369.         final int seconds = (int) (t_seconds % 60);
  370.         final int minutes = (int) (t_minutes % 60);
  371.         final int hours = (int) (t_hours % 60);
  372.         final int days = (int) (t_days % 24);
  373.         return (nf.format(days) + ":" + nf.format(hours) + ":" + nf.format(minutes) + ":" + nf.format(seconds));
  374.     }
  375.  
  376.     private class MousePathPoint extends Point { // credits to Enfilade
  377.         private int toColor(double d) { // credits to Enfilade
  378.             return Math.min(255, Math.max(0, (int) d));
  379.         }
  380.  
  381.         private long finishTime;
  382.         private double lastingTime;
  383.  
  384.         public MousePathPoint(int x, int y, int lastingTime) {
  385.             super(x, y);
  386.             this.lastingTime = lastingTime;
  387.             finishTime = System.currentTimeMillis() + lastingTime;
  388.         }
  389.  
  390.         public boolean isUp() {
  391.             return System.currentTimeMillis() > finishTime;
  392.         }
  393.  
  394.         public Color getColor() {
  395.             return new Color(
  396.                     122,
  397.                     25,
  398.                     17,
  399.                     toColor(256 * ((finishTime - System.currentTimeMillis()) / lastingTime)));
  400.         }
  401.     }
  402.    
  403. /*___________________________________________________________________________*/
  404.  
  405.     public void messageReceived(MessageEvent me) {
  406.         if (me.getID() == MessageEvent.MESSAGE_ACTION || me.getID() == MessageEvent.MESSAGE_SERVER) {
  407.             serverMsg = me.getMessage().toLowerCase();
  408.             if ( serverMsg.contains("workable") ){
  409.                 totalSCMade += 1;
  410.             }
  411.         }
  412.     }
  413.     public void mouseClicked(MouseEvent e) {
  414.     }
  415.     public void mousePressed(MouseEvent e) {
  416.     }
  417.     public void mouseReleased(MouseEvent e) {
  418.     }
  419.     public void mouseEntered(MouseEvent e) {
  420.     }
  421.     public void mouseExited(MouseEvent e) {
  422.     }
  423.     public void mouseDragged(MouseEvent e)
  424.     {
  425.     }
  426.     public void mouseMoved(MouseEvent e)
  427.     {
  428.         p = e.getPoint();
  429.     }
  430.  
  431. /*___________________________________________________________________________*/
  432.    
  433.     public void onRepaint(Graphics g) {
  434.         ((Graphics2D) g).setRenderingHints(rh);
  435.        
  436.         runTime = System.currentTimeMillis() - startTime;
  437.         String infoStr;
  438.         g.setColor(BLACK);
  439.         g.drawRect(6, 269, 240, 68);
  440.         g.setColor(TRANSPARRENT2);
  441.         g.fillRect(8, 271, 237, 65);
  442.         g.setColor(WHITE);
  443.         g.setFont(textFontB);
  444.         g.drawString(program, 11, 284);
  445.         g.setFont(textFont);
  446.         g.setColor(TXTBLUE);
  447.         g.drawString("Run Time: " + formatTime(runTime), 11, 296);
  448.         g.drawString("Status: ", 11, 308);
  449.         g.setColor(TXTCOLOR);
  450.         g.drawString(status, 46, 308);
  451.         g.setColor(TXTBLUE);
  452.         g.drawString("Soft clay in Bank: " + scInBank + " Total made so far: " + totalSCMade, 11, 320);
  453.         g.drawString("Clay left in Bank: " + totalCInBank, 11, 332);
  454.        
  455.         Point p = mouse.getLocation();
  456.         g.setColor(myColor);
  457.         g.fillRect(p.x - 5, p.y, 12, 2);
  458.         g.fillRect(p.x, p.y - 5, 2, 12);
  459.         while (!mousePath.isEmpty() && mousePath.peek().isUp())
  460.             // credits to Enfilade
  461.             mousePath.remove();
  462.         Point clientCursor = mouse.getLocation();
  463.         MousePathPoint mpp = new MousePathPoint(clientCursor.x,
  464.                 clientCursor.y, 3000);
  465.         if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp))
  466.             mousePath.add(mpp);
  467.         MousePathPoint lastPoint = null;
  468.         for (MousePathPoint p1 : mousePath) {
  469.             if (lastPoint != null) {
  470.                 g.setColor(p1.getColor());
  471.                 g.drawLine(p1.x, p1.y, lastPoint.x, lastPoint.y);
  472.             }
  473.             lastPoint = p1;
  474.         }      
  475.     }
  476. }
  477.  
  478. /*Algol 2011*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement