mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2026-08-22 19:05:11 -06:00
Adding more tests
This commit is contained in:
parent
30ce30ac04
commit
1aaa1a46f8
7 changed files with 56 additions and 54 deletions
|
|
@ -166,7 +166,7 @@ public final class BuildingUtils {
|
|||
int roomX = object.getLocation().getChunkX();
|
||||
int roomY = object.getLocation().getChunkY();
|
||||
int z = object.getLocation().getZ();
|
||||
Region region = player.getHouseManager().getRegion();
|
||||
Region region = player.getHouseManager().getHouseRegion();
|
||||
if (HouseManager.isInDungeon(player)) {
|
||||
region = player.getHouseManager().getDungeonRegion();
|
||||
z = 3;
|
||||
|
|
@ -265,7 +265,7 @@ public final class BuildingUtils {
|
|||
Hotspot h = r.getStairs();
|
||||
if (h != null) {
|
||||
h.setDecorationIndex(decIndex);
|
||||
Region reg = plane == 3 ? player.getHouseManager().getDungeonRegion() : player.getHouseManager().getRegion();
|
||||
Region reg = plane == 3 ? player.getHouseManager().getDungeonRegion() : player.getHouseManager().getHouseRegion();
|
||||
if (reg == null) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -352,7 +352,7 @@ public final class BuildingUtils {
|
|||
}
|
||||
Location l = object.getLocation();
|
||||
Room room = player.getHouseManager().getRooms()[l.getZ()][l.getChunkX()][l.getChunkY()];
|
||||
Region region = player.getHouseManager().getRegion();
|
||||
Region region = player.getHouseManager().getHouseRegion();
|
||||
if (HouseManager.isInDungeon(player)) {
|
||||
region = player.getHouseManager().getDungeonRegion();
|
||||
room = player.getHouseManager().getRooms()[3][l.getChunkX()][l.getChunkY()];
|
||||
|
|
@ -396,7 +396,7 @@ public final class BuildingUtils {
|
|||
Hotspot h = r.getStairs();
|
||||
if (h != null) {
|
||||
h.setDecorationIndex(-1);
|
||||
Region reg = plane == 3 ? player.getHouseManager().getDungeonRegion() : player.getHouseManager().getRegion();
|
||||
Region reg = plane == 3 ? player.getHouseManager().getDungeonRegion() : player.getHouseManager().getHouseRegion();
|
||||
if (reg == null) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,12 +34,12 @@ public final class HouseManager {
|
|||
/**
|
||||
* The current region.
|
||||
*/
|
||||
private DynamicRegion region;
|
||||
private DynamicRegion houseRegion;
|
||||
|
||||
/**
|
||||
* The current region.
|
||||
*/
|
||||
private DynamicRegion dungeon;
|
||||
private DynamicRegion dungeonRegion;
|
||||
|
||||
/**
|
||||
* The house location.
|
||||
|
|
@ -186,7 +186,7 @@ public final class HouseManager {
|
|||
}
|
||||
player.setAttribute("poh_entry", HouseManager.this);
|
||||
player.lock(1);
|
||||
player.sendMessage("House location: " + region.getBaseLocation() + ", entry: " + getEnterLocation());
|
||||
player.sendMessage("House location: " + houseRegion.getBaseLocation() + ", entry: " + getEnterLocation());
|
||||
player.getProperties().setTeleportLocation(getEnterLocation());
|
||||
openLoadInterface(player);
|
||||
checkForAndSpawnServant(player);
|
||||
|
|
@ -240,7 +240,7 @@ public final class HouseManager {
|
|||
*/
|
||||
public static void leave(Player player) {
|
||||
HouseManager house = player.getAttribute("poh_entry", player.getHouseManager());
|
||||
if (house.getRegion() == null){
|
||||
if (house.getHouseRegion() == null){
|
||||
return;
|
||||
}
|
||||
if (house.isInHouse(player)) {
|
||||
|
|
@ -278,10 +278,10 @@ public final class HouseManager {
|
|||
int diffX = player.getLocation().getLocalX();
|
||||
int diffY = player.getLocation().getLocalY();
|
||||
int diffZ = player.getLocation().getZ();
|
||||
boolean inDungeon = player.getViewport().getRegion() == dungeon;
|
||||
boolean inDungeon = player.getViewport().getRegion() == dungeonRegion;
|
||||
this.buildingMode = buildingMode;
|
||||
construct();
|
||||
Location newLoc = (dungeon == null ? region : (inDungeon ? dungeon : region)).getBaseLocation().transform(diffX,diffY,diffZ);
|
||||
Location newLoc = (dungeonRegion == null ? houseRegion : (inDungeon ? dungeonRegion : houseRegion)).getBaseLocation().transform(diffX,diffY,diffZ);
|
||||
player.getProperties().setTeleportLocation(newLoc);
|
||||
}
|
||||
|
||||
|
|
@ -291,15 +291,15 @@ public final class HouseManager {
|
|||
*/
|
||||
public void expelGuests(Player player) {
|
||||
if (isLoaded()) {
|
||||
for (RegionPlane plane : region.getPlanes()) {
|
||||
for (RegionPlane plane : houseRegion.getPlanes()) {
|
||||
for (Player p : plane.getPlayers()) {
|
||||
if (p != player) {
|
||||
leave(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dungeon != null) {
|
||||
for (RegionPlane plane : dungeon.getPlanes()) {
|
||||
if (dungeonRegion != null) {
|
||||
for (RegionPlane plane : dungeonRegion.getPlanes()) {
|
||||
for (Player p : plane.getPlayers()) {
|
||||
if (p != player) {
|
||||
leave(p);
|
||||
|
|
@ -315,7 +315,7 @@ public final class HouseManager {
|
|||
* @return The entering location.
|
||||
*/
|
||||
public Location getEnterLocation() {
|
||||
if (region == null) {
|
||||
if (houseRegion == null) {
|
||||
SystemLogger.logErr("House wasn't constructed yet!");
|
||||
return null;
|
||||
}
|
||||
|
|
@ -327,7 +327,7 @@ public final class HouseManager {
|
|||
if (h.getDecorationIndex() > -1) {
|
||||
Decoration d = h.getHotspot().getDecorations()[h.getDecorationIndex()];
|
||||
if (d == Decoration.PORTAL) {
|
||||
return region.getBaseLocation().transform(x * 8 + h.getChunkX(), y * 8 + h.getChunkY() + 2, 0);
|
||||
return houseRegion.getBaseLocation().transform(x * 8 + h.getChunkX(), y * 8 + h.getChunkY() + 2, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -390,17 +390,14 @@ public final class HouseManager {
|
|||
Region.load(from, true);
|
||||
RegionChunk defaultChunk = from.getPlanes()[style.getPlane()].getRegionChunk(1, 0);
|
||||
RegionChunk defaultSkyChunk = from.getPlanes()[1].getRegionChunk(0,0);
|
||||
ZoneBorders borders = DynamicRegion.reserveArea(8,8);
|
||||
region = new DynamicRegion(-1, borders.getSouthWestX() >> 6, borders.getSouthWestY() >> 6);
|
||||
region.setBorders(borders);
|
||||
region.setUpdateAllPlanes(true);
|
||||
RegionManager.addRegion(region.getId(), region);
|
||||
houseRegion = getPreparedRegion();
|
||||
RegionManager.addRegion(houseRegion.getId(), houseRegion);
|
||||
configureRoofs();
|
||||
for (int z = 0; z < 4; z++) {
|
||||
for (int x = 0; x < 8; x++) {
|
||||
for (int y = 0; y < 8; y++) {
|
||||
if(z == 3){
|
||||
region.replaceChunk(z, x, y, defaultSkyChunk.copy(region.getPlanes()[z]), from);
|
||||
houseRegion.replaceChunk(z, x, y, defaultSkyChunk.copy(houseRegion.getPlanes()[z]), from);
|
||||
continue;
|
||||
}
|
||||
Room room = rooms[z][x][y];
|
||||
|
|
@ -408,37 +405,42 @@ public final class HouseManager {
|
|||
if (room.getProperties().isRoof() && buildingMode) {
|
||||
continue;
|
||||
}
|
||||
BuildRegionChunk copy = room.getChunk().copy(region.getPlanes()[z]);
|
||||
region.replaceChunk(z, x, y, copy, from);
|
||||
BuildRegionChunk copy = room.getChunk().copy(houseRegion.getPlanes()[z]);
|
||||
houseRegion.replaceChunk(z, x, y, copy, from);
|
||||
room.loadDecorations(z, copy, this);
|
||||
} else {
|
||||
region.replaceChunk(z, x, y, z != 0 ? null : defaultChunk.copy(region.getPlanes()[0]), from);
|
||||
houseRegion.replaceChunk(z, x, y, z != 0 ? null : defaultChunk.copy(houseRegion.getPlanes()[0]), from);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasDungeon()) {
|
||||
defaultChunk = from.getPlanes()[style.getPlane()].getRegionChunk(3, 0);
|
||||
borders = DynamicRegion.reserveArea(8, 8);
|
||||
dungeon = new DynamicRegion(-1, borders.getSouthWestX() >> 6, borders.getSouthWestY() >> 6);
|
||||
dungeon.setBorders(borders);
|
||||
dungeon.setUpdateAllPlanes(true);
|
||||
RegionManager.addRegion(dungeon.getId(), dungeon);
|
||||
dungeonRegion = getPreparedRegion();
|
||||
RegionManager.addRegion(dungeonRegion.getId(), dungeonRegion);
|
||||
for (int x = 0; x < 8; x++) {
|
||||
for (int y = 0; y < 8; y++) {
|
||||
Room room = rooms[3][x][y];
|
||||
if (hasRoomAt(3, x, y)) {
|
||||
BuildRegionChunk copy = room.getChunk().copy(dungeon.getPlanes()[0]);
|
||||
dungeon.replaceChunk(0, x, y, copy, from);
|
||||
BuildRegionChunk copy = room.getChunk().copy(dungeonRegion.getPlanes()[0]);
|
||||
dungeonRegion.replaceChunk(0, x, y, copy, from);
|
||||
room.loadDecorations(3, copy, this);
|
||||
} else {
|
||||
dungeon.replaceChunk(0, x, y, buildingMode ? null : defaultChunk.copy(dungeon.getPlanes()[0]), from);
|
||||
dungeonRegion.replaceChunk(0, x, y, buildingMode ? null : defaultChunk.copy(dungeonRegion.getPlanes()[0]), from);
|
||||
}
|
||||
}
|
||||
}
|
||||
region.link(dungeon);
|
||||
houseRegion.link(dungeonRegion);
|
||||
}
|
||||
ZoneBuilder.configure(zone);
|
||||
return houseRegion;
|
||||
}
|
||||
|
||||
public DynamicRegion getPreparedRegion() {
|
||||
ZoneBorders borders = DynamicRegion.reserveArea(8,8);
|
||||
DynamicRegion region = new DynamicRegion(-1, borders.getSouthWestX() >> 6, borders.getSouthWestY() >> 6);
|
||||
region.setBorders(borders);
|
||||
region.setUpdateAllPlanes(true);
|
||||
return region;
|
||||
}
|
||||
|
||||
|
|
@ -469,7 +471,7 @@ public final class HouseManager {
|
|||
*/
|
||||
public Room getRoom(Location l) {
|
||||
int z = l.getZ();
|
||||
if (dungeon != null && l.getRegionId() == dungeon.getId()) {
|
||||
if (dungeonRegion != null && l.getRegionId() == dungeonRegion.getId()) {
|
||||
z = 3;
|
||||
}
|
||||
return rooms[z][l.getChunkX()][l.getChunkY()];
|
||||
|
|
@ -539,7 +541,7 @@ public final class HouseManager {
|
|||
}
|
||||
int diffX = player.getLocation().getLocalX();
|
||||
int diffY = player.getLocation().getLocalY();
|
||||
player.getProperties().setTeleportLocation(dungeon.getBaseLocation().transform(diffX, diffY, 0));
|
||||
player.getProperties().setTeleportLocation(dungeonRegion.getBaseLocation().transform(diffX, diffY, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -680,7 +682,7 @@ public final class HouseManager {
|
|||
* @return {@code True} if so.
|
||||
*/
|
||||
public boolean isInHouse(Player player) {
|
||||
return isLoaded() && (player.getViewport().getRegion() == region || player.getViewport().getRegion() == dungeon);
|
||||
return isLoaded() && (player.getViewport().getRegion() == houseRegion || player.getViewport().getRegion() == dungeonRegion);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -689,7 +691,7 @@ public final class HouseManager {
|
|||
* @return {@code True} if so.
|
||||
*/
|
||||
public static boolean isInDungeon(Player player) {
|
||||
return player.getViewport().getRegion() == player.getHouseManager().dungeon;
|
||||
return player.getViewport().getRegion() == player.getHouseManager().dungeonRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -697,7 +699,7 @@ public final class HouseManager {
|
|||
* @return {@code True} if an active region for the house exists.
|
||||
*/
|
||||
public boolean isLoaded() {
|
||||
return (region != null) || (dungeon != null);
|
||||
return (houseRegion != null) || (dungeonRegion != null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -776,8 +778,8 @@ public final class HouseManager {
|
|||
* Gets the region.
|
||||
* @return The region.
|
||||
*/
|
||||
public DynamicRegion getRegion() {
|
||||
return region;
|
||||
public DynamicRegion getHouseRegion() {
|
||||
return houseRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -785,7 +787,7 @@ public final class HouseManager {
|
|||
* @return The dungeon region.
|
||||
*/
|
||||
public Region getDungeonRegion() {
|
||||
return dungeon;
|
||||
return dungeonRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ public final class HouseZone extends MapZone {
|
|||
if (previousDungeon != -1) {
|
||||
unregisterRegion(previousDungeon);
|
||||
}
|
||||
registerRegion(house.getRegion().getId());
|
||||
registerRegion(house.getHouseRegion().getId());
|
||||
if (house.getDungeonRegion() != null) {
|
||||
registerRegion(house.getRegion().getId());
|
||||
registerRegion(house.getHouseRegion().getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public final class RoomBuilder {
|
|||
break;
|
||||
case RECURSIVE:
|
||||
room.setAllDecorationIndex(hotspot.getDecorationIndex(deco), h.getHotspot());
|
||||
Scenery[][] objects = player.getHouseManager().getRegion().getPlanes()[l.getZ()].getChunks()[l.getLocalX() >> 3][l.getLocalY() >> 3].getObjects();
|
||||
Scenery[][] objects = player.getHouseManager().getHouseRegion().getPlanes()[l.getZ()].getChunks()[l.getLocalX() >> 3][l.getLocalY() >> 3].getObjects();
|
||||
for (int j = 0; j < objects.length; j++) {
|
||||
for (int k = 0; k < objects[j].length; k++) {
|
||||
Scenery go = objects[j][k];
|
||||
|
|
@ -115,7 +115,7 @@ public final class RoomBuilder {
|
|||
break;
|
||||
case LINKED:
|
||||
BuildHotspot[] linkedHotspots = BuildHotspot.getLinkedHotspots(h.getHotspot());
|
||||
BuildRegionChunk chunk = (BuildRegionChunk) player.getHouseManager().getRegion().getPlanes()[l.getZ()].getChunks()[l.getLocalX() >> 3][l.getLocalY() >> 3];
|
||||
BuildRegionChunk chunk = (BuildRegionChunk) player.getHouseManager().getHouseRegion().getPlanes()[l.getZ()].getChunks()[l.getLocalX() >> 3][l.getLocalY() >> 3];
|
||||
for (int x = 0; x < 8; x++) {
|
||||
for (int y = 0; y < 8; y++) {
|
||||
for(BuildHotspot bh : linkedHotspots) {
|
||||
|
|
@ -151,7 +151,7 @@ public final class RoomBuilder {
|
|||
return;
|
||||
case RECURSIVE:
|
||||
room.setAllDecorationIndex(-1, hotspot.getHotspot());
|
||||
Scenery[][] objects = player.getHouseManager().getRegion().getPlanes()[l.getZ()].getChunks()[l.getLocalX() >> 3][l.getLocalY() >> 3].getObjects();
|
||||
Scenery[][] objects = player.getHouseManager().getHouseRegion().getPlanes()[l.getZ()].getChunks()[l.getLocalX() >> 3][l.getLocalY() >> 3].getObjects();
|
||||
for (int j = 0; j < objects.length; j++) {
|
||||
for (int k = 0; k < objects[j].length; k++) {
|
||||
Scenery go = objects[j][k];
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public final class StaircasePlugin extends OptionHandler {
|
|||
} else {
|
||||
Location destination = l.transform(0, 0, z);
|
||||
if (player.getViewport().getRegion() == house.getDungeonRegion()) {
|
||||
destination = house.getRegion().getBaseLocation().transform(l.getLocalX(), l.getLocalY(), 0);
|
||||
destination = house.getHouseRegion().getBaseLocation().transform(l.getLocalX(), l.getLocalY(), 0);
|
||||
}
|
||||
else if (plane == 3) {
|
||||
destination = house.getDungeonRegion().getBaseLocation().transform(l.getLocalX(), l.getLocalY(), 0);
|
||||
|
|
|
|||
|
|
@ -523,7 +523,7 @@ public class HouseServantDialogue extends DialoguePlugin {
|
|||
|
||||
@Override
|
||||
public boolean pulse() {
|
||||
if (player == null || player.getHouseManager().getRegion() != player.getViewport().getRegion()) { //TODO: Check if in dungeon?
|
||||
if (player == null || player.getHouseManager().getHouseRegion() != player.getViewport().getRegion()) { //TODO: Check if in dungeon?
|
||||
return true;
|
||||
}
|
||||
int amt = player.getBank().getAmount(item.getId());
|
||||
|
|
|
|||
|
|
@ -20,38 +20,38 @@ class HouseManagerTests {
|
|||
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)
|
||||
Assertions.assertNotEquals(0, newManager.houseRegion.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)
|
||||
Assertions.assertEquals(true, RegionManager.forId(newManager.houseRegion.id) == newManager.houseRegion)
|
||||
}
|
||||
|
||||
@Test fun constructShouldSetTheRegionInTheHouseManager() {
|
||||
val newManager = HouseManager()
|
||||
newManager.construct()
|
||||
Assertions.assertNotEquals(null, newManager.region)
|
||||
Assertions.assertNotEquals(null, newManager.houseRegion)
|
||||
}
|
||||
|
||||
@Test fun constructShouldSetTheRegionBorders() {
|
||||
val newManager = HouseManager()
|
||||
newManager.construct()
|
||||
Assertions.assertNotEquals(null, newManager.region.borders)
|
||||
Assertions.assertNotEquals(null, newManager.houseRegion.borders)
|
||||
}
|
||||
|
||||
@Test fun constructShouldSetUpdateAllPlanes() {
|
||||
val newManager = HouseManager()
|
||||
newManager.construct()
|
||||
Assertions.assertEquals(true, newManager.region.isUpdateAllPlanes)
|
||||
Assertions.assertEquals(true, newManager.houseRegion.isUpdateAllPlanes)
|
||||
}
|
||||
|
||||
@Test fun constructShouldReplacePlanes1And2UnusedChunksAndAllPlane3ChunksWithEmptyChunks() {
|
||||
val newManager = HouseManager()
|
||||
newManager.construct()
|
||||
for(z in 1..3)
|
||||
for (objs in newManager.region.planes[z].objects)
|
||||
for (objs in newManager.houseRegion.planes[z].objects)
|
||||
for (obj in objs) Assertions.assertEquals(null, obj)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue