Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.event.KeyEvent;
- import java.io.Console;
- import java.text.DecimalFormat;
- import java.util.concurrent.TimeUnit;
- import org.tbot.util.Condition;
- import org.tbot.wrappers.Area;
- import org.tbot.wrappers.GameObject;
- import org.tbot.wrappers.Item;
- import org.tbot.wrappers.NPC;
- import org.tbot.wrappers.Tile;
- import org.tbot.wrappers.WidgetChild;
- import org.tbot.bot.TBot;
- import org.tbot.internal.AbstractScript;
- import org.tbot.internal.Manifest;
- import org.tbot.internal.event.listeners.PaintListener;
- import org.tbot.methods.Bank;
- import org.tbot.methods.Camera;
- import org.tbot.methods.Game;
- import org.tbot.methods.GameObjects;
- import org.tbot.methods.Menu;
- import org.tbot.methods.Mouse;
- import org.tbot.methods.Npcs;
- import org.tbot.methods.Players;
- import org.tbot.methods.Random;
- import org.tbot.methods.Shop;
- import org.tbot.methods.ShopItem;
- import org.tbot.methods.Skills;
- import org.tbot.methods.Time;
- import org.tbot.methods.Widgets;
- import org.tbot.methods.input.keyboard.Keyboard;
- import org.tbot.methods.tabs.Inventory;
- import org.tbot.methods.walking.Walking;
- @Manifest(name = "oreBuy", authors = "James", version = 0.1, description = "Buys/Hops")
- public class oreBuy extends AbstractScript implements PaintListener{
- GameObject rocks;
- public enum State {
- WAIT, BUY, BANK, HOP, EMPTY, WALKBANK, LOGIN, RETURN;
- }
- private Tile startTile;
- private int xpStart;
- private int mY, mX;
- int barsGained=0;
- private int moneyBefore= Inventory.getCount(995);
- private long timeBegan;
- private long timeRan;
- char control = KeyEvent.VK_CONTROL;
- int invb4;
- int i=0;
- int totalGold=0;
- int totalCoal=0;
- int totalIron=0;
- int moneyGained=0;
- ShopItem myItem;
- NPC banker;
- NPC orden;
- private final Area BUY_AREA = new Area(1937, 4967, 1935, 4965);
- private final Area BANK_AREA = new Area(1947, 4959, 1949, 4957);
- int[] worldArray;
- //359, 334, 328, 303, 317, 338, 329, 313, 370, 330,302
- //346, 376, 342, 367, 304, 321, 354, 358, 377, 365, 343
- //386, 351, 305, 306, 341, 309, 349, 362, 320, 378, 312
- //333, 322, 369, 314, 336, 344, 375, 310, 350, 327, 368
- private final Tile bankTile=new Tile(1948, 4957);
- private int currentWorld;
- private String currentState = "";
- WidgetChild welcomeScreen = Widgets.getWidget(378, 17);
- private final Condition LOGGED_IN = new Condition(){
- public boolean check(){
- return (Game.isLoggedIn());
- }
- };
- private final Condition WELCOME = new Condition(){
- public boolean check(){
- return (welcomeScreen.isVisible());
- }
- };
- private final Condition SHOP_OPEN = new Condition(){
- public boolean check(){
- return (Shop.isOpen());
- }
- };
- private final Condition empty = new Condition(){
- public boolean check(){
- return (Inventory.getCount(7810) > 10);
- }
- };
- private final Condition itemGone = new Condition(){
- public boolean check(){
- return (myItem.getStackSize()<1);
- }
- };
- private final Condition bankIsOpen = new Condition(){
- public boolean check(){
- return (Bank.isOpen());
- }
- };
- private State getState(){
- if(!welcomeScreen.isValid() && !Game.isLoggedIn())
- return State.LOGIN;
- if(welcomeScreen.isValid())
- welcome();
- if(Players.getLocal().inCombat()==true)
- {
- Walking.setRun(true);
- currentState = "Running from combat";
- walkbank();
- Time.sleep(20000);
- }
- if (!welcomeScreen.isValid() && Inventory.getCount()==1 && ((Npcs.getNearest(1560)!=null && !Npcs.getNearest(1560).isOnScreen()) || Npcs.getNearest(1560)==null))
- return State.RETURN;
- if (!welcomeScreen.isValid() && Inventory.isFull() && GameObjects.getNearest(26707)!=null && !GameObjects.getNearest(26707).isOnScreen())
- return State.WALKBANK;
- //26707
- if (!welcomeScreen.isValid() && GameObjects.getNearest(26707)!=null && Inventory.getCount()>1 && Npcs.getNearest(1560)!=null && Npcs.getNearest(1560).distance()>1)
- return State.BANK;
- //hop
- if (!welcomeScreen.isValid() && Shop.isOpen())
- Time.sleepUntil(SHOP_OPEN,500);
- if ((Shop.isOpen() && Shop.getItem(440)!=null && Shop.getItem(440).getStackSize()<1) && (Shop.isOpen() && Shop.getItem(453)!=null && Shop.getItem(453).getStackSize()<81) && Shop.getItem(444) != null && Shop.getItem(444).getStackSize()<91)
- return State.HOP;
- //buy
- if(!welcomeScreen.isValid() && Npcs.getNearest(1560)!=null && Npcs.getNearest(1560).distance()<10)
- return State.BUY;
- //bank
- if(!welcomeScreen.isValid() && !Game.isLoggedIn())
- return State.LOGIN;
- return State.WAIT;
- //coal prof= 16600
- //iron prof= 60000
- //gold prof= 77200
- }
- @Override
- public int loop() {
- try{
- switch (getState()) {
- case BUY:
- currentState = "Buying";
- loot();
- break;
- case HOP:
- currentState = "Hopping";
- hop();
- break;
- case WAIT:
- currentState = "Waiting";
- Time.sleep(400);
- break;
- case WALKBANK:
- currentState = "Walking to bank";
- walkbank();
- Time.sleep(500);
- break;
- case BANK:
- currentState="Banking";
- bank();
- break;
- case RETURN:
- currentState = "Returning to store";
- walkBack();
- Time.sleep(500);
- break;
- case LOGIN:
- currentState = "Logging in";
- login();
- break;
- default:
- log("Error, Stopping the script.");
- return -1;
- }
- }catch(Exception e)
- {
- }
- return 0;
- }
- @Override
- public boolean onStart(){
- String user = TBot.getBot().getCurrentAccount().getUsername();
- //359, 334, 328, 303, 317, 338, 329, 313, 370, 330,302
- //346, 376, 342, 367, 304, 321, 354, 358, 377, 365, 343
- //386, 351, 305, 306, 341, 309, 349, 362, 320, 378, 312
- //333, 322, 369, 314, 336, 344, 375, 310, 350, 327, 368
- if(user.contains("yung1@"))
- {
- worldArray=new int[]{359, 334, 328, 303, 317, 338, 329, 313, 370, 330,302};
- }
- if(user.contains("yung11@"))
- {
- worldArray=new int[]{346, 376, 342, 367, 304, 354, 358, 377, 365, 343};
- }
- if(user.contains("yung12@"))
- {
- worldArray=new int[]{386, 351, 305, 306, 341, 309, 362, 320, 378, 312};
- }
- if(user.contains("yung13@"))
- {
- worldArray=new int[]{333, 322, 369, 314, 336, 344, 375, 310, 350, 327, 368};
- }
- Mouse.setSpeed(50);
- timeBegan = System.currentTimeMillis();
- startTile = Players.getLocal().getLocation();
- xpStart = Skills.getTotalExperience();
- return true;
- }
- int money=(int) (moneyGained * 3600000D / (System.currentTimeMillis() - timeBegan));
- @Override
- public void onRepaint(Graphics g) {
- DecimalFormat df = new DecimalFormat("#");
- g.setColor(Color.WHITE);
- mX = Mouse.getX();
- mY = Mouse.getY();
- g.drawLine(mX-1, mY+5, mX-1, mY-5);
- g.drawLine(mX, mY+6, mX, mY-6);
- g.drawLine(mX+1, mY+5, mX+1, mY-5);
- g.drawLine(mX+5, mY-1, mX-5, mY-1);
- g.drawLine(mX+6, mY, mX-6, mY);
- g.drawLine(mX+5, mY+1, mX-5, mY+1);
- timeRan = System.currentTimeMillis() - this.timeBegan;
- g.drawString("Money spent: " + (moneyBefore-Inventory.getCount(995)), 20, 325);
- g.drawString("Time: " + ft(timeRan), 20, 310);
- g.drawString("Money p/hr: " + ((moneyGained * 3600000D )/( (System.currentTimeMillis() - timeBegan))),20, 295);
- g.drawString("World: " + currentWorld, 20, 280);
- g.drawString("State: " + currentState, 20, 265);
- g.drawString("Iron earned: " + (totalIron), 20, 250);
- g.drawString("Coal earned: " + (totalCoal), 20, 235);
- g.drawString("Gold earned: " + (totalGold), 20, 220);
- g.drawString("Money earned: " + (Game.getGameState()), 20, 205);
- //g.drawRect(15, 250, 125, 80);
- //
- currentWorld = Game.getCurrentWorld();
- }
- //Other methods
- private void loot()
- {
- myItem=null;
- WidgetChild j=null;
- int ironOre = Inventory.getCount(440);
- int coal = Inventory.getCount(453);
- int gold = Inventory.getCount(444);
- orden = Npcs.getNearest(1560);
- if (!Shop.isOpen()){
- if(orden.interact("Trade"))
- {
- Time.sleepUntil(SHOP_OPEN, 1000);
- }
- }
- Time.sleep(200, 300);
- if (Shop.isOpen())
- {
- if(Shop.getItem(444)!=null && Shop.getItem(444).getStackSize()>90)
- {
- //gold
- j = Widgets.getWidget(300).getChild(2).getChild(5);
- myItem = Shop.getItem(444);
- }
- if(Shop.getItem(453)!=null && Shop.getItem(453).getStackSize()>80)
- {
- //coal
- j = Widgets.getWidget(300).getChild(2).getChild(6);
- myItem = Shop.getItem(453);
- }
- if(Shop.getItem(440) != null && Shop.getItem(440).getStackSize()>0)
- {
- //iron
- j = Widgets.getWidget(300).getChild(2).getChild(2);
- myItem = Shop.getItem(440);
- }
- if (j!=null && myItem!=null)
- {
- myItem.interact("Buy 10");
- if (Inventory.isFull())
- walkbank();
- }
- }
- totalGold+=Inventory.getCount(444)-gold;
- totalIron+=Inventory.getCount(440)-ironOre;
- totalCoal+=Inventory.getCount(453)-coal;
- moneyGained=((totalCoal*200)+(totalGold*400)+(totalIron*170));
- }
- private void welcome(){
- WidgetChild welcomeScreen = Widgets.getWidget(378,17);
- if(welcomeScreen.isValid()){
- welcomeScreen.interact("Play Runescape");
- }
- }
- public void login() {
- final WidgetChild wc = Widgets.getWidget(378, 17);
- final int state = Game.getGameState();
- if (state == 30) {
- if (wc != null && wc.isValid() && wc.isVisible()) {
- if (wc != null)
- if (wc.click())
- Time.sleepUntil(new Condition() {
- @Override
- public boolean check() {
- return !wc.isValid() && !wc.isVisible();
- }
- }, 1500);
- }
- } else if (state == 10) {
- final String loginText = getLoginText();
- if (Game.getLoginMenuIndex() == 2) {
- final String currentUsername = Game.getCurrentUsername();
- final String wantedName = TBot.getBot().getCurrentAccount().getUsername();
- final String currentPassword = TBot.getBot().getClient().getCurrentPassword();
- final String wantedPassword = TBot.getBot().getCurrentAccount().getPassword();
- if (currentUsername.equalsIgnoreCase(wantedName) && currentPassword.equalsIgnoreCase(wantedPassword)) {
- if (Game.getGameState() == 10)
- if (Mouse.click((int) (235 + (Math.random() * (370 - 235))), (int) (305 + (Math.random() * (335 - 305))), true)){
- Time.sleep(Random.nextInt(2000, 3000));
- }
- } else {
- if (!currentUsername.equalsIgnoreCase(wantedName)) {
- if (!currentUsername.isEmpty()) {
- Mouse.click(Random.nextInt(400, 512), Random.nextInt(307, 330), true);
- } else {
- Mouse.click((int) (340 + (Math.random() * (450 - 340))), (int) (246 + (Math.random() * (260 - 246))), true);
- Keyboard.sendText(wantedName);
- }
- }
- if (!currentPassword.equalsIgnoreCase(wantedPassword)) {
- if (!currentPassword.isEmpty()) {
- Mouse.click(Random.nextInt(400, 512), Random.nextInt(307, 330), true);
- } else {
- Mouse.click((int) (340 + (Math.random() * (450 - 340))), (int) (261 + (Math.random() * (275 - 261))), true);
- Keyboard.sendText(wantedPassword);
- }
- }
- }
- if (loginText.contains("Too many")) {
- Time.sleep(3000, 5000);
- }
- if (loginText.contains("exceeded")) {
- Game.instaHopNextP2P();
- Time.sleep(1000, 2000);
- }
- if (loginText.contains("disable")) {
- TBot.getBot().getScriptHandler().stopScript();
- } else if (loginText.contains("update")) {
- System.exit(0);
- TBot.getBot().getScriptHandler().stopScript();
- }
- } else if (loginText.contains("Locked")) {
- TBot.getBot().getScriptHandler().stopScript();
- } else if (Game.getLoginMenuIndex() == 0) {
- Mouse.click((int) (395 + (Math.random() * (530 - 395))), (int) (275 + (Math.random() * (305 - 275))), true);
- Time.sleep(Random.nextInt(500, 750));
- } else if (Game.getLoginMenuIndex() == 3) {
- Mouse.click((int) (315 + (Math.random() * (450 - 315))), (int) (335 + (Math.random() * (335 - 305))), true);
- Time.sleep(Random.nextInt(500, 750));
- }
- }
- }
- private static String getLoginText() {
- return Game.getLoginMessage1() + Game.getLoginMessage2();
- }
- private void hop(){
- if (i==worldArray.length)
- {
- i=0;
- }
- if(Game.instaHop(worldArray[i]))
- Time.sleepUntil(WELCOME,5000);
- currentWorld = Game.getCurrentWorld();
- i++;
- }
- private void walkbank()
- {
- Tile[] areaArr = BANK_AREA.getTileArray();
- int areaRan = Random.nextInt(BANK_AREA.getTileArray().length-1);
- Keyboard.pressKey(control);
- Walking.findLocalPath(areaArr[areaRan]).traverse();
- Keyboard.releaseKey(control); }
- private void bank()
- {
- Inventory.deselectItem();
- GameObject booth = GameObjects.getNearest(26707);
- if (booth!=null)
- booth = GameObjects.getNearest(26707);
- if (booth != null) {
- if (booth.isOnScreen()) {
- booth.interact("Use Bank chest");
- Time.sleepUntil(bankIsOpen, 1000);
- Bank.depositAllExcept(995);
- }
- else {
- Camera.turnTo(booth);
- }
- }
- }
- private void walkBack()
- {
- Tile[] areaArr = BUY_AREA.getTileArray();
- int areaRan = Random.nextInt(BUY_AREA.getTileArray().length-1);
- Keyboard.pressKey(control);
- Walking.findLocalPath(areaArr[areaRan]).traverse();
- Keyboard.releaseKey(control);
- }
- private String ft(long duration)
- {
- String res = "";
- long hours = TimeUnit.MILLISECONDS.toHours(duration)
- - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
- long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
- - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
- .toHours(duration));
- long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
- - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
- .toMinutes(duration));
- res = (hours + ":" + minutes + ":" + seconds);
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement