From 29a9f788e10c729b8c8d9c0f2dbd8febdf30ba74 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 8 Sep 2022 17:14:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8B=A9=E7=8C=8E=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E6=8E=92=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 3 +- modules/hunting/api.go | 8 +++- modules/hunting/api_ranklist.go | 24 +++++++++--- modules/hunting/model_rank.go | 36 +++++++++++------ modules/timer/vikingrank.go | 7 ++-- modules/viking/api.go | 8 +++- modules/viking/api_challenge.go | 11 +----- modules/viking/api_ranklist.go | 24 +++++++++--- modules/viking/model_rank.go | 69 ++++++++++++++++++++++++++++----- pb/hunting_msg.pb.go | 34 ++++++++++++---- pb/mainline_db.pb.go | 2 +- 11 files changed, 170 insertions(+), 56 deletions(-) diff --git a/comm/const.go b/comm/const.go index e9e36c8c8..860f8e5a4 100644 --- a/comm/const.go +++ b/comm/const.go @@ -123,7 +123,8 @@ const ( // TableViking = "viking" // 维京远征排行榜 - TableVikingRank = "vikingrank" + TableVikingRank = "vikingrank" + TableVikingRankList = "vikingranklist" //月之秘境 TableMoonfantasy = "moonfantasy" diff --git a/modules/hunting/api.go b/modules/hunting/api.go index 838208ce0..3911b648e 100644 --- a/modules/hunting/api.go +++ b/modules/hunting/api.go @@ -1,6 +1,7 @@ package hunting import ( + "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" ) @@ -19,6 +20,7 @@ type apiComp struct { service core.IService configure *configureComp module *Hunting + friend comm.IFriend } //组件初始化接口 @@ -32,6 +34,10 @@ func (this *apiComp) Init(service core.IService, module core.IModule, comp core. func (this *apiComp) Start() (err error) { err = this.MCompGate.Start() - + var module core.IModule + if module, err = this.service.GetModule(comm.ModuleFriend); err != nil { + return + } + this.friend = module.(comm.IFriend) return } diff --git a/modules/hunting/api_ranklist.go b/modules/hunting/api_ranklist.go index 3c98c529c..ac331a5db 100644 --- a/modules/hunting/api_ranklist.go +++ b/modules/hunting/api_ranklist.go @@ -14,15 +14,29 @@ func (this *apiComp) RankListCheck(session comm.IUserSession, req *pb.HuntingRan } func (this *apiComp) RankList(session comm.IUserSession, req *pb.HuntingRankListReq) (code pb.ErrorCode, data proto.Message) { - + var ( + ranks []*pb.DBHuntingRank + err error + ) code = this.RankListCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } - szRank, err := this.module.modulerank.GetRankData() - if err != nil { - code = pb.ErrorCode_DBError + if !req.Friend { + ranks, err = this.module.modulerank.GetRankData(req.BoosType) + if err != nil { + code = pb.ErrorCode_DBError + } + } else { + uids := this.friend.GetFriendList(session.GetUserId()) + for _, id := range uids { + rankData := this.module.modulerank.getHuntingRankListByBossType(id, req.BoosType) + if rankData != nil { + ranks = append(ranks, rankData) + } + } } - session.SendMsg(string(this.module.GetType()), HuntingRankListResp, &pb.HuntingRankListResp{Ranks: szRank}) + + session.SendMsg(string(this.module.GetType()), HuntingRankListResp, &pb.HuntingRankListResp{Ranks: ranks}) return } diff --git a/modules/hunting/model_rank.go b/modules/hunting/model_rank.go index 7a3968639..53a607535 100644 --- a/modules/hunting/model_rank.go +++ b/modules/hunting/model_rank.go @@ -28,15 +28,6 @@ func (this *ModelRank) AddRank(uId string, data *pb.DBHuntingRank) (err error) { return nil } -// func (this *ModelRank) GetUserRandData(uid string) (result *pb.DBHuntingRank, err error) { -// result = &pb.DBHuntingRank{} -// if err = this.Get(uid, result); err != nil && redis.RedisNil != err { -// return -// } -// err = nil -// return result, err -// } - // 更新排行榜数据 func (this *ModelRank) ChangeUserRank(uid string, objId string, value map[string]interface{}) (err error) { if len(value) == 0 { @@ -46,10 +37,17 @@ func (this *ModelRank) ChangeUserRank(uid string, objId string, value map[string } // 获取排行榜数据 -func (this *ModelRank) GetRankData() (data []*pb.DBHuntingRank, err error) { +func (this *ModelRank) GetRankData(bossType int32) (data []*pb.DBHuntingRank, err error) { + tmpdata := make([]*pb.DBHuntingRank, 0) data = make([]*pb.DBHuntingRank, 0) - err = this.Redis.LRange(comm.TableHuntingRankList, 0, -1, &data) // 0 表示列表的第一个元素 -1 表示列表的最后一个元素 - + err = this.Redis.LRange(comm.TableVikingRank, 0, -1, &tmpdata) + if err == nil { + for _, v := range tmpdata { + if v.Bosstype == bossType { + data = append(data, v) + } + } + } return } @@ -61,6 +59,7 @@ func (this *ModelRank) getHuntingRankList(uid string) []*pb.DBHuntingRank { } return ranks } + func (this *ModelRank) updatehuntingRankList(session comm.IUserSession, difficulty int32, boosType int32) { // 查询是不是更新数据 ranks := this.getHuntingRankList(session.GetUserId()) @@ -91,3 +90,16 @@ func (this *ModelRank) updatehuntingRankList(session comm.IUserSession, difficul } return } +func (this *ModelRank) getHuntingRankListByBossType(uid string, bossType int32) *pb.DBHuntingRank { + ranks := make([]*pb.DBHuntingRank, 0) + err := this.GetList(uid, &ranks) + if err != nil { + return nil + } + for _, v := range ranks { + if v.Bosstype == bossType { + return v + } + } + return nil +} diff --git a/modules/timer/vikingrank.go b/modules/timer/vikingrank.go index 0e7f6f825..518d2682a 100644 --- a/modules/timer/vikingrank.go +++ b/modules/timer/vikingrank.go @@ -17,12 +17,13 @@ import ( type VikingRank struct { modules.MCompModel service core.IService + dbName string } //组件初始化接口 func (this *VikingRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - - this.TableName = comm.TableVikingRank + this.dbName = comm.TableVikingRank + this.TableName = comm.TableVikingRankList this.MCompModel.Init(service, module, comp, options) this.service = service return @@ -38,7 +39,7 @@ func (this *VikingRank) Start() (err error) { func (this *VikingRank) Timer() { data := make([]interface{}, 0) // options.Find().SetLimit(comm.MaxRankList) for i := 1; i <= 3; i++ { // boss 类型 1 2 3 后面封装 // 时间参数战斗调完后再加进来 - if _data, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{"bosstype": i}, options.Find().SetSort(bson.M{"difficulty": -1}).SetLimit(comm.MaxRankList)); err == nil { + if _data, err := this.DB.Find(core.SqlTable(this.dbName), bson.M{"bosstype": i}, options.Find().SetSort(bson.M{"difficulty": -1}).SetLimit(comm.MaxRankList)); err == nil { for _data.Next(context.TODO()) { temp := &pb.DBVikingRank{} if err = _data.Decode(temp); err == nil { diff --git a/modules/viking/api.go b/modules/viking/api.go index 6588a655e..cbb00f37c 100644 --- a/modules/viking/api.go +++ b/modules/viking/api.go @@ -1,6 +1,7 @@ package viking import ( + "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" ) @@ -19,6 +20,7 @@ type apiComp struct { service core.IService configure *configureComp module *Viking + friend comm.IFriend } //组件初始化接口 @@ -32,6 +34,10 @@ func (this *apiComp) Init(service core.IService, module core.IModule, comp core. func (this *apiComp) Start() (err error) { err = this.MCompGate.Start() - + var module core.IModule + if module, err = this.service.GetModule(comm.ModuleFriend); err != nil { + return + } + this.friend = module.(comm.IFriend) return } diff --git a/modules/viking/api_challenge.go b/modules/viking/api_challenge.go index 108912f57..997bff660 100644 --- a/modules/viking/api_challenge.go +++ b/modules/viking/api_challenge.go @@ -66,7 +66,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.VikingChalleng mapData["Boss"] = viking.Boss // viking.ChallengeTime[req.BossType<<16+req.Difficulty] = 0 // todo 耗时 // mapData["challengeTime"] = viking.ChallengeTime - + this.module.modulerank.updateVikingRankList(session, req.Difficulty, req.BossType, 100) } // 耗时校验 当前战斗胜利时间消耗小于之前刷新数据 @@ -79,15 +79,6 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.VikingChalleng return } - mapRankData := make(map[string]interface{}, 0) - mapRankData["difficulty"] = req.Difficulty - mapRankData["bosstype"] = req.BossType - mapRankData["uid"] = session.GetUserId() - userinfo := this.module.ModuleUser.GetUser(session.GetUserId()) - mapRankData["nickname"] = userinfo.Name - mapRankData["lv"] = userinfo.Lv - mapRankData["costTime"] = 120 - this.module.modulerank.ChangeUserRank(session.GetUserId(), mapRankData) session.SendMsg(string(this.module.GetType()), VikingChallengeResp, &pb.VikingChallengeResp{Data: viking}) return } diff --git a/modules/viking/api_ranklist.go b/modules/viking/api_ranklist.go index 732796610..7a323dd96 100644 --- a/modules/viking/api_ranklist.go +++ b/modules/viking/api_ranklist.go @@ -16,15 +16,29 @@ func (this *apiComp) RankListCheck(session comm.IUserSession, req *pb.VikingRank } func (this *apiComp) RankList(session comm.IUserSession, req *pb.VikingRankListReq) (code pb.ErrorCode, data proto.Message) { - + var ( + ranks []*pb.DBVikingRank + err error + ) code = this.RankListCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } - szRank, err := this.module.modulerank.GetRankData(req.BoosType) - if err != nil { - code = pb.ErrorCode_DBError + if !req.Friend { + ranks, err = this.module.modulerank.GetRankData(req.BoosType) + if err != nil { + code = pb.ErrorCode_DBError + } + } else { + uids := this.friend.GetFriendList(session.GetUserId()) + for _, id := range uids { + rankData := this.module.modulerank.getVikingRankListByBossType(id, req.BoosType) + if rankData != nil { + ranks = append(ranks, rankData) + } + } } - session.SendMsg(string(this.module.GetType()), VikingRankListResp, &pb.VikingRankListResp{Ranks: szRank}) + + session.SendMsg(string(this.module.GetType()), VikingRankListResp, &pb.VikingRankListResp{Ranks: ranks}) return } diff --git a/modules/viking/model_rank.go b/modules/viking/model_rank.go index 285cda738..1058f0164 100644 --- a/modules/viking/model_rank.go +++ b/modules/viking/model_rank.go @@ -6,6 +6,8 @@ import ( "go_dreamfactory/lego/sys/redis" "go_dreamfactory/modules" "go_dreamfactory/pb" + + "go.mongodb.org/mongo-driver/bson/primitive" ) type ModelRank struct { @@ -36,31 +38,78 @@ func (this *ModelRank) GetUserRandData(uid string) (result *pb.DBVikingRank, err } // 更新排行榜数据 -func (this *ModelRank) ChangeUserRank(uid string, value map[string]interface{}) (err error) { +func (this *ModelRank) ChangeUserRank(uid string, objId string, value map[string]interface{}) (err error) { if len(value) == 0 { return nil } - return this.Change(uid, value) + return this.ChangeList(uid, objId, value) } func (this *ModelRank) GetRankData(bossType int32) (data []*pb.DBVikingRank, err error) { tmpdata := make([]*pb.DBVikingRank, 0) data = make([]*pb.DBVikingRank, 0) err = this.Redis.LRange(comm.TableVikingRank, 0, -1, &tmpdata) - for _, v := range tmpdata { - if v.Bosstype == bossType { - data = append(data, v) + if err == nil { + for _, v := range tmpdata { + if v.Bosstype == bossType { + data = append(data, v) + } } } + return } // 获取排行榜数据 -func (this *ModelRank) GetUserRankData(bossType int32, uid string) (data *pb.DBVikingRank) { - data = &pb.DBVikingRank{} - if err := this.Get(uid, data); err != nil { - this.moduleViking.Debugf("get dbVikingRank data err:%v", err) - return +func (this *ModelRank) getVikingRankList(uid string) []*pb.DBVikingRank { + ranks := make([]*pb.DBVikingRank, 0) + err := this.GetList(uid, &ranks) + if err != nil { + return nil + } + return ranks +} + +func (this *ModelRank) updateVikingRankList(session comm.IUserSession, difficulty int32, boosType int32, costTime int32) { + // 查询是不是更新数据 + ranks := this.getVikingRankList(session.GetUserId()) + bfind := false + for _, v := range ranks { + if v.Bosstype == boosType { + mapRankData := make(map[string]interface{}, 0) + mapRankData["difficulty"] = difficulty + mapRankData["bosstype"] = boosType + this.ChangeUserRank(session.GetUserId(), v.Id, mapRankData) + bfind = true + break + } + } + if !bfind { + userinfo := this.moduleViking.ModuleUser.GetUser(session.GetUserId()) + new := &pb.DBVikingRank{ + Id: primitive.NewObjectID().Hex(), + Uid: session.GetUserId(), + Difficulty: difficulty, + Bosstype: boosType, + Nickname: userinfo.Name, + Icon: "", + Lv: userinfo.Lv, + CostTime: costTime, // + } + this.AddList(session.GetUserId(), new.Id, new) } return } +func (this *ModelRank) getVikingRankListByBossType(uid string, bossType int32) *pb.DBVikingRank { + ranks := make([]*pb.DBVikingRank, 0) + err := this.GetList(uid, &ranks) + if err != nil { + return nil + } + for _, v := range ranks { + if v.Bosstype == bossType { + return v + } + } + return nil +} diff --git a/pb/hunting_msg.pb.go b/pb/hunting_msg.pb.go index f254fd629..55b592ca0 100644 --- a/pb/hunting_msg.pb.go +++ b/pb/hunting_msg.pb.go @@ -308,6 +308,9 @@ type HuntingRankListReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + BoosType int32 `protobuf:"varint,1,opt,name=boosType,proto3" json:"boosType"` // boss 类型 + Friend bool `protobuf:"varint,2,opt,name=friend,proto3" json:"friend"` // 是否是好友榜 } func (x *HuntingRankListReq) Reset() { @@ -342,6 +345,20 @@ func (*HuntingRankListReq) Descriptor() ([]byte, []int) { return file_hunting_hunting_msg_proto_rawDescGZIP(), []int{6} } +func (x *HuntingRankListReq) GetBoosType() int32 { + if x != nil { + return x.BoosType + } + return 0 +} + +func (x *HuntingRankListReq) GetFriend() bool { + if x != nil { + return x.Friend + } + return false +} + type HuntingRankListResp struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -414,13 +431,16 @@ var file_hunting_hunting_msg_proto_rawDesc = []byte{ 0x6e, 0x74, 0x22, 0x30, 0x0a, 0x0e, 0x48, 0x75, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x42, 0x75, 0x79, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x44, 0x42, 0x48, 0x75, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x22, 0x14, 0x0a, 0x12, 0x48, 0x75, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x52, - 0x61, 0x6e, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x22, 0x3b, 0x0a, 0x13, 0x48, 0x75, - 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x61, 0x6e, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, - 0x70, 0x12, 0x24, 0x0a, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x48, 0x75, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x61, 0x6e, 0x6b, - 0x52, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x61, 0x74, 0x61, 0x22, 0x48, 0x0a, 0x12, 0x48, 0x75, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x52, + 0x61, 0x6e, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x6f, + 0x6f, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x62, 0x6f, + 0x6f, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x22, 0x3b, + 0x0a, 0x13, 0x48, 0x75, 0x6e, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x61, 0x6e, 0x6b, 0x4c, 0x69, 0x73, + 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x24, 0x0a, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x48, 0x75, 0x6e, 0x74, 0x69, 0x6e, 0x67, + 0x52, 0x61, 0x6e, 0x6b, 0x52, 0x05, 0x72, 0x61, 0x6e, 0x6b, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, + 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pb/mainline_db.pb.go b/pb/mainline_db.pb.go index 7f6aae1c0..99b364285 100644 --- a/pb/mainline_db.pb.go +++ b/pb/mainline_db.pb.go @@ -30,7 +30,7 @@ type DBMainline struct { ChapterId int32 `protobuf:"varint,3,opt,name=chapterId,proto3" json:"chapterId" bson:"chapterId"` //章节ID MainlineId int32 `protobuf:"varint,4,opt,name=mainlineId,proto3" json:"mainlineId" bson:"mainlineId"` //主线关卡ID AwaredID int32 `protobuf:"varint,5,opt,name=awaredID,proto3" json:"awaredID" bson:"awaredID"` //是否领奖(设置int是考虑后续扩展有多个宝箱情况) - BranchID []int32 `protobuf:"varint,6,rep,packed,name=branchID,proto3" json:"branchID" bson:"branchID"` // 记录分支通关的情况 + BranchID []int32 `protobuf:"varint,6,rep,packed,name=branchID,proto3" json:"branchID" bson:"branchID"` // Intensity int32 `protobuf:"varint,7,opt,name=intensity,proto3" json:"intensity"` // 难度 }