rendered paste body/*
* Kitty Flax Stringer
* (kittyFlaxStringer.java)
*
* Start at bank, with flax in first slot.
*
* Credits:
* kr0n1k - Borrowed BankBooth class and used as template
* for spiralStaircase and closedDoor, even though you got it from ruler. ;)
*
* Copyright © 2007 Michael West
*/
import impsoft.nexus.bots.color.constants.*;
import impsoft.nexus.bots.color.methods.*;
import impsoft.nexus.bots.color.scriptobjects.*;
import impsoft.nexus.bots.reflection.scriptobjects.walking.*;
import impsoft.nexus.bots.color.listeners.ChatListener;
import java.awt.Rectangle;
public class kittyFlaxStringer extends ColorScript implements ChatListener{
public final static double version = 1.0;
public String[] commands = new String[] { "Spin 100 flax", "Spin 250 Flax", "Spin 500 Flax", "Use arguments box" };
public String author = "T3h Ub3r K1tten";
public String description = "Spins flax at Lumbridge";
private kittyBankBooth bank;
private spiralStaircase stairs;
private closedDoor door;
private spinningWheel wheel;
private flaxCounter flaxLeft;
private boolean noFlax = false;
private boolean debug = false;
private void debugLog(String logWhat) {if (debug) log("DEBUG: " + logWhat);}
private void debugLog(String name, String logWhat) {if (debug) log("DEBUG (" + name + "): " + logWhat);}
private void progressReport() {
log("******** kittyFlaxStringer ********");
log("******* By: T3h ub3r k1tten *******");
log("*** Runs : " + flaxLeft.runsDone());
log("*** Flax spun: " + flaxLeft.numberSpun());
log("*** Fights : " + fights);
log("***********************************");
}
private String concArray(String[] theArray) {
StringBuffer buf = new StringBuffer();
for (String value: theArray) {
buf.append( value);
}
return buf.toString();
}
private short[][][] xBmp = BitmapFromString(9, 13, "z78DA33753135313137258B744302C48863CA1A80017E715C7A31D593A78B783FE2B705BF5DC4DB426A3820BB8A16214F497CE10A31624292181200BB5DA1F2");
public void chat(String message) {
if (message.contains("out of flax")) noFlax = true;
if (message.contains("poisoned")){
log("You've been poisoned by the strange plant!");
progressReport();
}
}
private int bsSpun() throws InterruptedException{
int i = 0;
while(true){
i++;
if (i==28) break;
hoverMouseOverInventoryIndex(i);
if (getTopText().contains("flax")) return 28-i;
sleep(500);
}
return 0;
}
public boolean doStart(String cmd, String[] args) throws InterruptedException, IndexOutOfBoundsException {
debugLog("doStart(" + cmd + "," + concArray(args) + ");");
Integer a = 0;
if (cmd.contains("arguments")) a =Integer.parseInt( concArray(args));
if (cmd.contains("100")) a = 100;
if (cmd.contains("250")) a = 250;
if (cmd.contains("500")) a = 500;
debugLog("doStart", "a=" + a.toString());
if (a==0) return false;
flaxLeft = new flaxCounter(a);
bank = new kittyBankBooth(this);
wheel = new spinningWheel(this);
stairs = new spiralStaircase(this);
door = new closedDoor(this);
return true;
}
private AryanTile stairsTile = new AryanTile(3205,3209, this);
private AryanTile wheelTile1 = new AryanTile(3205,3209, this);
private AryanTile wheelTile2 = new AryanTile(3209,3213, this);
private AryanTile bankTile = new AryanTile(3208,3220,this);
private void walkToSpinningWheel() throws InterruptedException, SpinningWheelNotFoundException{
wheelTile1.walkTo();
door.open();
wheelTile2.walkTo();
}
private int fights = 0;
public boolean inFight() throws InterruptedException {
Rectangle HitBox = new Rectangle(210, 110, 300, 175);
XY GreenHealthBar = findXY(getColorArray2d(), new RGB(0, 255, 0), HitBox);
if(GreenHealthBar != null) {
fights++;
log("Found fight! Finishing spinning prematurely.");
return true;
} else {
return false;
}
}
private void spin() throws InterruptedException, SpinningWheelNotFoundException, SpinningMenuException {
wheel.spinMenu();
sleep(500);
XY xXY = FindBitmap(xBmp);
mouseMove(xXY);
sleep(200);
mouseClickLeft(xXY);
sleep(1500);
SendText("2");
sleep(500);
SendText("8");
sleep(500);
SendKey(10);
sleep(1000);
}
@Override
public void script() throws InterruptedException {
try {
int i = 0;
int j = 0;
debugLog("script",this.getClass().getName() + " v" + Double.toString(version) + " by " + author);
log(this.getClass().getName() + " v" + Double.toString(version) + " by " + author);
sleep(2000);
if (!isLoggedIn()) {
while(!isLoggedIn()) {
debugLog("script","Logged out");
log("Logged Out...");
sleep(5000);
}
}
while (flaxLeft.runsLeft() > 0) {
setRun(true);
setTab(3);
debugLog("script", "bank.bank();");
bank.bank();
sleep(500);
debugLog("script", "stairsTile.walkTo();");
stairsTile.walkTo();
sleep(500);
debugLog("script", "stairs.climb(false);");
stairs.climb(false);
sleep(3000);
debugLog("script", "walkToSpinningWheel();");
walkToSpinningWheel();
sleep(500);
door.open();
sleep(500);
debugLog("script", "spin();");
spin();
while(true && !noFlax) {
if (inFight()) j++;
if (j == 3) {
fights++;
break;
}
i++;
if (i == 6) spin();
sleep(10000);
if (i >= 10) break;
}
debugLog("script","stairsTile.walkTo();");
stairsTile.walkTo();
sleep(1000);
debugLog("script", "stairs.climb();");
stairs.climb(true);
sleep(1000);
debugLog("script","walkToBank();");
bankTile.walkTo();
flaxLeft.banked(bsSpun());
progressReport();
}
} catch (StairsNotFoundException ex) {
log("Spiral staircase not found!");
} catch (IndexOutOfBoundsException ex) {
log("Args did not contain a valid number for how many flax to spin!");
} catch (BankNotFoundException ex) {
log("Bank not found! Start at the bank!");
} catch (InterruptedException ex) {
log("Script terminating due to interrupt by iBot");
} catch (SpinningWheelNotFoundException ex) {
log("Spinning wheel not found!");
} catch (BankWithdrawalErrorException ex) {
log("Failed withdrawing flax!");
log("Put flax in first bank slot!");
} catch (SpinningMenuException ex) {
log ("Failed to select menu for spinning flax");
} catch (NullPointerException ex) {
log ("Null pointer exception!");
} finally {
progressReport();
}
}
}
class spinningWheel extends RGBCluster {
public spinningWheel(GameScreenMethods methods) {
super(new RGB[] { new RGB(222, 217, 217), new RGB(127, 86, 13), new RGB(95, 63, 8) },methods);
}
public void open() throws InterruptedException, SpinningWheelNotFoundException{
int i = 0;
while(true) {
try {
gatherNewPoints(15);
sortPointsByDistanceToXY(new XY((int) Areas.GAME.getCenterX(),(int) Areas.GAME.getCenterY()));
if (!doTopTextAndMenu("Spin", "Spin")) {
i++;
if (i >= 5) throw new SpinningWheelNotFoundException();
} else {
break;
}
} catch (NullPointerException ex){
throw new SpinningWheelNotFoundException();
}
}
}
@SuppressWarnings("static-access")
public void spinMenu() throws InterruptedException, SpinningWheelNotFoundException, SpinningMenuException {
open();
theScript.sleep(2000);
theScript.mouseMove(new Rectangle(249,103,7,7));
theScript.sleep(250 + theScript.random(25,300));
theScript.mouseClickRight(theScript.currentMouseX(),theScript.currentMouseY());
theScript.sleep(1000);
}
}
class closedDoor extends RGBCluster {
public closedDoor(GameScreenMethods methods) {
super(new RGB[] { new RGB(201, 75, 51), new RGB(114, 110, 37), new RGB(80, 48, 37) },
methods);
}
public boolean open() throws InterruptedException {
int i = 0;
while (true) {
gatherNewPoints(15);
sortPointsByDistanceToXY(new XY((int) Areas.GAME.getCenterX(),(int) Areas.GAME.getCenterY()));
if (!doTopTextAndMenu("Open Door", "Open")) {
i++;
if (i >=3) {
return false;
}
} else {
return true;
}
}
}
}
class spiralStaircase extends RGBCluster {
public spiralStaircase(GameScreenMethods methods) {
super(new RGB[] { new RGB(80, 54, 8), new RGB(80, 80, 76) },
methods);
}
public void climb(boolean up) throws InterruptedException, StairsNotFoundException {
int i = 0;
boolean exit = false;
String find1;
String find2;
if (up) {
find1 = "Climb";
find2 = "Climb-up";
} else {
find1 = "Climb";
find2 = "Climb-down";
}
while (!exit) {
gatherNewPoints(5*i);
sortPointsByDistanceToXY(new XY((int) Areas.GAME.getCenterX(),(int) Areas.GAME.getCenterY()));
if (!doTopTextAndMenu(find1, find2)) {
i++;
if (i >= 5) { throw new StairsNotFoundException();}
} else {
exit = true;
break;
}
}
}
}
class kittyBankBooth extends RGBCluster {
public kittyBankBooth(GameScreenMethods methods) {
super(new RGB[] { new RGB(90, 66, 8), new RGB(137, 116, 77),new RGB(176, 168, 144) }, methods);
}
public void fixBank() throws InterruptedException{
theScript.mouseMove(new Rectangle(472,82,4,4));
theScript.sleep(250);
theScript.mouseClickLeft(theScript.currentMouseX(), theScript.currentMouseY());
}
@SuppressWarnings({ "static-access", "deprecation" })
public void bank() throws InterruptedException, BankNotFoundException, BankWithdrawalErrorException {
Timer theJig = new Timer(30000);
int i = 0;
boolean j = false;
boolean dontExit = true;
while (!theJig.isUp() && dontExit) {
while (true) {
gatherNewPoints(10);
if (doTopTextAndMenu("Bank", "quickly")){
j = true;
break;
}
i++;
if (i >= 5) throw new BankNotFoundException();
}
if (j) {
fixBank();
theScript.sleep(2000);
theScript.doActionAtInventory(new String[] { "Flax" },"All", 28);
theScript.sleep(2500);
theScript.mouseMove(new Rectangle(89,72,10,10));
theScript.sleep(250 + theScript.random(25,3000));
theScript.mouseClickRight(theScript.currentMouseX(),theScript.currentMouseY());
theScript.sleep(2000);
Menu menu = theScript.getMenu(Areas.GAME, 2000);
if (menu != null) {
if (menu.selectContains("Withdraw All Flax")) {
} else {
menu.exit();
throw new BankWithdrawalErrorException("Could not withdraw flax");
}
} else {
throw new BankWithdrawalErrorException();
}
theScript.mouseMove(new Rectangle(478,36,5,5));
theScript.sleep(250 + theScript.random(25,300));
theScript.mouseClickLeft(theScript.currentMouseX(),theScript.currentMouseY());
theScript.sleep(2000);
dontExit = false;
} else {
throw new BankNotFoundException();
}
}
}
}
class flaxCounter {
private int flax = 0;
private int runs = 0;
private int flaxSpun = 0;
public flaxCounter(int start) {
flax = start;
}
public int numberSpun() {
return flaxSpun;
}
public int runsDone() {
return runs;
}
public void banked(int i) {
runs++;
if (flax <= i) {
flax = 0;
} else {
flax = flax - i;
flaxSpun = flaxSpun + i;
}
}
public int runsLeft() {
return flax / 28;
}
}
class SpinningMenuException extends Exception {
private static final long serialVersionUID = -2919554898916621091L;
SpinningMenuException() {}
SpinningMenuException(String msg) {super(msg);}
}
class SpinningWheelNotFoundException extends Exception {
private static final long serialVersionUID = -7345560108795323342L;
SpinningWheelNotFoundException() {}
SpinningWheelNotFoundException(String msg) {super(msg);}
}
class StairsNotFoundException extends Exception {
private static final long serialVersionUID = 5040645221733848390L;
StairsNotFoundException() {}
StairsNotFoundException(String msg) {super(msg);}
}
class BankNotFoundException extends Exception {
private static final long serialVersionUID = 6065024886620443334L;
BankNotFoundException() {}
BankNotFoundException(String msg) {super(msg);}
}
class BankWithdrawalErrorException extends Exception {
private static final long serialVersionUID = 6320222594769892684L;
BankWithdrawalErrorException() {}
BankWithdrawalErrorException(String msg) {super(msg);}
}