Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.mining.iclayfarmer;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import java.text.DecimalFormat;
- 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.api2007.Game;
- import org.tribot.api2007.Interfaces;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.NPCChat;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.Skills;
- import org.tribot.api2007.Skills.SKILLS;
- import org.tribot.api2007.Walking;
- import org.tribot.api2007.types.RSInterface;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.script.EnumScript;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.Painting;
- import scripts.methods.Methods;
- @ScriptManifest(authors = { "Ian" }, category = "Money Making", name = "iClayFarmer")
- public class Main extends EnumScript<Settings.State> implements Painting {
- private Bank banking = null;
- private Data data = null;
- private Walk walking = null;
- private Mining mining = null;
- private Pickaxe pickaxe = null;
- private Settings.Task task = null;
- private GUI gui = null;
- private SmokingRock smokingRock = null;
- private AntiBan antiBan = null;
- private Settings.Bracelet bracelet = null;
- private Settings.Locations location = null;
- private Settings.State state = null;
- private int hoursToRun = -1;
- private int braceletPrice = -1;
- private int clayPrice = -1;
- private int softClayPrice = -1;
- private boolean scriptEnd = false;
- private DecimalFormat decimalFormat = new DecimalFormat("#.##");
- private final String PAINT_PICTURE_URL = "http://i43.tinypic.com/mjpbbt.png";
- private final Image PAINT_IMG = Methods.getImage(PAINT_PICTURE_URL);
- @Override
- public void onPaint(Graphics g) {
- ((Graphics2D)g).drawImage(PAINT_IMG, 0, 290, null);
- g.setColor(Color.WHITE);
- g.setFont(new Font("default", Font.BOLD, 12));
- g.drawString(getStateToString(), 39, 430);
- int clay = getTask().equals(Settings.Task.MINE) && getBracelet().equals(Settings.Bracelet.NO) ? getData().getClayMined() : getData().getSoftClayMade();
- int softClayHr = (int) (clay / ((getRunningTime()) / 3600000D));
- g.drawString(clay + " (" + softClayHr + ")", 290, 358);
- double gpMade = getGPMade();
- double gpPerHour = (double) (gpMade / ((getRunningTime()) / 3600000D));
- g.drawString(setInMoneyFormat(gpMade) + " (" + setInMoneyFormat(gpPerHour) + ")", 290, 384);
- int levelsGained = Skills.getActualLevel(SKILLS.MINING) - getData().getStartLevel();
- g.drawString(Skills.getActualLevel(SKILLS.MINING) + " (" + levelsGained +")", 290, 412);
- int xpGained = getData().getCurrentXP() - getData().getStartXP();
- int xpPerHour = (int) (xpGained / ((getRunningTime()) / 3600000D));
- g.drawString(xpGained + " (" + xpPerHour + ")", 290, 438);
- g.drawString(Timing.msToString(getRunningTime()), 290, 464);
- }
- public int getGPMade() {
- int softClayMade = getData().getSoftClayMade();
- int moneySpent = getData().getMoneySpent();
- int clayMined = getData().getClayMined();
- boolean wearingBracelet = getBracelet().equals(Settings.Bracelet.YES);
- switch(getTask()) {
- case MINE:
- if(wearingBracelet) {
- return (softClayMade * getSoftClayPrice()) - moneySpent;
- }
- return (clayMined * getClayPrice());
- case MINE_AND_SOFTEN:
- return (softClayMade * getSoftClayPrice());
- case SOFTEN:
- return ((softClayMade * getSoftClayPrice()) - (softClayMade * getClayPrice()));
- }
- return 0;
- }
- @Override
- public Settings.State getInitialState() {
- if(gui == null) {
- setGui(new GUI(this));
- }
- while(getGui().isVisible()) {
- sleep(50, 100);
- }
- if(data == null) {
- setData(new Data(this));
- }
- if(banking == null) {
- setBanking(new Bank(this));
- }
- if(pickaxe == null) {
- setPickaxe(new Pickaxe(this));
- }
- if(walking == null) {
- setWalking(new Walk(this));
- }
- if(mining == null) {
- setMining(new Mining(this));
- }
- if(smokingRock == null) {
- setSmokingRock(new SmokingRock(this));
- }
- if(antiBan == null) {
- setAntiBan(new AntiBan(this));
- }
- getData().getInitialData();
- Walking.setWalkingTimeout(2000);
- Walking.setControlClick(true);
- Mouse.setSpeed(130+General.random(0, 10));
- println("Location: " + getLocation().toString());
- if(getPickaxe().hasBrokenAxe()) {
- Settings.State s = null;
- if(Inventory.getCount(995) < getPickaxeRepairReq(getData().getPickaxeId())) {
- s = Settings.State.WALKING_TO_BANK;
- } else {
- s = Settings.State.WALKING_TO_BOB;
- }
- setState(s);
- return s;
- }
- if(Constants.isInsideVarrockMine() || Constants.isInsideCraftingGuild()) {
- setState(Settings.State.MINING_CLAY_ROCKS);
- return Settings.State.MINING_CLAY_ROCKS;
- }
- if(isAtWaterSource()) {
- setState(Settings.State.MAKING_SOFT_CLAY);
- return Settings.State.MAKING_SOFT_CLAY;
- }
- if(getBanking().isInsideBank()) {
- setState(Settings.State.BANKING);
- return Settings.State.BANKING;
- }
- setState(Settings.State.BANKING);
- return Settings.State.BANKING;
- }
- public int getPickaxeRepairReq(int pickaxeId) {
- final int[][] data = Constants.PICKAXES;
- if(pickaxeId == data[0][0]) {
- return 0;
- } else if(pickaxeId == data[1][0]) {
- return 0;
- } else if(pickaxeId == data[2][0]) {
- return 17;
- } else if(pickaxeId == data[3][0]) {
- return 43;
- } else if(pickaxeId == data[4][0]) {
- return 107;
- } else if(pickaxeId == data[5][0]) {
- return 1100;
- }
- return 0;
- }
- @Override
- public Settings.State handleState(Settings.State state) {
- if(isScriptEnd()) {
- Thread.currentThread().interrupt();
- return null;
- }
- state = getState() != null ? getState() : getInitialState();
- getData().setCurrentXP(Skills.getXP(Skills.SKILLS.MINING));
- getData().setCurrentLevel(Skills.getActualLevel(Skills.SKILLS.MINING));
- switch(state) {
- case BANKING:
- if(getBanking().isInsideBank()) {
- getBanking().performBankTask();
- if(getBanking().isInventorySetup()) {
- switch(getTask()) {
- case MINE:
- case MINE_AND_SOFTEN:
- setState(Settings.State.WALKING_TO_CLAY_ROCKS);
- return Settings.State.WALKING_TO_CLAY_ROCKS;
- case SOFTEN:
- setState(Settings.State.WALKING_TO_WATER_SOURCE);
- return Settings.State.WALKING_TO_WATER_SOURCE;
- }
- }
- return Settings.State.BANKING;
- }
- setState(Settings.State.WALKING_TO_BANK);
- return Settings.State.WALKING_TO_BANK;
- case WALKING_TO_CLAY_ROCKS:
- getWalking().toMine();
- return Settings.State.WALKING_TO_CLAY_ROCKS;
- case MINING_CLAY_ROCKS:
- if(getMining().isInsideMine()) {
- if(!getPickaxe().hasPickaxe()) {
- if(getPickaxe().isHeadOnGround()) {
- getPickaxe().pickupHead();
- getPickaxe().attachHead();
- } else {
- setState(Settings.State.WALKING_TO_BANK);
- return Settings.State.WALKING_TO_BANK;
- }
- }
- if(getMining().canMine()) {
- getMining().mineRock();
- return Settings.State.MINING_CLAY_ROCKS;
- }
- switch(getTask()) {
- case MINE_AND_SOFTEN:
- setState(Settings.State.WALKING_TO_WATER_SOURCE);
- return Settings.State.WALKING_TO_WATER_SOURCE;
- case MINE:
- setState(Settings.State.WALKING_TO_BANK);
- return Settings.State.WALKING_TO_BANK;
- }
- }
- setState(Settings.State.WALKING_TO_CLAY_ROCKS);
- return Settings.State.WALKING_TO_CLAY_ROCKS;
- case WALKING_TO_WATER_SOURCE:
- getWalking().toFountain();
- return Settings.State.WALKING_TO_WATER_SOURCE;
- case MAKING_SOFT_CLAY:
- if(isAtWaterSource()) {
- performClayTask();
- if(isClayTaskFinished()) {
- setState(Settings.State.WALKING_TO_BANK);
- return Settings.State.WALKING_TO_BANK;
- }
- return Settings.State.MAKING_SOFT_CLAY;
- }
- setState(Settings.State.WALKING_TO_BANK);
- return Settings.State.WALKING_TO_BANK;
- case WALKING_TO_BANK:
- if(getPickaxe().isAxeBroken()) {
- getPickaxe().walkToBank();
- return Settings.State.WALKING_TO_BANK;
- }
- getWalking().toBank();
- return Settings.State.WALKING_TO_BANK;
- case WALKING_TO_BOB:
- getPickaxe().walkToShop();
- if(Constants.isInsideAxeShop()) {
- setState(Settings.State.REPAIRING_PICKAXE);
- return Settings.State.REPAIRING_PICKAXE;
- }
- return Settings.State.WALKING_TO_BOB;
- case REPAIRING_PICKAXE:
- getPickaxe().repairAxe();
- if(!getPickaxe().isAxeBroken()) {
- setState(Settings.State.WALKING_TO_BANK);
- return Settings.State.WALKING_TO_BANK;
- }
- return Settings.State.REPAIRING_PICKAXE;
- }
- return null;
- }
- public boolean isAtWaterSource() {
- if(Constants.isInsideVarrockSquare()
- || Constants.isAtWaterPump()
- || Constants.isAtWell()
- || Constants.isAtEastFountain()) {
- return true;
- }
- return false;
- }
- private boolean isClayTaskFinished() {
- RSItem[] clay = Inventory.find(Constants.CLAY_ITEM);
- if(clay == null || clay.length <= 0) {
- return true;
- }
- return false;
- }
- private void performClayTask() {
- RSObject fountain = Methods.findObjectByModelPoints(new int[]{ getWaterModelPoints() });
- if(fountain != null) {
- makeSoftClay();
- }
- }
- private int getWaterModelPoints() {
- switch(getLocation()) {
- case VARROCK:
- switch(getTask()) {
- case MINE_AND_SOFTEN:
- return Constants.VARROCK_SQUARE_FOUNTAIN;
- case SOFTEN:
- return Constants.VARROCK_EAST_FOUNTAIN;
- }
- case FALADOR:
- return Constants.WATERPUMP;
- case EDGEVILLE:
- return Constants.WELL;
- }
- return -1;
- }
- private void makeSoftClay() {
- if(Inventory.getCount(Constants.CLAY_ITEM) <= 0) {
- int softClayMade = Inventory.getCount(Constants.SOFT_CLAY);
- getData().setSoftClayMade(getData().getSoftClayMade() + softClayMade);
- setState(Settings.State.WALKING_TO_BANK);
- return;
- }
- while(Inventory.getCount(Constants.BUCKET_OF_WATER) < Inventory.getCount(Constants.CLAY_ITEM) && Inventory.getCount(Constants.BUCKET) > 0) {
- fillBuckets(Methods.findObjectByModelPoints(new int[]{ getWaterModelPoints() }));
- sleep(50, 100);
- }
- RSItem[] clay = Inventory.find(Constants.CLAY_ITEM);
- RSItem[] waterBucket = Inventory.find(Constants.BUCKET_OF_WATER);
- if(clay != null && waterBucket != null) {
- getData().setTimeout(System.currentTimeMillis());
- while(clay != null && clay.length >= 0
- && waterBucket != null && waterBucket.length >= 0
- && !isTimedOut(20000, 22000)) {
- clay = Inventory.find(Constants.CLAY_ITEM);
- waterBucket = Inventory.find(Constants.BUCKET_OF_WATER);
- if(Inventory.getCount(Constants.CLAY_ITEM) > 0
- && Inventory.getCount(Constants.BUCKET_OF_WATER) > 0) {
- if(clay[0].click("Use")) {
- if(waterBucket[waterBucket.length - 1].click("Use")) {
- if(Inventory.getCount(Constants.CLAY_ITEM) == 1) {
- if(allClaySoft(1500)) {
- int softClayMade = Inventory.getCount(Constants.SOFT_CLAY);
- getData().setSoftClayMade(getData().getSoftClayMade() + softClayMade);
- setState(Settings.State.WALKING_TO_BANK);
- break;
- }
- }
- if(makeInterface(1000)) {
- int[] clayInterfaceData = Constants.SOFT_CLAY_INTERFACE;
- RSInterface clayInterface = Interfaces.get(clayInterfaceData[0], clayInterfaceData[1]);
- if(clayInterface != null) {
- while(Interfaces.get(clayInterfaceData[0], clayInterfaceData[1]) != null) {
- if(clayInterface.click("Make All")) {
- int clayCount = Inventory.getCount(Constants.CLAY_ITEM);
- if(allClaySoft(clayCount * 1500)) {
- int softClayMade = Inventory.getCount(Constants.SOFT_CLAY);
- getData().setSoftClayMade(getData().getSoftClayMade() + softClayMade);
- setState(Settings.State.WALKING_TO_BANK);
- break;
- }
- }
- sleep(50, 100);
- }
- }
- if(getState().equals(Settings.State.WALKING_TO_BANK)) {
- break;
- }
- }
- }
- }
- }
- sleep(50, 100);
- }
- }
- }
- private boolean allClaySoft(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- getAntiBan().performRandomAntiBan();
- if(Inventory.getCount(Constants.CLAY_ITEM) <= 0) {
- return true;
- }
- if(NPCChat.getMessage() != null) {
- return false;
- }
- if(Inventory.getCount(Constants.BUCKET_OF_WATER) <= 0) {
- return false;
- }
- sleep(50, 150);
- }
- return false;
- }
- private boolean makeInterface(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- RSInterface clayInterface = Interfaces.get(309, 2);
- if(clayInterface != null) {
- return true;
- }
- sleep(50, 150);
- }
- return false;
- }
- private void fillBuckets(RSObject fountain) {
- RSItem[] bucket = Inventory.find(Constants.BUCKET);
- if(bucket != null) {
- if(bucket != null && bucket.length > 0) {
- bucket = Inventory.find(Constants.BUCKET);
- if(bucket != null && bucket.length > 0) {
- if(bucket[0].click("Use")) {
- String uptext = getWaterUptext();
- while(Inventory.getCount(Constants.BUCKET) > 0 && !Game.getUptext().contains(uptext) && Game.getUptext().contains("Bucket")) {
- if(!Game.getUptext().contains(uptext))
- fountain.hover();
- sleep(50, 100);
- }
- if(fountain.click("Use")) {
- int bucketAmount = Inventory.getCount(Constants.BUCKET);
- if(playingBucketAnimation(4000)) {
- bucketsFull(600 * bucketAmount);
- }
- }
- }
- }
- }
- }
- }
- private String getWaterUptext() {
- switch(getLocation()) {
- case VARROCK:
- return "Fountain";
- case FALADOR:
- return "Waterpump";
- case EDGEVILLE:
- return "Well";
- }
- return "";
- }
- private boolean bucketsFull(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if(NPCChat.getMessage() != null) {
- return false;
- }
- if(Inventory.getCount(Constants.BUCKET_OF_WATER) >= Inventory.getCount(Constants.CLAY_ITEM)){
- return true;
- }
- if(Player.getAnimation() == -1) {
- if (Inventory.getCount(Constants.BUCKET) <= 0) {
- return true;
- }
- }
- sleep(50, 150);
- }
- return false;
- }
- private boolean playingBucketAnimation(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if(Player.getAnimation() == 832) {
- return true;
- }
- sleep(50, 150);
- }
- return false;
- }
- private String getStateToString() {
- switch(getState()) {
- case BANKING:
- return "Banking";
- case WALKING_TO_CLAY_ROCKS:
- return "Walking to Clay Rocks";
- case MINING_CLAY_ROCKS:
- return "Mining Clay Rocks";
- case WALKING_TO_WATER_SOURCE:
- return "Walking to Water Source";
- case MAKING_SOFT_CLAY:
- return "Making Soft Clay";
- case WALKING_TO_BANK:
- return "Walking to Bank";
- case WALKING_TO_BOB:
- return "Walking to Bob";
- case REPAIRING_PICKAXE:
- return "Repairing Pickaxe";
- }
- return "Waiting";
- }
- public boolean isTimedOut(int min, int max) {
- if(System.currentTimeMillis() - getData().getTimeout() < General.random(min, max)) {
- return false;
- }
- return true;
- }
- private static 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 itemName) {
- String s = "";
- try {
- s = readUrl("http://forums.zybez.net/runescape-2007-prices/api/"+itemName.replaceAll("\\s","+"));
- } catch (Exception e) {
- e.printStackTrace();
- }
- Pattern pattern = Pattern.compile("(?<=\"average\":\")[0-9]+");
- Matcher matcher = pattern.matcher(s);
- while (matcher.find())
- return(Integer.parseInt(matcher.group()));
- return 0;
- }
- private String zybezString = "";
- public void openZybezItemData(String ItemName){
- try {
- zybezString = readUrl("http://forums.zybez.net/runescape-2007-prices/api/"+ItemName.replaceAll("\\s","+"));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public int getAveragePrice() {
- Pattern pattern = Pattern.compile("(?<=\"average\":\")[0-9]+");
- Matcher matcher = pattern.matcher(zybezString);
- while (matcher.find())
- return(Integer.parseInt(matcher.group()));
- return 0;
- }
- private String setInMoneyFormat(double amount) {
- final int ONE_K = 1000;
- if(amount >= ONE_K) {
- return decimalFormat.format(((double) amount / ONE_K)) + "K";
- }
- return "" + decimalFormat.format(amount);
- }
- public Bank getBanking() {
- return banking;
- }
- public void setBanking(Bank banking) {
- this.banking = banking;
- }
- public Data getData() {
- return data;
- }
- public void setData(Data data) {
- this.data = data;
- }
- public void setState(Settings.State state) {
- this.state = state;
- }
- public Settings.State getState() {
- return state;
- }
- public void setWalking(Walk walking) {
- this.walking = walking;
- }
- public Walk getWalking() {
- return walking;
- }
- public void setMining(Mining mining) {
- this.mining = mining;
- }
- public Mining getMining() {
- return mining;
- }
- public void setPickaxe(Pickaxe pickaxe) {
- this.pickaxe = pickaxe;
- }
- public Pickaxe getPickaxe() {
- return pickaxe;
- }
- public int getSoftClayPrice() {
- return softClayPrice;
- }
- public void setSoftClayPrice(int softClayPrice) {
- this.softClayPrice = softClayPrice;
- }
- public void setTask(Settings.Task task) {
- this.task = task;
- }
- public Settings.Task getTask() {
- return task;
- }
- public void setGui(GUI gui) {
- this.gui = gui;
- }
- public GUI getGui() {
- return gui;
- }
- public void setScriptEnd(boolean scriptEnd) {
- this.scriptEnd = scriptEnd;
- }
- public boolean isScriptEnd() {
- return scriptEnd;
- }
- public void setSmokingRock(SmokingRock smokingRock) {
- this.smokingRock = smokingRock;
- }
- public SmokingRock getSmokingRock() {
- return smokingRock;
- }
- public AntiBan getAntiBan() {
- return antiBan;
- }
- public void setAntiBan(AntiBan antiBan) {
- this.antiBan = antiBan;
- }
- public void setLocation(Settings.Locations location) {
- this.location = location;
- }
- public Settings.Locations getLocation() {
- return location;
- }
- public void setClayPrice(int clayPrice) {
- this.clayPrice = clayPrice;
- }
- public int getClayPrice() {
- return clayPrice;
- }
- public void setHoursToRun(int hoursToRun) {
- this.hoursToRun = hoursToRun;
- }
- public int getHoursToRun() {
- return hoursToRun;
- }
- public void setBracelet(Settings.Bracelet bracelet) {
- this.bracelet = bracelet;
- }
- public Settings.Bracelet getBracelet() {
- return bracelet;
- }
- public void setBraceletPrice(int braceletPrice) {
- this.braceletPrice = braceletPrice;
- }
- public int getBraceletPrice() {
- return braceletPrice;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement