Implement using fuels

This commit is contained in:
Melledy
2023-11-13 22:48:36 -08:00
parent a313903455
commit bb62a6a2cb
6 changed files with 1215 additions and 1 deletions

View File

@@ -0,0 +1,616 @@
// 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 UseItemCsReqOuterClass {
/**
* Protobuf type {@code UseItemCsReq}
*/
public static final class UseItemCsReq extends ProtoMessage<UseItemCsReq> implements Cloneable {
private static final long serialVersionUID = 0L;
/**
* <code>optional uint32 base_avatar_id = 1;</code>
*/
private int baseAvatarId;
/**
* <code>optional uint32 use_item_count = 4;</code>
*/
private int useItemCount;
/**
* <code>optional uint32 optional_reward_id = 6;</code>
*/
private int optionalRewardId;
/**
* <code>optional uint32 use_item_id = 14;</code>
*/
private int useItemId;
/**
* <code>optional .AvatarType use_avatar_type = 9;</code>
*/
private int useAvatarType;
private UseItemCsReq() {
}
/**
* @return a new empty instance of {@code UseItemCsReq}
*/
public static UseItemCsReq newInstance() {
return new UseItemCsReq();
}
/**
* <code>optional uint32 base_avatar_id = 1;</code>
* @return whether the baseAvatarId field is set
*/
public boolean hasBaseAvatarId() {
return (bitField0_ & 0x00000001) != 0;
}
/**
* <code>optional uint32 base_avatar_id = 1;</code>
* @return this
*/
public UseItemCsReq clearBaseAvatarId() {
bitField0_ &= ~0x00000001;
baseAvatarId = 0;
return this;
}
/**
* <code>optional uint32 base_avatar_id = 1;</code>
* @return the baseAvatarId
*/
public int getBaseAvatarId() {
return baseAvatarId;
}
/**
* <code>optional uint32 base_avatar_id = 1;</code>
* @param value the baseAvatarId to set
* @return this
*/
public UseItemCsReq setBaseAvatarId(final int value) {
bitField0_ |= 0x00000001;
baseAvatarId = value;
return this;
}
/**
* <code>optional uint32 use_item_count = 4;</code>
* @return whether the useItemCount field is set
*/
public boolean hasUseItemCount() {
return (bitField0_ & 0x00000002) != 0;
}
/**
* <code>optional uint32 use_item_count = 4;</code>
* @return this
*/
public UseItemCsReq clearUseItemCount() {
bitField0_ &= ~0x00000002;
useItemCount = 0;
return this;
}
/**
* <code>optional uint32 use_item_count = 4;</code>
* @return the useItemCount
*/
public int getUseItemCount() {
return useItemCount;
}
/**
* <code>optional uint32 use_item_count = 4;</code>
* @param value the useItemCount to set
* @return this
*/
public UseItemCsReq setUseItemCount(final int value) {
bitField0_ |= 0x00000002;
useItemCount = value;
return this;
}
/**
* <code>optional uint32 optional_reward_id = 6;</code>
* @return whether the optionalRewardId field is set
*/
public boolean hasOptionalRewardId() {
return (bitField0_ & 0x00000004) != 0;
}
/**
* <code>optional uint32 optional_reward_id = 6;</code>
* @return this
*/
public UseItemCsReq clearOptionalRewardId() {
bitField0_ &= ~0x00000004;
optionalRewardId = 0;
return this;
}
/**
* <code>optional uint32 optional_reward_id = 6;</code>
* @return the optionalRewardId
*/
public int getOptionalRewardId() {
return optionalRewardId;
}
/**
* <code>optional uint32 optional_reward_id = 6;</code>
* @param value the optionalRewardId to set
* @return this
*/
public UseItemCsReq setOptionalRewardId(final int value) {
bitField0_ |= 0x00000004;
optionalRewardId = value;
return this;
}
/**
* <code>optional uint32 use_item_id = 14;</code>
* @return whether the useItemId field is set
*/
public boolean hasUseItemId() {
return (bitField0_ & 0x00000008) != 0;
}
/**
* <code>optional uint32 use_item_id = 14;</code>
* @return this
*/
public UseItemCsReq clearUseItemId() {
bitField0_ &= ~0x00000008;
useItemId = 0;
return this;
}
/**
* <code>optional uint32 use_item_id = 14;</code>
* @return the useItemId
*/
public int getUseItemId() {
return useItemId;
}
/**
* <code>optional uint32 use_item_id = 14;</code>
* @param value the useItemId to set
* @return this
*/
public UseItemCsReq setUseItemId(final int value) {
bitField0_ |= 0x00000008;
useItemId = value;
return this;
}
/**
* <code>optional .AvatarType use_avatar_type = 9;</code>
* @return whether the useAvatarType field is set
*/
public boolean hasUseAvatarType() {
return (bitField0_ & 0x00000010) != 0;
}
/**
* <code>optional .AvatarType use_avatar_type = 9;</code>
* @return this
*/
public UseItemCsReq clearUseAvatarType() {
bitField0_ &= ~0x00000010;
useAvatarType = 0;
return this;
}
/**
* <code>optional .AvatarType use_avatar_type = 9;</code>
* @return the useAvatarType
*/
public AvatarTypeOuterClass.AvatarType getUseAvatarType() {
return AvatarTypeOuterClass.AvatarType.forNumber(useAvatarType);
}
/**
* Gets the value of the internal enum store. The result is
* equivalent to {@link UseItemCsReq#getUseAvatarType()}.getNumber().
*
* @return numeric wire representation
*/
public int getUseAvatarTypeValue() {
return useAvatarType;
}
/**
* Sets the value of the internal enum store. This does not
* do any validity checks, so be sure to use appropriate value
* constants from {@link AvatarTypeOuterClass.AvatarType}. Setting an invalid value
* can cause {@link UseItemCsReq#getUseAvatarType()} to return null
*
* @param value the numeric wire value to set
* @return this
*/
public UseItemCsReq setUseAvatarTypeValue(final int value) {
bitField0_ |= 0x00000010;
useAvatarType = value;
return this;
}
/**
* <code>optional .AvatarType use_avatar_type = 9;</code>
* @param value the useAvatarType to set
* @return this
*/
public UseItemCsReq setUseAvatarType(final AvatarTypeOuterClass.AvatarType value) {
bitField0_ |= 0x00000010;
useAvatarType = value.getNumber();
return this;
}
@Override
public UseItemCsReq copyFrom(final UseItemCsReq other) {
cachedSize = other.cachedSize;
if ((bitField0_ | other.bitField0_) != 0) {
bitField0_ = other.bitField0_;
baseAvatarId = other.baseAvatarId;
useItemCount = other.useItemCount;
optionalRewardId = other.optionalRewardId;
useItemId = other.useItemId;
useAvatarType = other.useAvatarType;
}
return this;
}
@Override
public UseItemCsReq mergeFrom(final UseItemCsReq other) {
if (other.isEmpty()) {
return this;
}
cachedSize = -1;
if (other.hasBaseAvatarId()) {
setBaseAvatarId(other.baseAvatarId);
}
if (other.hasUseItemCount()) {
setUseItemCount(other.useItemCount);
}
if (other.hasOptionalRewardId()) {
setOptionalRewardId(other.optionalRewardId);
}
if (other.hasUseItemId()) {
setUseItemId(other.useItemId);
}
if (other.hasUseAvatarType()) {
setUseAvatarTypeValue(other.useAvatarType);
}
return this;
}
@Override
public UseItemCsReq clear() {
if (isEmpty()) {
return this;
}
cachedSize = -1;
bitField0_ = 0;
baseAvatarId = 0;
useItemCount = 0;
optionalRewardId = 0;
useItemId = 0;
useAvatarType = 0;
return this;
}
@Override
public UseItemCsReq clearQuick() {
if (isEmpty()) {
return this;
}
cachedSize = -1;
bitField0_ = 0;
return this;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof UseItemCsReq)) {
return false;
}
UseItemCsReq other = (UseItemCsReq) o;
return bitField0_ == other.bitField0_
&& (!hasBaseAvatarId() || baseAvatarId == other.baseAvatarId)
&& (!hasUseItemCount() || useItemCount == other.useItemCount)
&& (!hasOptionalRewardId() || optionalRewardId == other.optionalRewardId)
&& (!hasUseItemId() || useItemId == other.useItemId)
&& (!hasUseAvatarType() || useAvatarType == other.useAvatarType);
}
@Override
public void writeTo(final ProtoSink output) throws IOException {
if ((bitField0_ & 0x00000001) != 0) {
output.writeRawByte((byte) 8);
output.writeUInt32NoTag(baseAvatarId);
}
if ((bitField0_ & 0x00000002) != 0) {
output.writeRawByte((byte) 32);
output.writeUInt32NoTag(useItemCount);
}
if ((bitField0_ & 0x00000004) != 0) {
output.writeRawByte((byte) 48);
output.writeUInt32NoTag(optionalRewardId);
}
if ((bitField0_ & 0x00000008) != 0) {
output.writeRawByte((byte) 112);
output.writeUInt32NoTag(useItemId);
}
if ((bitField0_ & 0x00000010) != 0) {
output.writeRawByte((byte) 72);
output.writeEnumNoTag(useAvatarType);
}
}
@Override
protected int computeSerializedSize() {
int size = 0;
if ((bitField0_ & 0x00000001) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(baseAvatarId);
}
if ((bitField0_ & 0x00000002) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(useItemCount);
}
if ((bitField0_ & 0x00000004) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(optionalRewardId);
}
if ((bitField0_ & 0x00000008) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(useItemId);
}
if ((bitField0_ & 0x00000010) != 0) {
size += 1 + ProtoSink.computeEnumSizeNoTag(useAvatarType);
}
return size;
}
@Override
@SuppressWarnings("fallthrough")
public UseItemCsReq mergeFrom(final ProtoSource input) throws IOException {
// Enabled Fall-Through Optimization (QuickBuffers)
int tag = input.readTag();
while (true) {
switch (tag) {
case 8: {
// baseAvatarId
baseAvatarId = input.readUInt32();
bitField0_ |= 0x00000001;
tag = input.readTag();
if (tag != 32) {
break;
}
}
case 32: {
// useItemCount
useItemCount = input.readUInt32();
bitField0_ |= 0x00000002;
tag = input.readTag();
if (tag != 48) {
break;
}
}
case 48: {
// optionalRewardId
optionalRewardId = input.readUInt32();
bitField0_ |= 0x00000004;
tag = input.readTag();
if (tag != 112) {
break;
}
}
case 112: {
// useItemId
useItemId = input.readUInt32();
bitField0_ |= 0x00000008;
tag = input.readTag();
if (tag != 72) {
break;
}
}
case 72: {
// useAvatarType
final int value = input.readInt32();
if (AvatarTypeOuterClass.AvatarType.forNumber(value) != null) {
useAvatarType = value;
bitField0_ |= 0x00000010;
}
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.writeUInt32(FieldNames.baseAvatarId, baseAvatarId);
}
if ((bitField0_ & 0x00000002) != 0) {
output.writeUInt32(FieldNames.useItemCount, useItemCount);
}
if ((bitField0_ & 0x00000004) != 0) {
output.writeUInt32(FieldNames.optionalRewardId, optionalRewardId);
}
if ((bitField0_ & 0x00000008) != 0) {
output.writeUInt32(FieldNames.useItemId, useItemId);
}
if ((bitField0_ & 0x00000010) != 0) {
output.writeEnum(FieldNames.useAvatarType, useAvatarType, AvatarTypeOuterClass.AvatarType.converter());
}
output.endObject();
}
@Override
public UseItemCsReq mergeFrom(final JsonSource input) throws IOException {
if (!input.beginObject()) {
return this;
}
while (!input.isAtEnd()) {
switch (input.readFieldHash()) {
case 118022725:
case -1756826157: {
if (input.isAtField(FieldNames.baseAvatarId)) {
if (!input.trySkipNullValue()) {
baseAvatarId = input.readUInt32();
bitField0_ |= 0x00000001;
}
} else {
input.skipUnknownField();
}
break;
}
case -1104380939:
case 871430811: {
if (input.isAtField(FieldNames.useItemCount)) {
if (!input.trySkipNullValue()) {
useItemCount = input.readUInt32();
bitField0_ |= 0x00000002;
}
} else {
input.skipUnknownField();
}
break;
}
case -1391749078:
case -1451381236: {
if (input.isAtField(FieldNames.optionalRewardId)) {
if (!input.trySkipNullValue()) {
optionalRewardId = input.readUInt32();
bitField0_ |= 0x00000004;
}
} else {
input.skipUnknownField();
}
break;
}
case -815318027:
case 1396027151: {
if (input.isAtField(FieldNames.useItemId)) {
if (!input.trySkipNullValue()) {
useItemId = input.readUInt32();
bitField0_ |= 0x00000008;
}
} else {
input.skipUnknownField();
}
break;
}
case -1816914662:
case -1808431192: {
if (input.isAtField(FieldNames.useAvatarType)) {
if (!input.trySkipNullValue()) {
final AvatarTypeOuterClass.AvatarType value = input.readEnum(AvatarTypeOuterClass.AvatarType.converter());
if (value != null) {
useAvatarType = value.getNumber();
bitField0_ |= 0x00000010;
} else {
input.skipUnknownEnumValue();
}
}
} else {
input.skipUnknownField();
}
break;
}
default: {
input.skipUnknownField();
break;
}
}
}
input.endObject();
return this;
}
@Override
public UseItemCsReq clone() {
return new UseItemCsReq().copyFrom(this);
}
@Override
public boolean isEmpty() {
return ((bitField0_) == 0);
}
public static UseItemCsReq parseFrom(final byte[] data) throws InvalidProtocolBufferException {
return ProtoMessage.mergeFrom(new UseItemCsReq(), data).checkInitialized();
}
public static UseItemCsReq parseFrom(final ProtoSource input) throws IOException {
return ProtoMessage.mergeFrom(new UseItemCsReq(), input).checkInitialized();
}
public static UseItemCsReq parseFrom(final JsonSource input) throws IOException {
return ProtoMessage.mergeFrom(new UseItemCsReq(), input).checkInitialized();
}
/**
* @return factory for creating UseItemCsReq messages
*/
public static MessageFactory<UseItemCsReq> getFactory() {
return UseItemCsReqFactory.INSTANCE;
}
private enum UseItemCsReqFactory implements MessageFactory<UseItemCsReq> {
INSTANCE;
@Override
public UseItemCsReq create() {
return UseItemCsReq.newInstance();
}
}
/**
* Contains name constants used for serializing JSON
*/
static class FieldNames {
static final FieldName baseAvatarId = FieldName.forField("baseAvatarId", "base_avatar_id");
static final FieldName useItemCount = FieldName.forField("useItemCount", "use_item_count");
static final FieldName optionalRewardId = FieldName.forField("optionalRewardId", "optional_reward_id");
static final FieldName useItemId = FieldName.forField("useItemId", "use_item_id");
static final FieldName useAvatarType = FieldName.forField("useAvatarType", "use_avatar_type");
}
}
}

