Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.54 KB | None | 0 0
  1. package com.fruityscripts.api.runepouch;
  2.  
  3. import com.fruityscripts.FruityNMZ;
  4. import com.fruityscripts.api.utils.time.Time;
  5. import com.fruityscripts.api.widgets.FruityWidgets;
  6. import org.osbot.rs07.api.model.Item;
  7. import org.osbot.rs07.api.ui.RS2Widget;
  8. import org.osbot.rs07.listener.ConfigListener;
  9. import org.osbot.rs07.script.API;
  10.  
  11. import java.util.ArrayList;
  12. import java.util.LinkedHashMap;
  13. import java.util.List;
  14. import java.util.Map;
  15. import java.util.stream.Collectors;
  16.  
  17. /**
  18.  * Created by BenMason on 22/03/17.
  19.  */
  20. public class RunePouch extends API implements ConfigListener {
  21.  
  22.     private final FruityNMZ script;
  23.     private LinkedHashMap<Rune, Integer> runes = new LinkedHashMap<>();
  24.     private boolean checked;
  25.  
  26.     public RunePouch(FruityNMZ script) throws InterruptedException {
  27.         exchangeContext(script.getBot());
  28.         this.script = script;
  29.         script.getBot().addConfigListener(this);
  30.         this.checked = false;
  31.         onConfig(1139, getConfigs().get(1139));
  32.     }
  33.  
  34.     @Override
  35.     public void initializeModule() {
  36.  
  37.     }
  38.  
  39.     @Override
  40.     public void onConfig(int id, int value) throws InterruptedException {
  41.         if (runes.size() == 3) {
  42.             if (id == 1139) {
  43.                 /*
  44.                  * Gets the quantities of runes in rune pouch from configs
  45.                  */
  46.                 long con = (long) value; // getConfigs().get(1139);
  47.                 long config = con < 0 ? Integer.MAX_VALUE + (Integer.MAX_VALUE - Math.abs(con)) : con;
  48.  
  49.                 if (config > 0) {
  50.                     int first = 0, second = 0, third = 0;
  51.  
  52.                     int slotConfig = getConfigs().get(1140);
  53.                     if (slotConfig > 0) {
  54.                         if (slotConfig >= 16385) {
  55.                             third = (int) Math.floor(slotConfig / 16384);
  56.                             slotConfig = slotConfig % 16384;
  57.                         }
  58.  
  59.                         if (slotConfig > 0) {
  60.                             second = slotConfig;
  61.                         }
  62.                     }
  63.  
  64.                     int a = ((int) Math.floor(config / 4096));
  65.                     first = (int) Math.floor(a / 64);
  66. //                f = f % 64;
  67.  
  68. //                Rune runeC = Rune.forValue(f);
  69. //                config = config % 4096;
  70.                     addRune((Rune) runes.keySet().toArray()[2], third);
  71.  
  72. //                e = (int) Math.floor(config / 64);
  73. //                Rune runeB = Rune.forValue(e);
  74. //                config = config % 64;
  75.                     addRune((Rune) runes.keySet().toArray()[1], second);
  76.  
  77. //                Rune runeA = Rune.forValue((int) config);
  78.                     addRune((Rune) runes.keySet().toArray()[0], first);
  79.                 } else {
  80.                     runes = new LinkedHashMap<>();
  81.                 }
  82.             }
  83.         }
  84.     }
  85.  
  86.     public List<Rune> getRunes() {
  87.         return new ArrayList<>(runes.keySet());
  88.     }
  89.  
  90.     public int getQuantity(Rune rune) {
  91.         return runes.get(rune);
  92.     }
  93.  
  94.     private void addRune(Rune rune, int quantity) {
  95.         if (rune != null) {
  96.             runes.put(rune, quantity);
  97.         } else {
  98.             if (getRunes().contains(Rune.BLANK_A)) {
  99.                 runes.put(Rune.BLANK_B, 0);
  100.             } else {
  101.                 runes.put(Rune.BLANK_A, 0);
  102.             }
  103.         }
  104.     }
  105.  
  106.     public boolean contains(Rune rune) {
  107.         return runes.containsKey(rune);
  108.     }
  109.  
  110.     public boolean contains(Rune rune, int quantity) {
  111.         return contains(rune) && getQuantity(rune) >= quantity;
  112.     }
  113.  
  114.  
  115.     public boolean canStore(Rune rune, int quantity) {
  116.         if (getInventory().contains(rune.getName())) {
  117.             if (contains(rune)) {
  118.                 return getQuantity(rune) <= (16000 - quantity);
  119.             } else return getRunes().size() < 3;
  120.         }
  121.         return false;
  122.     }
  123.  
  124.     public boolean checked() {
  125.         return checked;
  126.     }
  127.  
  128.     public void check() throws InterruptedException {
  129.         script.getPainter().setStatus("Checking rune pouch");
  130.         if (!getBank().isOpen()) {
  131.             if (isOpen()) {
  132.                 for (int i = 0; i < 3; i++) {
  133.                     RS2Widget widget = getRuneAtPosition(i);
  134.                     if (widget != null) {
  135.                         addRune(Rune.forID(widget.getItemId()), 0);
  136.                     } else {
  137.                         addRune(null, 0);
  138.                     }
  139.                 }
  140.                 onConfig(1139, getConfigs().get(1139));
  141.                 checked = true;
  142.             } else {
  143.                 Item item = getInventory().getItem("Rune pouch");
  144.                 if (item != null && item.interact()) {
  145.                     Time.sleep(this::isOpen);
  146.                 }
  147.             }
  148.         } else {
  149.             script.getBank().close();
  150.         }
  151.     }
  152.  
  153.     private RS2Widget getInterfaceWidget() {
  154.         return FruityWidgets.getInstance().containingText("Rune pouch");
  155.     }
  156.  
  157.     private RS2Widget getRuneAtPosition(int position) {
  158.         if (position >= 0 && position < 3) {
  159.             return getWidgets().get(190, 4, position);
  160.         }
  161.         return null;
  162.     }
  163.  
  164.     public boolean isOpen() {
  165.         return getInterfaceWidget() != null;
  166.     }
  167.  
  168.     public boolean close() {
  169.         script.getPainter().setStatus("Closing rune pouch");
  170.         if (getWidgets().containingActions(190, "Close").stream().findFirst().orElse(null).interact()) {
  171.             Time.sleep(() -> !isOpen());
  172.             return true;
  173.         }
  174.         return false;
  175.     }
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement