Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • QuickPrayer class


    Articron
     Share

    Recommended Posts

    Feel free to give criticism/tips :) 

     

    Utility methods for quick prayer management  :ph34r:

    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

    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
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.