View File

@@ -0,0 +1,522 @@
// 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 UseItemScRspOuterClass {
/**
* Protobuf type {@code UseItemScRsp}
*/
public static final class UseItemScRsp extends ProtoMessage<UseItemScRsp> implements Cloneable {
private static final long serialVersionUID = 0L;
/**
* <code>optional uint32 use_item_id = 6;</code>
*/
private int useItemId;
/**
* <code>optional uint32 use_item_count = 10;</code>
*/
private int useItemCount;
/**
* <code>optional uint32 retcode = 13;</code>
*/
private int retcode;
/**
* <code>optional .ItemList return_data = 9;</code>
*/
private final ItemListOuterClass.ItemList returnData = ItemListOuterClass.ItemList.newInstance();
private UseItemScRsp() {
}
/**
* @return a new empty instance of {@code UseItemScRsp}
*/
public static UseItemScRsp newInstance() {
return new UseItemScRsp();
}
/**
* <code>optional uint32 use_item_id = 6;</code>
* @return whether the useItemId field is set
*/
public boolean hasUseItemId() {
return (bitField0_ & 0x00000001) != 0;
}
/**
* <code>optional uint32 use_item_id = 6;</code>
* @return this
*/
public UseItemScRsp clearUseItemId() {
bitField0_ &= ~0x00000001;
useItemId = 0;
return this;
}
/**
* <code>optional uint32 use_item_id = 6;</code>
* @return the useItemId
*/
public int getUseItemId() {
return useItemId;
}
/**
* <code>optional uint32 use_item_id = 6;</code>
* @param value the useItemId to set
* @return this
*/
public UseItemScRsp setUseItemId(final int value) {
bitField0_ |= 0x00000001;
useItemId = value;
return this;
}
/**
* <code>optional uint32 use_item_count = 10;</code>
* @return whether the useItemCount field is set
*/
public boolean hasUseItemCount() {
return (bitField0_ & 0x00000002) != 0;
}
/**
* <code>optional uint32 use_item_count = 10;</code>
* @return this
*/
public UseItemScRsp clearUseItemCount() {
bitField0_ &= ~0x00000002;
useItemCount = 0;
return this;
}
/**
* <code>optional uint32 use_item_count = 10;</code>
* @return the useItemCount
*/
public int getUseItemCount() {
return useItemCount;
}
/**
* <code>optional uint32 use_item_count = 10;</code>
* @param value the useItemCount to set
* @return this
*/
public UseItemScRsp setUseItemCount(final int value) {
bitField0_ |= 0x00000002;
useItemCount = value;
return this;
}
/**
* <code>optional uint32 retcode = 13;</code>
* @return whether the retcode field is set
*/
public boolean hasRetcode() {
return (bitField0_ & 0x00000004) != 0;
}
/**
* <code>optional uint32 retcode = 13;</code>
* @return this
*/
public UseItemScRsp clearRetcode() {
bitField0_ &= ~0x00000004;
retcode = 0;
return this;
}
/**
* <code>optional uint32 retcode = 13;</code>
* @return the retcode
*/
public int getRetcode() {
return retcode;
}
/**
* <code>optional uint32 retcode = 13;</code>
* @param value the retcode to set
* @return this
*/
public UseItemScRsp setRetcode(final int value) {
bitField0_ |= 0x00000004;
retcode = value;
return this;
}
/**
* <code>optional .ItemList return_data = 9;</code>
* @return whether the returnData field is set
*/
public boolean hasReturnData() {
return (bitField0_ & 0x00000008) != 0;
}
/**
* <code>optional .ItemList return_data = 9;</code>
* @return this
*/
public UseItemScRsp clearReturnData() {
bitField0_ &= ~0x00000008;
returnData.clear();
return this;
}
/**
* <code>optional .ItemList return_data = 9;</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 #getMutableReturnData()} if you want to modify it.
*
* @return internal storage object for reading
*/
public ItemListOuterClass.ItemList getReturnData() {
return returnData;
}
/**
* <code>optional .ItemList return_data = 9;</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 getMutableReturnData() {
bitField0_ |= 0x00000008;
return returnData;
}
/**
* <code>optional .ItemList return_data = 9;</code>
* @param value the returnData to set
* @return this
*/
public UseItemScRsp setReturnData(final ItemListOuterClass.ItemList value) {
bitField0_ |= 0x00000008;
returnData.copyFrom(value);
return this;
}
@Override
public UseItemScRsp copyFrom(final UseItemScRsp other) {
cachedSize = other.cachedSize;
if ((bitField0_ | other.bitField0_) != 0) {
bitField0_ = other.bitField0_;
useItemId = other.useItemId;
useItemCount = other.useItemCount;
retcode = other.retcode;
returnData.copyFrom(other.returnData);
}
return this;
}
@Override
public UseItemScRsp mergeFrom(final UseItemScRsp other) {
if (other.isEmpty()) {
return this;
}
cachedSize = -1;
if (other.hasUseItemId()) {
setUseItemId(other.useItemId);
}
if (other.hasUseItemCount()) {
setUseItemCount(other.useItemCount);
}
if (other.hasRetcode()) {
setRetcode(other.retcode);
}
if (other.hasReturnData()) {
getMutableReturnData().mergeFrom(other.returnData);
}
return this;
}
@Override
public UseItemScRsp clear() {
if (isEmpty()) {
return this;
}
cachedSize = -1;
bitField0_ = 0;
useItemId = 0;
useItemCount = 0;
retcode = 0;
returnData.clear();
return this;
}
@Override
public UseItemScRsp clearQuick() {
if (isEmpty()) {
return this;
}
cachedSize = -1;
bitField0_ = 0;
returnData.clearQuick();
return this;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof UseItemScRsp)) {
return false;
}
UseItemScRsp other = (UseItemScRsp) o;
return bitField0_ == other.bitField0_
&& (!hasUseItemId() || useItemId == other.useItemId)
&& (!hasUseItemCount() || useItemCount == other.useItemCount)
&& (!hasRetcode() || retcode == other.retcode)
&& (!hasReturnData() || returnData.equals(other.returnData));
}
@Override
public void writeTo(final ProtoSink output) throws IOException {
if ((bitField0_ & 0x00000001) != 0) {
output.writeRawByte((byte) 48);
output.writeUInt32NoTag(useItemId);
}
if ((bitField0_ & 0x00000002) != 0) {
output.writeRawByte((byte) 80);
output.writeUInt32NoTag(useItemCount);
}
if ((bitField0_ & 0x00000004) != 0) {
output.writeRawByte((byte) 104);
output.writeUInt32NoTag(retcode);
}
if ((bitField0_ & 0x00000008) != 0) {
output.writeRawByte((byte) 74);
output.writeMessageNoTag(returnData);
}
}
@Override
protected int computeSerializedSize() {
int size = 0;
if ((bitField0_ & 0x00000001) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(useItemId);
}
if ((bitField0_ & 0x00000002) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(useItemCount);
}
if ((bitField0_ & 0x00000004) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(retcode);
}
if ((bitField0_ & 0x00000008) != 0) {
size += 1 + ProtoSink.computeMessageSizeNoTag(returnData);
}
return size;
}
@Override
@SuppressWarnings("fallthrough")
public UseItemScRsp mergeFrom(final ProtoSource input) throws IOException {
// Enabled Fall-Through Optimization (QuickBuffers)
int tag = input.readTag();
while (true) {
switch (tag) {
case 48: {
// useItemId
useItemId = input.readUInt32();
bitField0_ |= 0x00000001;
tag = input.readTag();
if (tag != 80) {
break;
}
}
case 80: {
// useItemCount
useItemCount = input.readUInt32();
bitField0_ |= 0x00000002;
tag = input.readTag();
if (tag != 104) {
break;
}
}
case 104: {
// retcode
retcode = input.readUInt32();
bitField0_ |= 0x00000004;
tag = input.readTag();
if (tag != 74) {
break;
}
}
case 74: {
// returnData
input.readMessage(returnData);
bitField0_ |= 0x00000008;
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.writeUInt32(FieldNames.useItemId, useItemId);
}
if ((bitField0_ & 0x00000002) != 0) {
output.writeUInt32(FieldNames.useItemCount, useItemCount);
}
if ((bitField0_ & 0x00000004) != 0) {
output.writeUInt32(FieldNames.retcode, retcode);
}
if ((bitField0_ & 0x00000008) != 0) {
output.writeMessage(FieldNames.returnData, returnData);
}
output.endObject();
}
@Override
public UseItemScRsp mergeFrom(final JsonSource input) throws IOException {
if (!input.beginObject()) {
return this;
}
while (!input.isAtEnd()) {
switch (input.readFieldHash()) {
case -815318027:
case 1396027151: {
if (input.isAtField(FieldNames.useItemId)) {
if (!input.trySkipNullValue()) {
useItemId = input.readUInt32();
bitField0_ |= 0x00000001;
}
} else {
input.skipUnknownField();
}
break;
}
case -1104380939:
case 871430811: {
if (input.isAtField(FieldNames.useItemCount)) {
if (!input.trySkipNullValue()) {
useItemCount = input.readUInt32();
bitField0_ |= 0x00000002;
}
} else {
input.skipUnknownField();
}
break;
}
case 1097936398: {
if (input.isAtField(FieldNames.retcode)) {
if (!input.trySkipNullValue()) {
retcode = input.readUInt32();
bitField0_ |= 0x00000004;
}
} else {
input.skipUnknownField();
}
break;
}
case 1336707322:
case -1486739111: {
if (input.isAtField(FieldNames.returnData)) {
if (!input.trySkipNullValue()) {
input.readMessage(returnData);
bitField0_ |= 0x00000008;
}
} else {
input.skipUnknownField();
}
break;
}
default: {
input.skipUnknownField();
break;
}
}
}
input.endObject();
return this;
}
@Override
public UseItemScRsp clone() {
return new UseItemScRsp().copyFrom(this);
}
@Override
public boolean isEmpty() {
return ((bitField0_) == 0);
}
public static UseItemScRsp parseFrom(final byte[] data) throws InvalidProtocolBufferException {
return ProtoMessage.mergeFrom(new UseItemScRsp(), data).checkInitialized();
}
public static UseItemScRsp parseFrom(final ProtoSource input) throws IOException {
return ProtoMessage.mergeFrom(new UseItemScRsp(), input).checkInitialized();
}
public static UseItemScRsp parseFrom(final JsonSource input) throws IOException {
return ProtoMessage.mergeFrom(new UseItemScRsp(), input).checkInitialized();
}
/**
* @return factory for creating UseItemScRsp messages
*/
public static MessageFactory<UseItemScRsp> getFactory() {
return UseItemScRspFactory.INSTANCE;
}
private enum UseItemScRspFactory implements MessageFactory<UseItemScRsp> {
INSTANCE;
@Override
public UseItemScRsp create() {
return UseItemScRsp.newInstance();
}
}
/**
* Contains name constants used for serializing JSON
*/
static class FieldNames {
static final FieldName useItemId = FieldName.forField("useItemId", "use_item_id");
static final FieldName useItemCount = FieldName.forField("useItemCount", "use_item_count");
static final FieldName retcode = FieldName.forField("retcode");
static final FieldName returnData = FieldName.forField("returnData", "return_data");
}
}
}

