Advertisement
Ulsting

Firemaker

May 17th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.12 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Paint;
  4. import java.awt.PaintContext;
  5. import java.awt.Rectangle;
  6. import java.awt.RenderingHints;
  7. import java.awt.geom.AffineTransform;
  8. import java.awt.geom.Rectangle2D;
  9. import java.awt.image.ColorModel;
  10. import java.util.ArrayList;
  11. import java.util.Arrays;
  12. import java.util.Date;
  13. import java.util.List;
  14.  
  15. import org.tribot.api2007.Banking;
  16. import org.tribot.api2007.Inventory;
  17. import org.tribot.api2007.NPCs;
  18. import org.tribot.api2007.Objects;
  19. import org.tribot.api2007.Player;
  20. import org.tribot.api2007.WebWalking;
  21. import org.tribot.api2007.types.RSItem;
  22. import org.tribot.api2007.types.RSNPC;
  23. import org.tribot.api2007.types.RSObject;
  24. import org.tribot.api2007.types.RSTile;
  25. import org.tribot.script.Script;
  26. import org.tribot.script.ScriptManifest;
  27. import org.tribot.script.interfaces.MessageListening07;
  28.  
  29. @ScriptManifest(authors = {"Ulsting"}, category = "Firemaking", name = "Ulsting's Firemaking", version = 0.01, description = "Makes fires of any log type near any bank.", gameMode = 1)
  30. public class Firemaker extends Script implements Paint, MessageListening07{
  31.     private String logType;
  32.     private RSTile cityTile;
  33.    
  34.     private final AntiBanExtenderUtil ABC = new AntiBanExtenderUtil();
  35.    
  36.     private final List<String> BAD_OBJECTS = new ArrayList<String>(Arrays.asList(
  37.             "Fire",
  38.             "Fern",
  39.             "Daisies",
  40.             "Tree",
  41.             "Wilderness Sign"
  42.         ));
  43.    
  44.     //West Varrock
  45.     private final RSTile WEST_VARROCK_BANK = new RSTile(3183, 3440);
  46.     private final int[] WEST_VARROCK_X_COORDS = { //X:[3192-3198]
  47.             3192,
  48.             3193, 3193,
  49.             3194, 3194, 3194,
  50.             3195, 3195, 3195, 3195,
  51.             3196, 3196, 3196,
  52.             3197, 3197,
  53.             3198
  54.     };
  55.     private final int[] WEST_VARROCK_Y_COORDS = { //Y:[3429-3432]
  56.             3429,
  57.             3430, 3430,
  58.             3431, 3431,
  59.             3432
  60.     };
  61.    
  62.     //East Varrock
  63.     private final RSTile EAST_VARROCK_BANK = new RSTile(3254, 3422);
  64.     private final int[] EAST_VARROCK_X_COORDS = { //X:[3258-3265]
  65.             3258,
  66.             3259, 3259,
  67.             3260, 3260, 3260,
  68.             3261, 3261, 3261, 3261,
  69.             3262, 3262, 3262, 3262,
  70.             3263, 3263, 3263,
  71.             3264, 3264,
  72.             3265
  73.     };
  74.     private final int[] EAST_VARROCK_Y_COORDS = { //Y:[3428-3431]
  75.             3428,
  76.             3429, 3429,
  77.             3430, 3430,
  78.             3431
  79.     };
  80.  
  81.     //EAST Falador
  82.     private final RSTile EAST_FALADOR_BANK = new RSTile(2945, 3370);
  83.     private final int[] EAST_FALADOR_X_COORDS = {  //X:[2937-2942]
  84.             2937,
  85.             2938, 2938,
  86.             2939, 2939, 2939,
  87.             2940, 2940, 2940,
  88.             2941, 2941,
  89.             2942
  90.     };
  91.     private final int[] EAST_FALADOR_Y_COORDS = { //Y:[3370-3376]
  92.             3370,
  93.             3371, 3371,
  94.             3372, 3372, 3372,
  95.             3373, 3373, 3373, 3373,
  96.             3374, 3374, 3374,
  97.             3375, 3375,
  98.             3376
  99.     };
  100.    
  101.     //Draynor
  102.     private final RSTile DRAYNOR_BANK = new RSTile(3093, 3243);
  103.     private final int[] DRAYNOR_X_COORDS = { //X:[3094-3097]
  104.             3094,
  105.             3095, 3095,
  106.             3096, 3096,
  107.             3097
  108.     };
  109.     private final int[] DRAYNOR_Y_COORDS = { //Y:[3247-3250]
  110.             3247,
  111.             3248, 3248,
  112.             3249, 3249,
  113.             3250
  114.     };
  115.  
  116.     @Override
  117.     public void run() {
  118.         if (onStart()) {
  119.             while (true) {
  120.                 int loopCode = this.mainLoop();
  121.                 if (loopCode == -1) break;
  122.                 else sleep(loopCode);
  123.             }
  124.            
  125.             println("Exiting...");
  126.         }
  127.     }
  128.    
  129.     private boolean onStart () {
  130.         //TODO: Create menu with drop down to get which type of log the user wants to burn
  131.         this.logType = "Logs";
  132.        
  133.         RSTile currentLocation = Player.getPosition();
  134.         if (currentLocation.distanceTo(WEST_VARROCK_BANK) <= 25) {
  135.             cityTile = EAST_VARROCK_BANK.clone();
  136.             println("You are near the western bank of Varrock.");
  137.         } else if (currentLocation.distanceTo(EAST_VARROCK_BANK) <= 25) {
  138.             cityTile = EAST_VARROCK_BANK.clone();
  139.             println("You are near the eastern bank of Varrock.");
  140.         } else if (currentLocation.distanceTo(EAST_FALADOR_BANK) <= 25) {
  141.             cityTile = EAST_FALADOR_BANK.clone();
  142.             println("You are near the eastern bank of Falador.");
  143.         } else if (currentLocation.distanceTo(DRAYNOR_BANK) <= 25) {
  144.             cityTile = DRAYNOR_BANK.clone();
  145.             println("You are near Draynor Bank.");
  146.         } else {
  147.             println("Please be closer to one of the following banks:");
  148.             println("East Varrock Bank");
  149.             println("West Varrock Bank");
  150.             println("East Falador Bank");
  151.             println("Draynor Bank");
  152.             return false;
  153.         }
  154.        
  155.         final RSItem[] tinderboxes = Inventory.find("Tinderbox");
  156.         final RSItem[] logs = Inventory.find(this.logType);
  157.         if (tinderboxes.length <= 0 && logs.length <= 0) {
  158.             if (!this.bank()) return false;
  159.         } else {
  160.             this.walkToOpenGround();
  161.         }
  162.        
  163.         return true;
  164.     }
  165.  
  166.     private int mainLoop() {
  167.         println("Starting main loop...");
  168.        
  169.         if (!this.makeFire()) {
  170.             println("A fire was unable to be made...");
  171.             if (!this.bank()) return -1;
  172.         }
  173.        
  174.         return 50;
  175.     }
  176.    
  177.     private boolean bank() {
  178.         this.walkToBank();
  179.         return this.emptyInventoryAndGetTinderboxAndLogsAndWalkBackToOpenGround();
  180.     }
  181.    
  182.     private boolean isInBank() {
  183.         final RSObject[] booths = Objects.findNearest(20,  "Bank booth");
  184.         if (booths.length > 0) {
  185.             if (booths[0].isOnScreen()) {
  186.                 return true;
  187.             }
  188.         }
  189.        
  190.         final RSNPC[] bankers = NPCs.findNearest("Banker");
  191.         if (bankers.length > 0) {
  192.             if (bankers[0].isOnScreen()) {
  193.                 return true;
  194.             }
  195.         }
  196.        
  197.         return false;
  198.     }
  199.    
  200.     private boolean walkToBank() {
  201.         println("Walking to bank...");
  202.         if (!WebWalking.walkToBank()) {
  203.             return false;
  204.         }
  205.        
  206.         return true;
  207.     }
  208.    
  209.     private boolean emptyInventoryAndGetTinderboxAndLogsAndWalkBackToOpenGround() {
  210.         println("Banking...");
  211.         if (!Banking.isBankScreenOpen()) {
  212.             if (!Banking.openBank()) {
  213.                 return false;
  214.             }
  215.         }
  216.         sleep(1000); //Sleep to allow the bank screen to open and the "player" to find what they are looking for
  217.        
  218.         println("Making sure bank is open. Current status: " + Banking.isBankScreenOpen());
  219.        
  220.         Banking.depositAllExcept("Tinderbox", this.logType);
  221.        
  222.         if (Inventory.getCount("Tinderbox") == 0) {
  223.             if (!Banking.withdraw(1, "Tinderbox")) {
  224.                 println("Unable to withdraw Tinderbox...");
  225.                 return false;
  226.             }
  227.         }
  228.        
  229.         if (!Banking.withdraw(0, this.logType)) {
  230.             println("Unable to withdraw Logs...");
  231.             return false;
  232.         }
  233.        
  234.         Banking.close();
  235.        
  236.         return this.walkToOpenGround();
  237.     }
  238.    
  239.     private boolean isMakingFire() {
  240.         return Player.getAnimation() == 733;
  241.     }
  242.    
  243.     private boolean makeFire() {
  244.         println("Making fire...");
  245.         //TODO: Consider putting the beef of this function in a while loop, so we continuously make logs as long as ground underneath us is clear and we have logs
  246.        
  247.         if (!isGroundOpen()) {
  248.             println("Ground is not open...");
  249.             walkToOpenGround();
  250.         }
  251.        
  252.         final RSItem[] tinderboxes = Inventory.find("Tinderbox");
  253.         final RSItem[] logs = Inventory.find(logType);
  254.         if (tinderboxes.length > 0 && logs.length > 0) {
  255.             if (!tinderboxes[0].click()) {
  256.                 println("Was unable to click Tinderbox...");
  257.                 return false;
  258.             }
  259.            
  260.             println("Using tinderbox on logs...");
  261.             if (!logs[0].click()) {
  262.                 println("Was unable to click logs...");
  263.                 return false;
  264.             }
  265.            
  266.             sleep(1000); //Sleep for a bit to allow to character to begin making the fire
  267.         } else {
  268.             println("No Tinderbox/Logs found in inventory when trying to make fire...");
  269.             return false;
  270.         }
  271.        
  272.         Date startTime = new Date();
  273.         while (true) {
  274.             println("In fire making loop...");
  275.             if (!isMakingFire()) break;
  276.             if (this.ABC.performTimedAntibans()) startTime = new Date();
  277.             sleep(500);
  278.         }
  279.         Date endTime = new Date();
  280.         int timeToStartFire = (int) (endTime.getTime() - startTime.getTime() - 250); //Subtract 250 to split the sleep time of 500 milliseconds, as we are not sure if all of it was necessary
  281.         timeToStartFire = (timeToStartFire > 0) ? timeToStartFire : timeToStartFire + 250; //If we subtracted so much time that we get a negative wait period, add the time back
  282.        
  283.         println("Entering sleepForReactionTime() for a wait time of " + timeToStartFire);
  284.         this.ABC.sleepForReactionTime(timeToStartFire);
  285.        
  286.         return true;
  287.     }
  288.    
  289.     private boolean isLocationOpen(RSTile location) {
  290.         if (location == null) return false;
  291.        
  292.         RSObject[] objectsAtCurrentLocation = Objects.getAt(location);
  293.         for (RSObject object : objectsAtCurrentLocation) {
  294.             String objectName = object.getDefinition().getName();
  295.             if (BAD_OBJECTS.contains(objectName)) {
  296.                 return false;
  297.             }
  298.         }
  299.        
  300.         return true;
  301.     }
  302.    
  303.     private boolean isGroundOpen() {
  304.         return this.isLocationOpen(Player.getPosition());
  305.     }
  306.    
  307.     private boolean walkToOpenGround() {
  308.         println("Walking to open ground...");
  309.         this.ABC.activateRunIfAboveThreshhold();
  310.         RSTile currentLocation = Player.getPosition();
  311.        
  312.         int xCoord = currentLocation.getX() - 1, yCoord = currentLocation.getY();
  313.         if (cityTile.equals(WEST_VARROCK_BANK)) {
  314.             println("Using WEST_VARROCK__COORDS...");
  315.             xCoord = WEST_VARROCK_X_COORDS[(int) (Math.random() * WEST_VARROCK_X_COORDS.length)];
  316.             yCoord = WEST_VARROCK_Y_COORDS[(int) (Math.random() * WEST_VARROCK_Y_COORDS.length)];
  317.         } else if (cityTile.equals(EAST_VARROCK_BANK)) {
  318.             println("Using EAST_VARROCK__COORDS...");
  319.             xCoord = EAST_VARROCK_X_COORDS[(int) (Math.random() * EAST_VARROCK_X_COORDS.length)];
  320.             yCoord = EAST_VARROCK_Y_COORDS[(int) (Math.random() * EAST_VARROCK_Y_COORDS.length)];
  321.         } else if (cityTile.equals(EAST_FALADOR_BANK)) {
  322.             println("Using EAST_FALADOR__COORDS...");
  323.             xCoord = EAST_FALADOR_X_COORDS[(int) (Math.random() * EAST_FALADOR_X_COORDS.length)];
  324.             yCoord = EAST_FALADOR_Y_COORDS[(int) (Math.random() * EAST_FALADOR_Y_COORDS.length)];
  325.         } else if (cityTile.equals(DRAYNOR_BANK)) {
  326.             println("Using DRAYNOR__COORDS...");
  327.             xCoord = DRAYNOR_X_COORDS[(int) Math.random() * DRAYNOR_X_COORDS.length];
  328.             yCoord = DRAYNOR_Y_COORDS[(int) Math.random() * DRAYNOR_Y_COORDS.length];
  329.         }
  330.        
  331.         println("xCoord = " + xCoord + ", yCoord = " + yCoord);
  332.         RSTile newLocation = new RSTile(xCoord, yCoord);
  333.        
  334.         if (newLocation.isOnScreen()) {
  335.             println("Clicking on new location...");
  336.             if (!newLocation.click()) {
  337.                 return false;
  338.             } else {
  339.                 while (!currentLocation.equals(newLocation)) {
  340.                     currentLocation = Player.getPosition().clone();
  341.                     sleep(100);
  342.                 }
  343.             }
  344.         } else {
  345.             if (!WebWalking.walkTo(newLocation)) {
  346.                 return false;
  347.             }
  348.         }
  349.        
  350.         if (!this.isLocationOpen(newLocation)) {
  351.             sleep(100);
  352.             return this.walkToOpenGround();
  353.         }
  354.        
  355.         return true;
  356.     }
  357.    
  358.     @Override
  359.     public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) {
  360.         // TODO Auto-generated method stub
  361.         return null;
  362.     }
  363.  
  364.     @Override
  365.     public int getTransparency() {
  366.         // TODO Auto-generated method stub
  367.         return 0;
  368.     }
  369.    
  370.     @Override
  371.     public void serverMessageReceived(String arg0) {
  372.         if (arg0.equals("You can't light a fire here.")) {
  373.             println("You tried to light a fire where you shouldn't have!...");
  374.             this.walkToOpenGround();
  375.         }
  376.     }
  377.  
  378.     @Override
  379.     public void clanMessageReceived(String arg0, String arg1) {}
  380.     @Override
  381.     public void duelRequestReceived(String arg0, String arg1) {}
  382.     @Override
  383.     public void personalMessageReceived(String arg0, String arg1) {}
  384.     @Override
  385.     public void playerMessageReceived(String arg0, String arg1) {}
  386.     @Override
  387.     public void tradeRequestReceived(String arg0) {}
  388. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement