比赛观战
This commit is contained in:
parent
cd321a3f55
commit
00b0e01000
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue