Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts;
- import java.awt.Paint;
- import java.awt.PaintContext;
- import java.awt.Rectangle;
- import java.awt.RenderingHints;
- import java.awt.geom.AffineTransform;
- import java.awt.geom.Rectangle2D;
- import java.awt.image.ColorModel;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- import org.tribot.api2007.Banking;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.NPCs;
- import org.tribot.api2007.Objects;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.WebWalking;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSNPC;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.api2007.types.RSTile;
- import org.tribot.script.Script;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.MessageListening07;
- @ScriptManifest(authors = {"Ulsting"}, category = "Firemaking", name = "Ulsting's Firemaking", version = 0.01, description = "Makes fires of any log type near any bank.", gameMode = 1)
- public class Firemaker extends Script implements Paint, MessageListening07{
- private String logType;
- private RSTile cityTile;
- private final AntiBanExtenderUtil ABC = new AntiBanExtenderUtil();
- private final List<String> BAD_OBJECTS = new ArrayList<String>(Arrays.asList(
- "Fire",
- "Fern",
- "Daisies",
- "Tree",
- "Wilderness Sign"
- ));
- //West Varrock
- private final RSTile WEST_VARROCK_BANK = new RSTile(3183, 3440);
- private final int[] WEST_VARROCK_X_COORDS = { //X:[3192-3198]
- 3192,
- 3193, 3193,
- 3194, 3194, 3194,
- 3195, 3195, 3195, 3195,
- 3196, 3196, 3196,
- 3197, 3197,
- 3198
- };
- private final int[] WEST_VARROCK_Y_COORDS = { //Y:[3429-3432]
- 3429,
- 3430, 3430,
- 3431, 3431,
- 3432
- };
- //East Varrock
- private final RSTile EAST_VARROCK_BANK = new RSTile(3254, 3422);
- private final int[] EAST_VARROCK_X_COORDS = { //X:[3258-3265]
- 3258,
- 3259, 3259,
- 3260, 3260, 3260,
- 3261, 3261, 3261, 3261,
- 3262, 3262, 3262, 3262,
- 3263, 3263, 3263,
- 3264, 3264,
- 3265
- };
- private final int[] EAST_VARROCK_Y_COORDS = { //Y:[3428-3431]
- 3428,
- 3429, 3429,
- 3430, 3430,
- 3431
- };
- //EAST Falador
- private final RSTile EAST_FALADOR_BANK = new RSTile(2945, 3370);
- private final int[] EAST_FALADOR_X_COORDS = { //X:[2937-2942]
- 2937,
- 2938, 2938,
- 2939, 2939, 2939,
- 2940, 2940, 2940,
- 2941, 2941,
- 2942
- };
- private final int[] EAST_FALADOR_Y_COORDS = { //Y:[3370-3376]
- 3370,
- 3371, 3371,
- 3372, 3372, 3372,
- 3373, 3373, 3373, 3373,
- 3374, 3374, 3374,
- 3375, 3375,
- 3376
- };
- //Draynor
- private final RSTile DRAYNOR_BANK = new RSTile(3093, 3243);
- private final int[] DRAYNOR_X_COORDS = { //X:[3094-3097]
- 3094,
- 3095, 3095,
- 3096, 3096,
- 3097
- };
- private final int[] DRAYNOR_Y_COORDS = { //Y:[3247-3250]
- 3247,
- 3248, 3248,
- 3249, 3249,
- 3250
- };
- @Override
- public void run() {
- if (onStart()) {
- while (true) {
- int loopCode = this.mainLoop();
- if (loopCode == -1) break;
- else sleep(loopCode);
- }
- println("Exiting...");
- }
- }
- private boolean onStart () {
- //TODO: Create menu with drop down to get which type of log the user wants to burn
- this.logType = "Logs";
- RSTile currentLocation = Player.getPosition();
- if (currentLocation.distanceTo(WEST_VARROCK_BANK) <= 25) {
- cityTile = EAST_VARROCK_BANK.clone();
- println("You are near the western bank of Varrock.");
- } else if (currentLocation.distanceTo(EAST_VARROCK_BANK) <= 25) {
- cityTile = EAST_VARROCK_BANK.clone();
- println("You are near the eastern bank of Varrock.");
- } else if (currentLocation.distanceTo(EAST_FALADOR_BANK) <= 25) {
- cityTile = EAST_FALADOR_BANK.clone();
- println("You are near the eastern bank of Falador.");
- } else if (currentLocation.distanceTo(DRAYNOR_BANK) <= 25) {
- cityTile = DRAYNOR_BANK.clone();
- println("You are near Draynor Bank.");
- } else {
- println("Please be closer to one of the following banks:");
- println("East Varrock Bank");
- println("West Varrock Bank");
- println("East Falador Bank");
- println("Draynor Bank");
- return false;
- }
- final RSItem[] tinderboxes = Inventory.find("Tinderbox");
- final RSItem[] logs = Inventory.find(this.logType);
- if (tinderboxes.length <= 0 && logs.length <= 0) {
- if (!this.bank()) return false;
- } else {
- this.walkToOpenGround();
- }
- return true;
- }
- private int mainLoop() {
- println("Starting main loop...");
- if (!this.makeFire()) {
- println("A fire was unable to be made...");
- if (!this.bank()) return -1;
- }
- return 50;
- }
- private boolean bank() {
- this.walkToBank();
- return this.emptyInventoryAndGetTinderboxAndLogsAndWalkBackToOpenGround();
- }
- private boolean isInBank() {
- final RSObject[] booths = Objects.findNearest(20, "Bank booth");
- if (booths.length > 0) {
- if (booths[0].isOnScreen()) {
- return true;
- }
- }
- final RSNPC[] bankers = NPCs.findNearest("Banker");
- if (bankers.length > 0) {
- if (bankers[0].isOnScreen()) {
- return true;
- }
- }
- return false;
- }
- private boolean walkToBank() {
- println("Walking to bank...");
- if (!WebWalking.walkToBank()) {
- return false;
- }
- return true;
- }
- private boolean emptyInventoryAndGetTinderboxAndLogsAndWalkBackToOpenGround() {
- println("Banking...");
- if (!Banking.isBankScreenOpen()) {
- if (!Banking.openBank()) {
- return false;
- }
- }
- sleep(1000); //Sleep to allow the bank screen to open and the "player" to find what they are looking for
- println("Making sure bank is open. Current status: " + Banking.isBankScreenOpen());
- Banking.depositAllExcept("Tinderbox", this.logType);
- if (Inventory.getCount("Tinderbox") == 0) {
- if (!Banking.withdraw(1, "Tinderbox")) {
- println("Unable to withdraw Tinderbox...");
- return false;
- }
- }
- if (!Banking.withdraw(0, this.logType)) {
- println("Unable to withdraw Logs...");
- return false;
- }
- Banking.close();
- return this.walkToOpenGround();
- }
- private boolean isMakingFire() {
- return Player.getAnimation() == 733;
- }
- private boolean makeFire() {
- println("Making fire...");
- //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
- if (!isGroundOpen()) {
- println("Ground is not open...");
- walkToOpenGround();
- }
- final RSItem[] tinderboxes = Inventory.find("Tinderbox");
- final RSItem[] logs = Inventory.find(logType);
- if (tinderboxes.length > 0 && logs.length > 0) {
- if (!tinderboxes[0].click()) {
- println("Was unable to click Tinderbox...");
- return false;
- }
- println("Using tinderbox on logs...");
- if (!logs[0].click()) {
- println("Was unable to click logs...");
- return false;
- }
- sleep(1000); //Sleep for a bit to allow to character to begin making the fire
- } else {
- println("No Tinderbox/Logs found in inventory when trying to make fire...");
- return false;
- }
- Date startTime = new Date();
- while (true) {
- println("In fire making loop...");
- if (!isMakingFire()) break;
- if (this.ABC.performTimedAntibans()) startTime = new Date();
- sleep(500);
- }
- Date endTime = new Date();
- 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
- timeToStartFire = (timeToStartFire > 0) ? timeToStartFire : timeToStartFire + 250; //If we subtracted so much time that we get a negative wait period, add the time back
- println("Entering sleepForReactionTime() for a wait time of " + timeToStartFire);
- this.ABC.sleepForReactionTime(timeToStartFire);
- return true;
- }
- private boolean isLocationOpen(RSTile location) {
- if (location == null) return false;
- RSObject[] objectsAtCurrentLocation = Objects.getAt(location);
- for (RSObject object : objectsAtCurrentLocation) {
- String objectName = object.getDefinition().getName();
- if (BAD_OBJECTS.contains(objectName)) {
- return false;
- }
- }
- return true;
- }
- private boolean isGroundOpen() {
- return this.isLocationOpen(Player.getPosition());
- }
- private boolean walkToOpenGround() {
- println("Walking to open ground...");
- this.ABC.activateRunIfAboveThreshhold();
- RSTile currentLocation = Player.getPosition();
- int xCoord = currentLocation.getX() - 1, yCoord = currentLocation.getY();
- if (cityTile.equals(WEST_VARROCK_BANK)) {
- println("Using WEST_VARROCK__COORDS...");
- xCoord = WEST_VARROCK_X_COORDS[(int) (Math.random() * WEST_VARROCK_X_COORDS.length)];
- yCoord = WEST_VARROCK_Y_COORDS[(int) (Math.random() * WEST_VARROCK_Y_COORDS.length)];
- } else if (cityTile.equals(EAST_VARROCK_BANK)) {
- println("Using EAST_VARROCK__COORDS...");
- xCoord = EAST_VARROCK_X_COORDS[(int) (Math.random() * EAST_VARROCK_X_COORDS.length)];
- yCoord = EAST_VARROCK_Y_COORDS[(int) (Math.random() * EAST_VARROCK_Y_COORDS.length)];
- } else if (cityTile.equals(EAST_FALADOR_BANK)) {
- println("Using EAST_FALADOR__COORDS...");
- xCoord = EAST_FALADOR_X_COORDS[(int) (Math.random() * EAST_FALADOR_X_COORDS.length)];
- yCoord = EAST_FALADOR_Y_COORDS[(int) (Math.random() * EAST_FALADOR_Y_COORDS.length)];
- } else if (cityTile.equals(DRAYNOR_BANK)) {
- println("Using DRAYNOR__COORDS...");
- xCoord = DRAYNOR_X_COORDS[(int) Math.random() * DRAYNOR_X_COORDS.length];
- yCoord = DRAYNOR_Y_COORDS[(int) Math.random() * DRAYNOR_Y_COORDS.length];
- }
- println("xCoord = " + xCoord + ", yCoord = " + yCoord);
- RSTile newLocation = new RSTile(xCoord, yCoord);
- if (newLocation.isOnScreen()) {
- println("Clicking on new location...");
- if (!newLocation.click()) {
- return false;
- } else {
- while (!currentLocation.equals(newLocation)) {
- currentLocation = Player.getPosition().clone();
- sleep(100);
- }
- }
- } else {
- if (!WebWalking.walkTo(newLocation)) {
- return false;
- }
- }
- if (!this.isLocationOpen(newLocation)) {
- sleep(100);
- return this.walkToOpenGround();
- }
- return true;
- }
- @Override
- public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public int getTransparency() {
- // TODO Auto-generated method stub
- return 0;
- }
- @Override
- public void serverMessageReceived(String arg0) {
- if (arg0.equals("You can't light a fire here.")) {
- println("You tried to light a fire where you shouldn't have!...");
- this.walkToOpenGround();
- }
- }
- @Override
- public void clanMessageReceived(String arg0, String arg1) {}
- @Override
- public void duelRequestReceived(String arg0, String arg1) {}
- @Override
- public void personalMessageReceived(String arg0, String arg1) {}
- @Override
- public void playerMessageReceived(String arg0, String arg1) {}
- @Override
- public void tradeRequestReceived(String arg0) {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement