Merge branch 'look' into develop

This commit is contained in:
sk 2024-08-15 16:28:50 +08:00
commit b1c936fae8
21 changed files with 2057 additions and 1760 deletions

View File

@ -6,7 +6,7 @@
"VerifyClientVersion":true,
"SrvMaintain":false,
"WhiteHttpAddr": [],
"HundredScenePreCreate":true,
"HundredScenePreCreate":false,
"WriteEventLog": true,
"SpreadAccountQPT":100,
"FakeVerifyCode":"123456",

View File

@ -2,17 +2,26 @@ package svc
import (
"errors"
"net/rpc"
"github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/dbproxy/mongo"
"mongo.games.com/game/model"
"net/rpc"
)
var (
MatchAwardLogDBErr = errors.New("log_matchawardlog db open failed.")
MatchAwardDBErr = errors.New("log_matchawardlog db open failed")
)
func MatchAwardLogCollection(plt string) *mongo.Collection {
type MatchAwardLog struct {
AwardNum map[string]map[int32]int32 // 奖励数量
Platform string
}
func MatchAwardCollection(plt string) *mongo.Collection {
s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, model.MatchAwardLogDBName)
if s != nil {
c, _ := s.DB().C(model.MatchAwardLogCollName)
@ -21,47 +30,55 @@ func MatchAwardLogCollection(plt string) *mongo.Collection {
return nil
}
func InsertOrUpdateMatchAwardLog(logs ...*model.MatchAwardLog) (err error) {
for _, log := range logs {
clog := MatchAwardLogCollection(log.Platform)
if clog == nil {
return
}
_, err = clog.Upsert(nil, log)
if err != nil {
// 处理错误
return err
}
}
return
type MatchAwardSvc struct {
}
type MatchAwardLogSvc struct {
}
func (svc *MatchAwardSvc) UpsertMatchAward(req *model.MatchAward, ret *bool) (err error) {
c := MatchAwardCollection(req.Platform)
if c == nil {
return MatchAwardDBErr
}
func (svc *MatchAwardLogSvc) InsertOrUpdateMatchAwardLog(args []*model.MatchAwardLog, ret *bool) (err error) {
err = InsertOrUpdateMatchAwardLog(args...)
if err == nil {
*ret = true
}
return
}
func GetMatchAward(plt string, ret *model.MatchAwardLog) (err error) {
clog := MatchAwardLogCollection(plt)
if clog == nil {
return nil
}
selecter := bson.M{"platform": plt}
err = clog.Find(selecter).One(&ret)
_, err = c.Upsert(nil, req)
if err != nil {
return nil
logger.Logger.Errorf("UpsertMatchAward err:%v", err)
}
return
}
func (svc *MatchAwardLogSvc) GetMatchAward(Plt string, ret *model.MatchAwardLog) (err error) {
err = GetMatchAward(Plt, ret)
return err
}
func init() {
rpc.Register(new(MatchAwardLogSvc))
func (svc *MatchAwardSvc) GetMatchAward(plt string, ret *model.MatchAward) (err error) {
c := MatchAwardCollection(plt)
if c == nil {
return MatchAwardDBErr
}
// 旧数据
old := &MatchAwardLog{}
err = c.Find(bson.M{"platform": "1"}).One(old)
if err == nil {
for k, v := range old.AwardNum {
d := &model.MatchAward{
Platform: k,
Award: make(map[int32]int32),
}
for kk, vv := range v {
d.Award[kk] = vv
}
var b bool
svc.UpsertMatchAward(d, &b)
}
c.Remove(bson.M{"platform": "1"})
}
// 旧数据
err = nil
err = c.Find(nil).One(ret)
if err != nil && err != mgo.ErrNotFound {
logger.Logger.Errorf("GetMatchAward err:%v", err)
}
return err
}
func init() {
rpc.Register(new(MatchAwardSvc))
}

View File

@ -39,4 +39,5 @@ const (
ETCDKEY_RANK_TYPE = "/game/RankType" // 排行榜奖励配置
ETCDKEY_AWARD_CONFIG = "/game/awardlog_config" //获奖记录
ETCDKEY_GUIDE = "/game/guide_config" //新手引导配置
ETCDKEY_MatchAudience = "/game/match_audience" //比赛观众
)

View File

@ -135,6 +135,7 @@ type AllConfig struct {
*webapi.AwardLogConfig
// 新手引导配置
*webapi.GuideConfig
MatchAudience map[int32]*webapi.MatchAudience // 比赛观众列表
}
type GlobalConfig struct {
@ -163,6 +164,7 @@ func (cm *ConfigMgr) GetConfig(platform string) *AllConfig {
EntrySwitch: make(map[int32]*webapi.EntrySwitch),
ShopInfos: make(map[int32]*ShopInfo),
ChannelSwitch: make(map[int32]*webapi.ChannelSwitchConfig),
MatchAudience: make(map[int32]*webapi.MatchAudience),
}
cm.platform[platform] = c
}
@ -356,3 +358,18 @@ func (cm *ConfigMgr) GetSkinSkillMaxLevel(plt string, skinId int32) int32 {
}
return level
}
func (cm *ConfigMgr) AddMatchAudience(d *webapi.MatchAudience) {
cfg := cm.GetConfig(d.Platform)
cfg.MatchAudience[d.GetSnId()] = d
}
func (cm *ConfigMgr) DelMatchAudience(d *webapi.MatchAudience) {
delete(cm.GetConfig(d.Platform).MatchAudience, d.GetSnId())
}
// IsMatchAudience 是不是比赛场观众
func (cm *ConfigMgr) IsMatchAudience(plt string, snId int32) bool {
_, ok := cm.GetConfig(plt).MatchAudience[snId]
return ok
}

View File

@ -4,30 +4,29 @@ import (
"time"
)
// 比赛详情
type MatchAwardLog struct {
AwardNum map[string]map[int32]int32 // 奖励数量
Platform string
}
var (
MatchAwardLogDBName = "log"
MatchAwardLogCollName = "log_matchawardlog"
)
func NewMatchAwardLog() *MatchAwardLog {
return &MatchAwardLog{}
type MatchAward struct {
Platform string `bson:"-"`
Award map[int32]int32
}
func InsertOrUpdateMatchAwardLog(logs ...*MatchAwardLog) (err error) {
func UpsertMatchAward(data *MatchAward) error {
if rpcCli == nil {
return ErrRPClientNoConn
}
var ret bool
return rpcCli.CallWithTimeout("MatchAwardLogSvc.InsertOrUpdateMatchAwardLog", logs, &ret, time.Second*30)
return rpcCli.CallWithTimeout("MatchAwardSvc.UpsertMatchAward", data, &ret, time.Second*30)
}
func GetMatchAwardLog(platform string) (ret MatchAwardLog, err error) {
err = rpcCli.CallWithTimeout("MatchAwardLogSvc.GetMatchAward", platform, &ret, time.Second*30)
return ret, err
func GetMatchAward(platform string) (ret *MatchAward, err error) {
if rpcCli == nil {
return nil, ErrRPClientNoConn
}
ret = new(MatchAward)
err = rpcCli.CallWithTimeout("MatchAwardSvc.GetMatchAward", platform, ret, time.Second*30)
return
}

View File

@ -66,7 +66,7 @@
- 2720~2739
#### tournament锦标赛
- 2740~2759
- 2740~2779
#### RankMatch 排位赛
- 2780~2800

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,10 @@ enum TOURNAMENTID{
PACKET_TM_SCTMSeasonRank = 2754;//
PACKET_TM_CSTMSeasonAward = 2755;//
PACKET_TM_SCTMSeasonAward = 2756;//
PACKET_TM_CSMatchList = 2757;//
PACKET_TM_SCMatchList = 2758;//
PACKET_TM_CSRoomList = 2759; //
PACKET_TM_SCRoomList = 2760; //
}
//
//PACKET_TM_CSTMInfo
@ -65,6 +69,7 @@ message TMInfo{
repeated string OnChannelName = 21;//
int32 ShowId = 22; //
int32 AwardNum = 23; //
int32 AudienceSwitch = 27; // 1 2
}
message MatchTypeInfo{
@ -187,4 +192,57 @@ message CSTMSeasonAward {
message SCTMSeasonAward {
int32 Lv = 1;//
int32 Code = 2;//0 1
}
//PACKET_TM_CSMatchList
message CSMatchList{
int64 MatchId = 1; // id 0
int32 Tp = 2; // 0 1
}
message MatchPlayer{
int32 SnId = 1; // id
string Name = 2; //
string HeadUrl = 3;//
int32 UseRoleId = 4;//使id
int32 UseSkinId = 5; // id
int32 Rank = 6;//
int32 Score = 7;//
}
message MatchInfo{
int64 MatchId = 1; // id
int64 InstanceId = 2; // id
string Name = 3; //
int32 Round = 4; //
int32 TotalRound = 5; //
int32 RemainNum = 6; //
repeated MatchPlayer Players = 7; //
}
message SCTMMatchList{
repeated MatchInfo List = 1;
int64 MatchId = 2;
int32 Tp = 3;
}
//PACKET_TM_CSRoomList
message CSRoomList{
int64 Id = 1; // id 0
int32 Tp = 2; // 0 1
}
message MatchRoom{
int64 RoomId = 1; // id
int64 MatchId = 2; // id
int64 InstanceId = 3; // id
int32 Round = 4; //
int32 TotalRound = 5; //
repeated MatchPlayer Players = 7; //
}
message SCRoomList{
repeated MatchRoom List = 1;
int64 Id = 2;
int32 Tp = 3;
}

File diff suppressed because it is too large Load Diff

View File

@ -490,6 +490,7 @@ message GameMatchDate {
int32 CardType = 24; //
int32 ShowId = 25; //
int32 AwardNum = 26; //
int32 AudienceSwitch = 27; // 1 2
}
// etcd /game/game_match
@ -889,4 +890,11 @@ message GuideConfig {
string Platform = 1; //
int32 On = 2; // 1 2
int32 Skip = 3; // 1 2
}
// etcd /game/match_audience
message MatchAudience {
string Platform = 1; //
int32 SnId = 2; // ID
int64 Ts = 3; //
}

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
package main
import (
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib"
"mongo.games.com/game/common"
"mongo.games.com/game/protocol/tournament"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/netlib"
"sort"
)
func CSTMInfo(s *netlib.Session, packetid int, data interface{}, sid int64) error {
@ -94,9 +94,135 @@ func CSSignRace(s *netlib.Session, packetid int, data interface{}, sid int64) er
return nil
}
func CSMatchList(s *netlib.Session, packetId int, data interface{}, sid int64) error {
logger.Logger.Trace("CSMatchList ", data)
msg, ok := data.(*tournament.CSMatchList)
if !ok {
return nil
}
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSMatchList p == nil.")
return nil
}
pack := &tournament.SCTMMatchList{
MatchId: msg.GetMatchId(),
Tp: msg.GetTp(),
}
audience := msg.GetTp() == 1
list := TournamentMgr.GetTmMatch(p.Platform, int32(msg.GetMatchId()), p.LastChannel, audience, 0)
// 开始时间排序
sort.Slice(list, func(i, j int) bool {
return list[i].StartTime < list[j].StartTime
})
for _, v := range list {
round := TournamentMgr.GetRound(v.SortId)
d := &tournament.MatchInfo{
MatchId: int64(v.TMId),
InstanceId: v.SortId,
Name: v.gmd.MatchName,
Round: round,
TotalRound: v.GetTotalRound(),
RemainNum: TournamentMgr.GetRemainNum(v.SortId),
}
for _, v := range TournamentMgr.GetRemainPlayer(v.SortId) {
var name, headUrl string
p := PlayerMgrSington.GetPlayerBySnId(v.SnId)
if p != nil {
name = p.Name
headUrl = p.HeadUrl
}
d.Players = append(d.Players, &tournament.MatchPlayer{
SnId: v.SnId,
Name: name,
HeadUrl: headUrl,
UseRoleId: v.RoleId,
UseSkinId: v.SkinId,
Rank: v.Rank,
Score: v.Grade,
})
}
sort.Slice(d.Players, func(i, j int) bool {
if d.Players[i].Score > d.Players[j].Score {
return true
}
if d.Players[i].Score < d.Players[j].Score {
return false
}
return d.Players[i].SnId < d.Players[j].SnId
})
pack.List = append(pack.List, d)
}
p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCMatchList), pack)
logger.Logger.Tracef("SCMatchList %v", pack)
return nil
}
func CSRoomList(s *netlib.Session, packetId int, data interface{}, sid int64) error {
logger.Logger.Trace("CSRoomList ", data)
msg, ok := data.(*tournament.CSRoomList)
if !ok {
return nil
}
p := PlayerMgrSington.GetPlayer(sid)
if p == nil {
logger.Logger.Warnf("CSRoomList p == nil.")
return nil
}
pack := &tournament.SCRoomList{
Id: msg.GetId(),
Tp: msg.GetTp(),
}
audience := msg.GetTp() == 1
scenes := TournamentMgr.GetTmRoom(p.Platform, 0, p.LastChannel, audience, msg.GetId())
for _, v := range scenes {
tm := TournamentMgr.GetTm(v.matchId)
if tm == nil {
continue
}
room := &tournament.MatchRoom{
RoomId: int64(v.sceneId),
MatchId: int64(tm.TMId),
InstanceId: tm.SortId,
Round: TournamentMgr.GetRound(tm.SortId),
TotalRound: tm.GetTotalRound(),
}
for _, v := range v.players {
if v.matchCtx == nil {
continue
}
d := &tournament.MatchPlayer{
SnId: v.matchCtx.copySnid,
Name: v.Name,
HeadUrl: v.HeadUrl,
UseRoleId: v.matchCtx.copyRoleId,
UseSkinId: v.matchCtx.copySkinId,
Rank: v.matchCtx.rank,
Score: v.matchCtx.grade,
}
room.Players = append(room.Players, d)
}
pack.List = append(pack.List, room)
}
p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCRoomList), pack)
logger.Logger.Tracef("SCRoomList %v", pack)
return nil
}
func init() {
// 比赛信息列表
// 比赛配置列表
common.Register(int(tournament.TOURNAMENTID_PACKET_TM_CSTMInfo), tournament.CSTMInfo{}, CSTMInfo)
// 比赛报名
common.Register(int(tournament.TOURNAMENTID_PACKET_TM_CSSignRace), tournament.CSSignRace{}, CSSignRace)
// 比赛中比赛列表
common.Register(int(tournament.TOURNAMENTID_PACKET_TM_CSMatchList), tournament.CSMatchList{}, CSMatchList)
// 比赛中房间列表
common.Register(int(tournament.TOURNAMENTID_PACKET_TM_CSRoomList), tournament.CSRoomList{}, CSRoomList)
}

View File

@ -128,6 +128,7 @@ func (this *AwardLogManager) Update() {
func (this *AwardLogManager) Shutdown() {
this.Save()
module.UnregisteModule(this)
}
func (this *AwardLogManager) OnHourTimer() {

View File

@ -148,6 +148,7 @@ func (csm *CoinSceneMgr) PlayerEnter(p *Player, id int32, roomId int32, exclude
}
// AudienceEnter 观众进入房间
// id 场次id
func (csm *CoinSceneMgr) AudienceEnter(p *Player, id int32, roomId int32, exclude []int32, ischangeroom bool) hall_proto.OpResultCode {
//多平台支持
platform := p.GetPlatform()

View File

@ -89,6 +89,8 @@ func init() {
etcd.Register(etcd.ETCDKEY_AWARD_CONFIG, webapi.AwardLogConfig{}, platformConfigEvent)
// 新手引导
etcd.Register(etcd.ETCDKEY_GUIDE, webapi.GuideConfig{}, platformConfigEvent)
// 比赛观众
etcd.Register(etcd.ETCDKEY_MatchAudience, webapi.MatchAudience{}, handlerEvent)
}
func platformConfigEvent(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) {
@ -395,6 +397,13 @@ func handlerEvent(ctx context.Context, completeKey string, isInit bool, event *c
if isInit || event.Type == clientv3.EventTypePut {
ActMgrSington.AddGiveConfig(config, config.Platform)
}
case *webapi.MatchAudience:
switch event.Type {
case clientv3.EventTypePut:
PlatformMgrSingleton.AddMatchAudience(config)
case clientv3.EventTypeDelete:
PlatformMgrSingleton.DelMatchAudience(config)
}
default:
logger.Logger.Errorf("etcd completeKey:%s, Not processed", completeKey)

View File

@ -97,7 +97,6 @@ func (ms *MatchSceneMgr) MatchStart(tm *TmMatch) {
}
// 填充机器人
if scene != nil && !scene.IsFull() {
tm.RobotGradesDecline(1)
needRobotNum := scene.playerNum - len(scene.players)
logger.Logger.Trace("MatchStart 填充机器人", needRobotNum)
pack := &server.WGInviteMatchRob{

View File

@ -1594,7 +1594,7 @@ func (this *Player) DgGameLogout() {
}
func (this *Player) ThirdGameLogout() {
_LeaveTransferThird2SystemTask(this)
}
func (this *Player) IsOnLine() bool {

View File

@ -1024,6 +1024,7 @@ func (this *Scene) GetSceneName() string {
}
return "[unknow scene name]"
}
func (this *Scene) RandRobotCnt() {
if len(this.paramsEx) > 0 {
gps := PlatformMgrSingleton.GetGameFree(this.limitPlatform.IdStr, this.paramsEx[0])
@ -1263,3 +1264,17 @@ func (this *Scene) TryForceDelectMatchInfo() {
}
}
}
// CanAudience 是否允许观战
func (this *Scene) CanAudience() bool {
switch {
case this.matchId > 0: // 比赛场
tm := TournamentMgr.GetTm(this.matchId)
if tm != nil {
return tm.gmd.GetAudienceSwitch() == 1
}
return false
default:
return true
}
}

View File

@ -115,6 +115,19 @@ func (m *SceneMgr) GetScenesByGameFreeId(gameFreeId int32) []*Scene {
return scenes
}
func (m *SceneMgr) GetMatchRoom(sortId int64) []*Scene {
var scenes []*Scene
for _, value := range m.scenes {
if value.matchId == sortId {
s := m.GetScene(value.sceneId)
if s != nil {
scenes = append(scenes, value)
}
}
}
return scenes
}
// MarshalAllRoom 获取房间列表
func (m *SceneMgr) MarshalAllRoom(platform string, groupId, gameId int, gameMode, clubId, sceneMode, sceneId int,
gameFreeId, snId int32, start, end, pageSize int32) ([]*webapi2.RoomInfo, int32, int32) {

View File

@ -74,6 +74,8 @@ func (tm *TmMatch) Start() {
tm.BroadcastMessage(int(tournament.TOURNAMENTID_PACKET_TM_SCTMStart), pack)
logger.Logger.Trace("SCTMStart ", pack)
tm.RobotGradesDecline(1)
//创建房间
timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool {
MatchSceneMgrSingleton.MatchStart(tm)
@ -87,6 +89,10 @@ func (tm *TmMatch) Stop() {
logger.Logger.Trace("(this *TmMatch) Stop()")
}
func (tm *TmMatch) GetTotalRound() int32 {
return int32(len(tm.gmd.GetMatchPromotion()) - 1)
}
func (tm *TmMatch) BroadcastMessage(packetId int, rawPack interface{}) {
mgs := make(map[*netlib.Session][]*srvproto.MCSessionUnion)
for _, tmp := range tm.TmPlayer {

View File

@ -24,13 +24,8 @@ import (
"mongo.games.com/game/webapi"
)
func init() {
module.RegisteModule(TournamentMgr, time.Second, 0)
ClockMgrSington.RegisteSinker(TournamentMgr)
}
// 如果这里比赛类型没有,默认是锦标赛
const (
// 如果这里比赛类型没有,默认是锦标赛
MatchTypeNormal = iota + 1 // 锦标赛
MatchTypeChampion // 冠军赛/实物赛
MatchTypeVIP // vip比赛
@ -54,6 +49,11 @@ const (
DaiDing = 2 // 待定
)
func init() {
module.RegisteModule(TournamentMgr, time.Second, 0)
ClockMgrSington.RegisteSinker(TournamentMgr)
}
var TournamentMgr = NewTournament()
type PerRankInfo struct {
@ -78,8 +78,8 @@ type SignupInfo struct {
type PlayerRoundInfo struct {
players []*PlayerMatchContext // 本轮结算信息
ranks []*PlayerMatchContext // 本排名
num int // 本完成人数
ranks []*PlayerMatchContext // 本排名
num int // 本完成人数
}
type Tournament struct {
@ -91,7 +91,7 @@ type Tournament struct {
playerWaitStart map[int32]int64 // 等待时间 玩家Id:等待时长秒
matches map[int32]map[int64]*TmMatch // 开始比赛的数据比赛配置Id:比赛顺序序号:一场开始的比赛数据
players map[int64]map[int32]*PlayerMatchContext // 比赛中玩家 比赛顺序序号:玩家id:玩家信息
roundPlayers map[int64]map[int32]*PlayerRoundInfo // 每轮比赛数据 比赛顺序序号:第几轮
roundPlayers map[int64]map[int32]*PlayerRoundInfo // 每轮比赛数据备份 比赛顺序序号:第几轮
finalPerRank map[int64][]*PerRankInfo // 本场比赛排名,每淘汰一位记录一位,最后记录决赛玩家 比赛顺序序号
MatchAwardNum map[string]map[int32]int32 // 比赛配置Id:比赛奖励次數
}
@ -146,6 +146,7 @@ func (this *Tournament) checkData(cfg *webapiproto.GameMatchDate) bool {
return true
}
// 记录淘汰人员
func (this *Tournament) addFinalPlayer(sortId int64, p *PerRankInfo) {
if this.finalPerRank[sortId] == nil {
this.finalPerRank[sortId] = []*PerRankInfo{}
@ -153,6 +154,7 @@ 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 {
_, ok := this.roundPlayers[sortId]
if !ok {
@ -168,6 +170,96 @@ func (this *Tournament) getRoundPlayer(sortId int64, round int32) *PlayerRoundIn
return v
}
// GetRemainNum 剩余比赛人数
func (this *Tournament) GetRemainNum(sortId int64) int32 {
tm := this.GetTm(sortId)
if tm == nil {
return 0
}
round := this.GetRound(sortId)
l := tm.gmd.GetMatchPromotion()
if round <= int32(len(l)) {
return l[round-1]
}
return 0
}
type MatchPlayerInfo struct {
SnId int32
RoleId int32
SkinId int32
Rank int32
Grade int32
}
// GetRemainPlayer 未淘汰的人
func (this *Tournament) GetRemainPlayer(sortId int64) []*MatchPlayerInfo {
tm := this.GetTm(sortId)
if tm == nil {
return nil
}
round := this.GetRound(sortId)
useRobot := this.IsRobotOn(tm.gmd)
var ret []*MatchPlayerInfo
realPlayer := func() {
for _, v := range tm.TmPlayer {
p := PlayerMgrSington.GetPlayerBySnId(v.SnId)
if p != nil {
ret = append(ret, &MatchPlayerInfo{
SnId: v.SnId,
RoleId: p.GetRoleId(),
SkinId: p.Skin.ModId,
Grade: 1000,
})
}
}
}
robotPlayer := func(n int) {
for _, v := range tm.robotGrades[n] {
ret = append(ret, &MatchPlayerInfo{
SnId: v.copySnid,
RoleId: v.copyRoleId,
SkinId: v.CopySkinId,
Grade: v.grade,
})
}
}
if round <= 1 {
if useRobot {
robotPlayer(0)
realPlayer()
} else {
realPlayer()
}
} else {
if useRobot {
robotPlayer(int(round - 1))
} else {
if this.roundPlayers[sortId] != nil {
d := this.roundPlayers[sortId][round-1]
if d != nil {
for _, v := range d.ranks {
ret = append(ret, &MatchPlayerInfo{
SnId: v.copySnid,
RoleId: v.copyRoleId,
SkinId: v.copySkinId,
Grade: v.grade,
})
}
}
}
}
}
return ret
}
// GetSignUpPlayers 获取报名人员
// id 比赛配置id
func (this *Tournament) GetSignUpPlayers(platform string, id int32) map[int32]*TmPlayer {
v, ok := this.signupPlayers[platform]
if !ok {
@ -194,7 +286,7 @@ func (this *Tournament) UpdateData(init bool, data *webapiproto.GameMatchDateLis
this.FixMatchTimeStamp(v)
configs[v.Id] = v
} else {
logger.Logger.Error("GameMatchDate error: ", v)
logger.Logger.Errorf("GameMatchDate check error: %v", v)
}
}
@ -239,14 +331,6 @@ func (this *Tournament) UpdateData(init bool, data *webapiproto.GameMatchDateLis
}
}
this.GameMatchDateList[data.Platform] = configs
//拉取数据
if this.MatchAwardNum == nil {
ret, err := model.GetMatchAwardLog(data.Platform)
logger.Logger.Tracef("ret = %v,err = %v", ret, err)
if err == nil {
this.MatchAwardNum = ret.AwardNum
}
}
// 通知平台玩家数据更新
if !init {
//todo 优化
@ -796,6 +880,7 @@ func (this *Tournament) CreatePlayerMatchContext(p *Player, m *TmMatch, seq int)
return nil
}
// 是否淘汰
func (this *Tournament) isOut(sortId int64, snid int32) bool {
if this.finalPerRank[sortId] != nil {
for _, info := range this.finalPerRank[sortId] {
@ -1516,6 +1601,72 @@ func (this *Tournament) GetSCTMInfosPack(platform, channelName string) *tourname
return pack
}
// GetTmMatch 查询比赛中的比赛
func (this *Tournament) GetTmMatch(plt string, matchId int32, channelName string, audience bool, sortId int64) []*TmMatch {
matches := this.GetAllMatchInfo(plt)
if matches == nil {
return nil
}
var ids []int32
for id, info := range matches {
if info == nil || info.MatchSwitch != 1 {
continue
}
if matchId > 0 && id != matchId {
continue
}
if channelName != "" && !common.InMatchChannel(info.OnChannelName, channelName) {
continue
}
if info.GetAudienceSwitch() == 1 != audience {
continue
}
ids = append(ids, id)
}
var ret []*TmMatch
if sortId > 0 {
for _, v := range ids {
d := this.matches[v]
if d != nil {
r, ok := d[sortId]
if ok && r != nil {
return []*TmMatch{r}
}
}
}
return ret
}
for _, v := range ids {
for _, vv := range this.matches[v] {
ret = append(ret, vv)
}
}
return ret
}
func (this *Tournament) GetTmRoom(plt string, matchId int32, channelName string, audience bool, sortId int64) []*Scene {
tm := this.GetTmMatch(plt, matchId, channelName, audience, sortId)
sort.Slice(tm, func(i, j int) bool {
return tm[i].SortId < tm[j].SortId
})
var ret []*Scene
for _, v := range tm {
d := SceneMgrSingleton.GetMatchRoom(v.SortId)
sort.Slice(d, func(i, j int) bool {
return d[i].createTime.Before(d[j].createTime)
})
ret = append(ret, d...)
}
return ret
}
func (this *Tournament) MakeMatchLog(platform string, tmId int32, sortId int64) *model.MatchLog {
gameMatchDate := this.GetMatchInfo(platform, tmId, sortId)
if gameMatchDate == nil {
@ -1608,6 +1759,20 @@ func (this *Tournament) ModuleName() string {
func (this *Tournament) Init() {
logger.Logger.Trace("Tournament Init")
for _, v := range PlatformMgrSingleton.GetPlatforms() {
if v == nil || v.IdStr == "0" {
continue
}
ret, err := model.GetMatchAward(v.IdStr)
if err != nil {
logger.Logger.Tracef("GetMatchAward error %v", err)
continue
}
if this.MatchAwardNum == nil {
this.MatchAwardNum = make(map[string]map[int32]int32)
}
this.MatchAwardNum[v.IdStr] = ret.Award
}
}
func (this *Tournament) Update() {
@ -1650,35 +1815,42 @@ func (this *Tournament) Update() {
}
}
}
func (this *Tournament) OnDayTimer() {
this.MatchAwardNum = make(map[string]map[int32]int32)
this.Save()
logger.Logger.Trace("比赛场每日库存清理!!!")
for k := range this.MatchAwardNum {
this.MatchAwardNum[k] = make(map[int32]int32)
}
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
this.SaveMatchAward()
return nil
}), nil, "save_match_award_times").Start()
}
func (this *Tournament) Shutdown() {
// 保存数据
this.Save()
this.SaveMatchAward()
module.UnregisteModule(this)
}
func (this *Tournament) Save() {
logger.Logger.Info("保存比赛场每日奖励数据!!!!", this.MatchAwardNum)
func (this *Tournament) SaveMatchAward() {
if this.MatchAwardNum == nil {
return
}
for platform, _ := range this.MatchAwardNum {
matchAwardLog := model.NewMatchAwardLog()
matchAwardLog.AwardNum = this.MatchAwardNum
matchAwardLog.Platform = platform
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
err := model.InsertOrUpdateMatchAwardLog(matchAwardLog)
if err != nil {
logger.Logger.Error("saveMatchAwardLog error %v", err)
return err
}
return nil
}), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) {
})).StartByFixExecutor("saveMatchAwardLogTask")
logger.Logger.Tracef("保存比赛场奖励领取次数")
for platform, v := range this.MatchAwardNum {
d := &model.MatchAward{
Platform: platform,
Award: make(map[int32]int32),
}
for k, vv := range v {
d.Award[k] = vv
}
err := model.UpsertMatchAward(d)
if err != nil {
logger.Logger.Errorf("SaveMatchAward error %v", err)
}
}
}
func (this *Tournament) getWeekDay() int {
getWeekNum := func(t time.Time) int {
strWeek := []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
@ -1711,7 +1883,7 @@ func (this *Tournament) FixMatchTimeStamp(d *webapiproto.GameMatchDate) {
week := this.getWeekDay()
st := time.Unix(d.MatchTimeStamp[0], 0).In(l)
et := time.Unix(d.MatchTimeStamp[1], 0).In(l)
logger.Logger.Tracef("FixMatchTimeStamp 1 id:%v now:%v week:%v start:%v end:%v", d.Id, bTs, bTs.Weekday(), st, et)
//logger.Logger.Tracef("FixMatchTimeStamp 1 id:%v now:%v week:%v start:%v end:%v", d.Id, bTs, bTs.Weekday(), st, et)
// 重复时间段比赛时间
for _, v := range d.MatchTimeWeek {
if v == int32(week) {
@ -1723,8 +1895,7 @@ func (this *Tournament) FixMatchTimeStamp(d *webapiproto.GameMatchDate) {
st = time.Unix(d.MatchTimeStamp[0], 0).In(l)
et = time.Unix(d.MatchTimeStamp[1], 0).In(l)
logger.Logger.Tracef("FixMatchTimeStamp 2 id:%v now:%v week:%v start:%v end:%v", d.Id, bTs, bTs.Weekday(), st, et)
//logger.Logger.Tracef("FixMatchTimeStamp 2 id:%v now:%v week:%v start:%v end:%v", d.Id, bTs, bTs.Weekday(), st, et)
break
}
}
@ -1738,6 +1909,8 @@ func (this *Tournament) OnHourTimer() {
}
}
// GetMatchAwardNum 剩余奖励数量
// id 比赛配置id
func (this *Tournament) GetMatchAwardNum(platform string, id int32) int32 {
var num int32
if this.MatchAwardNum != nil && this.MatchAwardNum[platform] != nil {
@ -1761,3 +1934,11 @@ func (this *Tournament) GetMatchAwardNum(platform string, id int32) int32 {
}
return num
}
func (this *Tournament) GetRound(sortId int64) int32 {
d, ok := this.roundPlayers[sortId]
if !ok || d == nil {
return 1
}
return int32(len(d))
}