All pastes #359641 Raw Edit

Stuff

public java v1 · immutable
·published 2007-02-16 23:30 UTC
rendered paste body
import impsoft.nexus.bots.color.methods.ColorScript;import impsoft.nexus.bots.color.scriptobjects.MiniMap;import impsoft.nexus.bots.color.scriptobjects.RGB;import impsoft.nexus.bots.color.scriptobjects.XY;import impsoft.nexus.components.paint.PaintJob;import java.awt.Color;import java.awt.Graphics;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.util.ArrayList;public class WalkerMaker extends ColorScript {	XY[] topPoints;	public boolean doStart(String cmd, String[] args)			throws InterruptedException {		return true;	}	public void walktTillSpit(int degrees, RGB rgb) throws InterruptedException {		while (true) {			XY split = split(degrees, rgb);			if (split != null) {				mouseClickLeft(split);				return;			}			// if (!walk(degrees, rgb)) {			// return;			// }		}	}	public XY split(int degrees, RGB rgb) throws InterruptedException {		if (Math.abs(getCompass() - degrees) > 5) {			setCompass(degrees);		}		int r = rgb.r;		int g = rgb.g;		int b = rgb.b;		int redTolerance = autoTolerace(r, 50);		int greenTolerance = autoTolerace(g, 50);		int blueTolerance = autoTolerace(b, 50);		boolean matches[] = new boolean[topPoints.length];		for (int i = 0; i < topPoints.length; i++) {			matches[i] = compareRGB(getRGB(topPoints[i].x, topPoints[i].y),					rgb, redTolerance, greenTolerance, blueTolerance);		}		ArrayList<XY> possibleLocals = new ArrayList<XY>(0);		int inColor = 0;		int outColot = 0;		for (int i = 0; i < matches.length; i++) {			if (matches[i]) {				inColor++;				outColot = 0;			} else {				outColot++;			}			if (inColor > 5 && outColot > 6) {				int spot = i - 6;				possibleLocals.add(topPoints[spot]);				inColor = 0;				outColot = 0;			}		}		final ArrayList<XY> possibleLocalsFinal = possibleLocals;		if (possibleLocals.size() > 2) {			addPaintJob(new PaintJob() {				long start = System.currentTimeMillis();				@Override				public void paint(Graphics g) {					g.setColor(Color.BLUE);					for (XY place : possibleLocalsFinal) {						g.drawRect(place.x, place.y, 0, 0);					}				}				@Override				public boolean timeUp() {					return start + 5000 < System.currentTimeMillis();				}			});			return possibleLocalsFinal.get(0);		}		return null;	}	public boolean walk90(int degrees, int x, int y, RGB rgb)			throws InterruptedException {		return walk(degrees, x, y, rgb, MiniMap.walkZone90);	}	public boolean walk45(int degrees, int x, int y, RGB rgb)			throws InterruptedException {		return walk(degrees, x, y, rgb, MiniMap.walkZone45);	}	public boolean walk360(int degrees, int x, int y, RGB rgb)			throws InterruptedException {		return walk(degrees, x, y, rgb, MiniMap.miniMap);	}	public boolean walk(int degrees, int x, int y, RGB rgb,			boolean[][] walkArray) throws InterruptedException {		if (Math.abs(getCompass() - degrees) > 5) {			setCompass(degrees);		}		short[][][] colorMap = getColorArray2d();		int bX = MiniMap.minX;		int bY = MiniMap.minY;		int bW = walkArray.length;		int bH = walkArray[0].length;		int startX = x;		int startY = y;		int maxsize = 0;		if (maxsize < startX - bX) {			maxsize = startX - bX;		}		if (maxsize < bX + bW - startX) {			maxsize = bX + bW - startX;		}		if (maxsize < startY - bY) {			maxsize = startY - bY;		}		if (maxsize < bY + bH - startY) {			maxsize = bY + bH - startY;		}		int r = rgb.r;		int g = rgb.g;		int b = rgb.b;		XY walkTo = null;		for (int cT = 1; cT < 4; cT++) {			int redTolerance = autoTolerace(r, cT * 20);			;			int greenTolerance = autoTolerace(g, cT * 20);			;			int blueTolerance = autoTolerace(b, cT * 20);			int size = 0;			int dx = 0;			int dy = 0;			boolean valid = false;			while (size < maxsize && !valid) {				if (dy == size && dx < size && dx > 0)					dx++;				else if (dx == 0 && dy >= 0) {					dy++;					dx++;					size++;				} else if (dy == size && dx < 0)					dx++;				else if (dy == (-1 * size) && dx > (-1 * size))					dx--;				else if (dx == size)					dy--;				else if (dx == -1 * size)					dy++;				int relX = startX + dx;				int relY = startY + dy;				if (bX < relX && relX < bX + bW && bY < relY && relY < bY + bH) {					if (!walkArray[relX - bX][relY - bY]) {						continue;					}					int redChange = colorMap[relX][relY][0] - r;					if ((redChange >= 0 ? redChange : -redChange) > redTolerance) {						continue;					}					int greenChange = colorMap[relX][relY][1] - g;					if ((greenChange >= 0 ? greenChange : -greenChange) > greenTolerance) {						continue;					}					int blueChange = colorMap[relX][relY][2] - b;					if ((blueChange >= 0 ? blueChange : -blueChange) > blueTolerance) {						continue;					}					valid = true;				}				if (valid) {					walkTo = new XY(relX, relY);					break;				}			}		}		if (walkTo == null) {			log("walk failed degrees=" + degrees + " rgb=" + rgb);			return false;		}		int pxDistance = distance(walkTo, MiniMap.center);		mouseClickLeft(walkTo);		sleep(pxDistance * 30);		log("pxDistance=" + pxDistance);		while (isMoving() || isMapFlagUp()) {			sleep(500);		}		return true;	}	public void script() throws InterruptedException {		theBot.theApplet.getComponentAt(1, 1).addMouseListener(ml);		try {			while (true) {				addPaintJob(new PaintJob() {					long start = System.currentTimeMillis();					@Override					public void paint(Graphics g) {						g.setColor(Color.WHITE);						for (int i = 0; i < MiniMap.topPoints.length; i++) {							g.drawRect(MiniMap.topPoints[i].x,									MiniMap.topPoints[i].y, 0, 0);						}						g.setColor(Color.RED);						{							boolean[][] ba = MiniMap.walkZone90;							for (int x = 0; x < ba.length; x++) {								for (int y = 0; y < ba[0].length; y++) {									if (ba[x][y]) {										g.drawRect(MiniMap.minX + x,												MiniMap.minY + y, 0, 0);									}								}							}						}						g.setColor(Color.BLUE);						{							boolean[][] ba = MiniMap.walkZone45;							for (int x = 0; x < ba.length; x++) {								for (int y = 0; y < ba[0].length; y++) {									if (ba[x][y]) {										g.drawRect(MiniMap.minX + x,												MiniMap.minY + y, 0, 0);									}								}							}						}					}					@Override					public boolean timeUp() {						return start + 250 < System.currentTimeMillis();					}				});				sleep(1000);			}		} catch (InterruptedException e) {			theBot.theApplet.getComponentAt(1, 1).removeMouseListener(ml);			throw e;		}	}	MouseListener ml = new MouseAdapter() {		public void mouseClicked(MouseEvent e) {			try {				int x = e.getX();				int y = e.getY();				if (MiniMap.inMiniMap(x, y)) {					RGB rgb = getColor(x, y);					if (x - MiniMap.minX < MiniMap.walkZone45.length							&& y - MiniMap.minY < MiniMap.walkZone45[0].length) {						if (MiniMap.walkZone45[x - MiniMap.minX][y - MiniMap.minY]) {							log("walk45(" + getCompass() + "," + x + "," + y									+ "," + "new RGB(" + rgb.r + "," + rgb.g									+ "," + rgb.b + "))");							return;						}											}					if (x - MiniMap.minX < MiniMap.walkZone90.length							&& y - MiniMap.minY < MiniMap.walkZone90[0].length) {						if (MiniMap.walkZone90[x - MiniMap.minX][y - MiniMap.minY]) {							log("walk90(" + getCompass() + "," + x + "," + y									+ "," + "new RGB(" + rgb.r + "," + rgb.g									+ "," + rgb.b + "))");							return;						}											}					log("walk(" + getCompass() + "," + x + "," + y + ","							+ "new RGB(" + rgb.r + "," + rgb.g + "," + rgb.b							+ "))");				}			} catch (Exception ee) {				exception(ee);			}		}	};}