Finalized ColorJump #13
@@ -52,7 +52,7 @@ public enum GameList {
|
|||||||
BOATRACE(new BoatRaceFactory(), GameType.OTHER),
|
BOATRACE(new BoatRaceFactory(), GameType.OTHER),
|
||||||
PILLARS(new PillarsFactory(), GameType.PROTOTYPE),
|
PILLARS(new PillarsFactory(), GameType.PROTOTYPE),
|
||||||
BLOCKBATTLE(new BlockBattleFactory(), GameType.PVP),
|
BLOCKBATTLE(new BlockBattleFactory(), GameType.PVP),
|
||||||
COLORJUMP(new ColorJumpFactory(), GameType.PROTOTYPE);
|
COLORJUMP(new ColorJumpFactory(), GameType.JUMPNRUN);
|
||||||
|
|
||||||
private final GameFactory factory;
|
private final GameFactory factory;
|
||||||
private final GameType type;
|
private final GameType type;
|
||||||
|
|||||||
+47
-12
@@ -8,10 +8,13 @@ import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGen
|
|||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.entity.GameMode;
|
import net.minestom.server.entity.GameMode;
|
||||||
|
import net.minestom.server.event.inventory.InventoryPreClickEvent;
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||||
|
import net.minestom.server.event.player.PlayerSwapItemEvent;
|
||||||
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
import net.minestom.server.instance.batch.AbsoluteBlockBatch;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
|
import net.minestom.server.timer.Scheduler;
|
||||||
import net.minestom.server.timer.TaskSchedule;
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -32,13 +35,25 @@ public class ColorJump extends StatelessGame {
|
|||||||
Block.PINK_CONCRETE
|
Block.PINK_CONCRETE
|
||||||
);
|
);
|
||||||
private Block currentBlock;
|
private Block currentBlock;
|
||||||
|
private Block blockLastRound;
|
||||||
private double roundTime = 5;
|
private double roundTime = 5;
|
||||||
|
private final double multiplierNextRoundTime = 0.9;
|
||||||
|
|
||||||
public ColorJump() {
|
public ColorJump() {
|
||||||
super(Dimension.THE_END.key, "ColorJump", new LastWinsScore());
|
super(Dimension.THE_END.key, "ColorJump", new LastWinsScore());
|
||||||
this.getScore().setIgnoreLastPlayers(1);
|
this.getScore().setIgnoreLastPlayers(1);
|
||||||
|
|
||||||
this.setGenerator(new CircularPlateTerrainGenerator(100));
|
this.setGenerator(new CircularPlateTerrainGenerator(100));
|
||||||
|
|
||||||
|
this.eventNode().addListener(
|
||||||
|
InventoryPreClickEvent.class,
|
||||||
|
inventoryPreClickEvent -> inventoryPreClickEvent.setCancelled(true)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.eventNode().addListener(
|
||||||
|
PlayerSwapItemEvent.class,
|
||||||
|
playerSwapItemEvent -> playerSwapItemEvent.setCancelled(true)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,8 +68,11 @@ public class ColorJump extends StatelessGame {
|
|||||||
|
|
||||||
private void nextRound() {
|
private void nextRound() {
|
||||||
this.generate();
|
this.generate();
|
||||||
|
do {
|
||||||
this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
|
this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
|
||||||
|
} while(this.currentBlock == this.blockLastRound);
|
||||||
|
this.blockLastRound = this.currentBlock;
|
||||||
|
|
||||||
ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material()));
|
ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material()));
|
||||||
this.getPlayers().forEach(player -> {
|
this.getPlayers().forEach(player -> {
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
@@ -67,26 +85,43 @@ public class ColorJump extends StatelessGame {
|
|||||||
TaskSchedule stop = TaskSchedule.stop();
|
TaskSchedule stop = TaskSchedule.stop();
|
||||||
|
|
||||||
scheduler.scheduleTask(() -> {
|
scheduler.scheduleTask(() -> {
|
||||||
|
if(!this.isRunning) return stop;
|
||||||
this.destroyAllExcept(this.currentBlock);
|
this.destroyAllExcept(this.currentBlock);
|
||||||
|
|
||||||
scheduler.scheduleTask(() -> {
|
scheduler.scheduleTask(() -> {
|
||||||
this.nextRound();
|
if(this.isRunning) this.nextRound();
|
||||||
return stop;
|
return stop;
|
||||||
}, TaskSchedule.seconds(3));
|
}, TaskSchedule.seconds(3));
|
||||||
return stop;
|
return stop;
|
||||||
}, TaskSchedule.seconds((long) this.roundTime));
|
}, TaskSchedule.seconds((long) this.roundTime));
|
||||||
if(this.roundTime > 0.5)
|
this.roundTime = this.roundTime * this.multiplierNextRoundTime;
|
||||||
this.roundTime = this.roundTime * 0.9;
|
if(this.roundTime <= 1) this.roundTime = 1;
|
||||||
|
|
||||||
long secondsLeft = Math.max(0, (long) this.roundTime);
|
long totalTicks = (long) (this.roundTime * 20);
|
||||||
|
MineTec marked this conversation as resolved
|
|||||||
|
this.scheduleExpUpdate(scheduler, totalTicks, totalTicks);
|
||||||
for (int i = Math.min(3, (int) secondsLeft); i >= 0; i--) {
|
|
||||||
int level = i;
|
|
||||||
scheduler.scheduleTask(() -> {
|
|
||||||
this.getPlayers().forEach(player -> player.setLevel(level));
|
|
||||||
return stop;
|
|
||||||
}, TaskSchedule.seconds(secondsLeft-i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void scheduleExpUpdate(Scheduler scheduler, long remainingTicks, long totalTicks) {
|
||||||
|
if (!this.isRunning) return;
|
||||||
|
|
||||||
|
if (remainingTicks <= 0) {
|
||||||
|
this.getPlayers().forEach(player -> {
|
||||||
|
player.setExp(0f);
|
||||||
|
player.setLevel(0);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float progress = (float) remainingTicks / totalTicks;
|
||||||
|
|
||||||
|
this.getPlayers().forEach(player -> {
|
||||||
|
player.setExp(progress);
|
||||||
|
player.setLevel((int) Math.ceil(remainingTicks / 20.0));
|
||||||
|
});
|
||||||
|
scheduler.scheduleTask(() -> {
|
||||||
|
this.scheduleExpUpdate(scheduler, remainingTicks -1, totalTicks);
|
||||||
|
return TaskSchedule.stop();
|
||||||
|
}, TaskSchedule.tick(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generate() {
|
private void generate() {
|
||||||
|
|||||||
Reference in New Issue
Block a user
andere Lösung für das effective-final wär schön
passt so?