Here is my unitTest script
I have many easy to use functiosn whill at the same time letting the scripter have unlmited freedom. direct access to pixle array, force refresh, send mouse orders instead of sleeping while waiting for the mouse scan to amke sure the object dosn't move.
Code:
import static java.lang.Thread.sleep;
import impsoft.ibot.Areas;
import impsoft.ibot.Info;
import impsoft.ibot.managers.SettingsManager;
import impsoft.ibot.methods.Menu;
import impsoft.ibot.methods.RGB;
import impsoft.ibot.methods.Random;
import impsoft.ibot.methods.Script;
import impsoft.ibot.methods.XY;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import org.eclipse.swt.internal.gdip.Rect;
public class unitTest extends Script {
public static double version = 2.1;
public static String[] commands = new String[] { "overall", "just toptext",
"chat", "tabs", "stats", "chat Listener", "running", "menus",
"inventory", "find bank","speed" };
public String author = "ruler,rikioh";
public String description = "a simple demo";
public static String args[];
private String cmd;
private int mode;
private String lastText = "";
private int i = 0;
private RGB bank = new RGB(244, 218, 93);
private RGB booth = new RGB(149, 120, 83);
@Override
public boolean doStart(String cmd, String[] args) {
for (int i = 0; i < commands.length; i++) {
if (cmd.equalsIgnoreCase(commands[i])) {
mode = i;
break;
}
}
return true;
}
@Override
public void script() throws InterruptedException {
while (true) {
if (theBot.loggedIn && !theBot.theRandomManager.Active) {
switch (mode) {
case 0:
// log("***************unitTestTabs");
// unitTestTabs();
// log("***************unitFindBank (beta)");
// unitFindBank();
log("***************unitTestChat");
unitTestChat();
log("***************unitTestInv");
unitTestInv();
log("***************unitTestMenu");
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
unitTestMenu();
log("***************unitTestStats");
unitTestStats();
log("***************unitTextOptions");
unitTextOptions();
//log("***************unitSendMessage");
//unitSendMessage();
break;
case 1:
unitTestTopText();
break;
case 2:
unitTestChat();
break;
case 3:
unitTestTabs();
break;
case 4:
unitTestStats();
break;
case 5:
unitTextChatListener();
break;
case 6:
unitTextOptions();
break;
case 7:
unitTestMenu();
break;
case 8:
unitTestInv();
break;
case 9:
unitFindBank();
break;
case 10:
unitTestSpeed();
break;
}
}
sleep(100);
}
}
public void unitTestChat() throws InterruptedException {
for (Random rh : theBot.theRandomManager.randomHandlers) {
if (rh.name.equalsIgnoreCase("PublicChatOff") && rh.active == true) {
log("Turning random 'PublicChatOff' off");
theBot.theRandomManager.stopRandom("PublicChatOff");
break;
}
}
if (getButtonMode(Info.BUTTON_PUBLIC_CHAT) != Info.MODE_ON) {
log(" Setting Public Chat to on");
setButtonMode(Info.BUTTON_PUBLIC_CHAT, Info.MODE_ON);
}
for (int i = 0; i < 5; i++) {
log(" {Chat OCR " + i + "}: " + getChat(i));
sleep(2);
}
}
public void unitTestTabs() throws InterruptedException {
for (int i = 0; i < 13; i++) {
int nextTab = i;
int currentab = getTab();
log(" {Tab Cycler}: Switching from "
+ Info.tabToString(currentab) + " to "
+ Info.tabToString(nextTab));
setTab(nextTab);
sleep(500);
}
}
public void unitTestInv() throws InterruptedException {
if (getTab() != Info.TAB_INVENTORY) {
log(" swithing from " + Info.tabToString(getTab()) + " to "
+ Info.tabToString(Info.TAB_INVENTORY));
setTab(Info.TAB_INVENTORY);
}
for (int i = 1; i < 29; i++) {
for (int loop = 0; itemExist(i);) {
mouseMove(Info.getInventoryRectangle(i));
sleep(300);
String topText = getTopText().trim();
if (topText.indexOf(" ") != -1 && topText.indexOf("/") != -1) {
// This determines the items name from the topText
String item = topText.substring(topText.indexOf(" "),
topText.indexOf("/")).trim();
while (item.length() < 40) {
item += " ";
}
if (item.length() > 1) {
log(" {Inventory Cycler}: Slot " + i + " " + item
+ topText);
break;
}
}
loop++;
if (loop > 10) {
break;
}
}
}
}
public void unitTestStats() throws InterruptedException {
if (getTab() != Info.TAB_STATS) {
log(" swithing from " + Info.tabToString(getTab()) + " to "
+ Info.tabToString(Info.TAB_STATS));
setTab(Info.TAB_STATS);
}
sleep(1500);
for (int statNumber = 0; statNumber < 22; statNumber++) {
log(" {Stat Cycler}:" + Info.statToString(statNumber) + " "
+ getStatTop(statNumber) + " / "
+ getStatBottom(statNumber));
}
int mode = getButtonMode(Info.BUTTON_PRIVATE_CHAT);
if (mode == Info.MODE_FRIEND) {
log("PRIVATE_CHAT is set to Friend");
} else if (mode == Info.MODE_ON) {
log("PRIVATE_CHAT is set to On");
} else if (mode == Info.MODE_OFF) {
log("PRIVATE_CHAT is set to Off");
}
mode = getButtonMode(Info.BUTTON_PUBLIC_CHAT);
if (mode == Info.MODE_FRIEND) {
log("PUBLIC_CHAT is set to Friend");
} else if (mode == Info.MODE_ON) {
log("PUBLIC_CHAT is set to On");
} else if (mode == Info.MODE_OFF) {
log("PUBLIC_CHAT is set to Off");
} else if (mode == Info.MODE_HIDE) {
log("PUBLIC_CHAT is set to Hide");
}
mode = getButtonMode(Info.BUTTON_TRADE);
if (mode == Info.MODE_FRIEND) {
log("BUTTON_TRADE is set to Friend");
} else if (mode == Info.MODE_ON) {
log("BUTTON_TRADE is set to On");
} else if (mode == Info.MODE_OFF) {
log("BUTTON_TRADE is set to Off");
}
}
public void unitTextOptions() throws InterruptedException {
if (getTab() != Info.TAB_OPTIONS) {
log(" swithing from " + Info.tabToString(getTab()) + " to "
+ Info.tabToString(Info.TAB_OPTIONS));
setTab(Info.TAB_OPTIONS);
}
if (getRun())
log("Running is on with " + getEnergy() + " Energy");
else
log("Running is off with " + getEnergy() + " Energy");
}
public void unitTextChatListener() throws InterruptedException {
String text = getChat(4);
if (!text.equalsIgnoreCase(lastText)) {
log(" {Chat OCR " + i++ + "}: " + text);
lastText = text;
}
}
public void unitTestMenu() throws InterruptedException {
Rectangle rect = Areas.GAME;
rect= new Rectangle(rect.x + rect.width * 1 / 3, rect.y + rect.height * 1 / 3,rect.width / 3,rect.height / 3);
mouseClickRight(rect);
Menu result = getMenu(Areas.GAME, 2000);
if (result != null) {
log("");
log("+-----------------------------------------------+");
for (int slot = 0; slot < result.options.length; slot++) {
String text = result.options[slot];
while (text.length() < 40) {
text += " ";
}
log("| " + text + result.getRectange(slot));
}
log("+-----------------------------------------------+");
mouseMove(result.location.x-50, result.location.y-50);
}
}
public void unitTestTopText() throws InterruptedException {
mouseMove(Areas.GAME);
sleep(500);
log("{Top OCR}: " + getTopText());
}
public void unitSendMessage() {
String message = "Hello Runescape " + random(0, 1000);
log(" {Sending message} " + message);
SendText(message);
SendKey(KeyEvent.VK_ENTER);
}
public void unitTestSpeed() {
getColorArray2d(0);
int done=0;
long time = System.currentTimeMillis();
int maxtime=500;
while(System.currentTimeMillis()-time<maxtime){
getTopText();
done++;
}
log((System.currentTimeMillis()-time) + " did getTopText() " + done + " times "+ getTopText());
getColorArray2d(0);
done=0;
time = System.currentTimeMillis();
maxtime=500;
while(System.currentTimeMillis()-time<maxtime){
getChat(4);
done++;
}
log((System.currentTimeMillis()-time) + " did getChat(4) " + done + " times "+ getChat(4));
}
public void unitFindBank() throws InterruptedException {
XY bankMiniMap = getMiniMapBank();
if (bankMiniMap != null) {
// Bank Symbol
log("Found Bank Symbol!");
mouseClickLeft(bankMiniMap.x, bankMiniMap.y);
log("Moving to Bank Symbol");
sleep(1500);
int distanceToFlag = distanceMapToFlag();
while (distanceToFlag > -1) {
log("Distance to Destination: " + distanceToFlag);
sleep(1000);
distanceToFlag = distanceMapToFlag();
}
sleep(4000);
XY booth = getBankBooth();
if (booth != null) {
log("Clicking Bank Booth");
mouseClickLeft(booth);
sleep(1000);
Menu menu = getMenu(Areas.GAME, 2000);
if (menu != null) {
for (int i = 0; i < menu.options.length; i++) {
if (menu.options[i].indexOf("quickly") != -1) {
mouseClickRight(menu.getRectange(i));
sleep(100);
}
}
}
sleep(3000);
// exit
mouseClickLeft(480, 40);
}
}
}
public XY getMiniMapBank() {
return findXYspiral(Areas.MINI_MAP, 50, 25, bank, 57, 57, 57);
}
public XY getBankBooth() {
return findXYspiral(Areas.GAME, Areas.GAME.x + Areas.GAME.width / 2,
Areas.GAME.y + Areas.GAME.height / 2, booth, 4, 4, 4);
}
}