View File

@@ -425,6 +425,27 @@ public class Inventory extends BasePlayerManager {
public boolean verifyHcoin(int cost) {
return this.getPlayer().getHcoin() >= cost;
}
// Use item
public List<GameItem> useItem(int itemId, int count, int baseAvatarId) {
// Verify that the player actually has the item
GameItem useItem = this.getMaterialByItemId(itemId);
if (useItem == null || useItem.getCount() < count) {
return null;
}
// Remove item from inventory
this.removeItem(useItem, count);
// Use the item now
// TODO write better handler for this later
if (itemId == 201) {
this.getPlayer().addStamina(60 * count);
}
return null;
}
// Equips

View File

@@ -360,7 +360,7 @@ public class Player {
}
public void addStamina(int amount) {
this.stamina = Math.min(this.stamina + amount, GameConstants.MAX_STAMINA);
this.stamina += amount;
this.sendPacket(new PacketStaminaInfoScNotify(this));
}

View File

@@ -0,0 +1,24 @@
package emu.lunarcore.server.packet.recv;
import java.util.List;
import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.proto.UseItemCsReqOuterClass.UseItemCsReq;
import emu.lunarcore.server.game.GameSession;
import emu.lunarcore.server.packet.CmdId;
import emu.lunarcore.server.packet.Opcodes;
import emu.lunarcore.server.packet.PacketHandler;
import emu.lunarcore.server.packet.send.PacketUseItemScRsp;
@Opcodes(CmdId.UseItemCsReq)
public class HandlerUseItemCsReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
var req = UseItemCsReq.parseFrom(data);
List<GameItem> returnItems = session.getPlayer().getInventory().useItem(req.getUseItemId(), req.getUseItemCount(), req.getBaseAvatarId());
session.send(new PacketUseItemScRsp(req.getUseItemId(), req.getUseItemCount(), returnItems));
}
}

View File

@@ -0,0 +1,31 @@
package emu.lunarcore.server.packet.send;
import java.util.List;
import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.proto.ItemListOuterClass.ItemList;
import emu.lunarcore.proto.UseItemScRspOuterClass.UseItemScRsp;
import emu.lunarcore.server.packet.BasePacket;
import emu.lunarcore.server.packet.CmdId;
public class PacketUseItemScRsp extends BasePacket {
public PacketUseItemScRsp(int itemId, int itemCount, List<GameItem> returnItems) {
super(CmdId.UseItemScRsp);
var itemList = ItemList.newInstance();
if (returnItems != null && returnItems.size() > 0) {
for (var item : returnItems) {
itemList.addItemList(item.toProto());
}
}
var data = UseItemScRsp.newInstance()
.setUseItemId(itemId)
.setUseItemCount(itemCount)
.setReturnData(itemList);
this.setData(data);
}
}