Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- 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.Condition;
- import org.powerbot.concurrent.strategy.Strategy;
- import org.powerbot.game.api.ActiveScript;
- import org.powerbot.game.api.Manifest;
- import org.powerbot.game.api.methods.Tabs;
- 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.tab.Inventory;
- import org.powerbot.game.api.methods.widget.Camera;
- import org.powerbot.game.api.util.Random;
- import org.powerbot.game.api.util.Time;
- import org.powerbot.game.api.wrappers.widget.WidgetChild;
- import org.powerbot.game.bot.event.listener.PaintListener;
- @Manifest(name = "Choko Grinder", description = "Grinds Chokolate Bars to dust for profit", version = 1.0, authors = {"Thondar"})
- public class ChokoGrinder extends ActiveScript implements PaintListener {
- int ChokoBar = 1973;
- int ChokoDust = 1975;
- int DustCount;
- int DustInv;
- int Profit;
- int ProfitHour;
- int DustPrice;
- int BarPrice;
- int Banker[] = {3418, 553, 496, 497, 9710, 42192, 2718, 3416, 3293, 4456, 4457, 4458, 4459, 6200, 2759};
- long startTime;
- long runTime, xpTime;
- long hr, min, sec, xphr, xpmin, xpsec;
- long xpGain;
- String time;
- String status;
- boolean start = true;
- private static WidgetChild Powder;
- 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.replaceAll(",", ""));
- }
- @Override
- protected void setup() {
- startTime = System.currentTimeMillis();
- DustCount = 0;
- try {
- DustPrice = getPrice(1975);
- BarPrice = getPrice(1973);
- } catch (IOException e) {
- e.printStackTrace();
- }
- BankOpen bankopen = new BankOpen();
- Strategy bankopenStrategy = new Strategy(bankopen, bankopen);
- provide(bankopenStrategy);
- Bank bank = new Bank();
- Strategy bankStrategy = new Strategy(bank, bank);
- provide(bankStrategy);
- Grind grind = new Grind();
- Strategy grindStrategy = new Strategy(grind, grind);
- provide(grindStrategy);
- AntiBan ab = new AntiBan();
- Strategy abStrategy = new Strategy(ab, ab);
- provide(abStrategy);
- Tabs.INVENTORY.open(false);
- }
- private class BankOpen implements Task, Condition {
- @Override
- public void run() {
- status = ("Banking");
- NPCs.getNearest(Banker).interact("Bank");
- Time.sleep(Random.nextInt(700, 1100));
- }
- @Override
- public boolean validate() {
- return (Inventory.getCount(ChokoBar) == 0) && NPCs.getNearest(Banker).isOnScreen() && !org.powerbot.game.api.methods.widget.Bank.isOpen();
- }
- }
- private class Bank implements Task, Condition {
- @Override
- public void run() {
- status = ("Banking");
- DustInv = Inventory.getCount(ChokoDust);
- DustCount += DustInv;
- org.powerbot.game.api.methods.widget.Bank.depositInventory();
- Time.sleep(Random.nextInt(300, 500));
- org.powerbot.game.api.methods.widget.Bank.withdraw(ChokoBar, 28);
- Time.sleep(Random.nextInt(300, 500));
- org.powerbot.game.api.methods.widget.Bank.close();
- }
- @Override
- public boolean validate() {
- return Inventory.getCount(ChokoBar) < 1 && org.powerbot.game.api.methods.widget.Bank.isOpen();
- }
- }
- private class Grind implements Task, Condition {
- @Override
- public void run() {
- status = ("Making Dust");
- Powder = Widgets.get(905, 14);
- Tabs.INVENTORY.open(false);
- if(org.powerbot.game.api.methods.widget.Bank.isOpen()){
- org.powerbot.game.api.methods.widget.Bank.close();
- }
- if(!Powder.isOnScreen()){
- Inventory.getItem(ChokoBar).getWidgetChild().interact("Powder");
- Time.sleep(Random.nextInt(300, 500));
- }
- if(Powder.isOnScreen()) {
- Powder.click(true);
- Time.sleep(Random.nextInt(300, 500));
- }
- }
- @Override
- public boolean validate() {
- return (Inventory.getCount(ChokoBar) > 0) && (Players.getLocal().getAnimation() == -1);
- }
- }
- private class AntiBan implements Task, Condition {
- @Override
- public void run() {
- switch(Random.nextInt(1, 100)){
- case 3:
- Camera.setAngle(Random.nextInt(1, 150));
- case 33:
- Camera.setAngle(Random.nextInt(1, 310));
- case 75:
- Camera.setAngle(Random.nextInt(1, 210));
- default:
- }
- Time.sleep(Random.nextInt(500, 1000));
- }
- @Override
- public boolean validate() {
- return start;
- }
- }
- private AlphaComposite makeComposite(float alpha) {
- int type = AlphaComposite.SRC_OVER;
- return(AlphaComposite.getInstance(type, alpha));
- }
- private final Font font1 = new Font("Verdana", 0, 16);
- private final Font font2 = new Font("Verdana", 0, 12);
- private final Font font3 = new Font("Verdana", 0, 13);
- private final Font font4 = new Font("Verdana", 0, 9);
- @Override
- public void onRepaint(Graphics g) {
- Graphics2D g2d = (Graphics2D) g;
- g2d.setColor(Color.BLUE);
- g2d.drawLine((Mouse.getX() -3), Mouse.getY(), (Mouse.getX() +3), Mouse.getY());
- g2d.drawLine(Mouse.getX(), (Mouse.getY() - 3), Mouse.getX(), (Mouse.getY() + 3));
- g2d.drawLine((Mouse.getX() - 1), (Mouse.getY() - 1), (Mouse.getX() + 1), (Mouse.getY() + 1));
- g2d.drawLine((Mouse.getX() + 1), (Mouse.getY() - 1), (Mouse.getX() - 1), (Mouse.getY() + 1));
- int DustHour = (int) ((DustCount) * 3600000D / (System
- .currentTimeMillis() - startTime));
- int DustPrice1 = DustPrice - BarPrice;
- Profit = DustCount * DustPrice1;
- ProfitHour = DustHour * DustPrice1;
- Rectangle bg = new Rectangle(0, 0, 800, 50);
- g2d.setComposite(makeComposite(1f));
- g2d.setColor(Color.BLACK);
- g2d.fill(bg);
- g2d.setFont(font1);
- g2d.setComposite(makeComposite(1f));
- g2d.setColor(Color.BLUE);
- g2d.drawString("ChokoGrinder", 15, 20);
- g2d.setFont(font3);
- g2d.drawString("by Thondar", 27, 35);
- g2d.setFont(font4);
- g2d.drawString("Version 1.0", 33, 45);
- g2d.setFont(font2);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.WHITE);
- g2d.drawString("Time Run: " + timeRun(), 150, 20);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.WHITE);
- g2d.drawString("Status: " + status, 150, 40);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.WHITE);
- g2d.drawString("Dusts Banked: " + DustCount, 350, 20);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.WHITE);
- g2d.drawString("Dusts Banked/H: " + DustHour, 350, 40);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.WHITE);
- g2d.drawString("Profit: " + Profit, 550, 20);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.WHITE);
- g2d.drawString("Profit/H: " + ProfitHour, 550, 40);
- }
- public String timeRun() {
- runTime = System.currentTimeMillis() - startTime;
- time = "";
- hr = runTime / (1000 * 60 * 60);
- min = (runTime % (1000 * 60 * 60)) / (1000 * 60);
- sec = ((runTime % (1000 * 60 * 60)) % (1000 * 60)) / 1000;
- if (hr < 10)
- time += "0" + hr + ":";
- else
- time += hr + ":";
- if (min < 10)
- time += "0" + min + ":";
- else
- time += min + ":";
- if (sec < 10)
- time += "0" + sec;
- else
- time += sec;
- return time;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment