import impsoft.nexus.bots.color.constants.Areas; import impsoft.nexus.bots.color.methods.ColorScript; import impsoft.nexus.bots.color.scriptobjects.RGB; import java.awt.Rectangle; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.TreeSet; /*rsObject, revolutionizing finding objects in ibot * V1.0 * TODO: add more comparison methods. * allow multiple data inputs to be averaged into one object.-DONE! * simple object-creating script. * * By LardMaster */ public class rsObject { private ColorScript methods; String name; Rectangle minDimensions, maxDimensions; int numSources = 0; TreeSet data = new TreeSet(new Comparator() { public int compare(RGBit o1, RGBit o2) { return (int) ((o1.getPercent() - o2.getPercent()) / Math.abs(o1 .getPercent() - o2.getPercent())); } }); public rsObject(ColorScript methods, String name, RGB[][] colorMap, Rectangle minDimensions, Rectangle maxDimensions) { add(colorMap); this.minDimensions = minDimensions; this.maxDimensions = maxDimensions; this.methods = methods; this.name = name; } public rsObject(ColorScript father, String name, Rectangle outline, Rectangle minDimensions, Rectangle maxDimensions) { this(father, name, LardMethods.rectOnColorMap(convertShort(father.getColorArray2d()), outline), minDimensions, maxDimensions); } public double getPercent(RGB r, RGB[][] colorMap) { int count = 0; for (RGB[] i : colorMap) for (RGB j : i) if (j.equals(r)) count++; return count / (colorMap.length * colorMap[0].length); } private void add(RGBit colorData) { data.add(colorData); } public void add(RGB[][] colorMap) { RGBit duplicate; for (RGB[] i : colorMap) for (RGB j : i) { boolean copy = false; for (RGBit b : data) if (b.getColor().equals(j)) { copy = true; duplicate = b; if (copy) { data.remove(duplicate); double percent = (duplicate.getPercent() * numSources + getPercent(j, colorMap)) / (numSources + 1); add(new RGBit(j, percent)); } else add(new RGBit(j, getPercent(j, colorMap))); } } numSources++; } public double matchByPercent(rsObject o2, int numColors) { int totalOff = 0; RGBit match = null; if (o2.data.equals(this.data)) return 100; int i = 0; for (RGBit r : this.data) { if (i >= numColors) break; match = null; for (RGBit r2 : o2.data) if (r2.getColor().equals(r.getColor())) match = r2; if (match == null) { totalOff += 100; continue; } totalOff += match.percentOff(r); } return totalOff / numColors; } public double matchByPercent(RGB[][] o2, int numColors) { return matchByPercent(new rsObject(methods, "temp", o2, null, null), numColors); } public double matchByPercent(Rectangle r, int numColors) { return matchByPercent(LardMethods.rectOnColorMap(convertShort(methods.getColorArray2d()), r), numColors); } public boolean clickOne(String action) throws InterruptedException { methods.mouseMove(findOne()); if (!methods.getTopText().contains(this.name)) { methods.log("Could not Find " + this.name); return false; } if (methods.getTopText().contains(action)) { methods.mouseClickLeft(methods.theBot.mouse_x, methods.theBot.mouse_y); return true; } else { methods.mouseClickRight(methods.theBot.mouse_x, methods.theBot.mouse_y); if (!methods.getMenu(Areas.GAME, methods.random(300, 400)) .selectContains(action)) { methods.log("no such action: " + action); return false; } return true; } } public Rectangle findOne(int numColors) { Rectangle searchBounds = Areas.GAME; int xinc = (int) (minDimensions.getWidth() + this.maxDimensions .getWidth()) / 4; int yinc = (int) (minDimensions.getHeight() + this.maxDimensions .getHeight()) / 4; Rectangle minDimensions = this.minDimensions; Rectangle maxDimensions = this.maxDimensions; int widthStep = (int) (maxDimensions.getWidth() - minDimensions .getWidth()) / 8; int heightStep = (int) (maxDimensions.getHeight() - minDimensions .getHeight()) / 8; Rectangle result = null; int maxcount = 0; for (double i = 0; i < searchBounds.getWidth() - minDimensions.getWidth(); i = i + xinc) for (double b = 0; b < searchBounds.getHeight() - minDimensions.getHeight(); b = b + yinc) for (int width = (int) minDimensions.getWidth(); width < maxDimensions .getWidth(); width = width + widthStep) for (int height = (int) minDimensions.getHeight(); height > (int) maxDimensions .getHeight(); height = height + heightStep) { Rectangle h = new Rectangle((int) i, (int) b, width, height); if (matchByPercent(h, numColors) > maxcount) { maxcount = (int) matchByPercent(h, numColors); result = h; } } return result; } public ArrayList getLocationsArray(int numcolors, double minPercent) { ArrayList result = new ArrayList(); Rectangle best; Rectangle searchBounds = Areas.GAME; int xinc = (int) (minDimensions.getWidth() + this.maxDimensions .getWidth()) / 4; int yinc = (int) (minDimensions.getHeight() + this.maxDimensions .getHeight()) / 4; Rectangle minDimensions = this.minDimensions; Rectangle maxDimensions = this.maxDimensions; int widthStep = (int) (maxDimensions.getWidth() - minDimensions .getWidth()) / 8; int heightStep = (int) (maxDimensions.getHeight() - minDimensions .getHeight()) / 8; while (true) { best = null; int maxcount = 0; for (double i = searchBounds.getMinX(); i < searchBounds.getMaxX() - minDimensions.getWidth(); i = i + xinc) for (double b = searchBounds.getMinY(); b < searchBounds .getMaxY() - minDimensions.getHeight(); b = b + yinc) for (int width = (int) minDimensions.getWidth(); width < maxDimensions .getWidth(); width = width + widthStep) for (int height = (int) minDimensions.getHeight(); height > (int) maxDimensions .getHeight(); height = height + heightStep) { Rectangle h = new Rectangle((int) i, (int) b, width, height); if (matchByOrder(h,numcolors)>minPercent && LardMethods.tooMuchOverlap(h, result, 20)) { } } if (best == null) break; result.add(best); } return result; } private double matchByOrder(rsObject o2, int numcolors) { RGBit[] ours=(RGBit[])this.data.toArray(); RGBit[] thiers=(RGBit[])o2.data.toArray(); double count=0; for(int i=0; i