diff --git a/src/generated/main/emu/lunarcore/proto/ScenePlaneEventScNotifyOuterClass.java b/src/generated/main/emu/lunarcore/proto/ScenePlaneEventScNotifyOuterClass.java new file mode 100644 index 0000000..bf90150 --- /dev/null +++ b/src/generated/main/emu/lunarcore/proto/ScenePlaneEventScNotifyOuterClass.java @@ -0,0 +1,281 @@ +// Code generated by protocol buffer compiler. Do not edit! +package emu.lunarcore.proto; + +import java.io.IOException; +import us.hebi.quickbuf.FieldName; +import us.hebi.quickbuf.InvalidProtocolBufferException; +import us.hebi.quickbuf.JsonSink; +import us.hebi.quickbuf.JsonSource; +import us.hebi.quickbuf.MessageFactory; +import us.hebi.quickbuf.ProtoMessage; +import us.hebi.quickbuf.ProtoSink; +import us.hebi.quickbuf.ProtoSource; + +public final class ScenePlaneEventScNotifyOuterClass { + /** + * Protobuf type {@code ScenePlaneEventScNotify} + */ + public static final class ScenePlaneEventScNotify extends ProtoMessage implements Cloneable { + private static final long serialVersionUID = 0L; + + /** + * optional .ItemList get_item_list = 1; + */ + private final ItemListOuterClass.ItemList getItemList = ItemListOuterClass.ItemList.newInstance(); + + private ScenePlaneEventScNotify() { + } + + /** + * @return a new empty instance of {@code ScenePlaneEventScNotify} + */ + public static ScenePlaneEventScNotify newInstance() { + return new ScenePlaneEventScNotify(); + } + + /** + * optional .ItemList get_item_list = 1; + * @return whether the getItemList field is set + */ + public boolean hasGetItemList() { + return (bitField0_ & 0x00000001) != 0; + } + + /** + * optional .ItemList get_item_list = 1; + * @return this + */ + public ScenePlaneEventScNotify clearGetItemList() { + bitField0_ &= ~0x00000001; + getItemList.clear(); + return this; + } + + /** + * optional .ItemList get_item_list = 1; + * + * This method returns the internal storage object without modifying any has state. + * The returned object should not be modified and be treated as read-only. + * + * Use {@link #getMutableGetItemList()} if you want to modify it. + * + * @return internal storage object for reading + */ + public ItemListOuterClass.ItemList getGetItemList() { + return getItemList; + } + + /** + * optional .ItemList get_item_list = 1; + * + * This method returns the internal storage object and sets the corresponding + * has state. The returned object will become part of this message and its + * contents may be modified as long as the has state is not cleared. + * + * @return internal storage object for modifications + */ + public ItemListOuterClass.ItemList getMutableGetItemList() { + bitField0_ |= 0x00000001; + return getItemList; + } + + /** + * optional .ItemList get_item_list = 1; + * @param value the getItemList to set + * @return this + */ + public ScenePlaneEventScNotify setGetItemList(final ItemListOuterClass.ItemList value) { + bitField0_ |= 0x00000001; + getItemList.copyFrom(value); + return this; + } + + @Override + public ScenePlaneEventScNotify copyFrom(final ScenePlaneEventScNotify other) { + cachedSize = other.cachedSize; + if ((bitField0_ | other.bitField0_) != 0) { + bitField0_ = other.bitField0_; + getItemList.copyFrom(other.getItemList); + } + return this; + } + + @Override + public ScenePlaneEventScNotify mergeFrom(final ScenePlaneEventScNotify other) { + if (other.isEmpty()) { + return this; + } + cachedSize = -1; + if (other.hasGetItemList()) { + getMutableGetItemList().mergeFrom(other.getItemList); + } + return this; + } + + @Override + public ScenePlaneEventScNotify clear() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + getItemList.clear(); + return this; + } + + @Override + public ScenePlaneEventScNotify clearQuick() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + getItemList.clearQuick(); + return this; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof ScenePlaneEventScNotify)) { + return false; + } + ScenePlaneEventScNotify other = (ScenePlaneEventScNotify) o; + return bitField0_ == other.bitField0_ + && (!hasGetItemList() || getItemList.equals(other.getItemList)); + } + + @Override + public void writeTo(final ProtoSink output) throws IOException { + if ((bitField0_ & 0x00000001) != 0) { + output.writeRawByte((byte) 10); + output.writeMessageNoTag(getItemList); + } + } + + @Override + protected int computeSerializedSize() { + int size = 0; + if ((bitField0_ & 0x00000001) != 0) { + size += 1 + ProtoSink.computeMessageSizeNoTag(getItemList); + } + return size; + } + + @Override + @SuppressWarnings("fallthrough") + public ScenePlaneEventScNotify mergeFrom(final ProtoSource input) throws IOException { + // Enabled Fall-Through Optimization (QuickBuffers) + int tag = input.readTag(); + while (true) { + switch (tag) { + case 10: { + // getItemList + input.readMessage(getItemList); + bitField0_ |= 0x00000001; + tag = input.readTag(); + if (tag != 0) { + break; + } + } + case 0: { + return this; + } + default: { + if (!input.skipField(tag)) { + return this; + } + tag = input.readTag(); + break; + } + } + } + } + + @Override + public void writeTo(final JsonSink output) throws IOException { + output.beginObject(); + if ((bitField0_ & 0x00000001) != 0) { + output.writeMessage(FieldNames.getItemList, getItemList); + } + output.endObject(); + } + + @Override + public ScenePlaneEventScNotify mergeFrom(final JsonSource input) throws IOException { + if (!input.beginObject()) { + return this; + } + while (!input.isAtEnd()) { + switch (input.readFieldHash()) { + case -1039787065: + case -1626556255: { + if (input.isAtField(FieldNames.getItemList)) { + if (!input.trySkipNullValue()) { + input.readMessage(getItemList); + bitField0_ |= 0x00000001; + } + } else { + input.skipUnknownField(); + } + break; + } + default: { + input.skipUnknownField(); + break; + } + } + } + input.endObject(); + return this; + } + + @Override + public ScenePlaneEventScNotify clone() { + return new ScenePlaneEventScNotify().copyFrom(this); + } + + @Override + public boolean isEmpty() { + return ((bitField0_) == 0); + } + + public static ScenePlaneEventScNotify parseFrom(final byte[] data) throws + InvalidProtocolBufferException { + return ProtoMessage.mergeFrom(new ScenePlaneEventScNotify(), data).checkInitialized(); + } + + public static ScenePlaneEventScNotify parseFrom(final ProtoSource input) throws IOException { + return ProtoMessage.mergeFrom(new ScenePlaneEventScNotify(), input).checkInitialized(); + } + + public static ScenePlaneEventScNotify parseFrom(final JsonSource input) throws IOException { + return ProtoMessage.mergeFrom(new ScenePlaneEventScNotify(), input).checkInitialized(); + } + + /** + * @return factory for creating ScenePlaneEventScNotify messages + */ + public static MessageFactory getFactory() { + return ScenePlaneEventScNotifyFactory.INSTANCE; + } + + private enum ScenePlaneEventScNotifyFactory implements MessageFactory { + INSTANCE; + + @Override + public ScenePlaneEventScNotify create() { + return ScenePlaneEventScNotify.newInstance(); + } + } + + /** + * Contains name constants used for serializing JSON + */ + static class FieldNames { + static final FieldName getItemList = FieldName.forField("getItemList", "get_item_list"); + } + } +} diff --git a/src/main/java/emu/lunarcore/command/commands/GiveAllCommand.java b/src/main/java/emu/lunarcore/command/commands/GiveAllCommand.java index 3f85e1c..f326ae9 100644 --- a/src/main/java/emu/lunarcore/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/lunarcore/command/commands/GiveAllCommand.java @@ -40,7 +40,7 @@ public class GiveAllCommand implements CommandHandler { // Credits items.add(new GameItem(2, 50_000_000)); // Add - args.getTarget().getInventory().addItems(items); + args.getTarget().getInventory().addItems(items, true); // Send message this.sendMessage(sender, "Giving " + args.getTarget().getName() + " " + items.size() + " items"); } diff --git a/src/main/java/emu/lunarcore/command/commands/GiveCommand.java b/src/main/java/emu/lunarcore/command/commands/GiveCommand.java index eff6f1c..818c9c2 100644 --- a/src/main/java/emu/lunarcore/command/commands/GiveCommand.java +++ b/src/main/java/emu/lunarcore/command/commands/GiveCommand.java @@ -33,17 +33,19 @@ public class GiveCommand implements CommandHandler { return; } + // Setup items + List items = new LinkedList<>(); + if (itemData.isEquippable()) { - List items = new LinkedList<>(); for (int i = 0; i < amount; i++) { items.add(new GameItem(itemData)); } - args.getTarget().getInventory().addItems(items); } else { - GameItem item = new GameItem(itemData, amount); - args.getTarget().getInventory().addItem(item); + items.add(new GameItem(itemData, amount)); } - + + // Add and send message to player + args.getTarget().getInventory().addItems(items, true); args.getTarget().sendMessage("Giving " + args.getTarget().getName() + " " + amount + " of " + itemId); } diff --git a/src/main/java/emu/lunarcore/game/inventory/Inventory.java b/src/main/java/emu/lunarcore/game/inventory/Inventory.java index 86458ba..0c540cb 100644 --- a/src/main/java/emu/lunarcore/game/inventory/Inventory.java +++ b/src/main/java/emu/lunarcore/game/inventory/Inventory.java @@ -17,6 +17,7 @@ import emu.lunarcore.game.avatar.GameAvatar; import emu.lunarcore.game.player.BasePlayerManager; import emu.lunarcore.game.player.Player; import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify; +import emu.lunarcore.server.packet.send.PacketScenePlaneEventScNotify; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -81,10 +82,8 @@ public class Inventory extends BasePlayerManager { return null; } - - public boolean addItem(int itemId) { - return addItem(itemId, 1); - } + + // Add/Remove items public boolean addItem(int itemId, int count) { ItemExcel itemExcel = GameData.getItemExcelMap().get(itemId); @@ -113,6 +112,10 @@ public class Inventory extends BasePlayerManager { } public List addItems(Collection items) { + return addItems(items, false); + } + + public List addItems(Collection items, boolean showHint) { // Init results List results = new ArrayList(items.size()); @@ -132,6 +135,9 @@ public class Inventory extends BasePlayerManager { // Send packet (update) if (results.size() > 0) { getPlayer().sendPacket(new PacketPlayerSyncScNotify(results)); + if (showHint) { + getPlayer().sendPacket(new PacketScenePlaneEventScNotify(items)); + } } return results; diff --git a/src/main/java/emu/lunarcore/server/packet/send/PacketScenePlaneEventScNotify.java b/src/main/java/emu/lunarcore/server/packet/send/PacketScenePlaneEventScNotify.java new file mode 100644 index 0000000..4c6f0b1 --- /dev/null +++ b/src/main/java/emu/lunarcore/server/packet/send/PacketScenePlaneEventScNotify.java @@ -0,0 +1,41 @@ +package emu.lunarcore.server.packet.send; + +import java.util.Collection; + +import emu.lunarcore.game.inventory.GameItem; +import emu.lunarcore.proto.ScenePlaneEventScNotifyOuterClass.ScenePlaneEventScNotify; +import emu.lunarcore.server.packet.BasePacket; +import emu.lunarcore.server.packet.CmdId; + +public class PacketScenePlaneEventScNotify extends BasePacket { + + public PacketScenePlaneEventScNotify(GameItem item) { + super(CmdId.ScenePlaneEventScNotify); + + var data = ScenePlaneEventScNotify.newInstance(); + + if (item != null) { + data.getMutableGetItemList().addItemList(item.toProto()); + } else { + data.getMutableGetItemList(); + } + + this.setData(data); + } + + public PacketScenePlaneEventScNotify(Collection items) { + super(CmdId.ScenePlaneEventScNotify); + + var data = ScenePlaneEventScNotify.newInstance(); + + if (items != null && items.size() > 0) { + for (var item : items) { + data.getMutableGetItemList().addItemList(item.toProto()); + } + } else { + data.getMutableGetItemList(); + } + + this.setData(data); + } +}