Add lightning event

This commit is contained in:
Mathieu Strypsteen 2024-09-22 22:56:22 +02:00
parent ca0efa5981
commit be6329b957
4 changed files with 86 additions and 10 deletions

View file

@ -15,7 +15,7 @@ import gent.zeus.mc13dtl.MC13DTL;
public class EventRunner implements Runnable {
static List<Event> currentEvents = new ArrayList<>();
public static List<Integer> startTimes = List.of(5000, 13000, 1000, 1000, 13000, 100, 1000, 500, 10000, 5000, 13000, 100);
public static List<Integer> 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();

View file

@ -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) {

View file

@ -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)";
}
}

View file

@ -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);
}
}