Jump to content

Why is my script not stopping?


Recommended Posts

Posted

Once it finishes the dialog with the wizard, it loops back to the bank and tries to get beads again. What am I doing wrong here? I've tried different variations and can't get it to stop once it sees the "Congratulations" message! :(

package quests;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.*;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.utility.ConditionalSleep;

public class ImpCatcher extends QuestObject {
	private Area wizardsTower;

	private Area[] area = { new Area(3103, 3162, 3105, 3164).setPlane(2), // wizards tower
	};

	private String[] items = new String[] { "Red bead", "Black bead", "Yellow bead", "White bead" };

	public ImpCatcher() {
		wizardsTower = area[0];
	}

	@Override
	public int run() throws InterruptedException {
		if (!checkInventory()) {
			return 1;
		}
		switch (configs.get(808)) {
		case 0:
			startQuest();
			break;
		case 1:
            if (completeQuest()) {
                log("Quest Complete!");
                return 2;
            }
		case 2:
			log("Quest has already been completed!");
		default:
			return 2;
		}
		return 1;
	}

	private boolean checkInventory() throws InterruptedException {
		boolean inventoryReady = getInventory().contains(items);
		if (!inventoryReady && !Banks.DRAYNOR.contains(myPosition())) {
			getWalking().webWalk(Banks.DRAYNOR);
			return false;
		} else if (!inventoryReady && Banks.DRAYNOR.contains(myPosition())) {
			openBank();
			bankItems();
			takeBankItems();
			return true;
		} else {
			log("Inventory does not need to be banked!");
			return true;
		}
	}

	private void openBank() throws InterruptedException {
		if (!getBank().isOpen()) {
			getBank().open();
			log("Opening Bank...");
			new ConditionalSleep(5000) {
				@Override
				public boolean condition() throws InterruptedException {
					return getBank().isOpen();
				}
			}.sleep();
		} else {
			log("Bank is already open!");
		}
	}

	private void takeBankItems() {
		for (String item : items) {
			if (getBank().contains(item)) {
				log("Found item for quest: " + item);
				getBank().withdraw(item, 1);
			}
		}
	}

	private void bankItems() {
		if (getBank().depositAll()) {
			log("Deposited all items!");
		} else {
			log("There was an issue depositing all items!");
		}
	}

	private void walkToArea(Area area, String location) {
		log("Walking to: " + location);
		if (!area.contains(myPosition())) {
			getWalking().webWalk(area);
			new ConditionalSleep(5000) {
				@Override
				public boolean condition() throws InterruptedException {
					return area.contains(myPosition());
				}
			}.sleep();
		} else {
			log("Already in Area: " + location);
		}
	}

	private void startQuest() throws InterruptedException {
		RS2Widget widget = getWidgets().get(277, 1);
		// walk to the tower
		walkToArea(wizardsTower, "Wizard's tower");
		talkToWizard();
		new ConditionalSleep(5000) {
			@Override
			public boolean condition() throws InterruptedException {
				return widget != null && widget.isVisible();
			}
		}.sleep();
	}

	public boolean completeQuest() {
		RS2Widget widget = getWidgets().get(277, 1);
		return (widget != null && widget.isVisible());
	}

	private void talkToWizard() throws InterruptedException {
		Entity wizard = npcs.closest("Wizard Mizgog");
		if (wizard != null) {
			if (!getDialogues().inDialogue()) {
				log("Not talking to Mizgog. Starting conversation.");
				wizard.interact("Talk-to");
				log("Sleeping until conversation starts!");
				new ConditionalSleep(5000) {
					@Override
					public boolean condition() throws InterruptedException {
						return getDialogues().inDialogue();
					}
				}.sleep();
			}
			String[] options = new String[] { "Click here to continue", "Give me a quest please." };
			if (getDialogues().completeDialogue(options)) {
				log("Dialogue complete successfully!");
			} else {
				log("Dialogue failed!");
			}
			log("Just spoke with Mizgog!");
		}
	}
}

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...