From 6925ef4fe60ee688867b9793643ff6b7f82b1a8d Mon Sep 17 00:00:00 2001 From: Melledy <121644117+Melledy@users.noreply.github.com> Date: Sat, 16 Dec 2023 02:00:28 -0800 Subject: [PATCH] Implement drop rates for world monster drops --- .../data/excel/MappingInfoExcel.java | 8 ++- .../data/excel/MonsterDropExcel.java | 58 ++++++++++++++++++- .../emu/lunarcore/game/drops/DropService.java | 16 +---- .../emu/lunarcore/game/enums/ItemRarity.java | 12 ++-- 4 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/main/java/emu/lunarcore/data/excel/MappingInfoExcel.java b/src/main/java/emu/lunarcore/data/excel/MappingInfoExcel.java index 775bfdd..1fa1656 100644 --- a/src/main/java/emu/lunarcore/data/excel/MappingInfoExcel.java +++ b/src/main/java/emu/lunarcore/data/excel/MappingInfoExcel.java @@ -25,6 +25,7 @@ public class MappingInfoExcel extends GameResource { private String FarmType; // is enum private List DisplayItemList; + // Temp solution for handling drop tables private transient List 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(); diff --git a/src/main/java/emu/lunarcore/data/excel/MonsterDropExcel.java b/src/main/java/emu/lunarcore/data/excel/MonsterDropExcel.java index 4a38a75..501383a 100644 --- a/src/main/java/emu/lunarcore/data/excel/MonsterDropExcel.java +++ b/src/main/java/emu/lunarcore/data/excel/MonsterDropExcel.java @@ -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 DisplayItemList; + + // Temp solution for handling drop tables + private transient List 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); + } + } + } } diff --git a/src/main/java/emu/lunarcore/game/drops/DropService.java b/src/main/java/emu/lunarcore/game/drops/DropService.java index f7fd787..5465b65 100644 --- a/src/main/java/emu/lunarcore/game/drops/DropService.java +++ b/src/main/java/emu/lunarcore/game/drops/DropService.java @@ -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); } } diff --git a/src/main/java/emu/lunarcore/game/enums/ItemRarity.java b/src/main/java/emu/lunarcore/game/enums/ItemRarity.java index 0293b1c..72d6a9c 100644 --- a/src/main/java/emu/lunarcore/game/enums/ItemRarity.java +++ b/src/main/java/emu/lunarcore/game/enums/ItemRarity.java @@ -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;