mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-15 06:45:04 +01:00
Implement configurable server drop rates
This commit is contained in:
@@ -22,6 +22,7 @@ public class Config {
|
|||||||
public GameServerConfig gameServer = new GameServerConfig(23301);
|
public GameServerConfig gameServer = new GameServerConfig(23301);
|
||||||
|
|
||||||
public ServerOptions serverOptions = new ServerOptions();
|
public ServerOptions serverOptions = new ServerOptions();
|
||||||
|
public ServerRates serverRates = new ServerRates();
|
||||||
public LogOptions logOptions = new LogOptions();
|
public LogOptions logOptions = new LogOptions();
|
||||||
public DownloadData downloadData = new DownloadData();
|
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
|
@Getter
|
||||||
public static class ServerProfile {
|
public static class ServerProfile {
|
||||||
public String name = "Server";
|
public String name = "Server";
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package emu.lunarcore.game.drops;
|
package emu.lunarcore.game.drops;
|
||||||
|
|
||||||
|
import emu.lunarcore.GameConstants;
|
||||||
|
import emu.lunarcore.LunarCore;
|
||||||
import emu.lunarcore.data.GameData;
|
import emu.lunarcore.data.GameData;
|
||||||
import emu.lunarcore.data.excel.ItemExcel;
|
import emu.lunarcore.data.excel.ItemExcel;
|
||||||
import emu.lunarcore.util.Utils;
|
import emu.lunarcore.util.Utils;
|
||||||
@@ -78,7 +80,8 @@ public class DropParam {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get count
|
// Get count
|
||||||
int count = generateCount();
|
double count = generateCount();
|
||||||
|
var rates = LunarCore.getConfig().getServerRates();
|
||||||
|
|
||||||
// Generate item(s)
|
// Generate item(s)
|
||||||
while (count > 0) {
|
while (count > 0) {
|
||||||
@@ -88,11 +91,29 @@ public class DropParam {
|
|||||||
if (excel == null) break;
|
if (excel == null) break;
|
||||||
|
|
||||||
if (excel.isEquippable()) {
|
if (excel.isEquippable()) {
|
||||||
drops.addTo(itemId, 1);
|
// Add relic/equipment drop
|
||||||
count--;
|
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 {
|
} else {
|
||||||
drops.addTo(itemId, count);
|
// Apply server rates to drop amount amount
|
||||||
count -= count;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import emu.lunarcore.GameConstants;
|
import emu.lunarcore.GameConstants;
|
||||||
|
import emu.lunarcore.LunarCore;
|
||||||
import emu.lunarcore.data.GameData;
|
import emu.lunarcore.data.GameData;
|
||||||
import emu.lunarcore.data.common.ItemParam;
|
import emu.lunarcore.data.common.ItemParam;
|
||||||
import emu.lunarcore.data.excel.ItemExcel;
|
import emu.lunarcore.data.excel.ItemExcel;
|
||||||
@@ -64,21 +65,24 @@ public class DropService extends BaseGameService {
|
|||||||
|
|
||||||
// Create drops
|
// Create drops
|
||||||
for (var entry : dropMap.entries()) {
|
for (var entry : dropMap.entries()) {
|
||||||
if (entry.getIntValue() <= 0) {
|
// Get amount
|
||||||
|
int amount = entry.getIntValue();
|
||||||
|
if (amount <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create item and add it to player
|
// Create item and add it to player
|
||||||
|
int itemId = 0;
|
||||||
ItemExcel excel = GameData.getItemExcelMap().get(entry.getIntKey());
|
ItemExcel excel = GameData.getItemExcelMap().get(entry.getIntKey());
|
||||||
if (excel == null) continue;
|
if (excel == null) continue;
|
||||||
|
|
||||||
// Add item
|
// Add item
|
||||||
if (excel.isEquippable()) {
|
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));
|
battle.getDrops().add(new GameItem(excel, 1));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
battle.getDrops().add(new GameItem(excel, entry.getIntValue()));
|
battle.getDrops().add(new GameItem(excel, amount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user