Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.rsbot.script.methods;
- import org.rsbot.script.methods.Game.Tab;
- import org.rsbot.script.wrappers.RSComponent;
- import org.rsbot.script.wrappers.RSItem;
- public class RuneCrafting extends MethodProvider {
- public static final int POUCH_SETTING = 720;
- public static final int MEDIUM_POUCH = 5510;
- public static final int DEGRADED_MEDIUM_POUCH = 5511;
- public static final int LARGE_POUCH = 5512;
- public static final int DEGRADED_LARGE_POUCH = 5513;
- public static final int GIANT_POUCH = 5514;
- public static final int DEGRADED_GIANT_POUCH = 5515;
- public static final int RUNE_POUCH_REPAIR_SPELL = 68;
- public static final int NPC_CONTACT_SPELL = 26;
- public RuneCrafting(MethodContext ctx) {
- super(ctx);
- }
- public int getSetting() {
- return methods.settings.getSetting(POUCH_SETTING);
- }
- /**
- * Checks if small runecrafting pouch is full.
- *
- * @author Robert G
- *
- * @return <tt>true</tt> if the pouch is full, else false.
- */
- public boolean smallPouchFull() {
- return getSetting() == 2;
- }
- /**
- * Checks if medium runecrafting pouch is full.
- *
- * @author Robert G
- *
- * @return <tt>true</tt> if the pouch is full, else false.
- */
- public boolean mediumPouchFull() {
- return getSetting() == 8 || getSetting() == 40;
- }
- /**
- * Checks if large runecrafting pouch is full.
- *
- * @author Robert G
- *
- * @return <tt>true</tt> if the pouch is full, else false.
- */
- public boolean giantPouchFull() {
- return getSetting() == 32 || getSetting() == 40;
- }
- /**
- * Checks if large runecrafting pouch is full.
- *
- * @author Robert G
- *
- * @return <tt>true</tt> if the pouch is full, else false.
- */
- public boolean largePouchFull() {
- return getSetting() == 32 || getSetting() == 40;
- }
- /**
- * Interacts with a runecrafting pouch.
- *
- * @author Robert G
- *
- * @param arg0
- * the pouch id
- *
- * @param action
- * the action to perform
- */
- public void pouch(int arg0, String action) {
- RSItem item = methods.inventory.getItem(arg0);
- if (item != null) {
- item.interact(action);
- sleep(random(1100, 1200));
- }
- }
- /**
- * Repairs a degraded runecrafting pouches using the lunar spell
- * rune pouch repair.
- *
- * @author Robert G
- */
- public void runePouchRepair() {
- if (methods.game.getTab() != Tab.MAGIC) {
- methods.game.openTab(Tab.MAGIC);
- waitForTab(Tab.MAGIC);
- }
- if (methods.magic.canCastSpell(Magic.Spell.REPAIR_RUNE_POUCH)) {
- methods.magic.castSpell(Magic.Spell.REPAIR_RUNE_POUCH);
- methods.game.openTab(Tab.INVENTORY);
- waitForTab(Tab.INVENTORY);
- if (methods.game.getTab() == Tab.INVENTORY) {
- if (methods.inventory.contains(DEGRADED_MEDIUM_POUCH)) {
- pouch(DEGRADED_MEDIUM_POUCH, "Repair");
- sleep(random(1000, 1200));
- }
- if (methods.inventory.contains(DEGRADED_LARGE_POUCH)) {
- pouch(DEGRADED_LARGE_POUCH, "Repair");
- sleep(random(1000, 1200));
- }
- if (methods.inventory.contains(DEGRADED_GIANT_POUCH)) {
- pouch(DEGRADED_GIANT_POUCH, "Repair");
- sleep(random(1000, 1200));
- }
- }
- }
- }
- /**
- * Repairs degraded runecrafting pouches.
- *
- * @author Robert G
- */
- public void npcRepair() {
- if (!getInt(88, 1).isValid()) {
- if (methods.game.getTab() != Tab.MAGIC) {
- methods.game.openTab(Tab.MAGIC);
- waitForTab(Tab.MAGIC);
- }
- methods.magic.castSpell(Magic.Spell.NPC_CONTACT);
- waitForInterface(88, 1);
- }
- if (getInt(88, 1).isValid()) {
- RSComponent scrollBar = getInt(88, 20).getComponent(1);
- methods.mouse.move(scrollBar.getCenter());
- methods.mouse.drag(460, 250);
- if (getInt(88, 22).getComponent(14).isValid()) {
- getInt(88, 22).getComponent(14).doClick();
- sleep(random(800, 1000));
- while (methods.players.getMyPlayer().getAnimation() != -1) {
- sleep(50);
- }
- waitForInterface(64, 5);
- }
- }
- if (getInt(64, 5).isValid()) {
- getInt(64, 5).doClick();
- waitForInterface(242, 6);
- }
- if (getInt(242, 6).isValid()) {
- getInt(242, 6).doClick();
- waitForInterface(65, 6);
- }
- if (getInt(65, 6).isValid()) {
- getInt(65, 6).doClick();
- waitForInterface(242, 6);
- }
- if (getInt(242, 6).isValid()) {
- getInt(242, 6).doClick();
- waitForInterface(65, 6);
- }
- if (getInt(65, 6).isValid()) {
- getInt(65, 6).doClick();
- waitForInterface(243, 7);
- }
- if (getInt(243, 7).isValid()) {
- getInt(243, 7).doClick();
- waitForInterface(228, 2);
- }
- if (getInt(228, 2).isValid()) {
- getInt(228, 2).doClick();
- waitForInterface(65, 6);
- }
- if (getInt(65, 6).isValid()) {
- getInt(65, 6).doClick();
- waitForInterface(243, 7);
- }
- if (getInt(243, 7).isValid()) {
- getInt(243, 7).doClick();
- sleep(random(500, 600));
- }
- }
- /**
- * Waits till a tab is open
- *
- * @param tab
- * the tab to wait for
- */
- public void waitForTab(Tab tab) {
- long start = System.currentTimeMillis();
- while (methods.game.getTab() != tab && System.currentTimeMillis() - start < 1000) {
- sleep(50);
- }
- }
- /**
- * Returns the RSComponent with the specified ids
- *
- * @author Robert G
- *
- * @param parent
- * The parent id
- *
- * @param child
- * The child id
- */
- public RSComponent getInt(int parent, int child) {
- return methods.interfaces.getComponent(parent, child);
- }
- /**
- * Waits till the specified interface is valid
- *
- * @author Robert G
- *
- * @param parent
- * The parent id
- *
- * @param child
- * The child id
- */
- public void waitForInterface(int parent, int child) {
- final long start = System.currentTimeMillis();
- while (System.currentTimeMillis() - start < 4000) {
- sleep(50);
- if (getInt(parent, child).isValid()) {
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment