Implement buying from shops

This commit is contained in:
Melledy
2023-10-16 03:57:04 -07:00
parent 3306629d29
commit b016f358bc
12 changed files with 1333 additions and 17 deletions

View File

@@ -0,0 +1,582 @@
// 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 BuyGoodsCsReqOuterClass {
/**
* Protobuf type {@code BuyGoodsCsReq}
*/
public static final class BuyGoodsCsReq extends ProtoMessage<BuyGoodsCsReq> implements Cloneable {
private static final long serialVersionUID = 0L;
/**
* <code>optional uint32 goods_num = 2;</code>
*/
private int goodsNum;
/**
* <code>optional uint32 item_id = 7;</code>
*/
private int itemId;
/**
* <code>optional uint32 COMHCIAONKJ = 9;</code>
*/
private int cOMHCIAONKJ;
/**
* <code>optional uint32 shop_id = 13;</code>
*/
private int shopId;
/**
* <code>optional uint32 goods_id = 14;</code>
*/
private int goodsId;
private BuyGoodsCsReq() {
}
/**
* @return a new empty instance of {@code BuyGoodsCsReq}
*/
public static BuyGoodsCsReq newInstance() {
return new BuyGoodsCsReq();
}
/**
* <code>optional uint32 goods_num = 2;</code>
* @return whether the goodsNum field is set
*/
public boolean hasGoodsNum() {
return (bitField0_ & 0x00000001) != 0;
}
/**
* <code>optional uint32 goods_num = 2;</code>
* @return this
*/
public BuyGoodsCsReq clearGoodsNum() {
bitField0_ &= ~0x00000001;
goodsNum = 0;
return this;
}
/**
* <code>optional uint32 goods_num = 2;</code>
* @return the goodsNum
*/
public int getGoodsNum() {
return goodsNum;
}
/**
* <code>optional uint32 goods_num = 2;</code>
* @param value the goodsNum to set
* @return this
*/
public BuyGoodsCsReq setGoodsNum(final int value) {
bitField0_ |= 0x00000001;
goodsNum = value;
return this;
}
/**
* <code>optional uint32 item_id = 7;</code>
* @return whether the itemId field is set
*/
public boolean hasItemId() {
return (bitField0_ & 0x00000002) != 0;
}
/**
* <code>optional uint32 item_id = 7;</code>
* @return this
*/
public BuyGoodsCsReq clearItemId() {
bitField0_ &= ~0x00000002;
itemId = 0;
return this;
}
/**
* <code>optional uint32 item_id = 7;</code>
* @return the itemId
*/
public int getItemId() {
return itemId;
}
/**
* <code>optional uint32 item_id = 7;</code>
* @param value the itemId to set
* @return this
*/
public BuyGoodsCsReq setItemId(final int value) {
bitField0_ |= 0x00000002;
itemId = value;
return this;
}
/**
* <code>optional uint32 COMHCIAONKJ = 9;</code>
* @return whether the cOMHCIAONKJ field is set
*/
public boolean hasCOMHCIAONKJ() {
return (bitField0_ & 0x00000004) != 0;
}
/**
* <code>optional uint32 COMHCIAONKJ = 9;</code>
* @return this
*/
public BuyGoodsCsReq clearCOMHCIAONKJ() {
bitField0_ &= ~0x00000004;
cOMHCIAONKJ = 0;
return this;
}
/**
* <code>optional uint32 COMHCIAONKJ = 9;</code>
* @return the cOMHCIAONKJ
*/
public int getCOMHCIAONKJ() {
return cOMHCIAONKJ;
}
/**
* <code>optional uint32 COMHCIAONKJ = 9;</code>
* @param value the cOMHCIAONKJ to set
* @return this
*/
public BuyGoodsCsReq setCOMHCIAONKJ(final int value) {
bitField0_ |= 0x00000004;
cOMHCIAONKJ = value;
return this;
}
/**
* <code>optional uint32 shop_id = 13;</code>
* @return whether the shopId field is set
*/
public boolean hasShopId() {
return (bitField0_ & 0x00000008) != 0;
}
/**
* <code>optional uint32 shop_id = 13;</code>
* @return this
*/
public BuyGoodsCsReq clearShopId() {
bitField0_ &= ~0x00000008;
shopId = 0;
return this;
}
/**
* <code>optional uint32 shop_id = 13;</code>
* @return the shopId
*/
public int getShopId() {
return shopId;
}
/**
* <code>optional uint32 shop_id = 13;</code>
* @param value the shopId to set
* @return this
*/
public BuyGoodsCsReq setShopId(final int value) {
bitField0_ |= 0x00000008;
shopId = value;
return this;
}
/**
* <code>optional uint32 goods_id = 14;</code>
* @return whether the goodsId field is set
*/
public boolean hasGoodsId() {
return (bitField0_ & 0x00000010) != 0;
}
/**
* <code>optional uint32 goods_id = 14;</code>
* @return this
*/
public BuyGoodsCsReq clearGoodsId() {
bitField0_ &= ~0x00000010;
goodsId = 0;
return this;
}
/**
* <code>optional uint32 goods_id = 14;</code>
* @return the goodsId
*/
public int getGoodsId() {
return goodsId;
}
/**
* <code>optional uint32 goods_id = 14;</code>
* @param value the goodsId to set
* @return this
*/
public BuyGoodsCsReq setGoodsId(final int value) {
bitField0_ |= 0x00000010;
goodsId = value;
return this;
}
@Override
public BuyGoodsCsReq copyFrom(final BuyGoodsCsReq other) {
cachedSize = other.cachedSize;
if ((bitField0_ | other.bitField0_) != 0) {
bitField0_ = other.bitField0_;
goodsNum = other.goodsNum;
itemId = other.itemId;
cOMHCIAONKJ = other.cOMHCIAONKJ;
shopId = other.shopId;
goodsId = other.goodsId;
}
return this;
}
@Override
public BuyGoodsCsReq mergeFrom(final BuyGoodsCsReq other) {
if (other.isEmpty()) {
return this;
}
cachedSize = -1;
if (other.hasGoodsNum()) {
setGoodsNum(other.goodsNum);
}
if (other.hasItemId()) {
setItemId(other.itemId);
}
if (other.hasCOMHCIAONKJ()) {
setCOMHCIAONKJ(other.cOMHCIAONKJ);
}
if (other.hasShopId()) {
setShopId(other.shopId);
}
if (other.hasGoodsId()) {
setGoodsId(other.goodsId);
}
return this;
}
@Override
public BuyGoodsCsReq clear() {
if (isEmpty()) {
return this;
}
cachedSize = -1;
bitField0_ = 0;
goodsNum = 0;
itemId = 0;
cOMHCIAONKJ = 0;
shopId = 0;
goodsId = 0;
return this;
}
@Override
public BuyGoodsCsReq 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 BuyGoodsCsReq)) {
return false;
}
BuyGoodsCsReq other = (BuyGoodsCsReq) o;
return bitField0_ == other.bitField0_
&& (!hasGoodsNum() || goodsNum == other.goodsNum)
&& (!hasItemId() || itemId == other.itemId)
&& (!hasCOMHCIAONKJ() || cOMHCIAONKJ == other.cOMHCIAONKJ)
&& (!hasShopId() || shopId == other.shopId)
&& (!hasGoodsId() || goodsId == other.goodsId);
}
@Override
public void writeTo(final ProtoSink output) throws IOException {
if ((bitField0_ & 0x00000001) != 0) {
output.writeRawByte((byte) 16);
output.writeUInt32NoTag(goodsNum);
}
if ((bitField0_ & 0x00000002) != 0) {
output.writeRawByte((byte) 56);
output.writeUInt32NoTag(itemId);
}
if ((bitField0_ & 0x00000004) != 0) {
output.writeRawByte((byte) 72);
output.writeUInt32NoTag(cOMHCIAONKJ);
}
if ((bitField0_ & 0x00000008) != 0) {
output.writeRawByte((byte) 104);
output.writeUInt32NoTag(shopId);
}
if ((bitField0_ & 0x00000010) != 0) {
output.writeRawByte((byte) 112);
output.writeUInt32NoTag(goodsId);
}
}
@Override
protected int computeSerializedSize() {
int size = 0;
if ((bitField0_ & 0x00000001) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(goodsNum);
}
if ((bitField0_ & 0x00000002) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(itemId);
}
if ((bitField0_ & 0x00000004) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(cOMHCIAONKJ);
}
if ((bitField0_ & 0x00000008) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(shopId);
}
if ((bitField0_ & 0x00000010) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(goodsId);
}
return size;
}
@Override
@SuppressWarnings("fallthrough")
public BuyGoodsCsReq mergeFrom(final ProtoSource input) throws IOException {
// Enabled Fall-Through Optimization (QuickBuffers)
int tag = input.readTag();
while (true) {
switch (tag) {
case 16: {
// goodsNum
goodsNum = input.readUInt32();
bitField0_ |= 0x00000001;
tag = input.readTag();
if (tag != 56) {
break;
}
}
case 56: {
// itemId
itemId = input.readUInt32();
bitField0_ |= 0x00000002;
tag = input.readTag();
if (tag != 72) {
break;
}
}
case 72: {
// cOMHCIAONKJ
cOMHCIAONKJ = input.readUInt32();
bitField0_ |= 0x00000004;
tag = input.readTag();
if (tag != 104) {
break;
}
}
case 104: {
// shopId
shopId = input.readUInt32();
bitField0_ |= 0x00000008;
tag = input.readTag();
if (tag != 112) {
break;
}
}
case 112: {
// goodsId
goodsId = input.readUInt32();
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.goodsNum, goodsNum);
}
if ((bitField0_ & 0x00000002) != 0) {
output.writeUInt32(FieldNames.itemId, itemId);
}
if ((bitField0_ & 0x00000004) != 0) {
output.writeUInt32(FieldNames.cOMHCIAONKJ, cOMHCIAONKJ);
}
if ((bitField0_ & 0x00000008) != 0) {
output.writeUInt32(FieldNames.shopId, shopId);
}
if ((bitField0_ & 0x00000010) != 0) {
output.writeUInt32(FieldNames.goodsId, goodsId);
}
output.endObject();
}
@Override
public BuyGoodsCsReq mergeFrom(final JsonSource input) throws IOException {
if (!input.beginObject()) {
return this;
}
while (!input.isAtEnd()) {
switch (input.readFieldHash()) {
case 2123191376:
case 1394923293: {
if (input.isAtField(FieldNames.goodsNum)) {
if (!input.trySkipNullValue()) {
goodsNum = input.readUInt32();
bitField0_ |= 0x00000001;
}
} else {
input.skipUnknownField();
}
break;
}
case -1178662002:
case 2116204999: {
if (input.isAtField(FieldNames.itemId)) {
if (!input.trySkipNullValue()) {
itemId = input.readUInt32();
bitField0_ |= 0x00000002;
}
} else {
input.skipUnknownField();
}
break;
}
case -2097477198: {
if (input.isAtField(FieldNames.cOMHCIAONKJ)) {
if (!input.trySkipNullValue()) {
cOMHCIAONKJ = input.readUInt32();
bitField0_ |= 0x00000004;
}
} else {
input.skipUnknownField();
}
break;
}
case -903151951:
case 2067081988: {
if (input.isAtField(FieldNames.shopId)) {
if (!input.trySkipNullValue()) {
shopId = input.readUInt32();
bitField0_ |= 0x00000008;
}
} else {
input.skipUnknownField();
}
break;
}
case 207037201:
case 2123207332: {
if (input.isAtField(FieldNames.goodsId)) {
if (!input.trySkipNullValue()) {
goodsId = input.readUInt32();
bitField0_ |= 0x00000010;
}
} else {
input.skipUnknownField();
}
break;
}
default: {
input.skipUnknownField();
break;
}
}
}
input.endObject();
return this;
}
@Override
public BuyGoodsCsReq clone() {
return new BuyGoodsCsReq().copyFrom(this);
}
@Override
public boolean isEmpty() {
return ((bitField0_) == 0);
}
public static BuyGoodsCsReq parseFrom(final byte[] data) throws InvalidProtocolBufferException {
return ProtoMessage.mergeFrom(new BuyGoodsCsReq(), data).checkInitialized();
}
public static BuyGoodsCsReq parseFrom(final ProtoSource input) throws IOException {
return ProtoMessage.mergeFrom(new BuyGoodsCsReq(), input).checkInitialized();
}
public static BuyGoodsCsReq parseFrom(final JsonSource input) throws IOException {
return ProtoMessage.mergeFrom(new BuyGoodsCsReq(), input).checkInitialized();
}
/**
* @return factory for creating BuyGoodsCsReq messages
*/
public static MessageFactory<BuyGoodsCsReq> getFactory() {
return BuyGoodsCsReqFactory.INSTANCE;
}
private enum BuyGoodsCsReqFactory implements MessageFactory<BuyGoodsCsReq> {
INSTANCE;
@Override
public BuyGoodsCsReq create() {
return BuyGoodsCsReq.newInstance();
}
}
/**
* Contains name constants used for serializing JSON
*/
static class FieldNames {
static final FieldName goodsNum = FieldName.forField("goodsNum", "goods_num");
static final FieldName itemId = FieldName.forField("itemId", "item_id");
static final FieldName cOMHCIAONKJ = FieldName.forField("COMHCIAONKJ");
static final FieldName shopId = FieldName.forField("shopId", "shop_id");
static final FieldName goodsId = FieldName.forField("goodsId", "goods_id");
}
}
}

