Skip to content

Instantly share code, notes, and snippets.

@phl0w
Created June 30, 2013 22:56
Show Gist options
  • Select an option

  • Save phl0w/5897347 to your computer and use it in GitHub Desktop.

Select an option

Save phl0w/5897347 to your computer and use it in GitHub Desktop.
package org.phl0w.itcrafting.utilities.enums.armour;
import org.phl0w.itcrafting.utilities.Constants;
import org.phl0w.itcrafting.utilities.Utilities;
import org.phl0w.itcrafting.utilities.interfaces.CraftingItem;
import org.powerbot.core.script.job.Task;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.tab.Inventory;
import org.powerbot.game.api.methods.tab.Skills;
import org.powerbot.game.api.methods.widget.Bank;
import org.powerbot.game.api.wrappers.node.Item;
import org.powerbot.game.api.wrappers.widget.WidgetChild;
public enum Leather implements CraftingItem {
LEATHER_GLOVES(Constants.LEATHER, 1, 1, 2),
LEATHER_BOOTS(Constants.LEATHER, 1, 7, 6),
LEATHER_COWL(Constants.LEATHER, 1, 9, 10),
LEATHER_VAMBRACES(Constants.LEATHER, 1, 11, 14),
LEATHER_BODY(Constants.LEATHER, 1, 14, 18),
LEATHER_CHAPS(Constants.LEATHER, 1, 18, 22),
LEATHER_SHIELD(Constants.LEATHER, 1, 19, 26),
COIF(Constants.LEATHER, 1, 38, 46),
HARD_LEATHER_GLOVES(Constants.HARD_LEATHER, 1, 25, 30),
HARD_LEATHER_BOOTS(Constants.HARD_LEATHER, 1, 27, 34),
HARD_LEATER_BODY(Constants.HARD_LEATHER, 1, 28, 38),
HARD_LEATHER_SHIELD(Constants.HARD_LEATHER, 1, 29, 42),
IMPHIDE_GLOVES(Constants.IMPHIDE, 1, 10, 2),
IMPHIDE_BOOTS(Constants.IMPHIDE, 1, 11, 6),
IMPHIDE_HOOD(Constants.IMPHIDE, 2, 12, 10),
IMPHIDE_ROBE_BOTTOM(Constants.IMPHIDE, 2, 13, 14),
IMPHIDE_ROBE_TOP(Constants.IMPHIDE, 3, 14, 18),
IMPHIDE_BOOK(Constants.IMPHIDE, 3, 15, 22),
IMP_HORN_WAND(Constants.IMPHIDE, 3, 16, 26),
IMPHIDE_SHIELD(Constants.IMPHIDE, 4, 17, 30),
SPIDER_SILK_GLOVES(Constants.SPIDER_SILK, 1, 20, 2),
SPIDER_SILK_BOOTS(Constants.SPIDER_SILK, 1, 21, 6),
SPIDER_SILK_HOOD(Constants.SPIDER_SILK, 2, 22, 10),
SPIDER_SILK_ROBE_BOTTOM(Constants.SPIDER_SILK, 2, 23, 14),
SPIDER_SILK_ROBE_TOP(Constants.SPIDER_SILK, 3, 24, 18),
SPIDER_ORB(Constants.SPIDER_SILK, 2, 25, 22),
SPIDER_WAND(Constants.SPIDER_SILK, 2, 26, 26),
CARAPACE_GLOVES(Constants.CARAPACE, 1, 30, 2),
CARAPACE_BOOTS(Constants.CARAPACE, 1, 31, 6),
CARAPACE_HELM(Constants.CARAPACE, 2, 33, 10),
CARAPACE_LEGS(Constants.CARAPACE, 2, 34, 14),
CARAPACE_TORSO(Constants.CARAPACE, 3, 35, 18),
BATWING_GLOVES(Constants.BATWING, 1, 50, 2),
BATWING_BOOTS(Constants.BATWING, 1, 52, 6),
BATWING_HOOD(Constants.BATWING, 2, 54, 10),
BATWING_LEGS(Constants.BATWING, 2, 55, 14),
BATWING_TORSO(Constants.BATWING, 3, 56, 18),
BATWING_SHIELD(Constants.BATWING, 4, 58, 22),
BAT_BOOK(Constants.BATWING, 4, 59, 26),
BAT_WAND(Constants.BATWING, 4, 61, 30),
SNAKESKIN_BOOTS(Constants.SNAKESKIN, 6, 45, 2),
SNAKESKIN_VAMBRACES(Constants.SNAKESKIN, 8, 47, 6),
SNAKESKIN_BANDANA(Constants.SNAKESKIN, 5, 48, 10),
SNAKESKIN_CHAPS(Constants.SNAKESKIN, 12, 51, 14),
SNAKESKIN_BODY(Constants.SNAKESKIN, 15, 53, 18),
GREEN_D_HIDE_VAMBRACES(Constants.GREEN_LEATHER, 1, 57, 2),
GREEN_D_HIDE_CHAPS(Constants.GREEN_LEATHER, 2, 60, 6),
GREEN_D_HIDE_BODY(Constants.GREEN_LEATHER, 3, 63, 10),
GREEN_D_HIDE_SHIELD(Constants.GREEN_LEATHER, 4, 64, 14),
BLUE_D_HIDE_VAMBRACES(Constants.BLUE_LEATHER, 1, 66, 2),
BLUE_D_HIDE_CHAPS(Constants.BLUE_LEATHER, 2, 68, 6),
BLUE_D_HIDE_BODY(Constants.BLUE_LEATHER, 3, 71, 10),
BLUE_D_HIDE_SHIELD(Constants.BLUE_LEATHER, 4, 72, 14),
RED_D_HIDE_VAMBRACES(Constants.RED_LEATHER, 1, 73, 2),
RED_D_HIDE_CHAPS(Constants.RED_LEATHER, 2, 75, 6),
RED_D_HIDE_BODY(Constants.RED_LEATHER, 3, 77, 10),
RED_D_HIDE_SHIELD(Constants.RED_LEATHER, 4, 78, 14),
BLACK_D_HIDE_VAMBRACES(Constants.BLACK_LEATHER, 1, 79, 2),
BLACK_D_HIDE_CHAPS(Constants.BLACK_LEATHER, 2, 82, 6),
BLACK_D_HIDE_BODY(Constants.BLACK_LEATHER, 3, 84, 10),
BLACK_D_HIDE_SHIELD(Constants.BLACK_LEATHER, 4, 85, 14),
ROYAL_D_HIDE_VAMBRACES(Constants.ROYAL_LEATHER, 1, 87, 2),
ROYAL_D_HIDE_CHAPS(Constants.ROYAL_LEATHER, 2, 89, 6),
ROYAL_D_HIDE_BODY(Constants.ROYAL_LEATHER, 3, 93, 10);
private int leather;
private int reqAmount;
private int level;
private int widgetChild;
private Leather(final int leather, final int reqAmount, final int level, final int widgetChild) {
this.leather = leather;
this.reqAmount = reqAmount;
this.level = level;
this.widgetChild = widgetChild;
}
public boolean canCraft() {
return Inventory.getCount(leather) >= reqAmount && Inventory.contains(1734) &&
Skills.getLevel(Skills.CRAFTING) > level && !Utilities.isValid(Constants.WAIT_FOR_CRAFTING_CONDITION) &&
!Bank.isOpen();
}
public void craft() {
if (Utilities.isValid(Constants.SELECT_TOOL_INTERFACE_CONDITION)) {
final WidgetChild select = Widgets.get(1179, 16);
if (select != null && select.click(true)) {
Utilities.waitFor(Constants.WAIT_FOR_CRAFTING_SCREEN_CONDITION);
}
} else {
if (Utilities.isValid(Constants.WAIT_FOR_CRAFTING_SCREEN_CONDITION)) {
final String currentlyCrafting = Widgets.get(1370, 56).getText();
if (!currentlyCrafting.equals(getComparisonName())) {
if (Widgets.get(1371, 44).getChild(widgetChild).click(true)) {
Task.sleep(100, 200);
}
}
final WidgetChild craft = Widgets.get(1370, 38);
if (craft != null && craft.click(true)) {
Utilities.waitFor(Constants.WAIT_FOR_CRAFTING_CONDITION);
}
} else {
final Item leatherItem = Inventory.getItem(leather);
if (leatherItem != null) {
if (leatherItem.getWidgetChild().interact("Craft")) {
Utilities.waitFor(Constants.WAIT_FOR_CRAFTING_SCREEN_CONDITION);
}
}
}
}
}
public boolean needToBank() {
return (Inventory.getCount(leather) < reqAmount || !Inventory.contains(1734)) && !Utilities.isValid(Constants.WAIT_FOR_CRAFTING_CONDITION);
}
public void bank() {
if (Bank.open()) {
if (getInventoryCount() > 0) {
for (final Item i : Inventory.getItems()) {
if (i.getId() != 1734 && i.getId() != leather) {
Bank.deposit(i.getId(), 0);
}
}
}
if (!Inventory.contains(1734)) {
if (Inventory.isFull()) {
Bank.deposit(leather, 1);
}
Bank.withdraw(1734, 0);
}
if (!Inventory.isFull()) {
if (Bank.withdraw(leather, 0)) {
Bank.close();
}
}
}
}
private int getInventoryCount() {
final int toSubtract = Inventory.getCount(false, 1734) + Inventory.getCount(false, leather);
return Inventory.getCount() - toSubtract;
}
private String getComparisonName() {
String name = name().toLowerCase().replaceAll("_", " ");
if (name.contains("d") && name.contains("hide")) {
name = name.replace("d hide", "d'hide");
}
return name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment