diff --git a/src/generated/main/emu/lunarcore/proto/ChallengeRewardOuterClass.java b/src/generated/main/emu/lunarcore/proto/ChallengeRewardOuterClass.java new file mode 100644 index 0000000..8167cf6 --- /dev/null +++ b/src/generated/main/emu/lunarcore/proto/ChallengeRewardOuterClass.java @@ -0,0 +1,341 @@ +// 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 ChallengeRewardOuterClass { + /** + * Protobuf type {@code ChallengeReward} + */ + public static final class ChallengeReward extends ProtoMessage implements Cloneable { + private static final long serialVersionUID = 0L; + + /** + * optional uint64 taken_challenge_reward = 10; + */ + private long takenChallengeReward; + + /** + * optional uint32 group_id = 1; + */ + private int groupId; + + private ChallengeReward() { + } + + /** + * @return a new empty instance of {@code ChallengeReward} + */ + public static ChallengeReward newInstance() { + return new ChallengeReward(); + } + + /** + * optional uint64 taken_challenge_reward = 10; + * @return whether the takenChallengeReward field is set + */ + public boolean hasTakenChallengeReward() { + return (bitField0_ & 0x00000001) != 0; + } + + /** + * optional uint64 taken_challenge_reward = 10; + * @return this + */ + public ChallengeReward clearTakenChallengeReward() { + bitField0_ &= ~0x00000001; + takenChallengeReward = 0L; + return this; + } + + /** + * optional uint64 taken_challenge_reward = 10; + * @return the takenChallengeReward + */ + public long getTakenChallengeReward() { + return takenChallengeReward; + } + + /** + * optional uint64 taken_challenge_reward = 10; + * @param value the takenChallengeReward to set + * @return this + */ + public ChallengeReward setTakenChallengeReward(final long value) { + bitField0_ |= 0x00000001; + takenChallengeReward = value; + return this; + } + + /** + * optional uint32 group_id = 1; + * @return whether the groupId field is set + */ + public boolean hasGroupId() { + return (bitField0_ & 0x00000002) != 0; + } + + /** + * optional uint32 group_id = 1; + * @return this + */ + public ChallengeReward clearGroupId() { + bitField0_ &= ~0x00000002; + groupId = 0; + return this; + } + + /** + * optional uint32 group_id = 1; + * @return the groupId + */ + public int getGroupId() { + return groupId; + } + + /** + * optional uint32 group_id = 1; + * @param value the groupId to set + * @return this + */ + public ChallengeReward setGroupId(final int value) { + bitField0_ |= 0x00000002; + groupId = value; + return this; + } + + @Override + public ChallengeReward copyFrom(final ChallengeReward other) { + cachedSize = other.cachedSize; + if ((bitField0_ | other.bitField0_) != 0) { + bitField0_ = other.bitField0_; + takenChallengeReward = other.takenChallengeReward; + groupId = other.groupId; + } + return this; + } + + @Override + public ChallengeReward mergeFrom(final ChallengeReward other) { + if (other.isEmpty()) { + return this; + } + cachedSize = -1; + if (other.hasTakenChallengeReward()) { + setTakenChallengeReward(other.takenChallengeReward); + } + if (other.hasGroupId()) { + setGroupId(other.groupId); + } + return this; + } + + @Override + public ChallengeReward clear() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + takenChallengeReward = 0L; + groupId = 0; + return this; + } + + @Override + public ChallengeReward 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 ChallengeReward)) { + return false; + } + ChallengeReward other = (ChallengeReward) o; + return bitField0_ == other.bitField0_ + && (!hasTakenChallengeReward() || takenChallengeReward == other.takenChallengeReward) + && (!hasGroupId() || groupId == other.groupId); + } + + @Override + public void writeTo(final ProtoSink output) throws IOException { + if ((bitField0_ & 0x00000001) != 0) { + output.writeRawByte((byte) 80); + output.writeUInt64NoTag(takenChallengeReward); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeRawByte((byte) 8); + output.writeUInt32NoTag(groupId); + } + } + + @Override + protected int computeSerializedSize() { + int size = 0; + if ((bitField0_ & 0x00000001) != 0) { + size += 1 + ProtoSink.computeUInt64SizeNoTag(takenChallengeReward); + } + if ((bitField0_ & 0x00000002) != 0) { + size += 1 + ProtoSink.computeUInt32SizeNoTag(groupId); + } + return size; + } + + @Override + @SuppressWarnings("fallthrough") + public ChallengeReward mergeFrom(final ProtoSource input) throws IOException { + // Enabled Fall-Through Optimization (QuickBuffers) + int tag = input.readTag(); + while (true) { + switch (tag) { + case 80: { + // takenChallengeReward + takenChallengeReward = input.readUInt64(); + bitField0_ |= 0x00000001; + tag = input.readTag(); + if (tag != 8) { + break; + } + } + case 8: { + // groupId + groupId = input.readUInt32(); + bitField0_ |= 0x00000002; + 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.writeUInt64(FieldNames.takenChallengeReward, takenChallengeReward); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeUInt32(FieldNames.groupId, groupId); + } + output.endObject(); + } + + @Override + public ChallengeReward mergeFrom(final JsonSource input) throws IOException { + if (!input.beginObject()) { + return this; + } + while (!input.isAtEnd()) { + switch (input.readFieldHash()) { + case -743639637: + case 131659523: { + if (input.isAtField(FieldNames.takenChallengeReward)) { + if (!input.trySkipNullValue()) { + takenChallengeReward = input.readUInt64(); + bitField0_ |= 0x00000001; + } + } else { + input.skipUnknownField(); + } + break; + } + case 293428218: + case 506361563: { + if (input.isAtField(FieldNames.groupId)) { + if (!input.trySkipNullValue()) { + groupId = input.readUInt32(); + bitField0_ |= 0x00000002; + } + } else { + input.skipUnknownField(); + } + break; + } + default: { + input.skipUnknownField(); + break; + } + } + } + input.endObject(); + return this; + } + + @Override + public ChallengeReward clone() { + return new ChallengeReward().copyFrom(this); + } + + @Override + public boolean isEmpty() { + return ((bitField0_) == 0); + } + + public static ChallengeReward parseFrom(final byte[] data) throws + InvalidProtocolBufferException { + return ProtoMessage.mergeFrom(new ChallengeReward(), data).checkInitialized(); + } + + public static ChallengeReward parseFrom(final ProtoSource input) throws IOException { + return ProtoMessage.mergeFrom(new ChallengeReward(), input).checkInitialized(); + } + + public static ChallengeReward parseFrom(final JsonSource input) throws IOException { + return ProtoMessage.mergeFrom(new ChallengeReward(), input).checkInitialized(); + } + + /** + * @return factory for creating ChallengeReward messages + */ + public static MessageFactory getFactory() { + return ChallengeRewardFactory.INSTANCE; + } + + private enum ChallengeRewardFactory implements MessageFactory { + INSTANCE; + + @Override + public ChallengeReward create() { + return ChallengeReward.newInstance(); + } + } + + /** + * Contains name constants used for serializing JSON + */ + static class FieldNames { + static final FieldName takenChallengeReward = FieldName.forField("takenChallengeReward", "taken_challenge_reward"); + + static final FieldName groupId = FieldName.forField("groupId", "group_id"); + } + } +} diff --git a/src/generated/main/emu/lunarcore/proto/GetChallengeScRspOuterClass.java b/src/generated/main/emu/lunarcore/proto/GetChallengeScRspOuterClass.java index 57403b7..330de4c 100644 --- a/src/generated/main/emu/lunarcore/proto/GetChallengeScRspOuterClass.java +++ b/src/generated/main/emu/lunarcore/proto/GetChallengeScRspOuterClass.java @@ -24,6 +24,11 @@ public final class GetChallengeScRspOuterClass { */ private int retcode; + /** + * repeated .ChallengeReward challenge_reward_list = 1; + */ + private final RepeatedMessage challengeRewardList = RepeatedMessage.newEmptyInstance(ChallengeRewardOuterClass.ChallengeReward.getFactory()); + /** * repeated .Challenge challenge_list = 11; */ @@ -76,12 +81,83 @@ public final class GetChallengeScRspOuterClass { return this; } + /** + * repeated .ChallengeReward challenge_reward_list = 1; + * @return whether the challengeRewardList field is set + */ + public boolean hasChallengeRewardList() { + return (bitField0_ & 0x00000002) != 0; + } + + /** + * repeated .ChallengeReward challenge_reward_list = 1; + * @return this + */ + public GetChallengeScRsp clearChallengeRewardList() { + bitField0_ &= ~0x00000002; + challengeRewardList.clear(); + return this; + } + + /** + * repeated .ChallengeReward challenge_reward_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 #getMutableChallengeRewardList()} if you want to modify it. + * + * @return internal storage object for reading + */ + public RepeatedMessage getChallengeRewardList() { + return challengeRewardList; + } + + /** + * repeated .ChallengeReward challenge_reward_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 RepeatedMessage getMutableChallengeRewardList( + ) { + bitField0_ |= 0x00000002; + return challengeRewardList; + } + + /** + * repeated .ChallengeReward challenge_reward_list = 1; + * @param value the challengeRewardList to add + * @return this + */ + public GetChallengeScRsp addChallengeRewardList( + final ChallengeRewardOuterClass.ChallengeReward value) { + bitField0_ |= 0x00000002; + challengeRewardList.add(value); + return this; + } + + /** + * repeated .ChallengeReward challenge_reward_list = 1; + * @param values the challengeRewardList to add + * @return this + */ + public GetChallengeScRsp addAllChallengeRewardList( + final ChallengeRewardOuterClass.ChallengeReward... values) { + bitField0_ |= 0x00000002; + challengeRewardList.addAll(values); + return this; + } + /** * repeated .Challenge challenge_list = 11; * @return whether the challengeList field is set */ public boolean hasChallengeList() { - return (bitField0_ & 0x00000002) != 0; + return (bitField0_ & 0x00000004) != 0; } /** @@ -89,7 +165,7 @@ public final class GetChallengeScRspOuterClass { * @return this */ public GetChallengeScRsp clearChallengeList() { - bitField0_ &= ~0x00000002; + bitField0_ &= ~0x00000004; challengeList.clear(); return this; } @@ -118,7 +194,7 @@ public final class GetChallengeScRspOuterClass { * @return internal storage object for modifications */ public RepeatedMessage getMutableChallengeList() { - bitField0_ |= 0x00000002; + bitField0_ |= 0x00000004; return challengeList; } @@ -128,7 +204,7 @@ public final class GetChallengeScRspOuterClass { * @return this */ public GetChallengeScRsp addChallengeList(final ChallengeOuterClass.Challenge value) { - bitField0_ |= 0x00000002; + bitField0_ |= 0x00000004; challengeList.add(value); return this; } @@ -139,7 +215,7 @@ public final class GetChallengeScRspOuterClass { * @return this */ public GetChallengeScRsp addAllChallengeList(final ChallengeOuterClass.Challenge... values) { - bitField0_ |= 0x00000002; + bitField0_ |= 0x00000004; challengeList.addAll(values); return this; } @@ -150,6 +226,7 @@ public final class GetChallengeScRspOuterClass { if ((bitField0_ | other.bitField0_) != 0) { bitField0_ = other.bitField0_; retcode = other.retcode; + challengeRewardList.copyFrom(other.challengeRewardList); challengeList.copyFrom(other.challengeList); } return this; @@ -164,6 +241,9 @@ public final class GetChallengeScRspOuterClass { if (other.hasRetcode()) { setRetcode(other.retcode); } + if (other.hasChallengeRewardList()) { + getMutableChallengeRewardList().addAll(other.challengeRewardList); + } if (other.hasChallengeList()) { getMutableChallengeList().addAll(other.challengeList); } @@ -178,6 +258,7 @@ public final class GetChallengeScRspOuterClass { cachedSize = -1; bitField0_ = 0; retcode = 0; + challengeRewardList.clear(); challengeList.clear(); return this; } @@ -189,6 +270,7 @@ public final class GetChallengeScRspOuterClass { } cachedSize = -1; bitField0_ = 0; + challengeRewardList.clearQuick(); challengeList.clearQuick(); return this; } @@ -204,6 +286,7 @@ public final class GetChallengeScRspOuterClass { GetChallengeScRsp other = (GetChallengeScRsp) o; return bitField0_ == other.bitField0_ && (!hasRetcode() || retcode == other.retcode) + && (!hasChallengeRewardList() || challengeRewardList.equals(other.challengeRewardList)) && (!hasChallengeList() || challengeList.equals(other.challengeList)); } @@ -214,6 +297,12 @@ public final class GetChallengeScRspOuterClass { output.writeUInt32NoTag(retcode); } if ((bitField0_ & 0x00000002) != 0) { + for (int i = 0; i < challengeRewardList.length(); i++) { + output.writeRawByte((byte) 10); + output.writeMessageNoTag(challengeRewardList.get(i)); + } + } + if ((bitField0_ & 0x00000004) != 0) { for (int i = 0; i < challengeList.length(); i++) { output.writeRawByte((byte) 90); output.writeMessageNoTag(challengeList.get(i)); @@ -228,6 +317,9 @@ public final class GetChallengeScRspOuterClass { size += 1 + ProtoSink.computeUInt32SizeNoTag(retcode); } if ((bitField0_ & 0x00000002) != 0) { + size += (1 * challengeRewardList.length()) + ProtoSink.computeRepeatedMessageSizeNoTag(challengeRewardList); + } + if ((bitField0_ & 0x00000004) != 0) { size += (1 * challengeList.length()) + ProtoSink.computeRepeatedMessageSizeNoTag(challengeList); } return size; @@ -245,6 +337,14 @@ public final class GetChallengeScRspOuterClass { retcode = input.readUInt32(); bitField0_ |= 0x00000001; tag = input.readTag(); + if (tag != 10) { + break; + } + } + case 10: { + // challengeRewardList + tag = input.readRepeatedMessage(challengeRewardList, tag); + bitField0_ |= 0x00000002; if (tag != 90) { break; } @@ -252,7 +352,7 @@ public final class GetChallengeScRspOuterClass { case 90: { // challengeList tag = input.readRepeatedMessage(challengeList, tag); - bitField0_ |= 0x00000002; + bitField0_ |= 0x00000004; if (tag != 0) { break; } @@ -278,6 +378,9 @@ public final class GetChallengeScRspOuterClass { output.writeUInt32(FieldNames.retcode, retcode); } if ((bitField0_ & 0x00000002) != 0) { + output.writeRepeatedMessage(FieldNames.challengeRewardList, challengeRewardList); + } + if ((bitField0_ & 0x00000004) != 0) { output.writeRepeatedMessage(FieldNames.challengeList, challengeList); } output.endObject(); @@ -301,12 +404,24 @@ public final class GetChallengeScRspOuterClass { } break; } + case 1371323696: + case -2132566574: { + if (input.isAtField(FieldNames.challengeRewardList)) { + if (!input.trySkipNullValue()) { + input.readRepeatedMessage(challengeRewardList); + bitField0_ |= 0x00000002; + } + } else { + input.skipUnknownField(); + } + break; + } case -812402783: case 602944250: { if (input.isAtField(FieldNames.challengeList)) { if (!input.trySkipNullValue()) { input.readRepeatedMessage(challengeList); - bitField0_ |= 0x00000002; + bitField0_ |= 0x00000004; } } else { input.skipUnknownField(); @@ -368,6 +483,8 @@ public final class GetChallengeScRspOuterClass { static class FieldNames { static final FieldName retcode = FieldName.forField("retcode"); + static final FieldName challengeRewardList = FieldName.forField("challengeRewardList", "challenge_reward_list"); + static final FieldName challengeList = FieldName.forField("challengeList", "challenge_list"); } } diff --git a/src/generated/main/emu/lunarcore/proto/TakeChallengeRewardCsReqOuterClass.java b/src/generated/main/emu/lunarcore/proto/TakeChallengeRewardCsReqOuterClass.java new file mode 100644 index 0000000..7ac8afc --- /dev/null +++ b/src/generated/main/emu/lunarcore/proto/TakeChallengeRewardCsReqOuterClass.java @@ -0,0 +1,341 @@ +// 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 TakeChallengeRewardCsReqOuterClass { + /** + * Protobuf type {@code TakeChallengeRewardCsReq} + */ + public static final class TakeChallengeRewardCsReq extends ProtoMessage implements Cloneable { + private static final long serialVersionUID = 0L; + + /** + * optional uint32 group_id = 2; + */ + private int groupId; + + /** + * optional uint32 star_count = 13; + */ + private int starCount; + + private TakeChallengeRewardCsReq() { + } + + /** + * @return a new empty instance of {@code TakeChallengeRewardCsReq} + */ + public static TakeChallengeRewardCsReq newInstance() { + return new TakeChallengeRewardCsReq(); + } + + /** + * optional uint32 group_id = 2; + * @return whether the groupId field is set + */ + public boolean hasGroupId() { + return (bitField0_ & 0x00000001) != 0; + } + + /** + * optional uint32 group_id = 2; + * @return this + */ + public TakeChallengeRewardCsReq clearGroupId() { + bitField0_ &= ~0x00000001; + groupId = 0; + return this; + } + + /** + * optional uint32 group_id = 2; + * @return the groupId + */ + public int getGroupId() { + return groupId; + } + + /** + * optional uint32 group_id = 2; + * @param value the groupId to set + * @return this + */ + public TakeChallengeRewardCsReq setGroupId(final int value) { + bitField0_ |= 0x00000001; + groupId = value; + return this; + } + + /** + * optional uint32 star_count = 13; + * @return whether the starCount field is set + */ + public boolean hasStarCount() { + return (bitField0_ & 0x00000002) != 0; + } + + /** + * optional uint32 star_count = 13; + * @return this + */ + public TakeChallengeRewardCsReq clearStarCount() { + bitField0_ &= ~0x00000002; + starCount = 0; + return this; + } + + /** + * optional uint32 star_count = 13; + * @return the starCount + */ + public int getStarCount() { + return starCount; + } + + /** + * optional uint32 star_count = 13; + * @param value the starCount to set + * @return this + */ + public TakeChallengeRewardCsReq setStarCount(final int value) { + bitField0_ |= 0x00000002; + starCount = value; + return this; + } + + @Override + public TakeChallengeRewardCsReq copyFrom(final TakeChallengeRewardCsReq other) { + cachedSize = other.cachedSize; + if ((bitField0_ | other.bitField0_) != 0) { + bitField0_ = other.bitField0_; + groupId = other.groupId; + starCount = other.starCount; + } + return this; + } + + @Override + public TakeChallengeRewardCsReq mergeFrom(final TakeChallengeRewardCsReq other) { + if (other.isEmpty()) { + return this; + } + cachedSize = -1; + if (other.hasGroupId()) { + setGroupId(other.groupId); + } + if (other.hasStarCount()) { + setStarCount(other.starCount); + } + return this; + } + + @Override + public TakeChallengeRewardCsReq clear() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + groupId = 0; + starCount = 0; + return this; + } + + @Override + public TakeChallengeRewardCsReq 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 TakeChallengeRewardCsReq)) { + return false; + } + TakeChallengeRewardCsReq other = (TakeChallengeRewardCsReq) o; + return bitField0_ == other.bitField0_ + && (!hasGroupId() || groupId == other.groupId) + && (!hasStarCount() || starCount == other.starCount); + } + + @Override + public void writeTo(final ProtoSink output) throws IOException { + if ((bitField0_ & 0x00000001) != 0) { + output.writeRawByte((byte) 16); + output.writeUInt32NoTag(groupId); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeRawByte((byte) 104); + output.writeUInt32NoTag(starCount); + } + } + + @Override + protected int computeSerializedSize() { + int size = 0; + if ((bitField0_ & 0x00000001) != 0) { + size += 1 + ProtoSink.computeUInt32SizeNoTag(groupId); + } + if ((bitField0_ & 0x00000002) != 0) { + size += 1 + ProtoSink.computeUInt32SizeNoTag(starCount); + } + return size; + } + + @Override + @SuppressWarnings("fallthrough") + public TakeChallengeRewardCsReq mergeFrom(final ProtoSource input) throws IOException { + // Enabled Fall-Through Optimization (QuickBuffers) + int tag = input.readTag(); + while (true) { + switch (tag) { + case 16: { + // groupId + groupId = input.readUInt32(); + bitField0_ |= 0x00000001; + tag = input.readTag(); + if (tag != 104) { + break; + } + } + case 104: { + // starCount + starCount = input.readUInt32(); + bitField0_ |= 0x00000002; + 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.groupId, groupId); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeUInt32(FieldNames.starCount, starCount); + } + output.endObject(); + } + + @Override + public TakeChallengeRewardCsReq mergeFrom(final JsonSource input) throws IOException { + if (!input.beginObject()) { + return this; + } + while (!input.isAtEnd()) { + switch (input.readFieldHash()) { + case 293428218: + case 506361563: { + if (input.isAtField(FieldNames.groupId)) { + if (!input.trySkipNullValue()) { + groupId = input.readUInt32(); + bitField0_ |= 0x00000001; + } + } else { + input.skipUnknownField(); + } + break; + } + case 2121235933: + case 2124166370: { + if (input.isAtField(FieldNames.starCount)) { + if (!input.trySkipNullValue()) { + starCount = input.readUInt32(); + bitField0_ |= 0x00000002; + } + } else { + input.skipUnknownField(); + } + break; + } + default: { + input.skipUnknownField(); + break; + } + } + } + input.endObject(); + return this; + } + + @Override + public TakeChallengeRewardCsReq clone() { + return new TakeChallengeRewardCsReq().copyFrom(this); + } + + @Override + public boolean isEmpty() { + return ((bitField0_) == 0); + } + + public static TakeChallengeRewardCsReq parseFrom(final byte[] data) throws + InvalidProtocolBufferException { + return ProtoMessage.mergeFrom(new TakeChallengeRewardCsReq(), data).checkInitialized(); + } + + public static TakeChallengeRewardCsReq parseFrom(final ProtoSource input) throws IOException { + return ProtoMessage.mergeFrom(new TakeChallengeRewardCsReq(), input).checkInitialized(); + } + + public static TakeChallengeRewardCsReq parseFrom(final JsonSource input) throws IOException { + return ProtoMessage.mergeFrom(new TakeChallengeRewardCsReq(), input).checkInitialized(); + } + + /** + * @return factory for creating TakeChallengeRewardCsReq messages + */ + public static MessageFactory getFactory() { + return TakeChallengeRewardCsReqFactory.INSTANCE; + } + + private enum TakeChallengeRewardCsReqFactory implements MessageFactory { + INSTANCE; + + @Override + public TakeChallengeRewardCsReq create() { + return TakeChallengeRewardCsReq.newInstance(); + } + } + + /** + * Contains name constants used for serializing JSON + */ + static class FieldNames { + static final FieldName groupId = FieldName.forField("groupId", "group_id"); + + static final FieldName starCount = FieldName.forField("starCount", "star_count"); + } + } +} diff --git a/src/generated/main/emu/lunarcore/proto/TakeChallengeRewardScRspOuterClass.java b/src/generated/main/emu/lunarcore/proto/TakeChallengeRewardScRspOuterClass.java new file mode 100644 index 0000000..724b94f --- /dev/null +++ b/src/generated/main/emu/lunarcore/proto/TakeChallengeRewardScRspOuterClass.java @@ -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 TakeChallengeRewardScRspOuterClass { + /** + * Protobuf type {@code TakeChallengeRewardScRsp} + */ + public static final class TakeChallengeRewardScRsp extends ProtoMessage implements Cloneable { + private static final long serialVersionUID = 0L; + + /** + * optional uint32 star_count = 6; + */ + private int starCount; + + /** + * optional uint32 group_id = 7; + */ + private int groupId; + + /** + * optional uint32 retcode = 15; + */ + private int retcode; + + /** + * optional .ItemList reward = 10; + */ + private final ItemListOuterClass.ItemList reward = ItemListOuterClass.ItemList.newInstance(); + + private TakeChallengeRewardScRsp() { + } + + /** + * @return a new empty instance of {@code TakeChallengeRewardScRsp} + */ + public static TakeChallengeRewardScRsp newInstance() { + return new TakeChallengeRewardScRsp(); + } + + /** + * optional uint32 star_count = 6; + * @return whether the starCount field is set + */ + public boolean hasStarCount() { + return (bitField0_ & 0x00000001) != 0; + } + + /** + * optional uint32 star_count = 6; + * @return this + */ + public TakeChallengeRewardScRsp clearStarCount() { + bitField0_ &= ~0x00000001; + starCount = 0; + return this; + } + + /** + * optional uint32 star_count = 6; + * @return the starCount + */ + public int getStarCount() { + return starCount; + } + + /** + * optional uint32 star_count = 6; + * @param value the starCount to set + * @return this + */ + public TakeChallengeRewardScRsp setStarCount(final int value) { + bitField0_ |= 0x00000001; + starCount = value; + return this; + } + + /** + * optional uint32 group_id = 7; + * @return whether the groupId field is set + */ + public boolean hasGroupId() { + return (bitField0_ & 0x00000002) != 0; + } + + /** + * optional uint32 group_id = 7; + * @return this + */ + public TakeChallengeRewardScRsp clearGroupId() { + bitField0_ &= ~0x00000002; + groupId = 0; + return this; + } + + /** + * optional uint32 group_id = 7; + * @return the groupId + */ + public int getGroupId() { + return groupId; + } + + /** + * optional uint32 group_id = 7; + * @param value the groupId to set + * @return this + */ + public TakeChallengeRewardScRsp setGroupId(final int value) { + bitField0_ |= 0x00000002; + groupId = value; + return this; + } + + /** + * optional uint32 retcode = 15; + * @return whether the retcode field is set + */ + public boolean hasRetcode() { + return (bitField0_ & 0x00000004) != 0; + } + + /** + * optional uint32 retcode = 15; + * @return this + */ + public TakeChallengeRewardScRsp clearRetcode() { + bitField0_ &= ~0x00000004; + retcode = 0; + return this; + } + + /** + * optional uint32 retcode = 15; + * @return the retcode + */ + public int getRetcode() { + return retcode; + } + + /** + * optional uint32 retcode = 15; + * @param value the retcode to set + * @return this + */ + public TakeChallengeRewardScRsp setRetcode(final int value) { + bitField0_ |= 0x00000004; + retcode = value; + return this; + } + + /** + * optional .ItemList reward = 10; + * @return whether the reward field is set + */ + public boolean hasReward() { + return (bitField0_ & 0x00000008) != 0; + } + + /** + * optional .ItemList reward = 10; + * @return this + */ + public TakeChallengeRewardScRsp clearReward() { + bitField0_ &= ~0x00000008; + reward.clear(); + return this; + } + + /** + * optional .ItemList reward = 10; + * + * 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 #getMutableReward()} if you want to modify it. + * + * @return internal storage object for reading + */ + public ItemListOuterClass.ItemList getReward() { + return reward; + } + + /** + * optional .ItemList reward = 10; + * + * 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 getMutableReward() { + bitField0_ |= 0x00000008; + return reward; + } + + /** + * optional .ItemList reward = 10; + * @param value the reward to set + * @return this + */ + public TakeChallengeRewardScRsp setReward(final ItemListOuterClass.ItemList value) { + bitField0_ |= 0x00000008; + reward.copyFrom(value); + return this; + } + + @Override + public TakeChallengeRewardScRsp copyFrom(final TakeChallengeRewardScRsp other) { + cachedSize = other.cachedSize; + if ((bitField0_ | other.bitField0_) != 0) { + bitField0_ = other.bitField0_; + starCount = other.starCount; + groupId = other.groupId; + retcode = other.retcode; + reward.copyFrom(other.reward); + } + return this; + } + + @Override + public TakeChallengeRewardScRsp mergeFrom(final TakeChallengeRewardScRsp other) { + if (other.isEmpty()) { + return this; + } + cachedSize = -1; + if (other.hasStarCount()) { + setStarCount(other.starCount); + } + if (other.hasGroupId()) { + setGroupId(other.groupId); + } + if (other.hasRetcode()) { + setRetcode(other.retcode); + } + if (other.hasReward()) { + getMutableReward().mergeFrom(other.reward); + } + return this; + } + + @Override + public TakeChallengeRewardScRsp clear() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + starCount = 0; + groupId = 0; + retcode = 0; + reward.clear(); + return this; + } + + @Override + public TakeChallengeRewardScRsp clearQuick() { + if (isEmpty()) { + return this; + } + cachedSize = -1; + bitField0_ = 0; + reward.clearQuick(); + return this; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof TakeChallengeRewardScRsp)) { + return false; + } + TakeChallengeRewardScRsp other = (TakeChallengeRewardScRsp) o; + return bitField0_ == other.bitField0_ + && (!hasStarCount() || starCount == other.starCount) + && (!hasGroupId() || groupId == other.groupId) + && (!hasRetcode() || retcode == other.retcode) + && (!hasReward() || reward.equals(other.reward)); + } + + @Override + public void writeTo(final ProtoSink output) throws IOException { + if ((bitField0_ & 0x00000001) != 0) { + output.writeRawByte((byte) 48); + output.writeUInt32NoTag(starCount); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeRawByte((byte) 56); + output.writeUInt32NoTag(groupId); + } + if ((bitField0_ & 0x00000004) != 0) { + output.writeRawByte((byte) 120); + output.writeUInt32NoTag(retcode); + } + if ((bitField0_ & 0x00000008) != 0) { + output.writeRawByte((byte) 82); + output.writeMessageNoTag(reward); + } + } + + @Override + protected int computeSerializedSize() { + int size = 0; + if ((bitField0_ & 0x00000001) != 0) { + size += 1 + ProtoSink.computeUInt32SizeNoTag(starCount); + } + if ((bitField0_ & 0x00000002) != 0) { + size += 1 + ProtoSink.computeUInt32SizeNoTag(groupId); + } + if ((bitField0_ & 0x00000004) != 0) { + size += 1 + ProtoSink.computeUInt32SizeNoTag(retcode); + } + if ((bitField0_ & 0x00000008) != 0) { + size += 1 + ProtoSink.computeMessageSizeNoTag(reward); + } + return size; + } + + @Override + @SuppressWarnings("fallthrough") + public TakeChallengeRewardScRsp mergeFrom(final ProtoSource input) throws IOException { + // Enabled Fall-Through Optimization (QuickBuffers) + int tag = input.readTag(); + while (true) { + switch (tag) { + case 48: { + // starCount + starCount = input.readUInt32(); + bitField0_ |= 0x00000001; + tag = input.readTag(); + if (tag != 56) { + break; + } + } + case 56: { + // groupId + groupId = input.readUInt32(); + bitField0_ |= 0x00000002; + tag = input.readTag(); + if (tag != 120) { + break; + } + } + case 120: { + // retcode + retcode = input.readUInt32(); + bitField0_ |= 0x00000004; + tag = input.readTag(); + if (tag != 82) { + break; + } + } + case 82: { + // reward + input.readMessage(reward); + 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.starCount, starCount); + } + if ((bitField0_ & 0x00000002) != 0) { + output.writeUInt32(FieldNames.groupId, groupId); + } + if ((bitField0_ & 0x00000004) != 0) { + output.writeUInt32(FieldNames.retcode, retcode); + } + if ((bitField0_ & 0x00000008) != 0) { + output.writeMessage(FieldNames.reward, reward); + } + output.endObject(); + } + + @Override + public TakeChallengeRewardScRsp mergeFrom(final JsonSource input) throws IOException { + if (!input.beginObject()) { + return this; + } + while (!input.isAtEnd()) { + switch (input.readFieldHash()) { + case 2121235933: + case 2124166370: { + if (input.isAtField(FieldNames.starCount)) { + if (!input.trySkipNullValue()) { + starCount = input.readUInt32(); + bitField0_ |= 0x00000001; + } + } else { + input.skipUnknownField(); + } + break; + } + case 293428218: + case 506361563: { + if (input.isAtField(FieldNames.groupId)) { + if (!input.trySkipNullValue()) { + groupId = 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 -934326481: { + if (input.isAtField(FieldNames.reward)) { + if (!input.trySkipNullValue()) { + input.readMessage(reward); + bitField0_ |= 0x00000008; + } + } else { + input.skipUnknownField(); + } + break; + } + default: { + input.skipUnknownField(); + break; + } + } + } + input.endObject(); + return this; + } + + @Override + public TakeChallengeRewardScRsp clone() { + return new TakeChallengeRewardScRsp().copyFrom(this); + } + + @Override + public boolean isEmpty() { + return ((bitField0_) == 0); + } + + public static TakeChallengeRewardScRsp parseFrom(final byte[] data) throws + InvalidProtocolBufferException { + return ProtoMessage.mergeFrom(new TakeChallengeRewardScRsp(), data).checkInitialized(); + } + + public static TakeChallengeRewardScRsp parseFrom(final ProtoSource input) throws IOException { + return ProtoMessage.mergeFrom(new TakeChallengeRewardScRsp(), input).checkInitialized(); + } + + public static TakeChallengeRewardScRsp parseFrom(final JsonSource input) throws IOException { + return ProtoMessage.mergeFrom(new TakeChallengeRewardScRsp(), input).checkInitialized(); + } + + /** + * @return factory for creating TakeChallengeRewardScRsp messages + */ + public static MessageFactory getFactory() { + return TakeChallengeRewardScRspFactory.INSTANCE; + } + + private enum TakeChallengeRewardScRspFactory implements MessageFactory { + INSTANCE; + + @Override + public TakeChallengeRewardScRsp create() { + return TakeChallengeRewardScRsp.newInstance(); + } + } + + /** + * Contains name constants used for serializing JSON + */ + static class FieldNames { + static final FieldName starCount = FieldName.forField("starCount", "star_count"); + + static final FieldName groupId = FieldName.forField("groupId", "group_id"); + + static final FieldName retcode = FieldName.forField("retcode"); + + static final FieldName reward = FieldName.forField("reward"); + } + } +} diff --git a/src/main/java/emu/lunarcore/GameConstants.java b/src/main/java/emu/lunarcore/GameConstants.java index 3a05097..006dadb 100644 --- a/src/main/java/emu/lunarcore/GameConstants.java +++ b/src/main/java/emu/lunarcore/GameConstants.java @@ -15,6 +15,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_HCOIN_ID = 1; // Material id for jades. DO NOT CHANGE 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; diff --git a/src/main/java/emu/lunarcore/data/GameData.java b/src/main/java/emu/lunarcore/data/GameData.java index 2c0bb1d..dc077c6 100644 --- a/src/main/java/emu/lunarcore/data/GameData.java +++ b/src/main/java/emu/lunarcore/data/GameData.java @@ -28,10 +28,13 @@ public class GameData { @Getter private static Int2ObjectMap mapEntranceExcelMap = new Int2ObjectOpenHashMap<>(); @Getter private static Int2ObjectMap heroExcelMap = new Int2ObjectOpenHashMap<>(); @Getter private static Int2ObjectMap shopExcelMap = new Int2ObjectOpenHashMap<>(); + @Getter private static Int2ObjectMap rewardExcelMap = new Int2ObjectOpenHashMap<>(); @Getter private static Int2ObjectMap itemComposeExcelMap = new Int2ObjectOpenHashMap<>(); + @Getter private static Int2ObjectMap challengeGroupExcelMap = new Int2ObjectOpenHashMap<>(); @Getter private static Int2ObjectMap challengeExcelMap = new Int2ObjectOpenHashMap<>(); @Getter private static Int2ObjectMap challengeTargetExcelMap = new Int2ObjectOpenHashMap<>(); + private static Int2ObjectMap challengeRewardExcelMap = new Int2ObjectOpenHashMap<>(); @Getter private static Int2ObjectMap rogueManagerExcelMap = new Int2ObjectOpenHashMap<>(); @Getter private static Int2ObjectMap rogueTalentExcelMap = new Int2ObjectOpenHashMap<>(); @@ -135,4 +138,8 @@ public class GameData { public static MonsterDropExcel getMonsterDropExcel(int monsterNpcId, int worldLevel) { return monsterDropExcelMap.get((monsterNpcId << 4) + worldLevel); } + + public static ChallengeRewardExcel getChallengeRewardExcel(int groupId, int starCount) { + return challengeRewardExcelMap.get((groupId << 16) + starCount); + } } diff --git a/src/main/java/emu/lunarcore/data/excel/ChallengeExcel.java b/src/main/java/emu/lunarcore/data/excel/ChallengeExcel.java index 91b96c6..14e46d6 100644 --- a/src/main/java/emu/lunarcore/data/excel/ChallengeExcel.java +++ b/src/main/java/emu/lunarcore/data/excel/ChallengeExcel.java @@ -10,6 +10,7 @@ import lombok.Getter; @ResourceType(name = {"ChallengeMazeConfig.json"}) public class ChallengeExcel extends GameResource { private int ID; + private int GroupID; private int MapEntranceID; private int StageNum; private int ChallengeCountDown; diff --git a/src/main/java/emu/lunarcore/data/excel/ChallengeGroupExcel.java b/src/main/java/emu/lunarcore/data/excel/ChallengeGroupExcel.java new file mode 100644 index 0000000..2ba7a8f --- /dev/null +++ b/src/main/java/emu/lunarcore/data/excel/ChallengeGroupExcel.java @@ -0,0 +1,17 @@ +package emu.lunarcore.data.excel; + +import emu.lunarcore.data.GameResource; +import emu.lunarcore.data.ResourceType; +import lombok.Getter; + +@Getter +@ResourceType(name = {"ChallengeGroupConfig.json"}) +public class ChallengeGroupExcel extends GameResource { + private int GroupID; + private int RewardLineGroupID; + + @Override + public int getId() { + return GroupID; + } +} diff --git a/src/main/java/emu/lunarcore/data/excel/ChallengeRewardExcel.java b/src/main/java/emu/lunarcore/data/excel/ChallengeRewardExcel.java new file mode 100644 index 0000000..2e1f357 --- /dev/null +++ b/src/main/java/emu/lunarcore/data/excel/ChallengeRewardExcel.java @@ -0,0 +1,18 @@ +package emu.lunarcore.data.excel; + +import emu.lunarcore.data.GameResource; +import emu.lunarcore.data.ResourceType; +import lombok.Getter; + +@Getter +@ResourceType(name = {"ChallengeMazeRewardLine.json"}) +public class ChallengeRewardExcel extends GameResource { + private int GroupID; + private int StarCount; + private int RewardID; + + @Override + public int getId() { + return (GroupID << 16) + StarCount; + } +} diff --git a/src/main/java/emu/lunarcore/data/excel/RewardExcel.java b/src/main/java/emu/lunarcore/data/excel/RewardExcel.java new file mode 100644 index 0000000..7980602 --- /dev/null +++ b/src/main/java/emu/lunarcore/data/excel/RewardExcel.java @@ -0,0 +1,57 @@ +package emu.lunarcore.data.excel; + +import java.util.ArrayList; +import java.util.List; + +import emu.lunarcore.GameConstants; +import emu.lunarcore.data.GameResource; +import emu.lunarcore.data.ResourceType; +import emu.lunarcore.data.common.ItemParam; +import lombok.Getter; + +@Getter +@ResourceType(name = {"RewardData.json"}) +public class RewardExcel extends GameResource { + private int RewardID; + + private int Hcoin; + + private int ItemID_1; + private int Count_1; + private int ItemID_2; + private int Count_2; + private int ItemID_3; + private int Count_3; + private int ItemID_4; + private int Count_4; + private int ItemID_5; + private int Count_5; + + private transient List rewards; + + @Override + public int getId() { + return RewardID; + } + + @Override + public void onLoad() { + this.rewards = new ArrayList<>(); + + if (Hcoin > 0) { + this.rewards.add(new ItemParam(GameConstants.MATERIAL_HCOIN_ID, Hcoin)); + } + + if (ItemID_1 > 0) { + this.rewards.add(new ItemParam(ItemID_1, Count_1)); + } if (ItemID_2 > 0) { + this.rewards.add(new ItemParam(ItemID_2, Count_2)); + } if (ItemID_3 > 0) { + this.rewards.add(new ItemParam(ItemID_3, Count_3)); + } if (ItemID_4 > 0) { + this.rewards.add(new ItemParam(ItemID_4, Count_4)); + } if (ItemID_5 > 0) { + this.rewards.add(new ItemParam(ItemID_5, Count_5)); + } + } +} diff --git a/src/main/java/emu/lunarcore/game/challenge/ChallengeGroupReward.java b/src/main/java/emu/lunarcore/game/challenge/ChallengeGroupReward.java new file mode 100644 index 0000000..9b716e1 --- /dev/null +++ b/src/main/java/emu/lunarcore/game/challenge/ChallengeGroupReward.java @@ -0,0 +1,57 @@ +package emu.lunarcore.game.challenge; + +import org.bson.types.ObjectId; + +import dev.morphia.annotations.Entity; +import dev.morphia.annotations.Id; +import dev.morphia.annotations.Indexed; +import emu.lunarcore.LunarCore; +import emu.lunarcore.game.player.Player; +import emu.lunarcore.proto.ChallengeRewardOuterClass.ChallengeReward; +import lombok.Getter; + +@Getter +@Entity(value = "challengeReward", useDiscriminator = false) +public class ChallengeGroupReward { + @Id + private ObjectId id; + + @Indexed + private int ownerUid; + + private int groupId; + private long takenStars; + + @Deprecated // Morphia + public ChallengeGroupReward() {} + + public ChallengeGroupReward(Player player, int groupId) { + this.ownerUid = player.getUid(); + this.groupId = groupId; + } + + public boolean hasTakenReward(int starCount) { + return (takenStars & (1L << starCount)) != 0; + } + + public void setTakenReward(int starCount) { + this.takenStars |= 1L << starCount; + this.save(); + } + + public ChallengeReward toProto() { + var proto = ChallengeReward.newInstance() + .setGroupId(this.getGroupId()) + .setTakenChallengeReward(this.getTakenStars()); + + return proto; + } + + public void delete() { + LunarCore.getGameDatabase().delete(this); + } + + public void save() { + LunarCore.getGameDatabase().save(this); + } +} diff --git a/src/main/java/emu/lunarcore/game/challenge/ChallengeHistory.java b/src/main/java/emu/lunarcore/game/challenge/ChallengeHistory.java index 50f6b9a..1f7164a 100644 --- a/src/main/java/emu/lunarcore/game/challenge/ChallengeHistory.java +++ b/src/main/java/emu/lunarcore/game/challenge/ChallengeHistory.java @@ -21,6 +21,7 @@ public class ChallengeHistory { private int ownerUid; private int challengeId; + private int groupId; private int takenReward; private int stars; @@ -36,6 +37,14 @@ public class ChallengeHistory { this.stars = Math.max(this.stars, stars); } + public int getTotalStars() { + int total = 0; + for (int i = 0; i < 3; i++) { + total += (this.stars & (1 << i)) != 0 ? 1 : 0; + } + return total; + } + public Challenge toProto() { var proto = Challenge.newInstance() .setChallengeId(this.getChallengeId()) diff --git a/src/main/java/emu/lunarcore/game/challenge/ChallengeManager.java b/src/main/java/emu/lunarcore/game/challenge/ChallengeManager.java index 38eef99..7991183 100644 --- a/src/main/java/emu/lunarcore/game/challenge/ChallengeManager.java +++ b/src/main/java/emu/lunarcore/game/challenge/ChallengeManager.java @@ -1,10 +1,12 @@ package emu.lunarcore.game.challenge; +import java.util.List; import java.util.stream.Stream; import emu.lunarcore.LunarCore; import emu.lunarcore.data.GameData; import emu.lunarcore.data.excel.ChallengeExcel; +import emu.lunarcore.game.inventory.GameItem; import emu.lunarcore.game.player.BasePlayerManager; import emu.lunarcore.game.player.Player; import emu.lunarcore.game.player.lineup.PlayerLineup; @@ -17,10 +19,12 @@ import lombok.Getter; @Getter public class ChallengeManager extends BasePlayerManager { private Int2ObjectMap history; + private Int2ObjectMap takenRewards; public ChallengeManager(Player player) { super(player); this.history = new Int2ObjectOpenHashMap<>(); + this.takenRewards = new Int2ObjectOpenHashMap<>(); } public void startChallenge(int challengeId) { @@ -84,7 +88,7 @@ public class ChallengeManager extends BasePlayerManager { getPlayer().sendPacket(new PacketStartChallengeScRsp(getPlayer(), challengeId)); } - public void addHistory(int challengeId, int stars) { + public synchronized void addHistory(int challengeId, int stars) { // Dont write challenge history if the player didnt get any stars if (stars <= 0) return; @@ -96,11 +100,66 @@ public class ChallengeManager extends BasePlayerManager { info.save(); } + public synchronized List takeRewards(int groupId, int starCount) { + // Get excels + var challengeGroup = GameData.getChallengeGroupExcelMap().get(groupId); + if (challengeGroup == null) return null; + + var challengeReward = GameData.getChallengeRewardExcel(challengeGroup.getRewardLineGroupID(), starCount); + if (challengeReward == null) return null; + + var rewardExcel = GameData.getRewardExcelMap().get(challengeReward.getRewardID()); + if (rewardExcel == null) return null; + + // Validate + int totalStars = 0; + for (ChallengeHistory ch : this.getHistory().values()) { + // Legacy compatibility + if (ch.getGroupId() == 0) { + var challengeExcel = GameData.getChallengeExcelMap().get(ch.getChallengeId()); + if (challengeExcel == null) continue; + + ch.setGroupId(challengeExcel.getGroupID()); + ch.save(); + } + + // Add total stars + if (ch.getGroupId() == groupId) { + totalStars += ch.getTotalStars(); + } + } + + // Check if the player has enough stars + if (totalStars < starCount) { + return null; + } + + // Get reward info + var reward = this.getTakenRewards().computeIfAbsent(groupId, id -> new ChallengeGroupReward(getPlayer(), groupId)); + + if (reward.hasTakenReward(starCount)) { + return null; + } + + reward.setTakenReward(starCount); + + // Add items to inventory + return getPlayer().getInventory().addItemParams(rewardExcel.getRewards()); + } + public void loadFromDatabase() { - Stream stream = LunarCore.getGameDatabase().getObjects(ChallengeHistory.class, "ownerUid", this.getPlayer().getUid()); + // Load challenge history + Stream stream = LunarCore.getGameDatabase().getObjects(ChallengeHistory.class, "ownerUid", getPlayer().getUid()); stream.forEach(info -> { this.getHistory().put(info.getChallengeId(), info); }); + + // Load challenge rewards + Stream stream2 = LunarCore.getGameDatabase().getObjects(ChallengeGroupReward.class, "ownerUid", getPlayer().getUid()); + + stream2.forEach(info -> { + this.getTakenRewards().put(info.getGroupId(), info); + }); } } diff --git a/src/main/java/emu/lunarcore/game/inventory/Inventory.java b/src/main/java/emu/lunarcore/game/inventory/Inventory.java index d620e44..38838ab 100644 --- a/src/main/java/emu/lunarcore/game/inventory/Inventory.java +++ b/src/main/java/emu/lunarcore/game/inventory/Inventory.java @@ -142,6 +142,12 @@ public class Inventory extends BasePlayerManager { return results; } + + public List addItemParams(Collection params) { + // TODO handle params if they are equipment or relics + List items = params.stream().map(param -> new GameItem(param.getId(), param.getCount())).toList(); + return addItems(items, false); + } private synchronized GameItem putItem(GameItem item) { // Dont add items that dont have a valid item definition. diff --git a/src/main/java/emu/lunarcore/server/packet/recv/HandlerTakeChallengeRewardCsReq.java b/src/main/java/emu/lunarcore/server/packet/recv/HandlerTakeChallengeRewardCsReq.java new file mode 100644 index 0000000..00226d6 --- /dev/null +++ b/src/main/java/emu/lunarcore/server/packet/recv/HandlerTakeChallengeRewardCsReq.java @@ -0,0 +1,24 @@ +package emu.lunarcore.server.packet.recv; + +import java.util.List; + +import emu.lunarcore.game.inventory.GameItem; +import emu.lunarcore.proto.TakeChallengeRewardCsReqOuterClass.TakeChallengeRewardCsReq; +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.PacketTakeChallengeRewardScRsp; + +@Opcodes(CmdId.TakeChallengeRewardCsReq) +public class HandlerTakeChallengeRewardCsReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] data) throws Exception { + var req = TakeChallengeRewardCsReq.parseFrom(data); + + List rewards = session.getPlayer().getChallengeManager().takeRewards(req.getGroupId(), req.getStarCount()); + session.send(new PacketTakeChallengeRewardScRsp(req.getGroupId(), req.getStarCount(), rewards)); + } + +} diff --git a/src/main/java/emu/lunarcore/server/packet/send/PacketGetChallengeScRsp.java b/src/main/java/emu/lunarcore/server/packet/send/PacketGetChallengeScRsp.java index b9f5002..87b11ef 100644 --- a/src/main/java/emu/lunarcore/server/packet/send/PacketGetChallengeScRsp.java +++ b/src/main/java/emu/lunarcore/server/packet/send/PacketGetChallengeScRsp.java @@ -16,6 +16,10 @@ public class PacketGetChallengeScRsp extends BasePacket { data.addChallengeList(history.toProto()); } + for (var reward : player.getChallengeManager().getTakenRewards().values()) { + data.addChallengeRewardList(reward.toProto()); + } + this.setData(data); } } diff --git a/src/main/java/emu/lunarcore/server/packet/send/PacketTakeChallengeRewardScRsp.java b/src/main/java/emu/lunarcore/server/packet/send/PacketTakeChallengeRewardScRsp.java new file mode 100644 index 0000000..6a26604 --- /dev/null +++ b/src/main/java/emu/lunarcore/server/packet/send/PacketTakeChallengeRewardScRsp.java @@ -0,0 +1,30 @@ +package emu.lunarcore.server.packet.send; + +import java.util.Collection; + +import emu.lunarcore.game.inventory.GameItem; +import emu.lunarcore.proto.TakeChallengeRewardScRspOuterClass.TakeChallengeRewardScRsp; +import emu.lunarcore.server.packet.BasePacket; +import emu.lunarcore.server.packet.CmdId; + +public class PacketTakeChallengeRewardScRsp extends BasePacket { + + public PacketTakeChallengeRewardScRsp(int groupId, int starCount, Collection rewards) { + super(CmdId.TakeChallengeRewardScRsp); + + var data = TakeChallengeRewardScRsp.newInstance(); + + if (rewards != null) { + data.setGroupId(groupId) + .setStarCount(starCount); + + for (GameItem item : rewards) { + data.getMutableReward().addItemList(item.toProto()); + } + } else { + data.setRetcode(1); + } + + this.setData(data); + } +}