View File

@@ -0,0 +1,603 @@
// 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 BuyGoodsScRspOuterClass {
/**
* Protobuf type {@code BuyGoodsScRsp}
*/
public static final class BuyGoodsScRsp extends ProtoMessage<BuyGoodsScRsp> implements Cloneable {
private static final long serialVersionUID = 0L;
/**
* <code>optional uint32 goods_buy_times = 1;</code>
*/
private int goodsBuyTimes;
/**
* <code>optional uint32 goods_id = 2;</code>
*/
private int goodsId;
/**
* <code>optional uint32 retcode = 12;</code>
*/
private int retcode;
/**
* <code>optional uint32 shop_id = 15;</code>
*/
private int shopId;
/**
* <code>optional .ItemList return_item_list = 13;</code>
*/
private final ItemListOuterClass.ItemList returnItemList = ItemListOuterClass.ItemList.newInstance();
private BuyGoodsScRsp() {
}
/**
* @return a new empty instance of {@code BuyGoodsScRsp}
*/
public static BuyGoodsScRsp newInstance() {
return new BuyGoodsScRsp();
}
/**
* <code>optional uint32 goods_buy_times = 1;</code>
* @return whether the goodsBuyTimes field is set
*/
public boolean hasGoodsBuyTimes() {
return (bitField0_ & 0x00000001) != 0;
}
/**
* <code>optional uint32 goods_buy_times = 1;</code>
* @return this
*/
public BuyGoodsScRsp clearGoodsBuyTimes() {
bitField0_ &= ~0x00000001;
goodsBuyTimes = 0;
return this;
}
/**
* <code>optional uint32 goods_buy_times = 1;</code>
* @return the goodsBuyTimes
*/
public int getGoodsBuyTimes() {
return goodsBuyTimes;
}
/**
* <code>optional uint32 goods_buy_times = 1;</code>
* @param value the goodsBuyTimes to set
* @return this
*/
public BuyGoodsScRsp setGoodsBuyTimes(final int value) {
bitField0_ |= 0x00000001;
goodsBuyTimes = value;
return this;
}
/**
* <code>optional uint32 goods_id = 2;</code>
* @return whether the goodsId field is set
*/
public boolean hasGoodsId() {
return (bitField0_ & 0x00000002) != 0;
}
/**
* <code>optional uint32 goods_id = 2;</code>
* @return this
*/
public BuyGoodsScRsp clearGoodsId() {
bitField0_ &= ~0x00000002;
goodsId = 0;
return this;
}
/**
* <code>optional uint32 goods_id = 2;</code>
* @return the goodsId
*/
public int getGoodsId() {
return goodsId;
}
/**
* <code>optional uint32 goods_id = 2;</code>
* @param value the goodsId to set
* @return this
*/
public BuyGoodsScRsp setGoodsId(final int value) {
bitField0_ |= 0x00000002;
goodsId = value;
return this;
}
/**
* <code>optional uint32 retcode = 12;</code>
* @return whether the retcode field is set
*/
public boolean hasRetcode() {
return (bitField0_ & 0x00000004) != 0;
}
/**
* <code>optional uint32 retcode = 12;</code>
* @return this
*/
public BuyGoodsScRsp clearRetcode() {
bitField0_ &= ~0x00000004;
retcode = 0;
return this;
}
/**
* <code>optional uint32 retcode = 12;</code>
* @return the retcode
*/
public int getRetcode() {
return retcode;
}
/**
* <code>optional uint32 retcode = 12;</code>
* @param value the retcode to set
* @return this
*/
public BuyGoodsScRsp setRetcode(final int value) {
bitField0_ |= 0x00000004;
retcode = value;
return this;
}
/**
* <code>optional uint32 shop_id = 15;</code>
* @return whether the shopId field is set
*/
public boolean hasShopId() {
return (bitField0_ & 0x00000008) != 0;
}
/**
* <code>optional uint32 shop_id = 15;</code>
* @return this
*/
public BuyGoodsScRsp clearShopId() {
bitField0_ &= ~0x00000008;
shopId = 0;
return this;
}
/**
* <code>optional uint32 shop_id = 15;</code>
* @return the shopId
*/
public int getShopId() {
return shopId;
}
/**
* <code>optional uint32 shop_id = 15;</code>
* @param value the shopId to set
* @return this
*/
public BuyGoodsScRsp setShopId(final int value) {
bitField0_ |= 0x00000008;
shopId = value;
return this;
}
/**
* <code>optional .ItemList return_item_list = 13;</code>
* @return whether the returnItemList field is set
*/
public boolean hasReturnItemList() {
return (bitField0_ & 0x00000010) != 0;
}
/**
* <code>optional .ItemList return_item_list = 13;</code>
* @return this
*/
public BuyGoodsScRsp clearReturnItemList() {
bitField0_ &= ~0x00000010;
returnItemList.clear();
return this;
}
/**
* <code>optional .ItemList return_item_list = 13;</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 #getMutableReturnItemList()} if you want to modify it.
*
* @return internal storage object for reading
*/
public ItemListOuterClass.ItemList getReturnItemList() {
return returnItemList;
}
/**
* <code>optional .ItemList return_item_list = 13;</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 getMutableReturnItemList() {
bitField0_ |= 0x00000010;
return returnItemList;
}
/**
* <code>optional .ItemList return_item_list = 13;</code>
* @param value the returnItemList to set
* @return this
*/
public BuyGoodsScRsp setReturnItemList(final ItemListOuterClass.ItemList value) {
bitField0_ |= 0x00000010;
returnItemList.copyFrom(value);
return this;
}
@Override
public BuyGoodsScRsp copyFrom(final BuyGoodsScRsp other) {
cachedSize = other.cachedSize;
if ((bitField0_ | other.bitField0_) != 0) {
bitField0_ = other.bitField0_;
goodsBuyTimes = other.goodsBuyTimes;
goodsId = other.goodsId;
retcode = other.retcode;
shopId = other.shopId;
returnItemList.copyFrom(other.returnItemList);
}
return this;
}
@Override
public BuyGoodsScRsp mergeFrom(final BuyGoodsScRsp other) {
if (other.isEmpty()) {
return this;
}
cachedSize = -1;
if (other.hasGoodsBuyTimes()) {
setGoodsBuyTimes(other.goodsBuyTimes);
}
if (other.hasGoodsId()) {
setGoodsId(other.goodsId);
}
if (other.hasRetcode()) {
setRetcode(other.retcode);
}
if (other.hasShopId()) {
setShopId(other.shopId);
}
if (other.hasReturnItemList()) {
getMutableReturnItemList().mergeFrom(other.returnItemList);
}
return this;
}
@Override
public BuyGoodsScRsp clear() {
if (isEmpty()) {
return this;
}
cachedSize = -1;
bitField0_ = 0;
goodsBuyTimes = 0;
goodsId = 0;
retcode = 0;
shopId = 0;
returnItemList.clear();
return this;
}
@Override
public BuyGoodsScRsp clearQuick() {
if (isEmpty()) {
return this;
}
cachedSize = -1;
bitField0_ = 0;
returnItemList.clearQuick();
return this;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof BuyGoodsScRsp)) {
return false;
}
BuyGoodsScRsp other = (BuyGoodsScRsp) o;
return bitField0_ == other.bitField0_
&& (!hasGoodsBuyTimes() || goodsBuyTimes == other.goodsBuyTimes)
&& (!hasGoodsId() || goodsId == other.goodsId)
&& (!hasRetcode() || retcode == other.retcode)
&& (!hasShopId() || shopId == other.shopId)
&& (!hasReturnItemList() || returnItemList.equals(other.returnItemList));
}
@Override
public void writeTo(final ProtoSink output) throws IOException {
if ((bitField0_ & 0x00000001) != 0) {
output.writeRawByte((byte) 8);
output.writeUInt32NoTag(goodsBuyTimes);
}
if ((bitField0_ & 0x00000002) != 0) {
output.writeRawByte((byte) 16);
output.writeUInt32NoTag(goodsId);
}
if ((bitField0_ & 0x00000004) != 0) {
output.writeRawByte((byte) 96);
output.writeUInt32NoTag(retcode);
}
if ((bitField0_ & 0x00000008) != 0) {
output.writeRawByte((byte) 120);
output.writeUInt32NoTag(shopId);
}
if ((bitField0_ & 0x00000010) != 0) {
output.writeRawByte((byte) 106);
output.writeMessageNoTag(returnItemList);
}
}
@Override
protected int computeSerializedSize() {
int size = 0;
if ((bitField0_ & 0x00000001) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(goodsBuyTimes);
}
if ((bitField0_ & 0x00000002) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(goodsId);
}
if ((bitField0_ & 0x00000004) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(retcode);
}
if ((bitField0_ & 0x00000008) != 0) {
size += 1 + ProtoSink.computeUInt32SizeNoTag(shopId);
}
if ((bitField0_ & 0x00000010) != 0) {
size += 1 + ProtoSink.computeMessageSizeNoTag(returnItemList);
}
return size;
}
@Override
@SuppressWarnings("fallthrough")
public BuyGoodsScRsp mergeFrom(final ProtoSource input) throws IOException {
// Enabled Fall-Through Optimization (QuickBuffers)
int tag = input.readTag();
while (true) {
switch (tag) {
case 8: {
// goodsBuyTimes
goodsBuyTimes = input.readUInt32();
bitField0_ |= 0x00000001;
tag = input.readTag();
if (tag != 16) {
break;
}
}
case 16: {
// goodsId
goodsId = input.readUInt32();
bitField0_ |= 0x00000002;
tag = input.readTag();
if (tag != 96) {
break;
}
}
case 96: {
// retcode
retcode = input.readUInt32();
bitField0_ |= 0x00000004;
tag = input.readTag();
if (tag != 120) {
break;
}
}
case 120: {
// shopId
shopId = input.readUInt32();
bitField0_ |= 0x00000008;
tag = input.readTag();
if (tag != 106) {
break;
}
}
case 106: {
// returnItemList
input.readMessage(returnItemList);
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.goodsBuyTimes, goodsBuyTimes);
}
if ((bitField0_ & 0x00000002) != 0) {
output.writeUInt32(FieldNames.goodsId, goodsId);
}
if ((bitField0_ & 0x00000004) != 0) {
output.writeUInt32(FieldNames.retcode, retcode);
}
if ((bitField0_ & 0x00000008) != 0) {
output.writeUInt32(FieldNames.shopId, shopId);
}
if ((bitField0_ & 0x00000010) != 0) {
output.writeMessage(FieldNames.returnItemList, returnItemList);
}
output.endObject();
}
@Override
public BuyGoodsScRsp mergeFrom(final JsonSource input) throws IOException {
if (!input.beginObject()) {
return this;
}
while (!input.isAtEnd()) {
switch (input.readFieldHash()) {
case -1410858538:
case -230536540: {
if (input.isAtField(FieldNames.goodsBuyTimes)) {
if (!input.trySkipNullValue()) {
goodsBuyTimes = input.readUInt32();
bitField0_ |= 0x00000001;
}
} else {
input.skipUnknownField();
}
break;
}
case 207037201:
case 2123207332: {
if (input.isAtField(FieldNames.goodsId)) {
if (!input.trySkipNullValue()) {
goodsId = 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 -903151951:
case 2067081988: {
if (input.isAtField(FieldNames.shopId)) {
if (!input.trySkipNullValue()) {
shopId = input.readUInt32();
bitField0_ |= 0x00000008;
}
} else {
input.skipUnknownField();
}
break;
}
case -6533215:
case -807051781: {
if (input.isAtField(FieldNames.returnItemList)) {
if (!input.trySkipNullValue()) {
input.readMessage(returnItemList);
bitField0_ |= 0x00000010;
}
} else {
input.skipUnknownField();
}
break;
}
default: {
input.skipUnknownField();
break;
}
}
}
input.endObject();
return this;
}
@Override
public BuyGoodsScRsp clone() {
return new BuyGoodsScRsp().copyFrom(this);
}
@Override
public boolean isEmpty() {
return ((bitField0_) == 0);
}
public static BuyGoodsScRsp parseFrom(final byte[] data) throws InvalidProtocolBufferException {
return ProtoMessage.mergeFrom(new BuyGoodsScRsp(), data).checkInitialized();
}
public static BuyGoodsScRsp parseFrom(final ProtoSource input) throws IOException {
return ProtoMessage.mergeFrom(new BuyGoodsScRsp(), input).checkInitialized();
}
public static BuyGoodsScRsp parseFrom(final JsonSource input) throws IOException {
return ProtoMessage.mergeFrom(new BuyGoodsScRsp(), input).checkInitialized();
}
/**
* @return factory for creating BuyGoodsScRsp messages
*/
public static MessageFactory<BuyGoodsScRsp> getFactory() {
return BuyGoodsScRspFactory.INSTANCE;
}
private enum BuyGoodsScRspFactory implements MessageFactory<BuyGoodsScRsp> {
INSTANCE;
@Override
public BuyGoodsScRsp create() {
return BuyGoodsScRsp.newInstance();
}
}
/**
* Contains name constants used for serializing JSON
*/
static class FieldNames {
static final FieldName goodsBuyTimes = FieldName.forField("goodsBuyTimes", "goods_buy_times");
static final FieldName goodsId = FieldName.forField("goodsId", "goods_id");
static final FieldName retcode = FieldName.forField("retcode");
static final FieldName shopId = FieldName.forField("shopId", "shop_id");
static final FieldName returnItemList = FieldName.forField("returnItemList", "return_item_list");
}
}
}

View File

@@ -13,6 +13,7 @@ public class GameConstants {
public static final String DEFAULT_NAME = "Trailblazer";
public static final int TRAILBLAZER_AVATAR_ID = 8001;
public static final int MAX_TRAILBLAZER_LEVEL = 70;
public static final int MATERIAL_COIN_ID = 2; // Material id for credits. DO NOT CHANGE
public static final int MAX_STAMINA = 240;
public static final int MAX_AVATARS_IN_TEAM = 4;
public static final int DEFAULT_TEAMS = 6;

View File

@@ -18,6 +18,11 @@ public class ItemParam {
public ItemParam() {
// Gson
}
public ItemParam(int id, int count) {
this.id = id;
this.count = count;
}
public ItemParam(ItemParamType type, int id, int count) {
this.type = type;

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import emu.lunarcore.GameConstants;
import emu.lunarcore.data.GameResource;
import emu.lunarcore.data.ResourceType;
import emu.lunarcore.data.ResourceType.LoadPriority;
@@ -46,7 +47,7 @@ public class AvatarPromotionExcel extends GameResource {
Iterator<ItemParam> it = this.PromotionCostList.iterator();
while (it.hasNext()) {
ItemParam param = it.next();
if (param.getId() == 2) {
if (param.getId() == GameConstants.MATERIAL_COIN_ID) {
this.PromotionCostCoin = param.getCount();
it.remove();
}

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import emu.lunarcore.GameConstants;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.GameResource;
import emu.lunarcore.data.ResourceType;
@@ -44,7 +45,7 @@ public class AvatarSkillTreeExcel extends GameResource {
Iterator<ItemParam> it = this.MaterialList.iterator();
while (it.hasNext()) {
ItemParam param = it.next();
if (param.getId() == 2) {
if (param.getId() == GameConstants.MATERIAL_COIN_ID) {
this.MaterialCostCoin = param.getCount();
it.remove();
}

View File

@@ -1,10 +1,16 @@
package emu.lunarcore.data.excel;
import java.util.ArrayList;
import java.util.List;
import emu.lunarcore.GameConstants;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.GameResource;
import emu.lunarcore.data.ResourceType;
import emu.lunarcore.data.ResourceType.LoadPriority;
import emu.lunarcore.data.common.ItemParam;
import emu.lunarcore.proto.GoodsOuterClass.Goods;
import lombok.AccessLevel;
import lombok.Getter;
@Getter
@@ -14,9 +20,15 @@ public class ShopGoodsExcel extends GameResource {
private int ItemID;
private int ItemCount;
private int ShopID;
@Getter(AccessLevel.NONE)
private int[] CurrencyList;
@Getter(AccessLevel.NONE)
private int[] CurrencyCostList;
private transient List<ItemParam> costList;
private transient int coinCost;
@Override
public int getId() {
return GoodsID;
@@ -24,10 +36,28 @@ public class ShopGoodsExcel extends GameResource {
@Override
public void onLoad() {
// Add to shop excel
ShopExcel shop = GameData.getShopExcelMap().get(this.ShopID);
if (shop == null) return;
shop.getGoods().put(this.GoodsID, this);
// Cache currency cost
this.costList = new ArrayList<>(CurrencyList.length);
for (int i = 0; i < CurrencyList.length; i++) {
if (CurrencyList[i] == GameConstants.MATERIAL_COIN_ID) {
this.coinCost = CurrencyCostList[i];
continue;
}
ItemParam param = new ItemParam(CurrencyList[i], CurrencyCostList[i]);
this.costList.add(param);
}
// Done - Clear references to save memory
this.CurrencyList = null;
this.CurrencyCostList = null;
}
public Goods toProto() {

View File

@@ -261,6 +261,11 @@ public class GameItem {
public Item toProto() {
return Item.newInstance()
.setItemId(this.getItemId())
.setNum(this.getCount());
.setNum(this.getCount())
.setLevel(this.getLevel())
.setMainAffixId(this.getMainAffix())
.setRank(this.getRank())
.setPromotion(this.getPromotion())
.setUniqueId(this.getInternalUid());
}
}

View File

@@ -111,15 +111,16 @@ public class Inventory extends BasePlayerManager {
return false;
}
public void addItems(Collection<GameItem> items) {
// Sanity
if (items.size() == 0) {
return;
}
// Init results and add items to inventory
public List<GameItem> addItems(Collection<GameItem> items) {
// Init results
List<GameItem> results = new ArrayList<GameItem>(items.size());
// Sanity
if (items.size() == 0) {
return results;
}
// Add to inventory
for (GameItem item : items) {
GameItem result = putItem(item);
if (result != null) {
@@ -131,6 +132,8 @@ public class Inventory extends BasePlayerManager {
if (results.size() > 0) {
getPlayer().sendPacket(new PacketPlayerSyncScNotify(results));
}
return results;
}
private synchronized GameItem putItem(GameItem item) {
@@ -235,8 +238,12 @@ public class Inventory extends BasePlayerManager {
break;
}
}
public void removeItemsByParams(Collection<ItemParam> items) {
removeItemsByParams(items, 1);
}
public void removeItemsByParams(Collection<ItemParam> items, int multiplier) {
// Sanity
if (items.size() == 0) {
return;
@@ -249,7 +256,7 @@ public class Inventory extends BasePlayerManager {
GameItem item = this.getItemByParam(param);
if (item == null) continue;
GameItem result = this.deleteItem(item, param.getCount());
GameItem result = this.deleteItem(item, param.getCount() * multiplier);
if (result != null) {
results.add(result);
}

View File

@@ -6,10 +6,7 @@ import java.util.List;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.common.ItemParam;
import emu.lunarcore.data.excel.AvatarPromotionExcel;
import emu.lunarcore.data.excel.AvatarRankExcel;
import emu.lunarcore.data.excel.AvatarSkillTreeExcel;
import emu.lunarcore.data.excel.EquipmentPromotionExcel;
import emu.lunarcore.data.excel.*;
import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.game.player.Player;
@@ -542,4 +539,50 @@ public class InventoryService extends BaseGameService {
// Send packet
player.sendPacket(new PacketSellItemScRsp(returnItems));
}
public List<GameItem> buyShopGoods(Player player, int shopId, int goodsId, int goodsNum) {
// Get shop and goods excels
ShopExcel shop = GameData.getShopExcelMap().get(shopId);
if (shop == null) return null;
ShopGoodsExcel goods = shop.getGoods().get(goodsId);
if (goods == null) return null;
// Verify items
for (ItemParam param : goods.getCostList()) {
GameItem item = player.getInventory().getItemByParam(param);
if (item == null || item.getCount() < param.getCount() * goodsNum) {
return null;
}
}
// Verify credits
if (player.getScoin() < goods.getCoinCost() * goodsNum) {
return null;
}
// Pay items
player.getInventory().removeItemsByParams(goods.getCostList(), goodsNum);
player.addSCoin(goods.getCoinCost() * goodsNum);
// Buy items
List<GameItem> items = new ArrayList<>();
ItemExcel itemExcel = GameData.getItemExcelMap().get(goods.getItemID());
if (!itemExcel.isEquippable()) {
GameItem item = new GameItem(itemExcel, goods.getItemCount());
items.add(item);
} else {
int num = goods.getItemCount() * goodsNum;
for (int i = 0; i < num; i++) {
GameItem item = new GameItem(itemExcel, 1);
items.add(item);
}
}
// Add to inventory
player.getInventory().addItems(items);
return items;
}
}

View File

@@ -1,16 +1,21 @@
package emu.lunarcore.server.packet.recv;
import emu.lunarcore.proto.BuyGoodsCsReqOuterClass.BuyGoodsCsReq;
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.PacketBuyGoodsScRsp;
@Opcodes(CmdId.BuyGoodsCsReq)
public class HandlerBuyGoodsCsReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
session.send(CmdId.BuyGoodsScRsp);
var req = BuyGoodsCsReq.parseFrom(data);
var items = session.getServer().getInventoryService().buyShopGoods(session.getPlayer(), req.getShopId(), req.getGoodsId(), req.getGoodsNum());
session.send(new PacketBuyGoodsScRsp(req, items));
}
}

View File

@@ -0,0 +1,33 @@
package emu.lunarcore.server.packet.send;
import java.util.List;
import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.proto.BuyGoodsCsReqOuterClass.BuyGoodsCsReq;
import emu.lunarcore.proto.BuyGoodsScRspOuterClass.BuyGoodsScRsp;
import emu.lunarcore.proto.ItemListOuterClass.ItemList;
import emu.lunarcore.server.packet.BasePacket;
import emu.lunarcore.server.packet.CmdId;
public class PacketBuyGoodsScRsp extends BasePacket {
public PacketBuyGoodsScRsp(BuyGoodsCsReq req, List<GameItem> items) {
super(CmdId.BuyGoodsScRsp);
var data = BuyGoodsScRsp.newInstance();
if (items != null) {
ItemList returnItems = ItemList.newInstance();
items.stream().map(GameItem::toProto).forEach(returnItems::addItemList);
data.setShopId(req.getShopId());
data.setGoodsId(req.getGoodsId());
data.setGoodsBuyTimes(req.getGoodsNum());
data.setReturnItemList(returnItems);
} else {
data.setRetcode(1);
}
this.setData(data);
}
}