狩猎加获取好友排行

This commit is contained in:
meixiongfeng 2022-09-08 17:14:12 +08:00
parent 6584cb33e9
commit 29a9f788e1
11 changed files with 170 additions and 56 deletions

View File

@ -124,6 +124,7 @@ const (
TableViking = "viking"
// 维京远征排行榜
TableVikingRank = "vikingrank"
TableVikingRankList = "vikingranklist"
//月之秘境
TableMoonfantasy = "moonfantasy"

View File

@ -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
}

View File

@ -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 !req.Friend {
ranks, err = this.module.modulerank.GetRankData(req.BoosType)
if err != nil {
code = pb.ErrorCode_DBError
}
session.SendMsg(string(this.module.GetType()), HuntingRankListResp, &pb.HuntingRankListResp{Ranks: szRank})
} 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: ranks})
return
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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 !req.Friend {
ranks, err = this.module.modulerank.GetRankData(req.BoosType)
if err != nil {
code = pb.ErrorCode_DBError
}
session.SendMsg(string(this.module.GetType()), VikingRankListResp, &pb.VikingRankListResp{Ranks: szRank})
} 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: ranks})
return
}

View File

@ -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)
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
}

View File

@ -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 (

View File

@ -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"` // 难度
}