diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index d635d1a08..fa41ba563 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -71,6 +71,8 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq ret := this.module.CheckCondition(session.GetUserId()) if ret == true { // 命中插入5星英雄 szStar = append(szStar, 5) + heroRecord.Star5 = 0 // 重置保底 + star5Max++ // 记录当前 5星数量 continue } // 3,4,5 星权重 @@ -95,16 +97,34 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq if heroRecord.Inevitable == 0 && heroRecord.Drawcount > iStart && heroRecord.Drawcount < iEnd && iEnd >= iStart { n, _ := rand.Int(rand.Reader, big.NewInt(int64(iEnd-iStart))) if n.Int64() < 1 { // 抽中 - starIndex = star - 3 + starIndex = star heroRecord.Inevitable = heroRecord.Drawcount update["inevitable"] = heroRecord.Drawcount + szStar = append(szStar, star) + if star == 4 { + heroRecord.Star4 = 0 + star4Max++ + } else if star == 5 { + star5Max++ + heroRecord.Star5 = 0 + } + continue } } // 保底情况 if heroRecord.Drawcount == iEnd && heroRecord.Inevitable == 0 { - starIndex = star - 3 + starIndex = star heroRecord.Inevitable = heroRecord.Drawcount update["inevitable"] = heroRecord.Drawcount + szStar = append(szStar, star) + if star == 4 { + heroRecord.Star4 = 0 + star4Max++ + } else if star == 5 { + star5Max++ + heroRecord.Star5 = 0 + } + continue } } } diff --git a/modules/mainline/api_challengeover.go b/modules/mainline/api_challengeover.go index 0e88e6fee..97062a0c3 100644 --- a/modules/mainline/api_challengeover.go +++ b/modules/mainline/api_challengeover.go @@ -55,9 +55,14 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineCh } } // 校验通过 - code, isWin = this.module.battle.CheckBattleReport(session, req.Report) - if code != pb.ErrorCode_Success { - return + + if req.Report != nil { // 战斗失败 + code, isWin = this.module.battle.CheckBattleReport(session, req.Report) + if code != pb.ErrorCode_Success { + return + } + } else { + isWin = false } if !isWin { // 战斗失败直接返回 // 返还 @@ -66,7 +71,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineCh "ps": 0, }) - if code = this.module.DispenseRes(session, node.PsConsume, true); code != pb.ErrorCode_Success { // 扣1点 + if code = this.module.DispenseRes(session, node.PsConsume, true); code != pb.ErrorCode_Success { // 返还预扣体力 return } code = pb.ErrorCode_BattleNoWin diff --git a/modules/viking/api_challengeover.go b/modules/viking/api_challengeover.go index 34d551356..c8c71355f 100644 --- a/modules/viking/api_challengeover.go +++ b/modules/viking/api_challengeover.go @@ -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 { diff --git a/modules/viking/model_rank.go b/modules/viking/model_rank.go index 9540a3020..f1589e531 100644 --- a/modules/viking/model_rank.go +++ b/modules/viking/model_rank.go @@ -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 { diff --git a/modules/viking/module.go b/modules/viking/module.go index c504668b0..d73c6fbde 100644 --- a/modules/viking/module.go +++ b/modules/viking/module.go @@ -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...)