This commit is contained in:
liwei 2023-07-06 18:05:14 +08:00
commit ef27e4d247
5 changed files with 97 additions and 65 deletions

View File

@ -14,6 +14,7 @@ const (
VikingGetRewardResp = "getreward" VikingGetRewardResp = "getreward"
VikingBuyResp = "buy" VikingBuyResp = "buy"
VikingRankListResp = "ranklist" VikingRankListResp = "ranklist"
VikingSeasonRankReq = "seasonrank"
) )
type apiComp struct { type apiComp struct {

View File

@ -0,0 +1,75 @@
package viking
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/redis/pipe"
"go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"strconv"
"github.com/go-redis/redis/v8"
)
//参数校验
func (this *apiComp) SeasonRankCheck(session comm.IUserSession, req *pb.VikingSeasonRankReq) (errdata *pb.ErrorData) {
if req.BoosType == 0 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
}
return
}
func (this *apiComp) SeasonRank(session comm.IUserSession, req *pb.VikingSeasonRankReq) (errdata *pb.ErrorData) {
var (
szRank []*pb.DBVSeasonRank
rd *redis.StringSliceCmd
conn *db.DBConn
pipe *pipe.RedisPipe
err error
)
if errdata = this.SeasonRankCheck(session, req); errdata != nil {
return // 参数校验失败直接返回
}
if this.module.CheckCurSeasonData() {
conn, err = db.Local()
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
} else {
conn, _ = db.Cross()
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
}
dbModel := db.NewDBModel(comm.TableVikingRank, 0, conn)
pipe = conn.Redis.RedisPipe(context.TODO())
rd = pipe.ZRevRange("vSeasonRank"+strconv.Itoa(int(req.BoosType)), 0, comm.MaxRankList)
if _, err := pipe.Exec(); err != nil {
this.module.Errorln(err)
return
}
_dataList := rd.Val()
for _, v := range _dataList {
result := &pb.DBVSeasonRank{}
if err := dbModel.Redis.HGetAll(v, result); err == nil {
szRank = append(szRank, result)
}
}
session.SendMsg(string(this.module.GetType()), VikingSeasonRankReq, &pb.VikingSeasonRankResp{Ranks: szRank})
return
}

View File

@ -1,15 +1,11 @@
package viking package viking
import ( import (
"context"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/redis/pipe"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"github.com/go-redis/redis/v8"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx" "go.mongodb.org/mongo-driver/x/bsonx"
) )
@ -59,29 +55,3 @@ func (this *ModelRank) getVikingRankListByBossType(uid string, bossType int32) *
} }
return nil return nil
} }
// 排行数据写跨服
func (this *ModelRank) SetRankListData(tableName string, score int64, objId string) {
if !db.IsCross() {
if conn, err := db.Cross(); err == nil {
var (
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
menbers *redis.Z
)
menbers = &redis.Z{Score: float64(score), Member: objId}
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
dock, err1 := cmd.Result()
if err1 != nil {
this.moduleViking.Errorln(dock, err1)
}
}
if _, err := pipe.Exec(); err != nil {
this.moduleViking.Errorln(err)
return
}
}
}
}

View File

@ -1,15 +1,11 @@
package viking package viking
import ( import (
"context"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/redis/pipe"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"github.com/go-redis/redis/v8"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx" "go.mongodb.org/mongo-driver/x/bsonx"
) )
@ -59,29 +55,3 @@ func (this *ModelSeasonRank) getVikingSeasonRankListByBossType(uid string, bossT
} }
return nil return nil
} }
// 排行数据写跨服
func (this *ModelSeasonRank) SetRankListData(tableName string, score int64, objId string) {
if !db.IsCross() {
if conn, err := db.Cross(); err == nil {
var (
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
menbers *redis.Z
)
menbers = &redis.Z{Score: float64(score), Member: objId}
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
dock, err1 := cmd.Result()
if err1 != nil {
this.moduleViking.Errorln(dock, err1)
}
}
if _, err := pipe.Exec(); err != nil {
this.moduleViking.Errorln(err)
return
}
}
}
}

View File

@ -425,11 +425,23 @@ func (this *Viking) CheckPreSeasonData() (bLocal bool) {
} }
// 记录数据存在跨服 // 记录数据存在跨服
func (this *Viking) CheckSeasonRank(uid string, boosID int32, difficulty int32, leadpos int32, szLine []*pb.LineUp, huihe int32) { func (this *Viking) CheckSeasonRank(uid string, boosID int32, difficulty int32, leadpos int32, szLine []*pb.LineUp, huihe int32, bcross bool) {
conn_, err := db.Cross() // 获取跨服数据库对象 var (
conn_ *db.DBConn
err error
)
if bcross {
conn_, err = db.Cross() // 获取跨服数据库对象
if err != nil { if err != nil {
return return
} }
} else { //数据记录在本服
conn_, err = db.Local()
if err != nil {
return
}
}
userinfo := this.ModuleUser.GetUser(uid) userinfo := this.ModuleUser.GetUser(uid)
model := db.NewDBModel(comm.TableVikingSRank, 0, conn_) model := db.NewDBModel(comm.TableVikingSRank, 0, conn_)
@ -440,6 +452,11 @@ func (this *Viking) CheckSeasonRank(uid string, boosID int32, difficulty int32,
model.GetList(uid, &ranks) model.GetList(uid, &ranks)
for _, v := range ranks { for _, v := range ranks {
if v.Bosstype == boosID && v.Difficulty <= difficulty { if v.Bosstype == boosID && v.Difficulty <= difficulty {
if v.Difficulty == difficulty { // 难度相等 则回合数少则更新
if v.Huihe <= huihe {
break
}
}
mapRankData := make(map[string]interface{}, 0) mapRankData := make(map[string]interface{}, 0)
mapRankData["difficulty"] = difficulty mapRankData["difficulty"] = difficulty
mapRankData["bosstype"] = boosID mapRankData["bosstype"] = boosID
@ -454,7 +471,6 @@ func (this *Viking) CheckSeasonRank(uid string, boosID int32, difficulty int32,
} }
} }
if !bFind { if !bFind {
new := &pb.DBVSeasonRank{ new := &pb.DBVSeasonRank{
Id: primitive.NewObjectID().Hex(), Id: primitive.NewObjectID().Hex(),
Uid: uid, Uid: uid,