diff --git a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/turtleGame/TurtleGame.java b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/turtleGame/TurtleGame.java index 0b7f781..e14476b 100644 --- a/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/turtleGame/TurtleGame.java +++ b/src/main/java/eu/mhsl/minenet/minigames/instance/game/stateless/types/turtleGame/TurtleGame.java @@ -3,7 +3,7 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.turtleGame; import eu.mhsl.minenet.minigames.instance.Dimension; import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame; import eu.mhsl.minenet.minigames.score.PointsWinScore; -import net.kyori.adventure.text.Component; +import net.kyori.adventure.sound.Sound; import net.minestom.server.MinecraftServer; import net.minestom.server.coordinate.Pos; import net.minestom.server.coordinate.Vec; @@ -14,13 +14,16 @@ import net.minestom.server.event.player.PlayerTickEvent; import net.minestom.server.instance.block.Block; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; +import net.minestom.server.network.packet.server.play.ParticlePacket; +import net.minestom.server.particle.Particle; +import net.minestom.server.sound.SoundEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.concurrent.CompletableFuture; -// TODO: Sound Effects, Partikel und Info für Score +// TODO: Info für Score class TurtleGame extends StatelessGame { private final int radius; @@ -28,6 +31,7 @@ class TurtleGame extends StatelessGame { private final Map scoreMap = new WeakHashMap<>(); private final ArrayList snacks = new ArrayList<>(); private final ArrayList bombs = new ArrayList<>(); + private final Block snackBlock = Block.SUNFLOWER.withProperty("half", "upper"); private double speed; private final double maxSpeedIncrease; @@ -72,38 +76,52 @@ class TurtleGame extends StatelessGame { Vec targetDirection = direction.withY(0).normalize().mul(this.speed); turtle.setVelocity(targetDirection); - List hitSnacks = this.snacks.stream() + this.snacks.stream() .filter(snack -> snack.getBoundingBox().intersectBox(turtle.getPosition().sub(snack.getPosition()), turtle.getBoundingBox())) - .toList(); - List hitBombs = this.bombs.stream() + .toList() + .forEach(snack -> { + this.eat(p, snack); + this.generateNewSnack(); + if(this.scoreMap.values().stream().mapToInt(Integer::intValue).sum() % 3 == 0) this.generateNewBomb(); + }); + this.bombs.stream() .filter(bomb -> bomb.getBoundingBox().intersectBox(turtle.getPosition().sub(bomb.getPosition()), turtle.getBoundingBox())) - .toList(); - - hitSnacks.forEach(snack -> { - this.snacks.remove(snack); - snack.remove(); - this.generateNewSnack(); - this.scoreMap.put(p, this.scoreMap.get(p) + 1); - }); - hitBombs.forEach(bomb -> { - p.setGameMode(GameMode.SPECTATOR); - p.setFlying(true); - turtle.removePassenger(p); - turtle.remove(); - turtle.kill(); - this.bombs.remove(bomb); - bomb.remove(); - this.generateNewBomb(2); - this.getScore().insertResult(p, this.scoreMap.get(p)); - this.speed += this.maxSpeedIncrease / this.getPlayers().size(); - }); + .toList() + .forEach(bomb -> { + this.explode(p, bomb); + this.generateNewBomb(2); + this.speed += this.maxSpeedIncrease / this.getPlayers().size(); + }); } } + protected void eat(Player p, Entity snack) { + p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EAT, Sound.Source.MASTER, 1f, 1f), snack.getPosition()); + Material snackMaterial = this.snackBlock.registry().material(); + if(snackMaterial == null) snackMaterial = Material.DIRT; + p.sendPacket(new ParticlePacket(Particle.ITEM.withItem(ItemStack.of(snackMaterial)), p.getPosition(), new Pos(0.5, 0.5, 0.5), 0, 8)); + this.snacks.remove(snack); + snack.remove(); + this.scoreMap.put(p, this.scoreMap.get(p) + 1); + } + + protected void explode(Player p, Entity bomb) { + EntityCreature turtle = this.turtlePlayerMap.get(p); + p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.MASTER, 2f, 1f), bomb.getPosition()); + p.playSound(Sound.sound(SoundEvent.ENTITY_GENERIC_EXPLODE, Sound.Source.MASTER, 2f, 1f), bomb.getPosition()); + p.sendPacket(new ParticlePacket(Particle.EXPLOSION, p.getPosition(), new Pos(0.5, 0.5, 0.5), 0, 8)); + p.setGameMode(GameMode.SPECTATOR); + p.setFlying(true); + turtle.removePassenger(p); + turtle.remove(); + turtle.kill(); + this.getScore().insertResult(p, this.scoreMap.get(p)); + this.bombs.remove(bomb); + bomb.remove(); + } + @Override protected boolean onPlayerJoin(Player p) { - p.getInventory().setItemStack(0, ItemStack.builder(Material.BARRIER).customName(Component.text("Reset Snack")).build()); - if(this.turtlePlayerMap.get(p) == null) { EntityCreature turtle = new EntityCreature(EntityType.TURTLE); this.turtlePlayerMap.put(p, turtle); @@ -147,7 +165,7 @@ class TurtleGame extends StatelessGame { private void generateNewSnack() { Entity snack = new Entity(EntityType.FALLING_BLOCK); FallingBlockMeta meta = (FallingBlockMeta) snack.getEntityMeta(); - meta.setBlock(Block.SUNFLOWER.withProperty("half", "upper")); + meta.setBlock(this.snackBlock.withProperty("half", "upper")); snack.setInstance(this); Pos spawnPosition = this.newSpawnPosition(snack); if(spawnPosition == null) {