From ba1c5cd7e4ce583d27f02593724d53543ff13fc5 Mon Sep 17 00:00:00 2001 From: Harry <37844423+HSJ-OSRS@users.noreply.github.com> Date: Sun, 4 Aug 2019 05:21:59 +0100 Subject: [PATCH] re-add world point conversion methods (#1259) --- .../BatSolver/ThievingRoomType.java | 4 +- .../raidsthieving/RaidsThievingPlugin.java | 51 ++++++++++++++++++- .../plugins/raidsthieving/ThievingChest.java | 4 +- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/BatSolver/ThievingRoomType.java b/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/BatSolver/ThievingRoomType.java index 42d925e797..b319f24c06 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/BatSolver/ThievingRoomType.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/BatSolver/ThievingRoomType.java @@ -27,7 +27,7 @@ package net.runelite.client.plugins.raidsthieving.BatSolver; // There are three distinct Thieving rooms, distinguished by the position of the entrance relative to the exit // e.g. If you enter the room and must turn left to get to the exit and trough, this is a LEFT_TURN -import net.runelite.api.coords.WorldPoint; +import net.runelite.api.Point; public enum ThievingRoomType { @@ -44,7 +44,7 @@ public enum ThievingRoomType this.y = y; } - public static ThievingRoomType identifyByInstancePoint(WorldPoint point) + public static ThievingRoomType identifyByInstancePoint(Point point) { for (ThievingRoomType type : ThievingRoomType.values()) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/RaidsThievingPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/RaidsThievingPlugin.java index 7a04be9e82..43221f2221 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/RaidsThievingPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/RaidsThievingPlugin.java @@ -30,10 +30,12 @@ import javax.inject.Singleton; import lombok.AccessLevel; import lombok.Getter; import net.runelite.api.Client; +import static net.runelite.api.Constants.CHUNK_SIZE; import net.runelite.api.GameObject; import net.runelite.api.GraphicID; import net.runelite.api.GraphicsObject; import net.runelite.api.ObjectID; +import net.runelite.api.Point; import net.runelite.api.Varbits; import net.runelite.api.coords.WorldPoint; import net.runelite.api.events.ConfigChanged; @@ -65,6 +67,8 @@ import java.util.Map; @Singleton public class RaidsThievingPlugin extends Plugin { + private static final double CHUNK_OFFSET = 3.5; + @Inject private Client client; @Inject @@ -133,7 +137,7 @@ public class RaidsThievingPlugin extends Plugin { GameObject obj = event.getGameObject(); WorldPoint worldLoc = obj.getWorldLocation(); - WorldPoint instanceLoc = WorldPoint.fromLocalInstance(client, obj.getLocalLocation()); + Point instanceLoc = buildFromPoint(worldLoc, client); if (obj.getId() == ObjectID.TROUGH_29746) { @@ -270,6 +274,51 @@ public class RaidsThievingPlugin extends Plugin return chests.get(worldPoint).getChestId(); } + private static Point buildFromPoint(WorldPoint worldPoint, Client client) + { + Point point = new Point(worldPoint.getX(), worldPoint.getY()); + Point base = new Point(client.getBaseX(), client.getBaseY()); + int plane = worldPoint.getPlane(); + + int deltaX = point.getX() - base.getX(); + int deltaY = point.getY() - base.getY(); + int chunkIndexX = deltaX / CHUNK_SIZE; + int chunkIndexY = deltaY / CHUNK_SIZE; + + int chunkData = client.getInstanceTemplateChunks()[plane][chunkIndexX][chunkIndexY]; + int rotation = chunkData >> 1 & 0x3; + int y = (chunkData >> 3 & 0x7FF) * 8; + int x = (chunkData >> 14 & 0x3FF) * 8; + + return buildFromTile(base, point, rotation, new Point(x, y)); + } + + private static Point buildFromTile(Point base, Point tile, int rot, Point chunkOrigin) + { + int deltaX = tile.getX() - base.getX(); + int deltaY = tile.getY() - base.getY(); + + double chunkOffsetX = (deltaX % CHUNK_SIZE) - CHUNK_OFFSET; + double chunkOffsetY = (deltaY % CHUNK_SIZE) - CHUNK_OFFSET; + + for (int i = 0; i < rot; i++) + { + double temp = chunkOffsetX; + chunkOffsetX = -chunkOffsetY; + chunkOffsetY = temp; + } + + chunkOffsetX += CHUNK_OFFSET; + chunkOffsetY += CHUNK_OFFSET; + + int invariantChunkOffsetX = (int) chunkOffsetX; + int invariantChunkOffsetY = (int) chunkOffsetY; + + return new Point( + chunkOrigin.getX() + invariantChunkOffsetX, + chunkOrigin.getY() + invariantChunkOffsetY); + } + private void updateConfig() { this.potentialBatColor = config.getPotentialBatColor(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/ThievingChest.java b/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/ThievingChest.java index be3a18ef66..22949f9bab 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/ThievingChest.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/raidsthieving/ThievingChest.java @@ -68,13 +68,13 @@ public class ThievingChest * @param worldPoint The world location of the gameobject that corresponds with this trap. * @param instancePoint The world location accounting for instances of the gameobject that corresponds with this trap. */ - ThievingChest(final WorldPoint worldPoint, final WorldPoint instancePoint) + ThievingChest(final WorldPoint worldPoint, final Point instancePoint) { this.everOpened = false; this.poison = false; this.empty = false; this.worldPoint = worldPoint; - this.instancePoint = new Point(instancePoint.getX(), instancePoint.getY()); + this.instancePoint = instancePoint; this.chestId = -1; }