From 531718d3a24b438970fdb76a7d1e9b6e8b1524b8 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 11 Oct 2022 18:47:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=8E=A9=E5=AE=B6=E5=BF=83?= =?UTF-8?q?=E9=AD=94=E5=A1=94=E6=9C=80=E9=AB=98=E5=B1=82=E6=95=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/pagoda/api.go | 1 + modules/pagoda/api_challengeover.go | 14 ++- modules/pagoda/api_queryrecord.go | 37 +++++++ modules/pagoda/api_ranklist.go | 15 ++- modules/pagoda/model_pagoda.go | 14 +++ modules/pagoda/model_rank.go | 33 +++++- pb/pagoda_msg.pb.go | 157 ++++++++++++++++++++++++---- 7 files changed, 244 insertions(+), 27 deletions(-) create mode 100644 modules/pagoda/api_queryrecord.go diff --git a/modules/pagoda/api.go b/modules/pagoda/api.go index 89f2a20c7..0f052bbee 100644 --- a/modules/pagoda/api.go +++ b/modules/pagoda/api.go @@ -8,6 +8,7 @@ import ( const ( PagodaGetListResp = "getlist" + PagodaQueryRecordResp = "queryrecord" PagodaChallengeResp = "challenge" PagodaChallengeOverResp = "challengeover" PagodaGetRewardResp = "getreward" diff --git a/modules/pagoda/api_challengeover.go b/modules/pagoda/api_challengeover.go index ccadb97dd..b916866ae 100644 --- a/modules/pagoda/api_challengeover.go +++ b/modules/pagoda/api_challengeover.go @@ -92,7 +92,19 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal } else { this.module.Errorf("no found userdata uid:%s", session.GetUserId()) } - + if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 { + sz := make([]*pb.LineUp, 5) + for i, v := range req.Report.Info.Redflist[0].Team { + if v != nil { + sz[i] = &pb.LineUp{ + Cid: v.HeroID, + Star: v.Star, + Lv: v.Lv, + } + } + } + this.module.modulerank.addPagodaList(session, pagoda, req.Report.Info.Redflist[0].Leadpos, sz, req.Report.Costtime) + } // 普通塔通关了 Nomalcfg := this.module.configure.GetPagodaConfigData(comm.PagodaType, pagoda.PagodaId+1) if Nomalcfg == nil { // 创建赛季塔数据 diff --git a/modules/pagoda/api_queryrecord.go b/modules/pagoda/api_queryrecord.go new file mode 100644 index 000000000..43512ef31 --- /dev/null +++ b/modules/pagoda/api_queryrecord.go @@ -0,0 +1,37 @@ +package pagoda + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "go.mongodb.org/mongo-driver/bson/primitive" + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) QueryRecordCheck(session comm.IUserSession, req *pb.PagodaQueryRecordReq) (code pb.ErrorCode) { + + return +} + +///获取主线关卡信息 +func (this *apiComp) QueryRecord(session comm.IUserSession, req *pb.PagodaQueryRecordReq) (code pb.ErrorCode, data proto.Message) { + var ( + record *pb.DBPagodaRecord + ) + + list, _ := this.module.modelPagoda.getPagodaList(session.GetUserId()) + if list == nil { // redis没有数据 + list = &pb.DBPagoda{} + list.Id = primitive.NewObjectID().Hex() + + list.Uid = session.GetUserId() + list.PagodaId = 0 // 初始数据0层 + list.Type = comm.PagodaType + this.module.modelPagoda.addNewPagoda(session.GetUserId(), list) + } else { + record = this.module.modelPagoda.getPagodaRankList(session.GetUserId(), list.PagodaId) + } + session.SendMsg(string(this.module.GetType()), PagodaQueryRecordResp, &pb.PagodaQueryRecordResp{Data: record}) + return +} diff --git a/modules/pagoda/api_ranklist.go b/modules/pagoda/api_ranklist.go index 97bbd3bf4..df53d7ae9 100644 --- a/modules/pagoda/api_ranklist.go +++ b/modules/pagoda/api_ranklist.go @@ -22,10 +22,17 @@ func (this *apiComp) RankList(session comm.IUserSession, req *pb.PagodaRankListR if code != pb.ErrorCode_Success { return } - if req.FloorId == 0 && req.Friend == false { - szRank, err = this.module.modulerank.GetRankData() - if err != nil { - code = pb.ErrorCode_DBError + if !req.Friend { + if req.FloorId == 0 { + szRank, err = this.module.modulerank.GetRankData() + if err != nil { + code = pb.ErrorCode_DBError + } + } else { + szRank, err = this.module.modulerank.GetFloorRankList(req.FloorId) + if err != nil { + code = pb.ErrorCode_DBError + } } } diff --git a/modules/pagoda/model_pagoda.go b/modules/pagoda/model_pagoda.go index 1b3f1591f..eac492eca 100644 --- a/modules/pagoda/model_pagoda.go +++ b/modules/pagoda/model_pagoda.go @@ -53,3 +53,17 @@ func (this *ModelPagoda) addNewPagoda(uId string, data *pb.DBPagoda) (err error) } return nil } + +func (this *ModelPagoda) getPagodaRankList(uid string, floorid int32) *pb.DBPagodaRecord { + pagodaRank := make([]*pb.DBPagodaRecord, 0) + err := this.GetList(uid, &pagodaRank) + if err != nil { + return nil + } + for _, v := range pagodaRank { + if v.PagodaId == floorid { + return v + } + } + return nil +} diff --git a/modules/pagoda/model_rank.go b/modules/pagoda/model_rank.go index 538cad61d..80b97a24b 100644 --- a/modules/pagoda/model_rank.go +++ b/modules/pagoda/model_rank.go @@ -67,6 +67,29 @@ func (this *ModelRank) getPagodaRankList(uid string) []*pb.DBPagodaRecord { } return pagodaRank } +func (this *ModelRank) addPagodaList(session comm.IUserSession, data *pb.DBPagoda, Leadpos int32, line []*pb.LineUp, costTime int32) { + userinfo := this.modulePagoda.ModuleUser.GetUser(session.GetUserId()) + new := &pb.DBPagodaRecord{ + Id: primitive.NewObjectID().Hex(), + Uid: session.GetUserId(), + PagodaId: data.PagodaId, + Type: data.Type, + Nickname: userinfo.Name, + Icon: "", // icon 暂无 + Lv: userinfo.Lv, + CostTime: costTime, + Line: line, + } + this.AddList(session.GetUserId(), new.Id, new) //写爬塔记录 + // 查询本层是否上榜 + rankData, ilen, err1 := this.GetFloorLastRankData(data.PagodaId) + if err1 == nil { + if ilen < comm.MaxRankNum || rankData.CostTime < costTime { + this.ChangeFloorRankList(session, data.PagodaId, new) + } + } + return +} // 插入新的排行数据 func (this *ModelRank) addPagodaRankList(session comm.IUserSession, data *pb.DBSeasonPagoda, Leadpos int32, line []*pb.LineUp, costTime int32) { @@ -104,7 +127,7 @@ func (this *ModelRank) GetFloorRankList(floor int32) (result []*pb.DBPagodaRecor result = make([]*pb.DBPagodaRecord, len(temp)) for n, v := range temp { result[n] = v - n++ + //n++ } return } @@ -136,15 +159,19 @@ func (this *ModelRank) ChangeFloorRankList(session comm.IUserSession, floor int3 this.modulePagoda.Errorf("err:%v", err) return } + // 排序 sort.SliceStable(temp, func(i, j int) bool { return temp[i].CostTime < temp[j].CostTime }) - + iLne := len(temp) if this.Redis.RPush(key, temp); err != nil { this.modulePagoda.Errorf("err:%v", err) return } - err = this.Redis.Ltrim(key, -1*comm.MaxRankNum, -1) //对一个列表进行修剪 + if iLne > comm.MaxRankNum { + iLne = comm.MaxRankNum + } + err = this.Redis.Ltrim(key, -1*iLne, -1) //对一个列表进行修剪 if err != nil { log.Errorf("delete failed") } diff --git a/pb/pagoda_msg.pb.go b/pb/pagoda_msg.pb.go index b2aef9bb1..5c245a1b2 100644 --- a/pb/pagoda_msg.pb.go +++ b/pb/pagoda_msg.pb.go @@ -550,6 +550,92 @@ func (x *PagodaRankListResp) GetRanks() []*DBPagodaRecord { return nil } +// 查询玩家最佳通关记录数据 +type PagodaQueryRecordReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *PagodaQueryRecordReq) Reset() { + *x = PagodaQueryRecordReq{} + if protoimpl.UnsafeEnabled { + mi := &file_pagoda_pagoda_msg_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PagodaQueryRecordReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PagodaQueryRecordReq) ProtoMessage() {} + +func (x *PagodaQueryRecordReq) ProtoReflect() protoreflect.Message { + mi := &file_pagoda_pagoda_msg_proto_msgTypes[10] + 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 PagodaQueryRecordReq.ProtoReflect.Descriptor instead. +func (*PagodaQueryRecordReq) Descriptor() ([]byte, []int) { + return file_pagoda_pagoda_msg_proto_rawDescGZIP(), []int{10} +} + +type PagodaQueryRecordResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Data *DBPagodaRecord `protobuf:"bytes,1,opt,name=data,proto3" json:"data"` +} + +func (x *PagodaQueryRecordResp) Reset() { + *x = PagodaQueryRecordResp{} + if protoimpl.UnsafeEnabled { + mi := &file_pagoda_pagoda_msg_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PagodaQueryRecordResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PagodaQueryRecordResp) ProtoMessage() {} + +func (x *PagodaQueryRecordResp) ProtoReflect() protoreflect.Message { + mi := &file_pagoda_pagoda_msg_proto_msgTypes[11] + 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 PagodaQueryRecordResp.ProtoReflect.Descriptor instead. +func (*PagodaQueryRecordResp) Descriptor() ([]byte, []int) { + return file_pagoda_pagoda_msg_proto_rawDescGZIP(), []int{11} +} + +func (x *PagodaQueryRecordResp) GetData() *DBPagodaRecord { + if x != nil { + return x.Data + } + return nil +} + var File_pagoda_pagoda_msg_proto protoreflect.FileDescriptor var file_pagoda_pagoda_msg_proto_rawDesc = []byte{ @@ -602,8 +688,14 @@ var file_pagoda_pagoda_msg_proto_rawDesc = []byte{ 0x64, 0x22, 0x3b, 0x0a, 0x12, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, 0x52, 0x61, 0x6e, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x25, 0x0a, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x44, 0x42, 0x50, 0x61, 0x67, 0x6f, 0x64, - 0x61, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x42, 0x06, - 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x22, 0x16, + 0x0a, 0x14, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x63, + 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x22, 0x3c, 0x0a, 0x15, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, + 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, + 0x23, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, + 0x44, 0x42, 0x50, 0x61, 0x67, 0x6f, 0x64, 0x61, 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, } var ( @@ -618,7 +710,7 @@ func file_pagoda_pagoda_msg_proto_rawDescGZIP() []byte { return file_pagoda_pagoda_msg_proto_rawDescData } -var file_pagoda_pagoda_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 10) +var file_pagoda_pagoda_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_pagoda_pagoda_msg_proto_goTypes = []interface{}{ (*PagodaGetListReq)(nil), // 0: PagodaGetListReq (*PagodaGetListResp)(nil), // 1: PagodaGetListResp @@ -630,23 +722,26 @@ var file_pagoda_pagoda_msg_proto_goTypes = []interface{}{ (*PagodaChallengeOverResp)(nil), // 7: PagodaChallengeOverResp (*PagodaRankListReq)(nil), // 8: PagodaRankListReq (*PagodaRankListResp)(nil), // 9: PagodaRankListResp - (*DBPagoda)(nil), // 10: DBPagoda - (*BattleInfo)(nil), // 11: BattleInfo - (*BattleReport)(nil), // 12: BattleReport - (*DBPagodaRecord)(nil), // 13: DBPagodaRecord + (*PagodaQueryRecordReq)(nil), // 10: PagodaQueryRecordReq + (*PagodaQueryRecordResp)(nil), // 11: PagodaQueryRecordResp + (*DBPagoda)(nil), // 12: DBPagoda + (*BattleInfo)(nil), // 13: BattleInfo + (*BattleReport)(nil), // 14: BattleReport + (*DBPagodaRecord)(nil), // 15: DBPagodaRecord } var file_pagoda_pagoda_msg_proto_depIdxs = []int32{ - 10, // 0: PagodaGetListResp.data:type_name -> DBPagoda - 10, // 1: PagodaGetRewardResp.data:type_name -> DBPagoda - 11, // 2: PagodaChallengeResp.info:type_name -> BattleInfo - 12, // 3: PagodaChallengeOverReq.report:type_name -> BattleReport - 10, // 4: PagodaChallengeOverResp.data:type_name -> DBPagoda - 13, // 5: PagodaRankListResp.ranks:type_name -> DBPagodaRecord - 6, // [6:6] is the sub-list for method output_type - 6, // [6:6] is the sub-list for method input_type - 6, // [6:6] is the sub-list for extension type_name - 6, // [6:6] is the sub-list for extension extendee - 0, // [0:6] is the sub-list for field type_name + 12, // 0: PagodaGetListResp.data:type_name -> DBPagoda + 12, // 1: PagodaGetRewardResp.data:type_name -> DBPagoda + 13, // 2: PagodaChallengeResp.info:type_name -> BattleInfo + 14, // 3: PagodaChallengeOverReq.report:type_name -> BattleReport + 12, // 4: PagodaChallengeOverResp.data:type_name -> DBPagoda + 15, // 5: PagodaRankListResp.ranks:type_name -> DBPagodaRecord + 15, // 6: PagodaQueryRecordResp.data:type_name -> DBPagodaRecord + 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 } func init() { file_pagoda_pagoda_msg_proto_init() } @@ -777,6 +872,30 @@ func file_pagoda_pagoda_msg_proto_init() { return nil } } + file_pagoda_pagoda_msg_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PagodaQueryRecordReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pagoda_pagoda_msg_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PagodaQueryRecordResp); 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{ @@ -784,7 +903,7 @@ func file_pagoda_pagoda_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_pagoda_pagoda_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 10, + NumMessages: 12, NumExtensions: 0, NumServices: 0, },