Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions src/main/java/fr/hugman/build_rush/game/state/BRActive.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.Pair;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand All @@ -62,10 +63,7 @@
import xyz.nucleoid.stimuli.event.player.PlayerDamageEvent;
import xyz.nucleoid.stimuli.event.player.PlayerDeathEvent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.*;

public class BRActive {
private final ServerWorld world;
Expand Down Expand Up @@ -918,25 +916,41 @@ public void startElimination() {
this.perfectRoundsInARow++;
}

List<Pair<ServerPlayerEntity, Integer>> scores = new ArrayList<>();

for (var player : this.space.getPlayers()) {
var data = this.playerDataMap.get(player.getUuid());
if (data == null || data.eliminated) {
continue;
}

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

player.sendMessage(TextUtil.translatable(TextUtil.DASH, TextUtil.NEUTRAL, "text.build_rush.score", scoreText), false);
TextUtil.sendSubtitle(player, scoreText, 0, 2 * 20, 5);
player.playSoundToPlayer(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 1.0f, 1.0f);
this.world.getServer().getPlayerManager().broadcast(Text.translatable("generic.build_rush.round_stats.title").setStyle(Style.EMPTY.withColor(TextUtil.LEGENDARY).withBold(true)), false);
int rank = 0;
int previousScore = Integer.MAX_VALUE;
for (int i = scores.size() - 1; i >= 0; i--) {
Pair<ServerPlayerEntity, Integer> pair = scores.get(i);
if (pair.getRight() < previousScore) {
rank++;
}
float scorePercentage = pair.getRight() / (float) this.maxScore;
String scoreAsPercent = String.format("%.2f", scorePercentage * 100).replaceAll("0*$", "").replaceAll("[,.]$", "");

var scoreText = Text.translatable("generic.build_rush.score", scoreAsPercent)
.setStyle(Style.EMPTY.withColor(TextUtil.lerpScoreColor(scorePercentage)).withBold(true));

int color = switch (rank) {
case 1 -> TextUtil.GOLD;
case 2 -> TextUtil.SILVER;
case 3 -> TextUtil.BRONZE;
default -> TextUtil.NEUTRAL;
};

this.world.getServer().getPlayerManager().broadcast(Text.translatable("generic.build_rush.round_stats.entry", rank, pair.getLeft().getDisplayName(), scoreText).setStyle(Style.EMPTY.withColor(color)), false);
previousScore = pair.getRight();
}

if (this.loserUuid == null) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fr/hugman/build_rush/text/TextUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class TextUtil {
public static final int LEGENDARY = 0xface3e;
public static final int LEGENDARY_S = 0xd9a107;

public static final int GOLD = 0xc98910;
public static final int SILVER = 0x965a38;
public static final int BRONZE = 0xa8a8a8;

public static final String DASH = "»";
public static final String SKULL = "☠";
public static final String PICKAXE = "⛏";
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/data/build_rush/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
"game.build_rush.flags.signal": "Build Rush: Signal Flags",

"generic.build_rush.score": "%d%%",
"generic.build_rush.round_stats.title": "Round stats:",
"generic.build_rush.round_stats.entry": "%d. %s - %s",

"text.build_rush.eliminated": "%s has been eliminated! They got a %s percent correct build.",
"text.build_rush.eliminated": "%s has been eliminated! They got a %s percent correct build.",
"text.build_rush.eliminated.self": "You have been eliminated!",
"text.build_rush.score": "You got a %s correct build!",
"text.build_rush.finished": "You got the entire build correctly!",
Expand Down