Add StructureEvent

This commit is contained in:
Mathieu Strypsteen 2024-09-21 18:00:28 +02:00
parent 91201cae96
commit eb9262991d
2 changed files with 64 additions and 1 deletions

View file

@ -15,7 +15,7 @@ import gent.zeus.mc13dtl.MC13DTL;
public class EventRunner implements Runnable { public class EventRunner implements Runnable {
static List<Event> currentEvents = new ArrayList<>(); static List<Event> currentEvents = new ArrayList<>();
public static List<Integer> startTimes = List.of(5000, 13000, 1000, 13000, 1000); public static List<Integer> startTimes = List.of(5000, 13000, 1000, 13000, 1000, 500);
private long day; private long day;
@ -45,6 +45,7 @@ public class EventRunner implements Runnable {
case 2 -> new CraftEvent(team, difficulty, getDayScore()); case 2 -> new CraftEvent(team, difficulty, getDayScore());
case 3 -> new ClimbEvent(team, difficulty, getDayScore()); case 3 -> new ClimbEvent(team, difficulty, getDayScore());
case 4 -> new KillPlayerEvent(team, difficulty, getDayScore(), teams); case 4 -> new KillPlayerEvent(team, difficulty, getDayScore(), teams);
case 5 -> new StructureEvent(team, difficulty, getDayScore());
default -> throw new IllegalStateException("Unexpected day: " + (int) day); default -> throw new IllegalStateException("Unexpected day: " + (int) day);
}; };
event.start(); event.start();

View file

@ -0,0 +1,62 @@
package gent.zeus.mc13dtl.events.catalog;
import gent.zeus.mc13dtl.MC13DTL;
import gent.zeus.mc13dtl.events.Difficulty;
import gent.zeus.mc13dtl.events.Event;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.generator.structure.Structure;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.StructureSearchResult;
public class StructureEvent extends Event {
enum StructureType {
RUINED_PORTAL, VILLAGE, PYRAMID, SWAMP_HUT, FORTRESS, END_CITY
}
private final StructureType structure;
public StructureEvent(Team team, Difficulty difficulty, int scoreOnSuccess) {
super(team, difficulty, scoreOnSuccess);
structure = switch (difficulty) {
case BABY -> StructureType.RUINED_PORTAL;
case EASY -> StructureType.VILLAGE;
case MEDIUM -> StructureType.PYRAMID;
case HARD -> StructureType.SWAMP_HUT;
case SWEAT -> StructureType.FORTRESS;
case IMPOSSIBLE -> StructureType.END_CITY;
};
}
@Override
public void run() {
Structure[] structures = switch (structure) {
case RUINED_PORTAL -> new Structure[] { Structure.RUINED_PORTAL, Structure.RUINED_PORTAL_DESERT, Structure.RUINED_PORTAL_JUNGLE, Structure.RUINED_PORTAL_MOUNTAIN, Structure.RUINED_PORTAL_NETHER,
Structure.RUINED_PORTAL_OCEAN, Structure.RUINED_PORTAL_SWAMP };
case END_CITY -> new Structure[] { Structure.END_CITY };
case FORTRESS -> new Structure[] { Structure.FORTRESS };
case PYRAMID -> new Structure[] { Structure.DESERT_PYRAMID, Structure.JUNGLE_PYRAMID };
case SWAMP_HUT -> new Structure[] { Structure.SWAMP_HUT };
case VILLAGE -> new Structure[] { Structure.VILLAGE_DESERT, Structure.VILLAGE_PLAINS, Structure.VILLAGE_SAVANNA, Structure.VILLAGE_SNOWY, Structure.VILLAGE_TAIGA };
};
for (Player player : MC13DTL.board.getPlayers(team)) {
Location pos = player.getLocation();
for (Structure struct : structures) {
StructureSearchResult res = player.getWorld().locateNearestStructure(pos, struct, 5, false);
if (res != null) {
if (res.getLocation().distance(pos) < 200) {
eventSuccess();
}
}
}
}
}
@Override
protected String getMessage() {
return "Find this structure before tomorrow: " + structure.toString();
}
}