From a76e181ce8da636de4882a51bee8b8b180e03002 Mon Sep 17 00:00:00 2001 From: XiaoMoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Thu, 15 Aug 2024 01:12:48 +0800 Subject: [PATCH] Update BukkitGameManager.java --- .../bukkit/game/BukkitGameManager.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java b/core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java index d4c43009..e40c926e 100644 --- a/core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java +++ b/core/src/main/java/net/momirealms/customfishing/bukkit/game/BukkitGameManager.java @@ -987,20 +987,30 @@ public class BukkitGameManager implements GameManager { private final int judgementAreaOffset = section.getInt("arguments.judgment-area-offset"); private final int pointerIconWidth = section.getInt("arguments.pointer-icon-width"); private final int pointerOffset = section.getInt("arguments.pointer-offset"); + private final int maxSpeed = section.getInt("arguments.max-speed", 150); + private final int minSpeed = section.getInt("arguments.min-speed", 15); @Override public BiFunction gamingPlayerProvider() { return (customFishingHook, gameSetting) -> new AbstractGamingPlayer(customFishingHook, gameSetting) { + private static final int MIN_VALUE = 1; + private static final int MAX_VALUE = 100; + private int progress = -1; private boolean face = true; private final int judgement_position = RandomUtils.generateRandomInt(0, barEffectiveWidth - judgementAreaWidth); private final TextValue title = TextValue.auto(titles.get(RandomUtils.generateRandomInt(0, titles.size() - 1))); + private long mapValueToIntervalMicroseconds(int value) { + double frequency = minSpeed + ((double) (value - MIN_VALUE) / (MAX_VALUE - MIN_VALUE)) * (maxSpeed - minSpeed); + return (long) (1_000_000 / frequency); + } + @Override public void arrangeTask() { - var period = ((double) 10*(200-settings.difficulty()))/((double) (1+4*settings.difficulty())); - this.task = plugin.getScheduler().asyncRepeating(this, 50, (long) period, TimeUnit.MILLISECONDS); + long period = mapValueToIntervalMicroseconds((int) settings.difficulty()); + this.task = plugin.getScheduler().asyncRepeating(this, period, period, TimeUnit.MICROSECONDS); } @Override