From 00b0e0100082fc05e0f671c6cdd0fc323ce4a521 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Wed, 21 Aug 2024 10:46:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=94=E8=B5=9B=E8=A7=82=E6=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worldsrv/action_tournament.go | 8 ++-- worldsrv/tmmatch.go | 8 +++- worldsrv/tournament.go | 78 ++++++++++++++++++++++++++++++++--- 3 files changed, 84 insertions(+), 10 deletions(-) diff --git a/worldsrv/action_tournament.go b/worldsrv/action_tournament.go index bcebbf6..dbbbf14 100644 --- a/worldsrv/action_tournament.go +++ b/worldsrv/action_tournament.go @@ -199,13 +199,15 @@ func CSRoomList(s *netlib.Session, packetId int, data interface{}, sid int64) er if v.matchCtx == nil { continue } + + p := PlayerMgrSington.GetPlayerBySnId(v.matchCtx.copySnid) + d := &tournament.MatchPlayer{ SnId: v.matchCtx.copySnid, - Name: v.Name, - HeadUrl: v.HeadUrl, + Name: p.GetName(), UseRoleId: v.matchCtx.copyRoleId, UseSkinId: v.matchCtx.copySkinId, - Rank: v.matchCtx.rank, + Rank: TournamentMgr.GetRank(tm.SortId, v.matchCtx.copySnid), Score: v.matchCtx.grade, } room.Players = append(room.Players, d) diff --git a/worldsrv/tmmatch.go b/worldsrv/tmmatch.go index 482162c..bc23dc5 100644 --- a/worldsrv/tmmatch.go +++ b/worldsrv/tmmatch.go @@ -19,6 +19,10 @@ import ( "mongo.games.com/game/srvdata" ) +func getSortId() int64 { + return time.Now().UnixMilli() +} + type TmPlayer struct { SnId int32 seq int // 报名序号(第几个报名的) @@ -30,6 +34,7 @@ type TmGradeInfo struct { copyLv int32 copyRoleId int32 CopySkinId int32 + rank int32 } type TmMatch struct { @@ -48,7 +53,7 @@ type TmMatch struct { func NewTmMatch(platform string, match *webapi_proto.GameMatchDate, players map[int32]*TmPlayer) *TmMatch { ret := &TmMatch{ - SortId: time.Now().UnixNano(), + SortId: getSortId(), TMId: match.Id, TmPlayer: make(map[int32]*TmPlayer), Platform: platform, @@ -307,6 +312,7 @@ func (tm *TmMatch) RobotGradesDecline(round int) { copyLv: info.copyLv, copyRoleId: info.copyRoleId, CopySkinId: info.CopySkinId, + rank: info.rank, } tm.robotGrades[lastRound][i] = gradeInfo if info.copySnid != 0 { diff --git a/worldsrv/tournament.go b/worldsrv/tournament.go index 02bf60e..8519cf2 100644 --- a/worldsrv/tournament.go +++ b/worldsrv/tournament.go @@ -154,8 +154,8 @@ func (this *Tournament) addFinalPlayer(sortId int64, p *PerRankInfo) { this.finalPerRank[sortId] = append(this.finalPerRank[sortId], p) } -// 查询一场比赛某轮的历史数据 -func (this *Tournament) getRoundPlayer(sortId int64, round int32) *PlayerRoundInfo { +// GetRoundPlayer 查询一场比赛某轮的历史数据 +func (this *Tournament) GetRoundPlayer(sortId int64, round int32) *PlayerRoundInfo { _, ok := this.roundPlayers[sortId] if !ok { return nil @@ -923,6 +923,59 @@ func (this *Tournament) getRank(sortId int64, round, snid int32, isFinals bool) return 0 } +// GetRank 获取排名 +func (this *Tournament) GetRank(sortId int64, snid int32) int32 { + tm := this.GetTm(sortId) + if tm == nil { + return 0 + } + round := this.GetRound(sortId) + useRobot := this.IsRobotOn(tm.gmd) + + robotRankFunc := func(n int, snid int32) int32 { + rank := int32(0) + for _, v := range tm.robotGrades[n] { + if v.copySnid == snid { + return v.rank + } + if v.copySnid == 0 { + rank = v.rank + } + } + return rank + } + + playerRankFunc := func(n int, snid int32) int32 { + d := this.GetRoundPlayer(sortId, int32(n)) + if d != nil { + for _, v := range d.players { + if v.p.SnId == snid { + return v.rank + } + } + } + d = this.GetRoundPlayer(sortId, int32(n-1)) + if d != nil { + for _, v := range d.players { + if v.p.SnId == snid { + return v.rank + } + } + } + return 0 + } + + if round <= 1 { + return 0 + } else { + if useRobot { + return robotRankFunc(int(round-1), snid) + } else { + return playerRankFunc(int(round-1), snid) + } + } +} + // UpdateMatchInfo 玩家比赛结束 更新积分 func (this *Tournament) UpdateMatchInfo(p *Player, sortId int64, grade, isWin int32, matchRobotGrades map[int32]int32) { logger.Logger.Tracef("UpdateMatchInfo: sortId:%v, grade:%v, isWin: %v, matchRobotGrades:%v", sortId, grade, isWin, matchRobotGrades) @@ -999,7 +1052,7 @@ func (this *Tournament) stopMatch(matchId int32, sortId int64) (isOver bool) { // 开启机器人时使用 func (this *Tournament) NextRoundStartSingle(sortId int64, playerCtx *PlayerMatchContext, matchRobotGrades map[int32]int32) { logger.Logger.Tracef("NextRoundStartSingle 当前第 %v 轮", playerCtx.round) - info := this.getRoundPlayer(sortId, playerCtx.round) + info := this.GetRoundPlayer(sortId, playerCtx.round) if info == nil { return } @@ -1042,11 +1095,24 @@ func (this *Tournament) NextRoundStartSingle(sortId int64, playerCtx *PlayerMatc } sort.Slice(arr, func(i, j int) bool { + if arr[i].grade == arr[j].grade { // 真人在前 + if arr[i].copySnid == 0 { + return true + } + if arr[j].copySnid == 0 { + return false + } + } return arr[i].grade > arr[j].grade }) + for k, v := range arr { + v.rank = int32(k + 1) + } + playerCtx.tm.robotGrades[int(round)] = arr for _, info := range arr { - logger.Logger.Tracef("NextRoundStart_Single 本轮积分排名 Snid:%v Grade:%v copyLv:%v copyRoleId:%v", info.copySnid, info.grade, info.copyLv, info.copyRoleId) + logger.Logger.Tracef("NextRoundStart_Single 本轮积分排名 round:%v Snid:%v Grade:%v copyLv:%v copyRoleId:%v rank:%v", + playerCtx.round, info.copySnid, info.grade, info.copyLv, info.copyRoleId, info.rank) } // 获取排名 @@ -1117,7 +1183,7 @@ func (this *Tournament) NextRoundStartSingle(sortId int64, playerCtx *PlayerMatc // 关闭机器时使用 func (this *Tournament) NextRoundStart(sortId int64, playerCtx *PlayerMatchContext) { logger.Logger.Tracef("NextRoundStart 当前第 %v 轮", playerCtx.round) - info := this.getRoundPlayer(sortId, playerCtx.round) + info := this.GetRoundPlayer(sortId, playerCtx.round) if info == nil { return } @@ -1158,7 +1224,7 @@ func (this *Tournament) NextRoundStart(sortId int64, playerCtx *PlayerMatchConte info.players = info.players[len(ps):] willOut := false - if promotionNum1 == this.getRoundPlayer(sortId, playerCtx.round-1).num { + if promotionNum1 == this.GetRoundPlayer(sortId, playerCtx.round-1).num { // 最后一个人打完了,确定要淘汰的人 willOut = true } else {