比赛场数据统计
This commit is contained in:
parent
0e6487256a
commit
355c6aae93
|
@ -7,32 +7,15 @@ import (
|
||||||
"github.com/globalsign/mgo/bson"
|
"github.com/globalsign/mgo/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
MATCHPLAYER_FLAG_ISROB uint = iota //机器人
|
|
||||||
MATCHPLAYER_FLAG_ISFIRST //首次参赛
|
|
||||||
MATCHPLAYER_FLAG_ISNEWBIE //新人
|
|
||||||
MATCHPLAYER_FLAG_ISQUIT //退赛
|
|
||||||
MATCHPLAYER_FLAG_SIGNUP_USEFREE //免费报名
|
|
||||||
MATCHPLAYER_FLAG_SIGNUP_USETICKET //使用报名券报名
|
|
||||||
MATCHPLAYER_FLAG_SIGNUP_USECOIN //使用金币报名
|
|
||||||
)
|
|
||||||
|
|
||||||
// 比赛各阶段时间消耗
|
|
||||||
type MatchProcessTimeSpend struct {
|
|
||||||
Name string //赛程名称
|
|
||||||
MMType int32 //赛制类型
|
|
||||||
Spend int32 //用时,单位:秒
|
|
||||||
}
|
|
||||||
|
|
||||||
// 比赛参赛人员信息
|
// 比赛参赛人员信息
|
||||||
type MatchPlayer struct {
|
type MatchPlayer struct {
|
||||||
SnId int32 //玩家id
|
SnId int32 //玩家id
|
||||||
Flag int32 //玩家类型,二进制 第1位:1是机器人,0玩家 第2位:1首次参加 0:非首次参加 第3位:1新人 0:老玩家 第4位:1退赛 0未退赛 第5位: 1免费报名 第6位: 1使用入场券报名 第7位: 1使用金币报名
|
CostCoin int64 //报名消耗金币
|
||||||
Spend int32 //报名消耗
|
CostDiamond int64 //报名消耗钻石
|
||||||
Gain int32 //获得奖励
|
Coin int64 //比赛获得金币
|
||||||
Rank int32 //名次
|
Diamond int64 //比赛获得钻石
|
||||||
WaitTime int32 //从报名到开始比赛的等待时间 单位:秒
|
Item map[int32]int64 //比赛获得物品id
|
||||||
MatchTime int32 //比赛中用时 从开始比赛到比赛结束总的用时 单位:秒
|
Rank int32 //名次
|
||||||
}
|
}
|
||||||
|
|
||||||
// 比赛牌局记录
|
// 比赛牌局记录
|
||||||
|
@ -47,35 +30,14 @@ type MatchGameLog struct {
|
||||||
|
|
||||||
// 比赛详情
|
// 比赛详情
|
||||||
type MatchLog struct {
|
type MatchLog struct {
|
||||||
Id bson.ObjectId `bson:"_id"`
|
Id bson.ObjectId `bson:"_id"`
|
||||||
Platform string //平台编号
|
Platform string //平台编号
|
||||||
MatchId int32 //比赛编号
|
MatchId int32 //比赛编号
|
||||||
MatchName string //比赛名称
|
MatchName string //比赛名称
|
||||||
GameFreeId int32 //游戏类型
|
GameFreeId int32 //游戏类型
|
||||||
StartTime time.Time //开始时间
|
StartTime time.Time //开始时间
|
||||||
EndTime time.Time //结束时间
|
EndTime time.Time //结束时间
|
||||||
Players []*MatchPlayer //参赛人员数据
|
Players []*MatchPlayer //参赛人员数据
|
||||||
TimeSpend []*MatchProcessTimeSpend //赛程用时
|
|
||||||
GameLogs []*MatchGameLog //牌局记录
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ml *MatchLog) AppendMatchProcess(name string, mmtype int32, spend int32) {
|
|
||||||
ml.TimeSpend = append(ml.TimeSpend, &MatchProcessTimeSpend{
|
|
||||||
Name: name,
|
|
||||||
MMType: mmtype,
|
|
||||||
Spend: spend,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ml *MatchLog) AppendGameLog(name string, gamelogId string, processIdx, numOfGame, spendTime int32, snids []int32) {
|
|
||||||
ml.GameLogs = append(ml.GameLogs, &MatchGameLog{
|
|
||||||
Name: name,
|
|
||||||
GameLogId: gamelogId,
|
|
||||||
ProcessIdx: processIdx,
|
|
||||||
NumOfGame: numOfGame,
|
|
||||||
SpendTime: spendTime,
|
|
||||||
SnIds: snids,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -34,6 +34,7 @@ type TmMatch struct {
|
||||||
robotGrades map[int][]*TmGradeInfo // 第几轮:玩家积分
|
robotGrades map[int][]*TmGradeInfo // 第几轮:玩家积分
|
||||||
copyRobotGrades []*TmGradeInfo // 最近一轮的机器人积分备份
|
copyRobotGrades []*TmGradeInfo // 最近一轮的机器人积分备份
|
||||||
useRobot int32 // 是否使用机器人
|
useRobot int32 // 是否使用机器人
|
||||||
|
StartTime int64 // 本场比赛开始时间
|
||||||
}
|
}
|
||||||
|
|
||||||
type TmGradeInfo struct {
|
type TmGradeInfo struct {
|
||||||
|
@ -52,7 +53,7 @@ func (tm *TmMatch) Start() {
|
||||||
proto.SetDefaults(pack)
|
proto.SetDefaults(pack)
|
||||||
logger.Logger.Trace("SCTMStart:", pack)
|
logger.Logger.Trace("SCTMStart:", pack)
|
||||||
tm.BroadcastMessage(int(tournament.TOURNAMENTID_PACKET_TM_SCTMStart), pack)
|
tm.BroadcastMessage(int(tournament.TOURNAMENTID_PACKET_TM_SCTMStart), pack)
|
||||||
|
tm.StartTime = time.Now().Unix()
|
||||||
//创建房间
|
//创建房间
|
||||||
timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool {
|
timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool {
|
||||||
MatchSceneMgrSingleton.MatchStart(tm)
|
MatchSceneMgrSingleton.MatchStart(tm)
|
||||||
|
|
|
@ -1010,6 +1010,24 @@ func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int32,
|
||||||
this.CheckAddMatchSeasonLv(mc)
|
this.CheckAddMatchSeasonLv(mc)
|
||||||
}
|
}
|
||||||
delete(this.players[sortId], mc.p.SnId)
|
delete(this.players[sortId], mc.p.SnId)
|
||||||
|
//真人被淘汰,如果剩下的都是机器人,比赛解散
|
||||||
|
if !mc.p.IsRob {
|
||||||
|
if this.players[sortId] != nil {
|
||||||
|
hasReal := false
|
||||||
|
for snid, context := range this.players[sortId] {
|
||||||
|
if !context.p.IsRob && !this.isOut(sortId, snid) { // 有真人没有淘汰
|
||||||
|
hasReal = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//没有真人比赛解散
|
||||||
|
if !hasReal {
|
||||||
|
logger.Logger.Trace("没有真人比赛解散")
|
||||||
|
this.StopMatch(mc.tm.TMId, sortId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1196,6 +1214,8 @@ func (this *Tournament) CheckAddMatchSeasonLv(mc *PlayerMatchContext) {
|
||||||
func (this *Tournament) StopMatch(tmId, sortId int32) {
|
func (this *Tournament) StopMatch(tmId, sortId int32) {
|
||||||
//房间清理
|
//房间清理
|
||||||
if this.matches[tmId] != nil && this.matches[tmId][sortId] != nil {
|
if this.matches[tmId] != nil && this.matches[tmId][sortId] != nil {
|
||||||
|
matchLog := this.MakeMatchLog(this.matches[tmId][sortId].Platform, tmId, sortId)
|
||||||
|
this.saveMatchLog(matchLog)
|
||||||
this.matches[tmId][sortId].Stop()
|
this.matches[tmId][sortId].Stop()
|
||||||
delete(this.matches[tmId], sortId)
|
delete(this.matches[tmId], sortId)
|
||||||
}
|
}
|
||||||
|
@ -1426,3 +1446,62 @@ func (this *Tournament) Shutdown() {
|
||||||
func init() {
|
func init() {
|
||||||
module.RegisteModule(TournamentMgr, time.Second, 0)
|
module.RegisteModule(TournamentMgr, time.Second, 0)
|
||||||
}
|
}
|
||||||
|
func (this *Tournament) MakeMatchLog(platform string, tmId, sortId int32) *model.MatchLog {
|
||||||
|
gameMatchDate := this.GetMatchInfo(platform, tmId)
|
||||||
|
matchLog := model.NewMatchLog()
|
||||||
|
players := this.copyPlayers[sortId][1]
|
||||||
|
for _, player := range players {
|
||||||
|
if !player.p.IsRob {
|
||||||
|
|
||||||
|
var coin, diamond int64
|
||||||
|
items := make(map[int32]int64)
|
||||||
|
rankId := int32(-1)
|
||||||
|
perRankInfo := this.finalPerRank[sortId]
|
||||||
|
for _, info := range perRankInfo {
|
||||||
|
if info.SnId == player.p.SnId {
|
||||||
|
rankId = info.RankId
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gameMatchDate.Award != nil {
|
||||||
|
for _, award := range gameMatchDate.Award {
|
||||||
|
if rankId >= award.UpLimit && rankId <= award.DownLimit { //上下限是反的,我也是醉了
|
||||||
|
coin = award.Coin
|
||||||
|
diamond = award.Diamond
|
||||||
|
if award.ItemId != nil {
|
||||||
|
for _, info := range award.ItemId {
|
||||||
|
items[info.ItemId] = info.ItemNum
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matchLog.Players = append(matchLog.Players, &model.MatchPlayer{
|
||||||
|
SnId: player.p.SnId,
|
||||||
|
CostCoin: this.matches[tmId][sortId].gmd.SignupCostCoin,
|
||||||
|
CostDiamond: this.matches[tmId][sortId].gmd.SignupCostDiamond,
|
||||||
|
Coin: coin,
|
||||||
|
Diamond: diamond,
|
||||||
|
Item: items,
|
||||||
|
Rank: rankId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matchLog.MatchId = tmId
|
||||||
|
matchLog.MatchName = gameMatchDate.MatchName
|
||||||
|
matchLog.Platform = platform
|
||||||
|
matchLog.GameFreeId = gameMatchDate.GameFreeId
|
||||||
|
matchLog.StartTime = time.Unix(this.matches[tmId][sortId].StartTime, 0)
|
||||||
|
matchLog.EndTime = time.Now()
|
||||||
|
logger.Logger.Trace("比赛场log记录", matchLog)
|
||||||
|
return matchLog
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Tournament) saveMatchLog(matchLog *model.MatchLog) {
|
||||||
|
err := model.InsertMatchLogs(matchLog)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Error("saveMatchLog error %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue