Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.rsbuddy.event.listeners.PaintListener;
- import com.rsbuddy.script.ActiveScript;
- import com.rsbuddy.script.Manifest;
- import com.rsbuddy.script.methods.*;
- import com.rsbuddy.script.util.Filter;
- import com.rsbuddy.script.util.Random;
- import com.rsbuddy.script.util.Timer;
- import com.rsbuddy.script.wrappers.Component;
- import com.rsbuddy.script.wrappers.GameObject;
- import com.rsbuddy.script.wrappers.Item;
- import com.rsbuddy.script.wrappers.Widget;
- import org.rsbuddy.tabs.Inventory;
- import org.rsbuddy.widgets.Bank;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- @Manifest(name = "ProFletcher", version = 1.2, authors = { "ccman32", "Speed" }, keywords = {
- "Fletching", "Stringing" }, description = "My first script, select options in GUI")
- public class ProFletcher extends ActiveScript implements PaintListener,
- MouseListener {
- private static final int KNIFE_ID = 946, CLAY_KNIFE = 14111;
- private static final int BOWSTRING_ID = 1777;
- private static final String[] TYPE_OPTION = new String[] { "Fletch",
- "String" };
- private static final String[] SELECT_OPTION = new String[] { "Shortbow",
- "Longbow", "Oak shortbow", "Oak longbow", "Willow shortbow",
- "Willow longbow", "Maple shortbow", "Maple longbow",
- "Yew shortbow", "Yew longbow", "Magic shortbow", "Magic longbow" };
- private static final int[] UNSTRUNG_BOWS = new int[] { 50, 48, 54, 56, 60,
- 58, 64, 62, 68, 66, 72, 70 };
- private static final int[] LOG_IDS = new int[] { 1511, 1511, 1521, 1521,
- 1519, 1519, 1517, 1517, 1515, 1515, 1513, 1513 };
- private static final Filter<GameObject> FILTER_VISIBLE = new Filter<GameObject>() {
- public boolean accept(GameObject obj) {
- return obj.isOnScreen();
- }
- };
- private final WaitTerminate waitForBusy = new WaitTerminate() {
- public boolean end() {
- return isBusy(10);
- }
- };
- private static final int WIDGET_FLETCH = 905;
- private int mouseSpeed;
- private int oldSpeed;
- private Type type;
- private int logIndex;
- private boolean shortbow;
- private int startXP, startLevel;
- private int item1, item2;
- private long startTime;
- private long minutes;
- private long hours;
- private GUI gui;
- private boolean paint = true;
- private Rectangle chatBoxPoint;
- private WaitTerminate waitForInterface;
- private enum State {
- BANK, FLETCH, ANTIBAN, OPENBANK, CLOSEBANK
- }
- private enum Type {
- CUT, STRING
- }
- public boolean onStart() {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- gui = new GUI();
- }
- });
- return true;
- }
- private int child;
- public void onRepaint(final Graphics g) {
- if (startTime == 0) {
- return;
- }
- long runTime = System.currentTimeMillis() - startTime;
- long seconds = runTime / 1000;
- if (seconds >= 60) {
- minutes = seconds / 60;
- seconds -= (minutes * 60);
- }
- if (minutes >= 60) {
- hours = minutes / 60;
- minutes -= (hours * 60);
- }
- final int gainedXp = Skills.getCurrentExp(Skills.FLETCHING) - startXP;
- final int gainedLevels = Skills.getRealLevel(Skills.FLETCHING)
- - startLevel;
- g.setColor(Color.BLUE);
- if (paint) {
- g.fill3DRect(6, 345, 508, 129, true);
- g.setColor(Color.BLACK);
- g.drawString("ProFletcher by ccman32", 15, 362);
- g.drawString("Gained XP: " + gainedXp, 20, 390);
- g.drawString("Levels gained: " + gainedLevels, 20, 410);
- g.drawString("Runtime: " + hours + ":" + minutes + ":" + seconds,
- 20, 430);
- if ((runTime / 1000) > 0 && gainedXp > 0) {
- int xpPerHour = (int) ((3600000.0 / (double) runTime) * gainedXp);
- g.drawString("XP/hour: " + xpPerHour, 310, 390);
- }
- g.drawString("% to "
- + (Skills.getCurrentLevel(Skills.FLETCHING) + 1 > 99 ? 99
- : Skills.getCurrentLevel(Skills.FLETCHING) + 1)
- + " :" + Skills.getPercentToNextLevel(Skills.FLETCHING),
- 310, 410);
- g.drawString("Click anywhere to hide the paint", 189, 470);
- } else {
- g.fill3DRect(6, 345, 10, 10, true);
- }
- }
- abstract class WaitTerminate {
- public abstract boolean end();
- public boolean wasTerminated(long timeout) {
- final Timer time = new Timer(timeout);
- while (time.isRunning()) {
- if (end()) {
- return true;
- }
- sleep(50);
- }
- return false;
- }
- }
- public int loop() {
- if (item1 == 0) {
- return 100;
- } else if (oldSpeed != mouseSpeed) {
- Mouse.setSpeed(mouseSpeed);
- oldSpeed = mouseSpeed;
- } else if (startTime == 0
- && Skills.getRealLevel(Skills.CONSTITUTION) > 1) {
- startTime = System.currentTimeMillis();
- startXP = Skills.getCurrentExp(Skills.FLETCHING);
- startLevel = Skills.getRealLevel(Skills.FLETCHING);
- } else if (Inventory.getSelectedItem() != null) {
- final int id = Inventory.getSelectedItem().getId();
- if (id != item1 && id != item2) {
- Inventory.clickSelectedItem();
- }
- } else if (Widgets.canContinue())
- Widgets.clickContinue();
- switch (getState()) {
- case BANK:
- switch (type) {
- case CUT:
- if (Inventory.getCount() > 1
- && Inventory.getCount() != Inventory.getCount(item1,
- item2)) {
- Bank.depositAllExcept(item1);
- } else {
- if (Bank.getCount(item2) < 27) {
- log("Finished");
- Bank.close();
- Game.logout(false);
- return -1;
- } else {
- Bank.withdraw(item2, 27);
- }
- if (!Inventory.contains(item1)) {
- if (Bank.getCount(item1) >= 1) {
- Bank.withdraw(item1, 1);
- return Random.nextInt(500, 700);
- } else {
- if (item1 == CLAY_KNIFE) {
- item1 = KNIFE_ID;
- log("Your clay knife finished, using normal knife");
- return Random.nextInt(100, 200);
- } else {
- log("Couldn't find knife.");
- return -1;
- }
- }
- }
- }
- break;
- case STRING:
- if (Inventory.getCount() > 0
- && Inventory.getCount() != Inventory.getCount(item1,
- item2)) {
- Bank.depositAll();
- } else {
- if (Bank.getCount(item1) < 14 || Bank.getCount(item2) < 14) {
- log("Finished");
- return -1;
- } else if (Bank.getCount(item1) > 14
- && Bank.getCount(item2) > 14) {
- if (!Inventory.contains(item1)) {
- Bank.withdraw(item1, 14);
- sleep(400, 700);
- }
- if (!Inventory.contains(item2)) {
- Bank.withdraw(item2, 14);
- sleep(400, 700);
- }
- }
- }
- break;
- default:
- break;
- }
- return Random.nextInt(500, 800);
- case FLETCH:
- final Widget inf = Widgets.get(ProFletcher.WIDGET_FLETCH);
- final Component child = inf.getComponent(this.child);
- if (child != null && child.isValid()) {
- if (chatBoxPoint == null) {
- chatBoxPoint = child.getContentRect();
- }
- int tries = 0;
- do {
- if (child.isValid())
- child.click();
- else
- break;
- } while (++tries <= 5 && !waitForBusy.wasTerminated(1000));
- return Random.nextInt(350, 500);
- } else if (child != null && !child.isValid()) {
- if (Inventory.getSelectedItem() != null) {
- int selected = Inventory.getSelectedItem().getId();
- if (selected == item1 || selected == item2) {
- if (selected == item1) {
- Inventory.getItem(item2).interact("Use");
- } else {
- Inventory.getItem(item1).interact("Use");
- }
- if (chatBoxPoint != null) {
- int x = Random.nextInt(chatBoxPoint.x,
- chatBoxPoint.x + chatBoxPoint.width);
- int y = Random.nextInt(chatBoxPoint.y,
- chatBoxPoint.y + chatBoxPoint.height);
- Mouse.move(mouseSpeed, x, y, 4, 4);
- }
- waitForInterface.wasTerminated(Random.nextInt(1200,
- 1500));
- return Random.nextInt(200, 400);
- } else {
- Inventory.clickSelectedItem();
- }
- } else {
- Inventory.getItem(item1, item2).interact("Use");
- }
- }
- return Random.nextInt(300, 600);
- case OPENBANK:
- if (!Bank.isOpen())
- Bank.open();
- return Random.nextInt(200, 500);
- case CLOSEBANK:
- if (Bank.isOpen())
- Bank.close();
- return Random.nextInt(200, 400);
- case ANTIBAN:
- if (Random.nextInt(0, 20) == 0) {
- GameObject[] obj = Objects.getLoaded(FILTER_VISIBLE);
- switch (Random.nextInt(1, 5)) {
- case 1:
- Camera.moveRandomly(Random.nextInt(2000, 4200));
- break;
- case 2:
- if (Random.nextInt(0, 5) == 0)
- Camera.setPitch(true);
- break;
- case 3:
- if (Random.nextInt(0, 5) == 0)
- Camera.setPitch(false);
- break;
- case 4:
- if (obj.length > 0) {
- Camera.turnTo(obj[Random.nextInt(0, obj.length - 1)]
- .getLocation());
- }
- break;
- default:
- break;
- }
- }
- if (Random.nextInt(0, 20) == 0) {
- GameObject[] objs = Objects.getLoaded(FILTER_VISIBLE);
- switch (Random.nextInt(1, 7)) {
- case 1:
- Mouse.move((int) ((Mouse.getLocation().x * 3.5) / 2.5)
- + Random.nextInt(10, 30), ((int) ((Mouse
- .getLocation().y * 3.5) / 2.5) + Random.nextInt(10,
- 30)));
- break;
- case 2:
- Item[] items = Inventory.getItems();
- items[Random.nextInt(0, items.length - 1)].getComponent()
- .hover();
- break;
- case 3:
- if (objs.length > 0) {
- objs[Random.nextInt(0, objs.length - 1)].hover();
- }
- break;
- case 4:
- Mouse.move((int) ((Mouse.getLocation().x * 3.5) / 2.5)
- + Random.nextInt(5, 30), ((int) ((Mouse
- .getLocation().y * 3.5) / 2.5) + Random.nextInt(5,
- 30)));
- break;
- case 5:
- Mouse.moveRandomly(Random.nextInt(900, 2000));
- default:
- break;
- }
- }
- return Random.nextInt(500, 700);
- default:
- return Random.nextInt(200, 400);
- }
- }
- private boolean isBusy() {
- return isBusy(25);
- }
- private boolean isBusy(final int interval) {
- for (int i = 0; i < 15; i++) {
- if (Players.getLocal().isMoving()
- || Players.getLocal().getAnimation() != -1) {
- return true;
- }
- sleep(interval);
- }
- return false;
- }
- public void onFinish() {
- if (Bank.isOpen()) {
- Bank.close();
- }
- if (Game.isLoggedIn()) {
- Game.logout(false);
- }
- log(String.format(
- "Thanks for using ProFletcher, you gained %d fletching xp.",
- Skills.getCurrentExp(Skills.FLETCHING) - startXP));
- }
- private State getState() {
- if (!isBusy()) {
- if (!Inventory.containsAll(item1, item2) && !Bank.isOpen()) {
- return State.OPENBANK;
- } else if (Bank.isOpen() && !Inventory.containsAll(item1, item2)) {
- return State.BANK;
- } else if (Bank.isOpen() && Inventory.containsAll(item1, item2)) {
- return State.CLOSEBANK;
- } else if (Inventory.containsAll(item1, item2) && !Bank.isOpen()) {
- return State.FLETCH;
- }
- }
- return State.ANTIBAN;
- }
- class GUI extends JFrame {
- private JComboBox selector, select1;
- private JLabel label, label1, label2;
- private JButton startButton, cancelButton;
- private JCheckBox clayKnife;
- private JSlider speed;
- public GUI() {
- createAndShowGUI();
- setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- }
- private void createAndShowGUI() {
- selector = new JComboBox(TYPE_OPTION);
- select1 = new JComboBox(SELECT_OPTION);
- label = new JLabel("Fletching type:");
- label1 = new JLabel("Make:");
- label2 = new JLabel("Mouse speed (lower=faster):");
- startButton = new JButton("Start");
- cancelButton = new JButton("Cancel");
- clayKnife = new JCheckBox("Clay knife?");
- speed = new JSlider();
- speed.setPaintTicks(true);
- speed.setPaintLabels(true);
- speed.setMaximum(10);
- speed.setMinimum(1);
- speed.setMajorTickSpacing(1);
- speed.setSnapToTicks(true);
- startButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (selector.getSelectedItem().equals(TYPE_OPTION[0])) {
- logIndex = select1.getSelectedIndex();
- type = ProFletcher.Type.CUT;
- item1 = clayKnife.isSelected() ? CLAY_KNIFE : KNIFE_ID;
- item2 = LOG_IDS[select1.getSelectedIndex()];
- } else {
- logIndex = select1.getSelectedIndex();
- type = ProFletcher.Type.STRING;
- item2 = BOWSTRING_ID;
- item1 = UNSTRUNG_BOWS[select1.getSelectedIndex()];
- }
- mouseSpeed = gui.speed.getValue();
- shortbow = logIndex == 0 || (logIndex % 2) == 0;
- if (type == ProFletcher.Type.CUT)
- if (shortbow) {
- if (logIndex < 2) {
- child = 15;
- } else {
- child = 14;
- }
- } else {
- if (logIndex < 2) {
- child = 16;
- } else {
- child = 15;
- }
- }
- else
- child = 14;
- waitForInterface = new WaitTerminate() {
- public boolean end() {
- final Component c = Widgets
- .getComponent(905, child);
- return c != null && c.isValid();
- }
- };
- if (startButton.getText().equals("Start")) {
- startButton.setText("Update");
- }
- if (cancelButton.getText().equals("Cancel")) {
- cancelButton.setText("Stop");
- }
- }
- });
- cancelButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- dispose();
- stop();
- }
- });
- setSize(400, 300);
- setLayout(new GridLayout(0, 2));
- add(label);
- add(selector);
- add(label1);
- add(select1);
- add(clayKnife);
- add(new JLabel());// empty space
- add(label2);
- add(speed);
- add(startButton);
- add(cancelButton);
- setVisible(true);
- }
- }
- public void mouseEntered(MouseEvent arg0) {
- }
- public void mouseExited(MouseEvent arg0) {
- }
- public void mousePressed(MouseEvent arg0) {
- }
- public void mouseReleased(MouseEvent arg0) {
- }
- public void mouseClicked(MouseEvent e) {
- final Point p = e.getPoint();
- if (paint && p.x >= 0 && p.x <= 764 && p.y >= 0 && p.y <= 527) {
- paint = false;
- } else if (!paint && p.x >= 0 && p.x <= 764 && p.y >= 0 && p.x <= 527) {
- paint = true;
- }
- }
- }
Add Comment
Please, Sign In to add comment