Skip to content

Instantly share code, notes, and snippets.

@sajattack
Forked from xcvd/VialFiller.java
Created June 8, 2012 05:51
Show Gist options
  • Save sajattack/2893841 to your computer and use it in GitHub Desktop.
Save sajattack/2893841 to your computer and use it in GitHub Desktop.
Vial Filler
/* )............( /
/ / ___/| \ /
/ | /o \/| | /
/ | \_____/\| | /
/ \ -xcvd- / /
/ ')__________(' */
import org.powerbot.concurrent.Task;
import org.powerbot.concurrent.strategy.Strategy;
import org.powerbot.game.api.ActiveScript;
import org.powerbot.game.api.Manifest;
import org.powerbot.game.api.methods.Walking;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.input.Mouse;
import org.powerbot.game.api.methods.interactive.NPCs;
import org.powerbot.game.api.methods.interactive.Players;
import org.powerbot.game.api.methods.node.SceneEntities;
import org.powerbot.game.api.methods.node.Menu;
import org.powerbot.game.api.methods.tab.Inventory;
import org.powerbot.game.api.methods.widget.Camera;
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.Tile;
import org.powerbot.game.api.wrappers.interactive.NPC;
import org.powerbot.game.api.wrappers.node.Item;
import org.powerbot.game.api.wrappers.node.SceneObject;
import org.powerbot.game.api.wrappers.widget.WidgetChild;
import org.powerbot.game.bot.event.listener.PaintListener;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Fills vials at the GE
* Start anywhere in the grand exchange
*
* @author xcvd
*/
@Manifest(name = "Vial Filler", description = "Fills vials. By xcvd", version = 1.6d, authors = {"xcvd"}, website="http://www.powerbot.org/community/topic/672724-xcvds-vial-filler-40-60k-an-hour/")
public class VialFiller extends ActiveScript implements PaintListener {
private static final int[] LOCATION_FOUNTAIN = {47150};
private static final int ITEM_ID_VIAL = 229;
private static final int ITEM_ID_VIAL_OF_WATER = 227;
private static final Tile[] FOUNTAIN_TILES = {new Tile(3162, 3490, 0), new Tile(3161, 3490, 0), new Tile(3160, 3488, 0)};
private static final Tile[] BANK_TILES = {new Tile(3151, 3483, 0), new Tile(3148, 3483, 0), new Tile(3149, 3481, 0)};
private int vialsFilled = 0;
private int profit = 0;
private long startTime = System.currentTimeMillis();
private static BufferedImage paintBackground;
private static Font georgia = new Font("Georgia", Font.PLAIN, 18);
enum State{ACTIVE, INACTIVE, DELETED}
@Override
protected void setup() {
provide(new ClickBank());
provide(new DoBank());
provide(new FillVials());
try {
paintBackground = ImageIO.read(new URL("http://localhostr.com/file/bGN82th/VialFillerMain.png"));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private final class ClickBank extends Strategy implements Task {
@Override
public boolean validate() {
for(Item i:Inventory.getItems())
{
if(i.getId() != 229)
return true;
}
return Inventory.getCount() != 28;
}
@Override
public void run() {
Walking.walk(BANK_TILES[Random.nextInt(0,2)]);
Time.sleep(Random.nextInt(700, 1300));
while(Players.getLocal().isMoving())
Time.sleep(100);
Bank.open();
Time.sleep(Random.nextInt(900, 1500));
while(!Bank.isOpen())
{
Bank.open();
Time.sleep(Random.nextInt(900, 1500));
}
}
}
private final class DoBank extends Strategy implements Task {
@Override
public boolean validate() {
return Bank.isOpen();
}
@Override
public void run() {
Time.sleep(Random.nextInt(900, 1500));
while(Inventory.getCount() > 0)
{
Bank.depositAll();
Time.sleep(Random.nextInt(900, 1500));
}
WidgetChild bankWidget = Widgets.get(762, 95);
for (WidgetChild c : bankWidget.getChildren()) {
if (new Item(c).getName().equals("Vial")) {
c.interact("Withdraw-All");
Time.sleep(Random.nextInt(500, 1000));
}
}
Bank.close();
Time.sleep(Random.nextInt(500, 1000));
while(Widgets.get(762, 1).isOnScreen())
{
Bank.close();
Time.sleep(Random.nextInt(500, 1000));
}
}
}
private final class FillVials extends Strategy implements Task {
@Override
public boolean validate() {
return Inventory.getCount(ITEM_ID_VIAL) > 0;
}
@Override
public void run() {
if(Camera.getYaw() > 50)
Camera.setNorth();
Time.sleep(Random.nextInt(60, 90));
Walking.walk(FOUNTAIN_TILES[Random.nextInt(0, 2)]);
Time.sleep(Random.nextInt(200, 2500));
while(Players.getLocal().isMoving())
Time.sleep(100);
final SceneObject fountain = SceneEntities.getNearest(LOCATION_FOUNTAIN[0]);
Inventory.getItems()[0].getWidgetChild().click(true);
Time.sleep(Random.nextInt(100,200));
fountain.interact("Use", "Vial -> Fountain");
int sleepTime = 0;
while(Inventory.getCount(new Filter<Item>() { public boolean accept(final Item n)
{
return n.getId()==227;
}}) < 28)
{
Time.sleep(500);
sleepTime += 500;
// crappy failsafe since Players.getLocal().getAnimation() seems to always return -1
if(sleepTime % 5000 == 0 && Inventory.getCount(ITEM_ID_VIAL_OF_WATER) == 0) {
Inventory.getItems()[27].getWidgetChild().click(true);
Time.sleep(Random.nextInt(100,200));
fountain.interact("Use", "Vial -> Fountain");
}
}
vialsFilled += 28;
profit += (28*28);
}
}
public static class Bank {
private static final int[] NPC_ID_BANKERS = {3416};
private static final int WIDGET_BANK = 762;
private static final int WIDGET_BANK_INVENTORY = 95;
private static final int WIDGET_CHILD_DEPOSIT_ALL = 34;
private static final int WIDGET_CHILD_CLOSE = 45;
public static boolean isOpen() {
return Widgets.get(WIDGET_BANK, 1).isOnScreen();
}
public static boolean open() {
final NPC banker = NPCs.getNearest(NPC_ID_BANKERS[0]);
return banker != null && banker.interact("Bank");
}
public static boolean depositAll() {
return isOpen() && Widgets.get(WIDGET_BANK).getChild(WIDGET_CHILD_DEPOSIT_ALL).click(true);
}
/* public static boolean withdraw(final int itemId, int amount) {
final WidgetChild item = getItemWidgetChild(itemId);
if(item != null) {
final int bankSlotX = Widgets.get(WIDGET_BANK).getChild(WIDGET_BANK_INVENTORY).getRelativeX() + item.getRelativeX();
final int bankSlotY = Widgets.get(WIDGET_BANK).getChild(WIDGET_BANK_INVENTORY).getRelativeY() + item.getRelativeY();
if(Mouse.click(bankSlotX + (item.getWidth() / 2), bankSlotY + (item.getHeight() / 2), false)) {
if(amount > 0)
return Menu.isOpen() && Menu.select("Withdraw-" + amount);
else
return Menu.isOpen() && Menu.select("Withdraw-All");
}
}
return false;
}
*/
private static WidgetChild getItemWidgetChild(int id)
{
WidgetChild item = null;
for(WidgetChild i:Widgets.get(WIDGET_BANK).getChild(WIDGET_BANK_INVENTORY).getChildren())
{
if(new Item(i).getId() == id)
{
item = i;
break;
}
}
return item;
}
private static boolean close() {
return Widgets.get(WIDGET_BANK).getChild(WIDGET_CHILD_CLOSE).click(true);
}
}
public void onRepaint(final Graphics render) {
Graphics2D g2 = (Graphics2D)render;
g2.drawImage(paintBackground, 8, 345, null);
g2.setFont(georgia);
g2.setColor(Color.getHSBColor(0.616666667f, 0.05f, 0.46f));
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
g2.drawString("VIALS FILLED: " + vialsFilled, 14, 410);
g2.drawString("TOTAL PROFIT: " + profit, 14, 442);
long timeNow = System.currentTimeMillis();
g2.drawString("TIME RUNNING: " + (int)(timeNow-startTime)/3600000 + ":" + (int)((timeNow-startTime)-(((timeNow-startTime)/3600000)*3600000))/60000 + ":" + (int)((timeNow-startTime)-(((timeNow-startTime)/3600000)*3600000)-(((timeNow-startTime)-(((timeNow-startTime)/3600000)*3600000))/60000)*60000)/1000, 220, 410);
g2.drawString("PROFIT/HOUR: " + (int)(((double)profit/(double)(timeNow-startTime))*3600000), 220, 442);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment