diff --git a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java index 3bf708e5..a168192b 100644 --- a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java +++ b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java @@ -13,11 +13,14 @@ public class BukkitWorldEditor { - private static final int SIGN_INDEX = 1; private static final World WORLD = Bukkit.getWorld(ConfigManager.getInstance().getWorldName()); - private static final int DAY_START_TIME = 0; - private static final int NIGHT_START_TIME = 13000; +// ######################################### +// # Vault # +// ######################################### + + private static final int SIGN_INDEX = 1; + public static void addSignAboveVault(PrisonEscapeLocation location, String text) { Location bukkitLocation = new Location(WORLD, location.getX(), location.getY() + 1, location.getZ()); bukkitLocation.getBlock().setType(Material.OAK_WALL_SIGN); @@ -41,6 +44,13 @@ public static void deleteVaultAndRespectiveSign(PrisonEscapeLocation location) { signLocation.getBlock().setType(Material.AIR); } +// ######################################## +// # Time # +// ######################################## + + private static final int DAY_START_TIME = 0; + private static final int NIGHT_START_TIME = 13000; + public static void changeTimeToDay() { WORLD.setTime(DAY_START_TIME); } @@ -49,4 +59,58 @@ public static void changeTimeToNight() { WORLD.setTime(NIGHT_START_TIME); } +// ######################################## +// # Wall # +// ######################################## + + private static final Material DEFAULT_BLOCK = Material.STONE_BRICKS; + private static final Material CRACKED_BLOCK = Material.CRACKED_STONE_BRICKS; + + public static void buildWall(PrisonEscapeLocation loc1, PrisonEscapeLocation loc2) { + int lowerX; + int higherX; + if (loc1.getX() >= loc2.getX()) { + higherX = loc1.getX(); + lowerX = loc2.getX(); + } + else { + higherX = loc2.getX(); + lowerX = loc1.getX(); + } + + int lowerZ; + int higherZ; + if (loc1.getZ() >= loc2.getZ()) { + higherZ = loc1.getZ(); + lowerZ = loc2.getZ(); + } + else { + higherZ = loc2.getZ(); + lowerZ = loc1.getZ(); + } + + int lowerY; + int higherY; + if (loc1.getY() >= loc2.getY()) { + higherY = loc1.getY(); + lowerY = loc2.getY(); + } + else { + higherY = loc2.getY(); + lowerY = loc1.getY(); + } + + for (int x = lowerX; x <= higherX; x++) { + for (int z = lowerZ; z <= higherZ; z++) { + for (int y = lowerY; y <= higherY; y++) { + WORLD.getBlockAt(x, y, z).setType(DEFAULT_BLOCK); + } + } + } + } + + public static void putCrackOnWall(PrisonEscapeLocation loc) { + WORLD.getBlockAt(loc.getX(), loc.getY(), loc.getZ()).setType(CRACKED_BLOCK); + } + } diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/PrisonBuilding.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/PrisonBuilding.java index 7ca82165..7d42a81e 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/PrisonBuilding.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/PrisonBuilding.java @@ -30,6 +30,7 @@ public class PrisonBuilding { private Hashtable _chests; private List _metalDetectorsLocations; + private Wall _wall; // ######################################### // # Constructor # @@ -65,6 +66,9 @@ public PrisonBuilding(PrisonEscapeLocation reference) { } _metalDetectorsLocations = new ArrayList<>(); + + _wall = new Wall(); + _wall.raiseFixedWall(); } private List createLocationsList( diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Wall.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Wall.java new file mode 100644 index 00000000..0407a7c5 --- /dev/null +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Wall.java @@ -0,0 +1,89 @@ +package net.tiagofar78.prisonescape.game.prisonbuilding; + +import java.util.List; +import java.util.Random; + +import org.joml.Math; + +import net.tiagofar78.prisonescape.bukkit.BukkitWorldEditor; + +public class Wall { + + private static final int WALL_HEIGHT = 5; + private static final int MIN_CRACK_DISTANCE = 10; + private static final int MAX_CRACK_DISTANCE = 30; + + private static final char CRACK_CHAR = '#'; + private static final String[] CRACK_FORMAT = { + "O###O", + "#####", + "#####", + "#####", + "O###O" + }; + + private List _cornersLocations; + + public Wall() { + + } + + public void raiseFixedWall() { + for (int i = 0; i < _cornersLocations.size() - 1; i++) { + PrisonEscapeLocation loc1 = _cornersLocations.get(i); + PrisonEscapeLocation loc2 = _cornersLocations.get(i + 1).add(0, WALL_HEIGHT - 1, 0); + BukkitWorldEditor.buildWall(loc1, loc2); + } + } + + public void putRandomCracks() { + if (_cornersLocations.size() == 0) { + return; + } + + int crackPos = 0; + for (int i = 0; i < _cornersLocations.size(); i++) { + PrisonEscapeLocation corner1 = _cornersLocations.get(i); + PrisonEscapeLocation corner2 = _cornersLocations.get(i + 1); + + int xDiff = corner2.getX() - corner1.getX(); + int xAbsDiff = Math.abs(xDiff); + int zDiff = corner2.getZ() - corner1.getZ(); + int zAbsDiff = Math.abs(zDiff); + + int xDirection = xDiff == 0 ? 0 : xDiff > 0 ? 1 : -1; + int zDirection = zDiff == 0 ? 0 : zDiff > 0 ? 1 : -1; + + while (true) { + Random random = new Random(); + crackPos += random.nextInt(MIN_CRACK_DISTANCE, MAX_CRACK_DISTANCE + 1); + + int nextX = crackPos * xDirection; + int nextZ = crackPos * zDirection; + int crackLength = CRACK_FORMAT[0].length(); + if (nextX + crackLength * xDirection > xAbsDiff || nextZ + crackLength * zDirection > zAbsDiff) { + crackPos = 0; + break; + } + + PrisonEscapeLocation crackLoc = new PrisonEscapeLocation(corner1).add(nextX, 0, nextZ); + putCrack(crackLoc, CRACK_FORMAT, xDirection, zDirection); + crackPos += crackLength; + } + } + } + + private void putCrack(PrisonEscapeLocation crackLocation, String[] crackFormat, int xDirection, int zDirection) { + int crackLength = crackFormat[0].length(); + int crackHeight = crackFormat.length; + + for (int l = 0; l < crackLength; l++) { + for (int h = 0; h < crackHeight; h++) { + if (crackFormat[crackHeight - 1 - h].charAt(l) == CRACK_CHAR) { + BukkitWorldEditor.putCrackOnWall(crackLocation.add(xDirection * l, h, zDirection * l)); + } + } + } + } + +} diff --git a/src/main/java/net/tiagofar78/prisonescape/managers/ConfigManager.java b/src/main/java/net/tiagofar78/prisonescape/managers/ConfigManager.java index 7fb82993..db9853d2 100644 --- a/src/main/java/net/tiagofar78/prisonescape/managers/ConfigManager.java +++ b/src/main/java/net/tiagofar78/prisonescape/managers/ConfigManager.java @@ -56,6 +56,7 @@ public static ConfigManager getInstance() { private Hashtable _policeSecretPassageLocations; private List _vaultsLocations; private List _chestsLocations; + private List _wallCornersLocations; private Hashtable> _regionsChestContents; @@ -102,6 +103,7 @@ public ConfigManager() { _policeSecretPassageLocations = createLocationsMap(config, "PoliceSecretPassagesLocation"); _vaultsLocations = createLocationList(config, "VaultsLocations"); _chestsLocations = createLocationList(config, "ChestsLocations"); + _wallCornersLocations = createLocationList(config, "WallCorners"); _regionsChestContents = createRegionsChestContentsMap(config); @@ -344,6 +346,10 @@ public List getChestsLocations() { return createLocationsListCopy(_chestsLocations); } + public List getWallCornersLocations() { + return createLocationsListCopy(_wallCornersLocations); + } + public List getChestContents(String regionName) { if (!_regionsChestContents.containsKey(regionName)) { return null; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d49952e8..d5e8daee 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -101,6 +101,11 @@ ChestsContents: RegionName: Item1Name: 0.25 Item2Name: 0.05 +WallCorners: + "1": + X: 0 + Y: 0 + Z: 0 CommonItemsProbability: 0.8 RareItemsProbability: 0.25 ChestSize: 5