维京排行优化
This commit is contained in:
parent
f080a2fa2b
commit
b6526455e9
@ -91,6 +91,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal
|
||||
code = pb.ErrorCode_BattleNoWin
|
||||
return
|
||||
}
|
||||
|
||||
key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty))
|
||||
if viking.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励
|
||||
viking.Boss[req.BossId]++
|
||||
@ -99,8 +100,12 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, viking, req.Report)
|
||||
if viking.BossTime[key] > req.Report.Costtime || viking.BossTime[key] == 0 && req.Difficulty >= viking.Boss[req.BossId] {
|
||||
viking.BossTime[key] = req.Report.Costtime
|
||||
mapData["bossTime"] = viking.BossTime // 更新时间
|
||||
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
||||
this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, req.Report, userinfo)
|
||||
}
|
||||
reward = this.module.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励
|
||||
if code, atno = this.module.DispenseAtno(session, reward, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
@ -119,7 +124,6 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal
|
||||
if len(del) > 0 { // 自动出售
|
||||
this.equip.SellEquipments(session, del)
|
||||
}
|
||||
mapData["bossTime"] = viking.BossTime // 更新时间
|
||||
|
||||
// if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
||||
// for _, v := range req.Report.Info.Redflist[0].Team {
|
||||
|
@ -55,7 +55,7 @@ func (this *ModelRank) getVikingRankListByBossType(uid string, bossType int32) *
|
||||
}
|
||||
|
||||
// 排行数据写跨服
|
||||
func (this *ModelRank) SetRankListData(tableName string, score int64, uid string) {
|
||||
func (this *ModelRank) SetRankListData(tableName string, score int64, objId string) {
|
||||
if !db.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
var (
|
||||
@ -63,7 +63,7 @@ func (this *ModelRank) SetRankListData(tableName string, score int64, uid string
|
||||
menbers *redis.Z
|
||||
)
|
||||
|
||||
menbers = &redis.Z{Score: float64(score), Member: uid}
|
||||
menbers = &redis.Z{Score: float64(score), Member: objId}
|
||||
|
||||
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
|
||||
|
||||
|
@ -6,8 +6,10 @@
|
||||
package viking
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
@ -17,6 +19,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
@ -84,67 +87,86 @@ func (this *Viking) CheckUserBaseVikingInfo(uid string) (data []*pb.DBVikingRank
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Viking) CheckRank(uid string, boosID int32, difficulty int32, viking *pb.DBViking, report *pb.BattleReport) {
|
||||
costTime := report.Costtime
|
||||
key := strconv.Itoa(int(boosID)) + "_" + strconv.Itoa(int(difficulty))
|
||||
// 记录数据存在跨服
|
||||
func (this *Viking) CheckRank(uid string, boosID int32, difficulty int32, report *pb.BattleReport, userinfo *pb.DBUser) {
|
||||
conn_, _ := db.Cross() // 获取跨服数据库对象
|
||||
|
||||
if viking.BossTime[key] > costTime || viking.BossTime[key] == 0 && difficulty >= viking.Boss[boosID] { // 刷新记录
|
||||
viking.BossTime[key] = costTime
|
||||
szLine := make([]*pb.LineUp, 5)
|
||||
Leadpos := 0
|
||||
if report != nil && report.Info != nil && len(report.Info.Redflist) > 0 {
|
||||
costTime = report.Costtime
|
||||
Leadpos = int(report.Info.Redflist[0].Leadpos)
|
||||
for i, v := range report.Info.Redflist[0].Team {
|
||||
if v != nil {
|
||||
szLine[i] = &pb.LineUp{
|
||||
Cid: v.HeroID,
|
||||
Star: v.Star,
|
||||
Lv: v.Lv,
|
||||
}
|
||||
model := db.NewDBModel(comm.TableVikingRank, time.Hour, conn_)
|
||||
|
||||
costTime := report.Costtime
|
||||
szLine := make([]*pb.LineUp, 5)
|
||||
Leadpos := 0
|
||||
if report != nil && report.Info != nil && len(report.Info.Redflist) > 0 {
|
||||
costTime = report.Costtime
|
||||
Leadpos = int(report.Info.Redflist[0].Leadpos)
|
||||
for i, v := range report.Info.Redflist[0].Team {
|
||||
if v != nil {
|
||||
szLine[i] = &pb.LineUp{
|
||||
Cid: v.HeroID,
|
||||
Star: v.Star,
|
||||
Lv: v.Lv,
|
||||
}
|
||||
}
|
||||
}
|
||||
// 写入排行榜
|
||||
objID := ""
|
||||
bFind := false
|
||||
ranks := this.modulerank.getVikingRankList(uid)
|
||||
for _, v := range ranks {
|
||||
if v.Bosstype == boosID {
|
||||
mapRankData := make(map[string]interface{}, 0)
|
||||
mapRankData["difficulty"] = difficulty
|
||||
mapRankData["bosstype"] = boosID
|
||||
mapRankData["Leadpos"] = Leadpos
|
||||
mapRankData["line"] = szLine
|
||||
mapRankData["costTime"] = costTime
|
||||
conn_, _ := db.Cross()
|
||||
dbModel := db.NewDBModel(comm.TableVikingRank, time.Hour, conn_)
|
||||
dbModel.ChangeList(uid, v.Id, mapRankData)
|
||||
objID = v.Id
|
||||
bFind = true
|
||||
break
|
||||
}
|
||||
}
|
||||
// 写入排行榜
|
||||
objID := ""
|
||||
bFind := false
|
||||
ranks := make([]*pb.DBVikingRank, 0)
|
||||
model.GetList(uid, &ranks)
|
||||
for _, v := range ranks {
|
||||
if v.Bosstype == boosID {
|
||||
mapRankData := make(map[string]interface{}, 0)
|
||||
mapRankData["difficulty"] = difficulty
|
||||
mapRankData["bosstype"] = boosID
|
||||
mapRankData["Leadpos"] = Leadpos
|
||||
mapRankData["line"] = szLine
|
||||
mapRankData["costTime"] = costTime
|
||||
|
||||
model.ChangeList(uid, v.Id, mapRankData)
|
||||
objID = v.Id
|
||||
bFind = true
|
||||
break
|
||||
}
|
||||
if !bFind {
|
||||
userinfo := this.ModuleUser.GetUser(uid)
|
||||
new := &pb.DBVikingRank{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
Uid: uid,
|
||||
Difficulty: difficulty,
|
||||
Bosstype: boosID,
|
||||
Nickname: userinfo.Name,
|
||||
Icon: "",
|
||||
Lv: userinfo.Lv,
|
||||
Leadpos: int32(Leadpos),
|
||||
Line: szLine,
|
||||
CostTime: costTime,
|
||||
}
|
||||
objID = new.Id
|
||||
conn_, _ := db.Cross()
|
||||
dbModel := db.NewDBModel(comm.TableVikingRank, time.Hour, conn_)
|
||||
dbModel.AddList(uid, new.Id, new)
|
||||
}
|
||||
if !bFind {
|
||||
|
||||
new := &pb.DBVikingRank{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
Uid: uid,
|
||||
Difficulty: difficulty,
|
||||
Bosstype: boosID,
|
||||
Nickname: userinfo.Name,
|
||||
Icon: "",
|
||||
Lv: userinfo.Lv,
|
||||
Leadpos: int32(Leadpos),
|
||||
Line: szLine,
|
||||
CostTime: costTime,
|
||||
}
|
||||
this.modulerank.SetRankListData("vikingRank"+strconv.Itoa(int(boosID)), int64(difficulty<<31)+int64(math.MaxInt32-costTime), objID)
|
||||
objID = new.Id
|
||||
model.AddList(uid, new.Id, new)
|
||||
}
|
||||
|
||||
var (
|
||||
pipe *pipe.RedisPipe = conn_.Redis.RedisPipe(context.TODO())
|
||||
menbers *redis.Z
|
||||
tableName string
|
||||
score int64
|
||||
)
|
||||
score = int64(difficulty<<31) + int64(math.MaxInt32-costTime)
|
||||
tableName = "vikingRank" + strconv.Itoa(int(boosID))
|
||||
menbers = &redis.Z{Score: float64(score), Member: objID}
|
||||
|
||||
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
|
||||
|
||||
dock, err1 := cmd.Result()
|
||||
if err1 != nil {
|
||||
this.Errorln(dock, err1)
|
||||
}
|
||||
}
|
||||
if _, err := pipe.Exec(); err != nil {
|
||||
this.Errorln(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,8 +304,8 @@ func (this *Viking) AutoBattleOver(session comm.IUserSession, Report *pb.BattleR
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.CheckRank(session.GetUserId(), bossId, difficulty, viking, Report)
|
||||
userinfo := this.ModuleUser.GetUser(session.GetUserId())
|
||||
this.CheckRank(session.GetUserId(), bossId, difficulty, Report, userinfo)
|
||||
reward := this.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励
|
||||
if c, res1 := this.DispenseAtno(session, reward, true); c == pb.ErrorCode_Success {
|
||||
atno = append(atno, res1...)
|
||||
|
Loading…
Reference in New Issue
Block a user