Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.moneymaking.flaxpicker;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Point;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api.input.Mouse;
- import org.tribot.api.util.ABCUtil;
- import org.tribot.api2007.Banking;
- import org.tribot.api2007.Camera;
- import org.tribot.api2007.Game;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Options;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.Walking;
- import org.tribot.api2007.WebWalking;
- import org.tribot.api2007.types.RSArea;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.api2007.types.RSTile;
- import org.tribot.script.EnumScript;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.MouseActions;
- import org.tribot.script.interfaces.MousePainting;
- import org.tribot.script.interfaces.MouseSplinePainting;
- import org.tribot.script.interfaces.Painting;
- import scripts.methods.Methods;
- @ScriptManifest(authors = { "Ian" }, category = "Money Making", name = "iFlaxPicker")
- public class FlaxPicker extends EnumScript<FlaxState> implements Painting,
- MouseSplinePainting, MousePainting, MouseActions {
- private FlaxState state;
- private FlaxLocation location;
- private RSArea bankArea = null;
- private RSArea flaxArea = null;
- private RSTile flaxTile = null;
- private RSTile bankTile = null;
- private int flaxCount = 0;
- private int tripCount = 0;
- private int flaxPrice = -1;
- private long timeout = 0,
- startTime = 0,
- lastTripTime = 0,
- currentTripTime = 0,
- averageTripTime = 0,
- totalTripTime = 0,
- lastPlayerRan = 0;
- private DecimalFormat decimalFormat = new DecimalFormat("#.##");
- private final String PAINT_PICTURE_URL = "http://i43.tinypic.com/2euha2g.png";
- private final Image PAINT_IMAGE = Methods.getImage(PAINT_PICTURE_URL);
- @Override
- public void onPaint(Graphics g) {
- ((Graphics2D)g).drawImage(PAINT_IMAGE, 7, 345, null);
- g.setFont(new Font("Verdana", Font.BOLD, 11));
- g.setColor(Color.WHITE);
- g.drawString(getState().toString().replaceAll("_", " "), 11, 470);
- int flaxPerHr = ((int) (getFlaxCount() / (getRunningTime() / 3600000D)));
- double gpMade = ((double) (getFlaxCount() * getFlaxPrice()));
- double gpPerHr = ((double) (gpMade / (getRunningTime() / 3600000D)));
- g.drawString(getFlaxCount() + " (" +flaxPerHr+")", 125, 370);
- g.drawString(setInMoneyFormat(gpMade) + " (" +setInMoneyFormat(gpPerHr)+")", 110, 390);
- g.drawString(Timing.msToString(getRunningTime()), 127, 410);
- int tripsPerHr = ((int) (getTripCount() / (getRunningTime() / 3600000D)));
- g.drawString(getTripCount() + " (" + tripsPerHr + ")", 317, 370);
- g.drawString(Timing.msToString(getLastTripTime()), 385, 390);
- g.drawString(Timing.msToString(getAverageTripTime()), 415, 410);
- }
- public void setArea() {
- if(FlaxConstants.GNOME_BANK_AREA.contains(Player.getPosition())
- || FlaxConstants.GNOME_FLAX_AREA.contains(Player.getPosition())) {
- setLocation(FlaxLocation.GNOME_STRONGHOLD);
- setBankArea(FlaxConstants.GNOME_BANK_AREA);
- setFlaxArea(FlaxConstants.GNOME_FLAX_AREA);
- setFlaxTile(FlaxConstants.GNOME_FLAX_TILE);
- setBankTile(FlaxConstants.GNOME_BANK_TILE);
- } else if(FlaxConstants.SEERS_BANK_AREA.contains(Player.getPosition())
- || FlaxConstants.SEERS_FLAX_AREA.contains(Player.getPosition())) {
- setLocation(FlaxLocation.SEERS_VILLAGE);
- setBankArea(FlaxConstants.SEERS_BANK_AREA);
- setFlaxArea(FlaxConstants.SEERS_FLAX_AREA);
- setFlaxTile(FlaxConstants.SEERS_FLAX_TILE);
- setBankTile(FlaxConstants.SEERS_BANK_TILE);
- }
- }
- private String readUrl(String urlString) throws Exception {
- BufferedReader reader = null;
- URLConnection uc = null;
- try {
- URL url = new URL(urlString);
- uc = url.openConnection();
- uc.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
- uc.connect();
- reader = new BufferedReader(new InputStreamReader(uc.getInputStream()));
- StringBuffer buffer = new StringBuffer();
- int read;
- char[] chars = new char[1024];
- while ((read = reader.read(chars)) != -1)
- buffer.append(chars, 0, read);
- return buffer.toString();
- } finally {
- if (reader != null)
- reader.close();
- }
- }
- public int getZybezPrice(String name) {
- String s = "";
- try {
- s = readUrl("http://forums.zybez.net/runescape-2007-prices/api/"+name.replaceAll("\\s","+"));
- } catch (Exception e) {
- e.printStackTrace();
- }
- Pattern pattern = Pattern.compile("(?<=\"average\":\")[0-9]+");
- Matcher matcher = pattern.matcher(s);
- while (matcher.find()) {
- println(Integer.parseInt(matcher.group()));
- return(Integer.parseInt(matcher.group()));
- }
- return 1;
- }
- private String setInMoneyFormat(double amount) {
- final int ONE_K = 1000;
- final int ONE_M = 1000000;
- if(amount >= ONE_M) {
- return decimalFormat.format(((double) amount / ONE_M)) + "M";
- }
- if(amount >= ONE_K) {
- return decimalFormat.format(((double) amount / ONE_K)) + "K";
- }
- return "" + decimalFormat.format(amount);
- }
- @Override
- public FlaxState getInitialState() {
- setFlaxPrice(getZybezPrice("flax"));
- setArea();
- setStartTime(System.currentTimeMillis());
- Mouse.setSpeed(125 + General.random(0, 25));
- Walking.setWalkingTimeout(2000);
- if(getBankArea().contains(Player.getPosition())) {
- return FlaxState.BANKING;
- } else if(getFlaxArea().contains(Player.getPosition())) {
- if(!Inventory.isFull())
- return FlaxState.PICKING_FLAX;
- else
- return FlaxState.WALKING_TO_BANK;
- } else {
- if(!Inventory.isFull())
- return FlaxState.WALKING_TO_FLAX;
- else
- return FlaxState.WALKING_TO_BANK;
- }
- }
- @Override
- public FlaxState handleState(FlaxState state) {
- checkPlayerRun();
- switch(state) {
- case BANKING:
- if(getBankArea().contains(Player.getPosition())) {
- if(isFlaxBanked()) {
- return FlaxState.WALKING_TO_FLAX;
- }
- return FlaxState.BANKING;
- }
- return FlaxState.WALKING_TO_BANK;
- case WALKING_TO_FLAX:
- if(walkedToFlax()) {
- return FlaxState.PICKING_FLAX;
- }
- return FlaxState.BANKING;
- case PICKING_FLAX:
- if(getFlaxArea().contains(Player.getPosition())) {
- if(pickedFlax()) {
- return FlaxState.WALKING_TO_BANK;
- }
- return FlaxState.PICKING_FLAX;
- }
- return FlaxState.WALKING_TO_FLAX;
- case WALKING_TO_BANK:
- if(walkedToBank()) {
- return FlaxState.BANKING;
- }
- return FlaxState.PICKING_FLAX;
- }
- return null;
- }
- private void bankFlax() {
- setState(FlaxState.BANKING);
- getTripInformation();
- if(!isInventoryEmpty()) {
- if(isBankScreenOpen()) {
- Banking.depositAll();
- }
- }
- }
- private boolean isFlaxBanked() {
- Mouse.setSpeed(180);
- bankFlax();
- if(isInventoryEmpty()) {
- setState(FlaxState.WALKING_TO_FLAX);
- return true;
- }
- return isFlaxBanked();
- }
- private boolean walkedToFlax() {
- Mouse.setSpeed(150);
- if(getCurrentTripTime() == 0)
- setCurrentTripTime(System.currentTimeMillis());
- setTimeout(System.currentTimeMillis());
- while(!getFlaxArea().contains(Player.getPosition()) && !isTimedOut(30000, 60000)) {
- if(Player.getPosition().getPlane() == 1) {
- RSObject staircase = Methods.findObjectByModelPoints(
- new int[] {
- FlaxConstants.STAIRCASE_DOWN_MODEL_POINT_COUNT
- });
- if(staircase != null) {
- WebWalking.walkTo(staircase);
- staircase.click("Climb-down");
- isDown(1000);
- }
- } else {
- Methods.performAntiBan();
- WebWalking.walkTo(getFlaxTile());
- walkedToFlax(3000);
- }
- }
- if(getFlaxArea().contains(Player.getPosition())) {
- setState(FlaxState.PICKING_FLAX);
- return true;
- }
- return walkedToFlax();
- }
- private ABCUtil abc = new ABCUtil();
- private boolean pickedFlax() {
- Mouse.setSpeed(180);
- final int FLAX = 1779;
- setState(FlaxState.PICKING_FLAX);
- Camera.setCameraAngle(General.random(80, 100));
- setTimeout(System.currentTimeMillis());
- while(!Inventory.isFull() && !isTimedOut(90000, 120000)) {
- RSObject flax = Methods.findObjectByModelPoints(new int[]{FlaxConstants.FLAX_MODEL_POINT_COUNT});
- if(flax != null) {
- if(!Player.isMoving()) {
- Methods.waitNewOrSwitchDelay(this.last_chopping_time, false);
- flax.click("Pick");
- this.last_chopping_time = System.currentTimeMillis();
- }
- }
- }
- if(Inventory.isFull()) {
- setState(FlaxState.WALKING_TO_BANK);
- setFlaxCount(getFlaxCount() + Inventory.getCount(FLAX));
- return true;
- }
- return pickedFlax();
- }
- private boolean walkedToBank() {
- Mouse.setSpeed(150);
- setState(FlaxState.WALKING_TO_BANK);
- setTimeout(System.currentTimeMillis());
- while(!getBankArea().contains(Player.getPosition()) && !isTimedOut(30000, 60000)) {
- Methods.performAntiBan();
- WebWalking.walkTo(getBankTile());
- walkedToBank(3000);
- if(getLocation().equals(FlaxLocation.GNOME_STRONGHOLD)) {
- RSObject staircase = Methods.findObjectByModelPoints(
- new int[] {
- FlaxConstants.STAIRCASE_UP_MODEL_POINT_COUNT
- });
- if(staircase != null) {
- staircase.click("Climb-up");
- isUp(1000);
- }
- }
- }
- if(getBankArea().contains(Player.getPosition())) {
- setState(FlaxState.BANKING);
- return true;
- }
- return walkedToBank();
- }
- private void checkPlayerRun() {
- long ran = lastPlayerRan;
- long interval = 60000;
- if(!Game.isRunOn() && System.currentTimeMillis() - ran > interval) {
- if(Game.getRunEnergy() >= abc.INT_TRACKER.NEXT_RUN_AT.next()) {
- Options.setRunOn(true);
- Inventory.open();
- abc.INT_TRACKER.NEXT_RUN_AT.reset();
- }
- }
- if(Game.isRunOn()) {
- lastPlayerRan = System.currentTimeMillis();
- }
- }
- private long last_chopping_time = 0L;
- private void getTripInformation() {
- if(getCurrentTripTime() == 0 && getTripCount() > 0) {
- return;
- }
- if(getTripCount() != 0) {
- setLastTripTime(System.currentTimeMillis() - getCurrentTripTime());
- setTotalTripTime(getTotalTripTime() + getLastTripTime());
- setAverageTripTime(getTotalTripTime() / getTripCount());
- setCurrentTripTime(0);
- setTripCount(getTripCount() + 1);
- } else {
- setTripCount(1);
- }
- }
- private boolean isTimedOut(int min, int max) {
- if(System.currentTimeMillis() - getTimeout() < General.random(min, max)) {
- return false;
- }
- return true;
- }
- private boolean isBankScreenOpen() {
- setTimeout(System.currentTimeMillis());
- while(!Banking.isBankScreenOpen() && !isTimedOut(12000, 15000)) {
- Banking.openBank();
- openedBank(2000);
- }
- return Banking.isBankScreenOpen();
- }
- private boolean isInventoryEmpty() {
- return Inventory.getAll().length <= 0;
- }
- private boolean isDown(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if (Player.getPosition().getPlane() == 0) {
- return true;
- }
- sleep(50, 150);
- }
- return false;
- }
- private boolean isUp(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if (Player.getPosition().getPlane() == 1) {
- return true;
- }
- sleep(50, 150);
- }
- return false;
- }
- private boolean openedBank(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if (Banking.isBankScreenOpen()) {
- return true;
- }
- sleep(50, 150);
- }
- return false;
- }
- private boolean walkedToBank(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if (getBankArea().contains(Player.getPosition())) {
- return true;
- }
- if (!Player.isMoving()) {
- return false;
- }
- sleep(50, 150);
- }
- return false;
- }
- private boolean walkedToFlax(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if (getFlaxArea().contains(Player.getPosition())) {
- return true;
- }
- if (!Player.isMoving()) {
- return false;
- }
- sleep(50, 150);
- }
- return false;
- }
- public void setState(FlaxState state) {
- this.state = state;
- }
- public FlaxState getState() {
- return state;
- }
- public void setFlaxCount(int flaxCount) {
- this.flaxCount = flaxCount;
- }
- public int getFlaxCount() {
- return flaxCount;
- }
- public void setStartTime(long startTime) {
- this.startTime = startTime;
- }
- public long getStartTime() {
- return startTime;
- }
- public long getTimeout() {
- return timeout;
- }
- public void setTimeout(long timeout) {
- this.timeout = timeout;
- }
- public long getLastTripTime() {
- return lastTripTime;
- }
- public void setLastTripTime(long lastTripTime) {
- this.lastTripTime = lastTripTime;
- }
- public long getCurrentTripTime() {
- return currentTripTime;
- }
- public void setCurrentTripTime(long currentTripTime) {
- this.currentTripTime = currentTripTime;
- }
- public long getAverageTripTime() {
- return averageTripTime;
- }
- public void setAverageTripTime(long averageTripTime) {
- this.averageTripTime = averageTripTime;
- }
- public long getTotalTripTime() {
- return totalTripTime;
- }
- public void setTotalTripTime(long totalTripTime) {
- this.totalTripTime = totalTripTime;
- }
- public void setTripCount(int tripCount) {
- this.tripCount = tripCount;
- }
- public int getTripCount() {
- return tripCount;
- }
- public void setFlaxPrice(int flaxPrice) {
- this.flaxPrice = flaxPrice;
- }
- public int getFlaxPrice() {
- return flaxPrice;
- }
- private class Cross {
- private final long time;
- private final Point location;
- private final double rot;
- public Cross(long lifetime, long st, Point loc, double rot) {
- this.time = System.currentTimeMillis() + lifetime;
- location = loc;
- this.rot = rot;
- }
- public long getAge() {
- return time - System.currentTimeMillis();
- }
- public int getAlpha() {
- return Math.min(255,
- Math.max(0, (int) (256.0D * (getAge() / 1500.0D))));
- }
- public boolean handle() {
- return System.currentTimeMillis() <= time;
- }
- public double getRot() {
- return rot;
- }
- public Point getLocation() {
- return location;
- }
- @Override
- public boolean equals(Object o) {
- if (o instanceof Cross) {
- Cross oo = (Cross) o;
- return oo.location.equals(this.location);
- }
- return false;
- }
- }
- public double getRot() {
- return System.currentTimeMillis() % 3600 / 5.0D;
- }
- private final List<Cross> clicks = new LinkedList<Cross>();
- private final Object lock = new Object();
- private boolean paintClick;
- public boolean isPaintClick() {
- return paintClick;
- }
- public void setPaintClick(boolean paintClick) {
- this.paintClick = paintClick;
- }
- @Override
- public void mouseDragged(Point arg0, int arg1, boolean arg2) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseMoved(Point arg0, boolean arg1) {
- // TODO Auto-generated method stub
- }
- @Override
- public void mouseReleased(Point arg0, int arg1, boolean arg2) {
- // TODO Auto-generated method stub
- }
- @Override
- public void paintMouse(Graphics g, Point arg1, Point arg2) {
- final Point location = new Point(Mouse.getPos().x, Mouse.getPos().y);
- g.setColor(Color.GREEN);
- g.drawLine(location.x, location.y - 5, location.x, location.y + 5);
- g.drawLine(location.x - 5, location.y, location.x + 5, location.y);
- if (isPaintClick()) {
- setPaintClick(false);
- Cross newCross = new Cross(1500, General.random(40, 300), location,
- getRot());
- if (!clicks.contains(newCross)) {
- clicks.add(newCross);
- }
- }
- synchronized (lock) {
- Iterator<Cross> clickIterator = clicks.listIterator();
- while (clickIterator.hasNext()) {
- Cross toDraw = clickIterator.next();
- if (toDraw.handle()) {
- drawPoint(toDraw.getLocation(), toDraw.getRot(), g,
- toDraw.getAlpha());
- } else {
- clicks.remove(toDraw);
- }
- }
- }
- }
- private void drawPoint(Point location, double rot, Graphics g, int al) {
- Graphics2D g1 = (Graphics2D) g.create();
- g1.setColor(new Color(255, 0, 0, 155));
- g1.rotate(rot, location.x, location.y);
- g1.drawLine(location.x, location.y - 5, location.x, location.y + 5);
- g1.drawLine(location.x - 5, location.y, location.x + 5, location.y);
- }
- @Override
- public void mouseClicked(Point p, int button, boolean isBot) {
- setPaintClick(true);
- }
- @Override
- public void paintMouseSpline(Graphics arg0, ArrayList<Point> arg1) {
- // TODO Auto-generated method stub
- }
- public void setLocation(FlaxLocation location) {
- this.location = location;
- }
- public FlaxLocation getLocation() {
- return location;
- }
- public void setBankArea(RSArea bankArea) {
- this.bankArea = bankArea;
- }
- public RSArea getBankArea() {
- return bankArea;
- }
- public void setFlaxArea(RSArea flaxArea) {
- this.flaxArea = flaxArea;
- }
- public RSArea getFlaxArea() {
- return flaxArea;
- }
- public void setFlaxTile(RSTile flaxTile) {
- this.flaxTile = flaxTile;
- }
- public RSTile getFlaxTile() {
- return flaxTile;
- }
- public void setBankTile(RSTile bankTile) {
- this.bankTile = bankTile;
- }
- public RSTile getBankTile() {
- return bankTile;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement