mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 22:04:36 +01:00
Implement item hints when receiving items
This commit is contained in:
@@ -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<ScenePlaneEventScNotify> implements Cloneable {
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
/**
|
||||
* <code>optional .ItemList get_item_list = 1;</code>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>optional .ItemList get_item_list = 1;</code>
|
||||
* @return whether the getItemList field is set
|
||||
*/
|
||||
public boolean hasGetItemList() {
|
||||
return (bitField0_ & 0x00000001) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>optional .ItemList get_item_list = 1;</code>
|
||||
* @return this
|
||||
*/
|
||||
public ScenePlaneEventScNotify clearGetItemList() {
|
||||
bitField0_ &= ~0x00000001;
|
||||
getItemList.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>optional .ItemList get_item_list = 1;</code>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>optional .ItemList get_item_list = 1;</code>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>optional .ItemList get_item_list = 1;</code>
|
||||
* @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<ScenePlaneEventScNotify> getFactory() {
|
||||
return ScenePlaneEventScNotifyFactory.INSTANCE;
|
||||
}
|
||||
|
||||
private enum ScenePlaneEventScNotifyFactory implements MessageFactory<ScenePlaneEventScNotify> {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -33,17 +33,19 @@ public class GiveCommand implements CommandHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup items
|
||||
List<GameItem> items = new LinkedList<>();
|
||||
|
||||
if (itemData.isEquippable()) {
|
||||
List<GameItem> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<GameItem> addItems(Collection<GameItem> items) {
|
||||
return addItems(items, false);
|
||||
}
|
||||
|
||||
public List<GameItem> addItems(Collection<GameItem> items, boolean showHint) {
|
||||
// Init results
|
||||
List<GameItem> results = new ArrayList<GameItem>(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;
|
||||
|
||||
@@ -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<GameItem> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user