From bbc398d3740b5634eb656943d43d24a94ccd3076 Mon Sep 17 00:00:00 2001 From: zhaodice <63996691+zhaodice@users.noreply.github.com> Date: Fri, 3 Jun 2022 15:06:17 +0800 Subject: [PATCH] Incompletely implement about QuickUseWidgetReq WARNING: with the consuming of material widget ( Example: bomb ), this is just a implement designed to the decreasing of count ### Known Bug: No effects after using item but decrease. ### If you know which Packet could make the effects, feel free to contribute! --- .../packet/recv/HandlerQuickUseWidgetReq.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerQuickUseWidgetReq.java diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuickUseWidgetReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuickUseWidgetReq.java new file mode 100644 index 000000000..6e2b6097f --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuickUseWidgetReq.java @@ -0,0 +1,52 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.inventory.GameItem; +import emu.grasscutter.game.inventory.Inventory; +import emu.grasscutter.game.inventory.InventoryTab; +import emu.grasscutter.game.inventory.ItemType; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.QuickUseWidgetRspOuterClass.QuickUseWidgetRsp; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketPullRecentChatRsp; + +@Opcodes(PacketOpcodes.QuickUseWidgetReq) +public class HandlerQuickUseWidgetReq extends PacketHandler { + /* + * WARNING: with the consuming of material widget ( Example: bomb ), + * this is just a implement designed to the decreasing of count + * + * ### Known Bug: No effects after using item but decrease. ### + * + * If you know which Packet could make the effects, feel free to contribute! + * */ + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + QuickUseWidgetRsp.Builder proto = QuickUseWidgetRsp.newBuilder(); + Player pl = session.getPlayer(); + synchronized (pl) { + int materialId = pl.getWidgetId(); + Inventory inventory = session.getPlayer().getInventory(); + InventoryTab inventoryTab = inventory.getInventoryTab(ItemType.ITEM_MATERIAL); + GameItem item = inventoryTab.getItemById(materialId); + int remain = item.getCount(); + if (remain > 0) { + remain--; + if (remain <= 0) { + proto.setRetcode(1); + } else { + proto.setRetcode(0); + } + proto.setMaterialId(materialId); + inventory.removeItem(item,1);// decrease count + BasePacket rsp = new BasePacket(PacketOpcodes.QuickUseWidgetRsp); + rsp.setData(proto); + session.send(rsp); + // but no effects in the game, feel free to implement it! + } + } + } +}