From be6329b95735afc59246e445fbba429e870845a9 Mon Sep 17 00:00:00 2001 From: Mathieu Strypsteen Date: Sun, 22 Sep 2024 22:56:22 +0200 Subject: [PATCH] Add lightning event --- .../gent/zeus/mc13dtl/events/EventRunner.java | 5 +- .../mc13dtl/events/catalog/FallEvent.java | 5 +- .../events/catalog/LightningEvent.java | 80 +++++++++++++++++++ .../events/catalog/RunToSpawnEvent.java | 6 +- 4 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 src/main/java/gent/zeus/mc13dtl/events/catalog/LightningEvent.java diff --git a/src/main/java/gent/zeus/mc13dtl/events/EventRunner.java b/src/main/java/gent/zeus/mc13dtl/events/EventRunner.java index 56fdd12..8370115 100644 --- a/src/main/java/gent/zeus/mc13dtl/events/EventRunner.java +++ b/src/main/java/gent/zeus/mc13dtl/events/EventRunner.java @@ -15,7 +15,7 @@ import gent.zeus.mc13dtl.MC13DTL; public class EventRunner implements Runnable { static List currentEvents = new ArrayList<>(); - public static List startTimes = List.of(5000, 13000, 1000, 1000, 13000, 100, 1000, 500, 10000, 5000, 13000, 100); + public static List startTimes = List.of(5000, 13000, 1000, 1000, 13000, 100, 1000, 500, 10000, 5000, 13000, 13000, 100); private long day; @@ -51,7 +51,8 @@ public class EventRunner implements Runnable { case 8 -> new KillSurvivingTeamEvent(team, difficulty, getDayScore()); case 9 -> new KillMobs2Event(team, difficulty, getDayScore()); case 10 -> new RunToSpawnEvent(team, difficulty, getDayScore()); - case 11 -> new EndEvent(team, difficulty, getDayScore()); // TODO: Move to last day + case 11 -> new LightningEvent(team, difficulty, getDayScore()); + case 12 -> new EndEvent(team, difficulty, getDayScore()); default -> throw new IllegalStateException("Unexpected day: " + (int) day); }; event.start(); diff --git a/src/main/java/gent/zeus/mc13dtl/events/catalog/FallEvent.java b/src/main/java/gent/zeus/mc13dtl/events/catalog/FallEvent.java index ac2ee40..1bf944c 100644 --- a/src/main/java/gent/zeus/mc13dtl/events/catalog/FallEvent.java +++ b/src/main/java/gent/zeus/mc13dtl/events/catalog/FallEvent.java @@ -36,10 +36,7 @@ public class FallEvent extends Event { Player player = MC13DTL.board.getPlayers(team).getFirst(); Location location = player.getLocation(); World world = player.getWorld(); - location.setY(300); - while (location.y() > 50 && world.getBlockAt(location).getType() == Material.AIR) { - location.setY(location.getY() - 1); - } + location.setY(world.getHighestBlockYAt(location)); targetHeight = (int) location.getY() + 5; int blocksToIncrease = extraHeight; while (location.y() < 315 && blocksToIncrease > 0) { diff --git a/src/main/java/gent/zeus/mc13dtl/events/catalog/LightningEvent.java b/src/main/java/gent/zeus/mc13dtl/events/catalog/LightningEvent.java new file mode 100644 index 0000000..12e5337 --- /dev/null +++ b/src/main/java/gent/zeus/mc13dtl/events/catalog/LightningEvent.java @@ -0,0 +1,80 @@ +package gent.zeus.mc13dtl.events.catalog; + +import gent.zeus.mc13dtl.MC13DTL; +import gent.zeus.mc13dtl.events.Difficulty; +import gent.zeus.mc13dtl.events.Event; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scoreboard.Team; +import java.util.Random; + +public class LightningEvent extends Event { + + private int timeBetweenStrikes; + private int timeCount; + private final Random ran = new Random(); + + public LightningEvent(Team team, Difficulty difficulty, int scoreOnSuccess) { + super(team, difficulty, scoreOnSuccess); + timeBetweenStrikes = switch (difficulty) { + case BABY -> 20; + case EASY -> 10; + case MEDIUM -> 5; + case HARD -> 3; + case SWEAT -> 2; + case IMPOSSIBLE -> 1; + }; + timeCount = timeBetweenStrikes; + } + + @Override + public void run() { + if (MC13DTL.board.getPlayers(team).size() == 0) { + return; + } + World world = Bukkit.getWorld("world"); + world.setThundering(true); + timeCount--; + if (timeCount == 0) { + timeCount = timeBetweenStrikes; + Player player = MC13DTL.board.getPlayers(team).get(ran.nextInt(MC13DTL.board.getPlayers(team).size())); + Location location = player.getLocation(); + Location lightningPos = new Location(world, ran.nextInt(-20, 20) + location.x(), + location.y(), + ran.nextInt(-20, 20) + location.z()); + lightningPos.setY(world.getHighestBlockYAt(lightningPos)); + world.strikeLightning(lightningPos); + EntityType mob = switch (ran.nextInt(6)) { + case 0 -> EntityType.ZOMBIE; + case 1 -> EntityType.SKELETON; + case 2 -> EntityType.ENDERMAN; + case 3 -> EntityType.SPIDER; + case 4 -> EntityType.CAVE_SPIDER; + case 5 -> EntityType.CREEPER; + default -> EntityType.ZOMBIE; + }; + world.spawnEntity(lightningPos, mob); + } + for (Player i : MC13DTL.board.getPlayers(team)) { + Location pos = i.getLocation(); + int highest = pos.getWorld().getHighestBlockYAt(pos); + if (highest > pos.getY()) { + i.sendMessage(Component.text("Stop hiding!").color(NamedTextColor.RED)); + i.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 40, 0)); + } + } + } + + @Override + protected String getMessage() { + return "Survive the night while staying outdoors (you need to have direct sky light above you at all times)"; + } +} diff --git a/src/main/java/gent/zeus/mc13dtl/events/catalog/RunToSpawnEvent.java b/src/main/java/gent/zeus/mc13dtl/events/catalog/RunToSpawnEvent.java index 04a215f..655e4f7 100644 --- a/src/main/java/gent/zeus/mc13dtl/events/catalog/RunToSpawnEvent.java +++ b/src/main/java/gent/zeus/mc13dtl/events/catalog/RunToSpawnEvent.java @@ -69,13 +69,11 @@ public class RunToSpawnEvent extends Event { } else { teamSpawnReached = false; double p = Math.max(0.2, (maxDistanceSquared - location.distanceSquared(spawn)) / maxDistanceSquared); - double zombies = player.getNearbyEntities(maxZombieDistance / 2.0, maxZombieDistance / 2.0, maxZombieDistance / 2.0).stream().filter(e -> e.getType().equals(EntityType.ZOMBIE)).count(); - System.out.println(zombies); + double zombies = player.getNearbyEntities(maxZombieDistance / 2.0, maxZombieDistance / 2.0, maxZombieDistance / 2.0).stream().filter(e -> e.getType().equals(EntityType.ZOMBIE)).count(); for (int i = 0; i < p * maxRate - zombies; i++) { Location zombieLocation = new Location(world, ran.nextInt(-maxZombieDistance, maxZombieDistance) + location.x(), location.y() + 5, - ran.nextInt(-maxZombieDistance, maxZombieDistance) + location.z() - ); + ran.nextInt(-maxZombieDistance, maxZombieDistance) + location.z()); world.spawnEntity(zombieLocation, EntityType.ZOMBIE); } }