Articron 738 Share Posted September 2, 2017 Feel free to give criticism/tips Utility methods for quick prayer management package io.articron.cronfighter.feature; import io.articron.cronfighter.fw.ScriptEnvironment; import org.dreambot.api.methods.prayer.Prayer; import org.dreambot.api.wrappers.widgets.WidgetChild; import java.util.Arrays; import java.util.stream.Collectors; /** * Author: Articron * Date: 2/09/2017. */ public class QuickPrayer { private ScriptEnvironment env; private final int PARENT_WIDGET = 77; private final int SUB_PARENT_WIDGET = 4; private final int ORB_WIDGET = 160; private final int PRAYER_ORB = 14; private final int QUICK_PRAYER_SETTING = 83; private final int QUICK_PRAYER_ACTIVE_SETTING = 375; private final int DONE_BUTTON = 5; public QuickPrayer(ScriptEnvironment env) { this.env = env; } public boolean isOpen() { WidgetChild quickPrayerScreen = getQuickPrayerWidget(); return quickPrayerScreen != null && quickPrayerScreen.isVisible(); } public boolean open() { if (isOpen()) return true; WidgetChild prayerOrb = getPrayerOrb(); return (prayerOrb != null) && prayerOrb.isVisible() && prayerOrb.interact("Setup"); } public boolean close() { if (!isOpen()) return true; WidgetChild closeButton = env.getDreambot().getWidgets().getWidgetChild(PARENT_WIDGET,DONE_BUTTON); return (closeButton != null) && closeButton.interact("Done"); } public boolean tickPrayer(boolean on, Prayer prayer) { if (!isOpen()) return open() && tickPrayer(on,prayer); if (isTicked(prayer) != on) { WidgetChild prayerBox = getQuickPrayerWidget().getChild(prayer.getChildIndex() - 4); return prayerBox.interact("Toggle") && tickPrayer(on,prayer); } return on == isTicked(prayer); } public boolean tickPrayers(boolean on, Prayer... prayers) { return Arrays.stream(prayers).anyMatch(p -> !tickPrayer(on,p)); } public boolean isActive() { return env.getDreambot().getPlayerSettings().getConfig(QUICK_PRAYER_ACTIVE_SETTING) == 1; } public boolean setActive(boolean active) { return getPrayerOrb().interact(active ? "Activate" : "Deactivate"); } public boolean isTicked(Prayer prayer) { return ((env.getDreambot().getPlayerSettings().getConfig(QUICK_PRAYER_SETTING) & prayer.getSetting()) == prayer.getSetting()); } public boolean isTicked(Prayer... prayers) { return Arrays.stream(prayers) .allMatch(this::isTicked); } public Prayer[] getTickedPrayers() { return (Prayer[]) Arrays.stream(Prayer.values()) .filter(this::isTicked) .collect(Collectors.toList()) .toArray(); } private WidgetChild getQuickPrayerWidget() { return env.getDreambot().getWidgets().getWidgetChild(PARENT_WIDGET,SUB_PARENT_WIDGET); } private WidgetChild getPrayerOrb() { return env.getDreambot().getWidgets().getWidgetChild(ORB_WIDGET,PRAYER_ORB); } } Link to comment Share on other sites More sharing options...
Manly 879 Share Posted September 2, 2017 Nice. Another method you could add is flashing prayers Link to comment Share on other sites More sharing options...
Articron 738 Author Share Posted September 2, 2017 Nice. Another method you could add is flashing prayers I have that but I purposely took that one out Link to comment Share on other sites More sharing options...
Dinh 496 Share Posted September 2, 2017 Make Snippets great again, thanks mr. cron Link to comment Share on other sites More sharing options...
century 26 Share Posted September 2, 2017 Excellent. +1 Link to comment Share on other sites More sharing options...
Articron 738 Author Share Posted September 3, 2017 Excellent. +1 Cheers mate Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.