tower-generator #6
@ -15,11 +15,11 @@ tower:
|
|||||||
doors:
|
doors:
|
||||||
1:
|
1:
|
||||||
x: 138
|
x: 138
|
||||||
y: 229
|
y: 228
|
||||||
z: 858
|
z: 858
|
||||||
2:
|
2:
|
||||||
x: 137
|
x: 137
|
||||||
y: 229
|
y: 228
|
||||||
z: 858
|
z: 858
|
||||||
lavaY: 255
|
lavaY: 255
|
||||||
laveSpace: 7
|
laveSpace: 7
|
||||||
@ -32,7 +32,7 @@ tower:
|
|||||||
minX: 93
|
minX: 93
|
||||||
maxX: 167
|
maxX: 167
|
||||||
minZ: 813
|
minZ: 813
|
||||||
maxZ: 863
|
maxZ: 883
|
||||||
|
|
||||||
winconditions:
|
winconditions:
|
||||||
- LAST_REMAINING
|
- LAST_REMAINING
|
||||||
|
@ -64,6 +64,8 @@ towerGenerator:
|
|||||||
x: 0
|
x: 0
|
||||||
y: 12
|
y: 12
|
||||||
z: 0
|
z: 0
|
||||||
|
minHeight: 200
|
||||||
|
maxHeight: 250
|
||||||
schematicType: steamtower
|
schematicType: steamtower
|
||||||
fillRegions:
|
fillRegions:
|
||||||
1:
|
1:
|
||||||
@ -87,6 +89,44 @@ towerGenerator:
|
|||||||
maxZ: 46
|
maxZ: 46
|
||||||
percentage: 1.0
|
percentage: 1.0
|
||||||
material: MANGROVE_ROOTS
|
material: MANGROVE_ROOTS
|
||||||
|
minNoBombFloors: 2
|
||||||
|
maxNoBombFloors: 7
|
||||||
|
minBombs: 20
|
||||||
|
maxBombs: 60
|
||||||
|
tntChance: 0.3
|
||||||
|
tntRegions:
|
||||||
|
1:
|
||||||
|
minX: 3
|
||||||
|
minZ: 3
|
||||||
|
maxX: 26
|
||||||
|
maxZ: 76
|
||||||
|
2:
|
||||||
|
minX: 43
|
||||||
|
minZ: 3
|
||||||
|
maxX: 66
|
||||||
|
maxZ: 76
|
||||||
|
3:
|
||||||
|
minX: 27
|
||||||
|
minZ: 53
|
||||||
|
maxX: 42
|
||||||
|
maxZ: 76
|
||||||
|
4:
|
||||||
|
minX: 27
|
||||||
|
minZ: 3
|
||||||
|
maxX: 42
|
||||||
|
maxZ: 26
|
||||||
|
keyChance: 0.3
|
||||||
|
minNoKeyFloors: 2
|
||||||
|
maxNoKeyFloors: 7
|
||||||
|
doorBlocks:
|
||||||
|
1:
|
||||||
|
x: 30
|
||||||
|
dy: 1
|
||||||
|
z: 35
|
||||||
|
2:
|
||||||
|
x: 30
|
||||||
|
dy: 1
|
||||||
|
z: 36
|
||||||
|
|
||||||
minX: -28
|
minX: -28
|
||||||
maxX: 98
|
maxX: 98
|
||||||
|
@ -214,13 +214,35 @@ public class WorldConfig {
|
|||||||
public final int x;
|
public final int x;
|
||||||
public final int y;
|
public final int y;
|
||||||
public final int z;
|
public final int z;
|
||||||
|
public final int minHeight;
|
||||||
|
public final int maxHeight;
|
||||||
|
public final int minNoBombFloors;
|
||||||
|
public final int maxNoBombFloors;
|
||||||
|
public final double tntChance;
|
||||||
|
public final int minBombs;
|
||||||
|
public final int maxBombs;
|
||||||
|
public final double keyChance;
|
||||||
|
public final int minNoKeyFloors;
|
||||||
|
public final int maxNoKeyFloors;
|
||||||
public final SchematicType schematicType;
|
public final SchematicType schematicType;
|
||||||
public final TowerGeneratorFillRegion[] fillRegions;
|
public final TowerGeneratorFillRegion[] fillRegions;
|
||||||
|
public final Region[] tntRegions;
|
||||||
|
public final TowerGeneratorDoorBlock[] doorBlocks;
|
||||||
|
|
||||||
public TowerGeneratorConfig(ConfigurationSection section) {
|
public TowerGeneratorConfig(ConfigurationSection section) {
|
||||||
x = section.getInt("x");
|
x = section.getInt("x");
|
||||||
y = section.getInt("y");
|
y = section.getInt("y");
|
||||||
z = section.getInt("z");
|
z = section.getInt("z");
|
||||||
|
minHeight = section.getInt("minHeight");
|
||||||
|
maxHeight = section.getInt("maxHeight");
|
||||||
|
minNoBombFloors = section.getInt("minNoBombFloors");
|
||||||
|
maxNoBombFloors = section.getInt("maxNoBombFloors");
|
||||||
|
minBombs = section.getInt("minBombs");
|
||||||
|
maxBombs = section.getInt("maxBombs");
|
||||||
|
tntChance = section.getDouble("tntChance");
|
||||||
|
keyChance = section.getDouble("keyChance");
|
||||||
|
minNoKeyFloors = section.getInt("minNoKeyFloors");
|
||||||
|
maxNoKeyFloors = section.getInt("maxNoKeyFloors");
|
||||||
schematicType = SchematicType.fromDB(section.getString("schematicType"));
|
schematicType = SchematicType.fromDB(section.getString("schematicType"));
|
||||||
|
|
||||||
ConfigurationSection fillRegionsSection = section.getConfigurationSection("fillRegions");
|
ConfigurationSection fillRegionsSection = section.getConfigurationSection("fillRegions");
|
||||||
@ -236,6 +258,34 @@ public class WorldConfig {
|
|||||||
} else {
|
} else {
|
||||||
fillRegions = new TowerGeneratorFillRegion[0];
|
fillRegions = new TowerGeneratorFillRegion[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigurationSection tntRegionsSection = section.getConfigurationSection("tntRegions");
|
||||||
|
if (tntRegionsSection != null) {
|
||||||
|
List<ConfigurationSection> tntRegions = tntRegionsSection.getKeys(false).stream()
|
||||||
|
.map(tntRegionsSection::getConfigurationSection)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
this.tntRegions = new Region[tntRegions.size()];
|
||||||
|
for (int i = 0; i < tntRegions.size(); i++) {
|
||||||
|
this.tntRegions[i] = new Region(tntRegions.get(i));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tntRegions = new Region[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigurationSection doorBlocksSection = section.getConfigurationSection("doorBlocks");
|
||||||
|
if (doorBlocksSection != null) {
|
||||||
|
List<ConfigurationSection> doorBlocks = doorBlocksSection.getKeys(false).stream()
|
||||||
|
.map(doorBlocksSection::getConfigurationSection)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
this.doorBlocks = new TowerGeneratorDoorBlock[doorBlocks.size()];
|
||||||
|
for (int i = 0; i < doorBlocks.size(); i++) {
|
||||||
|
this.doorBlocks[i] = new TowerGeneratorDoorBlock(doorBlocks.get(i));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
doorBlocks = new TowerGeneratorDoorBlock[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,4 +307,17 @@ public class WorldConfig {
|
|||||||
material = Material.valueOf(section.getString("material"));
|
material = Material.valueOf(section.getString("material"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static final class TowerGeneratorDoorBlock {
|
||||||
|
private final int x;
|
||||||
|
private final int dy;
|
||||||
|
private final int z;
|
||||||
|
|
||||||
|
public TowerGeneratorDoorBlock(ConfigurationSection section) {
|
||||||
|
x = section.getInt("x");
|
||||||
|
dy = section.getInt("dy");
|
||||||
|
z = section.getInt("z");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,18 @@ import de.steamwar.towerrun.game.TowerRunGame;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.*;
|
||||||
|
import org.bukkit.block.data.Bisected;
|
||||||
|
import org.bukkit.block.data.type.Door;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -66,11 +72,14 @@ public class TowerGenerator {
|
|||||||
|
|
||||||
public void generate() {
|
public void generate() {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
int height = random.nextInt(50) + 200;
|
int height = random.nextInt(config.maxHeight - config.minHeight) + config.minHeight;
|
||||||
int y = TowerGenerator.this.config.y;
|
int y = TowerGenerator.this.config.y;
|
||||||
|
int noBombFloors;
|
||||||
|
int noKeyFloors;
|
||||||
|
|
||||||
{
|
{
|
||||||
TowerGenerator.this.height = height;
|
noBombFloors = random.nextInt(config.maxNoBombFloors - config.minNoBombFloors) + config.minNoBombFloors;
|
||||||
|
noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,21 +88,93 @@ public class TowerGenerator {
|
|||||||
SchematicNode schematicNode = allSchematics.get(random.nextInt(allSchematics.size()));
|
SchematicNode schematicNode = allSchematics.get(random.nextInt(allSchematics.size()));
|
||||||
SchematicData schematicData = new SchematicData(schematicNode);
|
SchematicData schematicData = new SchematicData(schematicNode);
|
||||||
int currentY;
|
int currentY;
|
||||||
|
int width;
|
||||||
|
int depth;
|
||||||
try {
|
try {
|
||||||
Clipboard clipboard = schematicData.load();
|
Clipboard clipboard = schematicData.load();
|
||||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||||
ClipboardHolder ch = new ClipboardHolder(clipboard);
|
ClipboardHolder ch = new ClipboardHolder(clipboard);
|
||||||
Operations.completeBlindly(ch.createPaste(e).to(BlockVector3.at(config.x, y, config.z)).build());
|
Operations.completeBlindly(ch.createPaste(e).to(BlockVector3.at(config.x, y, config.z)).build());
|
||||||
}
|
}
|
||||||
|
width = clipboard.getDimensions().getX();
|
||||||
|
depth = clipboard.getDimensions().getZ();
|
||||||
currentY = y;
|
currentY = y;
|
||||||
y += clipboard.getDimensions().getY();
|
y += clipboard.getDimensions().getY();
|
||||||
height -= clipboard.getDimensions().getY();
|
height -= clipboard.getDimensions().getY();
|
||||||
|
TowerGenerator.this.height += clipboard.getDimensions().getY();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
allSchematics.remove(schematicNode);
|
allSchematics.remove(schematicNode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
spawn = WorldConfig.SPAWN.clone().add(0, y, 0);
|
spawn = WorldConfig.SPAWN.clone().add(0, y, 0);
|
||||||
|
|
||||||
|
List<Container> chestBlocks = new ArrayList<>();
|
||||||
|
for (int x = config.x; x < config.x + width; x++) {
|
||||||
|
for (int z = config.z; z < config.z + depth; z++) {
|
||||||
|
for (int y = currentY; y < this.y; y++) {
|
||||||
|
Block block = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
|
||||||
|
BlockState blockState = block.getState();
|
||||||
|
if (blockState instanceof Chest) {
|
||||||
|
chestBlocks.add((Container) blockState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
noBombFloors--;
|
||||||
|
if (noBombFloors < 0 && random.nextDouble() < config.tntChance) {
|
||||||
|
noBombFloors = random.nextInt(config.maxNoBombFloors - config.minNoBombFloors) + config.minNoBombFloors;
|
||||||
|
int bombCount = random.nextInt(config.maxBombs - config.minBombs) + config.minBombs;
|
||||||
|
for (int i = 0; i < bombCount; i++) {
|
||||||
|
WorldConfig.Region region = config.tntRegions[random.nextInt(config.tntRegions.length)];
|
||||||
|
int x = random.nextInt(region.max.getBlockX() - region.min.getBlockX()) + region.min.getBlockX();
|
||||||
|
int z = random.nextInt(region.max.getBlockZ() - region.min.getBlockZ()) + region.min.getBlockZ();
|
||||||
|
int y = currentY + 1;
|
||||||
|
Bukkit.getWorlds().get(0).getBlockAt(x, y, z).setType(Material.TNT, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
noKeyFloors--;
|
||||||
|
if (!chestBlocks.isEmpty() && noKeyFloors < 0 && random.nextDouble() < config.keyChance) {
|
||||||
|
noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors;
|
||||||
|
Inventory inventory = chestBlocks.get(random.nextInt(chestBlocks.size())).getInventory();
|
||||||
|
inventory.addItem(new ItemStack(Material.LEVER, 1));
|
||||||
|
|
||||||
|
for (WorldConfig.TowerGeneratorDoorBlock doorBlock : config.doorBlocks) {
|
||||||
|
int x = doorBlock.getX();
|
||||||
|
int y = currentY + doorBlock.getDy();
|
||||||
|
int z = doorBlock.getZ();
|
||||||
|
Block block = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
if (block.getType().isAir()) {
|
||||||
|
block.setType(Material.IRON_BLOCK, true);
|
||||||
|
block = block.getRelative(0, 1, 0);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> {
|
||||||
|
Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
|
||||||
|
door.setType(Material.IRON_DOOR, true);
|
||||||
|
door = door.getRelative(0, 1, 0);
|
||||||
|
door.setType(Material.IRON_DOOR, true);
|
||||||
|
}, 10);
|
||||||
|
Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> {
|
||||||
|
Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
|
||||||
|
Door doorState = (Door) door.getBlockData();
|
||||||
|
doorState.setFacing(BlockFace.EAST);
|
||||||
|
door.setBlockData(doorState, true);
|
||||||
|
|
||||||
|
door = door.getRelative(0, 1, 0);
|
||||||
|
doorState = (Door) door.getBlockData();
|
||||||
|
doorState.setFacing(BlockFace.EAST);
|
||||||
|
doorState.setHalf(Bisected.Half.TOP);
|
||||||
|
door.setBlockData(doorState, true);
|
||||||
|
}, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (WorldConfig.TowerGeneratorFillRegion fillRegion : config.fillRegions) {
|
for (WorldConfig.TowerGeneratorFillRegion fillRegion : config.fillRegions) {
|
||||||
for (int x = fillRegion.getMinX(); x < fillRegion.getMaxX(); x++) {
|
for (int x = fillRegion.getMinX(); x < fillRegion.getMaxX(); x++) {
|
||||||
for (int z = fillRegion.getMinZ(); z < fillRegion.getMaxZ(); z++) {
|
for (int z = fillRegion.getMinZ(); z < fillRegion.getMaxZ(); z++) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren