Jump to content

[Snippet] Prayers Compatibility


Botre

Recommended Posts

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