Add lives limit for final event

This commit is contained in:
Mathieu Strypsteen 2024-09-23 09:25:19 +02:00
parent 827d1ba070
commit 160eb45f8d
2 changed files with 10 additions and 2 deletions

View file

@ -55,7 +55,7 @@ public class EventRunner implements Runnable {
case 9 -> new KillMobs2Event(team, difficulty, dayScore);
case 10 -> new RunToSpawnEvent(team, difficulty, dayScore);
case 11 -> new LightningEvent(team, difficulty, dayScore);
case 12 -> new EndEvent(team, difficulty, dayScore); // TODO: Move to last day
case 12 -> new EndEvent(team, difficulty, dayScore);
default -> throw new IllegalStateException("Unexpected day: " + (int) day);
};
event.start();

View file

@ -19,6 +19,7 @@ import gent.zeus.mc13dtl.events.Event;
public class EndEvent extends Event {
private PotionEffectType[] effects;
private int livesLeft = 5;
public EndEvent(Team team, Difficulty difficulty, int scoreOnSuccess) {
super(team, difficulty, scoreOnSuccess);
@ -60,8 +61,11 @@ public class EndEvent extends Event {
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntityType() == EntityType.ENDER_DRAGON) {
if (!MC13DTL.board.getPlayers(team).isEmpty()) {
if (!MC13DTL.board.getPlayers(team).isEmpty() && livesLeft > 0) {
eventSuccess();
} else {
eventFailed();
}
}
}
@ -69,6 +73,10 @@ public class EndEvent extends Event {
@Override
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
if (!MC13DTL.board.getPlayers(team).contains(event.getPlayer())) {
return;
}
livesLeft--;
}
@Override