比赛场优化
This commit is contained in:
parent
48456483c7
commit
f3b757d0bc
|
@ -42,6 +42,7 @@ func (this *GameDropMgr) GetKey(gameid, basescore int32) string {
|
|||
}
|
||||
|
||||
func (this *GameDropMgr) Init() {
|
||||
this.GameDropData = make(map[string][]*GameDropData)
|
||||
gdArr := PBDB_Game_DropMgr.Datas.Arr
|
||||
if gdArr != nil {
|
||||
for _, drop := range gdArr {
|
||||
|
|
|
@ -11,7 +11,7 @@ type PlayerMatchContext struct {
|
|||
grade int32 //比赛积分
|
||||
rank int32 //当前第几名
|
||||
gaming bool //是否比赛中
|
||||
record map[int32]int32 //战绩
|
||||
record map[int32]int32 //战绩 胜负次数统计
|
||||
copySnid int32
|
||||
copyLv int32
|
||||
copyRoleId int32
|
||||
|
@ -40,6 +40,7 @@ func (p MatchContextSlice) Sort(isFinals bool) {
|
|||
mc.rank = int32(i + 1)
|
||||
}
|
||||
if isFinals {
|
||||
// 积分相同名次相同
|
||||
lastRank := int32(0)
|
||||
lastGrade := int32(0)
|
||||
for i := 0; i < len(p); i++ {
|
||||
|
|
|
@ -23,25 +23,25 @@ type MatchSceneMgr struct {
|
|||
// round 第几轮
|
||||
func (ms *MatchSceneMgr) NewScene(tm *TmMatch, isFinals bool, round int32) *Scene {
|
||||
sceneId := SceneMgrSingleton.GenOneMatchSceneId()
|
||||
|
||||
gameId := int(tm.dbGameFree.GameId)
|
||||
gameMode := tm.dbGameFree.GetGameMode()
|
||||
|
||||
// 获取游戏服务器
|
||||
gs := GameSessMgrSington.GetMinLoadSess(gameId)
|
||||
if gs == nil {
|
||||
logger.Logger.Warn("not found game server, gameid: ", gameId)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 平台
|
||||
limitPlatform := PlatformMgrSingleton.GetPlatform(tm.Platform)
|
||||
if limitPlatform == nil || !limitPlatform.Isolated {
|
||||
limitPlatform = PlatformMgrSingleton.GetPlatform(DefaultPlatform)
|
||||
}
|
||||
|
||||
finals := int32(0) // 是否决赛
|
||||
// 是否决赛
|
||||
finals := int32(0)
|
||||
if isFinals {
|
||||
finals = 1
|
||||
}
|
||||
// 获取本局比赛人数和下一局比赛人数
|
||||
curPlayerNum := int32(1) // 本轮比赛总人数
|
||||
nextNeed := int32(0) // 下一轮比赛总人数
|
||||
if tm.gmd != nil && len(tm.gmd.MatchPromotion) >= int(round) {
|
||||
|
@ -67,11 +67,9 @@ func (ms *MatchSceneMgr) NewScene(tm *TmMatch, isFinals bool, round int32) *Scen
|
|||
return nil
|
||||
}
|
||||
|
||||
// MatchStart 开始首轮比赛
|
||||
func (ms *MatchSceneMgr) MatchStart(tm *TmMatch) {
|
||||
scene := ms.NewScene(tm, false, 1)
|
||||
if scene != nil {
|
||||
ms.scenes[scene.sceneId] = scene
|
||||
}
|
||||
var scene *Scene
|
||||
for _, tmp := range tm.TmPlayer { //先进真人
|
||||
if scene == nil || scene.IsFull() {
|
||||
scene = ms.NewScene(tm, false, 1)
|
||||
|
@ -79,21 +77,26 @@ func (ms *MatchSceneMgr) MatchStart(tm *TmMatch) {
|
|||
ms.scenes[scene.sceneId] = scene
|
||||
}
|
||||
}
|
||||
|
||||
p := PlayerMgrSington.GetPlayerBySnId(tmp.SnId)
|
||||
if p != nil && p.scene == nil {
|
||||
mc := TournamentMgr.CreatePlayerMatchContext(p, tm, tmp.seq)
|
||||
if mc != nil {
|
||||
mc.gaming = true
|
||||
scene.PlayerEnter(mc.p, -1, true)
|
||||
}
|
||||
} else {
|
||||
if p != nil {
|
||||
logger.Logger.Error("MatchStart error: snid: ", p.SnId, " p.scene: ", p.scene)
|
||||
}
|
||||
|
||||
if p == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if p.scene != nil {
|
||||
logger.Logger.Errorf("MatchStart error: snid:%v in scene %v", p.SnId, p.scene.sceneId)
|
||||
continue
|
||||
}
|
||||
|
||||
mc := TournamentMgr.CreatePlayerMatchContext(p, tm, tmp.seq)
|
||||
if mc != nil {
|
||||
mc.gaming = true
|
||||
scene.PlayerEnter(p, -1, true)
|
||||
}
|
||||
}
|
||||
|
||||
if scene != nil && !scene.IsFull() { //填充机器人
|
||||
// 填充机器人
|
||||
if scene != nil && !scene.IsFull() {
|
||||
tm.RobotGradesDecline(1)
|
||||
needRobotNum := scene.playerNum - len(scene.players)
|
||||
logger.Logger.Trace("MatchStart 填充机器人", needRobotNum)
|
||||
|
@ -108,11 +111,9 @@ func (ms *MatchSceneMgr) MatchStart(tm *TmMatch) {
|
|||
}
|
||||
}
|
||||
|
||||
// NewRoundStart 开始非首轮比赛
|
||||
func (ms *MatchSceneMgr) NewRoundStart(tm *TmMatch, mct []*PlayerMatchContext, finals bool, round int32) {
|
||||
scene := ms.NewScene(tm, finals, round)
|
||||
if scene != nil {
|
||||
ms.scenes[scene.sceneId] = scene
|
||||
}
|
||||
var scene *Scene
|
||||
for _, tmp := range mct {
|
||||
if scene == nil || scene.IsFull() {
|
||||
scene = ms.NewScene(tm, finals, round)
|
||||
|
@ -121,21 +122,24 @@ func (ms *MatchSceneMgr) NewRoundStart(tm *TmMatch, mct []*PlayerMatchContext, f
|
|||
}
|
||||
}
|
||||
p := tmp.p
|
||||
if p != nil && p.scene == nil {
|
||||
if mc, ok := TournamentMgr.players[tm.SortId][p.SnId]; ok {
|
||||
mc.gaming = true
|
||||
mc.grade = mc.grade * 75 / 100 //积分衰减
|
||||
mc.rank = tmp.rank
|
||||
scene.PlayerEnter(mc.p, -1, true)
|
||||
}
|
||||
} else {
|
||||
if p != nil {
|
||||
logger.Logger.Error("NewRoundStart error: snid: ", p.SnId, " p.scene: ", p.scene)
|
||||
}
|
||||
if p == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if p.scene != nil {
|
||||
logger.Logger.Errorf("NewRoundStart error: snid:%v in scene %v", p.SnId, p.scene.sceneId)
|
||||
continue
|
||||
}
|
||||
|
||||
if mc, ok := TournamentMgr.players[tm.SortId][p.SnId]; ok {
|
||||
mc.gaming = true
|
||||
mc.grade = mc.grade * 75 / 100 //积分衰减
|
||||
mc.rank = tmp.rank
|
||||
scene.PlayerEnter(p, -1, true)
|
||||
}
|
||||
}
|
||||
|
||||
if scene != nil && !scene.IsFull() { //填充机器人
|
||||
// 填充机器人
|
||||
if scene != nil && !scene.IsFull() {
|
||||
tm.RobotGradesDecline(int(round))
|
||||
needRobotNum := scene.playerNum - len(scene.players)
|
||||
logger.Logger.Trace("NewRoundStart 填充机器人", needRobotNum)
|
||||
|
|
|
@ -22,6 +22,7 @@ type TmPlayer struct {
|
|||
SnId int32
|
||||
seq int // 报名序号(第几个报名的)
|
||||
}
|
||||
|
||||
type TmMatch struct {
|
||||
SortId int32 // 比赛开始时间戳,纳秒
|
||||
TMId int32 // 比赛配置Id
|
||||
|
@ -32,7 +33,7 @@ type TmMatch struct {
|
|||
dbGameFree *server.DB_GameFree // 游戏配置
|
||||
robotGrades map[int][]*TmGradeInfo // 第几轮:玩家积分
|
||||
copyRobotGrades []*TmGradeInfo // 最近一轮的机器人积分备份
|
||||
tmpUseRobot int32 // 是否使用机器人
|
||||
useRobot int32 // 是否使用机器人
|
||||
}
|
||||
|
||||
type TmGradeInfo struct {
|
||||
|
@ -98,6 +99,7 @@ func (tm *TmMatch) CopyMap(b map[int32]*TmPlayer) {
|
|||
}
|
||||
|
||||
// CreateRobotGrades 生成假积分
|
||||
// 完成机器人积分上升或下降
|
||||
func (tm *TmMatch) CreateRobotGrades(round int) {
|
||||
logger.Logger.Tracef("======创建假积分======当前第 %v 轮============", round)
|
||||
if tm.robotGrades == nil {
|
||||
|
@ -106,10 +108,10 @@ func (tm *TmMatch) CreateRobotGrades(round int) {
|
|||
if tm.robotGrades[round] == nil { //生成假数据
|
||||
gmd := tm.gmd
|
||||
lastPromotionNum := gmd.MatchPromotion[round-1] - 1 // 当前轮机器人数量
|
||||
logger.Logger.Trace("机器人数量: ", lastPromotionNum)
|
||||
logger.Logger.Tracef("CreateRobotGrades round:%v 机器人数量:%v", round, lastPromotionNum)
|
||||
|
||||
// 第初始轮数据
|
||||
if tm.robotGrades == nil || tm.robotGrades[round-1] == nil { //初始化数据
|
||||
// 上一轮数据,用在线玩家数据填充包含机器人,如果不够填充假数据
|
||||
if tm.robotGrades[round-1] == nil { //初始化数据
|
||||
tm.robotGrades[round-1] = []*TmGradeInfo{}
|
||||
snids := []int32{}
|
||||
lvs := []int32{}
|
||||
|
@ -167,29 +169,15 @@ func (tm *TmMatch) CreateRobotGrades(round int) {
|
|||
// 当前轮数据
|
||||
tm.robotGrades[round] = []*TmGradeInfo{}
|
||||
upNum := int32(math.Floor(float64(lastPromotionNum*tm.gml.RobotUpRatio) / 100.0))
|
||||
indexs := []int32{}
|
||||
for i := 0; i < int(lastPromotionNum); i++ {
|
||||
indexs = append(indexs, int32(i))
|
||||
}
|
||||
upIndexs := []int32{} // 积分上升的机器人
|
||||
for i := 0; i < int(upNum); i++ {
|
||||
randIndex := rand.Intn(len(indexs))
|
||||
upIndexs = append(upIndexs, indexs[randIndex])
|
||||
indexs = append(indexs[:randIndex], indexs[randIndex+1:]...)
|
||||
}
|
||||
downNum := lastPromotionNum - upNum
|
||||
downIndexs := []int32{} // 积分下降的机器人
|
||||
for i := 0; i < int(downNum); i++ {
|
||||
randIndex := rand.Intn(len(indexs))
|
||||
downIndexs = append(downIndexs, indexs[randIndex])
|
||||
indexs = append(indexs[:randIndex], indexs[randIndex+1:]...)
|
||||
}
|
||||
indexes := rand.Perm(int(lastPromotionNum))
|
||||
upIndexes := indexes[:upNum] // 积分上升的机器人
|
||||
downIndexes := indexes[upNum:] // 积分下降的机器人
|
||||
// 上升
|
||||
var n int32
|
||||
for _, v := range tm.gml.UpGradeOdds {
|
||||
n += v
|
||||
}
|
||||
for _, index := range upIndexs {
|
||||
for _, index := range upIndexes {
|
||||
grade := tm.robotGrades[round-1][index].grade
|
||||
r := rand.Int31n(n)
|
||||
t := int32(0)
|
||||
|
@ -215,7 +203,7 @@ func (tm *TmMatch) CreateRobotGrades(round int) {
|
|||
for _, v := range tm.gml.DownGradeOdds {
|
||||
n += v
|
||||
}
|
||||
for _, index := range downIndexs {
|
||||
for _, index := range downIndexes {
|
||||
grade := tm.robotGrades[round-1][index].grade
|
||||
r := rand.Int31n(n) //0-999
|
||||
t := int32(0)
|
||||
|
|
|
@ -43,9 +43,9 @@ const (
|
|||
// tournament
|
||||
|
||||
var TournamentMgr = &Tournament{
|
||||
GameMatchDateList: make(map[string]map[int32]*webapi_proto.GameMatchDate), //比赛配置
|
||||
matches: make(map[int32]map[int32]*TmMatch),
|
||||
GameMatchDateList: make(map[string]map[int32]*webapi_proto.GameMatchDate),
|
||||
signUpPlayers: make(map[string]map[int32]*SignInfo),
|
||||
matches: make(map[int32]map[int32]*TmMatch),
|
||||
players: make(map[int32]map[int32]*PlayerMatchContext),
|
||||
copyPlayers: make(map[int32]map[int32][]*PlayerMatchContext),
|
||||
rankPlayers: make(map[int32]map[int32][]*PlayerMatchContext),
|
||||
|
@ -59,11 +59,11 @@ var TournamentMgr = &Tournament{
|
|||
|
||||
type Tournament struct {
|
||||
GameMatchDateList map[string]map[int32]*webapi_proto.GameMatchDate // 比赛配置,platform:比赛场配置id:比赛配置
|
||||
matches map[int32]map[int32]*TmMatch // 开始比赛的数据,比赛配置Id:比赛顺序序号:一场开始的比赛数据
|
||||
signUpPlayers map[string]map[int32]*SignInfo // 报名的玩家 platform:比赛配置id:报名人
|
||||
matches map[int32]map[int32]*TmMatch // 开始比赛的数据,比赛配置Id:比赛顺序序号:一场开始的比赛数据
|
||||
players map[int32]map[int32]*PlayerMatchContext // 比赛中玩家 比赛顺序序号:snid:玩家信息
|
||||
copyPlayers map[int32]map[int32][]*PlayerMatchContext // 比赛玩家数据备份 比赛顺序序号:round:玩家信息
|
||||
rankPlayers map[int32]map[int32][]*PlayerMatchContext //比赛玩家为了每轮积分排名用 比赛顺序序号,round
|
||||
rankPlayers map[int32]map[int32][]*PlayerMatchContext // 比赛玩家为了每轮积分排名用 比赛顺序序号:round
|
||||
roundOverPlayerNum map[int32]map[int32]int32 // 完成比赛人数 比赛序号:轮次:人数
|
||||
finalPerRank map[int32][]*PerRankInfo //本场比赛最后排名,每淘汰一位记录一位,最后记录决赛玩家
|
||||
playerWaitStart map[int32]int64 // 等待时间 玩家Id:等待时长秒
|
||||
|
@ -117,7 +117,7 @@ func (this *Tournament) checkData(cfg *webapi_proto.GameMatchDate) bool {
|
|||
if num%4 != 0 { //必须是4的整倍数
|
||||
return false
|
||||
}
|
||||
if num < cfg.MatchPromotion[i+1] { //必须递减
|
||||
if num <= cfg.MatchPromotion[i+1] { //必须递减
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -604,11 +604,11 @@ func (this *Tournament) Start(platform string, tmId int32) {
|
|||
signInfo := this.signUpPlayers[platform][tmId]
|
||||
sortId := int32(time.Now().Nanosecond())
|
||||
tm := &TmMatch{
|
||||
TMId: tmId,
|
||||
SortId: sortId,
|
||||
gmd: matchInfo,
|
||||
Platform: signInfo.Platform,
|
||||
tmpUseRobot: matchInfo.UseRobot,
|
||||
TMId: tmId,
|
||||
SortId: sortId,
|
||||
gmd: matchInfo,
|
||||
Platform: signInfo.Platform,
|
||||
useRobot: matchInfo.UseRobot,
|
||||
}
|
||||
tm.gml = srvdata.MatchLevelMgr.Get(matchInfo.GameFreeId, matchInfo.MatchLevel)
|
||||
tm.dbGameFree = srvdata.PBDB_GameFreeMgr.GetData(matchInfo.GameFreeId)
|
||||
|
@ -686,6 +686,7 @@ func (this *Tournament) NextRoundStartSingle(sortId int32, mtp *PlayerMatchConte
|
|||
index = gmd.MatchPromotion[mtp.round-1]
|
||||
}
|
||||
if index <= promotionNum {
|
||||
// 晋级
|
||||
mtp.rank = index
|
||||
this.sendPromotionInfo(mtp, sortId, JinJi, false, false) //晋级
|
||||
|
||||
|
@ -699,6 +700,7 @@ func (this *Tournament) NextRoundStartSingle(sortId int32, mtp *PlayerMatchConte
|
|||
return true
|
||||
}), nil, time.Second*7, 1)
|
||||
} else {
|
||||
// 淘汰
|
||||
mtp.rank = index
|
||||
pri := &PerRankInfo{
|
||||
Name: mtp.p.Name,
|
||||
|
@ -916,7 +918,7 @@ func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int32,
|
|||
return
|
||||
}
|
||||
rankId := mc.rank
|
||||
if mc.tm.tmpUseRobot == MatchNotUserRobot { // 不使用机器人
|
||||
if mc.tm.useRobot == MatchNotUserRobot { // 不使用机器人
|
||||
rankId = this.getRank(sortId, mc.round, mc.p.SnId, isFinals)
|
||||
mc.rank = rankId
|
||||
}
|
||||
|
@ -1275,7 +1277,7 @@ func (this *Tournament) UpdateMatchInfo(p *Player, sortId, grade, isWin int32, m
|
|||
}
|
||||
this.rankPlayers[sortId][mtp.round] = append(this.rankPlayers[sortId][mtp.round], &mc)
|
||||
logger.Logger.Tracef("========snid(%v) grade(%v) ============", p.SnId, grade)
|
||||
if mtp.tm.tmpUseRobot == MatchUseRobot { // 使用机器人
|
||||
if mtp.tm.useRobot == MatchUseRobot { // 使用机器人
|
||||
this.NextRoundStartSingle(sortId, mtp, matchRobotGrades)
|
||||
} else {
|
||||
this.NextRoundStart(sortId, mtp)
|
||||
|
|
Loading…
Reference in New Issue