Implement drop rates for world monster drops

This commit is contained in:
Melledy 2023-12-16 02:00:28 -08:00
parent 2b5141882e
commit 6925ef4fe6
4 changed files with 73 additions and 21 deletions

View File

@ -25,6 +25,7 @@ public class MappingInfoExcel extends GameResource {
private String FarmType; // is enum
private List<ItemParam> DisplayItemList;
// Temp solution for handling drop tables
private transient List<DropParam> dropList;
@Override
@ -35,7 +36,12 @@ public class MappingInfoExcel extends GameResource {
@Override
public void onLoad() {
// 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 relicDrops = new Int2ObjectOpenHashMap<IntList>();

View File

@ -1,24 +1,80 @@
package emu.lunarcore.data.excel;
import java.util.ArrayList;
import java.util.List;
import emu.lunarcore.GameConstants;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.GameResource;
import emu.lunarcore.data.ResourceType;
import emu.lunarcore.data.ResourceType.LoadPriority;
import emu.lunarcore.data.common.ItemParam;
import emu.lunarcore.game.drops.DropParam;
import lombok.Getter;
@Getter
@ResourceType(name = {"MonsterDrop.json"})
@ResourceType(name = {"MonsterDrop.json"}, loadPriority = LoadPriority.LOW)
public class MonsterDropExcel extends GameResource {
private int MonsterTemplateID;
private int WorldLevel;
private int AvatarExpReward;
private List<ItemParam> DisplayItemList;
// Temp solution for handling drop tables
private transient List<DropParam> dropList;
@Override
public int getId() {
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);
}
}
}
}

View File

@ -5,7 +5,6 @@ import java.util.List;
import emu.lunarcore.GameConstants;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.common.ItemParam;
import emu.lunarcore.data.excel.ItemExcel;
import emu.lunarcore.game.battle.Battle;
import emu.lunarcore.game.inventory.GameItem;
@ -28,19 +27,10 @@ public class DropService extends BaseGameService {
// Calculate drops from monsters
for (EntityMonster monster : battle.getNpcMonsters()) {
var dropExcel = GameData.getMonsterDropExcel(monster.getExcel().getId(), monster.getWorldLevel());
if (dropExcel == null || dropExcel.getDisplayItemList() == null) {
continue;
}
if (dropExcel == null) continue;
for (ItemParam param : dropExcel.getDisplayItemList()) {
int id = param.getId();
int count = Utils.randomRange(0, 3);
if (id == 2) {
count = dropExcel.getAvatarExpReward();
}
dropMap.addTo(id, count);
for (var dropParam : dropExcel.getDropList()) {
dropParam.roll(dropMap);
}
}

View File

@ -4,12 +4,12 @@ import lombok.Getter;
@Getter
public enum ItemRarity {
Unknown (0),
Normal (1),
NotNormal (2),
Rare (3),
VeryRare (4),
SuperRare (5);
Unknown (0),
Normal (1),
NotNormal (2),
Rare (3),
VeryRare (4),
SuperRare (5);
private int val;