Skip to content

Instantly share code, notes, and snippets.

@CalebWhiting
Created April 8, 2012 18:01
Show Gist options
  • Save CalebWhiting/2338779 to your computer and use it in GitHub Desktop.
Save CalebWhiting/2338779 to your computer and use it in GitHub Desktop.
import org.powerbot.game.api.methods.Tabs;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.tab.Inventory;
import org.powerbot.game.api.util.Filter;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Time;
import org.powerbot.game.api.wrappers.node.Item;
import org.powerbot.game.api.wrappers.widget.WidgetChild;
/**
* @author Caleb Date: 08/04/12 Time: 18:46
*/
public class Inventory2 {
public static final int WIDGET = 679;
public static boolean isFull() {
return Inventory.getCount() == 28;
}
public static Item[] getItems() {
return Inventory.getItems();
}
public static boolean contains(final int ID) {
for(final Item item : getItems()) {
if(item.getId() == ID) {
return true;
}
}
return false;
}
public static boolean contains(final int... IDS) {
for(final int ID : IDS) {
if(!contains(ID)){
return false;
}
}
return true;
}
public static Item getItemAt(final int index) {
WidgetChild comp = getComponent().getChildren()[index];
return 0 <= index && index < 28 && comp != null && comp.getChildId() != - 1 ? new Item(comp) : null;
}
public static WidgetChild getComponent() {
for (final int widget : Inventory.ALT_WIDGETS) {
WidgetChild inventory = Widgets.get(widget, 0);
if (inventory != null && inventory.getAbsoluteLocation().x > 50) {
return inventory;
}
}
Tabs.INVENTORY.open();
return Widgets.get(WIDGET, 0);
}
public static Item getItem(final int ID) {
for(final Item ITEM : getItems()) {
if(ITEM.getId() == ID) {
return ITEM;
}
}
return null;
}
public static int getCount(final int... IDS) {
int count = 0;
for(final int ID : IDS) {
count += Inventory.getCount(ID);
}
return count;
}
public static int getCount(final String... NAMES) {
int count = 0;
for(final String NAME : NAMES) {
count += Inventory.getCount(new Filter<Item>() {
@Override public boolean accept(final Item ITEM) {
return ITEM.getName().equalsIgnoreCase(NAME);
}
});
}
return count;
}
public static Item getItem(final String NAME) {
for(final Item ITEM : getItems()) {
if(ITEM.getName().equalsIgnoreCase(NAME)) {
return ITEM;
}
}
return null;
}
public static void dropAllExcept(final int... IDS) {
for (final Item item : Inventory.getItems()) {
boolean drop = true;
for (final int ID : IDS) {
if (ID == item.getId()) {
drop = false;
break;
}
}
if (drop) {
item.getWidgetChild().interact("Drop");
Time.sleep(Random.nextInt(50, 300));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment