Merge pull request #38 from Parabot/Prayer-class

[FEATURE] Added Prayer class
This commit is contained in:
Jeroen Ketelaar
2016-01-10 15:16:57 +01:00
@@ -3,11 +3,26 @@ package org.rev317.min.api.methods;
import org.parabot.environment.api.utils.Time; import org.parabot.environment.api.utils.Time;
import org.parabot.environment.scripts.framework.SleepCondition; import org.parabot.environment.scripts.framework.SleepCondition;
import java.util.ArrayList;
/** /**
* @author JKetelaar, Fryslan * @author JKetelaar, Fryslan
* TODO Set the actual level requirements * TODO Set the actual level requirements
* TODO Set curses setting and action ids.
*/ */
public enum Prayer { public class Prayer {
public interface Book {
public int getSetting();
public int getAction();
public int getLevel();
public String getName();
}
public enum Normal implements Book {
THICK_SKIN(83, 5609, 1), THICK_SKIN(83, 5609, 1),
BURST_OF_STRENGTH(84, 5610, 1), BURST_OF_STRENGTH(84, 5610, 1),
CLARITY_OF_THOUGHT(85, 5611, 1), CLARITY_OF_THOUGHT(85, 5611, 1),
@@ -43,7 +58,7 @@ public enum Prayer {
private int action; private int action;
private int level; private int level;
Prayer(int setting, int action, int level) { Normal(int setting, int action, int level) {
this.setting = setting; this.setting = setting;
this.action = action; this.action = action;
this.level = level; this.level = level;
@@ -78,44 +93,145 @@ public enum Prayer {
/** /**
* Returns the name of the prayer action * Returns the name of the prayer action
* * <p/>
* TODO Get the actual string from the variable * TODO Get the actual string from the variable
* *
* @return String containing the name of the prayer action * @return String containing the name of the prayer action
*/ */
public String getName() { public String getName() {
return name().charAt(0)+name().substring(1).toLowerCase().replace("_", " "); return name().charAt(0) + name().substring(1).toLowerCase().replace("_", " ");
} }
public int getSettingID() { }
public enum Curse implements Book {
PROTECT_ITEM_CURSE(0, 0, 50),
SAP_WARRIOR(0, 0, 50),
SAP_RANGER(0, 0, 52),
SAP_MAGE(0, 0, 54),
SAP_SPIRIT(0, 0, 56),
BERSERKER(0, 0, 59),
DEFLECT_SUMMONING(0, 0, 62),
DEFLECT_MAGIC(0, 0, 65),
DEFLECT_MISSILE(0, 0, 68),
DEFLECT_MELEE(0, 0, 71),
LEECH_ATTACK(0, 0, 74),
LEECH_RANGE(0, 0, 76),
LEECH_MAGIC(0, 0, 78),
LEECH_DEFENCE(0, 0, 80),
LEECH_STRENGTH(0, 0, 82),
LEECH_ENERGY(0, 0, 84),
LEECH_SPECIAL_ATTACK(0, 0, 86),
WRATH(0, 0, 89),
SOUL_SPLIT(0, 0, 92),
TURMOIL(0, 0, 95);
private int setting;
private int action;
private int level;
Curse(int setting, int action, int level) {
this.setting = setting;
this.action = action;
this.level = level;
}
/**
* Returns the required level for the requested prayer action
*
* @return Int standing for the required level
*/
public int getLevel() {
return level;
}
/**
* Returns the setting ID that can be used for detecting if it's enabled or not
*
* @return Int that stands for the setting ID
*/
public int getSetting() {
return setting; return setting;
} }
public boolean isEnabled(){ /**
return Game.getSetting(setting) == 1; * The action ID that can be used to perform a direct action within the client
*
* @return Int standing for the action ID
*/
public int getAction() {
return action;
} }
public void enable() { /**
if (!isEnabled()) { * Returns the name of the prayer action
Menu.sendAction(169, -1, -1, action); * <p/>
* TODO Get the actual string from the variable
*
* @return String containing the name of the prayer action
*/
public String getName() {
return name().charAt(0) + name().substring(1).toLowerCase().replace("_", " ");
}
}
public static boolean isEnabled(Book book) {
return Game.getSetting(book.getSetting()) == 1;
}
public static void enable(final Book book) {
if (!isEnabled(book)) {
Menu.sendAction(169, -1, -1, book.getAction());
Time.sleep(new SleepCondition() { Time.sleep(new SleepCondition() {
@Override @Override
public boolean isValid() { public boolean isValid() {
return isEnabled(); return isEnabled(book);
} }
}, 1500); }, 1500);
} }
} }
public void disable() { public static void disable(final Book book) {
if (isEnabled()) { if (isEnabled(book)) {
Menu.sendAction(169, -1, -1, action); Menu.sendAction(169, -1, -1, book.getAction());
Time.sleep(new SleepCondition() { Time.sleep(new SleepCondition() {
@Override @Override
public boolean isValid() { public boolean isValid() {
return !isEnabled(); return !isEnabled(book);
} }
}, 1500); }, 1500);
} }
} }
public static Book[] getActivePrayers() {
ArrayList<Book> prayers = new ArrayList<>();
for (Book normal : Normal.values()) {
if (isEnabled(normal)) {
prayers.add(normal);
}
}
for (Book curse : Curse.values()) {
if (isEnabled(curse)) {
prayers.add(curse);
}
}
return prayers.toArray(new Book[prayers.size()]);
}
public static void setActivePrayers(Book[] prayers) {
for (Book book : prayers) {
for (Book normal : Normal.values()) {
if (!isEnabled(normal) && normal.equals(book)) {
enable(normal);
}
}
for (Book curse : Curse.values()) {
if (!isEnabled(curse) && curse.equals(book)) {
enable(curse);
}
}
}
}
} }