From ffca73e31eaf2017e6b47a2dcd2d2f4d13027bed Mon Sep 17 00:00:00 2001 From: Sirinut Euaungkanakul Date: Mon, 7 Oct 2024 14:04:22 +0700 Subject: [PATCH] fix full respawn calculation (cherry picked from commit 7babbacf645538a68143881b597fdd0403265968) --- src/main/java/server/maps/MapleMap.java | 8 +++--- src/test/java/server/maps/MapleMapTest.java | 31 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 src/test/java/server/maps/MapleMapTest.java diff --git a/src/main/java/server/maps/MapleMap.java b/src/main/java/server/maps/MapleMap.java index 2d1d711c21e..dc8c73709a4 100644 --- a/src/main/java/server/maps/MapleMap.java +++ b/src/main/java/server/maps/MapleMap.java @@ -3530,12 +3530,12 @@ private int getNumShouldSpawn(int numPlayers) { System.out.println("----------------------------------"); */ + float maxMob = monsterSpawn.size() * getWorldServer().getMobrate(); + if (YamlConfig.config.server.USE_ENABLE_FULL_RESPAWN) { - return (int) Math.ceil((monsterSpawn.size() - spawnedMonstersOnMap.get()) * getWorldServer().getMobrate()); + return (int) Math.ceil(maxMob) - spawnedMonstersOnMap.get(); } - - int maxNumShouldSpawn = (int) Math.ceil(getCurrentSpawnRate(numPlayers) * monsterSpawn.size() * getWorldServer().getMobrate()); - return maxNumShouldSpawn - spawnedMonstersOnMap.get(); + return (int) Math.ceil(getCurrentSpawnRate(numPlayers) * maxMob) - spawnedMonstersOnMap.get(); } public void respawn() { diff --git a/src/test/java/server/maps/MapleMapTest.java b/src/test/java/server/maps/MapleMapTest.java new file mode 100644 index 00000000000..bfe26d17ffe --- /dev/null +++ b/src/test/java/server/maps/MapleMapTest.java @@ -0,0 +1,31 @@ +package server.maps; + +import org.junit.jupiter.api.Test; + +class MapleMapTest { + + @Test + void randShouldIncludeEntireRange() { + Map rands = new HashMap<>(); + + final int rounds = 100_000; + for (int i = 0; i < rounds; i++) { + int randomValue = Randomizer.rand(-5, 5); + rands.compute(randomValue, (k, v) -> v == null ? 0 : v + 1); + } + + assertFalse(rands.containsKey(-6)); + assertTrue(rands.containsKey(-5)); + assertTrue(rands.containsKey(-4)); + assertTrue(rands.containsKey(-3)); + assertTrue(rands.containsKey(-2)); + assertTrue(rands.containsKey(-1)); + assertTrue(rands.containsKey(0)); + assertTrue(rands.containsKey(1)); + assertTrue(rands.containsKey(2)); + assertTrue(rands.containsKey(3)); + assertTrue(rands.containsKey(4)); + assertTrue(rands.containsKey(5)); + assertFalse(rands.containsKey(6)); + } +} \ No newline at end of file