Skip to content

Commit f43267f

Browse files
committed
Add round stats
1 parent f3dcd23 commit f43267f

3 files changed

Lines changed: 36 additions & 16 deletions

File tree

src/main/java/fr/hugman/build_rush/game/state/BRActive.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import net.minecraft.util.ActionResult;
3939
import net.minecraft.util.Formatting;
4040
import net.minecraft.util.Hand;
41+
import net.minecraft.util.Pair;
4142
import net.minecraft.util.hit.BlockHitResult;
4243
import net.minecraft.util.math.BlockPos;
4344
import net.minecraft.util.math.Direction;
@@ -62,10 +63,7 @@
6263
import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent;
6364
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;
6465

65-
import java.util.ArrayList;
66-
import java.util.HashMap;
67-
import java.util.List;
68-
import java.util.UUID;
66+
import java.util.*;
6967

7068
public class BRActive {
7169
private final ServerWorld world;
@@ -918,25 +916,41 @@ public void startElimination() {
918916
this.perfectRoundsInARow++;
919917
}
920918

919+
List<Pair<ServerPlayerEntity, Integer>> scores = new ArrayList<>();
920+
921921
for (var player : this.space.getPlayers()) {
922922
var data = this.playerDataMap.get(player.getUuid());
923923
if (data == null || data.eliminated) {
924924
continue;
925925
}
926926

927-
if (data.score == this.maxScore) {
928-
TextUtil.sendSubtitle(player, Text.translatable("title.build_rush.perfect").setStyle(Style.EMPTY.withColor(TextUtil.LEGENDARY).withBold(true)), 0, 3 * 20, 10);
929-
player.playSoundToPlayer(SoundEvents.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1.0f, 1.0f);
930-
} else {
931-
float scorePercentage = data.score / (float) this.maxScore;
932-
String scoreAsPercent = String.format("%.2f", scorePercentage * 100).replaceAll("0*$", "").replaceAll("[,.]$", "");
933-
var scoreText = Text.translatable("generic.build_rush.score", scoreAsPercent)
934-
.setStyle(Style.EMPTY.withColor(TextUtil.lerpScoreColor(scorePercentage)).withBold(true));
927+
scores.add(new Pair<>(player, data.score));
928+
}
929+
scores.sort(Comparator.comparing(Pair::getRight));
935930

936-
player.sendMessage(TextUtil.translatable(TextUtil.DASH, TextUtil.NEUTRAL, "text.build_rush.score", scoreText), false);
937-
TextUtil.sendSubtitle(player, scoreText, 0, 2 * 20, 5);
938-
player.playSoundToPlayer(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 1.0f, 1.0f);
931+
this.world.getServer().getPlayerManager().broadcast(Text.translatable("generic.build_rush.round_stats.title").setStyle(Style.EMPTY.withColor(TextUtil.LEGENDARY).withBold(true)), false);
932+
int rank = 0;
933+
int previousScore = Integer.MAX_VALUE;
934+
for (int i = scores.size() - 1; i >= 0; i--) {
935+
Pair<ServerPlayerEntity, Integer> pair = scores.get(i);
936+
if (pair.getRight() < previousScore) {
937+
rank++;
939938
}
939+
float scorePercentage = pair.getRight() / (float) this.maxScore;
940+
String scoreAsPercent = String.format("%.2f", scorePercentage * 100).replaceAll("0*$", "").replaceAll("[,.]$", "");
941+
942+
var scoreText = Text.translatable("generic.build_rush.score", scoreAsPercent)
943+
.setStyle(Style.EMPTY.withColor(TextUtil.lerpScoreColor(scorePercentage)).withBold(true));
944+
945+
int color = switch (rank) {
946+
case 1 -> TextUtil.GOLD;
947+
case 2 -> TextUtil.SILVER;
948+
case 3 -> TextUtil.BRONZE;
949+
default -> TextUtil.NEUTRAL;
950+
};
951+
952+
this.world.getServer().getPlayerManager().broadcast(Text.translatable("generic.build_rush.round_stats.entry", rank, pair.getLeft().getDisplayName(), scoreText).setStyle(Style.EMPTY.withColor(color)), false);
953+
previousScore = pair.getRight();
940954
}
941955

942956
if (this.loserUuid == null) {

src/main/java/fr/hugman/build_rush/text/TextUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public class TextUtil {
2323
public static final int LEGENDARY = 0xface3e;
2424
public static final int LEGENDARY_S = 0xd9a107;
2525

26+
public static final int GOLD = 0xc98910;
27+
public static final int SILVER = 0x965a38;
28+
public static final int BRONZE = 0xa8a8a8;
29+
2630
public static final String DASH = "»";
2731
public static final String SKULL = "☠";
2832
public static final String PICKAXE = "⛏";

src/main/resources/data/build_rush/lang/en_us.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
"game.build_rush.flags.signal": "Build Rush: Signal Flags",
1010

1111
"generic.build_rush.score": "%d%%",
12+
"generic.build_rush.round_stats.title": "Round stats:",
13+
"generic.build_rush.round_stats.entry": "%d. %s - %s",
1214

13-
"text.build_rush.eliminated": "%s has been eliminated! They got a %s percent correct build.",
15+
"text.build_rush.eliminated": "%s has been eliminated! They got a %s percent correct build.",
1416
"text.build_rush.eliminated.self": "You have been eliminated!",
1517
"text.build_rush.score": "You got a %s correct build!",
1618
"text.build_rush.finished": "You got the entire build correctly!",

0 commit comments

Comments
 (0)