added game length for anvil run
This commit is contained in:
parent
c9ef7197cc
commit
350cf108dd
@ -12,7 +12,6 @@ import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.entity.EntityTickEvent;
|
||||
import net.minestom.server.event.item.ItemDropEvent;
|
||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
||||
import net.minestom.server.event.player.PlayerBlockPlaceEvent;
|
||||
@ -49,8 +48,7 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
||||
.addListener(PlayerMoveEvent.class, this::onPlayerMove)
|
||||
.addListener(PlayerBlockBreakEvent.class, this::onBlockBreak)
|
||||
.addListener(PlayerBlockPlaceEvent.class, this::onBlockPlace)
|
||||
.addListener(ItemDropEvent.class, this::onItemDrop)
|
||||
.addListener(EntityTickEvent.class, this::onEntityTick);
|
||||
.addListener(ItemDropEvent.class, this::onItemDrop);
|
||||
}
|
||||
|
||||
public Game setParent(Room parentRoom) {
|
||||
@ -120,11 +118,6 @@ public abstract class Game extends MineNetInstance implements Spawnable {
|
||||
protected void onStop() {}
|
||||
protected void onUnload() {}
|
||||
|
||||
|
||||
protected void onEntityTick(@NotNull EntityTickEvent entityTickEvent) {
|
||||
|
||||
}
|
||||
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import net.minestom.server.timer.TaskSchedule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@ -26,14 +27,18 @@ class AnvilRun extends StatelessGame {
|
||||
|
||||
final int spawnHeight = 30;
|
||||
final int radius;
|
||||
final int speed;
|
||||
int anvilsPerSecond;
|
||||
final int seconds;
|
||||
final int anvilHeight = 200;
|
||||
final List<Pos> anvilSpawnPositions = new ArrayList<>();
|
||||
|
||||
public AnvilRun(int radius, int speed) {
|
||||
super(Dimension.THE_END.key, "Anvil Run", new LastWinsScore());
|
||||
public AnvilRun(int radius, int seconds) {
|
||||
super(Dimension.OVERWORLD.key, "Anvil Run", new LastWinsScore());
|
||||
this.radius = radius;
|
||||
this.speed = speed;
|
||||
this.seconds = seconds;
|
||||
this.setGenerator(new CircularPlateTerrainGenerator(radius));
|
||||
|
||||
eventNode().addListener(EntityTickEvent.class, this::onEntityTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,14 +49,15 @@ class AnvilRun extends StatelessGame {
|
||||
for (int z = -radius; z <= radius; z++) {
|
||||
if(new Pos(x, 0, z).distance(new Pos(0, 0, 0)) > radius) continue;
|
||||
|
||||
int height = super.rnd.nextInt(100, 500);
|
||||
|
||||
anvilSpawnPositions.add(new Pos(x+0.5, height, z+0.5));
|
||||
anvilSpawnPositions.add(new Pos(x+0.5, anvilHeight, z+0.5));
|
||||
|
||||
batch.setBlock(x, spawnHeight-1, z, Block.SNOW_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
this.anvilsPerSecond = anvilSpawnPositions.size() / this.seconds;
|
||||
Collections.shuffle(anvilSpawnPositions);
|
||||
|
||||
BatchUtil.loadAndApplyBatch(batch, this, () -> callback.complete(null));
|
||||
}
|
||||
|
||||
@ -66,14 +72,16 @@ class AnvilRun extends StatelessGame {
|
||||
super.onStart();
|
||||
|
||||
Scheduler scheduler = MinecraftServer.getSchedulerManager();
|
||||
scheduler.submitTask(() -> {
|
||||
if(anvilSpawnPositions.isEmpty()) return TaskSchedule.stop();
|
||||
for(int i = 0; i < speed; i++) {
|
||||
Pos position = anvilSpawnPositions.remove(super.rnd.nextInt(0, anvilSpawnPositions.size()-1));
|
||||
spawnAnvil(position);
|
||||
}
|
||||
return TaskSchedule.seconds(1);
|
||||
});
|
||||
for(int i=0; i<this.anvilSpawnPositions.size(); i++) {
|
||||
final int j = i;
|
||||
scheduler.scheduleTask(
|
||||
() -> spawnAnvil(this.anvilSpawnPositions.get(j)),
|
||||
TaskSchedule.millis(
|
||||
(long) Math.floor((double) i/this.anvilsPerSecond * 1000)
|
||||
),
|
||||
TaskSchedule.stop()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -87,11 +95,11 @@ class AnvilRun extends StatelessGame {
|
||||
if(playerMoveEvent.getNewPosition().y() < spawnHeight - 2) getScore().insertResult(playerMoveEvent.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEntityTick(@NotNull EntityTickEvent entityTickEvent) {
|
||||
if(!entityTickEvent.getEntity().getEntityType().equals(EntityType.FALLING_BLOCK)) return;
|
||||
Pos anvilPosition = entityTickEvent.getEntity().getPosition();
|
||||
if(anvilPosition.y() > spawnHeight + 0.5) return;
|
||||
if(anvilPosition.y() < spawnHeight - 3) entityTickEvent.getEntity().remove();
|
||||
if(this.getBlock(anvilPosition.withY(spawnHeight-1)).isAir()) return;
|
||||
this.setBlock(anvilPosition.withY(spawnHeight-1), Block.AIR);
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ public class AnvilRunFactory implements GameFactory {
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 5, 10, 15, 20, 25, 30))
|
||||
.addOption(new NumericOption("speed", Material.STICK, TranslatedComponent.byId("game_Deathcube#speed"), 10, 25, 50, 100, 250, 500));
|
||||
.addOption(new NumericOption("seconds", Material.STICK, TranslatedComponent.byId("game_Deathcube#seconds"), 10, 30, 60, 90, 120));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new AnvilRun(configuration.get("radius").getAsInt(), configuration.get("speed").getAsInt()).setParent(parent);
|
||||
return new AnvilRun(configuration.get("radius").getAsInt(), configuration.get("seconds").getAsInt()).setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user