Jump to content

[Snippet] Warrior's Guild API


Botre

Recommended Posts

Example

		WarriorsGuild wg = new WarriorsGuild(this);
		//...
		
		Defender next = wg.getNextDefender();
		if(next != null) {
			if(next == Defender.NONE) {
				//Go talk to Kamfreena
			}
			else if(next == Defender.RUNITE) {
				// If inventory contains rune defender -> go unlock Lorelai's door
				// Else -> continue killing regular cyclopses
			}
			else if(next == Defender.DRAGON) {
				// Kill high-level cyclopses
			}
			else {
				// Kill regular cyclopses
			}
		} 

Code

package org.botre.warriorsguild;

import java.awt.Point;

import org.osbot.rs07.script.MethodProvider;

public class WarriorsGuild {

	public static final int CONFIG = 788;
	
	public enum CatapultProjectile {
		
		SPIKED(679, CatapultDefenceStyle.STAB),
		ANVIL(680, CatapultDefenceStyle.BLUNT),
		KNIVES(681, CatapultDefenceStyle.SLASH),
		MAGICAL(682, CatapultDefenceStyle.MAGIC);
		
		private int id;
		private CatapultDefenceStyle defenceStyle;
		
		private CatapultProjectile(int id, CatapultDefenceStyle defenceStyle) {
			this.id = id;
			this.defenceStyle = defenceStyle;
		}
		
		public static CatapultProjectile forId(int id) {
			for (CatapultProjectile value : values()) {
				if(value.id == id) return value;
			}
			return null;
		}
		
		public int getId() {
			return id;
		}
		
		public CatapultDefenceStyle getDefenceStyle() {
			return defenceStyle;
		}
		
	}
	
	public enum CatapultDefenceStyle {
		
		STAB(1, new Point(564, 232)), 
		BLUNT(2, new Point(564, 288)), 
		SLASH(3, new Point(563, 344)),
		MAGIC(0, new Point(563, 401)); 
		
		private int maskedValue;
		private Point widgetPosition;
		
		private CatapultDefenceStyle(int maskedValue, Point widgetPosition) {
			this.maskedValue = maskedValue;
			this.widgetPosition = widgetPosition;
		}
		
		public int getMaskedValue() {
			return maskedValue;
		}
		
		public Point getWidgetPosition() {
			return widgetPosition;
		}
		
		public static CatapultDefenceStyle forConfigValue(int configValue) {
			for (CatapultDefenceStyle value : values()) {
				if(value.getMaskedValue() == (configValue & 0b00000011)) return value;
			}
			return null;
		}
		
	}
	
	public enum Defender {
		NONE(0),
		BRONZE(1),
		IRON(2),
		STEEL(3),
		BLACK(4),
		MITHRIL(5),
		ADAMANTITE(6),
		RUNITE(7),
		DRAGON(-1);
		
		private int maskedValue;
		
		private Defender(int maskedValue) {
			this.maskedValue = maskedValue;
		}
		
		public int getMaskedValue() {
			return maskedValue;
		}
		
		public static Defender forConfigValue(int configValue) {
			if(isLorelaisDoorUnlocked(configValue)) return Defender.DRAGON;
			for (Defender value : values()) {
				if(value.getMaskedValue() == ((configValue >> 3) & 0b000001111)) return value;
			}
			return null;
		}
		
	}
	
	private MethodProvider ctx;
	
	public WarriorsGuild(MethodProvider ctx) {
		this.ctx = ctx;
	}
	
	public CatapultDefenceStyle getCatapultDefenceStyle() {
		return CatapultDefenceStyle.forConfigValue(ctx.getConfigs().get(CONFIG));
	}
	
	public boolean isDefendingFromCatapultProjectile(CatapultProjectile projectile) {
		return getCatapultDefenceStyle() == projectile.getDefenceStyle();
	}
	
	public Defender getNextDefender() {
		return Defender.forConfigValue(ctx.getConfigs().get(CONFIG));
	}
	
	private static boolean isLorelaisDoorUnlocked(int configValue) {
		return ((configValue >> 12) & 0b00000001) == 1;
	}
	
	public boolean isLorelaisDoorUnlocked() {
		return isLorelaisDoorUnlocked(ctx.getConfigs().get(CONFIG));
	}
	
}
  • Like 4
Link to comment
Share on other sites

can u maybe make a enum guide for like Craftables (include like 5 examples of crafting stuff etc or fishing) that would be great thanks

 

ot: botre comin in hot with the snippets

public enum TestEnum {
SAPPHIRE("Sapphire", "blue", 1222, false); //here we add the name, color, price and if it's a member item.

private String name;
private String color;
private int price;
private boolean isMember;

/**
*
* @param name
* @param color
* @param price
* @param isMember
*/
TestEnum(String name, String color, int price, boolean isMember){
this.name = name;
this.color = color;
this.price = price;
this.isMember = isMember;
}

/**
*
* @return name
*/
public String getName(){
return name;
}

/**
*
* @return color
*/
public String getColor(){
return color;
}

/**
*
* @return price
*/
public int getPrice(){
return price;
}

/**
*
* @return ismember
*/
public boolean isMember(){
return isMember;
}
}

inventory.getItem(TestEnum.SAPPHIRE.getName());
2min work.

Google how enums work for a better understanding.

  • Like 1
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.
Note: Your post will require moderator approval before it will be visible.

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