Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.FlowLayout;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Point;
- import java.awt.Polygon;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import org.rsbot.event.listeners.PaintListener;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.util.Filter;
- import org.rsbot.script.wrappers.RSArea;
- import org.rsbot.script.wrappers.RSItem;
- import org.rsbot.script.wrappers.RSModel;
- import org.rsbot.script.wrappers.RSNPC;
- import org.rsbot.script.wrappers.RSPlayer;
- import org.rsbot.script.wrappers.RSTile;
- @ScriptManifest(authors = "Jomik", name = "Air Runner", version = 0.71, description = "This will run essence to the air altar.")
- public class AirRunner extends Script implements PaintListener {
- private final System system = new System();
- private final InfoDatabase info = new InfoDatabase();
- private final Trade trade = new Trade();
- private final GUI gui = new GUI();
- private final Paint paint = new Paint();
- private enum State {
- GO_BANK, GO_ALTAR, TRADE, BANK, UNK_0
- }
- @Override
- public boolean onStart() {
- return gui.show();
- }
- @Override
- public int loop() {
- mouse.setSpeed(random(4, 10));
- if (!game.isLoggedIn())
- return 1000;
- State curState = system.getState();
- switch (curState) {
- case TRADE:
- RSPlayer crafter = info.getCrafter();
- if (crafter == null) {
- system.setStatus("Searching for crafter");
- break;
- }
- if (trade.isConfirming()) {
- system.setStatus("Accepting");
- trade.accept();
- } else if (trade.isTrading()) {
- if (trade.getNumberOfItemsOffered() > 0) {
- system.setStatus("Accepting");
- trade.accept();
- } else if (inventory.contains(info.getEssenceID())) {
- system.setStatus("Offering items");
- trade.offer(info.getEssenceID(), trade.getFreeSlots());
- return random(1000, 1200);
- }
- } else if (crafter.isOnScreen()) {
- if (trade.requestTrade(crafter)) {
- system.setStatus("Requesting trade");
- return random(3000, 6000);
- }
- } else if (calc.distanceTo(crafter) < 5) {
- camera.turnToCharacter(crafter);
- } else {
- system.walk(crafter.getLocation());
- system.setStatus("Walking to crafter");
- }
- break;
- case BANK:
- system.setStatus("Banking");
- if (bank.isOpen()) {
- if (inventory.getCount() > 0)
- bank.depositAll();
- bank.withdraw(info.getEssenceID(), 0);
- return random(600, 800);
- } else {
- bank.open();
- }
- break;
- case GO_ALTAR:
- if (system.checkEnergy()) {
- system.setStatus("Walking to altar");
- // system.walkPath(info.getPath());
- system.walk(system.getTileInAreaTowardsTile(info.getPathArea(),
- info.ALTAR_TILE));
- }
- break;
- case GO_BANK:
- if (system.checkEnergy()) {
- system.setStatus("Walking to bank");
- // system.walkPath(walking.reversePath(info.getPath()));
- system.walk(system.getTileInAreaTowardsTile(info.getPathArea(),
- info.BANK_TILE));
- }
- break;
- }
- return random(400, 700);
- }
- private class System {
- private String status = "Starting up";
- private State getState() {
- if (trade.isTrading() || trade.isConfirming())
- return State.TRADE;
- if ((inventory.containsOneOf(info.getPaymentID()) || !inventory
- .isFull())) {
- if (!info.atBank()) {
- return State.GO_BANK;
- }
- return State.BANK;
- }
- if (inventory.contains(info.getEssenceID())) {
- if (info.getCrafter() != null) {
- if (calc.distanceTo(info.getCrafter()) < 10) {
- return State.TRADE;
- }
- }
- if (!info.atAltar()) {
- return State.GO_ALTAR;
- }
- return State.TRADE;
- }
- log("ERROR: UNKNOWN STATE!");
- return State.UNK_0;
- }
- private RSTile getTileInAreaTowardsTile(RSArea area, RSTile dest) {
- RSTile closest = walking.getClosestTileOnMap(dest);
- RSTile inArea = area.getNearestTile(closest);
- inArea = inArea.randomizeTile(3, 3);
- return area.getNearestTile(inArea);
- }
- private void walk(RSTile location) {
- if (!walking.isRunEnabled() && walking.getEnergy() > 20)
- walking.setRun(true);
- if (!getMyPlayer().isMoving()
- || calc.distanceTo(walking.getDestination()) < 6) {
- location = location.randomizeTile(2, 2);
- RSTile newTile = walking.getClosestTileOnMap(location);
- if (calc.tileOnScreen(newTile)) {
- mouse.move(calc.tileToScreen(newTile));
- menu.doAction("Walk here");
- } else {
- walking.walkTileMM(newTile);
- }
- }
- }
- private boolean checkEnergy() {
- if (getMyPlayer().getAnimation() == info.getRestingAnim()) {
- RSNPC musician = npcs.getNearest(info.getMusicianID());
- if (musician != null) {
- if (calc.distanceTo(musician) < 4) {
- if (walking.getEnergy() > 90)
- return true;
- } else {
- if (walking.getEnergy() > 50)
- return true;
- }
- }
- } else if (walking.getEnergy() < 20) {
- RSNPC musician = npcs.getNearest(info.getMusicianID());
- if (musician != null) {
- if (calc.distanceTo(musician) > 3
- && calc.distanceTo(musician) < 15) {
- system.walk(musician.getLocation());
- } else {
- walking.rest();
- }
- } else {
- walking.rest();
- }
- system.setStatus("Resting");
- return false;
- }
- return true;
- }
- private String getStatus() {
- return this.status;
- }
- private void setStatus(String status) {
- this.status = status;
- }
- }
- private class InfoDatabase {
- private final RSTile[] PATH_AREA_TILES = { new RSTile(3189, 3440),
- new RSTile(3182, 3440), new RSTile(3181, 3431),
- new RSTile(3171, 3431), new RSTile(3162, 3424),
- new RSTile(3148, 3422), new RSTile(3144, 3414),
- new RSTile(3124, 3406), new RSTile(3130, 3400),
- new RSTile(3143, 3410), new RSTile(3159, 3419),
- new RSTile(3173, 3425), new RSTile(3184, 3428) };
- private final RSArea PATH_AREA = new RSArea(PATH_AREA_TILES);
- private final RSTile BANK_TILE = new RSTile(3182, 3436);
- private final RSTile ALTAR_TILE = new RSTile(3129, 3407);
- private final RSArea ALTAR_AREA = new RSArea(new RSTile(3124, 3400),
- new RSTile(3134, 3408));
- private final RSArea BANK_AREA = new RSArea(new RSTile(3182, 3433),
- new RSTile(3189, 3446));
- private final int RESTING_ANIM = 11786;
- private final int ESSENCE_ID = 1436;
- private final int PURE_ESSENCE_ID = 7936;
- private final int PAYMENT_ID[] = { 1437, 7937, 556, 995 };
- private final int MUSICIAN_ID = 8699;
- private Filter<RSPlayer> CRAFTER_FILTER = new Filter<RSPlayer>() {
- public boolean accept(RSPlayer t) {
- if (t != null) {
- if (t.getName() != null) {
- return t.getName().toLowerCase()
- .equals(gui.getName().toLowerCase());
- }
- }
- return false;
- }
- };
- private boolean pure = false;
- private RSArea getPathArea() {
- return this.PATH_AREA;
- }
- private boolean atAltar() {
- return this.ALTAR_AREA.contains(getMyPlayer().getLocation());
- }
- private boolean atBank() {
- return BANK_AREA.contains(getMyPlayer().getLocation());
- }
- private int getRestingAnim() {
- return this.RESTING_ANIM;
- }
- private int getMusicianID() {
- return this.MUSICIAN_ID;
- }
- private int[] getPaymentID() {
- return this.PAYMENT_ID;
- }
- private int getEssenceID() {
- if (this.pure)
- return this.PURE_ESSENCE_ID;
- return this.ESSENCE_ID;
- }
- private RSPlayer getCrafter() {
- RSPlayer player = players.getNearest(CRAFTER_FILTER);
- return player;
- }
- }
- private class GUI {
- private String name = "";
- private boolean shouldStart = false;
- private String getName() {
- return this.name.replace(' ', '\u00A0');
- }
- private boolean show() {
- JFrame frame;
- JPanel namePanel = new JPanel();
- JTextField crafterName = new JTextField(12);
- namePanel.setLayout(new FlowLayout());
- namePanel.add(new JLabel("Crafter name: "));
- namePanel.add(crafterName);
- frame = new JFrame("GUI for Jomik's Air Runner!");
- JPanel panel = new JPanel();
- JButton submit = new JButton("Start!");
- panel.setLayout(new BorderLayout());
- panel.add(namePanel, BorderLayout.CENTER);
- frame.setLayout(new BorderLayout());
- frame.add(panel, BorderLayout.NORTH);
- frame.add(submit, BorderLayout.SOUTH);
- frame.pack();
- frame.setVisible(true);
- frame.setAlwaysOnTop(true);
- submit.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- shouldStart = true;
- }
- });
- while(!shouldStart)
- try{
- Thread.sleep(500);
- }catch(Exception e){
- return false;
- };
- try{
- String newName = crafterName.getText();
- if (newName != null && !newName.equals("")) {
- this.name = newName;
- }
- else {
- log("ERROR: INVALID NAME");
- frame.dispose();
- return false;
- }
- }catch(Exception e){
- frame.dispose();
- shouldStart = false;
- return false;
- }
- shouldStart = false;
- frame.dispose();
- return true;
- }
- }
- public class Trade {
- private final static int INTERFACE_MAIN = 335;
- private final static int INTERFACE_MAIN_ACCEPT = 16;
- private final static int INTERFACE_MAIN_DECLINE = 18;
- private final static int INTERFACE_MAIN_INV_SLOTS = 21;
- private final static int INTERFACE_MAIN_ITEMS = 31;
- private final static int INTERFACE_MAIN_INFO = 38;
- private final static int INTERFACE_CONFIRM = 334;
- private final static int INTERFACE_CONFIRM_ACCEPT = 35;
- private final static int INTERFACE_CONFIRM_DECLINE = 36;
- private final static int INTERFACE_CONFIRM_NAME = 46;
- private final static int INTERFACE_CONFIRM_INFO = 33;
- private boolean isTrading() {
- return interfaces.get(INTERFACE_MAIN)
- .getComponent(INTERFACE_MAIN_ACCEPT).isValid();
- }
- private boolean isConfirming() {
- return interfaces.get(INTERFACE_CONFIRM)
- .getComponent(INTERFACE_CONFIRM_ACCEPT).isValid();
- }
- private int getNumberOfItemsOffered() {
- int number = 0;
- for (int i = 0; i < 28; i++) {
- if (interfaces.get(INTERFACE_MAIN)
- .getComponent(INTERFACE_MAIN_ITEMS).getComponent(i)
- .getComponentStackSize() != 0)
- ++number;
- }
- return number;
- }
- private int getFreeSlots() {
- if (isTrading()) {
- String text = interfaces.get(INTERFACE_MAIN)
- .getComponent(INTERFACE_MAIN_INV_SLOTS).getText()
- .substring(4, 6);
- text = text.trim();
- try {
- return Integer.parseInt(text);
- } catch (Exception e) {
- }
- }
- return 0;
- }
- private boolean requestTrade(RSPlayer player) {
- if (player.isOnScreen()) {
- String action = "Trade with " + player.getName() + " (level: "
- + player.getCombatLevel() + ")";
- RSModel model = player.getModel();
- if (model == null)
- return false;
- Point p = model.getPoint();
- if (p.x == -1 || p.y == -1) {
- return false;
- }
- mouse.click(p, false);
- return menu.doAction(action);
- }
- return false;
- }
- private boolean accept() {
- if (isConfirming()) {
- if (interfaces.get(INTERFACE_CONFIRM)
- .getComponent(INTERFACE_CONFIRM_INFO).getText()
- .toLowerCase().contains("waiting"))
- return true;
- else
- return interfaces.get(INTERFACE_CONFIRM)
- .getComponent(INTERFACE_CONFIRM_ACCEPT)
- .doAction("Accept");
- }
- else if (isTrading()) {
- if (interfaces.get(INTERFACE_MAIN)
- .getComponent(INTERFACE_MAIN_INFO).getText()
- .toLowerCase().contains("waiting"))
- return true;
- else
- return interfaces.get(INTERFACE_MAIN)
- .getComponent(INTERFACE_MAIN_ACCEPT)
- .doAction("Accept");
- }
- return false;
- }
- private boolean decline() {
- if (isTrading())
- return interfaces.get(INTERFACE_MAIN)
- .getComponent(INTERFACE_MAIN_DECLINE)
- .doAction("Decline");
- else if (isConfirming()) {
- return interfaces.get(INTERFACE_CONFIRM)
- .getComponent(INTERFACE_CONFIRM_DECLINE)
- .doAction("Decline");
- }
- return false;
- }
- private boolean offer(final int itemID, final int numberToOffer) {
- if (isTrading()) {
- final int inventoryCount = inventory.getCount(itemID);
- RSItem item = inventory.getItem(itemID);
- if (numberToOffer < 0)
- throw new IllegalArgumentException("numberToOffer < 0 ("
- + numberToOffer + ")");
- switch (numberToOffer) {
- case 0:
- item.doAction("Offer-All");
- break;
- case 1:
- item.doAction("Offer-1");
- break;
- case 5:
- item.doAction("Offer-5");
- break;
- case 10:
- item.doAction("Offer-10");
- break;
- case 28:
- item.doAction("Offer-All");
- break;
- default:
- if (item.doAction("Offer-X")) {
- sleep(random(1000, 1300));
- keyboard.sendText("" + numberToOffer, true);
- }
- break;
- }
- return (inventory.getCount(itemID) < inventoryCount)
- || (inventory.getCount() == 0);
- }
- return false;
- }
- }
- public class Paint {
- /**
- * Gets the point the tile would be on if the minimap was bigger.
- *
- * @param t
- * The tile to convert to a point.
- * @author Enfilade
- */
- private Point tileToMinimap(RSTile t) {
- RSTile player = getMyPlayer().getLocation();
- Point a = calc.tileToMinimap(player);
- Point b = calc.tileToMinimap(new RSTile(player.getX(), player
- .getY() + 10));
- Point c = calc.tileToMinimap(new RSTile(player.getX() + 10, player
- .getY()));
- double bDistX = (b.x - a.x) / 10.0;
- double bDistY = (b.y - a.y) / 10.0;
- double cDistX = (c.x - a.x) / 10.0;
- double cDistY = (c.y - a.y) / 10.0;
- int xDist = t.getX() - player.getX();
- int yDist = t.getY() - player.getY();
- return new Point(a.x + (int) (cDistX * xDist + bDistX * yDist), a.y
- + (int) (bDistY * yDist + cDistY * xDist));
- }
- private void paint(Graphics render) {
- if (!game.isLoggedIn())
- return;
- Graphics2D g = (Graphics2D) render;
- g.drawString("Status: " + system.getStatus(), 200, 200);
- g.drawString("Crafter: " + gui.getName(), 200, 220);
- Polygon p = new Polygon();
- for (RSTile t : info.PATH_AREA_TILES) {
- Point po = tileToMinimap(t);
- p.addPoint(po.x, po.y);
- }
- g.setColor(Color.BLACK);
- g.draw(p);
- g.setColor(new Color(0, 255, 0, 100));
- g.fill(p);
- }
- }
- @Override
- public void onRepaint(Graphics render) {
- paint.paint(render);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement