diff --git a/proto/ForgeQueueDataNotify.proto b/proto/ForgeQueueDataNotify.proto new file mode 100644 index 000000000..761f7618b --- /dev/null +++ b/proto/ForgeQueueDataNotify.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +option java_package = "emu.grasscutter.net.proto"; + +import "ForgeQueueData.proto"; + +// CmdId: 633 +// EnetChannelId: 0 +// EnetIsReliable: true +// IsAllowClient: true +message ForgeQueueDataNotify { + map forge_queue_map = 14; + repeated uint32 removed_forge_queue_list = 8; +} 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 235bddb9c..f74f53ba6 100644 --- a/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java +++ b/src/main/java/emu/grasscutter/game/managers/ForgingManager/ForgingManager.java @@ -22,6 +22,7 @@ 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.PacketForgeQueueDataNotify; import emu.grasscutter.server.packet.send.PacketForgeQueueManipulateRsp; import emu.grasscutter.server.packet.send.PacketForgeStartRsp; import emu.grasscutter.utils.Utils; @@ -111,6 +112,15 @@ public class ForgingManager { /********** Initiate forging process. **********/ + private void sendForgeQueueDataNotify() { + var queueData = this.determineCurrentForgeQueueData(); + this.player.sendPacket(new PacketForgeQueueDataNotify(queueData, List.of())); + } + private void sendForgeQueueDataNotify(int removed) { + var queueData = this.determineCurrentForgeQueueData(); + this.player.sendPacket(new PacketForgeQueueDataNotify(queueData, List.of(removed))); + } + public void handleForgeStartReq(ForgeStartReq req) { // Refuse if all queues are already full. if (this.player.getActiveForges().size() >= this.determineNumberOfQueues()) { @@ -169,8 +179,8 @@ public class ForgingManager { this.player.getActiveForges().add(activeForge); // Done. + this.sendForgeQueueDataNotify(); this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_SUCC)); - this.sendForgeDataNotify(); } /********** @@ -210,15 +220,16 @@ public class ForgingManager { remainingForge.setStartTime(currentTime); this.player.getActiveForges().set(queueId - 1, remainingForge); + this.sendForgeQueueDataNotify(); } // Otherwise, completely remove it. else { this.player.getActiveForges().remove(queueId - 1); + this.sendForgeQueueDataNotify(queueId); } // Send response. this.player.sendPacket(new PacketForgeQueueManipulateRsp(Retcode.RET_SUCC, ForgeQueueManipulateType.FORGE_QUEUE_MANIPULATE_TYPE_RECEIVE_OUTPUT, List.of(addItem), List.of(), List.of())); - this.sendForgeDataNotify(); } private void cancelForge(int queueId) { @@ -253,9 +264,12 @@ public class ForgingManager { GameItem returnMora = new GameItem(moraItem, data.getScoinCost() * forge.getCount()); returnItems.add(returnMora); + // Remove the forge queue. + this.player.getActiveForges().remove(queueId - 1); + this.sendForgeQueueDataNotify(queueId); + // Send response. this.player.sendPacket(new PacketForgeQueueManipulateRsp(Retcode.RET_SUCC, ForgeQueueManipulateType.FORGE_QUEUE_MANIPULATE_TYPE_STOP_FORGE, List.of(), returnItems, List.of())); - this.sendForgeDataNotify(); } public void handleForgeQueueManipulateReq(ForgeQueueManipulateReq req) { diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueDataNotify.java new file mode 100644 index 000000000..7c7f99fb2 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketForgeQueueDataNotify.java @@ -0,0 +1,26 @@ +package emu.grasscutter.server.packet.send; + +import java.util.List; +import java.util.Map; + +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.ForgeQueueDataNotifyOuterClass.ForgeQueueDataNotify; +import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; + +public class PacketForgeQueueDataNotify extends BasePacket { + + public PacketForgeQueueDataNotify(Map queueData, List removedQueues) { + super(PacketOpcodes.ForgeQueueDataNotify); + + ForgeQueueDataNotify.Builder builder = ForgeQueueDataNotify.newBuilder() + .addAllRemovedForgeQueueList(removedQueues); + + for (int queueId : queueData.keySet()) { + var data = queueData.get(queueId); + builder.putForgeQueueMap(queueId, data); + } + + this.setData(builder.build()); + } +}