ruler
2006-11-04 03:23:51
import java.awt.Rectangle;
import java.io.IOException;
import impsoft.ibot.Areas;
import impsoft.ibot.Info;
import impsoft.ibot.managers.BitMapManger;
import impsoft.ibot.methods.Menu;
import impsoft.ibot.methods.RGB;
import impsoft.ibot.methods.Random;
import impsoft.ibot.methods.XY;
public class StrangeBox extends Random {
private short[][][] box;
private XY matches[];
public String author = "ruler,pups";
public boolean startUp() {
if (theBot.loggedIn) {
if (box == null) {
box = loadBitmap("bitmaps/strangebox.bmp");
}
if (getTab() == Info.TAB_INVENTORY) {
matches = findXYs(getColorArray2d(), Areas.INVENTORY, null,
box, null, 30, 5, 5, 5);
if (matches.length > 0) {
return true;
}
}
}
setNextCheck(3000);
return false;
}
public XY findText(String text) {
return findGameScreenText(text, Areas.GAME, new RGB(187, 185, 73), 3,
3, 3);
}
public String shapes[] = { "Pentagon", "Circle", "Square", "Star",
"Triangle" };
public void random() throws InterruptedException {
for (int i = 0; i < matches.length; i++) {
mouseClickRight(new Rectangle(matches[i].x, matches[i].y,
box.length, box[0].length));
Menu menu = getMenu(Areas.INVENTORY, 2000);
if (menu != null) {
boolean success = menu.selectContains("Open");
if (success) {
while (true) {
sleep(3000);
if (findText("What") != null) {
int shapeIndex = -1;
for (int shp = 0; shp < shapes.length; shp++) {
if (findText("" + shapes[shp]) != null) {
shapeIndex = shp;
break;
}
}
if (shapeIndex != -1) {
int options[] = new int[3];
int found = 0;
for (int num = 0; num < 10; num++) {
if (findText("" + num) != null) {
options[found] = num;
found++;
if (found == 3)
break;
}
}
if (found == 3) {
log("Which number is the "
+ shapes[shapeIndex]);
for (int option = 0; option < options.length; option++) {
log(" " + options[option]);
}
// TODO
}
} else {
log("Could not determine the shape to find");
}
} else if (findText("Which") != null) {
int numerToFind = -1;
for (int num = 0; num < 10; num++) {
if (findText("" + num) != null) {
numerToFind = num;
break;
}
}
if (numerToFind != -1) {
int options[] = new int[3];
int found = 0;
for (int shp = 0; shp < shapes.length; shp++) {
if (findText("" + shapes[shp]) != null) {
options[found] = shp;
found++;
if (found == 3)
break;
}
}
if (found == 3) {
log("Which shape has a " + numerToFind);
for (int option = 0; option < options.length; option++) {
log(" " + shapes[options[option]]);
}
XY center = new XY(239, 137);
log("test START");
int count = 0;
int tests = 50;
long time = System.currentTimeMillis();
while (true) {
sleep(50);
getColorArray2d(0);// reresh color
// array
if (findRGBXYs(getColorArray2d(),
new Rectangle(182, 45, 1, 180),
null, new RGB(16579837,
RGB.COLOR_TYPE_SCAR),
1, 5, 5, 5).length > 0) {
continue;
}
if (findRGBXYs(getColorArray2d(),
new Rectangle(342, 45, 1, 180),
null, new RGB(16579837,
RGB.COLOR_TYPE_SCAR),
1, 5, 5, 5).length > 0) {
continue;
}
if (findRGBXYs(getColorArray2d(),
new Rectangle(172, 55, 177, 1),
null, new RGB(16579837,
RGB.COLOR_TYPE_SCAR),
1, 5, 5, 5).length > 0) {
continue;
}
if (findRGBXYs(
getColorArray2d(),
new Rectangle(172, 215, 177, 1),
null, new RGB(16579837,
RGB.COLOR_TYPE_SCAR),
1, 5, 5, 5).length > 0) {
continue;
}
if (findRGBXYs(getColorArray2d(),
new Rectangle(182, 45, 1, 180),
null, new RGB(12764106,
RGB.COLOR_TYPE_SCAR),
1, 5, 5, 5).length > 0) {
continue;
}
if (findRGBXYs(getColorArray2d(),
new Rectangle(342, 45, 1, 180),
null, new RGB(12764106,
RGB.COLOR_TYPE_SCAR),
1, 5, 5, 5).length > 0) {
continue;
}
if (findRGBXYs(getColorArray2d(),
new Rectangle(172, 55, 177, 1),
null, new RGB(12764106,
RGB.COLOR_TYPE_SCAR),
1, 5, 5, 5).length > 0) {
continue;
}
if (findRGBXYs(
getColorArray2d(),
new Rectangle(172, 215, 1, 180),
null, new RGB(12764106,
RGB.COLOR_TYPE_SCAR),
1, 5, 5, 5).length > 0) {
continue;
}
count++;
if (count >= tests)
break;
}
log("Took "
+ (System.currentTimeMillis() - time)
+ " ms to complete pup's pre-function "
+ tests + " times");
try {
BitMapManger
.write(
theBot.theBitMapManger
.getBufferedImage(10),
"./QQQ"
+ System
.currentTimeMillis()
+ ".bmp");
} catch (IllegalArgumentException e) {
exception(e);
} catch (IOException e) {
exception(e);
}
log("test STOP");
}
} else {
log("Could not determine the number to find");
}
}
}
}
}
log("Found boxes at | X " + matches[i].x + " | Y " + matches[i].y);
}
log("Box Found Kill Bot");
shutDown();
}
}
I can get a frame that pup's algothrim defines as a possible flat one about every 400ms.The algothrim takes about 20ms to test for couting the refresh of the color arrays and i do it every 50ms.
I saved some of the frames to my hard drive and about 1 out of 3 looked absolutly flat.
So mebe a valid frame at least every 2 seconds at the min.
I was thinking to define which shape by how many lines. Working on counting the area.
The number ocr will be a hard me thinks.
Do they ever interchange 6 and 9 ?
Looking for any suggestions.