From 2b1239950626b4480b0ac7120f4c8429dfaf8b68 Mon Sep 17 00:00:00 2001 From: Emirlol <81419447+Emirlol@users.noreply.github.com> Date: Sun, 7 Jan 2024 02:58:21 +0300 Subject: Improved time score calculation --- .../de/hysky/skyblocker/skyblock/dungeon/DungeonScore.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 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 ebec99dc..6016813c 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScore.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScore.java @@ -35,7 +35,6 @@ public class DungeonScore { private static final Pattern SECRETS_PATTERN = Pattern.compile("Secrets Found: (?\\d+\\.?\\d*)%"); private static final Pattern PUZZLES_PATTERN = Pattern.compile(".+?(?=:): \\[(?.)](?: \\(\\w+\\))?"); private static final Pattern PUZZLE_COUNT_PATTERN = Pattern.compile("Puzzles: \\((?\\d+)\\)"); - private static final Pattern TIME_PATTERN = Pattern.compile("Time: (?:(?\\d+(?=h))?h? ?(?\\d+(?=m))?m? ?(?\\d+(?=s))s|Soon!)"); private static final Pattern CRYPTS_PATTERN = Pattern.compile("Crypts: (?\\d+)"); private static final Pattern COMPLETED_ROOMS_PATTERN = Pattern.compile(" *Completed Rooms: (?\\d+)"); private static final Pattern DUNGEON_START_PATTERN = Pattern.compile("(?:Auto-closing|Starting) in: \\d:\\d+"); @@ -49,6 +48,7 @@ public class DungeonScore { //Caching the dungeon start state to prevent unnecessary scoreboard pattern matching after dungeon starts private static boolean isDungeonStarted; private static boolean isMayorPaul; + private static long startingTime; private static final HashMap floorRequirements = new HashMap<>(Map.ofEntries( Map.entry("E", new FloorRequirement(30, 1200)), Map.entry("F1", new FloorRequirement(30, 600)), @@ -135,6 +135,7 @@ public class DungeonScore { isDungeonStarted = true; puzzleCount = getPuzzleCount(); isMayorPaul = Utils.getMayor().equals("Paul"); + startingTime = System.currentTimeMillis(); } private static int calculateScore() { @@ -158,16 +159,8 @@ public class DungeonScore { } private static int calculateTimeScore() { - Matcher timeMatcher = PlayerListMgr.regexAt(45, TIME_PATTERN); - if (timeMatcher == null) { - LOGGER.error("Time pattern doesn't match"); - return 0; - } int score = 100; - int hours = Optional.ofNullable(timeMatcher.group("hours")).map(Integer::parseInt).orElse(0); - int minutes = Optional.ofNullable(timeMatcher.group("minutes")).map(Integer::parseInt).orElse(0); - int seconds = Optional.ofNullable(timeMatcher.group("seconds")).map(Integer::parseInt).orElse(0); - int timeSpent = hours * 3600 + minutes * 60 + seconds; + int timeSpent = (int) (System.currentTimeMillis() - startingTime) / 1000; int timeRequirement = floorRequirements.get(currentFloor).timeLimit; if (timeSpent < timeRequirement) return score; -- cgit