Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Resource Simple addition to the node framework

mad

Joined
Jan 5, 2015
Messages
17
Code:
public class ModuleWrapper {

    private LinkedHashMap<Condition, ArrayList<Module>> arrayListMap = new LinkedHashMap<>();

    public ArrayList addModuleList(Condition condition) {
        return arrayListMap.put(condition, new ArrayList<>());
    }

    private ArrayList<Module> getMapKey(int key) {
        return arrayListMap.get(arrayListMap.keySet().toArray()[key]);
    }

    public void submit(final Module module, int key) {
        if(getMapKey(key) !=null) {
            getMapKey(key).add(module);
        }
    }

    public ArrayList<Module> getValidList() {
        ArrayList<Module> validList = new ArrayList<>();
        arrayListMap.forEach((aBoolean, modules) -> {
                if(aBoolean.check()) {
                    modules.forEach(validList::add);
                }
        });
        return validList;
    }

    public Module getValidModule() {
        for(Module m : getValidList()) {
            if(m.validate())
                return m;
        }
        return null;
    }
}

Module Interface
Code:
public interface Module {

    boolean validate();

    void execute();

}

Condition Interface
Code:
public interface Condition {

    boolean check();

}

Usage:
Code:
   public boolean onStart() {
            mw.addModuleList(Bank::isOpen);
            mw.addModuleList(() -> !Bank.isOpen());
            mw.submit(new Example(), 0);
            mw.submit(new Example2(), 1);
        return true;
    }

You can add array lists and then add modules to those array lists by putting the index of the array list in the hashmap as a parameter in the submit.

Then getValidModule gets the valid array list and then iterates through that valid list for modules that are valid.

This is a really easy way to split up scripts into sections.
 
Joined
Apr 18, 2015
Messages
408
The Task system is much easier in my opinion.. (and already supported by RM)

Main:
JavaScript:
@Override
public void onStart(String... args) {
add(new ChopTreeTask());
}

ChopTreeTask.java
JavaScript:
public class ChopTreeTask extends Task {
@Override
public boolean validate() {
return Skill.WOODCUTTING.getBaseLevel() > 60;
}

@Override
public void execute() {
tree = GameObjects.newQuery().names("Yew").results().nearest();
if(tree != null) {
tree.interact("Chop");
}
}
}
 
Top