mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-16 23:34:50 +01:00
Implement drop rates for world monster drops
This commit is contained in:
@@ -25,6 +25,7 @@ public class MappingInfoExcel extends GameResource {
|
|||||||
private String FarmType; // is enum
|
private String FarmType; // is enum
|
||||||
private List<ItemParam> DisplayItemList;
|
private List<ItemParam> DisplayItemList;
|
||||||
|
|
||||||
|
// Temp solution for handling drop tables
|
||||||
private transient List<DropParam> dropList;
|
private transient List<DropParam> dropList;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,7 +36,12 @@ public class MappingInfoExcel extends GameResource {
|
|||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
// Temp way to pre-calculate drop list
|
// Temp way to pre-calculate drop list
|
||||||
this.dropList = new ArrayList<>(this.getDisplayItemList().size());
|
if (this.DisplayItemList == null || DisplayItemList.size() == 0) {
|
||||||
|
this.dropList = new ArrayList<>(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dropList = new ArrayList<>(DisplayItemList.size());
|
||||||
|
|
||||||
var equipmentDrops = new IntArrayList();
|
var equipmentDrops = new IntArrayList();
|
||||||
var relicDrops = new Int2ObjectOpenHashMap<IntList>();
|
var relicDrops = new Int2ObjectOpenHashMap<IntList>();
|
||||||
|
|||||||
@@ -1,24 +1,80 @@
|
|||||||
package emu.lunarcore.data.excel;
|
package emu.lunarcore.data.excel;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import emu.lunarcore.GameConstants;
|
||||||
|
import emu.lunarcore.data.GameData;
|
||||||
import emu.lunarcore.data.GameResource;
|
import emu.lunarcore.data.GameResource;
|
||||||
import emu.lunarcore.data.ResourceType;
|
import emu.lunarcore.data.ResourceType;
|
||||||
|
import emu.lunarcore.data.ResourceType.LoadPriority;
|
||||||
import emu.lunarcore.data.common.ItemParam;
|
import emu.lunarcore.data.common.ItemParam;
|
||||||
|
import emu.lunarcore.game.drops.DropParam;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ResourceType(name = {"MonsterDrop.json"})
|
@ResourceType(name = {"MonsterDrop.json"}, loadPriority = LoadPriority.LOW)
|
||||||
public class MonsterDropExcel extends GameResource {
|
public class MonsterDropExcel extends GameResource {
|
||||||
private int MonsterTemplateID;
|
private int MonsterTemplateID;
|
||||||
private int WorldLevel;
|
private int WorldLevel;
|
||||||
private int AvatarExpReward;
|
private int AvatarExpReward;
|
||||||
|
|
||||||
private List<ItemParam> DisplayItemList;
|
private List<ItemParam> DisplayItemList;
|
||||||
|
|
||||||
|
// Temp solution for handling drop tables
|
||||||
|
private transient List<DropParam> dropList;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return (MonsterTemplateID << 4) + WorldLevel;
|
return (MonsterTemplateID << 4) + WorldLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
// Temp way to pre-calculate drop list
|
||||||
|
if (this.getDisplayItemList() == null || this.getDisplayItemList().size() == 0) {
|
||||||
|
this.dropList = new ArrayList<>(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dropList = new ArrayList<>(this.getDisplayItemList().size());
|
||||||
|
|
||||||
|
for (var itemParam : this.getDisplayItemList()) {
|
||||||
|
// Add item param if the amount is already set in the excel
|
||||||
|
if (itemParam.getCount() > 0) {
|
||||||
|
dropList.add(new DropParam(itemParam.getId(), itemParam.getCount()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO drop rate is not correct
|
||||||
|
if (itemParam.getId() == GameConstants.MATERIAL_COIN_ID) {
|
||||||
|
dropList.add(new DropParam(itemParam.getId(), getAvatarExpReward()));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get item excel
|
||||||
|
ItemExcel itemExcel = GameData.getItemExcelMap().get(itemParam.getId());
|
||||||
|
if (itemExcel == null) continue;
|
||||||
|
|
||||||
|
// TODO drop rate is not correct
|
||||||
|
double mod = switch (itemExcel.getRarity()) {
|
||||||
|
case NotNormal -> 0.8;
|
||||||
|
case Rare -> 0.3;
|
||||||
|
case VeryRare -> 0.125;
|
||||||
|
case SuperRare -> 0;
|
||||||
|
default -> 1.0;
|
||||||
|
};
|
||||||
|
|
||||||
|
double baseAmount = this.getWorldLevel() + 3;
|
||||||
|
|
||||||
|
// Create drop param
|
||||||
|
var drop = new DropParam(itemParam.getId(), 1);
|
||||||
|
drop.setMaxCount((int) Math.ceil(baseAmount * mod));
|
||||||
|
drop.setMinCount((int) Math.floor(baseAmount * mod * 0.5));
|
||||||
|
|
||||||
|
if (drop.getMaxCount() > 0) {
|
||||||
|
dropList.add(drop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import emu.lunarcore.GameConstants;
|
import emu.lunarcore.GameConstants;
|
||||||
import emu.lunarcore.data.GameData;
|
import emu.lunarcore.data.GameData;
|
||||||
import emu.lunarcore.data.common.ItemParam;
|
|
||||||
import emu.lunarcore.data.excel.ItemExcel;
|
import emu.lunarcore.data.excel.ItemExcel;
|
||||||
import emu.lunarcore.game.battle.Battle;
|
import emu.lunarcore.game.battle.Battle;
|
||||||
import emu.lunarcore.game.inventory.GameItem;
|
import emu.lunarcore.game.inventory.GameItem;
|
||||||
@@ -28,19 +27,10 @@ public class DropService extends BaseGameService {
|
|||||||
// Calculate drops from monsters
|
// Calculate drops from monsters
|
||||||
for (EntityMonster monster : battle.getNpcMonsters()) {
|
for (EntityMonster monster : battle.getNpcMonsters()) {
|
||||||
var dropExcel = GameData.getMonsterDropExcel(monster.getExcel().getId(), monster.getWorldLevel());
|
var dropExcel = GameData.getMonsterDropExcel(monster.getExcel().getId(), monster.getWorldLevel());
|
||||||
if (dropExcel == null || dropExcel.getDisplayItemList() == null) {
|
if (dropExcel == null) continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ItemParam param : dropExcel.getDisplayItemList()) {
|
for (var dropParam : dropExcel.getDropList()) {
|
||||||
int id = param.getId();
|
dropParam.roll(dropMap);
|
||||||
int count = Utils.randomRange(0, 3);
|
|
||||||
|
|
||||||
if (id == 2) {
|
|
||||||
count = dropExcel.getAvatarExpReward();
|
|
||||||
}
|
|
||||||
|
|
||||||
dropMap.addTo(id, count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import lombok.Getter;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public enum ItemRarity {
|
public enum ItemRarity {
|
||||||
Unknown (0),
|
Unknown (0),
|
||||||
Normal (1),
|
Normal (1),
|
||||||
NotNormal (2),
|
NotNormal (2),
|
||||||
Rare (3),
|
Rare (3),
|
||||||
VeryRare (4),
|
VeryRare (4),
|
||||||
SuperRare (5);
|
SuperRare (5);
|
||||||
|
|
||||||
private int val;
|
private int val;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user