Skip to content

Commit

Permalink
fix full respawn calculation
Browse files Browse the repository at this point in the history
(cherry picked from commit 7babbac)
  • Loading branch information
Sirinut Euaungkanakul committed Oct 7, 2024
1 parent 87f13e3 commit ffca73e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/server/maps/MapleMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/server/maps/MapleMapTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package server.maps;

import org.junit.jupiter.api.Test;

class MapleMapTest {

@Test
void randShouldIncludeEntireRange() {
Map<Integer, Integer> 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));
}
}

0 comments on commit ffca73e

Please sign in to comment.