Advertisement
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.util.LinkedList;
- import java.util.List;
- import javax.swing.*;
- import com.rarebot.event.events.MessageEvent;
- import com.rarebot.event.listeners.MessageListener;
- import com.rarebot.event.listeners.PaintListener;
- import com.rarebot.script.wrappers.RSItem;
- import com.rarebot.script.Script;
- import com.rarebot.script.ScriptManifest;
- import com.rarebot.script.methods.Skills;
- import com.rarebot.script.util.Filter;
- import com.rarebot.script.wrappers.RSNPC;
- import com.rarebot.script.wrappers.RSTile;
- @ScriptManifest(authors = "UberMouse", name = "UberFalconry", keywords = "Hunter", version = 1.0, description = "Catches kebbits at falconry area")
- public class UberFalconry extends Script implements MessageListener, PaintListener {
- private static List<Strategy> strategies = new LinkedList<Strategy>();
- //Booleans
- private boolean debug = false;
- private boolean reGetFalcon = false;
- //IDS
- public int[] kebbitIDs = { 5098, 5099, 5100 };
- private int kebbitID = 5098;
- private int[] falconIDs = {5094, 5095, 5096};
- private int falconerID = 5093;
- private int[] junk = { 526, 10125,10115,10127 };
- //Tiles
- private RSTile falconerTile = new RSTile(2375, 3604);
- //Statistics
- private long startTime;
- private int kebbitsCaught = 0;
- private int startXP;
- public interface Strategy {
- public void execute();
- public boolean isValid();
- }
- public class Debug {
- public void debug(Object text, boolean severe)
- {
- if (debug) {
- String className = this.getClass().getName();
- if (className.contains("$"))
- className = className.split("\\$")[1];
- StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
- int stacktraceIndex;
- if (stackTraceElements[2].getMethodName() == "debug")
- stacktraceIndex = 3;
- else
- stacktraceIndex = 2;
- StackTraceElement stacktrace = stackTraceElements[stacktraceIndex];
- String methodName = stacktrace.getMethodName();
- if (!severe)
- log("[" + className + "] -> [" + methodName + "] -> " + text);
- else
- log.severe("[" + className + "] -> [" + methodName + "] -> " + text);
- }
- }
- public void debug(Object text)
- {
- debug(text, false);
- }
- }
- public boolean onStart()
- {
- if (!game.isLoggedIn()) {
- log.severe("Start script loggedin.");
- stopScript();
- }
- GUI gui = new GUI(this);
- gui.setVisible(true);
- while (gui.isVisible())
- sleep(100);
- startTime = System.currentTimeMillis();
- startXP = skills.getCurrentExp(Skills.HUNTER);
- strategies.add(new reGetFalcon());
- strategies.add(new dropJunk());
- strategies.add(new catchKebbit());
- strategies.add(new takeFalcon());
- return true;
- }
- @Override
- public int loop()
- {
- try {
- if (interfaces.canContinue())
- interfaces.clickContinue();
- if (!getMyPlayer().isIdle() || !game.isLoggedIn())
- return 400;
- mouse.setSpeed(random(4, 7));
- for (Strategy strategy : strategies) {
- // debug = false;
- if (strategy.isValid()) {
- // debug = true;
- strategy.execute();
- return random(500, 1000);
- }
- }
- }
- catch (NullPointerException e) {}
- return 10;
- }
- public void turnToNPC(RSNPC npc)
- {
- if (npc == null)
- return;
- if (!npc.isOnScreen()) {
- camera.turnToCharacter(npc, random(10,25));
- if (!npc.isOnScreen())
- walking.walkTileMM(walking.getClosestTileOnMap(npc.getLocation()));
- }
- }
- public class catchKebbit extends Debug implements Strategy {
- @Override
- public void execute()
- {
- RSNPC kebbit = npcs.getNearest(new Filter<RSNPC>() {
- @Override
- public boolean accept(RSNPC t)
- {
- if (t.getID() == kebbitID)
- return true;
- return false;
- }
- });
- turnToNPC(kebbit);
- if (kebbit.doAction("Catch")) {
- int timeout = 0;
- while (npcs.getNearest(falconIDs) == null && ++timeout < 20)
- sleep(100);
- }
- }
- @Override
- public boolean isValid()
- {
- return (npcs.getNearest(falconIDs) == null);
- }
- }
- public class takeFalcon implements Strategy {
- @Override
- public void execute()
- {
- RSNPC falcon = npcs.getNearest(falconIDs);
- turnToNPC(falcon);
- if (falcon.doAction("Retrieve")) {
- kebbitsCaught++;
- int timeout = 0;
- while (npcs.getNearest(falconIDs) != null && ++timeout < 25)
- sleep(100);
- }
- }
- @Override
- public boolean isValid()
- {
- return (npcs.getNearest(falconIDs) != null);
- }
- }
- public class dropJunk implements Strategy {
- @Override
- public void execute()
- {
- for (RSItem item : inventory.getItems()) {
- if (arrayContains(junk, item.getID())) {
- item.doAction("Drop");
- sleep(random(600, 800));
- }
- }
- }
- @Override
- public boolean isValid()
- {
- return inventory.getCount() > 26;
- }
- }
- public class reGetFalcon implements Strategy {
- @Override
- public void execute()
- {
- walking.newTilePath(walking.findPath(falconerTile)).traverse();
- RSNPC falconer = npcs.getNearest(falconerID);
- turnToNPC(falconer);
- if (falconer.isOnScreen()) {
- if (falconer.doAction("Falconry")) {
- int timeout = 0;
- while (!interfaces.getComponent(236, 1).isValid() && ++timeout < 20)
- sleep(100);
- if (interfaces.getComponent(236, 1).doClick()) {
- timeout = 0;
- while (!interfaces.canContinue() && ++timeout < 20) {
- sleep(100);
- }
- reGetFalcon = false;
- }
- }
- }
- }
- @Override
- public boolean isValid()
- {
- return reGetFalcon;
- }
- }
- public boolean arrayContains(int[] array, int num)
- {
- for (int i : array) {
- if (i == num)
- return true;
- }
- return false;
- }
- @Override
- public void messageReceived(MessageEvent e)
- {
- String txt = e.getMessage();
- if (txt.contains("you see it heading back to the f"))
- reGetFalcon = true;
- }
- public String getTime(long millis)
- {
- long time = millis / 1000;
- String seconds = Integer.toString((int) (time % 60));
- String minutes = Integer.toString((int) ((time % 3600) / 60));
- String hours = Integer.toString((int) (time / 3600));
- for (int i = 0; i < 2; i++) {
- if (seconds.length() < 2) {
- seconds = "0" + seconds;
- }
- if (minutes.length() < 2) {
- minutes = "0" + minutes;
- }
- if (hours.length() < 2) {
- hours = "0" + hours;
- }
- }
- String returnThis = hours + ":" + minutes + ":" + seconds;
- return returnThis;
- }
- //START: Code generated using Enfilade's Easel
- private final Color color1 = new Color(0, 0, 153, 125);
- private final Color color2 = new Color(0, 0, 0);
- private final Color color3 = new Color(255, 255, 255);
- private final Color color4 = new Color(255, 0, 51);
- private final Color color5 = new Color(51, 255, 0);
- private final BasicStroke stroke1 = new BasicStroke(1);
- private final Font font1 = new Font("Arial", 0, 12);
- int xpGained, xpPH, kebbitsPH;
- long ttlCalc;
- String TTL, timeRan;
- public void onRepaint(Graphics g1)
- {
- xpGained = skills.getCurrentExp(Skills.HUNTER) - startXP;
- xpPH = (int) ((xpGained) * 3600000D / (System.currentTimeMillis() - startTime));
- String TTL;
- if(xpPH != 0)
- ttlCalc = (long) (skills.getExpToNextLevel(Skills.HUNTER) * 3600000D) / xpPH;
- kebbitsPH = (int) ((kebbitsCaught) * 3600000D / (System.currentTimeMillis() - startTime));
- TTL = getTime(ttlCalc);
- timeRan = getTime(System.currentTimeMillis() - startTime);
- Graphics2D g = (Graphics2D) g1;
- g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g.setColor(color1);
- g.fillRoundRect(550, 210, 188, 80, 16, 16);
- g.setColor(color2);
- g.setStroke(stroke1);
- g.drawRoundRect(550, 210, 188, 80, 16, 16);
- g.setFont(font1);
- g.setColor(color3);
- g.drawString("Kebbits caught (P/H):" + kebbitsCaught + "(" + kebbitsPH + ")", 555, 225);
- g.drawString("Exp gained (P/H):" + xpGained + "(" + xpPH + ")", 555, 240);
- g.drawString("Time running: " + getTime(System.currentTimeMillis() - startTime), 555, 255 );
- g.setColor(color4);
- g.fillRoundRect(555, 260, 175, 21, 16, 16);
- g.setColor(color2);
- g.drawRoundRect(555, 260, 175, 21, 16, 16);
- g.setColor(color5);
- g.fillRoundRect(555, 260, (int) (skills.getPercentToNextLevel(Skills.HUNTER) * 1.75), 21, 16, 16);
- g.setColor(color3);
- g.drawString(skills.getPercentToNextLevel(Skills.HUNTER) + "%/" + TTL, 596, 275);
- }
- //END: Code generated using Enfilade's Easel
- class GUI extends JFrame {
- UberFalconry script;
- public GUI(final UberFalconry script) {
- this.script = script;
- script.loop();
- initComponents();
- }
- private void startBtnActionPerformed(ActionEvent e)
- {
- script.kebbitID = script.kebbitIDs[kebbitSelect.getSelectedIndex()];
- dispose();
- }
- private void initComponents()
- {
- // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
- // Generated using JFormDesigner Evaluation license - Taylor Lodge
- kebbitLabel = new JLabel();
- kebbitSelect = new JComboBox(new Object[] {"Spotted Kebbit", "Dark Kebbit", "Dashing Kebbit"});
- startBtn = new JButton();
- //======== this ========
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- //---- kebbitLabel ----
- kebbitLabel.setText("Select Kebbit:");
- contentPane.add(kebbitLabel);
- kebbitLabel.setBounds(new Rectangle(new Point(5, 5), kebbitLabel.getPreferredSize()));
- contentPane.add(kebbitSelect);
- kebbitSelect.setBounds(5, 25, 110, kebbitSelect.getPreferredSize().height);
- //---- startBtn ----
- startBtn.setText("Start");
- startBtn.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- startBtnActionPerformed(e);
- }
- });
- contentPane.add(startBtn);
- startBtn.setBounds(new Rectangle(new Point(10, 55), startBtn.getPreferredSize()));
- { // 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 - Taylor Lodge
- private JLabel kebbitLabel;
- private JComboBox kebbitSelect;
- private JButton startBtn;
- // JFormDesigner - End of variables declaration //GEN-END:variables
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement