aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/dungeon
diff options
context:
space:
mode:
authorEmirlol <81419447+Emirlol@users.noreply.github.com>2024-01-15 19:05:55 +0300
committerRime <81419447+Emirlol@users.noreply.github.com>2024-01-21 09:37:31 +0300
commitcbdaa7a2b69ed2b17e36548b707400f416154c4f (patch)
treea87e8686b844bea1b0a4920cebd41fb4c77c682c /src/main/java/de/hysky/skyblocker/skyblock/dungeon
parent6a350f931609432bd93362b2dbdc26e23450e2b8 (diff)
downloadSkyblocker-cbdaa7a2b69ed2b17e36548b707400f416154c4f.tar.gz
Skyblocker-cbdaa7a2b69ed2b17e36548b707400f416154c4f.tar.bz2
Skyblocker-cbdaa7a2b69ed2b17e36548b707400f416154c4f.zip
Added dungeon score to the hud and cleaned up code
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dungeon')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScore.java73
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScoreHUD.java38
2 files changed, 79 insertions, 32 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScore.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScore.java
index 0334290d..0a9aec50 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScore.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScore.java
@@ -56,13 +56,14 @@ public class DungeonScore {
private static boolean sent270;
private static boolean sent300;
private static boolean isMimicKilled;
- private static int puzzleCount;
- private static boolean isDungeonStarted;
+ private static boolean dungeonStarted;
private static boolean isMayorPaul;
- private static long startingTime;
- private static int deathCount;
private static boolean firstDeathHasSpiritPet;
private static boolean bloodRoomCompleted;
+ private static long startingTime;
+ private static int puzzleCount;
+ private static int deathCount;
+ private static int score;
private static final Map<String, Boolean> SpiritPetCache = new HashMap<>();
public static void init() {
@@ -70,6 +71,7 @@ public class DungeonScore {
SkyblockEvents.LEAVE.register(SpiritPetCache::clear);
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> reset());
ClientReceiveMessageEvents.GAME.register((message, overlay) -> {
+ if (!Utils.isInDungeons() || !dungeonStarted) return;
String str = message.getString();
checkMessageForDeaths(str);
checkMessageForWatcher(str);
@@ -82,11 +84,11 @@ public class DungeonScore {
reset();
return;
}
- if (!isDungeonStarted) {
+ if (!dungeonStarted) {
if (checkIfDungeonStarted()) onDungeonStart();
return;
}
- int score = calculateScore();
+ score = calculateScore();
if (!sent270 && score >= 270 && score < 300) {
if (SCORE_CONFIG.enableDungeonScore270Message) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown(SCORE_CONFIG.dungeonScore270Message.replaceAll("\\[score]", "270"));
@@ -116,19 +118,23 @@ public class DungeonScore {
}
private static void reset() {
+ currentFloor = "";
sent270 = false;
sent300 = false;
- isDungeonStarted = false;
isMimicKilled = false;
+ dungeonStarted = false;
isMayorPaul = false;
firstDeathHasSpiritPet = false;
+ bloodRoomCompleted = false;
+ startingTime = 0L;
+ puzzleCount = 0;
deathCount = 0;
- currentFloor = "";
+ score = 0;
}
private static void onDungeonStart() {
setCurrentFloor();
- isDungeonStarted = true;
+ dungeonStarted = true;
puzzleCount = getPuzzleCount();
isMayorPaul = Utils.getMayor().equals("Paul");
startingTime = System.currentTimeMillis();
@@ -147,15 +153,11 @@ public class DungeonScore {
}
private static int calculateSkillScore() {
- int extraCompletedRooms = 0; //This is needed for calculating the score before going in, so we have the result sooner
- if (!DungeonManager.isInBoss()) extraCompletedRooms = bloodRoomCompleted ? 1 : 2;
- return 20 + (int) Math.floor(80.0 * (getCompletedRooms() + extraCompletedRooms) / getTotalRooms()) - getPuzzlePenalty() - getDeathScorePenalty();
+ return 20 + (int) Math.floor(80.0 * (getCompletedRooms() + getExtraCompletedRooms()) / getTotalRooms()) - getPuzzlePenalty() - getDeathScorePenalty();
}
private static int calculateExploreScore() {
- int extraCompletedRooms = 0;
- if (!DungeonManager.isInBoss()) extraCompletedRooms = bloodRoomCompleted ? 1 : 2;
- int completedRoomScore = (int) Math.floor(60.0 * (getCompletedRooms() + extraCompletedRooms) / getTotalRooms());
+ int completedRoomScore = (int) Math.floor(60.0 * (getCompletedRooms() + getExtraCompletedRooms()) / getTotalRooms());
int percentageRequirement = FloorRequirement.valueOf(currentFloor).percentage;
int secretsScore = (int) Math.floor(40 * Math.min(percentageRequirement, getSecretsPercentage()) / percentageRequirement);
return completedRoomScore + secretsScore;
@@ -168,18 +170,11 @@ public class DungeonScore {
if (timeSpent < timeRequirement) return score;
double timePastRequirement = ((double) (timeSpent - timeRequirement) / timeRequirement) * 100;
- if (timePastRequirement >= 0 && timePastRequirement < 20) {
- score -= (int) timePastRequirement / 2;
- } else if (timePastRequirement >= 20 && timePastRequirement < 40) {
- score -= (int) (10 + (timePastRequirement - 20) / 4);
- } else if (timePastRequirement >= 40 && timePastRequirement < 50) {
- score -= (int) (15 + (timePastRequirement - 40) / 5);
- } else if (timePastRequirement >= 50 && timePastRequirement < 60) {
- score -= (int) (17 + (timePastRequirement - 50) / 6);
- } else if (timePastRequirement >= 60) {
- score -= (int) (18 + (2.0 / 3.0) + (timePastRequirement - 60) / 7);
- }
- return score;
+ if (timePastRequirement < 20) return score - (int) timePastRequirement / 2;
+ if (timePastRequirement < 40) return score - (int) (10 + (timePastRequirement - 20) / 4);
+ if (timePastRequirement < 50) return score - (int) (15 + (timePastRequirement - 40) / 5);
+ if (timePastRequirement < 60) return score - (int) (17 + (timePastRequirement - 50) / 6);
+ return score - (int) (18 + (2.0 / 3.0) + (timePastRequirement - 60) / 7);
}
private static int calculateBonusScore() {
@@ -191,7 +186,7 @@ public class DungeonScore {
}
private static boolean checkIfDungeonStarted() {
- return Utils.STRING_SCOREBOARD.stream().anyMatch(s -> DUNGEON_START_PATTERN.matcher(s).matches());
+ return Utils.STRING_SCOREBOARD.stream().noneMatch(s -> DUNGEON_START_PATTERN.matcher(s).matches());
}
public static boolean isEntityMimic(Entity entity) {
@@ -214,6 +209,7 @@ public class DungeonScore {
public static void handleEntityDeath(Entity entity) {
if (isMimicKilled) return;
if (!isEntityMimic(entity)) return;
+ if (MIMIC_MESSAGES_CONFIG.sendMimicMessages) MessageScheduler.INSTANCE.sendMessageAfterCooldown(MIMIC_MESSAGES_CONFIG.mimicMessage);
isMimicKilled = true;
}
@@ -221,6 +217,8 @@ public class DungeonScore {
isMimicKilled = state;
}
+ //This is not very accurate at the beginning of the dungeon since clear percentage is rounded to the closest integer, so at lower percentages its effect on the result is quite high.
+ //For example: If clear percentage is 7% with a single room completed, it can be rounded from 6.5 or 7.49. In that range, the actual total room count can be either 14 or 15 while our result is 14.
private static int getTotalRooms() {
int completedRooms = getCompletedRooms();
return (int) Math.round(completedRooms / getClearPercentage());
@@ -231,6 +229,12 @@ public class DungeonScore {
return matcher != null ? Integer.parseInt(matcher.group("rooms")) : 0;
}
+ private static int getExtraCompletedRooms() { //This is needed for calculating the score before going in the boss room & completing the blood room, so we have the result sooner
+ if (!bloodRoomCompleted) return 2;
+ if (!DungeonManager.isInBoss()) return 1;
+ return 0;
+ }
+
private static double getClearPercentage() {
for (String sidebarLine : Utils.STRING_SCOREBOARD) {
Matcher clearMatcher = CLEARED_PATTERN.matcher(sidebarLine);
@@ -306,7 +310,6 @@ public class DungeonScore {
}
private static void checkMessageForDeaths(String message) {
- if (!Utils.isInDungeons()) return;
if (!message.startsWith("\u2620", 1)) return;
Matcher matcher = DEATHS_PATTERN.matcher(message);
if (!matcher.matches()) return;
@@ -317,9 +320,7 @@ public class DungeonScore {
else return s;
});
CompletableFuture.supplyAsync(() -> hasSpiritPet(whoDied))
- .thenAccept(hasSpiritPet -> {
- firstDeathHasSpiritPet = hasSpiritPet;
- });
+ .thenAccept(hasSpiritPet -> firstDeathHasSpiritPet = hasSpiritPet);
}
private static void checkMessageForWatcher(String message) {
@@ -336,6 +337,14 @@ public class DungeonScore {
LOGGER.error("Floor pattern doesn't match");
}
+ public static int getScore() {
+ return score;
+ }
+
+ public static boolean isDungeonStarted() {
+ return dungeonStarted;
+ }
+
enum FloorRequirement {
E(30, 1200),
F1(30, 600),
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScoreHUD.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScoreHUD.java
new file mode 100644
index 00000000..9da12426
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScoreHUD.java
@@ -0,0 +1,38 @@
+package de.hysky.skyblocker.skyblock.dungeon;
+
+import de.hysky.skyblocker.config.SkyblockerConfigManager;
+import de.hysky.skyblocker.utils.Utils;
+import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.DrawContext;
+import net.minecraft.text.Text;
+import net.minecraft.util.Formatting;
+
+public class DungeonScoreHUD {
+
+ public static void init() {
+ HudRenderCallback.EVENT.register(DungeonScoreHUD::onHudRender);
+ }
+
+ private static void onHudRender(DrawContext context, float tickDelta) {
+ if (!Utils.isInDungeons() || !DungeonScore.isDungeonStarted()) return;
+
+ int x = SkyblockerConfigManager.get().locations.dungeons.mapX;
+ int y = SkyblockerConfigManager.get().locations.dungeons.mapY;
+ int size = (int) (128 * SkyblockerConfigManager.get().locations.dungeons.mapScaling);
+ context.drawCenteredTextWithShadow(MinecraftClient.getInstance().textRenderer,
+ Text.literal("Score: ").append(formatScore(DungeonScore.getScore())),
+ x + (size >> 1),
+ y + size + 5,
+ 0x00FFFFFF);
+ }
+
+ private static Text formatScore(int score) {
+ if (score < 100) return Text.literal(String.valueOf(score)).withColor(0xDC1A1A).append(Text.literal(" (D)").formatted(Formatting.GRAY));
+ if (score < 160) return Text.literal(String.valueOf(score)).withColor(0x4141FF).append(Text.literal(" (C)").formatted(Formatting.GRAY));
+ if (score < 230) return Text.literal(String.valueOf(score)).withColor(0x7FCC19).append(Text.literal(" (B)").formatted(Formatting.GRAY));
+ if (score < 270) return Text.literal(String.valueOf(score)).withColor(0x7F3FB2).append(Text.literal(" (A)").formatted(Formatting.GRAY));
+ if (score < 300) return Text.literal(String.valueOf(score)).withColor(0xF1E252).append(Text.literal(" (S)").formatted(Formatting.GRAY));
+ return Text.literal(String.valueOf(score)).withColor(0xF1E252).formatted(Formatting.BOLD).append(Text.literal(" (S+)").formatted(Formatting.GRAY));
+ }
+}