diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetGatherObject.java b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetGatherObject.java index 34c6bda44..b29271038 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetGatherObject.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetGatherObject.java @@ -59,12 +59,11 @@ public final class GadgetGatherObject extends GadgetContent { GameItem item = new GameItem(itemData, 1); player.getInventory().addItem(item, ActionReason.Gather); - getGadget() - .getScene() - .getScriptManager() - .callEvent( - new ScriptArgs( - getGadget().getGroupId(), EventType.EVENT_GATHER, getGadget().getConfigId())); + var ScriptArgs = new ScriptArgs(getGadget().getGroupId(), EventType.EVENT_GATHER, getGadget().getConfigId()); + if(getGadget().getMetaGadget() != null){ + ScriptArgs.setEventSource(getGadget().getMetaGadget().config_id); + } + getGadget().getScene().getScriptManager().callEvent(ScriptArgs); getGadget() .getScene() diff --git a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetObject.java b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetObject.java index f84a56438..c3284e937 100644 --- a/src/main/java/emu/grasscutter/game/entity/gadget/GadgetObject.java +++ b/src/main/java/emu/grasscutter/game/entity/gadget/GadgetObject.java @@ -1,18 +1,52 @@ package emu.grasscutter.game.entity.gadget; +import emu.grasscutter.data.GameData; +import emu.grasscutter.data.excels.GatherData; +import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.game.entity.EntityGadget; +import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.player.Player; +import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.net.proto.GadgetInteractReqOuterClass; +import emu.grasscutter.net.proto.InteractTypeOuterClass; import emu.grasscutter.net.proto.SceneGadgetInfoOuterClass; +import emu.grasscutter.scripts.constants.EventType; +import emu.grasscutter.scripts.data.ScriptArgs; +import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp; public class GadgetObject extends GadgetContent { + private int itemId; + public GadgetObject(EntityGadget gadget) { super(gadget); + GatherData gatherData = GameData.getGatherDataMap().get(gadget.getPointType()); + if (gatherData != null) { + this.itemId = gatherData.getItemId(); + } } @Override public boolean onInteract(Player player, GadgetInteractReqOuterClass.GadgetInteractReq req) { - return false; + // This is a workaround until a proper gadget interaction system can be put in place. + ItemData itemData = GameData.getItemDataMap().get(this.itemId); + if (itemData == null) { + return false; + } + + GameItem item = new GameItem(itemData, 1); + player.getInventory().addItem(item, ActionReason.Gather); + + var ScriptArgs = new ScriptArgs(getGadget().getGroupId(), EventType.EVENT_GATHER, getGadget().getConfigId()); + if(getGadget().getMetaGadget() != null){ + ScriptArgs.setEventSource(getGadget().getMetaGadget().config_id); + } + getGadget().getScene().getScriptManager().callEvent(ScriptArgs); + + getGadget() + .getScene() + .broadcastPacket( + new PacketGadgetInteractRsp(getGadget(), InteractTypeOuterClass.InteractType.INTERACT_TYPE_GATHER)); + return true; } @Override