Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- import java.util.function.BooleanSupplier;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api.types.generic.Condition;
- import org.tribot.api2007.Banking;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Objects;
- import org.tribot.api2007.PathFinding;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.WebWalking;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.api2007.types.RSObject.TYPES;
- 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 2", version = 0.2, description = "Makes fires.", gameMode = 1)
- public class Firemaker2 extends Script implements MessageListening07 {
- private String logType;
- private RSTile cityTile;
- private STATE state;
- private final AntiBanExtenderUtil ABC = new AntiBanExtenderUtil();
- @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";
- //TODO: Consider creating a drop down menu so the player can specify which bank they want to use rather than determining it via proximity
- 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;
- }
- if (this.hasTinderbox() && this.hasLogs()) {
- this.state = STATE.WALK_TO_OPEN_GROUND;
- } else {
- this.state = STATE.WALK_TO_BANK;
- }
- return true;
- }
- private int mainLoop() {
- switch (STATE.valueOf(this.state.toString())) {
- case WALK_TO_OPEN_GROUND:
- println("Walking to open ground...");
- this.walkToOpenGround();
- break;
- case WALK_TO_BANK:
- println("Walking to bank...");
- this.walkToBank();
- break;
- case BANK:
- println("Banking...");
- this.bank();
- break;
- case MAKE_FIRE:
- println("Making fire...");
- this.makeFire();
- break;
- case EXIT:
- return -1;
- }
- return 50;
- }
- public void walkToBank() {
- WebWalking.walkToBank();
- this.state = STATE.BANK;
- }
- public boolean tryMethod(BooleanSupplier function, int repeat, long delay) {
- for (int i = 0; i < repeat; i++) {
- if (function.getAsBoolean()) {
- println("tryMethod succeded on try # " + i);
- return true;
- }
- else sleep(delay);
- }
- return false;
- }
- private void bank() {
- if (!Banking.isBankScreenOpen()) {
- if(!this.tryMethod(Banking::openBank, 3, 250)) {
- this.state = STATE.EXIT;
- return;
- } else {
- sleep(500); //Allows bank to open because Banking::openBank seems to return true as soon as the banker/booth is clicked
- }
- }
- Banking.depositAllExcept("Tinderbox", this.logType);
- if (Inventory.getCount("Tinderbox") == 0) {
- boolean tinderboxWithdrawSuccess = Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Banking.withdraw(1, "Tinderbox");
- }
- }, General.random(2000, 3000));
- if (!tinderboxWithdrawSuccess) {
- println("Unable to withdraw Tinderbox...");
- Banking.close();
- this.state = STATE.EXIT;
- return;
- }
- }
- boolean logWithdrawSuccess = Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Banking.withdraw(1, logType);
- }
- }, General.random(2000, 3000));
- if (!logWithdrawSuccess) {
- println("Unable to withdraw Logs...");
- Banking.close();
- this.state = STATE.EXIT;
- return;
- }
- Banking.close();
- this.state = STATE.WALK_TO_OPEN_GROUND;
- }
- private void makeFire() {
- if (!this.isLocationOpen(Player.getPosition())) {
- println("Ground is not open, walking to open ground...");
- this.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...");
- this.state = STATE.EXIT;
- return;
- }
- println("Using tinderbox on logs...");
- if (!logs[0].click()) {
- println("Was unable to click logs...");
- this.state = STATE.EXIT;
- return;
- }
- sleep(1000); //Sleep for a bit give the animation a chance to change
- } else {
- println("No Tinderbox/Logs found in inventory when trying to make fire...");
- this.state = STATE.WALK_TO_BANK;
- return;
- }
- Date startTime = new Date();
- while (isMakingFire()) {
- println("In fire making loop, time since last mouse action is " + (new Date().getTime() - startTime.getTime()) + " milliseconds...");
- if (this.ABC.performTimedAntibans()) {
- startTime = new Date();
- println("Performed timed antiban, resetting start time...");
- }
- 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);
- }
- private void walkToOpenGround() {
- 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()) {
- this.state = STATE.EXIT;
- return;
- } else {
- while (!currentLocation.equals(newLocation)) {
- currentLocation = Player.getPosition().clone();
- sleep(100);
- }
- }
- } else {
- if (!WebWalking.walkTo(newLocation)) {
- this.state = STATE.EXIT;
- return;
- }
- }
- if (!this.isLocationOpen(newLocation)) {
- sleep(100);
- this.walkToOpenGround();
- }
- this.state = STATE.MAKE_FIRE;
- }
- 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;
- // }
- // }
- //TODO: Test this way of determining if a fire is able to be made at this location to make sure it actually works
- RSObject[] objectsAtLocation = Objects.getAt(location);
- for (RSObject object : objectsAtLocation) {
- if (object.getType().equals(TYPES.INTERACTIVE)) {
- return false;
- }
- }
- return PathFinding.isTileWalkable(location.getPosition());
- }
- private boolean isMakingFire() {
- return Player.getAnimation() == 733;
- }
- private boolean hasLogs() {
- final RSItem[] logs = Inventory.find(this.logType);
- return logs.length > 0;
- }
- private boolean hasTinderbox() {
- final RSItem[] tinderboxes = Inventory.find("Tinderbox");
- return tinderboxes.length > 0;
- }
- enum STATE {
- WALK_TO_OPEN_GROUND,
- WALK_TO_BANK,
- BANK,
- MAKE_FIRE,
- EXIT
- }
- 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 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.state = STATE.WALK_TO_OPEN_GROUND;
- }
- }
- @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