Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.AlphaComposite;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.GroupLayout;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JRadioButton;
- import javax.swing.LayoutStyle;
- import javax.swing.SwingUtilities;
- import javax.swing.UIManager;
- import javax.swing.UnsupportedLookAndFeelException;
- 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.Tabs;
- import org.powerbot.game.api.methods.Widgets;
- import org.powerbot.game.api.methods.input.Mouse;
- import org.powerbot.game.api.methods.interactive.Players;
- import org.powerbot.game.api.methods.node.Menu;
- import org.powerbot.game.api.methods.node.SceneEntities;
- import org.powerbot.game.api.methods.tab.Inventory;
- import org.powerbot.game.api.methods.tab.Skills;
- 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.node.Item;
- import org.powerbot.game.api.wrappers.node.SceneObject;
- import org.powerbot.game.api.wrappers.widget.Widget;
- import org.powerbot.game.api.wrappers.widget.WidgetChild;
- import org.powerbot.game.bot.event.MessageEvent;
- import org.powerbot.game.bot.event.listener.MessageListener;
- import org.powerbot.game.bot.event.listener.PaintListener;
- @Manifest(authors = { "Flow_HRS" }, name = "iTFletcher", description = "Will cut or string your logs/bows for you. - By Flow_HRS.", version = 1.2)
- public class iTFletcher extends ActiveScript implements PaintListener,
- MessageListener {
- private boolean guiInitialized;
- private boolean[] selected = new boolean[2];
- private int bowType, // 0 = shortbow, 1 = longbow
- action, logType, fails, actions, startLevel, startXp; // 0 = cut, 1
- // = string
- private String status = "waiting for gui";
- private long startTime;
- @Override
- protected void setup() {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- JFrame ui = new GUI();
- ui.setVisible(true);
- }
- });
- provide(new WaitForGuiTask());
- provide(new Sleep());
- provide(new Cutting());
- provide(new Stringing());
- provide(new Bank());
- provide(new AntiBan());
- provide(new OpenBank());
- provide(new CloseBank());
- startTime = System.currentTimeMillis();
- startLevel = Skills.getLevels()[9];
- startXp = Skills.getExperiences()[9];
- }
- private enum LogTypes {
- Normal(1511), Oak(1521), Willow(1519), Maple(1517), Yew(1515), Magic(
- 1513);
- int logId;
- private LogTypes(int logId) {
- this.logId = logId;
- }
- }
- private enum BowData {
- Normal(50, 48, 1511), Oak(54, 56, 1521), Willow(60, 58, 1519), Maple(
- 64, 62, 1517), Yew(68, 66, 1515), Magic(72, 70, 1513);
- int log, unstrungLb, unstrungSb;
- BowData(int unstrungSb, int unstrungLb, int log) {
- this.unstrungSb = unstrungSb;
- this.unstrungLb = unstrungLb;
- this.log = log;
- }
- }
- @Override
- public void messageReceived(MessageEvent arg0) {
- String msg = arg0.getMessage();
- if (msg.contains("carefully cut") || msg.contains("add a string")) {
- actions++;
- }
- }
- private int getLogForName(String name) {
- for (LogTypes lt : LogTypes.values()) {
- if ((lt.name() + " log").equals(name)) {
- return lt.logId;
- }
- }
- return -1;
- }
- private int getUnstrung(int log, boolean longbow) {
- for (BowData bd : BowData.values()) {
- if (bd != null) {
- if (bd.log == log) {
- return longbow ? bd.unstrungLb : bd.unstrungSb;
- }
- }
- }
- return -1;
- }
- private final boolean playerHasItem(int id) {
- for (Item i : Inventory.getItems()) {
- if (i.getId() == id) {
- return true;
- }
- }
- return false;
- }
- 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);
- int expGained = Skills.getExperiences()[Skills.FLETCHING] - startXp;
- int expHour = (int) ((expGained) * 3600000D / (System
- .currentTimeMillis() - startTime));
- int perHour = (int) ((actions) * 3600000D / (System.currentTimeMillis() - startTime));
- Rectangle bg = new Rectangle(10, 23, 250, 155);
- Rectangle border = new Rectangle(8, 21, 254, 159);
- g2d.setColor(Color.CYAN);
- 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));
- g2d.setFont(title);
- g2d.drawString("iTFletcher", 20, 50);
- g2d.setFont(author);
- g2d.drawString("By: Flow_HRS", 20, 65);
- g2d.setFont(info);
- g2d.drawString("Fletching level: " + Skills.getLevels()[9] + "/"
- + startLevel + ".", 20, 85);
- g2d.drawString("Fletching experience gained: " + expGained + ".", 20,
- 100);
- g2d.drawString("Fletching experience/hour: " + expHour + ".", 20, 115);
- g2d.drawString("Successfully did " + actions + " actions. (" + perHour
- + "/hour)", 20, 130);
- g2d.drawString("Status: " + status + ".", 20, 145);
- g2d.drawString("Action: " + (action == 0 ? "cutting" : "stringing")
- + (bowType == 0 ? " shortbow" : " longbow") + ".", 20, 160);
- g2d.drawString("Time running: "
- + formatTime(System.currentTimeMillis() - startTime) + ".", 20,
- 175);
- }
- public String formatTime(final long milliseconds) {
- final long t_seconds = milliseconds / 1000;
- final long t_minutes = t_seconds / 60;
- final long t_hours = t_minutes / 60;
- final long seconds = t_seconds % 60;
- final long minutes = t_minutes % 60;
- final long hours = t_hours % 500;
- return hours + ":" + minutes + ":" + seconds;
- }
- private final class Sleep extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized && Players.getLocal().getAnimation() != -1;
- }
- @Override
- public void run() {
- Time.sleep(100);
- }
- }
- private final class Cutting extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized && Players.getLocal().getAnimation() == -1
- && playerHasItem(logType) && action == 0;
- }
- @Override
- public void run() {
- if (Tabs.getCurrent() != Tabs.INVENTORY) {
- Tabs.INVENTORY.open();
- Time.sleep(600);
- }
- for (Item i : Inventory.getItems()) {
- if (i.getId() == logType && Random.nextInt(0, 3) == 1) {
- i.getWidgetChild().click(true);
- Time.sleep(400);
- }
- break;
- }
- if (Widgets.get(1179, 12).visible()) {
- Widgets.get(1179, 12).click(true);
- Time.sleep(600);
- }
- if (Widgets.get(905, bowType == 0 ? 14 : 15).validate()) {
- Widgets.get(905, bowType == 0 ? 14 : 15).click(true);
- status = "cutting";
- Time.sleep(1000);
- }
- }
- }
- private final class Stringing extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized && Players.getLocal().getAnimation() == -1
- && playerHasItem(getUnstrung(logType, bowType == 1))
- && action == 1 && playerHasItem(1777);
- }
- @Override
- public void run() {
- if (Tabs.getCurrent() != Tabs.INVENTORY) {
- Tabs.INVENTORY.open();
- Time.sleep(600);
- }
- for (Item i : Inventory.getItems()) {
- if (i.getId() == 1777 && !selected[0]) {
- i.getWidgetChild().click(true);
- selected[0] = true;
- } else if (i.getId() == getUnstrung(logType, bowType == 1)
- && !selected[1]) {
- i.getWidgetChild().click(true);
- selected[1] = true;
- }
- }
- if (Widgets.get(905, 14).visible()) {
- Widgets.get(905, 14).click(true);
- status = "stringing";
- Time.sleep(500);
- }
- }
- }
- private class AntiBan extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized && Players.getLocal().getAnimation() != -1;
- }
- @Override
- public void run() {
- if (Random.nextInt(1, 15) <= 2) {
- executeAntiBan();
- }
- Time.sleep(1000);
- }
- private final void executeAntiBan() {
- Camera.setAngle(Random.nextInt(20, 300));
- }
- }
- private final class WaitForGuiTask extends Strategy implements Task {
- @Override
- public boolean validate() {
- return !guiInitialized;
- }
- @Override
- public void run() {
- Time.sleep(100);
- }
- }
- private class CloseBank extends Strategy implements Task {
- @Override
- public boolean validate() {
- return guiInitialized && Widgets.get(762, 1).visible()
- && Inventory.getCount(action == 0 ? logType : 1777) > 0;
- }
- @Override
- public void run() {
- Widgets.get(762, 45).interact("Close");
- Time.sleep(Random.nextInt(300, 700));
- }
- }
- private class OpenBank extends Strategy implements Task {
- private SceneObject bankChest() {
- return SceneEntities.getNearest(new Filter<SceneObject>() {
- public boolean accept(final SceneObject ENTITY) {
- return ENTITY.getId() == 42192;
- }
- });
- }
- @Override
- public boolean validate() {
- return guiInitialized
- && Inventory.getCount(action == 0 ? logType : 1777) == 0
- && !Widgets.get(762, 1).visible();
- }
- @Override
- public void run() {
- if (Tabs.getCurrent() != Tabs.INVENTORY) {
- Tabs.INVENTORY.open();
- }
- if (bankChest() != null) {
- status = "banking";
- bankChest().interact("Use");
- Time.sleep(Random.nextInt(800, 1200));
- }
- }
- }
- private class Bank extends Strategy implements Task {
- private final void deposit() {
- Widgets.get(762, 34).click(true);
- }
- private SceneObject bankChest() {
- return SceneEntities.getNearest(new Filter<SceneObject>() {
- public boolean accept(final SceneObject ENTITY) {
- return ENTITY.getId() == 42192;
- }
- });
- }
- @Override
- public boolean validate() {
- return guiInitialized && Widgets.get(762, 1).validate()
- && Inventory.getCount(action == 0 ? logType : 1777) == 0;
- }
- @Override
- public void run() {
- if (bankChest() != null) {
- status = "banking";
- selected[0] = false;
- selected[1] = false;
- if (!(Inventory.getCount() <= 1)) {
- deposit();
- // Widgets.get(762, 34).click(true);
- Time.sleep(Random.nextInt(1000, 1200));
- } else {
- if (action == 0) {
- if (!playerHasItem(logType)) {
- withdraw(logType);
- }
- } else {
- if (!playerHasItem(1777)) {
- withdraw(1777);
- }
- if (!playerHasItem(getUnstrung(logType, bowType == 1))) {
- withdraw(getUnstrung(logType, bowType == 1));
- }
- }
- Time.sleep(Random.nextInt(172, 257));
- Widgets.get(762, 45).click(true);
- }
- }
- if (!playerHasItem(action == 0 ? logType : getUnstrung(logType,
- bowType == 1))) {
- fails++;
- } else if (action == 1 && !playerHasItem(1777)) {
- fails++;
- } else {
- fails = 0;
- }
- if (fails == 4) {
- stop();
- }
- }
- }
- private final boolean withdraw(int item) {
- Widget bank = Widgets.get(762);
- WidgetChild items = bank.getChild(95);
- int baseX = items.getAbsoluteX(), baseY = items.getAbsoluteY();
- for (WidgetChild child : items.getChildren()) {
- if (child.getChildId() == item) {
- Mouse.click(child.getRelativeX() + baseX
- + (child.getWidth() / 2), child.getRelativeY() + baseY
- + (child.getHeight() / 2), false);
- return Menu
- .select(action == 0 ? "Withdraw-All" : "Withdraw-14");
- }
- }
- return false;
- }
- public class GUI extends JFrame {
- private static final long serialVersionUID = 1L;
- public GUI() {
- initComponents();
- }
- private void initComponents() {
- Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
- int w = getSize().width;
- int h = getSize().height;
- int x = (dim.width - w) / 2;
- int y = (dim.height - h) / 2;
- setLocation(x, y);
- try {
- for (UIManager.LookAndFeelInfo info : UIManager
- .getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null,
- ex);
- } catch (InstantiationException ex) {
- Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null,
- ex);
- } catch (IllegalAccessException ex) {
- Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null,
- ex);
- } catch (UnsupportedLookAndFeelException ex) {
- Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null,
- ex);
- }
- jLabel1 = new JLabel();
- jComboBox1 = new JComboBox();
- jLabel2 = new JLabel();
- jRadioButton1 = new JRadioButton();
- jRadioButton2 = new JRadioButton();
- jButton1 = new JButton();
- jRadioButton3 = new JRadioButton();
- jRadioButton4 = new JRadioButton();
- jLabel3 = new JLabel();
- setTitle("Fletcher");
- jLabel1.setText("Select your log type:");
- jComboBox1.setModel(new DefaultComboBoxModel(new String[] {
- "Normal log", "Oak log", "Willow log", "Maple log",
- "Yew log", "Magic log" }));
- jLabel2.setText("Select your bow type:");
- jRadioButton1.setText("String");
- // jRadioButton1.setEnabled(false);
- jRadioButton1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- jRadioButton1ActionPerformed(evt);
- }
- });
- jRadioButton2.setText("Cut");
- jRadioButton2.setSelected(true);
- jRadioButton2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- jRadioButton2ActionPerformed(evt);
- }
- });
- jButton1.setText("Start");
- jButton1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jRadioButton3.setText("Shortbow");
- jRadioButton3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- jRadioButton3ActionPerformed(evt);
- }
- });
- jRadioButton4.setSelected(true);
- jRadioButton4.setText("Longbow");
- jRadioButton4.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- jRadioButton4ActionPerformed(evt);
- }
- });
- jLabel3.setText("Select your action:");
- GroupLayout layout = new GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(layout
- .createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(
- layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(
- layout.createParallelGroup(
- GroupLayout.Alignment.LEADING)
- .addGroup(
- layout.createSequentialGroup()
- .addGroup(
- layout.createParallelGroup(
- GroupLayout.Alignment.LEADING)
- .addComponent(
- jRadioButton2)
- .addComponent(
- jRadioButton1))
- .addGap(0,
- 0,
- Short.MAX_VALUE))
- .addGroup(
- layout.createSequentialGroup()
- .addGroup(
- layout.createParallelGroup(
- GroupLayout.Alignment.LEADING)
- .addComponent(
- jComboBox1,
- 0,
- GroupLayout.DEFAULT_SIZE,
- Short.MAX_VALUE)
- .addGroup(
- layout.createSequentialGroup()
- .addGroup(
- layout.createParallelGroup(
- GroupLayout.Alignment.LEADING)
- .addComponent(
- jRadioButton4)
- .addComponent(
- jLabel1)
- .addComponent(
- jLabel2)
- .addComponent(
- jRadioButton3)
- .addComponent(
- jLabel3))
- .addGap(0,
- 57,
- Short.MAX_VALUE))
- .addComponent(
- jButton1,
- GroupLayout.DEFAULT_SIZE,
- GroupLayout.DEFAULT_SIZE,
- Short.MAX_VALUE))
- .addContainerGap()))));
- layout.setVerticalGroup(layout.createParallelGroup(
- GroupLayout.Alignment.LEADING).addGroup(
- layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel1)
- .addPreferredGap(
- LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jComboBox1,
- GroupLayout.PREFERRED_SIZE,
- GroupLayout.DEFAULT_SIZE,
- GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(
- LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel2)
- .addPreferredGap(
- LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton4)
- .addPreferredGap(
- LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton3)
- .addPreferredGap(
- LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel3)
- .addPreferredGap(
- LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton2)
- .addPreferredGap(
- LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton1)
- .addPreferredGap(
- LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton1)
- .addContainerGap(GroupLayout.DEFAULT_SIZE,
- Short.MAX_VALUE)));
- pack();
- }
- private void jButton1ActionPerformed(ActionEvent evt) {
- logType = getLogForName(jComboBox1.getSelectedItem().toString());
- System.out.println(logType);
- bowType = jRadioButton3.isSelected() ? 0 : 1;
- action = jRadioButton1.isSelected() ? 1 : 0;
- guiInitialized = true;
- dispose();
- }
- private void jRadioButton4ActionPerformed(ActionEvent evt) {
- jRadioButton3.setSelected(false);
- }
- private void jRadioButton3ActionPerformed(ActionEvent evt) {
- jRadioButton4.setSelected(false);
- }
- private void jRadioButton2ActionPerformed(ActionEvent evt) {
- jRadioButton1.setSelected(false);
- }
- private void jRadioButton1ActionPerformed(ActionEvent evt) {
- jRadioButton2.setSelected(false);
- }
- private JButton jButton1;
- private JComboBox jComboBox1;
- private JLabel jLabel1;
- private JLabel jLabel2;
- private JLabel jLabel3;
- private JRadioButton jRadioButton1;
- private JRadioButton jRadioButton2;
- private JRadioButton jRadioButton3;
- private JRadioButton jRadioButton4;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement