Skip to content

Commit

Permalink
Indicate players currently on the throne on the scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored and Restioson committed Jun 17, 2024
1 parent 475a19c commit a7a0ecf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
36 changes: 23 additions & 13 deletions src/main/java/io/github/restioson/koth/game/KothActive.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private void tick() {
continue;
}

boolean onThrone = this.gameMap.throne.asBox().intersects(player.getBoundingBox());
boolean onThrone = this.gameMap.throne.intersects(player.getBoundingBox());

if (onThrone) {
playersOnThrone += 1;
Expand Down Expand Up @@ -388,6 +388,8 @@ private void tick() {
return;
}

boolean rebuildLeaderboard = false;

for (ServerPlayerEntity player : this.participants.keySet()) {
player.setHealth(20.0f);

Expand Down Expand Up @@ -419,23 +421,31 @@ private void tick() {
continue;
}

if (this.config.winnerTakesAll()) {
List<KothPlayer> top = this.participants.values().stream()
.sorted(Comparator.comparingDouble(p -> -p.player.getY())) // Descending sort
.limit(1)
.collect(Collectors.toList());
this.scoreboard.render(top);
continue;
} else if (this.config.knockoff()) {
this.scoreboard.render(this.buildLeaderboard());
if (this.config.winnerTakesAll() || this.config.knockoff()) {
rebuildLeaderboard = true;
continue;
}

if (this.gameMap.throne.asBox().intersects(player.getBoundingBox()) && time % 20 == 0) {
if (this.gameMap.throne.intersects(player.getBoundingBox()) && time % 20 == 0) {
state.score += 1;
player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 1.0f, 1.0f);
player.addExperienceLevels(1);
this.scoreboard.render(this.buildLeaderboard());
rebuildLeaderboard = true;
} else if (time % 10 == 0) {
// Update flashing indicator
rebuildLeaderboard = true;
}
}

if (rebuildLeaderboard) {
if (this.config.winnerTakesAll()) {
List<KothPlayer> top = this.participants.values().stream()
.sorted(Comparator.comparingDouble(p -> -p.player.getY())) // Descending sort
.limit(1)
.collect(Collectors.toList());
this.scoreboard.render(top, this.gameMap.throne);
} else {
this.scoreboard.render(this.buildLeaderboard(), this.gameMap.throne);
}
}
}
Expand Down Expand Up @@ -509,7 +519,7 @@ private void broadcastWin(ServerPlayerEntity winner) {
.sorted(Comparator.comparingDouble(p -> -p.wins)) // Descending sort
.limit(5)
.collect(Collectors.toList());
this.scoreboard.render(top);
this.scoreboard.render(top, this.gameMap.throne);
}


Expand Down
14 changes: 13 additions & 1 deletion src/main/java/io/github/restioson/koth/game/KothScoreboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.Box;
import xyz.nucleoid.plasmid.game.common.GlobalWidgets;
import xyz.nucleoid.plasmid.game.common.widget.SidebarWidget;

Expand All @@ -27,7 +28,7 @@ public void renderTitle() {
});
}

public void render(List<KothPlayer> leaderboard) {
public void render(List<KothPlayer> leaderboard, Box throne) {
this.sidebar.set(content -> {
for (KothPlayer entry : leaderboard) {
String line;
Expand All @@ -50,6 +51,17 @@ public void render(List<KothPlayer> leaderboard) {
Formatting.RESET,
entry.score
);
} else if (throne.intersects(entry.player.getBoundingBox())) {
Formatting indicatorColor = entry.player.getWorld().getTime() % 20 == 0 ? Formatting.GOLD : Formatting.YELLOW;

line = String.format(
"%s♦ %s%s%s: %ds",
indicatorColor,
Formatting.AQUA,
entry.player.getEntityName(),
Formatting.RESET,
entry.score
);
} else {
line = String.format(
"%s%s%s: %ds",
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/github/restioson/koth/game/map/KothMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Util;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import xyz.nucleoid.map_templates.BlockBounds;
Expand All @@ -18,14 +19,14 @@ public class KothMap {
public final int spawnAngle;
public final BlockBounds bounds;
public final List<BlockBounds> noPvp;
public final BlockBounds throne;
public final Box throne;

public KothMap(MapTemplate template, List<BlockBounds> spawns, BlockBounds throne, int spawnAngle) {
this.template = template;
this.spawns = spawns;
this.spawnAngle = spawnAngle;
this.bounds = template.getBounds();
this.throne = throne;
this.throne = throne.asBox();

this.noPvp = new ArrayList<>(spawns.size());
for (BlockBounds spawn : spawns) {
Expand Down

0 comments on commit a7a0ecf

Please sign in to comment.