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