-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53a5b6c
commit 9bac576
Showing
5 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Wall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PrisonEscapeLocation> _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)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters