From 94e7197673a2ebf1c861ba0ba404dd91b6cf03b1 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 12 Jan 2023 10:55:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=83=8A=E5=96=9C?= =?UTF-8?q?=E8=B4=A7=E7=89=A9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/troll/api.go | 1 + modules/troll/api_getlist.go | 2 +- modules/troll/api_surpriseid.go | 81 ++++++++++++++++ pb/troll_msg.pb.go | 162 ++++++++++++++++++++++++++++---- 4 files changed, 227 insertions(+), 19 deletions(-) create mode 100644 modules/troll/api_surpriseid.go diff --git a/modules/troll/api.go b/modules/troll/api.go index 5c61312f0..64b03521a 100644 --- a/modules/troll/api.go +++ b/modules/troll/api.go @@ -12,6 +12,7 @@ const ( TrollRankListResp = "ranklist" TrollRecordListResp = "recordlist" TrollAfkSetResp = "afkset" + TrollSurpriseIdResp = "surpriseid" ) type apiComp struct { diff --git a/modules/troll/api_getlist.go b/modules/troll/api_getlist.go index dbeb880f5..a254293be 100644 --- a/modules/troll/api_getlist.go +++ b/modules/troll/api_getlist.go @@ -68,7 +68,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) return } if int32(configure.Now().Unix()-trolltrain.RefreshTime) < szTrain[trolltrain.TarinPos-1] { - session.SendMsg(string(this.module.GetType()), TrollGetListResp, &pb.TrollGetListResp{Data: trolltrain}) + //session.SendMsg(string(this.module.GetType()), TrollGetListResp, &pb.TrollGetListResp{Data: trolltrain}) return } trainNum := this.configure.GetTrollMaxTraintNum() diff --git a/modules/troll/api_surpriseid.go b/modules/troll/api_surpriseid.go new file mode 100644 index 000000000..7aa0a25dd --- /dev/null +++ b/modules/troll/api_surpriseid.go @@ -0,0 +1,81 @@ +package troll + +import ( + "crypto/rand" + "go_dreamfactory/comm" + "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + "math/big" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) SurpriseIdCheck(session comm.IUserSession, req *pb.TrollSurpriseIdReq) (code pb.ErrorCode) { + + return +} + +func (this *apiComp) SurpriseId(session comm.IUserSession, req *pb.TrollSurpriseIdReq) (code pb.ErrorCode, data proto.Message) { + var ( + update map[string]interface{} + maxCoefficient int32 + ) + + update = make(map[string]interface{}) + if code = this.SurpriseIdCheck(session, req); code != pb.ErrorCode_Success { + return // 参数校验失败直接返回 + } + trolltrain, err := this.module.modelTroll.getTrollList(session.GetUserId()) + if err != nil { + code = pb.ErrorCode_DBError + return + } + + maxCoefficient = this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值 + if maxCoefficient == 0 { + code = pb.ErrorCode_ConfigNoFound + return + } + + /// 计算经过了多少个周期 + szTrain := this.configure.GetTrollAllTrain() + var ( + circletime int32 // 循环一个周期的时间 + circleCount int32 // 循环的次数 + + ) + for _, v := range szTrain { + circletime += v + } + if int32(len(szTrain)) < trolltrain.TarinPos { + this.module.Errorf("TarinPos error: TarinPos:%d,maxLen:%d", trolltrain.TarinPos, len(szTrain)) + code = pb.ErrorCode_ConfigNoFound + return + } + if int32(configure.Now().Unix()-trolltrain.RefreshTime) < szTrain[trolltrain.TarinPos-1] { + session.SendMsg(string(this.module.GetType()), TrollGetListResp, &pb.TrollGetListResp{Data: trolltrain}) + return + } + trainNum := this.configure.GetTrollMaxTraintNum() + + t := int32(configure.Now().Unix() - trolltrain.Ctime) + circleCount = t / circletime // 经过的周期数 + if trolltrain.Circle != circleCount { + trolltrain.SurpriseID = make(map[int32]int32, 0) + n, _ := rand.Int(rand.Reader, big.NewInt(int64(trainNum))) + // 只算当前商人所属的货物 + g := this.configure.GetTrollGoodsFor(int32(n.Int64()) + 1) + n2, _ := rand.Int(rand.Reader, big.NewInt(int64(len(g)))) + trolltrain.SurpriseID[int32(n.Int64())+1] = g[int32(n2.Int64())] + update["surpriseID"] = trolltrain.SurpriseID + trolltrain.Circle = circleCount + update["circle"] = trolltrain.Circle + this.module.ModifyTrollData(session.GetUserId(), update) + } + + session.SendMsg(string(this.module.GetType()), TrollSurpriseIdResp, &pb.TrollSurpriseIdResp{ + SurpriseID: trolltrain.SurpriseID, + }) + return +} diff --git a/pb/troll_msg.pb.go b/pb/troll_msg.pb.go index 4abeac200..c0b24fa73 100644 --- a/pb/troll_msg.pb.go +++ b/pb/troll_msg.pb.go @@ -667,6 +667,93 @@ func (x *TrollRecordListResp) GetData() []*DBTrollRecord { return nil } +// 获取惊喜商品 +type TrollSurpriseIdReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *TrollSurpriseIdReq) Reset() { + *x = TrollSurpriseIdReq{} + if protoimpl.UnsafeEnabled { + mi := &file_troll_troll_msg_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TrollSurpriseIdReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TrollSurpriseIdReq) ProtoMessage() {} + +func (x *TrollSurpriseIdReq) ProtoReflect() protoreflect.Message { + mi := &file_troll_troll_msg_proto_msgTypes[13] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TrollSurpriseIdReq.ProtoReflect.Descriptor instead. +func (*TrollSurpriseIdReq) Descriptor() ([]byte, []int) { + return file_troll_troll_msg_proto_rawDescGZIP(), []int{13} +} + +// 返回进度信息 +type TrollSurpriseIdResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + SurpriseID map[int32]int32 `protobuf:"bytes,1,rep,name=surpriseID,proto3" json:"surpriseID" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"surpriseID"` //key商人id value惊喜货物ID +} + +func (x *TrollSurpriseIdResp) Reset() { + *x = TrollSurpriseIdResp{} + if protoimpl.UnsafeEnabled { + mi := &file_troll_troll_msg_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TrollSurpriseIdResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TrollSurpriseIdResp) ProtoMessage() {} + +func (x *TrollSurpriseIdResp) ProtoReflect() protoreflect.Message { + mi := &file_troll_troll_msg_proto_msgTypes[14] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TrollSurpriseIdResp.ProtoReflect.Descriptor instead. +func (*TrollSurpriseIdResp) Descriptor() ([]byte, []int) { + return file_troll_troll_msg_proto_rawDescGZIP(), []int{14} +} + +func (x *TrollSurpriseIdResp) GetSurpriseID() map[int32]int32 { + if x != nil { + return x.SurpriseID + } + return nil +} + var File_troll_troll_msg_proto protoreflect.FileDescriptor var file_troll_troll_msg_proto_rawDesc = []byte{ @@ -722,8 +809,19 @@ var file_troll_troll_msg_proto_rawDesc = []byte{ 0x0a, 0x13, 0x54, 0x72, 0x6f, 0x6c, 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x22, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x54, 0x72, 0x6f, 0x6c, 0x6c, 0x52, 0x65, 0x63, - 0x6f, 0x72, 0x64, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, - 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x72, 0x64, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x14, 0x0a, 0x12, 0x54, 0x72, 0x6f, + 0x6c, 0x6c, 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x49, 0x64, 0x52, 0x65, 0x71, 0x22, + 0x9a, 0x01, 0x0a, 0x13, 0x54, 0x72, 0x6f, 0x6c, 0x6c, 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, + 0x65, 0x49, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x44, 0x0a, 0x0a, 0x73, 0x75, 0x72, 0x70, 0x72, + 0x69, 0x73, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x54, 0x72, + 0x6f, 0x6c, 0x6c, 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x49, 0x64, 0x52, 0x65, 0x73, + 0x70, 0x2e, 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x49, 0x44, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x52, 0x0a, 0x73, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x49, 0x44, 0x1a, 0x3d, 0x0a, + 0x0f, 0x53, 0x75, 0x72, 0x70, 0x72, 0x69, 0x73, 0x65, 0x49, 0x44, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x06, 0x5a, 0x04, + 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -738,7 +836,7 @@ func file_troll_troll_msg_proto_rawDescGZIP() []byte { return file_troll_troll_msg_proto_rawDescData } -var file_troll_troll_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 14) +var file_troll_troll_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 17) var file_troll_troll_msg_proto_goTypes = []interface{}{ (*TrollGetListReq)(nil), // 0: TrollGetListReq (*TrollGetListResp)(nil), // 1: TrollGetListResp @@ -753,23 +851,27 @@ var file_troll_troll_msg_proto_goTypes = []interface{}{ (*TrollRankListResp)(nil), // 10: TrollRankListResp (*TrollRecordListReq)(nil), // 11: TrollRecordListReq (*TrollRecordListResp)(nil), // 12: TrollRecordListResp - nil, // 13: TrollBuyOrSellReq.ItemsEntry - (*DBTrollTrain)(nil), // 14: DBTrollTrain - (*DBTrollRecord)(nil), // 15: DBTrollRecord + (*TrollSurpriseIdReq)(nil), // 13: TrollSurpriseIdReq + (*TrollSurpriseIdResp)(nil), // 14: TrollSurpriseIdResp + nil, // 15: TrollBuyOrSellReq.ItemsEntry + nil, // 16: TrollSurpriseIdResp.SurpriseIDEntry + (*DBTrollTrain)(nil), // 17: DBTrollTrain + (*DBTrollRecord)(nil), // 18: DBTrollRecord } var file_troll_troll_msg_proto_depIdxs = []int32{ - 14, // 0: TrollGetListResp.data:type_name -> DBTrollTrain - 13, // 1: TrollBuyOrSellReq.items:type_name -> TrollBuyOrSellReq.ItemsEntry - 14, // 2: TrollBuyOrSellResp.data:type_name -> DBTrollTrain - 14, // 3: TrollAfkSetResp.data:type_name -> DBTrollTrain - 14, // 4: TrollNpcRewardResp.data:type_name -> DBTrollTrain + 17, // 0: TrollGetListResp.data:type_name -> DBTrollTrain + 15, // 1: TrollBuyOrSellReq.items:type_name -> TrollBuyOrSellReq.ItemsEntry + 17, // 2: TrollBuyOrSellResp.data:type_name -> DBTrollTrain + 17, // 3: TrollAfkSetResp.data:type_name -> DBTrollTrain + 17, // 4: TrollNpcRewardResp.data:type_name -> DBTrollTrain 9, // 5: TrollRankListResp.data:type_name -> RankData - 15, // 6: TrollRecordListResp.data:type_name -> DBTrollRecord - 7, // [7:7] is the sub-list for method output_type - 7, // [7:7] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 18, // 6: TrollRecordListResp.data:type_name -> DBTrollRecord + 16, // 7: TrollSurpriseIdResp.surpriseID:type_name -> TrollSurpriseIdResp.SurpriseIDEntry + 8, // [8:8] is the sub-list for method output_type + 8, // [8:8] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name } func init() { file_troll_troll_msg_proto_init() } @@ -935,6 +1037,30 @@ func file_troll_troll_msg_proto_init() { return nil } } + file_troll_troll_msg_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TrollSurpriseIdReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_troll_troll_msg_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TrollSurpriseIdResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -942,7 +1068,7 @@ func file_troll_troll_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_troll_troll_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 14, + NumMessages: 17, NumExtensions: 0, NumServices: 0, }, From d7b0d07b060114f6cb6ef5c8d16ab4ec4edc0ad7 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 12 Jan 2023 15:08:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=88=86=E5=8F=91?= =?UTF-8?q?=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/gateway/configure_comp.go | 10 ++---- modules/troll/api_surpriseid.go | 56 ++++++++++++------------------- 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/modules/gateway/configure_comp.go b/modules/gateway/configure_comp.go index be06b32b3..76da9ccbb 100644 --- a/modules/gateway/configure_comp.go +++ b/modules/gateway/configure_comp.go @@ -28,24 +28,20 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp // GetMsgDistribute 获取消息分发规则读取配置表 func (this *configureComp) GetMsgDistribute(msgmid, msguid string) (rule string, ok bool) { var ( - err error - v interface{} item *cfg.GameMsgdistribData ) - if v, err = this.GetConfigure(game_msgdistrib); err != nil { - ok = false - return - } else { + if v, err := this.GetConfigure(game_msgdistrib); err == nil { if item, ok = v.(*cfg.GameMsgdistrib).GetDataMap()[msgmid]; ok && item.Open { rule = item.Routrules + return } else { msgid := strings.ToLower(fmt.Sprintf("%s.%s", msgmid, msguid)) if item, ok = v.(*cfg.GameMsgdistrib).GetDataMap()[msgid]; ok && item.Open { rule = item.Routrules return } - ok = false } } + ok = false return } diff --git a/modules/troll/api_surpriseid.go b/modules/troll/api_surpriseid.go index 7aa0a25dd..76348352e 100644 --- a/modules/troll/api_surpriseid.go +++ b/modules/troll/api_surpriseid.go @@ -18,33 +18,20 @@ func (this *apiComp) SurpriseIdCheck(session comm.IUserSession, req *pb.TrollSur func (this *apiComp) SurpriseId(session comm.IUserSession, req *pb.TrollSurpriseIdReq) (code pb.ErrorCode, data proto.Message) { var ( - update map[string]interface{} - maxCoefficient int32 + circletime int32 // 循环一个周期的时间 + circleCount int32 // 循环的次数 + update map[string]interface{} ) - update = make(map[string]interface{}) - if code = this.SurpriseIdCheck(session, req); code != pb.ErrorCode_Success { - return // 参数校验失败直接返回 - } + trolltrain, err := this.module.modelTroll.getTrollList(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return } - maxCoefficient = this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值 - if maxCoefficient == 0 { - code = pb.ErrorCode_ConfigNoFound - return - } - /// 计算经过了多少个周期 szTrain := this.configure.GetTrollAllTrain() - var ( - circletime int32 // 循环一个周期的时间 - circleCount int32 // 循环的次数 - - ) for _, v := range szTrain { circletime += v } @@ -53,25 +40,24 @@ func (this *apiComp) SurpriseId(session comm.IUserSession, req *pb.TrollSurprise code = pb.ErrorCode_ConfigNoFound return } - if int32(configure.Now().Unix()-trolltrain.RefreshTime) < szTrain[trolltrain.TarinPos-1] { - session.SendMsg(string(this.module.GetType()), TrollGetListResp, &pb.TrollGetListResp{Data: trolltrain}) - return - } - trainNum := this.configure.GetTrollMaxTraintNum() + if int32(configure.Now().Unix()-trolltrain.RefreshTime) >= szTrain[trolltrain.TarinPos-1] { + trainNum := this.configure.GetTrollMaxTraintNum() - t := int32(configure.Now().Unix() - trolltrain.Ctime) - circleCount = t / circletime // 经过的周期数 - if trolltrain.Circle != circleCount { - trolltrain.SurpriseID = make(map[int32]int32, 0) - n, _ := rand.Int(rand.Reader, big.NewInt(int64(trainNum))) - // 只算当前商人所属的货物 - g := this.configure.GetTrollGoodsFor(int32(n.Int64()) + 1) - n2, _ := rand.Int(rand.Reader, big.NewInt(int64(len(g)))) - trolltrain.SurpriseID[int32(n.Int64())+1] = g[int32(n2.Int64())] - update["surpriseID"] = trolltrain.SurpriseID - trolltrain.Circle = circleCount - update["circle"] = trolltrain.Circle - this.module.ModifyTrollData(session.GetUserId(), update) + t := int32(configure.Now().Unix() - trolltrain.Ctime) + circleCount = t / circletime // 经过的周期数 + if trolltrain.Circle != circleCount { + trolltrain.SurpriseID = make(map[int32]int32, 0) + n, _ := rand.Int(rand.Reader, big.NewInt(int64(trainNum))) + // 只算当前商人所属的货物 + g := this.configure.GetTrollGoodsFor(int32(n.Int64()) + 1) + n2, _ := rand.Int(rand.Reader, big.NewInt(int64(len(g)))) + trolltrain.SurpriseID[int32(n.Int64())+1] = g[int32(n2.Int64())] + update["surpriseID"] = trolltrain.SurpriseID + trolltrain.Circle = circleCount + update["circle"] = trolltrain.Circle + this.module.ModifyTrollData(session.GetUserId(), update) + } + return } session.SendMsg(string(this.module.GetType()), TrollSurpriseIdResp, &pb.TrollSurpriseIdResp{