Gadgets can be picked up too (#2272)

* Gadgets can be picked up too

* put in a warning
This commit is contained in:
Nazrin 2023-07-22 20:17:39 -07:00 committed by GitHub
parent ddc082fc97
commit fe169398ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 7 deletions

View File

@ -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()

View File

@ -1,20 +1,54 @@
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) {
// 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
public void onBuildProto(SceneGadgetInfoOuterClass.SceneGadgetInfo.Builder gadgetInfo) {}
}