diff --git a/src/main/java/emu/grasscutter/data/common/MaterialItemsData.java b/src/main/java/emu/grasscutter/data/common/MaterialItemsData.java deleted file mode 100644 index 682b92fb2..000000000 --- a/src/main/java/emu/grasscutter/data/common/MaterialItemsData.java +++ /dev/null @@ -1,22 +0,0 @@ -package emu.grasscutter.data.common; - -import java.util.List; - -public class MaterialItemsData { - private int id; - private int count; - - public int getId() { - return this.id; - } - public void setId(int value) { - this.id = value; - } - - public int getCount() { - return this.count; - } - public void setCount(int value) { - this.count = value; - } -} diff --git a/src/main/java/emu/grasscutter/data/excels/ForgeData.java b/src/main/java/emu/grasscutter/data/excels/ForgeData.java index e8cd7e8d1..6648f9bc4 100644 --- a/src/main/java/emu/grasscutter/data/excels/ForgeData.java +++ b/src/main/java/emu/grasscutter/data/excels/ForgeData.java @@ -5,7 +5,7 @@ import java.util.List; import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; import emu.grasscutter.data.ResourceType.LoadPriority; -import emu.grasscutter.data.common.MaterialItemsData; +import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.common.OpenCondData; @ResourceType(name = {"ForgeExcelConfigData.json"}, loadPriority = LoadPriority.HIGHEST) @@ -18,7 +18,7 @@ public class ForgeData extends GameResource { private int queueNum; private int scoinCost; private int priority; - private List materialItems; + private List materialItems; @Override public int getId() { @@ -53,7 +53,7 @@ public class ForgeData extends GameResource { return priority; } - public List getMaterialItems() { + public List getMaterialItems() { return materialItems; } diff --git a/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java b/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java index 8f16233ab..663bb5b2a 100644 --- a/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java +++ b/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java @@ -5,8 +5,10 @@ import java.util.Map; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; +import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.excels.ForgeData; import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.inventory.ItemType; import emu.grasscutter.game.player.Player; import emu.grasscutter.net.proto.ForgeStartReqOuterClass; import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; @@ -16,8 +18,6 @@ import emu.grasscutter.server.packet.send.PacketForgeFormulaDataNotify; import emu.grasscutter.server.packet.send.PacketForgeGetQueueDataRsp; import emu.grasscutter.server.packet.send.PacketForgeStartRsp; import emu.grasscutter.utils.Utils; -import emu.grasscutter.utils.ConfigContainer.Game; -import net.bytebuddy.dynamic.TypeResolutionStrategy.Active; public class ForgingManager { private final Player player; @@ -114,17 +114,41 @@ public class ForgingManager { // Get the required forging information for the target item. if (!GameData.getForgeDataMap().containsKey(req.getForgeId())) { this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_FAIL)); //ToDo: Probably the wrong return code. - Grasscutter.getLogger().error("Missing forgeId"); return; } ForgeData forgeData = GameData.getForgeDataMap().get(req.getForgeId()); // Check if we have enough of each material. - // ToDo. + for (var material : forgeData.getMaterialItems()) { + if (material.getItemId() == 0) { + continue; + } - // Consume material. - // ToDo. + int currentCount = this.player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(material.getItemId()).getCount(); + + if (currentCount < material.getCount() * req.getForgeCount()) { + this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_FORGE_POINT_NOT_ENOUGH)); //ToDo: Probably the wrong return code. + return; + } + } + + // Check if we have enough Mora. + if (this.player.getMora() < forgeData.getScoinCost() * req.getForgeCount()) { + this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_FORGE_POINT_NOT_ENOUGH)); //ToDo: Probably the wrong return code. + return; + } + + // Consume material and Mora. + for (var material : forgeData.getMaterialItems()) { + if (material.getItemId() == 0) { + continue; + } + + this.player.getInventory().removeItem(material.getItemId(), material.getCount() * req.getForgeCount()); + } + + this.player.setMora(this.player.getMora() - forgeData.getScoinCost() * req.getForgeCount()); // Create and add active forge. ActiveForgeData activeForge = new ActiveForgeData();