package impsoft.nexus.bots.arga.methods; import java.awt.Rectangle; import com.ms.arga.hooks.*; import com.ms.arga.hooks.Character; import impsoft.nexus.bots.arga.scriptsobjects.Tile; import impsoft.nexus.bots.color.methods.BasicColorMethods; import impsoft.nexus.bots.color.scriptobjects.XY; public abstract class argaMethods extends BasicColorMethods { public Client theClient; public final void setClient(Client client) { theClient = client; } public final Player getPlayer() { return theClient.getMyPlayer(); } public final int getAnimation(Player player) { return player.getAnimation(); } public boolean isMoving() { return (getPlayer().isMoving() > 0); } public final int getFightMode() { return theClient.getSettingsArray()[43]; } public final int getInventoryCount() { try { int rez = 0; for (int i = 0; i < 28; i++) if (getInventoryArray()[i] > 0) rez++; return rez; } catch (Exception e) { return 0; } } public final int getInventoryCount(int itemID) { try { int rez = 0; for (int i = 0; i < 28; i++) if (getInventoryArray()[i] == itemID) rez++; return rez; } catch (Exception e) { return 0; } } public final Tile getTile(Character c) { int x = theClient.getBaseX() + (c.getCharX() >> 7); int y = theClient.getBaseY() + (c.getCharY() >> 7); return (new Tile(x, y)); } public final XY getScreenXY(Character c) { return TileToScreen(getTile(c), (c.getHeight()) / 2); } public final XY getScreenXY(int objectUid) { return TileToScreen(getTile(objectUid), 0); } public final XY TileToScreen(Tile t, int height) { return TileToScreen((t.x - theClient.getBaseX() + 0.5) * 128, (t.y - theClient.getBaseY() + 0.5) * 128, height); } public final int getObjectAt(Tile t) { return getObjectAt(t.x, t.y); } private final int getObjectAt(int x, int y) { for (int i = 0; i < 4; i++) { try { Ground ground = theClient.getWorldClassInstance() .getGroundArray()[i][x - theClient.getBaseX()][y - theClient.getBaseY()]; if (ground != null) { if (ground.getObject5Array() != null) { for (Thing obj : ground.getObject5Array()) if (obj != null && obj.getUID() != -1) return obj.getUID(); } if (ground.getObject4() != null && ground.getObject4().getUID() != -1) return ground.getObject4().getUID(); if (ground.getObject3() != null && ground.getObject3().getUID() != -1) return ground.getObject3().getUID(); if (ground.getObject2() != null && ground.getObject2().getUID() != -1) return ground.getObject2().getUID(); if (ground.getObject1() != null && ground.getObject1().getUID() != -1) return ground.getObject1().getUID(); } } catch (Exception e) { } } return -1; } /** * from SAL Methods */ private final Interface[][] getInterfaceCache() { try { return theClient.getInterfaceCache(); } catch (Exception e) { exception(e); return new Interface[0][0]; } } public int getInterface(){ return theClient.getCurrentInterface(); } /** * from SAL Methods */ public final int[] getInventoryArray() { try { int inv[] = getInterfaceCache()[149][0].getInventoryArray(); int sortOut[] = new int[inv.length]; for (int i = 0; i < inv.length; i++) { sortOut[i] = inv[i] - 1; } return sortOut; } catch (Exception e) { exception(e); return new int[0]; } } /** * from SAL Methods */ public final XY TileToMinimap(Tile tile) { int x = tile.x-theClient.getBaseX(); int y = tile.y-theClient.getBaseY(); int i = (x * 4 + 2) - getPlayer().getCharX() / 32; int j = (y * 4 + 2) - getPlayer().getCharY() / 32; int k = theClient.getMinimapInt1() + theClient.getMinimapInt2() & 0x7ff; int l = j * j + i * i; if (l > 6400) return null; int i1 = theClient.getCurveArray1()[k]; int j1 = theClient.getCurveArray2()[k]; i1 = (i1 * 256) / (theClient.getMinimapInt3() + 256); j1 = (j1 * 256) / (theClient.getMinimapInt3() + 256); int k1 = j * i1 + i * j1 >> 16; int l1 = j * j1 - i * i1 >> 16; int screenx = 550 + ((94 + k1) + 4); int screeny = 4 + (83 - l1 - 4); return new XY(screenx, screeny); } /** * from SAL Methods */ public final XY TileToScreen(double x, double y, int height) { try { int z = terrainCalc(x, y) - (height / 2); x -= theClient.getCamPosX(); y -= theClient.getCamPosY(); z -= theClient.getCamPosZ(); int yCurve1 = theClient.getCurveArray2()[theClient.getCamCurveY()]; int yCurve2 = theClient.getCurveArray1()[theClient.getCamCurveY()]; int xCurve1 = theClient.getCurveArray2()[theClient.getCamCurveX()]; int xCurve2 = theClient.getCurveArray1()[theClient.getCamCurveX()]; int store = (int) (((yCurve1 * x) + (yCurve2 * y))) >> 16; y = (int) (((y * yCurve1) - (yCurve2 * x))) >> 16; x = store; int store2 = (int) (((xCurve1 * z) - (xCurve2 * y))) >> 16; y = (int) (((y * xCurve1) + (z * xCurve2))) >> 16; z = (int) store2; int screenX = (int) (((int) x << 9) / y + 256); int screenY = (int) (int) ((z << 9) / y + 167); if (screenX > 516 || screenY > 337) return null; return new XY(screenX, screenY); } catch (Exception e) { exception(e); } return null; } /** * from SAL Methods */ private final int terrainCalc(double x, double y) { int x1 = (int) x >> 7; int y1 = (int) y >> 7; if (~x1 > -1 || y1 < 0 || x1 > 103 || y1 > 103) return 0; int j1 = theClient.getTerrainInt(); if (j1 < 3 && (2 & theClient.getGroundByteArray()[1][x1][y1]) == 2) j1++; int l1 = 0x7f & (int) y; int k1 = (int) x & 0x7f; int i2 = theClient.getGroundIntArray()[j1][1 + x1][y1] * k1 + (128 + -k1) * theClient.getGroundIntArray()[j1][x1][y1] >> 0xaf78bd87; int j2 = theClient.getGroundIntArray()[j1][1 + x1][1 + y1] * k1 + theClient.getGroundIntArray()[j1][x1][y1 + 1] * (128 - k1) >> 0xbe451847; return j2 * l1 + (-l1 + 128) * i2 >> 0x75faec87; } public final int getObject(int type, int searchConstraints) { return getObject(new int[] { type }, searchConstraints); } public final int objectType(int uid) { return uid >> 14 & 0x7fff; } public final Tile getTile(int objectUid) { return new Tile(theClient.getBaseX() + (objectUid & 0x7f), theClient .getBaseY() + (objectUid >> 7 & 0x7f)); } public final int getObject(int[] types, int searchConstraints) { boolean ON_MINI_MAP = SC.isConstraintSet(searchConstraints, SC.ON_MINI_MAP_BIT_INDEX); boolean ON_SCREEN = SC.isConstraintSet(searchConstraints, SC.ON_SCREEN_BIT_INDEX); boolean NO_PLAYER_WITH_ANIMATION_NEXT_TO = SC.isConstraintSet( searchConstraints, SC.NO_PLAYER_WITH_ANIMATION_NEXT_TO_BIT_INDEX); Tile playerTile = getTile(getPlayer()); Rectangle bounds = new Rectangle(theClient.getBaseX(), theClient .getBaseY(), 104, 104); int startX = playerTile.x; int startY = playerTile.y; int dx = 0; int dy = 0; int relX, relY; int size = 0; int bX = bounds.x; int bY = bounds.y; int bW = bounds.width; int bH = bounds.height; 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 obj = getObjectAt(playerTile); if (obj != -1) for (int typeIdx = 0; typeIdx < types.length; typeIdx++) { if (types[typeIdx] == objectType(obj)) { return obj; } } while (size < maxsize) { 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++; relX = startX + dx; relY = startY + dy; if (bX < relX && relX < bX + bW && bY < relY && relY < bY + bH) { obj = getObjectAt(relX, relY); if (obj != -1) for (int typeIdx = 0; typeIdx < types.length; typeIdx++) { if (types[typeIdx] == objectType(obj)) { if (ON_MINI_MAP && TileToMinimap(getTile(obj)) == null) { continue; } if (ON_SCREEN && TileToScreen(getTile(obj), 0) == null) { continue; } if (NO_PLAYER_WITH_ANIMATION_NEXT_TO) { Tile tileObj = getTile(obj); int[] playerIndexs = theClient.getPlayerIndexArray(); Player[] players = theClient.getPlayerArray(); for (int i = 0; i < players.length; i++) { Player player = players[playerIndexs[i]]; if (player == null) continue; Tile tilePlayer = getTile(player); if (tilePlayer == null) continue; if (distance(tilePlayer, tileObj) < 2 && player.getAnimation() != -1) { continue; } } } return obj; } } } } return -1; } public final NPC getNPC(String name, int searchConstraints) { return getNPC(new String[] { name }, searchConstraints); } public final NPC getNPC(int type, int searchConstraints) { return getNPC(new int[] { type }, searchConstraints); } public final NPC getNPC(int types[], int searchConstraints) { boolean ON_MINI_MAP = SC.isConstraintSet(searchConstraints, SC.ON_MINI_MAP_BIT_INDEX); boolean ON_SCREEN = SC.isConstraintSet(searchConstraints, SC.ON_SCREEN_BIT_INDEX); boolean NOT_IN_COMBAT_BIT_INDEX = SC.isConstraintSet(searchConstraints, SC.NOT_IN_COMBAT); Tile player = getTile(getPlayer()); int winnerDist = 1000; NPC winner = null; int[] npcIndexs = theClient.getNPCIndexArray(); NPC[] npcs = theClient.getNPCArray(); for (int i = 0; i < npcIndexs.length; i++) { try { NPC npc = npcs[npcIndexs[i]]; if (npc == null) continue; Tile tileNpc = getTile(npc); if (tileNpc == null) continue; if (ON_MINI_MAP && TileToMinimap(tileNpc) == null) { continue; } if (ON_SCREEN && TileToScreen(tileNpc, npc.getHeight() / 2) == null) { continue; } if (NOT_IN_COMBAT_BIT_INDEX && npc.getInteractingChar() != -1) { continue; } for (int typeIndex = 0; typeIndex < types.length; typeIndex++) { if (types[typeIndex] != npc.getNPCDef().getNPCType()) continue; int challengerDist = distance(player, getTile(npc)); if (challengerDist < winnerDist) { winnerDist = challengerDist; winner = npc; break; } } } catch (Exception e) { exception(e); } } return winner; } public final NPC getNPC(String names[], int searchConstraints) { boolean ON_MINI_MAP = SC.isConstraintSet(searchConstraints, SC.ON_MINI_MAP_BIT_INDEX); boolean ON_SCREEN = SC.isConstraintSet(searchConstraints, SC.ON_SCREEN_BIT_INDEX); boolean NOT_IN_COMBAT_BIT_INDEX = SC.isConstraintSet(searchConstraints, SC.NOT_IN_COMBAT); Tile player = getTile(getPlayer()); int winnerDist = 1000; NPC winner = null; int[] npcIndexs = theClient.getNPCIndexArray(); NPC[] npcs = theClient.getNPCArray(); for (int i = 0; i < npcIndexs.length; i++) { try { NPC npc = npcs[npcIndexs[i]]; Tile tileNpc = getTile(npc); if (npc == null) continue; if (ON_MINI_MAP && TileToMinimap(tileNpc) == null) { continue; } if (ON_SCREEN && TileToScreen(tileNpc, npc.getHeight() / 2) == null) { continue; } if (NOT_IN_COMBAT_BIT_INDEX && npc.getInteractingChar() != -1) { continue; } for (int nameIndex = 0; nameIndex < names.length; nameIndex++) { if (!names[nameIndex].equals(unwrap(npc.getNPCDef() .getNPCName()))) continue; int challengerDist = distance(player, getTile(npc)); if (challengerDist < winnerDist) { winnerDist = challengerDist; winner = npc; break; } } } catch (Exception e) { exception(e); } } return winner; } public final NPC getNPC(String names[], int types[], int searchConstraints) { boolean ON_MINI_MAP = SC.isConstraintSet(searchConstraints, SC.ON_MINI_MAP_BIT_INDEX); boolean ON_SCREEN = SC.isConstraintSet(searchConstraints, SC.ON_SCREEN_BIT_INDEX); boolean NOT_IN_COMBAT_BIT_INDEX = SC.isConstraintSet(searchConstraints, SC.NOT_IN_COMBAT); Tile player = getTile(getPlayer()); int winnerDist = 1000; NPC winner = null; int[] npcIndexs = theClient.getNPCIndexArray(); NPC[] npcs = theClient.getNPCArray(); for (int i = 0; i < npcIndexs.length; i++) { try { NPC npc = npcs[npcIndexs[i]]; Tile npcTile = getTile(npc); if (npc == null) continue; if (ON_MINI_MAP && TileToMinimap(npcTile) == null) { continue; } if (ON_SCREEN && TileToScreen(npcTile, npc.getHeight() / 2) == null) { continue; } if (NOT_IN_COMBAT_BIT_INDEX && npc.getInteractingChar() != -1) { continue; } for (int nameIndex = 0; nameIndex < names.length; nameIndex++) { if (!names[nameIndex].equals(unwrap(npc.getNPCDef() .getNPCName()))) continue; int challengerDist = distance(player, getTile(npc)); if (challengerDist < winnerDist) { winnerDist = challengerDist; winner = npc; break; } } for (int typeIndex = 0; typeIndex < types.length; typeIndex++) { if (types[typeIndex] != npc.getNPCDef().getNPCType()) continue; int challengerDist = distance(player, getTile(npc)); if (challengerDist < winnerDist) { winnerDist = challengerDist; winner = npc; break; } } } catch (Exception e) { exception(e); } } return winner; } public static final String unwrap(StringWrap sw) { return new String(sw.getBytes()); } public static final int distance(Tile a, Tile b) { return (int) Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } public final int walkTime(Tile destination) { if (getRun()) { return distanceTo(destination) * 149 + 550; } else { return distanceTo(destination) * 209 + 550; } } public final int distanceTo(Tile destination) { return distance(getTile(getPlayer()), destination); } public static final Tile[] reversePath(Tile[] path) { Tile[] t = new Tile[path.length]; for (int i = 0; i < t.length; i++) t[i] = path[path.length - 1 - i]; return t; } /** * Finds a tile toward the next nearest point on a path or to the next point * that is within 10 tiles away * * @param path * Tile[] * @return Tile along or to the path, otherwise null. */ public final Tile findTileAlongInvalidPath(Tile[] path) { int MostNear = 0; for (int i = 0; i < path.length; i++) { if (distanceTo(path[i]) < distanceTo(path[MostNear])) { MostNear = i; } } int SecMostNear = MostNear; if (SecMostNear < path.length - 1) { SecMostNear++; } while (SecMostNear < path.length - 1 && distanceTo(path[SecMostNear + 1]) < 11) { SecMostNear++; } if (distanceTo(path[SecMostNear]) < 11) { return path[SecMostNear]; } else { Tile challenger1 = path[MostNear]; Tile challenger2 = path[SecMostNear]; Tile winner = challenger1; int winnerDist = distanceTo(winner); int distanceBetweenChall = distance(challenger1, challenger2); int StartX = challenger1.x; int StartY = challenger1.y; int dx = StartX - challenger2.x; int dy = StartY - challenger2.y; for (int i = 0; i <= distanceBetweenChall; i++) { Tile Challenger = new Tile(StartX + dx * (i / distanceBetweenChall), StartY + dy * (i / distanceBetweenChall)); int challengerDist = distanceTo(Challenger); if (challengerDist < winnerDist) { winnerDist = challengerDist; winner = Challenger; } } return findTileOnWayToTile(winner); } } /** * Finds a tile in the direction of the Destionation * * @param Destination * The tile to walk to * @return Tile in the direction of the Destination, otherwise null. */ public final Tile findTileOnWayToTile(Tile Destination) { if (Destination == null) return null; Tile next = null; int x_difference = Destination.x - getTile(getPlayer()).x; int y_difference = Destination.y - getTile(getPlayer()).y; int abs_x_difference = Math.abs(x_difference); int abs_y_difference = Math.abs(y_difference); int multiple; int x; int y; int x_change = 0; int y_change = 0; int size = 0; if (distanceTo(Destination) > 9 || !(canReach(Destination))) { multiple = 7; x = (getTile(getPlayer()).x + multiple * x_difference / (abs_x_difference + abs_y_difference)); y = (getTile(getPlayer()).y + multiple * y_difference / (abs_x_difference + abs_y_difference)); while (!(canReach(new Tile(x, y)))) { if (size >= 8) break; else if (y_change == size && x_change < size && x_change > 0) x_change++; else if (x_change == 0 && y_change >= 0) { y_change++; x_change++; size++; } else if (y_change == size && x_change < 0) x_change++; else if (y_change == (-1 * size) && x_change > (-1 * size)) x_change--; else if (x_change == size) y_change--; else if (x_change == -1 * size) y_change++; } if (size < 8) { next = new Tile(x + x_change, y + y_change); } } else { next = Destination; } return next; } public boolean canReach(Tile tile) { // TODO (nag ms devs) return true; } }