diff --git a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/TScriptsPlugin.java b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/TScriptsPlugin.java index a800744..c280b6e 100644 --- a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/TScriptsPlugin.java +++ b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/TScriptsPlugin.java @@ -19,9 +19,7 @@ import net.runelite.client.plugins.tscripts.api.MethodManager; import net.runelite.client.plugins.tscripts.api.library.TWorldPoint; import net.runelite.client.plugins.tscripts.sevices.ScriptEventService; -import net.runelite.client.plugins.tscripts.sevices.TileOverlay; import net.runelite.client.plugins.tscripts.sevices.ipc.MulticastReceiver; -import net.runelite.client.plugins.tscripts.sevices.localpathfinder.LocalPathfinder; import net.runelite.client.plugins.tscripts.ui.TScriptsPanel; import net.runelite.client.plugins.tscripts.util.*; import net.runelite.client.plugins.tscripts.sevices.cache.GameCache; @@ -43,8 +41,10 @@ import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; /** * The main plugin class for TScripts. @@ -81,8 +81,6 @@ public class TScriptsPlugin extends Plugin { public static final String START_DIR = RuneLite.RUNELITE_DIR + File.separator + "HPQScripts" + File.separator; public static String HOME_DIR; private MulticastReceiver multicastReceiver; - private LocalPathfinder localPathfinder; - private TileOverlay overlays; @Getter private TScriptsPanel panel; @@ -124,9 +122,6 @@ protected void startUp() { clientToolbar.addNavigation(headlessToggleButton); this.multicastReceiver = new MulticastReceiver(); ThreadPool.submit(this.multicastReceiver); - localPathfinder = new LocalPathfinder(); - overlays = new TileOverlay(client); - overlayManager.add(overlays); } /** @@ -472,18 +467,6 @@ else if(opcode == MenuAction.WALK.getId()) .setTarget(color + name + " ") .setType(MenuAction.RUNELITE) .onClick(c -> Logging.copyToClipboard(worldPoint.getX() + ", " + worldPoint.getY())); - - /*client.createMenuEntry(1) - .setOption("Generate Local Path") - .setTarget(color + entry.getItemId() + " ") - .setType(MenuAction.RUNELITE) - .onClick(c -> { - ThreadPool.submit(() -> - { - List path = localPathfinder.pathTo(30, worldPoint, new ArrayList<>(), overlays); - overlays.updatePath(path); - }); - });*/ } } } diff --git a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/TileOverlay.java b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/TileOverlay.java deleted file mode 100644 index 9ab80b8..0000000 --- a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/TileOverlay.java +++ /dev/null @@ -1,76 +0,0 @@ -package net.runelite.client.plugins.tscripts.sevices; - -import net.runelite.api.Client; -import net.runelite.api.Perspective; -import net.runelite.api.coords.LocalPoint; -import net.runelite.client.plugins.tscripts.sevices.localpathfinder.Step; -import net.runelite.client.ui.overlay.Overlay; -import net.runelite.client.ui.overlay.OverlayLayer; -import net.runelite.client.ui.overlay.OverlayPosition; -import net.runelite.client.ui.overlay.OverlayUtil; -import java.awt.*; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -public class TileOverlay extends Overlay -{ - private final Client client; - private final List path = new CopyOnWriteArrayList<>(); - private Step start = null; - - public TileOverlay(Client client) - { - this.client = client; - setPosition(OverlayPosition.DYNAMIC); - setLayer(OverlayLayer.ABOVE_SCENE); - setPriority(PRIORITY_MED); - } - - public void updatePath(List path) - { - this.path.clear(); - this.path.addAll(path); - } - - public void addStep(Step step) - { - this.path.add(step); - } - - public void setStart(Step step) - { - this.path.add(0, step); - } - - @Override - public Dimension render(Graphics2D graphics) - { - if(start != null) - { - renderTile(graphics, LocalPoint.fromWorld(client, start.getPosition()), Color.GREEN); - } - for (Step step : path) - { - renderTile(graphics, LocalPoint.fromWorld(client, step.getPosition()), Color.RED); - } - - return null; - } - - private void renderTile(final Graphics2D graphics, final LocalPoint dest, Color color) - { - if (dest == null) - { - return; - } - - final Polygon poly = Perspective.getCanvasTilePoly(client, dest); - - if (poly == null) - { - return; - } - - OverlayUtil.renderPolygon(graphics, poly, color, color, new BasicStroke((float) (double) 3)); - } -} diff --git a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/BFSCache.java b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/BFSCache.java deleted file mode 100644 index 7ebcb6d..0000000 --- a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/BFSCache.java +++ /dev/null @@ -1,56 +0,0 @@ -package net.runelite.client.plugins.tscripts.sevices.localpathfinder; - -import org.jetbrains.kotlin.gnu.trove.TIntIntHashMap; - -import java.util.LinkedList; -import java.util.List; - -public class BFSCache -{ - private final TIntIntHashMap cache = new TIntIntHashMap(200000); - - public boolean put(final int point, final int parent) - { - if(cache.contains(point)) - return false; - cache.put(point, parent); - return true; - } - - public int get(final int position) - { - return cache.get(position); - } - - public void clear() - { - cache.clear(); - } - - public int size() - { - return cache.size(); - } - - public List path(int pos, int startX, int startY) - { - - int parent = get(shift(pos, startX, startY)); - LinkedList path = new LinkedList<>(); - path.add(0, new Step(shift(pos, startX, startY))); - while(parent != -1) - { - pos = parent; - parent = get(shift(pos, startX, startY)); - path.add(0, new Step(pos)); - } - return path; - } - - private int shift(int position, int startX, int startY) - { - int x = WorldPointUtil.getCompressedX(position) + startX; - int y = WorldPointUtil.getCompressedY(position) + startY; - return WorldPointUtil.compress(x, y, WorldPointUtil.getCompressedPlane(position)); - } -} \ No newline at end of file diff --git a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/FlagUtil.java b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/FlagUtil.java deleted file mode 100644 index 6255220..0000000 --- a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/FlagUtil.java +++ /dev/null @@ -1,56 +0,0 @@ -package net.runelite.client.plugins.tscripts.sevices.localpathfinder; - -import static net.runelite.api.CollisionDataFlag.*; - -public class FlagUtil -{ - public static byte all(int[][] map, int x, int y) - { - int flag = map[x][y]; - byte n = n(flag); - byte e = e(flag); - byte s = s(flag); - byte w = w(flag); - if((n | e | s | w) == 0) - { - return 0; - } - byte sw = (byte) (s & w & e(map[x][y - 1]) & n(map[x - 1][y])); - byte se = (byte) (s & e & w(map[x][y - 1]) & n(map[x + 1][y])); - byte nw = (byte) (n & w & e(map[x][y + 1]) & s(map[x - 1][y])); - byte ne = (byte) (n & e & w(map[x][y + 1]) & s(map[x + 1][y])); - - return (byte) (nw | (n << 1) | (ne << 2) | (w << 3) | (e << 4) | (sw << 5) | (s << 6) | (se << 7)); - } - - public static byte n(int flag) - { - return checkDirection(flag, BLOCK_MOVEMENT_NORTH, BLOCK_MOVEMENT_FULL, BLOCK_MOVEMENT_OBJECT, BLOCK_MOVEMENT_FLOOR_DECORATION) ? (byte) 1 : 0; - } - - public static byte e(int flag) - { - return checkDirection(flag, BLOCK_MOVEMENT_EAST, BLOCK_MOVEMENT_FULL, BLOCK_MOVEMENT_OBJECT, BLOCK_MOVEMENT_FLOOR_DECORATION) ? (byte) 1 : 0; - } - - public static byte s(int flag) - { - return checkDirection(flag, BLOCK_MOVEMENT_SOUTH, BLOCK_MOVEMENT_FULL, BLOCK_MOVEMENT_OBJECT, BLOCK_MOVEMENT_FLOOR_DECORATION) ? (byte) 1 : 0; - } - - public static byte w(int flag) - { - return checkDirection(flag, BLOCK_MOVEMENT_EAST, BLOCK_MOVEMENT_FULL, BLOCK_MOVEMENT_OBJECT, BLOCK_MOVEMENT_FLOOR_DECORATION) ? (byte) 1 : 0; - } - - public static boolean checkDirection(int currentState, int... directionFlag) { - for (int flag : directionFlag) { - if ((flag & currentState) != 0) { - return true; - } - - } - return false; - //return (currentState & directionFlag) == 0; - } -} diff --git a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/Flags.java b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/Flags.java deleted file mode 100644 index 70725ca..0000000 --- a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/Flags.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.runelite.client.plugins.tscripts.sevices.localpathfinder; - -public class Flags { - public static final byte NORTHWEST = 0x1; - public static final byte NORTH = 0x2; - public static final byte NORTHEAST = 0x4; - public static final byte WEST = 0x8; - public static final byte EAST = 0x10; - public static final byte SOUTHWEST = 0x20; - public static final byte SOUTH = 0x40; - public static final byte SOUTHEAST = (byte) 0x80; - public static final byte ALL = (byte) 0xFF; - public static final byte NONE = 0x0; -} diff --git a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/IntQueue.java b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/IntQueue.java deleted file mode 100644 index 3fa1438..0000000 --- a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/IntQueue.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.runelite.client.plugins.tscripts.sevices.localpathfinder; - -public final class IntQueue { - private final int[] data; - private int head; - private int tail; - - public IntQueue(final int capacity) { - data = new int[capacity]; - head = 0; - tail = 0; - } - - public void enqueue(final int value) { - data[tail++] = value; - } - - public int dequeue() { - return data[head++]; - } - - public boolean isEmpty() { - return head == tail; - } -} \ No newline at end of file diff --git a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/LocalPathfinder.java b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/LocalPathfinder.java deleted file mode 100644 index a71a553..0000000 --- a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/LocalPathfinder.java +++ /dev/null @@ -1,181 +0,0 @@ -package net.runelite.client.plugins.tscripts.sevices.localpathfinder; - -import net.runelite.api.CollisionData; -import net.runelite.api.TileObject; -import net.runelite.api.coords.WorldPoint; -import net.runelite.client.plugins.tscripts.api.library.TDelay; -import net.runelite.client.plugins.tscripts.api.library.TObjects; -import net.runelite.client.plugins.tscripts.sevices.TileOverlay; -import net.runelite.client.plugins.tscripts.util.Logging; -import net.unethicalite.client.Static; -import java.util.ArrayList; -import java.util.List; - -public class LocalPathfinder -{ - private int[][] collisionMap; - private int boundsRadius; - private int startX; - private int startY; - private int target; - private TileOverlay overlay; - - public List pathTo(int boundsRadius, WorldPoint destination, List filter, TileOverlay overlay) - { - this.overlay = overlay; - this.boundsRadius = boundsRadius; - this.collisionMap = collisionMap(); - final BFSCache visited = new BFSCache(); - int x; - int y; - int plane; - for(WorldPoint point : filter) - { - x = point.getX() - startX; - y = point.getY() - startY; - plane = point.getPlane(); - visited.put(WorldPointUtil.compress(x, y, plane), -1); - } - final IntQueue queue = new IntQueue(5000); - - WorldPoint point = Static.getClient().getLocalPlayer().getWorldLocation(); - x = point.getX() - startX; - y = point.getY() - startY; - plane = point.getPlane(); - - System.out.println("Start: " + x + ", " + y + ", " + plane); - queue.enqueue(WorldPointUtil.compress(x, y, plane)); - visited.put(WorldPointUtil.compress(x, y, plane), -1); - return bfs(visited, queue, destination); - } - - private List bfs(final BFSCache visited, final IntQueue queue, WorldPoint targetWorldPont) - { - int current; - overlay.setStart(new Step(WorldPointUtil.compress(targetWorldPont))); - int targetX = targetWorldPont.getX() - startX; - int targetY = targetWorldPont.getY() - startY; - int target = WorldPointUtil.compress(targetX, targetY, targetWorldPont.getPlane()); - this.target = target; - System.out.println("Target: " + targetX + ", " + targetY + ", " + targetWorldPont.getPlane()); - while(!queue.isEmpty()) - { - current = queue.dequeue(); - if(current == target) - { - Logging.info("Nodes visited: " + visited.size()); - return visited.path(current, startX, startY); - } - addNeighbors(current, queue, visited); - } - return new ArrayList<>(); - } - - private void addNeighbors(int node, IntQueue queue, BFSCache visited) - { - final short x = WorldPointUtil.getCompressedX(node); - final short y = WorldPointUtil.getCompressedY(node); - final byte plane = WorldPointUtil.getCompressedPlane(node); - - if(x < 0 || y < 0 || x >= collisionMap.length || y >= collisionMap[0].length) - return; - - final byte flags = FlagUtil.all(collisionMap, x, y); - - switch (flags) - { - case Flags.ALL: - addNeighbor(node, WorldPointUtil.compress(x - 1, y, plane), queue, visited); - addNeighbor(node, WorldPointUtil.compress(x + 1, y, plane), queue, visited); - addNeighbor(node, WorldPointUtil.compress(x, y - 1, plane), queue, visited); - addNeighbor(node, WorldPointUtil.compress(x, y + 1, plane), queue, visited); - addNeighbor(node, WorldPointUtil.compress(x - 1, y - 1, plane), queue, visited); - addNeighbor(node, WorldPointUtil.compress(x + 1, y - 1, plane), queue, visited); - addNeighbor(node, WorldPointUtil.compress(x - 1, y + 1, plane), queue, visited); - addNeighbor(node, WorldPointUtil.compress(x + 1, y + 1, plane), queue, visited); - return; - case Flags.NONE: - return; - } - - if ((flags & Flags.WEST) != 0) { - addNeighbor(node, WorldPointUtil.compress(x - 1, y, plane), queue, visited); - } - - if ((flags & Flags.EAST) != 0) { - addNeighbor(node, WorldPointUtil.compress(x + 1, y, plane), queue, visited); - } - - if ((flags & Flags.SOUTH) != 0) { - addNeighbor(node, WorldPointUtil.compress(x, y - 1, plane), queue, visited); - } - - if ((flags & Flags.NORTH) != 0) { - addNeighbor(node, WorldPointUtil.compress(x, y + 1, plane), queue, visited); - } - - if ((flags & Flags.SOUTHWEST) != 0) { - addNeighbor(node, WorldPointUtil.compress(x - 1, y - 1, plane), queue, visited); - } - - if ((flags & Flags.SOUTHEAST) != 0) { - addNeighbor(node, WorldPointUtil.compress(x + 1, y - 1, plane), queue, visited); - } - - if ((flags & Flags.NORTHWEST) != 0) { - addNeighbor(node, WorldPointUtil.compress(x - 1, y + 1, plane), queue, visited); - } - - if ((flags & Flags.NORTHEAST) != 0) { - addNeighbor(node, WorldPointUtil.compress(x + 1, y + 1, plane), queue, visited); - } - } - - private void addNeighbor(final int node, final int neighbor, final IntQueue queue, final BFSCache visited) { - if (visited.put(neighbor, node)) - { - int x = WorldPointUtil.getCompressedX(neighbor); - int y = WorldPointUtil.getCompressedY(neighbor); - int plane = WorldPointUtil.getCompressedPlane(neighbor); - System.out.println("Neighbor: " + x + ", " + y + ", " + plane + " - " + neighbor + " // " + target); - overlay.addStep(new Step(WorldPointUtil.compress(startX + x, startY + y, plane))); - queue.enqueue(neighbor); - TDelay.tick(1); - } - } - - //z,x,y - private int[][] collisionMap() { - int[][] collisionMap = new int[boundsRadius * 2 + 1][boundsRadius * 2 + 1]; - - CollisionData[] collisionMaps = Static.getClient().getCollisionMaps(); - if (collisionMaps == null) { - return collisionMap; - } - - WorldPoint local = Static.getClient().getLocalPlayer().getWorldLocation(); - - startX = local.getX() - boundsRadius; - startY = local.getY() - boundsRadius; - int endX = local.getX() + boundsRadius; - int endY = local.getY() + boundsRadius; - TileObject door; - - for (int x = startX; x < endX; x++) - { - if(x >= collisionMaps[0].getFlags().length) - continue; - for (int y = startY; y < endY; y++) - { - if(y >= collisionMaps[0].getFlags()[x].length) - continue; - door = TObjects.getObject("Door"); - if(door != null && door.getWorldLocation().getX() == x && door.getWorldLocation().getY() == y) - collisionMap[x - startX][y - startY] = 0; - else - collisionMap[x - startX][y - startY] = collisionMaps[0].getFlags()[x][y]; - } - } - return collisionMap; - } -} diff --git a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/LocalWalker.java b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/LocalWalker.java deleted file mode 100644 index 3fb270b..0000000 --- a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/LocalWalker.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.runelite.client.plugins.tscripts.sevices.localpathfinder; - -import net.runelite.api.coords.WorldPoint; -import net.runelite.client.plugins.tscripts.api.library.TDelay; -import net.unethicalite.api.movement.pathfinder.Walker; - -import java.util.List; - -public class LocalWalker -{ - public static void walkTo(int boundsRadius, WorldPoint destination, List filter) - { - LocalPathfinder pathfinder = new LocalPathfinder(); - List path = pathfinder.pathTo(boundsRadius, destination, filter, null); - - for(Step step : path) - { - Walker.walkTo(step.getPosition()); - TDelay.tick(1); - } - } -} diff --git a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/Step.java b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/Step.java deleted file mode 100644 index c72d7f8..0000000 --- a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/Step.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.runelite.client.plugins.tscripts.sevices.localpathfinder; - -import lombok.RequiredArgsConstructor; -import net.runelite.api.coords.WorldPoint; - -@RequiredArgsConstructor -public class Step -{ - public final int position; - public boolean checkpoint = false; - - public WorldPoint getPosition() - { - return WorldPointUtil.fromCompressed(position); - } -} diff --git a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/WorldPointUtil.java b/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/WorldPointUtil.java deleted file mode 100644 index c327b50..0000000 --- a/TScripts/src/main/java/net/runelite/client/plugins/tscripts/sevices/localpathfinder/WorldPointUtil.java +++ /dev/null @@ -1,52 +0,0 @@ -package net.runelite.client.plugins.tscripts.sevices.localpathfinder; - -import net.runelite.api.coords.WorldPoint; - -public class WorldPointUtil -{ - public static int compress(WorldPoint point) - { - return compress(point.getX(), point.getY(), point.getPlane()); - } - public static int compress(int x, int y, int z) { - return x | y << 14 | z << 29; - } - - public static short getCompressedX(int compressed) - { - return (short) (compressed & 0x3FFF); - } - - public static short getCompressedY(int compressed) - { - return (short) ((compressed >>> 14) & 0x7FFF); - } - - public static byte getCompressedPlane(int compressed) - { - return (byte)((compressed >>> 29) & 7); - } - - public static WorldPoint fromCompressed(int compressed) - { - int x = compressed & 0x3FFF; - int y = (compressed >>> 14) & 0x7FFF; - int z = (compressed >>> 29) & 7; - return new WorldPoint(x, y, z); - } - - public static int dx(int compressed, int n) - { - return compressed + n; - } - - public static int dy(int compressed, int n) - { - return compressed + (n << 14); - } - - public static int dxy(int compressed, int nx, int ny) - { - return compressed + nx + (ny << 14); - } -}