From cef8b53dd6a701c9641c104590b9909209324c50 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Thu, 1 Jun 2023 21:28:12 -0400 Subject: [PATCH] Fix quest chests not having drop data --- .../game/entity/gadget/GadgetChest.java | 1 + .../recv/HandlerQuestCreateEntityReq.java | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetChest.java b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetChest.java index 270dc26ed..9250633cd 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetChest.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetChest.java @@ -75,6 +75,7 @@ public class GadgetChest extends GadgetContent { } else if (chest.chest_drop_id != 0) { status = dropSystem.handleChestDrop(chest.chest_drop_id, chest.drop_count, getGadget()); } + if (status) { getGadget().updateState(ScriptGadgetState.ChestOpened); player.sendPacket( diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestCreateEntityReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestCreateEntityReq.java index 66462c97a..2c2b5015c 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestCreateEntityReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerQuestCreateEntityReq.java @@ -1,15 +1,13 @@ package emu.grasscutter.server.packet.recv; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.excels.GadgetData; import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.data.excels.monster.MonsterData; import emu.grasscutter.game.entity.*; import emu.grasscutter.game.world.Position; -import emu.grasscutter.net.packet.Opcodes; -import emu.grasscutter.net.packet.PacketHandler; -import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.packet.*; import emu.grasscutter.net.proto.QuestCreateEntityReqOuterClass.QuestCreateEntityReq; +import emu.grasscutter.scripts.data.SceneGadget; import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.packet.send.PacketQuestCreateEntityRsp; import lombok.val; @@ -30,12 +28,29 @@ public class HandlerQuestCreateEntityReq extends PacketHandler { case GADGET_ID -> { val gadgetId = entity.getGadgetId(); val gadgetInfo = entity.getGadget(); - GadgetData gadgetData = GameData.getGadgetDataMap().get(gadgetId); + var gadgetData = GameData.getGadgetDataMap().get(gadgetId); gameEntity = switch (gadgetData.getType()) { case Vehicle -> new EntityVehicle(scene, session.getPlayer(), gadgetId, 0, pos, rot); + case Chest -> { + var chest = gadgetInfo.getChest(); + var gadget = new EntityGadget(scene, gadgetId, pos, rot); + // Create the gadget data for the chest. + var metaGadget = new SceneGadget(); + metaGadget.drop_count = 1; // TODO: Check if more items should be dropped. + metaGadget.chest_drop_id = chest.getChestDropId(); + metaGadget.setShowcutscene(chest.getIsShowCutscene()); + // Apply the gadget data to the chest. + gadget.setMetaGadget(metaGadget); + + yield gadget; + } default -> new EntityGadget(scene, gadgetId, pos, rot); }; + + if (gameEntity instanceof EntityGadget gadget) { + gadget.buildContent(); + } } case ITEM_ID -> { val itemId = entity.getItemId();