Resource Simple addition to the node framework

Discussion in 'Tutorials & Resources' started by Mad, Jun 26, 2015.

  1. Code (Text):
    1. public class ModuleWrapper {
    2.  
    3.     private LinkedHashMap<Condition, ArrayList<Module>> arrayListMap = new LinkedHashMap<>();
    4.  
    5.     public ArrayList addModuleList(Condition condition) {
    6.         return arrayListMap.put(condition, new ArrayList<>());
    7.     }
    8.  
    9.     private ArrayList<Module> getMapKey(int key) {
    10.         return arrayListMap.get(arrayListMap.keySet().toArray()[key]);
    11.     }
    12.  
    13.     public void submit(final Module module, int key) {
    14.         if(getMapKey(key) !=null) {
    15.             getMapKey(key).add(module);
    16.         }
    17.     }
    18.  
    19.     public ArrayList<Module> getValidList() {
    20.         ArrayList<Module> validList = new ArrayList<>();
    21.         arrayListMap.forEach((aBoolean, modules) -> {
    22.                 if(aBoolean.check()) {
    23.                     modules.forEach(validList::add);
    24.                 }
    25.         });
    26.         return validList;
    27.     }
    28.  
    29.     public Module getValidModule() {
    30.         for(Module m : getValidList()) {
    31.             if(m.validate())
    32.                 return m;
    33.         }
    34.         return null;
    35.     }
    36. }
    Module Interface
    Code (Text):
    1. public interface Module {
    2.  
    3.     boolean validate();
    4.  
    5.     void execute();
    6.  
    7. }
    Condition Interface
    Code (Text):
    1. public interface Condition {
    2.  
    3.     boolean check();
    4.  
    5. }
    Usage:
    Code (Text):
    1.    public boolean onStart() {
    2.             mw.addModuleList(Bank::isOpen);
    3.             mw.addModuleList(() -> !Bank.isOpen());
    4.             mw.submit(new Example(), 0);
    5.             mw.submit(new Example2(), 1);
    6.         return true;
    7.     }
    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 bots into sections.
     
  2. The Task system is much easier in my opinion.. (and already supported by RM)

    Main:
    Code (Javascript):
    1. @Override
    2. public void onStart(String... args) {
    3. add(new ChopTreeTask());
    4. }
    ChopTreeTask.java
    Code (Javascript):
    1. public class ChopTreeTask extends Task {
    2. @Override
    3. public boolean validate() {
    4. return Skill.WOODCUTTING.getBaseLevel() > 60;
    5. }
    6.  
    7. @Override
    8. public void execute() {
    9. tree = GameObjects.newQuery().names("Yew").results().nearest();
    10. if(tree != null) {
    11. tree.interact("Chop");
    12. }
    13. }
    14. }
     
  3. Also, Tasks can have children Tasks, and can do what the OP wants already through this xD
     

Share This Page

Loading...