Refactored Score system

This commit is contained in:
2023-09-30 21:58:08 +02:00
parent 4fc8503d63
commit eecdeff77c
33 changed files with 248 additions and 103 deletions

View File

@@ -101,7 +101,7 @@ public abstract class Game extends MineNetInstance implements Spawnable {
}, TaskSchedule.seconds(10), TaskSchedule.stop());
}
protected void onLoad(CompletableFuture<Void> callback) {
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
callback.complete(null);
}
@@ -133,7 +133,7 @@ public abstract class Game extends MineNetInstance implements Spawnable {
protected void checkAbandoned() {
scheduleNextTick((instance) -> {
if(instance.getPlayers().size() == 0) this.unload();
if(instance.getPlayers().isEmpty()) this.unload();
});
}

View File

@@ -18,14 +18,14 @@ import java.util.concurrent.CompletableFuture;
public class StatelessGame extends Game {
private final String name;
private final Score score = new Score(this);
private Score score;
private int timeLimit = 0;
private int timePlayed = 0;
private final boolean preventExit = false;
public StatelessGame(DimensionType dimensionType, String gameName) {
public StatelessGame(DimensionType dimensionType, String gameName, Score score) {
super(dimensionType);
this.score = score;
this.name = gameName;
}
@@ -61,6 +61,9 @@ public class StatelessGame extends Game {
@Override
protected void start() {
score.setInstance(this);
score.attachListeners();
countdownStart().thenRun(() -> {
super.start();

View File

@@ -2,13 +2,19 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.backrooms;
import eu.mhsl.minenet.minigames.instance.Dimension;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import eu.mhsl.minenet.minigames.score.NoScore;
import net.minestom.server.event.player.PlayerBlockBreakEvent;
import org.jetbrains.annotations.NotNull;
public class Backrooms extends StatelessGame {
public Backrooms() {
super(Dimension.NETHER.DIMENSION, "Backrooms");
super(Dimension.NETHER.DIMENSION, "Backrooms", new NoScore());
BackroomsGenerator generator = new BackroomsGenerator();
setGenerator(unit -> generator.generateRoom(unit, 50));
}
@Override
protected void onBlockBreak(@NotNull PlayerBlockBreakEvent playerBlockBreakEvent) {
playerBlockBreakEvent.setCancelled(false);
}
}

View File

@@ -5,6 +5,7 @@ import eu.mhsl.minenet.minigames.instance.Dimension;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import eu.mhsl.minenet.minigames.instance.game.stateless.types.bedwars.data.BedwarsTeam;
import eu.mhsl.minenet.minigames.message.type.ActionBarMessage;
import eu.mhsl.minenet.minigames.score.LastWinsScore;
import eu.mhsl.minenet.minigames.util.MaterialUtil;
import eu.mhsl.minenet.minigames.util.Position;
import net.kyori.adventure.text.Component;
@@ -37,7 +38,7 @@ public class Bedwars extends StatelessGame {
public Bedwars() throws IOException {
super(Dimension.OVERWORLD.DIMENSION, "Bedwars");
super(Dimension.OVERWORLD.DIMENSION, "Bedwars", new LastWinsScore());
setChunkLoader(new AnvilLoader(Resource.GAME_MAP.getPath().resolve("bedwars/test")));
Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(Resource.GAME_MAP.getPath().resolve("bedwars/test/config.yml").toFile());

View File

@@ -1,6 +1,7 @@
package eu.mhsl.minenet.minigames.instance.game.stateless.types.deathcube;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
import eu.mhsl.minenet.minigames.util.BatchUtil;
import eu.mhsl.minenet.minigames.instance.Dimension;
import eu.mhsl.minenet.minigames.world.generator.BlockPallet;
@@ -22,7 +23,7 @@ class Deathcube extends StatelessGame {
final int percentage;
public Deathcube(int radius, int height, int percentage, int pvpEnabled) {
super(Dimension.THE_END.DIMENSION, "Deathcube");
super(Dimension.THE_END.DIMENSION, "Deathcube", new FirstWinsScore());
this.radius = radius;
this.height = height + 49;
this.percentage = percentage;
@@ -38,7 +39,7 @@ class Deathcube extends StatelessGame {
}
@Override
protected void onLoad(CompletableFuture<Void> callback) {
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
for(int x = -radius; x <= radius; x++) {

View File

@@ -2,6 +2,7 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import eu.mhsl.minenet.minigames.message.type.ActionBarMessage;
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
import eu.mhsl.minenet.minigames.util.BatchUtil;
import eu.mhsl.minenet.minigames.util.Intersect;
import eu.mhsl.minenet.minigames.instance.Dimension;
@@ -24,16 +25,16 @@ import java.util.concurrent.CompletableFuture;
class Minerun extends StatelessGame {
private int minePercentage = 50;
private int width = 100;
private int length = 50;
private int minePercentage;
private int width;
private int length;
private final int preRun = 5;
private final int afterMines = 2;
private final int afterFinishLine = 10;
public Minerun(int width, int length, int minePercentage) {
super(Dimension.THE_END.DIMENSION, "Minerun");
super(Dimension.THE_END.DIMENSION, "Minerun", new FirstWinsScore());
setGenerator(new SquareTerrainGenerator(width, length + preRun + afterFinishLine, true));
this.width = width;
@@ -42,7 +43,7 @@ class Minerun extends StatelessGame {
}
@Override
protected void onLoad(CompletableFuture<Void> callback) {
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
int spawnToFinishLine = preRun + length + afterMines;
Random random = new Random();
@@ -97,9 +98,9 @@ class Minerun extends StatelessGame {
playerMoveEvent.setCancelled(true);
}
if(getScore().hasResult(p) && middle.z() < preRun + length + afterMines) { // player cannot go back
playerMoveEvent.setCancelled(true);
new ActionBarMessage().appendStatic(Component.text("You cannot go back on the Field!", NamedTextColor.RED)).send(p);
if(middle.z() < preRun + length + afterMines) { // player cannot go back
// playerMoveEvent.setCancelled(true);
// new ActionBarMessage().appendStatic(Component.text("You cannot go back on the Field!", NamedTextColor.RED)).send(p);
return;
}

View File

@@ -2,6 +2,7 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight;
import eu.mhsl.minenet.minigames.instance.Dimension;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import eu.mhsl.minenet.minigames.score.LastWinsScore;
import eu.mhsl.minenet.minigames.util.BatchUtil;
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularTerrainGenerator;
import io.github.bloepiloepi.pvp.config.*;
@@ -17,7 +18,7 @@ import java.util.concurrent.CompletableFuture;
public class Stickfight extends StatelessGame {
public Stickfight() {
super(Dimension.OVERWORLD.DIMENSION, "Stickfight");
super(Dimension.OVERWORLD.DIMENSION, "Stickfight", new LastWinsScore());
eventNode().addChild(
PvPConfig.emptyBuilder()
@@ -35,7 +36,7 @@ public class Stickfight extends StatelessGame {
}
@Override
protected void onLoad(CompletableFuture<Void> callback) {
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
for (int z = -10; z <= 10; z++) {
batch.setBlock(0, 50, z, Block.SANDSTONE);

View File

@@ -3,13 +3,14 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense;
import eu.mhsl.minenet.minigames.instance.Dimension;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.generator.MazeGenerator;
import eu.mhsl.minenet.minigames.score.NoScore;
import net.minestom.server.entity.Player;
import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material;
public class Towerdefense extends StatelessGame {
public Towerdefense() {
super(Dimension.NETHER.DIMENSION, "Towerdefense");
super(Dimension.NETHER.DIMENSION, "Towerdefense", new NoScore());
setGenerator(new MazeGenerator());
}

View File

@@ -1,6 +1,7 @@
package eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace;
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
import eu.mhsl.minenet.minigames.util.BatchUtil;
import eu.mhsl.minenet.minigames.instance.Dimension;
import net.minestom.server.coordinate.Vec;
@@ -18,11 +19,11 @@ class TrafficLightRace extends StatelessGame {
private int phaseCounter = 1;
public TrafficLightRace() {
super(Dimension.THE_END.DIMENSION, "Ampelrennen");
super(Dimension.THE_END.DIMENSION, "Ampelrennen", new FirstWinsScore());
}
@Override
protected void onLoad(CompletableFuture<Void> callback) {
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
AbsoluteBlockBatch batch = new AbsoluteBlockBatch();
for (int x = -10; x <= 10; x++) {
for (int z = 5; z <= 100; z++) {

View File

@@ -13,13 +13,11 @@ import eu.mhsl.minenet.minigames.instance.hub.Hub;
import eu.mhsl.minenet.minigames.instance.room.entity.GameSelector;
import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.GameMode;
import net.minestom.server.entity.Player;
import net.minestom.server.event.player.PlayerBlockBreakEvent;
import net.minestom.server.event.player.PlayerDisconnectEvent;
import net.minestom.server.instance.AnvilLoader;
import team.unnamed.hephaestus.ModelDataCursor;
import team.unnamed.hephaestus.reader.ModelReader;
import team.unnamed.hephaestus.reader.blockbench.BBModelReader;
import java.util.*;
import java.util.logging.Logger;
@@ -55,6 +53,7 @@ public class Room extends MineNetInstance implements Spawnable {
p.clearEffects();
p.clearTitle();
p.getInventory().clear();
p.setGameMode(GameMode.ADVENTURE);
rooms.put(p, room);
MoveInstance.move(p, room);
}