Implement configurable server drop rates

This commit is contained in:
Melledy
2023-12-10 18:13:36 -08:00
parent 92a4fd379b
commit 851d4aa885
3 changed files with 43 additions and 8 deletions

View File

@@ -22,6 +22,7 @@ public class Config {
public GameServerConfig gameServer = new GameServerConfig(23301);
public ServerOptions serverOptions = new ServerOptions();
public ServerRates serverRates = new ServerRates();
public LogOptions logOptions = new LogOptions();
public DownloadData downloadData = new DownloadData();
@@ -131,6 +132,15 @@ public class Config {
}
}
@Getter
public static class ServerRates {
public double exp = 1.0;
public double credit = 1.0;
public double jade = 1.0;
public double material = 1.0;
public double equip = 1.0;
}
@Getter
public static class ServerProfile {
public String name = "Server";

View File

@@ -1,5 +1,7 @@
package emu.lunarcore.game.drops;
import emu.lunarcore.GameConstants;
import emu.lunarcore.LunarCore;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.excel.ItemExcel;
import emu.lunarcore.util.Utils;
@@ -78,7 +80,8 @@ public class DropParam {
}
// Get count
int count = generateCount();
double count = generateCount();
var rates = LunarCore.getConfig().getServerRates();
// Generate item(s)
while (count > 0) {
@@ -88,11 +91,29 @@ public class DropParam {
if (excel == null) break;
if (excel.isEquippable()) {
drops.addTo(itemId, 1);
count--;
// Add relic/equipment drop
if (rates.getEquip() > 0) {
drops.addTo(itemId, 1);
count -= (1 / rates.getEquip());
} else {
count -= 1; // To prevent a rate of 0 from freezing the server
}
} else {
drops.addTo(itemId, count);
count -= count;
// Apply server rates to drop amount amount
int amount = switch (itemId) {
case GameConstants.TRAILBLAZER_EXP_ID -> (int) Math.floor(count * rates.getExp());
case GameConstants.MATERIAL_COIN_ID -> (int) Math.floor(count * rates.getCredit());
case GameConstants.MATERIAL_HCOIN_ID -> (int) Math.floor(count * rates.getJade());
default -> (int) Math.floor(count * rates.getMaterial());
};
// Add material/virtual drop
if (amount > 0) {
drops.addTo(itemId, amount);
}
// To prevent a rate of 0 from freezing the server
count -= count;
}
}
}

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import emu.lunarcore.GameConstants;
import emu.lunarcore.LunarCore;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.common.ItemParam;
import emu.lunarcore.data.excel.ItemExcel;
@@ -64,21 +65,24 @@ public class DropService extends BaseGameService {
// Create drops
for (var entry : dropMap.entries()) {
if (entry.getIntValue() <= 0) {
// Get amount
int amount = entry.getIntValue();
if (amount <= 0) {
continue;
}
// Create item and add it to player
int itemId = 0;
ItemExcel excel = GameData.getItemExcelMap().get(entry.getIntKey());
if (excel == null) continue;
// Add item
if (excel.isEquippable()) {
for (int i = 0; i < entry.getIntValue(); i++) {
for (int i = 0; i < amount; i++) {
battle.getDrops().add(new GameItem(excel, 1));
}
} else {
battle.getDrops().add(new GameItem(excel, entry.getIntValue()));
battle.getDrops().add(new GameItem(excel, amount));
}
}