All pastes #370102 Raw Edit

Unnamed

public java v1 · immutable
#370102 ·published 2007-02-24 06:36 UTC
rendered paste body
import impsoft.nexus.bots.color.constants.Areas;import impsoft.nexus.bots.color.constants.BitMapInfo;import impsoft.nexus.bots.color.constants.Compass;import impsoft.nexus.bots.color.constants.Info;import impsoft.nexus.bots.color.listeners.ChatListener;import impsoft.nexus.bots.color.methods.ColorScript;import impsoft.nexus.bots.color.methods.Timer;import impsoft.nexus.bots.color.scriptobjects.MiniMap;import impsoft.nexus.bots.color.scriptobjects.NPCChat;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.Rectangle;import java.awt.geom.Arc2D;import java.util.ArrayList;import com.sun.java_cup.internal.runtime.Symbol;public class IMPRimmington extends ColorScript implements ChatListener {	public String[] commands = new String[] { "power copper", "bank copper",			"bank iron" };	public String author = "ruler";	int mode = -1;	boolean Mining = true;	public void chat(String message) {		if (Mining) {			if (message.contains("manage")) {				Mining = false;			}		}	}	public void combatCheck() throws InterruptedException {		if (inCombat()) {			walk(Compass.NORTH, 30);			walk(Compass.NORTH, 30);			walk(Compass.NORTH, 30);			walk(Compass.NORTH, 30);			walk(Compass.SOUTH, 30);			walk(Compass.SOUTH, 30);			walk(Compass.SOUTH, 30);			walk(Compass.SOUTH, 30);			walkToOre();		}	}	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;	}	public void fixAxe() throws InterruptedException {		boolean headPickedUp = doActionAtRGBCluster(new RGB[] {				new RGB(45, 31, 0), new RGB(52, 35, 0) }, "Take", "Take");		Timer t = new Timer(120000);		while (!headPickedUp && !t.isUp()) {			Rectangle items[] = getItemsOnMinimap();			if (items.length > 0) {				Rectangle closes = items[1];				for (int i = 1; i < items.length; i++) {					if (distance(Areas.MINI_MAP_CENTER, items[i]) < distance(							Areas.MINI_MAP_CENTER, closes)) {						closes = items[i];					}				}				mouseClickLeft(closes);				sleep(5000);				while (isMoving() || isMapFlagUp()) {					sleep(500);				}			}			headPickedUp = doActionAtRGBCluster(new RGB[] { new RGB(45, 31, 0),					new RGB(52, 35, 0) }, "Take", "Take");		}		doActionAtInventory("head", "Use", 1);		doActionAtInventory("handle", "Use", 1);	}	public boolean inCombat() {		RGB fightColor = new RGB(65280);		Rectangle searchZone = new Rectangle(217, 129, 80, 80);		return (findRGBXY(getColorArray2d(), fightColor, searchZone) != null);	}	public void walkToOre() throws InterruptedException {		XY mine = findSymbol(MiniMap.SYMBOL_MINING_SPOT);		if (mine != null) {			log("Found Mine Symbol");			MMClick(mine);		} else			log("Failed to find Mine Symbol");		if (mode == 0 || mode == 1) {			doMMColor(60, 0, new RGB(59, 49, 61));		} else if (mode == 2) {			doMMColor(0, 60, new RGB(98, 108, 106));		}	}	@Override	public void script() throws InterruptedException {		log("mode=" + mode);		if(findSymbol(MiniMap.SYMBOL_BANK)!=null){			walkToMine();		}else{			walkToOre();		}		if (mode == 0 || mode == 1 || mode == 2) {			while (true) {				if (!isLoggedin()) {					log("not logged in");					sleep(3000);					continue;				}				setTab(Info.TAB_INVENTORY);				if (inventoryCount() == 28) {					if (mode == 1 || mode == 2) {						walkToBank();						boolean success = doActionAtRGBCluster(new RGB[] {								new RGB(27, 21, 9), new RGB(100, 77, 45),								new RGB(103, 84, 47) }, "Bank", "quickly");						if (!success)							doActionAtRGBCluster(new RGB[] {									new RGB(27, 21, 9), new RGB(100, 77, 45),									new RGB(103, 84, 47) }, "Bank", "quickly");						doActionAtInventory(new String[] { "pickaxe" }, "All",								28);						walkToMine();					} else if (mode == 0) {						doActionAtInventory(new String[] { "pickaxe" }, "Drop",								28);					}				}				setTab(Info.TAB_INVENTORY);				while (inventoryCount() != 28) {					boolean success = false;					if (mode == 0 || mode == 1)						success = doActionAtRGBCluster(new RGB[] {								new RGB(161, 100, 58), new RGB(179, 112, 66) },								5, 10000, 0, 0, "Mine", "Mine");					else if (mode == 2)						success = doActionAtRGBCluster(new RGB[] { new RGB(92,								58, 43) }, 5, 10000, 0, 0, "Mine", "Mine");					if (success) {						sleep(defaultmaxAgeInMillisecs * 5);						while (isMoving() || isMapFlagUp())							sleep(defaultmaxAgeInMillisecs * 7);						combatCheck();						NPCChat chat = getNPCChat(2000);						if (chat != null && chat.contains("You need")) {							log("Missing Axe head");							fixAxe();						}						Mining = true;						Timer t = new Timer(random(15000, 25000));						while (!t.isUp() && Mining) {							sleep(defaultmaxAgeInMillisecs);							combatCheck();						}					} else {						log("Could not Find Rock");						sleep(defaultmaxAgeInMillisecs * 20);					}					combatCheck();				}				sleep(defaultmaxAgeInMillisecs * 2);			}		}	}	public void walkToBank() throws InterruptedException {		XY mine = findSymbol(MiniMap.SYMBOL_MINING_SPOT);		if (mine != null) {			log("Found Mine Symbol");			MMClick(mine);		} else {			log("Failed to find Mine Symbol");		}		log("Clicking rock");		doMMColor(60, 0, new RGB(43, 41, 45));		walkToMMRoad(50, 0, new RGB(100, 90, 90));		followMMRoad(60, -20, new RGB(100, 90, 90));		followMMRoad(40, -110, new RGB(100, 90, 90));		followMMRoad(160, -25, new RGB(100, 90, 90));		followMMRoad(100, -10, new RGB(120, 110, 95));		XY bank = findSymbol(MiniMap.SYMBOL_BANK);		if (bank != null) {			log("found Bank Symbol");			MMClick(bank);		} else {			log("failed to find Bank Symbol");		}	}	public void walkToMine() throws InterruptedException {		XY bank = findSymbol(MiniMap.SYMBOL_BANK);		if (bank != null) {			log("found Bank Symbol");			MMClick(bank);		} else {			log("failed to find Bank Symbol");		}		doMMColor(-65, 25, new RGB(241, 0, 0));		followMMRoad(-105, -10, new RGB(120, 110, 95));		log("Should be at Fally Gate");		followMMRoad(-160, 15, new RGB(100, 90, 90));		log("Should be Next to Chickens");		followMMRoad(-50, 100, new RGB(100, 90, 90));		log("Should be A a cross Road");		followMMRoad(-60, 20, new RGB(100, 90, 90));		log("Clicking rock");		doMMColor(-60, 0, new RGB(43, 41, 45));		log("Should be At Mine");		walkToOre();	}	XY findSymbol(short[][][] symbol) {		XY result = null;		double accuracy = 1;		int tolerance = 15;		while (result == null && accuracy > 0.8) {			XY match[] = findSymbolIgnoreMMObjects(getColorArray2d(), 1,					symbol, accuracy, tolerance, tolerance, tolerance);			if (match.length > 0)				result = new XY(match[0].x + symbol.length / 2, match[0].y						+ symbol[0].length / 2);			if (tolerance < 60) {				tolerance += 5;			} else {				accuracy -= 0.1;			}			log("accuracy=" + accuracy + " tolerance=" + tolerance);		}		return result;	}	public XY[] findSymbolIgnoreMMObjects(short[][][] colorMap, int maxMatches,			short[][][] colorMapToFind, double accuracy, int redTolerance,			int greenTolerance, int blueTolerance) {		Rectangle npcs[] = getNpcsOnMinimap();		Rectangle items[] = getItemsOnMinimap();		Rectangle players[] = getPlayersOnMinimap();		int width = MiniMap.width;		int length = MiniMap.height;		boolean ignore[][] = new boolean[width][length];		for (int x = 0; x < width; x++) {			for (int y = 0; y < length; y++) {				ignore[x][y] = false;				for (Rectangle r : npcs) {					if (r.contains(x + MiniMap.minX, y + MiniMap.minY)) {						ignore[x][y] = true;					}				}				for (Rectangle r : items) {					if (r.contains(x + MiniMap.minX, y + MiniMap.minY)) {						ignore[x][y] = true;					}				}				for (Rectangle r : players) {					if (r.contains(x + MiniMap.minX, y + MiniMap.minY)) {						ignore[x][y] = true;					}				}			}		}		// temp varibles		int x, y, ix, iy, redChange, greenChange, blueChange;		// image		int iW = colorMapToFind.length;		int iL = colorMapToFind[0].length;		// deformed bitmap		double temp = (1 - accuracy) * (iW * iL);		int maxWrong = (int) temp;		double temp2 = (1 - 0.3) * (iW * iL);		int maxIgnores = (int) temp2;		int wrong;		// search zone		Rectangle bounds = Areas.MINI_MAP;		int minX = bounds.x;		int maxX = minX + bounds.width - iW;		int minY = bounds.y;		int maxY = minY + bounds.height - iL;		// results		ArrayList<XY> list = null;		if (maxMatches < 10) {			list = new ArrayList<XY>(10);		} else {			list = new ArrayList<XY>(maxMatches);		}		// masks, bitmask definition		;		int BITMASK_MATCH = BitMapInfo.BITMASK_MATCH;		int BITMASK_NOMATCH = BitMapInfo.BITMASK_NOMATCH;		int bitMaskR = 0, bitMaskG = 0, bitMaskB = 0;		int firstBitMaskXOffSet = -1, firstBitMaskYOffSet = -1;		boolean found = false;		for (x = 0; !found && x < iW; x++)			for (y = 0; !found && y < iL; y++)				if (colorMapToFind[x][y][0] == BITMASK_MATCH) {					firstBitMaskXOffSet = x;					firstBitMaskYOffSet = y;					found = true;				}		boolean valid = false;		boolean firstMask = false;		int relX, relY;		for (x = minX; x < maxX; x++) {			for (y = minY; y < maxY; y++) {				wrong = 0;				int ignores=0;				valid = true;				firstMask = true;				for (ix = 0; valid && ix < iW; ix++) {					for (iy = 0; iy < iL; iy++) {						if (wrong > maxWrong) {							valid = false;							break;						}						if (ignores > maxIgnores) {							valid = false;							break;						}						relX = x + ix;						relY = y + iy;						if (ignore[relX - minX][relY - minY]) {							ignores++;							continue;						}						if (colorMapToFind[ix][iy][0] < 0) {							if (firstMask) {								if (firstBitMaskXOffSet != -1										&& firstBitMaskYOffSet != -1) {									bitMaskR = colorMap[relX											+ firstBitMaskXOffSet][relY											+ firstBitMaskYOffSet][0];									bitMaskG = colorMap[relX											+ firstBitMaskXOffSet][relY											+ firstBitMaskYOffSet][1];									bitMaskB = colorMap[relX											+ firstBitMaskXOffSet][relY											+ firstBitMaskYOffSet][2];									firstMask = false;								}							}							if (colorMapToFind[ix][iy][0] == BITMASK_MATCH) {								redChange = bitMaskR - colorMap[relX][relY][0];								if ((redChange >= 0 ? redChange : -redChange) > redTolerance) {									wrong++;									continue;								}								greenChange = bitMaskG										- colorMap[relX][relY][1];								if ((greenChange >= 0 ? greenChange										: -greenChange) > greenTolerance) {									wrong++;									continue;								}								blueChange = bitMaskB - colorMap[relX][relY][2];								if ((blueChange >= 0 ? blueChange : -blueChange) > blueTolerance) {									wrong++;									continue;								}							} else if (colorMapToFind[ix][iy][0] == BITMASK_NOMATCH									&& !firstMask) {								redChange = bitMaskR - colorMap[relX][relY][0];								greenChange = bitMaskG										- colorMap[relX][relY][1];								blueChange = bitMaskB - colorMap[relX][relY][2];								if ((greenChange >= 0 ? greenChange										: -greenChange) < greenTolerance										&& (redChange >= 0 ? redChange												: -redChange) < redTolerance										&& (blueChange >= 0 ? blueChange												: -blueChange) < blueTolerance) {									wrong++;									continue;								}							}							continue;						}						redChange = colorMapToFind[ix][iy][0]								- colorMap[relX][relY][0];						if ((redChange >= 0 ? redChange : -redChange) > redTolerance) {							wrong++;							continue;						}						greenChange = colorMapToFind[ix][iy][1]								- colorMap[relX][relY][1];						if ((greenChange >= 0 ? greenChange : -greenChange) > greenTolerance) {							wrong++;							continue;						}						blueChange = colorMapToFind[ix][iy][2]								- colorMap[relX][relY][2];						if ((blueChange >= 0 ? blueChange : -blueChange) > blueTolerance) {							wrong++;							continue;						}					}				}				if (valid) {					list.add(new XY(x, y));					if (list.size() >= maxMatches) {						XY resultXY[] = new XY[list.size()];						for (int i = 0; i < resultXY.length; i++) {							resultXY[i] = list.get(i);						}						return resultXY;					}				}			}		}		XY resultXY[] = new XY[list.size()];		for (int i = 0; i < resultXY.length; i++) {			resultXY[i] = list.get(i);		}		list = null;		return resultXY;	}}