Jump to content
Mr def nerd

Fairy rings [Snippet]

Recommended Posts

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

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