From 10b1868fab1ec16e2c5794538cacf4ca98767b9a Mon Sep 17 00:00:00 2001 From: ceikry Date: Thu, 8 Jul 2021 17:05:17 -0500 Subject: [PATCH] Fixed Jatizso gates --- Server/src/main/kotlin/api/ContentAPI.kt | 64 ++++++++++++++++++- .../interaction/region/JatizsoListeners.kt | 42 ++++++++++++ 2 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 Server/src/main/kotlin/rs09/game/interaction/region/JatizsoListeners.kt diff --git a/Server/src/main/kotlin/api/ContentAPI.kt b/Server/src/main/kotlin/api/ContentAPI.kt index 8322b0b57..2f4fa55f9 100644 --- a/Server/src/main/kotlin/api/ContentAPI.kt +++ b/Server/src/main/kotlin/api/ContentAPI.kt @@ -22,6 +22,7 @@ import core.game.node.item.GroundItem import core.game.node.item.GroundItemManager import core.game.node.item.Item import core.game.system.task.Pulse +import core.game.world.map.Direction import core.game.world.map.Location import core.game.world.map.RegionManager import core.game.world.map.path.Pathfinder @@ -254,13 +255,50 @@ object ContentAPI { * @param toReplace the GameObject instance we are replacing * @param with the ID of the GameObject we wish to replace toReplace with * @param for_ticks the number of ticks the object should be replaced for. Use -1 for permanent. + * @param loc the location to move the new object to if necessary. Defaults to null. */ @JvmStatic - fun replaceScenery(toReplace: Scenery, with: Int, for_ticks: Int) { + fun replaceScenery(toReplace: Scenery, with: Int, for_ticks: Int, loc: Location? = null) { + val newLoc = when(loc){ + null -> toReplace.location + else -> loc + } if (for_ticks == -1) { - SceneryBuilder.replace(toReplace, toReplace.transform(with)) + SceneryBuilder.replace(toReplace, toReplace.transform(with,toReplace.rotation,newLoc)) } else { - SceneryBuilder.replace(toReplace, toReplace.transform(with), for_ticks) + SceneryBuilder.replace(toReplace, toReplace.transform(with,toReplace.rotation, newLoc), for_ticks) + } + toReplace.isActive = false + } + + /** + * Replace an object with the given revert timer with the given rotation + * @param toReplace the GameObject instance we are replacing + * @param with the ID of the GameObject we wish to replace toReplace with + * @param for_ticks the number of ticks the object should be replaced for. Use -1 for permanent. + * @Param rotation the Direction of the rotation it should use. Direction.NORTH, Direction.SOUTH, etc + * @param loc the location to move the new object to if necessary. Defaults to null. + */ + @JvmStatic + fun replaceScenery(toReplace: Scenery, with: Int, for_ticks: Int, rotation: Direction, loc: Location? = null){ + val newLoc = when(loc){ + null -> toReplace.location + else -> loc + } + val rot = when(rotation){ + Direction.NORTH_WEST -> 0 + Direction.NORTH -> 1 + Direction.NORTH_EAST -> 2 + Direction.EAST -> 4 + Direction.SOUTH_EAST -> 7 + Direction.SOUTH -> 6 + Direction.SOUTH_WEST -> 5 + Direction.WEST -> 3 + } + if (for_ticks == -1) { + SceneryBuilder.replace(toReplace, toReplace.transform(with,rot, newLoc)) + } else { + SceneryBuilder.replace(toReplace, toReplace.transform(with,rot,newLoc), for_ticks) } toReplace.isActive = false } @@ -493,6 +531,26 @@ object ContentAPI { return Repository.findNPC(id) } + /** + * Gets the spawned scenery from the world map using the given coordinates + * @param x the X coordinate to use + * @param y the Y coordinate to use + * @param z the Z coordinate to use + */ + @JvmStatic + fun getScenery(x: Int, y: Int, z: Int): Scenery?{ + return RegionManager.getObject(z,x,y) + } + + /** + * Gets the spawned scenery from the world map using the given Location object. + * @param loc the Location object to use. + */ + @JvmStatic + fun getScenery(loc: Location): Scenery?{ + return RegionManager.getObject(loc) + } + /** * Gets an NPC within render distance of the refLoc that matches the given ID * @param refLoc the Location to find the closes NPC to diff --git a/Server/src/main/kotlin/rs09/game/interaction/region/JatizsoListeners.kt b/Server/src/main/kotlin/rs09/game/interaction/region/JatizsoListeners.kt new file mode 100644 index 000000000..f53edd21e --- /dev/null +++ b/Server/src/main/kotlin/rs09/game/interaction/region/JatizsoListeners.kt @@ -0,0 +1,42 @@ +package rs09.game.interaction.region + +import api.ContentAPI +import core.game.world.map.Direction +import core.game.world.map.zone.ZoneBorders +import rs09.game.interaction.InteractionListener + +class JatizsoListeners : InteractionListener() { + val GATES_CLOSED = intArrayOf(21403,21405) + val NORTH_GATE_ZONE = ZoneBorders(2414,3822,2417,3825) + val WEST_GATE_ZONE = ZoneBorders(2386,3797,2390,3801) + override fun defineListeners() { + on(GATES_CLOSED, SCENERY, "open"){player, node -> + if(NORTH_GATE_ZONE.insideBorder(player)){ + if(node.id == GATES_CLOSED.first()){ + val other = ContentAPI.getScenery(node.location.transform(1, 0, 0)) ?: return@on true + ContentAPI.replaceScenery(node.asScenery(), node.id + 1, -1, Direction.EAST) + ContentAPI.replaceScenery(other.asScenery(), other.id - 1, -1, Direction.SOUTH) + } else { + val other = ContentAPI.getScenery(node.location.transform(-1, 0, 0)) ?: return@on true + ContentAPI.replaceScenery(node.asScenery(), node.id + 1, -1, Direction.SOUTH) + ContentAPI.replaceScenery(other.asScenery(), other.id, -1, Direction.EAST) + } + + ContentAPI.playAudio(player, ContentAPI.getAudio(81)) + } else if(WEST_GATE_ZONE.insideBorder(player)){ + if(node.id == GATES_CLOSED.first()){ + val other = ContentAPI.getScenery(node.location.transform(0, 1, 0)) ?: return@on true + ContentAPI.replaceScenery(node.asScenery(), node.id + 1, -1, Direction.WEST) + ContentAPI.replaceScenery(other.asScenery(), other.id + 1, -1, Direction.NORTH) + } else { + val other = ContentAPI.getScenery(node.location.transform(0, -1, 0)) ?: return@on true + ContentAPI.replaceScenery(node.asScenery(), node.id + 1, -1, Direction.NORTH) + ContentAPI.replaceScenery(other.asScenery(), other.id + 1, -1, Direction.WEST) + } + + ContentAPI.playAudio(player, ContentAPI.getAudio(81)) + } + return@on true + } + } +} \ No newline at end of file