Created
June 15, 2012 08:41
-
-
Save phl0w/2935456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.AlphaComposite; | |
| import java.awt.Color; | |
| import java.awt.Font; | |
| import java.awt.Graphics; | |
| import java.awt.Graphics2D; | |
| import java.awt.Rectangle; | |
| import java.io.BufferedReader; | |
| import java.io.IOException; | |
| import java.io.InputStreamReader; | |
| import java.net.URL; | |
| import java.net.URLConnection; | |
| 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.Calculations; | |
| 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.GroundItems; | |
| import org.powerbot.game.api.methods.node.SceneEntities; | |
| import org.powerbot.game.api.methods.tab.Inventory; | |
| import org.powerbot.game.api.methods.widget.Camera; | |
| import org.powerbot.game.api.methods.widget.DepositBox; | |
| import org.powerbot.game.api.util.Filter; | |
| 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.map.TilePath; | |
| import org.powerbot.game.api.wrappers.node.GroundItem; | |
| import org.powerbot.game.api.wrappers.node.SceneObject; | |
| import org.powerbot.game.bot.event.listener.PaintListener; | |
| @Manifest(authors = { "_phl0w" }, name = "SeaweedGrabber") | |
| public class SeaweedGrabber extends ActiveScript implements PaintListener { | |
| final int[] MONK_ARRAY = { 657, 2728, 2729 }; | |
| final int[] ENTRANA_MONK_ARRAY = { 658, 2730, 2731 }; | |
| private final Tile[] INVALID_TILES = new Tile[2]; | |
| public final TilePath PATH_TO_SEAWEED = new TilePath(new Tile[] { | |
| new Tile(2843, 3335, 0), new Tile(2855, 3341, 0), | |
| new Tile(2859, 3353, 0), new Tile(2857, 3369, 0), | |
| new Tile(2843, 3377, 0), new Tile(2827, 3379, 0), | |
| new Tile(2810, 3383, 0) }); | |
| private final TilePath PATH_TO_MONKS = new TilePath(new Tile[] { | |
| new Tile(2821, 3382, 0), new Tile(2827, 3379, 0), | |
| new Tile(2843, 3377, 0), new Tile(2857, 3369, 0), | |
| new Tile(2859, 3353, 0), new Tile(2855, 3341, 0), | |
| new Tile(2843, 3335, 0), }); | |
| private int seaweedPrice; | |
| private long startTime; | |
| private int takenSeaweed; | |
| private String status = "getting price..."; | |
| @Override | |
| protected void setup() { | |
| provide(new Deposit()); | |
| provide(new DepositOpen()); | |
| provide(new DepositClose()); | |
| provide(new TravelEntrana()); | |
| provide(new TravelPortSarim()); | |
| provide(new Pickup()); | |
| provide(new WalkSeaweed()); | |
| provide(new WalkMonk()); | |
| provide(new CrossPlank()); | |
| INVALID_TILES[0] = new Tile(2804, 3385, 0); | |
| INVALID_TILES[1] = new Tile(2803, 3382, 0); | |
| try { | |
| seaweedPrice = getPrice(401); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| startTime = System.currentTimeMillis(); | |
| } | |
| private class Pickup extends Strategy implements Task { | |
| @Override | |
| public boolean validate() { | |
| return Inventory.getCount() != 28 | |
| && Players.getLocal().getSpeed() == 0 | |
| && getSeaweed() != null; | |
| } | |
| @Override | |
| public void run() { | |
| status = "picking seaweed"; | |
| if (!getSeaweed().isOnScreen()) { | |
| Walking.walk(getSeaweed().getLocation()); | |
| Camera.turnTo(getSeaweed().getLocation()); | |
| } | |
| getSeaweed().interact("Take"); | |
| Time.sleep(600, 900); | |
| } | |
| } | |
| private class Deposit extends Strategy implements Task { | |
| @Override | |
| public boolean validate() { | |
| return DepositBox.isOpen() && DepositBox.getItemCount(false) > 0; | |
| } | |
| @Override | |
| public void run() { | |
| status = "depositing"; | |
| takenSeaweed += DepositBox.getItemCount(401); | |
| while (!DepositBox.depositInventory()) { | |
| Time.sleep(80, 120); | |
| } | |
| Time.sleep(300, 400); | |
| } | |
| } | |
| private class DepositOpen extends Strategy implements Task { | |
| @Override | |
| public boolean validate() { | |
| return !DepositBox.isOpen() && Inventory.getCount() != 0 | |
| && DepositBox.getNearest() != null | |
| && DepositBox.getNearest().isOnScreen(); | |
| } | |
| @Override | |
| public void run() { | |
| status = "opening depositbox"; | |
| while (!DepositBox.open()) { | |
| Time.sleep(80, 120); | |
| } | |
| Time.sleep(300, 400); | |
| } | |
| } | |
| private class DepositClose extends Strategy implements Task { | |
| @Override | |
| public boolean validate() { | |
| return DepositBox.isOpen() && DepositBox.getItemCount(401) == 0; | |
| } | |
| public void run() { | |
| status = "closing depositbox"; | |
| while (!DepositBox.close()) { | |
| Time.sleep(80, 120); | |
| } | |
| Time.sleep(300, 400); | |
| } | |
| } | |
| private class TravelEntrana extends Strategy implements Task { | |
| @Override | |
| public boolean validate() { | |
| return getMonk() != null && DepositBox.getNearest() != null | |
| && DepositBox.getNearest().isOnScreen() | |
| && Inventory.getCount() == 0 && !DepositBox.isOpen() | |
| && !Widgets.get(299, 24).isOnScreen() | |
| && !Players.getLocal().isMoving(); | |
| } | |
| @Override | |
| public void run() { | |
| status = "traveling entrana"; | |
| while (!getMonk().interact("Travel") | |
| && !Players.getLocal().isMoving()) { | |
| Time.sleep(80, 120); | |
| } | |
| Time.sleep(1000, 1400); | |
| while (Widgets.get(299, 24).isOnScreen()) { | |
| Time.sleep(80, 120); | |
| } | |
| } | |
| } | |
| private class WalkSeaweed extends Strategy implements Task { | |
| @Override | |
| public boolean validate() { | |
| return Calculations.distance(new Tile(2808, 3384, 0), Players | |
| .getLocal().getLocation()) > 10 | |
| && !Widgets.get(299, 24).isOnScreen() | |
| && Inventory.getCount() != 28 && needToWalk(); | |
| } | |
| @Override | |
| public void run() { | |
| status = "walking seaweed"; | |
| PATH_TO_SEAWEED.traverse(); | |
| } | |
| } | |
| private class WalkMonk extends Strategy implements Task { | |
| @Override | |
| public boolean validate() { | |
| return Inventory.getCount() == 28 && getEntranaMonk() == null | |
| && needToWalk(); | |
| } | |
| @Override | |
| public void run() { | |
| status = "walking monks"; | |
| PATH_TO_MONKS.traverse(); | |
| } | |
| } | |
| private class TravelPortSarim extends Strategy implements Task { | |
| @Override | |
| public boolean validate() { | |
| return getEntranaMonk() != null && getEntranaMonk().isOnScreen() | |
| && Inventory.getCount() == 28 | |
| && !Widgets.get(299, 24).isOnScreen() | |
| && !Players.getLocal().isMoving(); | |
| } | |
| @Override | |
| public void run() { | |
| status = "traveling portsarim"; | |
| Camera.turnTo(getEntranaMonk().getLocation()); | |
| while (!getEntranaMonk().interact("Travel")) { | |
| Time.sleep(80, 120); | |
| } | |
| Time.sleep(1000, 1400); | |
| while (Widgets.get(299, 24).isOnScreen()) { | |
| Time.sleep(80, 120); | |
| } | |
| } | |
| } | |
| private class CrossPlank extends Strategy implements Task { | |
| @Override | |
| public boolean validate() { | |
| return getPlank() != null && getPlank().isOnScreen() | |
| && !Widgets.get(299, 24).isOnScreen(); | |
| } | |
| @Override | |
| public void run() { | |
| status = "crossing gangplank"; | |
| while (!getPlank().interact("Cross")) { | |
| Time.sleep(80, 120); | |
| } | |
| Time.sleep(300, 400); | |
| } | |
| } | |
| private SceneObject getPlank() { | |
| return SceneEntities.getNearest(new Filter<SceneObject>() { | |
| @Override | |
| public boolean accept(SceneObject obj) { | |
| return obj.getId() == 2413 || obj.getId() == 2415; | |
| } | |
| }); | |
| } | |
| private NPC getMonk() { | |
| return NPCs.getNearest(new Filter<NPC>() { | |
| @Override | |
| public boolean accept(NPC n) { | |
| return n.getId() == MONK_ARRAY[0] || n.getId() == MONK_ARRAY[1] | |
| || n.getId() == MONK_ARRAY[2]; | |
| } | |
| }); | |
| } | |
| private NPC getEntranaMonk() { | |
| return NPCs.getNearest(new Filter<NPC>() { | |
| @Override | |
| public boolean accept(NPC n) { | |
| return n.getId() == ENTRANA_MONK_ARRAY[0] | |
| || n.getId() == ENTRANA_MONK_ARRAY[1] | |
| || n.getId() == ENTRANA_MONK_ARRAY[2]; | |
| } | |
| }); | |
| } | |
| private GroundItem getSeaweed() { | |
| return GroundItems.getNearest(new Filter<GroundItem>() { | |
| @Override | |
| public boolean accept(GroundItem item) { | |
| return item != null && item.getId() == 401 | |
| && !item.getLocation().equals(INVALID_TILES[0]) | |
| && !item.getLocation().equals(INVALID_TILES[1]); | |
| } | |
| }); | |
| } | |
| private boolean needToWalk() { | |
| if (Walking.getDestination().toString().equals("(-1, -1)")) { | |
| return true; | |
| } else { | |
| return Calculations.distance(Walking.getDestination(), Players | |
| .getLocal().getLocation()) <= 4; | |
| } | |
| } | |
| /** | |
| * @author Cakemix | |
| * @author Coma | |
| * @param id | |
| * the item id | |
| * @return the price | |
| * @throws IOException | |
| */ | |
| private int getPrice(int id) throws IOException { | |
| URL url = new URL("http://open.tip.it/json/ge_single_item?item=" + id); | |
| URLConnection con = url.openConnection(); | |
| BufferedReader in = new BufferedReader(new InputStreamReader( | |
| con.getInputStream())); | |
| String line = ""; | |
| String inputLine; | |
| while ((inputLine = in.readLine()) != null) { | |
| line += inputLine; | |
| } | |
| in.close(); | |
| if (!line.contains("mark_price")) | |
| return -1; | |
| line = line.substring(line.indexOf("mark_price\":\"") | |
| + "mark_price\":\"".length()); | |
| line = line.substring(0, line.indexOf("\"")); | |
| return Integer.parseInt(line); | |
| } | |
| private AlphaComposite makeComposite(float alpha) { | |
| int type = AlphaComposite.SRC_OVER; | |
| return (AlphaComposite.getInstance(type, alpha)); | |
| } | |
| @Override | |
| public void onRepaint(Graphics g) { | |
| Graphics2D g2d = (Graphics2D) g; | |
| Font title = new Font("Monotype Corsiva", Font.PLAIN, 25); | |
| Font author = new Font("Monotype Corsiva", Font.PLAIN, 16); | |
| Font info = new Font("Book Antiqua", Font.PLAIN, 15); | |
| Rectangle bg = new Rectangle(10, 23, 250, 155); | |
| Rectangle border = new Rectangle(8, 21, 254, 159); | |
| g2d.setColor(Color.YELLOW); | |
| g2d.setComposite(makeComposite(0.5f)); | |
| g2d.fill(bg); | |
| g2d.setColor(Color.BLACK); | |
| g2d.fill(border); | |
| g2d.setComposite(makeComposite(1.0f)); | |
| g2d.setColor(Color.WHITE); | |
| g2d.fill(new Rectangle(Mouse.getX() + 1, Mouse.getY() - 4, 2, 15)); | |
| g2d.fill(new Rectangle(Mouse.getX() - 6, Mouse.getY() + 2, 16, 2)); | |
| int moneyMade = takenSeaweed * seaweedPrice; | |
| int moneyMadeHour = (int) ((moneyMade) * 3600000D / (System | |
| .currentTimeMillis() - startTime)); | |
| int takenSeaweedHour = (int) ((takenSeaweed) * 3600000D / (System | |
| .currentTimeMillis() - startTime)); | |
| g2d.setFont(title); | |
| g2d.drawString("SeaweedGrabber", 20, 50); | |
| g2d.setFont(author); | |
| g2d.drawString("By: _phl0w", 20, 65); | |
| g2d.setFont(info); | |
| g2d.drawString("Seaweed taken: " + takenSeaweed + ".", 20, 85); | |
| g2d.drawString("Seaweed taken/h: " + takenSeaweedHour + ".", 20, 100); | |
| g2d.drawString("Money made: " + moneyMade + " gp (" + seaweedPrice | |
| + " ea).", 20, 115); | |
| g2d.drawString("Money made/h: " + moneyMadeHour + " gp.", 20, 130); | |
| g2d.drawString("Status: " + status + ".", 20, 145); | |
| g2d.drawString( | |
| "Time running: " | |
| + Time.format(System.currentTimeMillis() - startTime) | |
| + ".", 20, 160); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment