Jump to content

Fairy rings [Snippet]


Recommended Posts

Posted (edited)

Okay, so I just finished fairy rings for my web walker. I know there was a tutorial released a while back, but I can't seem to find it, so I am releasing this. I have an enum for the location codes, but its not done yet so I am not releasing it yet

 

To see it in action, please visit this post

 

The fairy ring class

import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.MethodProvider;

public class FairyRing {
	
	public static String[] LETTERS = {"a", "d", "c", "b", "i", "l", "k", "j", "p", "s", "r", "q"};
	
	private MethodProvider ctx;
	public FairyRing(MethodProvider ctx) {
		this.ctx = ctx;
	}
	
	public boolean setRing(String combination) {
		if (ctx.widgets.isVisible(398)) {
			for (int i = 0; i < 3; i++) {
				long start = System.currentTimeMillis();
				int value = getValue(""+combination.charAt(i));
				while (getRowConfig(i) != value && System.currentTimeMillis() - start <= 4000) {
					RS2Widget w = ctx.widgets.get(398, 19 + (i * 2));
					if (w != null) {
						if (w.interact("Rotate clockwise")) {
							try {
								MethodProvider.sleep(MethodProvider.random(1000, 1250));
							} catch (InterruptedException e) {}
						}
					}
				}
			}
			if (isValid(combination)) {
				return clickTeleport();
			}
			return false;
		}
		return false;
	}
	
	private boolean clickTeleport() {
		RS2Widget w = ctx.widgets.get(398, 26);
		if (w != null && w.isVisible()) {
			return w.interact("Confirm");
		}
		return false;
	}
	
	public boolean isInterfaceOpen() {
		return ctx.widgets.isVisible(398);
	}
	
	public boolean isValid(String combination) {
		for (int i = 0; i < 3; i++) {
			int value = getValue(""+combination.charAt(i));
			if (getRowConfig(i) != value)
				return false;
		}
		return true;
	}
	
	public int getValue(String letter) {
		for (int i = 0; i < LETTERS.length; i++) {
			if (letter.toLowerCase().equals(LETTERS[i])) {
				return i % 4;
			}
		}
		return -1;
	}
	
	public int getRowConfig(int row) {
		switch(row) {
			case 0:
				return ctx.configs.get(816) & 0x3;
			case 1:
				return (ctx.configs.get(816) >> 2) & 0x3;
			case 2:
				return (ctx.configs.get(816) >> 4) & 0x3;
		}
		return 0;
	}

}
 

 

Use as

instance.setRing("dkr");
Edited by Mrsdefnerd
  • Like 8

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...