Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.SwingConstants;
- 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.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.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.Area;
- import org.powerbot.game.api.wrappers.Tile;
- import org.powerbot.game.api.wrappers.widget.WidgetChild;
- import org.powerbot.game.bot.event.listener.PaintListener;
- @Manifest(name = "Cowhide Tanner", description = "Tans Cowhides in Al Kharid", version = 1.0, authors = {"Thondar"})
- public class CowhideTanner extends ActiveScript implements PaintListener {
- private static WidgetChild Tan;
- private static WidgetChild SoftTan;
- private static WidgetChild HardTan;
- int CowHide = 1739;
- int SoftLeather = 1741;
- int HardLeather = 1743;
- int Leather;
- int LeatherCount;
- int LeatherInv;
- int HideProfit;
- int LeatherProfit;
- int Profit;
- int ProfitHour;
- int HidePrice;
- int HourPrice;
- int SoftLeatherPrice;
- int HardLeatherPrice;
- int LeatherPrice;
- int Banker[] = {496, 497};
- int Tanner = 2824;
- int TanChoice = 1;
- long startTime;
- long runTime, xpTime;
- long hr, min, sec, xphr, xpmin, xpsec;
- long xpGain;
- String time;
- String status;
- Tile TannerTile = new Tile(3274, 3191, 0);
- Tile Bankile = new Tile(3270, 3167, 0);
- Tile[] TilesToTanner = new Tile[] {
- new Tile(3274, 3169, 0), new Tile(3276, 3176, 0),
- new Tile(3280, 3182, 0), new Tile(3281, 3188, 0),
- new Tile(3275, 3191, 0)
- };
- Tile[] TilesToBank = new Tile[] {
- new Tile(3281, 3188, 0), new Tile(3280, 3182, 0),
- new Tile(3276, 3176, 0), new Tile(3274, 3169, 0),
- new Tile(3270, 3166, 0)
- };
- Area TannerArea = new Area(new Tile(3270, 3189, 0), new Tile(3278, 3194, 0));
- Area BankArea = new Area(new Tile(3268, 3161, 0), new Tile(3272, 3173, 0));
- GUI g;
- private boolean guiWait = true;
- boolean start = true;
- 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();
- g = new GUI();
- g.setVisible(true);
- final WaitGui guiTask = new WaitGui();
- provide(new Strategy(guiTask, guiTask));
- provide(new Strategy(new WaitGui(), new WaitGui()));
- LeatherCount = 0;
- try {
- HidePrice = getPrice(CowHide);
- SoftLeatherPrice = getPrice(SoftLeather);
- HardLeatherPrice = getPrice(HardLeather);
- } 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);
- Tan tan = new Tan();
- Strategy tanStrategy = new Strategy(tan, tan);
- provide(tanStrategy);
- BankWalk bankwalk = new BankWalk();
- Strategy bankwalkStrategy = new Strategy(bankwalk, bankwalk);
- provide(bankwalkStrategy);
- TannerWalk tannerwalk = new TannerWalk();
- Strategy tannerwalkStrategy = new Strategy(tannerwalk, tannerwalk);
- provide(tannerwalkStrategy);
- Rest rest = new Rest();
- Strategy restStrategy = new Strategy(rest, rest);
- provide(restStrategy);
- AntiBan ab = new AntiBan();
- Strategy abStrategy = new Strategy(ab, ab);
- provide(abStrategy);
- }
- private class WaitGui implements Task, Condition {
- @Override
- public void run() {
- while (guiWait) {
- Time.sleep(500);
- }
- }
- public boolean validate() {
- return guiWait;
- }
- }
- private class BankOpen implements Task, Condition {
- @Override
- public void run() {
- status = ("Banking");
- NPCs.getNearest(Banker).interact("Bank");
- Time.sleep(Random.nextInt(600, 1100));
- }
- @Override
- public boolean validate() {
- return Inventory.getCount(CowHide) < 1 && BankArea.contains(Players.getLocal()) && !org.powerbot.game.api.methods.widget.Bank.isOpen();
- }
- }
- private class Bank implements Task, Condition {
- @Override
- public void run() {
- status = ("Banking");
- LeatherInv = Inventory.getCount(Leather);
- LeatherCount += LeatherInv;
- org.powerbot.game.api.methods.widget.Bank.depositInventory();
- Time.sleep(Random.nextInt(300, 500));
- org.powerbot.game.api.methods.widget.Bank.withdraw(CowHide, 28);
- Time.sleep(Random.nextInt(300, 500));
- org.powerbot.game.api.methods.widget.Bank.close();
- }
- @Override
- public boolean validate() {
- return Inventory.getCount(CowHide) < 1 && BankArea.contains(Players.getLocal()) && org.powerbot.game.api.methods.widget.Bank.isOpen();
- }
- }
- private class Tan implements Task, Condition {
- @Override
- public void run() {
- status = ("Tanning");
- Tan = Widgets.get(905, 0);
- SoftTan = Widgets.get(905, 14);
- HardTan = Widgets.get(905, 15);
- if(!Tan.isOnScreen()){
- NPCs.getNearest(Tanner).interact("Tan hides");
- Time.sleep(Random.nextInt(300, 500));
- }
- if(Tan.isOnScreen() && TanChoice == 1){
- SoftTan.click(true);
- Time.sleep(Random.nextInt(300, 500));
- }
- if(Tan.isOnScreen() && TanChoice == 2){
- HardTan.click(true);
- Time.sleep(Random.nextInt(300, 500));
- }
- }
- @Override
- public boolean validate() {
- return TannerArea.contains(Players.getLocal()) && Inventory.getCount(CowHide) > 1;
- }
- }
- private class BankWalk implements Task, Condition {
- @Override
- public void run() {
- status = ("Running to Bank");
- Walking.newTilePath(TilesToBank).traverse();
- Time.sleep(Random.nextInt(200, 300));
- }
- @Override
- public boolean validate() {
- return Inventory.getCount(CowHide) < 10 && !BankArea.contains(Players.getLocal());
- }
- }
- private class TannerWalk implements Task, Condition {
- @Override
- public void run() {
- status = ("Running to Tanner");
- Walking.newTilePath(TilesToTanner).traverse();
- Time.sleep(Random.nextInt(200, 300));
- }
- @Override
- public boolean validate() {
- return Inventory.getCount(Leather) < 10 && Inventory.getCount(CowHide) > 1 && !TannerArea.contains(Players.getLocal());
- }
- }
- private class Rest implements Task, Condition {
- @Override
- public void run() {
- status = ("Resting");
- Walking.setRun(true);
- Widgets.get(750, 0).interact("Rest");
- Time.sleep(Random.nextInt(16000, 22000));
- }
- @Override
- public boolean validate() {
- return Walking.getEnergy() < 20;
- }
- }
- 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.ORANGE);
- 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 LeatherHour = (int) ((LeatherCount) * 3600000D / (System
- .currentTimeMillis() - startTime));
- HideProfit = LeatherCount * HidePrice;
- LeatherProfit = LeatherCount * LeatherPrice;
- Profit = LeatherProfit - HideProfit;
- HourPrice = LeatherPrice - HidePrice;
- ProfitHour = LeatherHour * HourPrice;
- 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.ORANGE);
- g2d.drawString("Cowhide Tanner", 10, 20);
- g2d.setFont(font3);
- g2d.drawString("by Thondar", 30, 35);
- g2d.setFont(font4);
- g2d.drawString("Version 1.0", 36, 45);
- g2d.setFont(font2);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.LIGHT_GRAY);
- g2d.drawString("Time Run: " + timeRun(), 550, 20);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.LIGHT_GRAY);
- g2d.drawString("Status: " + status, 550, 40);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.LIGHT_GRAY);
- g2d.drawString("Leathers Banked: " + LeatherCount, 350, 20);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.LIGHT_GRAY);
- g2d.drawString("Leathers Banked/H: " + LeatherHour, 350, 40);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.LIGHT_GRAY);
- g2d.drawString("Profit: " + Profit, 170, 20);
- g2d.setComposite(makeComposite(.8f));
- g2d.setColor(Color.LIGHT_GRAY);
- g2d.drawString("Profit/H: " + ProfitHour, 170, 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;
- }
- class GUI extends JFrame {
- public GUI() {
- initComponents();
- }
- private void button1ActionPerformed(ActionEvent e) {
- String u = comboBox1.getSelectedItem().toString(); {
- if (u.equals("Leather")) {
- Leather = SoftLeather;
- LeatherPrice = SoftLeatherPrice;
- TanChoice = 1;
- }else if (u.equals("Hard Leather")) {
- Leather = HardLeather;
- LeatherPrice = HardLeatherPrice -3;
- TanChoice = 2;
- }
- }
- guiWait = false;
- g.dispose();
- }
- private void initComponents() {
- // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
- // Generated using JFormDesigner Evaluation license - Jonas Bill Jensen
- label1 = new JLabel();
- button1 = new JButton();
- label2 = new JLabel();
- comboBox1 = new JComboBox();
- //======== this ========
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- //---- label1 ----
- label1.setText("Cowhide Tanner");
- label1.setHorizontalAlignment(SwingConstants.CENTER);
- label1.setFont(new Font("Segoe Print", Font.BOLD, 28));
- contentPane.add(label1);
- label1.setBounds(0, 0, 295, 65);
- //---- button1 ----
- button1.setText("Start");
- button1.setFont(new Font("Verdana", Font.PLAIN, 12));
- button1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- button1ActionPerformed(e);
- }
- });
- contentPane.add(button1);
- button1.setBounds(0, 205, 295, 50);
- //---- label2 ----
- label2.setText("What to Tan?");
- label2.setHorizontalAlignment(SwingConstants.CENTER);
- label2.setFont(new Font("Verdana", Font.PLAIN, 12));
- contentPane.add(label2);
- label2.setBounds(0, 95, 295, label2.getPreferredSize().height);
- //---- comboBox1 ----
- comboBox1.setModel(new DefaultComboBoxModel(new String[] {
- "Leather",
- "Hard Leather"
- }));
- contentPane.add(comboBox1);
- comboBox1.setBounds(85, 115, 125, 30);
- { // compute preferred size
- Dimension preferredSize = new Dimension();
- for(int i = 0; i < contentPane.getComponentCount(); i++) {
- Rectangle bounds = contentPane.getComponent(i).getBounds();
- preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
- preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
- }
- Insets insets = contentPane.getInsets();
- preferredSize.width += insets.right;
- preferredSize.height += insets.bottom;
- contentPane.setMinimumSize(preferredSize);
- contentPane.setPreferredSize(preferredSize);
- }
- pack();
- setLocationRelativeTo(getOwner());
- // JFormDesigner - End of component initialization //GEN-END:initComponents
- }
- // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
- // Generated using JFormDesigner Evaluation license - Jonas Bill Jensen
- private JLabel label1;
- private JButton button1;
- private JLabel label2;
- private JComboBox comboBox1;
- // JFormDesigner - End of variables declaration //GEN-END:variables
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment