Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.WindowEvent;
- import java.awt.event.WindowListener;
- import java.util.ArrayList;
- import org.tribot.api.Timing;
- import org.tribot.api.input.Keyboard;
- import org.tribot.api.input.Mouse;
- import org.tribot.api.types.colour.Tolerance;
- import org.tribot.api.types.generic.Condition;
- import org.tribot.api2007.Banking;
- import org.tribot.api2007.Camera;
- import org.tribot.api2007.GameTab;
- import org.tribot.api2007.GameTab.TABS;
- import org.tribot.api2007.Interfaces;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Objects;
- import org.tribot.api2007.PathFinding;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.Walking;
- import org.tribot.api2007.types.RSInterfaceChild;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.api2007.types.RSTile;
- import org.tribot.script.Script;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.Painting;
- @ScriptManifest(authors = { "Aeronix" }, category = "Money Making", name = "Aeronix's Potato Picker")
- public class AeroPotatoPicker extends Script implements Painting {
- public static SleepCondition Skip;
- public static Integer ITEM_POTATO_ID = 1942;
- public static Integer OBJECT_POTATO_ID = 312;
- public static int[] sack_Ids = { 5418, 5420, 5422, 5424, 5426, 5428, 5430, 5432, 5434, 5436 };
- private Integer Potatoes_Picked = 0;
- private Double Version = 1.4;
- private Activity currentActivity = Activity.Picking;
- private Boolean Running = false;
- private Boolean SackSupport = false;
- Rectangle bankArea = new Rectangle(3092, 3240, 6, 5);
- RSArea PotatoField = null;
- RSTile[] potatoToBank = new RSTile[] { new RSTile(3146, 3286, 0),
- new RSTile(3145, 3294, 0), new RSTile(3135, 3288, 0),
- new RSTile(3135, 3275, 0), new RSTile(3135, 3263, 0),
- new RSTile(3122, 3262, 0), new RSTile(3111, 3259, 0),
- new RSTile(3105, 3251, 0), new RSTile(3094, 3244, 0), };
- RSTile[] bankToPotato;
- public class SleepCondition {
- Condition C;
- Integer Timeout;
- SleepCondition(Condition c, Integer timeout) {
- C = c;
- Timeout = timeout;
- }
- }
- public enum Activity {
- Picking,
- Extract
- }
- private final Color color1 = new Color(0, 0, 0);
- private final Color color2 = new Color(0, 0, 0, 130);
- private final Color color3 = new Color(255, 255, 255);
- private final BasicStroke stroke1 = new BasicStroke(1);
- private final Font font1 = new Font("Arial", 0, 12);
- private final Font font2 = new Font("Arial", 0, 15);
- private final Font font3 = new Font("Arial", 0, 11);
- @Override
- public void onPaint(Graphics arg0) {
- if (getRunningTime() == 0)
- return;
- Graphics2D g = (Graphics2D) arg0;
- Integer hourRate = (int) (Potatoes_Picked * 3600000 / (getRunningTime()));
- String potatoes = String.format("%d Potatoes (%d/HR)", Potatoes_Picked,
- hourRate);
- String timeRan = Timing.msToString(getRunningTime());
- g.setColor(color1);
- g.setStroke(stroke1);
- g.drawRect(556, 375, 173, 81);
- g.setColor(color2);
- g.fillRect(557, 376, 172, 80);
- g.setColor(color3);
- g.setFont(font1);
- g.drawString("Picked:", 571, 420);
- g.drawString("Time Ran:", 571, 398);
- g.setFont(font2);
- g.setColor(color1);
- g.drawString("Aeronix's Potato Picker", 571, 449);
- g.setColor(color3);
- g.drawString("Aeronix's Potato Picker", 569, 447);
- g.setFont(font3);
- g.setColor(color1);
- g.drawString(timeRan, 638, 401);
- g.setColor(color3);
- g.drawString(timeRan, 635, 398);
- g.setColor(color1);
- g.drawString(potatoes, 620, 422);
- g.setColor(color3);
- g.drawString(potatoes, 618, 420);
- }
- @Override
- public void run() {
- Skip = new SleepCondition(new Condition() {
- @Override
- public boolean active() {
- return true;
- }
- }, 1);
- println("Aeronix's Potato Picker BETA, running version " + Version + ".");
- println("Please remember to reguarly check for updates on the thread.");
- Mouse.setSpeed(170);
- bankToPotato = reversePath(potatoToBank);
- PotatoField = new RSArea(new RSTile[] { new RSTile(3153, 3291, 0), new RSTile(3142, 3291, 0), new RSTile(3142, 3290, 0),
- new RSTile(3138, 3290, 0), new RSTile(3138, 3286, 0), new RSTile(3137, 3285, 0),
- new RSTile(3137, 3280, 0), new RSTile(3138, 3279, 0), new RSTile(3138, 3275, 0),
- new RSTile(3137, 3274, 0), new RSTile(3137, 3269, 0), new RSTile(3138, 3268, 0),
- new RSTile(3141, 3268, 0), new RSTile(3141, 3267, 0), new RSTile(3150, 3267, 0),
- new RSTile(3150, 3268, 0), new RSTile(3153, 3268, 0), new RSTile(3155, 3270, 0),
- new RSTile(3155, 3273, 0), new RSTile(3156, 3273, 0), new RSTile(3156, 3282, 0),
- new RSTile(3157, 3282, 0), new RSTile(3157, 3288, 0), new RSTile(3154, 3291, 0) });
- final AeroPotatoPicker instance = this;
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new PotatoPicker(instance).setVisible(true);
- }
- });
- while (true) {
- if (!Running) {
- continue;
- }
- SleepCondition result = loop();
- Timing.waitCondition(result.C, result.Timeout);
- }
- }
- public SleepCondition loop() {
- SleepCondition resultCondition = Skip;
- if (currentActivity == Activity.Picking)
- {
- if (haveAmountInterface()) {
- final int Count = Inventory.getCount(5418);
- Keyboard.typeSend("18");
- resultCondition = new SleepCondition(new Condition() {
- @Override
- public boolean active() {
- return Inventory.getCount(5418) != Count;
- }
- }, 1500);
- Banking.close();
- } else if (Inventory.isFull()) {
- if (isInBank()) {
- RSObject[] booth = Objects.find(10, 2213);
- if (Banking.isBankScreenOpen()) {
- final int Count = Inventory.getCount(ITEM_POTATO_ID);
- Banking.depositAll();
- if (SackSupport) {
- if (Banking.find(5418).length == 0) {
- SackSupport = false;
- } else {
- Banking.find(5418)[0].click("Withdraw X");
- resultCondition = new SleepCondition(new Condition() {
- @Override
- public boolean active() {
- return haveAmountInterface();
- }
- }, 1500);
- }
- } else {
- resultCondition = new SleepCondition(new Condition() {
- @Override
- public boolean active() {
- return Inventory.getCount(ITEM_POTATO_ID) != Count;
- }
- }, 1500);
- Banking.close();
- }
- } else if (booth[0].click("Bank")) {
- if (GameTab.getOpen() != TABS.INVENTORY) {
- GameTab.open(TABS.INVENTORY);
- }
- resultCondition = new SleepCondition(new Condition() {
- @Override
- public boolean active() {
- return Banking.isBankScreenOpen();
- }
- }, 3000);
- }
- } else if (isInPotatoField() && containsEmptySacks() && SackSupport) {
- RSItem[] Sacks = Inventory.find(sack_Ids);
- if (Sacks.length > 0) {
- final int Count = Inventory.getAll().length;
- if (Sacks[0].click("Fill")) {
- resultCondition = new SleepCondition(new Condition() {
- @Override
- public boolean active() {
- return Inventory.getAll().length != Count;
- }
- }, 1250);
- }
- }
- } else if (isInPotatoField() && !isGateOpen()) {
- if (openGate()) {
- resultCondition = new SleepCondition(new Condition() {
- @Override
- public boolean active() {
- return isGateOpen();
- }
- }, 5000);
- }
- } else if (!Player.isMoving() && isGateOpen()) {
- runPath(potatoToBank);
- }
- } else {
- RSObject[] potatoes = Objects.findNearest(15, OBJECT_POTATO_ID);
- if (isNearGate() && !isGateOpen() && !isInPotatoField()) {
- if (openGate()) {
- resultCondition = new SleepCondition(new Condition() {
- @Override
- public boolean active() {
- return isGateOpen();
- }
- }, 6000);
- }
- } else if (isInPotatoField()) {
- if (potatoes.length > 0) {
- final int Count = Inventory.getAll().length;
- if (Interact(potatoes[0], "Pick")) {
- resultCondition = new SleepCondition(new Condition() {
- @Override
- public boolean active() {
- return Inventory.getAll().length != Count;
- }
- }, 4000);
- Potatoes_Picked++;
- }
- }
- } else if (!Player.isMoving()) {
- runPath(bankToPotato);
- }
- }
- } else if (currentActivity == Activity.Extract) {
- }
- return resultCondition;
- }
- public boolean isInBank() {
- int x = Player.getPosition().getX(), y = Player.getPosition().getY();
- return x >= bankArea.x && x <= (bankArea.x + bankArea.width)
- && y >= bankArea.y && y <= (bankArea.y + bankArea.height);
- }
- public boolean isInPotatoField() {
- return PotatoField.contains(Player.getPosition());
- }
- public boolean isNearGate() {
- RSObject[] gateObject = Objects.getAt(new RSTile(3145, 3291, 0));
- if (gateObject.length == 0) {
- return false;
- } else {
- return gateObject[0].getPosition().distanceTo(Player.getPosition()) < 5;
- }
- }
- public boolean isGateOpen() {
- return Objects.getAt(new RSTile(3145, 3291, 0)).length == 0;
- }
- public boolean openGate() {
- if (!isGateOpen()) {
- RSObject gateObject = getObjectAt(new RSTile(3145, 3291, 0), 1551);
- if (gateObject != null) {
- if (!isNearGate() || !gateObject.isOnScreen()) {
- Camera.turnToTile(gateObject.getPosition());
- if (PathFinding.canReach(gateObject.getPosition(), true)) {
- PathFinding.aStarWalk(gateObject.getPosition());
- } else {
- Walking.walkTo(gateObject.getPosition());
- }
- }
- return Interact(gateObject, "Open");
- }
- }
- return true;
- }
- public static void runPath(RSTile[] path) {
- Keyboard.pressKey((char) KeyEvent.VK_CONTROL);
- Walking.walkPath(path);
- Keyboard.releaseKey((char) KeyEvent.VK_CONTROL);
- }
- public static boolean Interact(RSObject object, String option) {
- if (!object.isOnScreen()) {
- Camera.turnToTile(object.getPosition());
- }
- return object.click(option);
- }
- public RSObject getObjectAt(RSTile tile, int Id) {
- RSObject[] objects = Objects.getAt(tile);
- for (RSObject object : objects) {
- if (object.getID() == Id) {
- return object;
- }
- }
- return null;
- }
- public boolean containsSacks() {
- return (containsEmptySacks() || Inventory.getCount(5438) > 0);
- }
- private boolean haveAmountInterface() {
- RSInterfaceChild amount = Interfaces.get(548, 94);
- if ((amount != null) && (!amount.isHidden())) {
- String txt = amount.getText();
- if ((txt != null) && (txt.equals("*"))) {
- Color c = org.tribot.api2007.Screen.getColorAt(259, 428);
- Color b = new Color(0, 0, 128);
- return org.tribot.api.Screen.coloursMatch(b, c, new Tolerance(10));
- }
- }
- return false;
- }
- public boolean containsEmptySacks() {
- for (RSItem item : Inventory.getAll()) {
- Integer Id = item.getID();
- if (Id == 5418 || Id == 5420 || Id == 5422 ||
- Id == 5424 || Id == 5426 || Id == 5428 ||
- Id == 5430 || Id == 5432 || Id == 5434 ||
- Id == 5436) {
- return true;
- }
- }
- return false;
- }
- public static RSTile[] reversePath(RSTile[] path) {
- RSTile[] reverse = new RSTile[path.length];
- int index = 0;
- for (int i = path.length - 1; i >= 0; i--) {
- if (path[i] == null) {
- continue;
- }
- reverse[index] = path[i];
- index++;
- }
- return reverse;
- }
- public class PotatoPicker extends javax.swing.JFrame {
- private static final long serialVersionUID = -172174336364840482L;
- public PotatoPicker(AeroPotatoPicker main) {
- initComponents(main);
- }
- private void initComponents(final AeroPotatoPicker main) {
- jLabel1 = new javax.swing.JLabel();
- jComboBox1 = new javax.swing.JComboBox();
- jCheckBox1 = new javax.swing.JCheckBox();
- jButton1 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setTitle("Aeronix's Potato Picker");
- setLocationRelativeTo(null);
- setAlwaysOnTop(true);
- setResizable(false);
- jLabel1.setText("Select an activity:");
- jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(AeroPotatoPicker.Activity.values()));
- jCheckBox1.setText("Use Sacks");
- jButton1.setText("Start");
- jButton1.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- main.currentActivity = (Activity)jComboBox1.getSelectedItem();
- main.SackSupport = jCheckBox1.isSelected();
- main.Running = true;
- dispose();
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jComboBox1, 0, 172, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jCheckBox1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jCheckBox1)
- .addComponent(jButton1))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- addWindowListener(new WindowListener() {
- public void windowClosed(WindowEvent e) {
- if (!main.Running) {
- main.stopScript();
- }
- }
- public void windowOpened(WindowEvent e) { }
- public void windowIconified(WindowEvent e) { }
- public void windowDeiconified(WindowEvent e) { }
- public void windowDeactivated(WindowEvent e) { }
- public void windowClosing(WindowEvent e) { }
- public void windowActivated(WindowEvent e) {}
- });
- pack();
- }
- private javax.swing.JButton jButton1;
- private javax.swing.JCheckBox jCheckBox1;
- private javax.swing.JComboBox jComboBox1;
- private javax.swing.JLabel jLabel1;
- }
- public class RSArea {
- private final Polygon area;
- private final int plane;
- public RSArea(final RSTile[] tiles, final int plane) {
- area = tilesToPolygon(tiles);
- this.plane = plane;
- }
- public RSArea(final RSTile[] tiles) {
- this(tiles, 0);
- }
- public RSArea(final RSTile southwest, final RSTile northeast) {
- this(southwest, northeast, 0);
- }
- public RSArea(final int swX, final int swY, final int neX, final int neY) {
- this(new RSTile(swX, swY), new RSTile(neX, neY), 0);
- }
- public RSArea(final int swX, final int swY, final int neX,
- final int neY, final int plane) {
- this(new RSTile(swX, swY), new RSTile(neX, neY), plane);
- }
- public RSArea(final RSTile southwest, final RSTile northeast,
- final int plane) {
- this(new RSTile[] { southwest,
- new RSTile(northeast.getX() + 1, southwest.getY()),
- new RSTile(northeast.getX() + 1, northeast.getY() + 1),
- new RSTile(southwest.getX(), northeast.getY() + 1) }, plane);
- }
- public boolean contains(final RSTile... tiles) {
- final RSTile[] areaTiles = getTiles();
- for (final RSTile check : tiles) {
- for (final RSTile space : areaTiles) {
- if (check.equals(space)) {
- return true;
- }
- }
- }
- return false;
- }
- public boolean contains(final int x, final int y) {
- return this.contains(new RSTile(x, y));
- }
- public boolean contains(final int plane, final RSTile... tiles) {
- return this.plane == plane && this.contains(tiles);
- }
- public Rectangle getDimensions() {
- return new Rectangle(area.getBounds().x + 1,
- area.getBounds().y + 1, getWidth(), getHeight());
- }
- public RSTile getNearestTile(final RSTile base) {
- RSTile tempTile = null;
- for (final RSTile tile : getTiles()) {
- if (tempTile == null
- || distanceBetween(base, tile) < distanceBetween(
- tempTile, tile)) {
- tempTile = tile;
- }
- }
- return tempTile;
- }
- public int getPlane() {
- return plane;
- }
- public Polygon getPolygon() {
- return area;
- }
- public RSTile[] getTiles() {
- ArrayList<RSTile> tiles = new ArrayList<RSTile>();
- for (int x = getX(); x <= getX() + getWidth(); x++) {
- for (int y = getY(); y <= getY() + getHeight(); y++) {
- if (area.contains(x, y)) {
- tiles.add(new RSTile(x, y));
- }
- }
- }
- return tiles.toArray(new RSTile[tiles.size()]);
- }
- public int getWidth() {
- return area.getBounds().width;
- }
- public int getHeight() {
- return area.getBounds().height;
- }
- public int getX() {
- return area.getBounds().x;
- }
- public int getY() {
- return area.getBounds().y;
- }
- public Polygon tilesToPolygon(final RSTile[] tiles) {
- final Polygon polygon = new Polygon();
- for (final RSTile t : tiles) {
- polygon.addPoint(t.getX(), t.getY());
- }
- return polygon;
- }
- public double distanceBetween(RSTile curr, RSTile dest) {
- return Math.sqrt((curr.getX() - dest.getX())
- * (curr.getX() - dest.getX()) + (curr.getY() - dest.getY())
- * (curr.getY() - dest.getY()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment