Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.fruityscripts.api.runepouch;
- import com.fruityscripts.FruityNMZ;
- import com.fruityscripts.api.utils.time.Time;
- import com.fruityscripts.api.widgets.FruityWidgets;
- import org.osbot.rs07.api.model.Item;
- import org.osbot.rs07.api.ui.RS2Widget;
- import org.osbot.rs07.listener.ConfigListener;
- import org.osbot.rs07.script.API;
- import java.util.ArrayList;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * Created by BenMason on 22/03/17.
- */
- public class RunePouch extends API implements ConfigListener {
- private final FruityNMZ script;
- private LinkedHashMap<Rune, Integer> runes = new LinkedHashMap<>();
- private boolean checked;
- public RunePouch(FruityNMZ script) throws InterruptedException {
- exchangeContext(script.getBot());
- this.script = script;
- script.getBot().addConfigListener(this);
- this.checked = false;
- onConfig(1139, getConfigs().get(1139));
- }
- @Override
- public void initializeModule() {
- }
- @Override
- public void onConfig(int id, int value) throws InterruptedException {
- if (runes.size() == 3) {
- if (id == 1139) {
- /*
- * Gets the quantities of runes in rune pouch from configs
- */
- long con = (long) value; // getConfigs().get(1139);
- long config = con < 0 ? Integer.MAX_VALUE + (Integer.MAX_VALUE - Math.abs(con)) : con;
- if (config > 0) {
- int first = 0, second = 0, third = 0;
- int slotConfig = getConfigs().get(1140);
- if (slotConfig > 0) {
- if (slotConfig >= 16385) {
- third = (int) Math.floor(slotConfig / 16384);
- slotConfig = slotConfig % 16384;
- }
- if (slotConfig > 0) {
- second = slotConfig;
- }
- }
- int a = ((int) Math.floor(config / 4096));
- first = (int) Math.floor(a / 64);
- // f = f % 64;
- // Rune runeC = Rune.forValue(f);
- // config = config % 4096;
- addRune((Rune) runes.keySet().toArray()[2], third);
- // e = (int) Math.floor(config / 64);
- // Rune runeB = Rune.forValue(e);
- // config = config % 64;
- addRune((Rune) runes.keySet().toArray()[1], second);
- // Rune runeA = Rune.forValue((int) config);
- addRune((Rune) runes.keySet().toArray()[0], first);
- } else {
- runes = new LinkedHashMap<>();
- }
- }
- }
- }
- public List<Rune> getRunes() {
- return new ArrayList<>(runes.keySet());
- }
- public int getQuantity(Rune rune) {
- return runes.get(rune);
- }
- private void addRune(Rune rune, int quantity) {
- if (rune != null) {
- runes.put(rune, quantity);
- } else {
- if (getRunes().contains(Rune.BLANK_A)) {
- runes.put(Rune.BLANK_B, 0);
- } else {
- runes.put(Rune.BLANK_A, 0);
- }
- }
- }
- public boolean contains(Rune rune) {
- return runes.containsKey(rune);
- }
- public boolean contains(Rune rune, int quantity) {
- return contains(rune) && getQuantity(rune) >= quantity;
- }
- public boolean canStore(Rune rune, int quantity) {
- if (getInventory().contains(rune.getName())) {
- if (contains(rune)) {
- return getQuantity(rune) <= (16000 - quantity);
- } else return getRunes().size() < 3;
- }
- return false;
- }
- public boolean checked() {
- return checked;
- }
- public void check() throws InterruptedException {
- script.getPainter().setStatus("Checking rune pouch");
- if (!getBank().isOpen()) {
- if (isOpen()) {
- for (int i = 0; i < 3; i++) {
- RS2Widget widget = getRuneAtPosition(i);
- if (widget != null) {
- addRune(Rune.forID(widget.getItemId()), 0);
- } else {
- addRune(null, 0);
- }
- }
- onConfig(1139, getConfigs().get(1139));
- checked = true;
- } else {
- Item item = getInventory().getItem("Rune pouch");
- if (item != null && item.interact()) {
- Time.sleep(this::isOpen);
- }
- }
- } else {
- script.getBank().close();
- }
- }
- private RS2Widget getInterfaceWidget() {
- return FruityWidgets.getInstance().containingText("Rune pouch");
- }
- private RS2Widget getRuneAtPosition(int position) {
- if (position >= 0 && position < 3) {
- return getWidgets().get(190, 4, position);
- }
- return null;
- }
- public boolean isOpen() {
- return getInterfaceWidget() != null;
- }
- public boolean close() {
- script.getPainter().setStatus("Closing rune pouch");
- if (getWidgets().containingActions(190, "Close").stream().findFirst().orElse(null).interact()) {
- Time.sleep(() -> !isOpen());
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement