diff options
Diffstat (limited to 'features/dungeonMap2')
-rw-r--r-- | features/dungeonMap2/DungeonMapData.js | 80 | ||||
-rw-r--r-- | features/dungeonMap2/DungeonMapRoom.js | 134 | ||||
-rw-r--r-- | features/dungeonMap2/DungeonRoomStaticData.js | 19 | ||||
-rw-r--r-- | features/dungeonMap2/index.js | 199 | ||||
-rw-r--r-- | features/dungeonMap2/metadata.json | 8 |
5 files changed, 440 insertions, 0 deletions
diff --git a/features/dungeonMap2/DungeonMapData.js b/features/dungeonMap2/DungeonMapData.js new file mode 100644 index 0000000..15ffcca --- /dev/null +++ b/features/dungeonMap2/DungeonMapData.js @@ -0,0 +1,80 @@ +import { m } from "../../../mappings/mappings" +import DungeonMapRoom from "./DungeonMapRoom" + +const BufferedImage = Java.type("java.awt.image.BufferedImage") + +class DungeonMapData { + constructor(floor) { + this.floor = floor + + this.greenRoom = undefined + /** + * @type {Map<String,DungeonMapRoom>} + */ + this.rooms = new Map() + + this.image = undefined + } + + setRoom(x, y, rotation, id) { + let locstr = x + "," + y + + if (this.rooms.get(locstr) && this.rooms.get(locstr).roomId !== id) { + this.rooms.get(locstr).setId(id) + this.mapChanged() + return + } + + let room = DungeonMapRoom.fromId(id, x, y, rotation) + + if (room.type === DungeonMapRoom.TYPE_SPAWN) { + this.greenRoom = locstr + } + console.log(room.type) + + this.rooms.set(locstr, room) + + this.mapChanged() + } + + mapChanged() { + if (this.image) { + this.image.getTexture()[m.deleteGlTexture]() + this.image = undefined + } + } + + /** + * @returns {Image} + */ + getImage() { + if (!this.image) { + this.image = new Image(this.render()) + } + return this.image + } + + /** + * @returns {BufferedImage} + */ + render() { + //create 256x256 image + let image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB) + + //if green room data not found yet then map should be empty + if (!this.greenRoom) return image + + //create graphics rendering context + let graphics = image.createGraphics() + + //render rooms + for (let data of this.rooms.entries()) { + let room = data[1] + room.draw(graphics, 256, 256) + } + + return image + } +} + +export default DungeonMapData
\ No newline at end of file diff --git a/features/dungeonMap2/DungeonMapRoom.js b/features/dungeonMap2/DungeonMapRoom.js new file mode 100644 index 0000000..10f26e2 --- /dev/null +++ b/features/dungeonMap2/DungeonMapRoom.js @@ -0,0 +1,134 @@ +import DungeonRoomStaticData from "./DungeonRoomStaticData" + +const Color = Java.type("java.awt.Color") + +class DungeonMapRoom { + + static TYPE_SPAWN = 0 + static TYPE_NORMAL = 1 + static TYPE_PUZZLE = 2 + static TYPE_MINIBOSS = 3 + static TYPE_FAIRY = 4 + static TYPE_BLOOD = 5 + static TYPE_UNKNOWN = 6 + + static SHAPE_1X1 = 0 + static SHAPE_1X2 = 1 + static SHAPE_1X3 = 2 + static SHAPE_1X4 = 3 + static SHAPE_2X2 = 4 + static SHAPE_L = 5 + + static fromId(roomId, x, y, rotation) { + let data = DungeonRoomStaticData.getDataFromId(roomId) + let type = DungeonMapRoom.TYPE_NORMAL + switch (data.type) { + case "mobs": + type = DungeonMapRoom.TYPE_NORMAL + break + case "miniboss": + type = DungeonMapRoom.TYPE_NORMAL + break + case "spawn": + type = DungeonMapRoom.TYPE_SPAWN + break + case "puzzle": + type = DungeonMapRoom.TYPE_PUZZLE + break + case "gold": + type = DungeonMapRoom.TYPE_MINIBOSS + break + case "fairy": + type = DungeonMapRoom.TYPE_FAIRY + break + case "blood": + type = DungeonMapRoom.TYPE_BLOOD + break + } + + let shape = DungeonMapRoom.SHAPE_1X1 + switch (data.shape) { + case "1x1": + shape = DungeonMapRoom.SHAPE_1X1 + break + case "1x2": + shape = DungeonMapRoom.SHAPE_1X2 + break + case "1x3": + shape = DungeonMapRoom.SHAPE_1X3 + break + case "1x4": + shape = DungeonMapRoom.SHAPE_1X4 + break + case "2x2": + shape = DungeonMapRoom.SHAPE_2X2 + break + case "L": + shape = DungeonMapRoom.SHAPE_L + break + } + return new DungeonMapRoom(type, shape, rotation, x, y, roomId) + } + + /** + * + * @param {Number} type + * @param {Number} shape + * @param {Number} rotation 0-3 + * @param {Number} x + * @param {Number} y + * @param {String} roomId + */ + constructor(type, shape, rotation, x, y, roomId) { + this.type = type + this.shape = shape + this.rotation = rotation + this.roomId = roomId + + this.location = [x, y] + } + + setId(id) { + this.roomId = id + } + + /** + * Renders this room onto the given Graphics2D + * @param {Graphics2D} graphics + */ + draw(graphics, xOff, yOff) { + + graphics.setColor(this.getRoomRenderColor()) + + switch (this.shape) { + case DungeonMapRoom.SHAPE_1X1: + graphics.fillRect(this.location[0] + xOff + 3, this.location[1] + yOff + 3, 26, 26) + break; + case DungeonMapRoom.SHAPE_1X2: + graphics.fillRect(this.location[0] + xOff + 3, this.location[1] + yOff + 3, 26 + 32, 26) + break; + case DungeonMapRoom.SHAPE_1X3: + graphics.fillRect(this.location[0] + xOff + 3, this.location[1] + yOff + 3, 26 + 64, 26) + break; + case DungeonMapRoom.SHAPE_1X4: + graphics.fillRect(this.location[0] + xOff + 3, this.location[1] + yOff + 3, 26 + 96, 26) + break; + } + + } + + getRoomRenderColor() { + return roomColorMap.get(this.type) + } +} + +let roomColorMap = new Map() +roomColorMap.set(DungeonMapRoom.TYPE_SPAWN, new Color(Renderer.color(0, 124, 0, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_NORMAL, new Color(Renderer.color(114, 67, 27, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_PUZZLE, new Color(Renderer.color(178, 76, 216, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_MINIBOSS, new Color(Renderer.color(229, 229, 51, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_FAIRY, new Color(Renderer.color(242, 127, 165, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_BLOOD, new Color(Renderer.color(255, 0, 0, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_UNKNOWN, new Color(Renderer.color(65, 65, 65, 255))) + +export default DungeonMapRoom
\ No newline at end of file diff --git a/features/dungeonMap2/DungeonRoomStaticData.js b/features/dungeonMap2/DungeonRoomStaticData.js new file mode 100644 index 0000000..75d5b1e --- /dev/null +++ b/features/dungeonMap2/DungeonRoomStaticData.js @@ -0,0 +1,19 @@ +class DungeonRoomStaticData { + constructor() { + this.fullRoomData = JSON.parse(FileLib.read("SoopyV2", "data/roomdata.json")) + + this.idMap = new Map() + this.fullRoomData.forEach((d, i) => { + d.id.forEach(id => { + this.idMap.set(id, i) + }) + this.idMap.set(d.index, i) + }) + } + + getDataFromId(id) { + return this.fullRoomData[this.idMap.get(id)] + } +} + +export default new DungeonRoomStaticData()
\ No newline at end of file diff --git a/features/dungeonMap2/index.js b/features/dungeonMap2/index.js new file mode 100644 index 0000000..c807e85 --- /dev/null +++ b/features/dungeonMap2/index.js @@ -0,0 +1,199 @@ +/// <reference types="../../../CTAutocomplete" /> +/// <reference lib="es2015" /> + +import Feature from "../../featureClass/class"; +import renderLibs from "../../../guimanager/renderLibs"; +import DungeonMapData from "./DungeonMapData"; +import DungeonRoomStaticData from "./DungeonRoomStaticData"; + +const AlphaComposite = Java.type("java.awt.AlphaComposite") + +class DungeonMap extends Feature { + constructor() { + super() + } + + onEnable() { + if (Player.getUUID().toString() !== "dc8c3964-7b29-4e03-ae9e-d13ebd65dd29") { + new SettingBase("Coming soontm", "maby", undefined, "coming_soontm", this) + return + } + + this.lastRoomId = undefined + + /**@type {DungeonMapData} */ + this.currentDungeon = undefined + + this.registerStep(true, 5, this.update) + + this.registerEvent("renderOverlay", this.renderOverlay) + } + + update() { + if (!this.isInDungeon()) { + this.lastRoomId = undefined + this.currentDungeon = undefined + return + } + + if (!this.currentDungeon) { + this.currentDungeon = new DungeonMapData(this.FeatureManager.features["dataLoader"].class.dungeonFloor) + } + + let roomid = this.getCurrentRoomId() + if (!roomid.includes(",")) return + + if (roomid !== this.lastRoomId) { + this.lastRoomId = roomid + + let roomWorldData = this.getRoomWorldData() + this.currentDungeon.setRoom(roomWorldData.x, roomWorldData.y, roomWorldData.rotation, roomid) + } + } + + renderOverlay() { + if (this.currentDungeon) { + let x = 10 + let y = 10 + let size = 100 + this.currentDungeon.getImage().draw(x, y, size, size) + + Renderer.drawRect(Renderer.color(0, 0, 0), x, y, size, 2) + Renderer.drawRect(Renderer.color(0, 0, 0), x, y, 2, size) + Renderer.drawRect(Renderer.color(0, 0, 0), x + size - 2, y, 2, size) + Renderer.drawRect(Renderer.color(0, 0, 0), x, y + size - 2, size, 2) + } + } + + getCurrentRoomId() { + if (Scoreboard.getLines().length === 0) return undefined + let id = Scoreboard.getLineByIndex(Scoreboard.getLines().length - 1).getName().trim().split(" ").pop() + + return id + } + + isInDungeon() { + if (!this.FeatureManager || !this.FeatureManager.features["dataLoader"]) return false + return this.FeatureManager.features["dataLoader"].class.isInDungeon + } + + getRoomXYWorld() { + let roomData = this.getRoomWorldData() + if (roomData.rotation === 4) { + return [roomData.x, roomData.y + 32] + } + + return [roomData.x, roomData.y] + } + + getCurrentRoomData() { + return DungeonRoomStaticData.getDataFromId(this.getCurrentRoomId()) + } + + getRotation(x, y, width, height, roofY) { + let currRoomData = this.getCurrentRoomData() + if (!currRoomData) return -1 + + if (currRoomData.shape !== "L") { + if (this.getTopBlockAt(x, y, roofY) === 11) return 0 + if (this.getTopBlockAt(x + width, y, roofY) === 11) return 1 + if (this.getTopBlockAt(x + width, y + height, roofY) === 11) return 2 + if (this.getTopBlockAt(x, y + height, roofY) === 11) return 3 + } else { + let one = this.getTopBlockAt2(x + width / 2 + 1, y + height / 2, roofY) + let two = this.getTopBlockAt2(x + width / 2 - 1, y + height / 2, roofY) + let three = this.getTopBlockAt2(x + width / 2, y + height / 2 + 1, roofY) + let four = this.getTopBlockAt2(x + width / 2, y + height / 2 - 1, roofY) + + if (one === 0 && three === 0) return 0 + if (two === 0 && three === 0) return 1 + if (one === 0 && four === 0) return 2 + if (two === 0 && four === 0) return 3//3 IS SO TOXIK HGOLY HEL I HATE L SHAPE ROOMS WHY DO THIS TO ME + } + + return -1 + } + + getRoomWorldData() { + let x = Math.floor((Player.getX() + 8) / 32) * 32 - 8 + let y = Math.floor((Player.getZ() + 8) / 32) * 32 - 8 + let width = 30 + let height = 30 + + let roofY = this.getRoofAt(x, y) + + while (World.getBlockStateAt(new BlockPos(x - 1, roofY, y)).getBlockId() !== 0) { + x -= 32 + width += 32 + } + while (World.getBlockStateAt(new BlockPos(x, roofY, y - 1)).getBlockId() !== 0) { + y -= 32 + height += 32 + } + while (World.getBlockStateAt(new BlockPos(x - 1, roofY, y)).getBlockId() !== 0) { //second iteration incase of L shape + x -= 32 + width += 32 + } + while (World.getBlockStateAt(new BlockPos(x + width + 1, roofY, y)).getBlockId() !== 0) { + width += 32 + } + while (World.getBlockStateAt(new BlockPos(x, roofY, y + height + 1)).getBlockId() !== 0) { + height += 32 + } + while (World.getBlockStateAt(new BlockPos(x + width, roofY, y + height + 1)).getBlockId() !== 0) { //second iteration incase of L shape + height += 32 + } + while (World.getBlockStateAt(new BlockPos(x + width + 1, roofY, y + height)).getBlockId() !== 0) { //second iteration incase of L shape + width += 32 + } + while (World.getBlockStateAt(new BlockPos(x + width, roofY, y - 1)).getBlockId() !== 0) {//second iteration incase of L shape + y -= 32 + height += 32 + } + while (World.getBlockStateAt(new BlockPos(x - 1, roofY, y + height)).getBlockId() !== 0) { //third iteration incase of L shape + x -= 32 + width += 32 + } + + + return { + x, + y, + width, + height, + cx: x + width / 2, + cy: y + height / 2, + rotation: this.getRotation(x, y, width, height, roofY) + } + } + + getRoofAt(x, z) { + let y = 255 + while (y > 0 && World.getBlockStateAt(new BlockPos(x, y, z)).getBlockId() === 0) y-- + + return y + } + + getTopBlockAt(x, z, y) { + if (!y) y = this.getHeightAt(x, z) + + return World.getBlockStateAt(new BlockPos(x, y, z)).getMetadata() + } + getTopBlockAt2(x, z, y) { + if (!y) y = this.getHeightAt(x, z) + + return World.getBlockStateAt(new BlockPos(x, y, z)).getBlockId() + } + getImageForPlayer(uuid) { + let img = renderLibs.getImage("https://crafatar.com/avatars/" + uuid.replace(/-/g, "") + "?size=8&overlay") + if (!img) return this.defaultPlayerImage + + return img + } + onDisable() { + } +} + +module.exports = { + class: new DungeonMap() +}
\ No newline at end of file diff --git a/features/dungeonMap2/metadata.json b/features/dungeonMap2/metadata.json new file mode 100644 index 0000000..a32de89 --- /dev/null +++ b/features/dungeonMap2/metadata.json @@ -0,0 +1,8 @@ +{ + "name": "Dungeon Map 2", + "description": "WIP", + "isHidden": false, + "isTogglable": true, + "defaultEnabled": false, + "sortA": 1 +}
\ No newline at end of file |