Jump to content

[Snippet] Prayers Compatibility


Recommended Posts

Posted (edited)

Examples:

 

1)

PrayerCompatibility.areCompatible(PrayerButton.BURST_OF_STRENGTH, PrayerButton.MYSTIC_LORE); // -> false

2)

 

0a74794d1b14dd8b81e6da22a9469518.gif

 

Code:

package org.botre.prayer;

import org.osbot.rs07.api.ui.PrayerButton;

public class PrayerCompatibility {

	private enum Wrapper {

		THICK_SKIN(PrayerButton.THICK_SKIN, (byte)0b00000001), 
		BURST_OF_STRENGTH(PrayerButton.BURST_OF_STRENGTH, (byte)0b00001010),
		CLARITY_OF_THOUGHT(PrayerButton.CLARITY_OF_THOUGHT, (byte)0b00010100),
		SHARP_EYE(PrayerButton.SHARP_EYE, (byte)0b00011110),
		MYSTIC_WILL(PrayerButton.MYSTIC_WILL, (byte)0b00011110),
		ROCK_SKIN(PrayerButton.ROCK_SKIN, (byte)0b00000001),
		SUPERHUMAN_STRENGTH(PrayerButton.SUPERHUMAN_STRENGTH, (byte)0b00001010),
		IMPROVED_REFLEXES(PrayerButton.IMPROVED_REFLEXES, (byte)0b00010100),
		RAPID_RESTORE(PrayerButton.RAPID_RESTORE, (byte)0b00000000),
		RAPID_HEAL(PrayerButton.RAPID_HEAL, (byte)0b00000000), 
		PROTECT_ITEM(PrayerButton.PROTECT_ITEM, (byte)0b00000000),
		HAWK_EYE(PrayerButton.HAWK_EYE, (byte)0b00011110),
		MYSTIC_LORE(PrayerButton.MYSTIC_LORE, (byte)0b00011110), 
		STEEL_SKIN(PrayerButton.STEEL_SKIN, (byte)0b00000001), 
		ULTIMATE_STRENGTH(PrayerButton.ULTIMATE_STRENGTH, (byte)0b00001010),
		INCREDIBLE_REFLEXES(PrayerButton.INCREDIBLE_REFLEXES, (byte)0b00010100),
		PROTECT_FROM_MAGIC(PrayerButton.PROTECT_FROM_MAGIC, (byte)0b00100000), 
		PROTECT_FROM_MISSILES(PrayerButton.PROTECT_FROM_MISSILES, (byte)0b00100000),
		PROTECT_FROM_MELEE(PrayerButton.PROTECT_FROM_MELEE, (byte)0b00100000),
		EAGLE_EYE(PrayerButton.EAGLE_EYE, (byte)0b00011110),
		MYSTIC_MIGHT(PrayerButton.MYSTIC_MIGHT, (byte)0b00011110), 
		RETRIBUTION(PrayerButton.RETRIBUTION, (byte)0b00100000),
		REDEMPTION(PrayerButton.REDEMPTION, (byte)0b00100000), 
		SMITE(PrayerButton.SMITE, (byte)0b00100000),
		CHIVALRY(PrayerButton.CHIVALRY, (byte)0b00011111),
		PIETY(PrayerButton.PIETY, (byte)0b00011111);

		private PrayerButton prayer;
		private byte types;

		private Wrapper(PrayerButton prayer, byte types) {
			this.prayer = prayer;
			this.types = types;
		}

	}

	public static byte forPrayer(PrayerButton prayer) {
		for (Wrapper value : Wrapper.values()) {
			if(value.prayer == prayer) return value.types;
		}
		throw new UnsupportedOperationException("Unable to determine types for: " + prayer);
	}

	public static PrayerButton[] findIncompatible(PrayerButton... prayers) {
		for (PrayerButton prayer : prayers) {
			byte b = forPrayer(prayer);
			for (PrayerButton other : prayers) {
				if(prayer == other) continue;
				byte o = forPrayer(other);
				if((b & o)!= 0) return new PrayerButton[]{prayer, other};
			}
		}
		return null;
	}

	public static boolean areCompatible(PrayerButton... prayers) {
		return findIncompatible(prayers) != null;
	}

}
Edited by Botre
  • Like 5

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