diff --git a/Server/src/main/java/core/game/node/entity/skill/construction/BuildingUtils.java b/Server/src/main/java/core/game/node/entity/skill/construction/BuildingUtils.java index 9a9dd5842..f68f4eb01 100644 --- a/Server/src/main/java/core/game/node/entity/skill/construction/BuildingUtils.java +++ b/Server/src/main/java/core/game/node/entity/skill/construction/BuildingUtils.java @@ -589,7 +589,7 @@ public final class BuildingUtils { if (HouseManager.isInDungeon(player)) { z = 3; } - if (player.getHouseManager().hasRoom(z, location[0], location[1])) { + if (player.getHouseManager().hasRoomAt(z, location[0], location[1])) { return location; } return null; @@ -666,7 +666,7 @@ public final class BuildingUtils { else if (player.getHouseManager().hasExit(z, roomX - 1, roomY, Direction.EAST)) { exits[2] = 1; } - else if (player.getHouseManager().hasRoom(z, roomX - 1, roomY)) { + else if (player.getHouseManager().hasRoomAt(z, roomX - 1, roomY)) { exits[2] = -1; } if (roomY == 7) { @@ -675,7 +675,7 @@ public final class BuildingUtils { else if (player.getHouseManager().hasExit(z, roomX, roomY + 1, Direction.SOUTH)) { exits[3] = 1; } - else if (player.getHouseManager().hasRoom(z, roomX, roomY + 1)) { + else if (player.getHouseManager().hasRoomAt(z, roomX, roomY + 1)) { exits[3] = -1; } if (roomX == 7) { @@ -684,7 +684,7 @@ public final class BuildingUtils { else if (player.getHouseManager().hasExit(z, roomX + 1, roomY, Direction.WEST)) { exits[0] = 1; } - else if (player.getHouseManager().hasRoom(z, roomX + 1, roomY)) { + else if (player.getHouseManager().hasRoomAt(z, roomX + 1, roomY)) { exits[0] = -1; } if (roomY == 0) { @@ -693,7 +693,7 @@ public final class BuildingUtils { else if (player.getHouseManager().hasExit(z, roomX, roomY - 1, Direction.NORTH)) { exits[1] = 1; } - else if (player.getHouseManager().hasRoom(z, roomX, roomY - 1)) { + else if (player.getHouseManager().hasRoomAt(z, roomX, roomY - 1)) { exits[1] = -1; } return exits; diff --git a/Server/src/main/java/core/game/node/entity/skill/construction/HouseManager.java b/Server/src/main/java/core/game/node/entity/skill/construction/HouseManager.java index 295d3b367..a4c6effd1 100644 --- a/Server/src/main/java/core/game/node/entity/skill/construction/HouseManager.java +++ b/Server/src/main/java/core/game/node/entity/skill/construction/HouseManager.java @@ -373,7 +373,7 @@ public final class HouseManager { * Creates the default house. * @param location The house location. */ - public void create(HouseLocation location) { + public void createNewHouseAt(HouseLocation location) { clearRooms(); Room room = rooms[0][4][3] = new Room(RoomProperties.GARDEN); room.configure(style); @@ -427,7 +427,7 @@ public final class HouseManager { for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { Room room = rooms[3][x][y]; - if (hasRoom(3, x, y)) { + if (hasRoomAt(3, x, y)) { BuildRegionChunk copy = room.getChunk().copy(dungeon.getPlanes()[0]); dungeon.replaceChunk(0, x, y, copy, from); room.loadDecorations(3, copy, this); @@ -524,7 +524,7 @@ public final class HouseManager { * @param roomY The room y-coordinate. * @return {@code True} if so. */ - public boolean hasRoom(int z, int roomX, int roomY) { + public boolean hasRoomAt(int z, int roomX, int roomY) { Room room = rooms[z][roomX][roomY]; return room != null && !room.getProperties().isRoof(); } diff --git a/Server/src/main/java/core/game/node/entity/skill/construction/RemovalDialogue.java b/Server/src/main/java/core/game/node/entity/skill/construction/RemovalDialogue.java index 91ebb92f5..727e908b7 100644 --- a/Server/src/main/java/core/game/node/entity/skill/construction/RemovalDialogue.java +++ b/Server/src/main/java/core/game/node/entity/skill/construction/RemovalDialogue.java @@ -68,7 +68,7 @@ public final class RemovalDialogue extends DialoguePlugin { public boolean handle(int interfaceId, int buttonId) { if (stage == 0) { if (buttonId == 1) { - if (plane == 0 && player.getHouseManager().hasRoom(1, pos[0], pos[1])) { + if (plane == 0 && player.getHouseManager().hasRoomAt(1, pos[0], pos[1])) { interpreter.sendPlainMessage(false, "You can't remove a room supporting another room."); stage = 1; return true; diff --git a/Server/src/main/kotlin/rs09/game/node/entity/skill/construction/EstateAgentDialogue.kt b/Server/src/main/kotlin/rs09/game/node/entity/skill/construction/EstateAgentDialogue.kt index ba5476286..c774de8be 100644 --- a/Server/src/main/kotlin/rs09/game/node/entity/skill/construction/EstateAgentDialogue.kt +++ b/Server/src/main/kotlin/rs09/game/node/entity/skill/construction/EstateAgentDialogue.kt @@ -137,7 +137,7 @@ class EstateAgentDialogue : DialoguePlugin { 7 -> { if (player.inventory.contains(995, 1000)) { player.inventory.remove(Item(995, 1000)) - player.houseManager.create(HouseLocation.RIMMINGTON) + player.houseManager.createNewHouseAt(HouseLocation.RIMMINGTON) npc( "Thank you. Go through the Rimmington house portal", "and you will find your house ready for you to start", diff --git a/Server/src/test/kotlin/HouseManagerTests.kt b/Server/src/test/kotlin/HouseManagerTests.kt index 957501471..36847d4b9 100644 --- a/Server/src/test/kotlin/HouseManagerTests.kt +++ b/Server/src/test/kotlin/HouseManagerTests.kt @@ -1,9 +1,10 @@ import api.forceWalk import core.game.node.entity.player.link.music.MusicEntry +import core.game.node.entity.skill.construction.HouseLocation import core.game.node.entity.skill.construction.HouseManager import core.game.node.entity.skill.construction.Servant import core.game.node.entity.skill.construction.ServantType -import org.junit.Assert +import core.game.world.map.RegionManager import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test @@ -15,6 +16,30 @@ class HouseManagerTests { val manager = HouseManager() val testPlayer = TestUtils.getMockPlayer("test") + @Test fun constructShouldLoadTheConstructedRegion() { + val newManager = HouseManager() + newManager.createNewHouseAt(HouseLocation.RIMMINGTON) //add a room to it, already tested below + newManager.construct() + Assertions.assertNotEquals(0, newManager.region.planes[0].getRegionChunk(4, 3).objects.size) + } + + @Test fun constructShouldRegisterNewRegionToRegionManager() { + val newManager = HouseManager() + newManager.construct() + Assertions.assertEquals(true, RegionManager.forId(newManager.region.id) == newManager.region) + } + + @Test fun constructShouldSetTheRegion() { + val newManager = HouseManager() + newManager.construct() + Assertions.assertNotEquals(null, newManager.region) + } + + @Test fun createShouldPlaceGardenInRooms() { + manager.createNewHouseAt(HouseLocation.RIMMINGTON) + Assertions.assertEquals(true, manager.hasRoomAt(0, 4, 3)) + } + @Test fun enterShouldConstructDynamicRegionIfItHasNotBeenConstructed() { manager.enter(testPlayer, false) Assertions.assertEquals(true, manager.isLoaded)