mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-26 07:15:43 +00:00
Check materials and mora
This commit is contained in:
parent
5db5c90a8b
commit
a668bd6ec1
@ -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;
|
||||
}
|
||||
}
|
@ -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<MaterialItemsData> materialItems;
|
||||
private List<ItemParamData> materialItems;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
@ -53,7 +53,7 @@ public class ForgeData extends GameResource {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public List<MaterialItemsData> getMaterialItems() {
|
||||
public List<ItemParamData> getMaterialItems() {
|
||||
return materialItems;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user