3 Commits

3 changed files with 33 additions and 43 deletions

View File

@@ -28,8 +28,7 @@ public class StickFightFactory implements GameFactory {
@Override @Override
public ConfigManager configuration() { public ConfigManager configuration() {
return new ConfigManager() return new ConfigManager()
.addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 7, 10, 13, 16, 19)) .addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 7, 10, 13, 16, 19));
.addOption(new NumericOption("seconds", Material.CLOCK, TranslatedComponent.byId("optionCommon#seconds"), 30, 60, 90, 120));
} }
@Override @Override
@@ -41,7 +40,7 @@ public class StickFightFactory implements GameFactory {
@Override @Override
public Game manufacture(Room parent, Map<String, Option<?>> configuration) { public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
return new Stickfight(configuration.get("length").getAsInt(), configuration.get("seconds").getAsInt()).setParent(parent); return new Stickfight(configuration.get("length").getAsInt()).setParent(parent);
} }
@Override @Override

View File

@@ -24,12 +24,10 @@ public class Stickfight extends StatelessGame {
private final WeakHashMap<Player, Pos> spawnPoints = new WeakHashMap<>(); private final WeakHashMap<Player, Pos> spawnPoints = new WeakHashMap<>();
private final Map<Player, Integer> scoreMap = new WeakHashMap<>(); private final Map<Player, Integer> scoreMap = new WeakHashMap<>();
private boolean countdownStarted = false; private boolean countdownStarted = false;
private final int seconds;
public Stickfight(int length, int seconds) { public Stickfight(int length) {
super(Dimension.OVERWORLD.key, "Stickfight", new LowestPointsWinScore()); super(Dimension.OVERWORLD.key, "Stickfight", new LowestPointsWinScore());
this.radius = length; this.radius = length;
this.seconds = seconds;
this.eventNode().addChild( this.eventNode().addChild(
CombatFeatures.empty() CombatFeatures.empty()
@@ -90,11 +88,6 @@ public class Stickfight extends StatelessGame {
super.start(); super.start();
} }
@Override
protected void onStart() {
this.setTimeLimit(this.seconds);
}
@Override @Override
protected void onStop() { protected void onStop() {
this.scoreMap.forEach((player, score) -> this.getScore().insertResult(player, score)); this.scoreMap.forEach((player, score) -> this.getScore().insertResult(player, score));

View File

@@ -6,18 +6,20 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetri
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetromino; import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.game.Tetromino;
import eu.mhsl.minenet.minigames.score.PointsWinScore; import eu.mhsl.minenet.minigames.score.PointsWinScore;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Pos; import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.Entity; import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.GameMode; import net.minestom.server.entity.GameMode;
import net.minestom.server.entity.Player; import net.minestom.server.entity.Player;
import net.minestom.server.entity.metadata.display.BlockDisplayMeta;
import net.minestom.server.event.player.PlayerHandAnimationEvent; import net.minestom.server.event.player.PlayerHandAnimationEvent;
import net.minestom.server.event.player.PlayerMoveEvent;
import net.minestom.server.event.player.PlayerTickEvent; import net.minestom.server.event.player.PlayerTickEvent;
import net.minestom.server.event.player.PlayerUseItemEvent; import net.minestom.server.event.player.PlayerUseItemEvent;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.ItemStack; import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material; import net.minestom.server.item.Material;
import net.minestom.server.potion.Potion; import net.minestom.server.timer.TaskSchedule;
import net.minestom.server.potion.PotionEffect;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Map; import java.util.Map;
@@ -78,18 +80,24 @@ class Tetris extends StatelessGame {
p.setGameMode(GameMode.SURVIVAL); p.setGameMode(GameMode.SURVIVAL);
} }
@Override private void onPlayerInteract(@NotNull PlayerUseItemEvent event) {
protected void onPlayerMove(@NotNull PlayerMoveEvent event) { event.setItemUseTime(0);
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseRight);
}
private void onPlayerAttack(@NotNull PlayerHandAnimationEvent event) {
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseLeft);
}
private void onPlayerTick(PlayerTickEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Pos currentPosition = event.getNewPosition();
TetrisGame tetrisGame = this.tetrisGames.get(player); TetrisGame tetrisGame = this.tetrisGames.get(player);
if(tetrisGame == null) return;
if(tetrisGame == null) { if(tetrisGame.lost) {
event.setCancelled(true); this.letPlayerLoose(player);
return; return;
} }
if(tetrisGame.lost) return;
if(player.getGameMode() == GameMode.SPECTATOR) return; if(player.getGameMode() == GameMode.SPECTATOR) return;
if(player.inputs().forward()) tetrisGame.pressedButton(TetrisGame.Button.W); if(player.inputs().forward()) tetrisGame.pressedButton(TetrisGame.Button.W);
@@ -97,26 +105,6 @@ class Tetris extends StatelessGame {
if(player.inputs().right()) tetrisGame.pressedButton(TetrisGame.Button.D); if(player.inputs().right()) tetrisGame.pressedButton(TetrisGame.Button.D);
if(player.inputs().left()) tetrisGame.pressedButton(TetrisGame.Button.A); if(player.inputs().left()) tetrisGame.pressedButton(TetrisGame.Button.A);
if(player.inputs().jump()) tetrisGame.pressedButton(TetrisGame.Button.space); if(player.inputs().jump()) tetrisGame.pressedButton(TetrisGame.Button.space);
event.setNewPosition(tetrisGame.getPlayerSpawnPosition().withView(currentPosition));
player.setSprinting(false);
}
protected void onPlayerInteract(@NotNull PlayerUseItemEvent event) {
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseRight);
}
protected void onPlayerAttack(@NotNull PlayerHandAnimationEvent event) {
this.tetrisGames.get(event.getPlayer()).pressedButton(TetrisGame.Button.mouseLeft);
}
protected void onPlayerTick(PlayerTickEvent event) {
Player player = event.getPlayer();
TetrisGame tetrisGame = this.tetrisGames.get(player);
if(tetrisGame == null) return;
if(tetrisGame.lost && player.getGameMode() != GameMode.SPECTATOR) {
this.letPlayerLoose(player);
}
} }
private void letPlayerLoose(Player player) { private void letPlayerLoose(Player player) {
@@ -124,6 +112,7 @@ class Tetris extends StatelessGame {
if(!this.getScore().hasResult(player)) { if(!this.getScore().hasResult(player)) {
player.setGameMode(GameMode.SPECTATOR); player.setGameMode(GameMode.SPECTATOR);
player.setInvisible(true); player.setInvisible(true);
if(player.getVehicle() != null) player.getVehicle().removePassenger(player);
this.getScore().insertResult(player, tetrisGame.getScore()); this.getScore().insertResult(player, tetrisGame.getScore());
} }
@@ -160,7 +149,16 @@ class Tetris extends StatelessGame {
p.teleport(tetrisGame.getPlayerSpawnPosition()); p.teleport(tetrisGame.getPlayerSpawnPosition());
tetrisGame.sidebar.addViewer(p); tetrisGame.sidebar.addViewer(p);
p.addEffect(new Potion(PotionEffect.SLOWNESS, 4, Potion.INFINITE_DURATION));
MinecraftServer.getSchedulerManager().scheduleTask(() -> {
Entity ghostBlock = new Entity(EntityType.BLOCK_DISPLAY);
((BlockDisplayMeta) ghostBlock.getEntityMeta()).setBlockState(Block.AIR);
ghostBlock.setNoGravity(true);
ghostBlock.setInstance(this, tetrisGame.getPlayerSpawnPosition());
ghostBlock.addPassenger(p);
return TaskSchedule.stop();
}, TaskSchedule.nextTick());
return super.onPlayerJoin(p); return super.onPlayerJoin(p);
} }