diff --git a/src/main/java/emu/grasscutter/game/managers/ForgingManager/ActiveForgeData.java b/src/main/java/emu/grasscutter/game/managers/ForgingManager/ActiveForgeData.java new file mode 100644 index 000000000..9681aa43b --- /dev/null +++ b/src/main/java/emu/grasscutter/game/managers/ForgingManager/ActiveForgeData.java @@ -0,0 +1,52 @@ +package emu.grasscutter.game.managers.ForgingManager; + +import dev.morphia.annotations.Entity; + +@Entity +public class ActiveForgeData { + private int queueId; + private int forgeId; + private int avatarId; + + private int startTime; + private int forgeTime; + // private int finishedCount; + // private int unfinishedCount; + // private int nextFinishTimestamp; + // private int totalFinishTimestamp; + + public int getQueueId() { + return this.queueId; + } + public void setQueueId(int value) { + this.queueId = value; + } + + public int getForgeId() { + return this.forgeId; + } + public void setForgeId(int value) { + this.forgeId = value; + } + + public int getAvatarId() { + return this.avatarId; + } + public void setAvatarId(int value) { + this.avatarId = value; + } + + public int getStartTime() { + return this.startTime; + } + public void setStartTime(int value) { + this.startTime = value; + } + + public int getForgeTime() { + return this.forgeTime; + } + public void setForgeTime(int value) { + this.forgeTime = value; + } +} 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 238e5acd0..d07f0d68f 100644 --- a/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java +++ b/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java @@ -1,11 +1,17 @@ package emu.grasscutter.game.managers.ForgingManager; +import java.util.HashMap; +import java.util.Map; + import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.proto.ForgeStartReqOuterClass; +import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.server.packet.send.PacketForgeDataNotify; import emu.grasscutter.server.packet.send.PacketForgeFormulaDataNotify; import emu.grasscutter.server.packet.send.PacketForgeGetQueueDataRsp; +import emu.grasscutter.server.packet.send.PacketForgeStartRsp; public class ForgingManager { private final Player player; @@ -46,20 +52,49 @@ public class ForgingManager { : 1; } + private Map determineCurrentForgeQueueData() { + // Dummy for now. + ForgeQueueData data = ForgeQueueData.newBuilder() + .setQueueId(1) + .setForgeId(11001) + .setFinishCount(2) + .setUnfinishCount(3) + .setNextFinishTimestamp(0) + .setNextFinishTimestamp(0) + .setAvatarId(0) + .build(); + + Map res = new HashMap<>(); + res.put(1, data); + + return res; + } + public void sendForgeDataNotify() { // Determine the number of queues and unlocked items. int numQueues = this.determineNumberOfQueues(); var unlockedItems = this.player.getUnlockedForgingBlueprints(); + var queueData = this.determineCurrentForgeQueueData(); // Send notification. - this.player.sendPacket(new PacketForgeDataNotify(unlockedItems, numQueues)); + this.player.sendPacket(new PacketForgeDataNotify(unlockedItems, numQueues, queueData)); } public void handleForgeGetQueueDataReq() { // Determine the number of queues. int numQueues = this.determineNumberOfQueues(); + var queueData = this.determineCurrentForgeQueueData(); // Reply. - this.player.sendPacket(new PacketForgeGetQueueDataRsp(Retcode.RET_SUCC, numQueues)); + this.player.sendPacket(new PacketForgeGetQueueDataRsp(Retcode.RET_SUCC, numQueues, queueData)); } + + /********** + Initiate forging process. + **********/ + public void startForging(ForgeStartReqOuterClass.ForgeStartReq req) { + // Dummy for now. + this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_SUCC)); + } + } diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 5a07cee6c..99620c1d3 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -30,6 +30,7 @@ import emu.grasscutter.game.managers.InsectCaptureManager; import emu.grasscutter.game.managers.StaminaManager.StaminaManager; import emu.grasscutter.game.managers.SotSManager; import emu.grasscutter.game.managers.EnergyManager.EnergyManager; +import emu.grasscutter.game.managers.ForgingManager.ActiveForgeData; import emu.grasscutter.game.managers.ForgingManager.ForgingManager; import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.EntityType; @@ -92,6 +93,7 @@ public class Player { private Set flyCloakList; private Set costumeList; private Set unlockedForgingBlueprints; + private Map activeForges; private Integer widgetId; @@ -188,6 +190,7 @@ public class Player { this.flyCloakList = new HashSet<>(); this.costumeList = new HashSet<>(); this.unlockedForgingBlueprints = new HashSet<>(); + this.activeForges = new HashMap<>(); this.setSceneId(3); this.setRegionId(1); @@ -523,7 +526,11 @@ public class Player { } public Set getUnlockedForgingBlueprints() { - return unlockedForgingBlueprints; + return this.unlockedForgingBlueprints; + } + + public Map getActiveForges() { + return this.activeForges; } public MpSettingType getMpSetting() { diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeStartReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeStartReq.java new file mode 100644 index 000000000..bd483cd6b --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerForgeStartReq.java @@ -0,0 +1,23 @@ +package emu.grasscutter.server.packet.recv; + +import java.lang.invoke.StringConcatFactory; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeStartReqOuterClass; +import emu.grasscutter.net.proto.DeleteFriendReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketDelMailRsp; + +@Opcodes(PacketOpcodes.ForgeStartReq) +public class HandlerForgeStartReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + ForgeStartReqOuterClass.ForgeStartReq req = ForgeStartReqOuterClass.ForgeStartReq.parseFrom(payload); + session.getPlayer().getForgingManager().startForging(req); + } + +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java index bf17ab823..e8aa495b5 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeDataNotify.java @@ -1,30 +1,27 @@ package emu.grasscutter.server.packet.send; +import java.util.Map; + import emu.grasscutter.game.player.Player; import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.ForgeDataNotifyOuterClass.ForgeDataNotify; +import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; public class PacketForgeDataNotify extends BasePacket { - public PacketForgeDataNotify(Iterable unlockedItem, int numQueues) { + public PacketForgeDataNotify(Iterable unlockedItem, int numQueues, Map queueData) { super(PacketOpcodes.ForgeDataNotify); - /*int adventureRank = player.getLevel(); - int numQueues = - (adventureRank >= 15) ? 4 - : (adventureRank >= 10) ? 3 - : (adventureRank >= 5) ? 2 - : 1;*/ - - ForgeDataNotify proto = ForgeDataNotify.newBuilder() + ForgeDataNotify.Builder builder = ForgeDataNotify.newBuilder() .addAllForgeIdList(unlockedItem) - .setMaxQueueNum(numQueues) - .build(); + .setMaxQueueNum(numQueues); - // ToDo: Add the information for the actual forging queues - // and ongoing forges. + for (int queueId : queueData.keySet()) { + var data = queueData.get(queueId); + builder.putForgeQueueMap(queueId, data); + } - this.setData(proto); + this.setData(builder.build()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeGetQueueDataRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeGetQueueDataRsp.java index dcf080335..fa24b5ac3 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeGetQueueDataRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeGetQueueDataRsp.java @@ -1,23 +1,27 @@ package emu.grasscutter.server.packet.send; +import java.util.Map; + import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.ForgeGetQueueDataRspOuterClass.ForgeGetQueueDataRsp; +import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; public class PacketForgeGetQueueDataRsp extends BasePacket { - public PacketForgeGetQueueDataRsp(Retcode retcode, int numQueues) { + public PacketForgeGetQueueDataRsp(Retcode retcode, int numQueues, Map queueData) { super(PacketOpcodes.ForgeGetQueueDataRsp); - ForgeGetQueueDataRsp proto = ForgeGetQueueDataRsp.newBuilder() + ForgeGetQueueDataRsp.Builder builder = ForgeGetQueueDataRsp.newBuilder() .setRetcode(retcode.getNumber()) - .setMaxQueueNum(numQueues) - .build(); + .setMaxQueueNum(numQueues); - // ToDo: Add the information for the actual forging queues - // and ongoing forges. + for (int queueId : queueData.keySet()) { + var data = queueData.get(queueId); + builder.putForgeQueueMap(queueId, data); + } - this.setData(proto); + this.setData(builder.build()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeStartRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeStartRsp.java new file mode 100644 index 000000000..0a7dc42e9 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeStartRsp.java @@ -0,0 +1,23 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeStartRspOuterClass.ForgeStartRsp; +import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; + +import java.util.ArrayList; +import java.util.List; + +public class PacketForgeStartRsp extends BasePacket { + + public PacketForgeStartRsp(Retcode retcode) { + super(PacketOpcodes.ForgeStartRsp); + + ForgeStartRsp proto = ForgeStartRsp.newBuilder() + .setRetcode(retcode.getNumber()) + .build(); + + this.setData(proto); + } +} \ No newline at end of file