Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop rate fixes #287

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/server/maps/MapleMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,14 @@ private byte dropItemsFromMonsterOnMap(List<MonsterDropEntry> dropEntry, Point p
float cardRate = chr.getCardRate(de.itemId);
int dropChance = (int) Math.min((float) de.chance * chRate * cardRate, Integer.MAX_VALUE);

if (Randomizer.nextInt(999999) < dropChance) {
if (Randomizer.nextInt(1000000) < dropChance) {
if (droptype == 3) {
pos.x = mobpos + ((d % 2 == 0) ? (40 * ((d + 1) / 2)) : -(40 * (d / 2)));
} else {
pos.x = mobpos + ((d % 2 == 0) ? (25 * ((d + 1) / 2)) : -(25 * (d / 2)));
}
if (de.itemId == 0) { // meso
int mesos = Randomizer.nextInt(de.Maximum - de.Minimum) + de.Minimum;
int mesos = Randomizer.nextInt(de.Maximum - de.Minimum + 1) + de.Minimum;

if (mesos > 0) {
if (chr.getBuffedValue(BuffStat.MESOUP) != null) {
Expand All @@ -692,7 +692,7 @@ private byte dropItemsFromMonsterOnMap(List<MonsterDropEntry> dropEntry, Point p
if (ItemConstants.getInventoryType(de.itemId) == InventoryType.EQUIP) {
idrop = ii.randomizeStats((Equip) ii.getEquipById(de.itemId));
} else {
idrop = new Item(de.itemId, (short) 0, (short) (de.Maximum != 1 ? Randomizer.nextInt(de.Maximum - de.Minimum) + de.Minimum : 1));
idrop = new Item(de.itemId, (short) 0, (short) (Randomizer.nextInt(de.Maximum - de.Minimum + 1) + de.Minimum));
}
spawnDrop(idrop, calcDropPos(pos, mob.getPosition()), mob, chr, droptype, de.questid);
}
Expand All @@ -710,7 +710,7 @@ private byte dropGlobalItemsFromMonsterOnMap(List<MonsterGlobalDropEntry> global
ItemInformationProvider ii = ItemInformationProvider.getInstance();

for (final MonsterGlobalDropEntry de : globalEntry) {
if (Randomizer.nextInt(999999) < de.chance) {
if (Randomizer.nextInt(1000000) < de.chance) {
if (droptype == 3) {
pos.x = mobpos + (d % 2 == 0 ? (40 * (d + 1) / 2) : -(40 * (d / 2)));
} else {
Expand All @@ -720,7 +720,7 @@ private byte dropGlobalItemsFromMonsterOnMap(List<MonsterGlobalDropEntry> global
if (ItemConstants.getInventoryType(de.itemId) == InventoryType.EQUIP) {
idrop = ii.randomizeStats((Equip) ii.getEquipById(de.itemId));
} else {
idrop = new Item(de.itemId, (short) 0, (short) (de.Maximum != 1 ? Randomizer.nextInt(de.Maximum - de.Minimum) + de.Minimum : 1));
idrop = new Item(de.itemId, (short) 0, (short) (Randomizer.nextInt(de.Maximum - de.Minimum + 1) + de.Minimum));
}
spawnDrop(idrop, calcDropPos(pos, mob.getPosition()), mob, chr, droptype, de.questid);
d++;
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/tools/NextIntTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package tools;

import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class NextIntTest {

@Test
void dropQuantityShouldIncludeEntireRange() {
Map<Integer, Integer> rands;
final int rounds = 100_000;
for (int min = 1; min < 100; min++) {
for (int max = min; max < 100; max++) {
rands = new HashMap<>();
for (int i = 0; i < rounds; i++) {
int randomValue = Randomizer.nextInt(max - min + 1) + min;
rands.compute(randomValue, (k, v) -> v == null ? 0 : v + 1);
}

assertFalse(rands.containsKey(min - 1));
for (int i = min; i <= max; i++) {
assertTrue(rands.containsKey(i));
}
assertFalse(rands.containsKey(max + 1));
}
}
}
}
Loading