improve things

# Conflicts:
#	src/main/java/gent/zeus/mc13dtl/events/EventRunner.java
This commit is contained in:
Xander 2024-09-22 23:31:31 +02:00
parent be6329b957
commit ff6c4bdb2b
No known key found for this signature in database
GPG key ID: 79979C7BA303E003
8 changed files with 80 additions and 37 deletions

View file

@ -1,11 +1,7 @@
package gent.zeus.mc13dtl;
import gent.zeus.mc13dtl.gamestate.*;
import gent.zeus.mc13dtl.group.GroupAddCommand;
import gent.zeus.mc13dtl.group.GroupRemoveCommand;
import gent.zeus.mc13dtl.group.SetScoreCommand;
import gent.zeus.mc13dtl.group.SurvivalHandler;
import gent.zeus.mc13dtl.group.SurvivalRunner;
import gent.zeus.mc13dtl.group.*;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@ -35,6 +31,7 @@ public class MC13DTL extends JavaPlugin {
commands.register("execute-event", "Execute given event number now", new ExecuteEventCommand());
commands.register("group-add", "Add player to team", new GroupAddCommand());
commands.register("group-remove", "Remove player from team", new GroupRemoveCommand());
commands.register("group-disband", "Fully disband a team", new GroupDisbandCommand());
});
BukkitScheduler scheduler = this.getServer().getScheduler();
scheduler.runTask(this, () -> {

View file

@ -89,6 +89,10 @@ public class TeamScoreBoard {
player.setGlowing(true);
}
public void disbandTeam(Team team) {
team.unregister();
}
public void sendMessageToTeam(Team team, Component message) {
this.getPlayers(team).forEach(p -> p.sendMessage(message));
}

View file

@ -25,8 +25,9 @@ public abstract class Event implements Listener, Runnable {
}
public void start() {
MC13DTL.board.sendMessageToTeam(team, Component.text("Difficulty is " + this.difficulty.toString()));
MC13DTL.board.sendMessageToTeam(team, Component.text(getMessage()).color(NamedTextColor.GRAY).decorate(TextDecoration.ITALIC));
team.sendMessage(Component.text("===== New Event ======").color(NamedTextColor.BLUE));
team.sendMessage(Component.text(getMessage()).color(NamedTextColor.BLUE).decorate(TextDecoration.ITALIC));
team.sendMessage(Component.text("DIFFICULTY: " + difficulty.toString() + " REWARD: " + scoreOnSuccess).color(NamedTextColor.BLUE));
MC13DTL.instance.getServer().getPluginManager().registerEvents(this, MC13DTL.instance);
BukkitScheduler scheduler = MC13DTL.instance.getServer().getScheduler();

View file

@ -17,6 +17,8 @@ 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, 13000, 100);
private final List<Integer> dayScores = List.of(10, 20, 50, 100, 150, 250, 400, 600, 850, 1150, 1500, 2000, 3000);
private long day;
@Override
@ -36,23 +38,24 @@ public class EventRunner implements Runnable {
List<Team> teams = MC13DTL.board.getTeams().stream().toList();
List<Difficulty> difficulties = getDifficulties(teams);
int dayScore = dayScores.get((int) day);
for (int i = 0; i < teams.size() && i < difficulties.size(); i++) {
Team team = teams.get(i);
Difficulty difficulty = difficulties.get(i);
Event event = switch ((int) day) {
case 0 -> new SuicideEvent(team, difficulty, getDayScore());
case 1 -> new KillMobs1Event(team, difficulty, getDayScore());
case 2 -> new CraftEvent(team, difficulty, getDayScore());
case 3 -> new MineEvent(team, difficulty, getDayScore());
case 4 -> new ClimbEvent(team, difficulty, getDayScore());
case 5 -> new FallEvent(team, difficulty, getDayScore());
case 6 -> new KillPlayerEvent(team, difficulty, getDayScore());
case 7 -> new StructureEvent(team, difficulty, getDayScore());
case 8 -> new KillSurvivingTeamEvent(team, difficulty, getDayScore());
case 9 -> new KillMobs2Event(team, difficulty, getDayScore());
case 10 -> new RunToSpawnEvent(team, difficulty, getDayScore());
case 11 -> new LightningEvent(team, difficulty, getDayScore());
case 12 -> new EndEvent(team, difficulty, getDayScore());
case 0 -> new SuicideEvent(team, difficulty, dayScore);
case 1 -> new KillMobs1Event(team, difficulty, dayScore);
case 2 -> new CraftEvent(team, difficulty, dayScore);
case 3 -> new MineEvent(team, difficulty, dayScore);
case 4 -> new ClimbEvent(team, difficulty, dayScore);
case 5 -> new FallEvent(team, difficulty, dayScore);
case 6 -> new KillPlayerEvent(team, difficulty, dayScore);
case 7 -> new StructureEvent(team, difficulty, dayScore);
case 8 -> new KillSurvivingTeamEvent(team, difficulty, dayScore);
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
default -> throw new IllegalStateException("Unexpected day: " + (int) day);
};
event.start();
@ -61,10 +64,6 @@ public class EventRunner implements Runnable {
}
}
private int getDayScore() {
return (int) Math.pow(2, this.day);
}
private List<Difficulty> getDifficulties(List<Team> teams) {
List<Integer> scores = teams.stream().map(team -> MC13DTL.board.getScore(team)).toList();
@ -75,15 +74,17 @@ public class EventRunner implements Runnable {
// average is mapped to Difficulty.Medium
for (Integer score : scores) {
long distance = (score - average) / getDayScore();
long distance = (score - average) / dayScores.get((int) day);
if (distance <= -3) {
difficulties.add(Difficulty.BABY);
} else if (distance <= -1) {
} else if (distance <= -2) {
difficulties.add(Difficulty.EASY);
} else if (distance == 0) {
} else if (distance <= 1) {
difficulties.add(Difficulty.MEDIUM);
} else if (distance <= 4) {
} else if (distance <= 3) {
difficulties.add(Difficulty.HARD);
} else if (distance <= 5) {
difficulties.add(Difficulty.SWEAT);
} else {
difficulties.add(Difficulty.IMPOSSIBLE);

View file

@ -24,7 +24,7 @@ public class KillMobs1Event extends Event {
Difficulty.BABY, new Pair<>(EntityType.ZOMBIE, 1),
Difficulty.EASY, new Pair<>(EntityType.ZOMBIE, 3),
Difficulty.MEDIUM, new Pair<>(EntityType.ZOMBIE, 6),
Difficulty.HARD, new Pair<>(EntityType.SKELETON, 5),
Difficulty.HARD, new Pair<>(EntityType.SKELETON, 4),
Difficulty.IMPOSSIBLE, new Pair<>(EntityType.ENDERMAN, 4));
monster = monsters.get(difficulty).getFirst();
killsLeft = monsters.get(difficulty).getSecond();

View file

@ -18,19 +18,25 @@ public class KillPlayerEvent extends Event {
for (Team t : MC13DTL.board.getTeams()) {
if (!MC13DTL.board.getPlayers(t).isEmpty()
&& t != team
&& !t.getName().equals(team.getName())
&& (huntingTeam == null ||
Math.abs(MC13DTL.board.getScore(t) - MC13DTL.board.getScore(team)) < Math.abs(MC13DTL.board.getScore(huntingTeam) - MC13DTL.board.getScore(team))
)) {
huntingTeam = t;
}
}
}
@Override
public void start() {
if (huntingTeam == null) {
team.sendMessage(Component.text("Oops no other team to hunt").color(NamedTextColor.BLUE));
eventFailed();
return;
}
super.start();
MC13DTL.board.sendMessageToTeam(huntingTeam, Component.text("Your team is being hunted by team " + team.getName()).color(NamedTextColor.BLUE));
huntingTeam.sendMessage(Component.text("Your team is being hunted by team " + team.getName()).color(NamedTextColor.BLUE));
}
@EventHandler

View file

@ -0,0 +1,32 @@
package gent.zeus.mc13dtl.group;
import gent.zeus.mc13dtl.MC13DTL;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.scoreboard.Team;
import org.jetbrains.annotations.NotNull;
public class GroupDisbandCommand implements BasicCommand {
@Override
public void execute(@NotNull CommandSourceStack commandSourceStack, @NotNull String[] args) {
try {
if (args.length == 1) {
Integer index = Integer.parseInt(args[0]);
Team team = MC13DTL.board.getTeam(index);
if (team != null) {
MC13DTL.board.disbandTeam(team);
}
} else {
commandSourceStack.getSender().sendMessage("usage: /group-disband <index>");
}
} catch (NumberFormatException ex) {
commandSourceStack.getSender().sendMessage("usage: /group-disband <NUMBER>");
}
}
@Override
public String permission() {
return "13dtl.manage-groups";
}
}

View file

@ -25,12 +25,14 @@ public class SurvivalRunner implements Runnable {
if (day > lastRunDay) {
List<Pair<Team, Integer>> grantedScores = new ArrayList<>();
for (Team team : MC13DTL.board.getTeams().stream().toList()) {
if (!MC13DTL.board.getPlayers(team).isEmpty()) {
int currentDays = MC13DTL.board.getDaysAlive(team) + 1;
int score = (int) Math.pow(2, currentDays);
MC13DTL.board.setDaysAlive(team, currentDays);
MC13DTL.board.addScore(team, score);
grantedScores.add(new Pair<>(team, score));
}
}
grantedScores.sort(Comparator.comparing(p -> -p.getSecond()));