Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Polygon;
- import java.io.IOException;
- import java.net.URL;
- import org.tribot.api.Timing;
- import org.tribot.api.General;
- import org.tribot.api2007.Screen;
- import org.tribot.api2007.types.RSTile;
- import javax.imageio.ImageIO;
- import org.tribot.api.DynamicClicking;
- import org.tribot.api.input.Mouse;
- 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.Inventory;
- import org.tribot.api2007.Login;
- import org.tribot.api2007.Objects;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.Walking;
- import org.tribot.api2007.GameTab.TABS;
- import org.tribot.api2007.types.RSArea;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.script.Script;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.Painting;
- import org.tribot.script.interfaces.Pausing;
- import org.tribot.script.interfaces.RandomEvents;
- @ScriptManifest(authors = { "Okokokok" }, category = "ok_Scripts", name = "ok_Potato")
- public class ok_Potato extends Script implements Painting, Pausing, RandomEvents {
- private boolean paused = false;
- private int potatoesCollected;
- private final double version = 1.03;
- private final String gateName = "Gate",
- gateOption = "Open",
- potatoName = "Potato",
- potatoOption = "Pick";
- private final String[] seedName = {"Potato seed"};
- private final RSTile bankTile = new RSTile (2618, 3332, 0),
- gateFrontTile = new RSTile (2635, 3361, 0),
- potatoTile = new RSTile (2631, 3360, 0);
- private final Polygon potatoArea = new Polygon(
- new int[] {2624, 2635, 2635, 2624},
- new int[] {3372, 3372, 3352, 3352},
- 4),
- ardyArea = new Polygon(
- new int[] {2609, 2641, 2641, 2609},
- new int[] {3372, 3372, 3327, 3327},
- 4),
- gateFrontArea = new Polygon(
- new int[] {2635, 2641, 2641, 2635},
- new int[] {3365, 3365, 3357, 3357},
- 4),
- gateBackArea = new Polygon(
- new int[] {2630, 2635, 2635, 2630},
- new int[] {3364, 3364, 3358, 3358},
- 4),
- bankAreas = new Polygon(
- new int[] {2612, 2622, 2622, 2612},
- new int[] {3337, 3337, 3330, 3330},
- 4);
- private RSArea bankArea = new RSArea(new RSTile(2612, 3330, 0), new RSTile(2621, 3336, 0)),
- walkingArea = new RSArea(new RSTile(2609, 3327, 0), new RSTile(2643, 3370, 0));
- private final RSTile [] bankPath = new RSTile[] { new RSTile (2635, 3359, 0),
- new RSTile (2635, 3354, 0),
- new RSTile (2635, 3347, 0),
- new RSTile (2635, 3340, 0),
- new RSTile (2631, 3336, 0),
- new RSTile (2625, 3336, 0),
- new RSTile (2620, 3337, 0),
- new RSTile (2616, 3334, 0),
- new RSTile (2617, 3332, 0)},
- potatoPath = new RSTile[] { new RSTile (2616, 3334, 0),
- new RSTile (2620, 3337, 0),
- new RSTile (2625, 3336, 0),
- new RSTile (2631, 3336, 0),
- new RSTile (2635, 3340, 0),
- new RSTile (2635, 3347, 0),
- new RSTile (2635, 3354, 0),
- new RSTile (2635, 3359, 0),
- new RSTile (2635, 3361, 0)};
- // MISC METHODS
- public boolean logout()
- {
- if (Login.getLoginState() == Login.STATE.INGAME)
- {
- Login.logout();
- for(int x = 0; x < 6; x++)
- {
- if(loggedOut())
- {
- return true;
- }
- sleep(490,510);
- }
- }
- return false;
- }
- public boolean waitFor(Condition c, long timeout) {
- Timer t = new Timer(timeout);
- while (t.isRunning()) {
- if (c.active()) {
- return true;
- }
- sleep(60, 80);
- }
- return false;
- }
- public boolean loggedOut() {
- return (Login.getLoginState() == Login.STATE.LOGINSCREEN)
- && (!Screen.getColorAt(100, 200).equals(new Color(0, 0, 0)));
- }
- public void antiBan(int rotation) {
- int number = General.random(1, 500);
- sleep(200);
- switch (number) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
- break;
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- case 26:
- case 27:
- case 28:
- case 29:
- case 30:
- case 31:
- Mouse.move(General.random(100, 200), General.random(200, 400));
- sleep(200);
- break;
- case 50:
- GameTab.open(TABS.INVENTORY);
- sleep(200);
- break;
- case 75:
- GameTab.open(TABS.STATS);
- sleep(300);
- Mouse.moveBox(678, 386, 725, 366);
- sleep(1000, 1500);
- GameTab.open(TABS.INVENTORY);
- break;
- case 76:
- GameTab.open(TABS.FRIENDS);
- sleep(2000, 3000);
- GameTab.open(TABS.INVENTORY);
- break;
- case 89:
- case 90:
- case 91:
- case 92:
- case 93:
- case 94:
- Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
- sleep(200, 400);
- break;
- case 95:
- case 96:
- case 97:
- case 98:
- case 99:
- case 100:
- Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
- sleep(200, 400);
- break;
- }
- }
- // BANKING METHODS
- private void openBank() {
- if (!Banking.isBankScreenOpen()) {
- Banking.openBankBanker();
- }
- }
- private void depositItem(String itemName){
- RSItem[] item = Inventory.find(itemName);
- if (item != null && item.length > 0){
- Banking.depositAll();
- sleep(500, 600);
- }
- }
- // WALKING METHODS
- private void walkDestination(final RSTile[] whichPath, final RSTile whichTile, final Polygon whichArea, final int radius) {
- RSTile myPos = Player.getPosition();
- if (myPos != whichTile && !Player.isMoving()) {
- if (Walking.walkPath(whichPath)) {
- waitFor(new Condition() {
- @Override
- public boolean active() {
- return areaContainsPlayer(whichArea) && isCloseToDestination(whichTile, radius) && !Player.isMoving();
- }
- }, 15000);
- }
- }
- }
- private void walkTile(final Polygon whichArea, RSTile destination){
- RSTile myPos2 = Player.getPosition();
- if (myPos2.distanceTo(destination) != 0){
- if (Walking.walkTo(destination)){
- waitFor(new Condition(){
- @Override
- public boolean active(){
- return areaContainsPlayer(whichArea) && !Player.isMoving();
- }
- }, 3000);
- }
- }
- }
- // AREA CHECKS
- private boolean isCloseToDestination(RSTile whichTile, int radius){
- RSTile myPos = Player.getPosition();
- return myPos.distanceTo(whichTile) < radius;
- }
- private boolean areaContainsPlayer(Polygon area){
- return area.contains(Player.getPosition().getX(), Player.getPosition().getY());
- }
- private boolean noInAnyArea(){
- RSTile myPos = Player.getPosition();
- if (areaContainsPlayer(ardyArea) && !bankArea.contains(myPos) &&
- !areaContainsPlayer(gateFrontArea) && !areaContainsPlayer(gateBackArea) &&
- !areaContainsPlayer(potatoArea)){
- return true;
- }
- return false;
- }
- // GATE METHODS
- private boolean isGateOpen(){
- RSObject[] gate = Objects.findNearest(5, "Gate");
- return gate.length > 0 && (getGateTile().equals(new RSTile(2635, 3361, 0)) || getGateTile().equals(new RSTile(2636, 3361, 0)));
- }
- private RSTile getGateTile(){
- RSObject[] gate = Objects.find(5, "Gate");
- return gate[0].getPosition();
- }
- private void openGate(int distance, String name, String option){
- RSObject[] gate = Objects.find(distance, name);
- boolean open = org.tribot.api2007.Game.isUptext(gateOption);
- if (gate != null && gate.length > 0){
- if (gate[0].hover()){
- if (open){
- if (DynamicClicking.clickRSObject(gate[0], "Open")){
- waitFor(new Condition(){
- @Override
- public boolean active(){
- return isGateOpen();
- }
- }, 20000);
- }
- }
- }
- }
- }
- // POTATO METHODS
- private RSTile getPotatoTile(int amount, String itemName){
- RSObject[] potato = Objects.findNearest(amount, itemName);
- return potato[0].getPosition();
- }
- private boolean pickedPotato(int amount, String itemName){
- RSTile myPos = Player.getPosition();
- RSObject[] potato = Objects.findNearest(amount, itemName);
- if (potato != null && potato.length > 0){
- return myPos == getPotatoTile(7, potatoName);
- }
- return false;
- }
- private boolean arePotatoesThere(int amount, String itemName){
- RSObject[] potato = Objects.findNearest(amount, itemName);
- return potato != null && potato.length > 0 && potato[0].isOnScreen();
- }
- private void pickPotato(int amount, String itemName, String option){
- RSObject[] potato = Objects.findNearest(amount, itemName);
- if (potato != null && potato.length > 0 && potato[0].isOnScreen()){
- if (DynamicClicking.clickRSObject(potato[0], option)){
- waitFor(new Condition(){
- @Override
- public boolean active(){
- return pickedPotato(15, potatoName) || Inventory.isFull();
- }
- }, 1900);
- }
- }
- }
- // DROPPING METHODS
- private boolean haveSeed(){
- RSItem[] seed = Inventory.find("Potato seed");
- return seed != null && seed.length > 0;
- }
- private void dropSeed(){
- RSItem[] seed = Inventory.find("Potato seed");
- if(seed.length > 0){
- Inventory.drop(seedName);
- sleep(500, 600);
- }
- }
- // PAINT
- private Image getImage(String url) {
- try {
- return ImageIO.read(new URL(url));
- } catch (IOException e) {
- return null;
- }
- }
- private final Image img = getImage("http://i42.tinypic.com/2zgx8j8.jpg");
- private static final long startTime = System.currentTimeMillis();
- Font font = new Font("Calibri", Font.BOLD, 16);
- private State SCRIPT_STATE = getState();
- @Override
- public void onPaint(Graphics g) {
- Graphics2D gg = (Graphics2D) g;
- gg.drawImage(img, 9, 345, null);
- long timeRan = System.currentTimeMillis() - startTime;
- double multiplier = timeRan / 3600000D;
- int potatoes = potatoesCollected;
- g.setFont(font);
- g.setColor(new Color(254, 229, 53));
- g.drawString("ok_Potato V" + version, 14, 360);
- g.drawString("Action: " + SCRIPT_STATE, 14, 425);
- g.drawString("Time running: " + Timing.msToString(timeRan), 14, 440);
- g.drawString("Potatoes p/h: " + (int) (potatoes / multiplier) + " p/h", 14, 455);
- g.drawString("Potatoes collected: " + potatoes, 14, 470);
- }
- public enum State{
- WALKING_TO_BANK, WALKING_TO_POTATOES,
- WALKING_TO_FIELD, OPENING_GATE,
- OPENING_BANK, DEPOSITING_POTATOES,
- CLOSING_BANK, PICKING_POTATOES,
- WALKING_PAST_GATE, DROPPING_SEEDS,
- LOGING_OUT;
- }
- private State getState(){
- RSTile myPos = Player.getPosition();
- if (bankArea.contains(myPos)){
- if(!Banking.isBankScreenOpen()){
- if(Inventory.isFull() && !Player.isMoving()){
- return State.OPENING_BANK;
- }
- if(!Inventory.isFull()){
- return State.WALKING_TO_FIELD;
- }
- }
- if(Banking.isBankScreenOpen()){
- if(Inventory.isFull()){
- return State.DEPOSITING_POTATOES;
- }
- if(!Inventory.isFull()){
- return State.CLOSING_BANK;
- }
- }
- }
- if (areaContainsPlayer(gateFrontArea)){
- if(!Inventory.isFull()){
- if(!isGateOpen()){
- return State.OPENING_GATE;
- }
- if(isGateOpen()){
- return State.WALKING_TO_POTATOES;
- }
- }
- if(Inventory.isFull()){
- return State.WALKING_TO_BANK;
- }
- }
- if (areaContainsPlayer(potatoArea)){
- if(haveSeed()){
- return State.DROPPING_SEEDS;
- }
- if(!Inventory.isFull()){
- if(arePotatoesThere(10, potatoName)){
- return State.PICKING_POTATOES;
- }
- if(!arePotatoesThere(10, potatoName)){
- return State.WALKING_TO_POTATOES;
- }
- }
- if(Inventory.isFull()){
- if(!areaContainsPlayer(gateBackArea)){
- if(!isGateOpen()){
- return State.WALKING_TO_POTATOES;
- }
- }
- if(areaContainsPlayer(gateBackArea)){
- if(!isGateOpen()){
- return State.OPENING_GATE;
- }
- if(isGateOpen()){
- return State.WALKING_PAST_GATE;
- }
- }
- }
- }
- if (noInAnyArea()){
- if(walkingArea.contains(myPos)){
- if (!Inventory.isFull()){
- return State.WALKING_TO_FIELD;
- }
- if (Inventory.isFull()){
- return State.WALKING_TO_BANK;
- }
- }
- }
- return State.LOGING_OUT;
- }
- @SuppressWarnings("deprecation")
- @Override
- public void run() {
- println("Okokokok: Goodluck getting your Potatoes!");
- Walking.setControlClick(true);
- while (true) {
- if (loggedOut()) {
- super.setLoginBotState(active);
- } else {
- while (!loggedOut()) {
- SCRIPT_STATE = getState();
- int mSpeed = General.random(130, 160);
- Mouse.setSpeed(mSpeed);
- switch (SCRIPT_STATE) {
- case CLOSING_BANK:
- Banking.close();
- sleep (50, 100);
- break;
- case DEPOSITING_POTATOES:
- depositItem(potatoName);
- sleep (50, 100);
- break;
- case LOGING_OUT:
- logout();
- stopScript();
- break;
- case OPENING_BANK:
- int rotation = General.random(90, 200);
- antiBan(rotation);
- openBank();
- sleep (50, 100);
- potatoesCollected += Inventory.getCount(1942);
- break;
- case OPENING_GATE:
- int rotation1 = General.random(90, 200);
- antiBan(rotation1);
- openGate(6, gateName, gateOption);
- break;
- case PICKING_POTATOES:
- int rotation11 = General.random(90, 200);
- antiBan(rotation11);
- pickPotato(15, potatoName, potatoOption);
- sleep (50, 100);
- break;
- case WALKING_PAST_GATE:
- walkTile(gateBackArea, gateFrontTile);
- sleep (50, 100);
- break;
- case WALKING_TO_BANK:
- walkDestination(bankPath, bankTile, bankAreas, 6);
- break;
- case WALKING_TO_FIELD:
- walkDestination(potatoPath, gateFrontTile, gateFrontArea, 6);
- break;
- case WALKING_TO_POTATOES:
- walkTile(gateBackArea, potatoTile);
- break;
- case DROPPING_SEEDS:
- dropSeed();
- break;
- }
- }
- }
- }
- }
- @Override
- public void onRandom(RANDOM_SOLVERS arg0) {
- paused = true;
- }
- @Override
- public boolean randomFailed(RANDOM_SOLVERS arg0) {
- paused = false;
- return false;
- }
- @Override
- public void randomSolved(RANDOM_SOLVERS arg0) {
- paused = false;
- }
- @Override
- public void onPause() {
- paused = true;
- while(paused){
- sleep(100, 200);
- }
- }
- @Override
- public void onResume() {
- paused = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement