diff --git a/common/slice.go b/common/slice.go index a748a3b..4fc046f 100644 --- a/common/slice.go +++ b/common/slice.go @@ -40,6 +40,18 @@ func CopySliceIntToInt32(s []int) []int32 { return nil } +func CopySliceInt64ToInt32(s []int64) []int32 { + n := len(s) + if n != 0 { + temp := make([]int32, n) + for i := 0; i < n; i++ { + temp[i] = int32(s[i]) + } + return temp + } + return nil +} + func CopySliceInt32ToInt(s []int32) []int { n := len(s) if n != 0 { diff --git a/gamesrv/avengers/scenepolicy_avengers.go b/gamesrv/avengers/scenepolicy_avengers.go index 2cad9cc..68e2d47 100644 --- a/gamesrv/avengers/scenepolicy_avengers.go +++ b/gamesrv/avengers/scenepolicy_avengers.go @@ -233,7 +233,7 @@ func AvengersSendRoomInfo(s *base.Scene, p *base.Player, sceneEx *AvengersSceneD Creator: proto.Int32(s.Creator), GameId: proto.Int(s.GameId), RoomMode: proto.Int(s.GameMode), - Params: s.Params, + Params: common.CopySliceInt64ToInt32(s.Params), State: proto.Int(s.SceneState.GetState()), Jackpot: proto.Int64(sceneEx.jackpot.VirtualJK), GameFreeId: proto.Int32(s.DbGameFree.Id), diff --git a/gamesrv/base/scene.go b/gamesrv/base/scene.go index 185d68b..0e6b7ab 100644 --- a/gamesrv/base/scene.go +++ b/gamesrv/base/scene.go @@ -61,7 +61,7 @@ type Scene struct { SceneMode int // 房间模式,如:公共房间 common.SceneMode_Public SceneType int // 场次,新手场,中级场... Platform string // 平台id - Params []int32 + Params []int64 paramsEx []int32 Creator int32 agentor int32 @@ -124,12 +124,12 @@ type Scene struct { WebUser string // 操作人 resultHistory [][]int // 记录数 [控制结果,局数...] BaseScore int32 //tienlen游戏底分 - MatchId int32 //标记本次比赛的id,并不是后台id + MatchId int64 //标记本次比赛的id,并不是后台id MatchFinals bool //比赛场决赛 - MatchRound int32 - MatchCurPlayerNum int32 - MatchNextNeed int32 - MatchType int32 // 0.普通场 1.锦标赛 2.冠军赛 3.vip专属 + MatchRound int64 + MatchCurPlayerNum int64 + MatchNextNeed int64 + MatchType int64 // 0.普通场 1.锦标赛 2.冠军赛 3.vip专属 MatchStop bool RealCtrl bool Novice bool @@ -137,7 +137,7 @@ type Scene struct { KillPoints bool } -func NewScene(ws *netlib.Session, sceneId, gameMode, sceneMode, gameId int, platform string, params []int32, +func NewScene(ws *netlib.Session, sceneId, gameMode, sceneMode, gameId int, platform string, params []int64, agentor, creator int32, replayCode string, hallId, groupId, totalOfGames int32, dbGameFree *server.DB_GameFree, bEnterAfterStart bool, baseScore int32, playerNum int, cherank []int32, paramsEx ...int32) *Scene { sp := GetScenePolicy(gameId, gameMode) if sp == nil { @@ -267,7 +267,7 @@ func (this *Scene) init() bool { return true } -func (this *Scene) GetParam(idx int) int32 { +func (this *Scene) GetParam(idx int) int64 { if idx < 0 || idx >= len(this.Params) { return -1 } @@ -387,10 +387,10 @@ func (this *Scene) GetSceneMode() int { func (this *Scene) SetSceneMode(sceneMode int) { this.SceneMode = sceneMode } -func (this *Scene) GetParams() []int32 { +func (this *Scene) GetParams() []int64 { return this.Params } -func (this *Scene) SetParams(params []int32) { +func (this *Scene) SetParams(params []int64) { this.Params = params } func (this *Scene) GetParamsEx() []int32 { @@ -614,7 +614,7 @@ func (this *Scene) PlayerLeave(p *Player, reason int, isBill bool) { LostTimes: proto.Int(p.lostTimes), TotalConvertibleFlow: proto.Int64(p.TotalConvertibleFlow), ValidCacheBetTotal: proto.Int64(p.ValidCacheBetTotal), - MatchId: proto.Int32(this.MatchId), + MatchId: this.MatchId, CurIsWin: proto.Int64(p.CurIsWin), // 负数:输 0:平局 正数:赢 } matchRobotGrades := p.MatchRobotGrades @@ -822,7 +822,7 @@ func (this *Scene) PlayerReturn(p *Player, isLoaded bool) { RoomId: proto.Int(this.SceneId), GameId: proto.Int(this.GameId), ModeType: proto.Int(this.GameMode), - Params: this.Params, + Params: common.CopySliceInt64ToInt32(this.Params), HallId: proto.Int32(this.hallId), IsLoaded: proto.Bool(isLoaded), OpRetCode: gamehall.OpResultCode_Game_OPRC_Sucess_Game, diff --git a/gamesrv/base/scene_mgr.go b/gamesrv/base/scene_mgr.go index ebbb1f3..c241b03 100644 --- a/gamesrv/base/scene_mgr.go +++ b/gamesrv/base/scene_mgr.go @@ -33,7 +33,7 @@ func (this *SceneMgr) makeKey(gameid, gamemode int) int { } func (this *SceneMgr) CreateScene(s *netlib.Session, sceneId, gameMode, sceneMode, gameId int, platform string, - params []int32, agentor, creator int32, replayCode string, hallId, groupId, totalOfGames int32, + params []int64, agentor, creator int32, replayCode string, hallId, groupId, totalOfGames int32, dbGameFree *server.DB_GameFree, bEnterAfterStart bool, baseScore int32, playerNum int, chessRank []int32, paramsEx ...int32) *Scene { scene := NewScene(s, sceneId, gameMode, sceneMode, gameId, platform, params, agentor, creator, replayCode, hallId, groupId, totalOfGames, dbGameFree, bEnterAfterStart, baseScore, playerNum, chessRank, paramsEx...) diff --git a/gamesrv/caishen/scenepolicy_caishen.go b/gamesrv/caishen/scenepolicy_caishen.go index 6593944..0f9b0f0 100644 --- a/gamesrv/caishen/scenepolicy_caishen.go +++ b/gamesrv/caishen/scenepolicy_caishen.go @@ -234,7 +234,7 @@ func CaiShenSendRoomInfo(s *base.Scene, p *base.Player, sceneEx *CaiShenSceneDat Creator: proto.Int32(s.Creator), GameId: proto.Int(s.GameId), RoomMode: proto.Int(s.GameMode), - Params: s.Params, + Params: common.CopySliceInt64ToInt32(s.Params), State: proto.Int(s.SceneState.GetState()), Jackpot: proto.Int64(sceneEx.jackpot.VirtualJK), GameFreeId: proto.Int32(s.DbGameFree.Id), diff --git a/gamesrv/chess/scenepolicy.go b/gamesrv/chess/scenepolicy.go index 9b6e6ee..a4fbb4f 100644 --- a/gamesrv/chess/scenepolicy.go +++ b/gamesrv/chess/scenepolicy.go @@ -481,7 +481,7 @@ func CreateRoomInfoPacket(s *base.Scene, p *base.Player, sceneEx *SceneEx, playe Creator: proto.Int32(s.GetCreator()), GameId: proto.Int(s.GetGameId()), RoomMode: proto.Int(s.GetSceneMode()), - Params: s.GetParams(), + Params: common.CopySliceInt64ToInt32(s.GetParams()), State: proto.Int32(int32(s.GetSceneState().GetState())), TimeOut: proto.Int(s.GetSceneState().GetTimeout(s)), NumOfGames: proto.Int(sceneEx.NumOfGames), @@ -493,10 +493,6 @@ func CreateRoomInfoPacket(s *base.Scene, p *base.Player, sceneEx *SceneEx, playe MaxPlayerNum: proto.Int(s.GetPlayerNum()), GameFreeId: proto.Int32(s.GetDBGameFree().GetId()), SceneType: proto.Int32(s.GetDBGameFree().GetSceneType()), - // 比赛场相关 - Round: proto.Int32(s.MatchRound), - CurPlayerNum: proto.Int32(s.MatchCurPlayerNum), - NextNeed: proto.Int32(s.MatchNextNeed), // 计步 StepSnId: proto.Int32(sceneEx.stepSnId), StepNum: int64(sceneEx.stepNum), @@ -529,7 +525,7 @@ func CreateRoomInfoPacket(s *base.Scene, p *base.Player, sceneEx *SceneEx, playe pack.IsMatch = int32(0) // 0.普通场 1.锦标赛 2.冠军赛 3.vip专属 if s.IsMatchScene() { - pack.IsMatch = s.MatchType + } pack.MatchFinals = 0 if s.MatchFinals { diff --git a/gamesrv/easterisland/scenepolicy_easterisland.go b/gamesrv/easterisland/scenepolicy_easterisland.go index 5f35f58..67f98f8 100644 --- a/gamesrv/easterisland/scenepolicy_easterisland.go +++ b/gamesrv/easterisland/scenepolicy_easterisland.go @@ -234,7 +234,7 @@ func EasterIslandSendRoomInfo(s *base.Scene, p *base.Player, sceneEx *EasterIsla Creator: proto.Int32(s.Creator), GameId: proto.Int(s.GameId), RoomMode: proto.Int(s.GameMode), - Params: s.Params, + Params: common.CopySliceInt64ToInt32(s.Params), State: proto.Int(s.SceneState.GetState()), Jackpot: proto.Int64(sceneEx.jackpot.VirtualJK), GameFreeId: proto.Int32(s.DbGameFree.Id), diff --git a/gamesrv/fishing/scenepolicy_fishing.go b/gamesrv/fishing/scenepolicy_fishing.go index 64a5a22..efb769a 100644 --- a/gamesrv/fishing/scenepolicy_fishing.go +++ b/gamesrv/fishing/scenepolicy_fishing.go @@ -185,7 +185,7 @@ func FishingSendRoomInfo(p *base.Player, sceneEx *FishingSceneData) { RoomMode: proto.Int(sceneEx.sceneMode), AgentId: proto.Int32(sceneEx.agentor), SceneType: proto.Int(sceneEx.sceneType), - Params: sceneEx.GetParams(), + Params: common.CopySliceInt64ToInt32(sceneEx.GetParams()), NumOfGames: proto.Int(sceneEx.GetNumOfGames()), State: proto.Int(sceneEx.GetSceneState().GetState()), TimeOut: proto.Int(sceneEx.GetSceneState().GetTimeout(sceneEx.Scene)), diff --git a/gamesrv/fruits/scenepolicy_fruits.go b/gamesrv/fruits/scenepolicy_fruits.go index 65e1b34..292247b 100644 --- a/gamesrv/fruits/scenepolicy_fruits.go +++ b/gamesrv/fruits/scenepolicy_fruits.go @@ -152,7 +152,7 @@ func FruitsCreateRoomInfoPacket(s *base.Scene, sceneEx *FruitsSceneData, playerE GameId: proto.Int(s.GameId), RoomMode: proto.Int(s.SceneMode), SceneType: proto.Int(s.SceneType), - Params: s.Params, + Params: common.CopySliceInt64ToInt32(s.Params), NumOfGames: proto.Int(sceneEx.NumOfGames), State: proto.Int(s.SceneState.GetState()), ParamsEx: s.DbGameFree.OtherIntParams, diff --git a/gamesrv/iceage/scenepolicy_iceage.go b/gamesrv/iceage/scenepolicy_iceage.go index 4714098..0ff231d 100644 --- a/gamesrv/iceage/scenepolicy_iceage.go +++ b/gamesrv/iceage/scenepolicy_iceage.go @@ -234,7 +234,7 @@ func IceAgeSendRoomInfo(s *base.Scene, p *base.Player, sceneEx *IceAgeSceneData, Creator: proto.Int32(s.GetCreator()), GameId: proto.Int(s.GetGameId()), RoomMode: proto.Int(s.GetSceneMode()), - Params: s.GetParams(), + Params: common.CopySliceInt64ToInt32(s.GetParams()), State: proto.Int(s.GetSceneState().GetState()), Jackpot: proto.Int64(sceneEx.jackpot.VirtualJK), GameFreeId: proto.Int32(s.GetDBGameFree().GetId()), diff --git a/gamesrv/richblessed/scenepolicy_richblessed.go b/gamesrv/richblessed/scenepolicy_richblessed.go index cee9421..73ff76a 100644 --- a/gamesrv/richblessed/scenepolicy_richblessed.go +++ b/gamesrv/richblessed/scenepolicy_richblessed.go @@ -152,7 +152,7 @@ func RichBlessedCreateRoomInfoPacket(s *base.Scene, sceneEx *RichBlessedSceneDat GameId: proto.Int(s.GameId), RoomMode: proto.Int(s.SceneMode), SceneType: proto.Int(s.SceneType), - Params: s.Params, + Params: common.CopySliceInt64ToInt32(s.Params), NumOfGames: proto.Int(sceneEx.NumOfGames), State: proto.Int(s.SceneState.GetState()), ParamsEx: common.Int64ToInt32(s.DbGameFree.OtherIntParams), //s.GetParamsEx(), diff --git a/gamesrv/smallrocket/scene.go b/gamesrv/smallrocket/scene.go index e732167..b95f183 100644 --- a/gamesrv/smallrocket/scene.go +++ b/gamesrv/smallrocket/scene.go @@ -3,12 +3,13 @@ package smallrocket import ( "time" + "mongo.games.com/goserver/core/logger" + + "mongo.games.com/game/common" rule "mongo.games.com/game/gamerule/smallrocket" "mongo.games.com/game/gamesrv/base" "mongo.games.com/game/proto" "mongo.games.com/game/protocol/smallrocket" - - "mongo.games.com/goserver/core/logger" ) type PlayerData struct { @@ -142,7 +143,7 @@ func (this *SceneEx) SamllRocketCreateRoomInfoPacket(s *base.Scene, p *base.Play RoomId: proto.Int(s.GetSceneId()), GameId: proto.Int(s.GetGameId()), RoomMode: proto.Int(s.GetSceneMode()), - Params: this.Params, + Params: common.CopySliceInt64ToInt32(s.Params), State: proto.Int(s.GetSceneState().GetState()), TimeOut: proto.Int(s.GetSceneState().GetTimeout(s)), BombMul: proto.Float32(float32(0)), diff --git a/gamesrv/tamquoc/scenepolicy_tamquoc.go b/gamesrv/tamquoc/scenepolicy_tamquoc.go index 5f00ff2..f2cd36b 100644 --- a/gamesrv/tamquoc/scenepolicy_tamquoc.go +++ b/gamesrv/tamquoc/scenepolicy_tamquoc.go @@ -230,7 +230,7 @@ func TamQuocSendRoomInfo(s *base.Scene, p *base.Player, sceneEx *TamQuocSceneDat Creator: proto.Int32(s.Creator), GameId: proto.Int(s.GameId), RoomMode: proto.Int(s.GameMode), - Params: s.Params, + Params: common.CopySliceInt64ToInt32(s.Params), State: proto.Int(s.SceneState.GetState()), Jackpot: proto.Int64(sceneEx.jackpot.VirtualJK), GameFreeId: proto.Int32(s.GetDBGameFree().GetId()), diff --git a/gamesrv/thirteen/scene.go b/gamesrv/thirteen/scene.go index 81a5696..63dc6eb 100644 --- a/gamesrv/thirteen/scene.go +++ b/gamesrv/thirteen/scene.go @@ -174,10 +174,10 @@ func (this *SceneEx) ThirteenWaterCreateRoomInfoPacket(s *base.Scene, p *base.Pl State: proto.Int(s.GetSceneState().GetState()), TimeOut: proto.Int(s.GetSceneState().GetTimeout(s)), DisbandGen: proto.Int(this.GetDisbandGen()), - BaseScore: proto.Int32(this.GetBaseScore()), + BaseScore: int32(this.GetBaseScore()), LeaveDeduct: this.GetDBGameFree().GetLeaveDeduct(), LeaveCombat: this.GetDBGameFree().GetLeaveCombat(), - Params: this.Params, + Params: common.CopySliceInt64ToInt32(s.Params), } // 玩家信息 for _, playerEx := range this.players { @@ -360,7 +360,7 @@ func (this *SceneEx) ThirteenWaterCreateRoomInfoPacket(s *base.Scene, p *base.Pl return pack } -func (this *SceneEx) GetBaseScore() int32 { //游戏底分 +func (this *SceneEx) GetBaseScore() int64 { //游戏底分 if this.DbGameFree.FreeMode == 1 { baseScore := this.GetParam(rule.ParamBaseScore) if baseScore > 0 { @@ -369,7 +369,7 @@ func (this *SceneEx) GetBaseScore() int32 { //游戏底分 } if this.DbGameFree != nil { - return this.DbGameFree.GetBaseScore() + return int64(this.DbGameFree.GetBaseScore()) } return 1 } diff --git a/gamesrv/thirteen/scenepolicy.go b/gamesrv/thirteen/scenepolicy.go index 749168f..df0d4ea 100644 --- a/gamesrv/thirteen/scenepolicy.go +++ b/gamesrv/thirteen/scenepolicy.go @@ -1258,7 +1258,7 @@ func (this *StateBilled) OnEnter(s *base.Scene) { RoomId: int32(sceneEx.SceneId), RoomRounds: int32(sceneEx.NumOfGames), RoomType: int32(sceneEx.SceneType), - BaseScore: sceneEx.GetBaseScore(), + BaseScore: int32(sceneEx.GetBaseScore()), NowRound: int32(sceneEx.NumOfGames), ClubRate: sceneEx.Scene.PumpCoin, } diff --git a/gamesrv/tienlen/scenepolicy_tienlen.go b/gamesrv/tienlen/scenepolicy_tienlen.go index 65b2ced..aff23b5 100644 --- a/gamesrv/tienlen/scenepolicy_tienlen.go +++ b/gamesrv/tienlen/scenepolicy_tienlen.go @@ -399,7 +399,7 @@ func TienLenCreateRoomInfoPacket(s *base.Scene, p *base.Player, sceneEx *TienLen Creator: proto.Int32(s.GetCreator()), GameId: proto.Int(s.GetGameId()), RoomMode: proto.Int(s.GetSceneMode()), - Params: s.GetParams(), + Params: common.CopySliceInt64ToInt32(s.GetParams()), State: proto.Int32(int32(s.GetSceneState().GetState())), TimeOut: proto.Int(s.GetSceneState().GetTimeout(s)), NumOfGames: proto.Int(sceneEx.NumOfGames), @@ -412,15 +412,15 @@ func TienLenCreateRoomInfoPacket(s *base.Scene, p *base.Player, sceneEx *TienLen RankType: s.GetDBGameFree().GetRankType(), SceneAdd: s.GetDBGameFree().GetSceneAdd(), // 比赛场相关 - Round: proto.Int32(s.MatchRound), - CurPlayerNum: proto.Int32(s.MatchCurPlayerNum), - NextNeed: proto.Int32(s.MatchNextNeed), + Round: int32(s.MatchRound), + CurPlayerNum: int32(s.MatchCurPlayerNum), + NextNeed: int32(s.MatchNextNeed), RecordId: sceneEx.recordId, } pack.IsMatch = int32(0) // 0.普通场 1.锦标赛 2.冠军赛 3.vip专属 if s.IsMatchScene() { - pack.IsMatch = s.MatchType + pack.IsMatch = int32(s.MatchType) } pack.MatchFinals = 0 if s.MatchFinals { diff --git a/model/friendrecord.go b/model/friendrecord.go index e412d62..e03392f 100644 --- a/model/friendrecord.go +++ b/model/friendrecord.go @@ -20,14 +20,14 @@ type FriendRecord struct { GameId int32 //游戏场次 BaseScore int32 //底分 BillCoin int64 //输赢分(税后) - MatchType int32 + MatchType int64 Ts int64 } func NewFriendRecordLog() *FriendRecord { return &FriendRecord{LogId: bson.NewObjectId()} } -func NewFriendRecordLogEx(platform string, snid, isWin, gameId, baseScore int32, billCoin int64, matchType int32) *FriendRecord { +func NewFriendRecordLogEx(platform string, snid, isWin, gameId, baseScore int32, billCoin int64, matchType int64) *FriendRecord { fri := NewFriendRecordLog() fri.Platform = platform fri.SnId = snid diff --git a/model/gamedetailedlog.go b/model/gamedetailedlog.go index 55f48a6..27c3f80 100644 --- a/model/gamedetailedlog.go +++ b/model/gamedetailedlog.go @@ -42,7 +42,7 @@ type GameDetailedLog struct { Platform string //平台id Channel string //渠道 Promoter string //推广员 - MatchId int32 //比赛ID + MatchId int64 //比赛ID SceneId int32 //场景ID GameMode int32 //游戏类型 GameFreeid int32 //游戏类型房间号 diff --git a/model/gameplayerlistlog.go b/model/gameplayerlistlog.go index c28fa63..baa5201 100644 --- a/model/gameplayerlistlog.go +++ b/model/gameplayerlistlog.go @@ -49,8 +49,8 @@ type GamePlayerListLog struct { RoomType int32 //房间类型 GameDif string //游戏标识 GameClass int32 //游戏类型 1棋牌 2电子 3百人 4捕鱼 5视讯 6彩票 7体育 - MatchId int32 - MatchType int32 //0.普通场 1.锦标赛 2.冠军赛 3.vip专属 + MatchId int64 + MatchType int64 //0.普通场 1.锦标赛 2.冠军赛 3.vip专属 Ts int32 IsFree bool //拉霸专用 是否免费 WinSmallGame int64 //拉霸专用 小游戏奖励 @@ -63,7 +63,7 @@ func NewGamePlayerListLog() *GamePlayerListLog { } func NewGamePlayerListLogEx(snid int32, gamedetailedlogid string, platform, channel, promoter, packageTag string, gameid, baseScore, sceneid, gamemode, gamefreeid int32, totalin, totalout int64, clubId int32, clubRoom string, taxCoin, pumpCoin int64, roomType int32, - betAmount, winAmountNoAnyTax int64, key, name string, gameClass int32, isFirst bool, matchid, matchType int32, + betAmount, winAmountNoAnyTax int64, key, name string, gameClass int32, isFirst bool, matchid, matchType int64, isFree bool, winSmallGame, winTotal int64) *GamePlayerListLog { cl := NewGamePlayerListLog() cl.SnId = snid diff --git a/protocol/server/server.pb.go b/protocol/server/server.pb.go index 79f734c..2a23ac8 100644 --- a/protocol/server/server.pb.go +++ b/protocol/server/server.pb.go @@ -851,7 +851,7 @@ type WGCreateScene struct { SceneId int32 `protobuf:"varint,1,opt,name=SceneId,proto3" json:"SceneId,omitempty"` GameId int32 `protobuf:"varint,2,opt,name=GameId,proto3" json:"GameId,omitempty"` GameMode int32 `protobuf:"varint,3,opt,name=GameMode,proto3" json:"GameMode,omitempty"` - Params []int32 `protobuf:"varint,4,rep,packed,name=Params,proto3" json:"Params,omitempty"` + Params []int64 `protobuf:"varint,4,rep,packed,name=Params,proto3" json:"Params,omitempty"` Creator int32 `protobuf:"varint,5,opt,name=Creator,proto3" json:"Creator,omitempty"` Agentor int32 `protobuf:"varint,6,opt,name=Agentor,proto3" json:"Agentor,omitempty"` ReplayCode string `protobuf:"bytes,7,opt,name=ReplayCode,proto3" json:"ReplayCode,omitempty"` @@ -926,7 +926,7 @@ func (x *WGCreateScene) GetGameMode() int32 { return 0 } -func (x *WGCreateScene) GetParams() []int32 { +func (x *WGCreateScene) GetParams() []int64 { if x != nil { return x.Params } @@ -1649,7 +1649,7 @@ type GWPlayerLeave struct { TotalConvertibleFlow int64 `protobuf:"varint,13,opt,name=TotalConvertibleFlow,proto3" json:"TotalConvertibleFlow,omitempty"` //流水 ValidCacheBetTotal int64 `protobuf:"varint,14,opt,name=ValidCacheBetTotal,proto3" json:"ValidCacheBetTotal,omitempty"` //有效下注缓存 Items map[int32]int64 `protobuf:"bytes,15,rep,name=Items,proto3" json:"Items,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` - MatchId int32 `protobuf:"varint,16,opt,name=MatchId,proto3" json:"MatchId,omitempty"` //比赛场id + MatchId int64 `protobuf:"varint,16,opt,name=MatchId,proto3" json:"MatchId,omitempty"` //比赛场id CurIsWin int64 `protobuf:"varint,17,opt,name=CurIsWin,proto3" json:"CurIsWin,omitempty"` //本局是否赢 负数:输 0:平局 正数:赢 MatchRobotGrades map[int32]int32 `protobuf:"bytes,18,rep,name=MatchRobotGrades,proto3" json:"MatchRobotGrades,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` //比赛数据 RankScore map[int32]int64 `protobuf:"bytes,19,rep,name=RankScore,proto3" json:"RankScore,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 排位积分 @@ -1792,7 +1792,7 @@ func (x *GWPlayerLeave) GetItems() map[int32]int64 { return nil } -func (x *GWPlayerLeave) GetMatchId() int32 { +func (x *GWPlayerLeave) GetMatchId() int64 { if x != nil { return x.MatchId } @@ -8723,7 +8723,7 @@ var file_server_proto_rawDesc = []byte{ 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x47, 0x61, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x47, 0x61, 0x6d, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x47, 0x61, 0x6d, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, - 0x6d, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x05, 0x52, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, + 0x6d, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x03, 0x52, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x43, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x41, 0x67, 0x65, @@ -8878,7 +8878,7 @@ var file_server_proto_rawDesc = []byte{ 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x47, 0x57, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x4c, 0x65, 0x61, 0x76, 0x65, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x4d, 0x61, 0x74, 0x63, 0x68, - 0x49, 0x64, 0x18, 0x10, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x49, + 0x49, 0x64, 0x18, 0x10, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x43, 0x75, 0x72, 0x49, 0x73, 0x57, 0x69, 0x6e, 0x18, 0x11, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x43, 0x75, 0x72, 0x49, 0x73, 0x57, 0x69, 0x6e, 0x12, 0x57, 0x0a, 0x10, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x52, 0x6f, 0x62, 0x6f, 0x74, 0x47, 0x72, 0x61, 0x64, 0x65, diff --git a/protocol/server/server.proto b/protocol/server/server.proto index 9f7b807..d0250b7 100644 --- a/protocol/server/server.proto +++ b/protocol/server/server.proto @@ -165,7 +165,7 @@ message WGCreateScene { int32 SceneId = 1; int32 GameId = 2; int32 GameMode = 3; - repeated int32 Params = 4; + repeated int64 Params = 4; int32 Creator = 5; int32 Agentor = 6; string ReplayCode = 7; @@ -267,7 +267,7 @@ message GWPlayerLeave{ int64 TotalConvertibleFlow = 13; //流水 int64 ValidCacheBetTotal = 14; //有效下注缓存 map Items = 15; - int32 MatchId = 16;//比赛场id + int64 MatchId = 16;//比赛场id int64 CurIsWin = 17;//本局是否赢 负数:输 0:平局 正数:赢 map MatchRobotGrades = 18;//比赛数据 map RankScore = 19;// 排位积分 diff --git a/worldsrv/action_friend.go b/worldsrv/action_friend.go index 6cfde42..1c9adf4 100644 --- a/worldsrv/action_friend.go +++ b/worldsrv/action_friend.go @@ -251,7 +251,7 @@ func (this *CSQueryPlayerGameLogHandler) Process(s *netlib.Session, packetid int IsWin: proto.Int32(gpl.IsWin), Ts: proto.Int64(gpl.Ts), BillCoin: proto.Int64(gpl.BillCoin), - MatchType: proto.Int32(gpl.MatchType), + MatchType: proto.Int32(int32(gpl.MatchType)), } pack.GameLogs = append(pack.GameLogs, gl) } diff --git a/worldsrv/action_game.go b/worldsrv/action_game.go index 7ac3e77..5e94a25 100644 --- a/worldsrv/action_game.go +++ b/worldsrv/action_game.go @@ -310,7 +310,7 @@ func (this *CSReturnRoomHandler) Process(s *netlib.Session, packetid int, data i pack.RoomId = proto.Int(scene.sceneId) pack.GameId = proto.Int(scene.gameId) pack.ModeType = proto.Int(scene.gameMode) - pack.Params = scene.params + pack.Params = common.CopySliceInt64ToInt32(scene.params) pack.HallId = proto.Int32(scene.hallId) gameVers := srvdata.GetGameVers(p.PackageID) if ver, ok := gameVers[fmt.Sprintf("%v,%v", scene.gameId, p.Channel)]; ok { @@ -1329,7 +1329,7 @@ func (this *CSQueryRoomInfoHandler) ProcessLocalGame(s *netlib.Session, packetid MaxPlayer: proto.Int(scene.playerNum), Creator: proto.Int32(scene.creator), CreateTs: proto.Int32(int32(scene.createTime.Unix())), - Params: scene.params, + Params: common.CopySliceInt64ToInt32(scene.params), } pack.RoomInfo = append(pack.RoomInfo, roomInfo) } @@ -1380,7 +1380,7 @@ func (this *CSQueryRoomInfoHandler) ProcessId(s *netlib.Session, packetid int, d MaxPlayer: proto.Int(scene.playerNum), Creator: proto.Int32(scene.creator), CreateTs: proto.Int32(int32(scene.createTime.Unix())), - Params: scene.params, + Params: common.CopySliceInt64ToInt32(scene.params), } pack.RoomInfo = append(pack.RoomInfo, roomInfo) } @@ -1819,7 +1819,7 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in var playerTakeCoin = p.GetCoin() var maxPlayerNum = int(msg.GetMaxPlayerNum()) var gameId = msg.GetGameId() - var params = msg.GetParams() + var params = common.CopySliceInt32ToInt64(msg.GetParams()) var roomId int var scene *Scene var sp ScenePolicy @@ -1888,7 +1888,7 @@ func (this *CSCreateRoomHandler) ProcessLocalGame(s *netlib.Session, packetid in } if len(params) == 0 { - params = common.CopySliceInt32(dbGameRule.GetParams()) + params = common.CopySliceInt32ToInt64(dbGameRule.GetParams()) } sp = GetScenePolicy(int(dbGameFree.GetGameId()), int(dbGameFree.GetGameMode())) if sp == nil { @@ -1980,7 +1980,7 @@ func (this *CSCreateRoomHandler) ProcessThirteen(s *netlib.Session, packetid int var code gamehall.OpResultCode_Game var dbGameFree *server.DB_GameFree var dbGameRule *server.DB_GameRule - var params = msg.GetParams() + var params = common.CopySliceInt32ToInt64(msg.GetParams()) var baseScore = msg.GetBaseCoin() var sp ScenePolicy var gamefreeId = msg.GetId() diff --git a/worldsrv/action_tournament.go b/worldsrv/action_tournament.go index 09ff3c9..8e9f114 100644 --- a/worldsrv/action_tournament.go +++ b/worldsrv/action_tournament.go @@ -1,465 +1,100 @@ package main import ( - "mongo.games.com/game/common" - "mongo.games.com/game/model" - "mongo.games.com/game/proto" - "mongo.games.com/game/protocol/tournament" - "mongo.games.com/game/srvdata" - "mongo.games.com/goserver/core/basic" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/netlib" - "mongo.games.com/goserver/core/task" - "sort" - "strconv" - "time" + + "mongo.games.com/game/common" + "mongo.games.com/game/protocol/tournament" ) -// 比赛场信息 -type CSTMInfoPacketFactory struct { -} -type CSTMInfoHandler struct { -} - -func (this *CSTMInfoPacketFactory) CreatePacket() interface{} { - pack := &tournament.CSTMInfo{} - return pack -} - -func (this *CSTMInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSTMInfoHandler Process recv ", data) - if _, ok := data.(*tournament.CSTMInfo); ok { - p := PlayerMgrSington.GetPlayer(sid) - if p == nil { - logger.Logger.Warnf("CSTMInfo p == nil.") - return nil - } - pack := TournamentMgr.GetSCTMInfosPack(p.Platform, p.AppChannel) - proto.SetDefaults(pack) - logger.Logger.Trace("SCTMInfos++++++++++++:", pack) - p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCTMInfos), pack) +func CSTMInfo(s *netlib.Session, packetid int, data interface{}, sid int64) error { + logger.Logger.Trace("CSTMInfoHandler ", data) + _, ok := data.(*tournament.CSTMInfo) + if !ok { + return nil } + + p := PlayerMgrSington.GetPlayer(sid) + if p == nil { + logger.Logger.Warnf("CSTMInfo p == nil.") + return nil + } + + pack := TournamentMgr.GetSCTMInfosPack(p.Platform, p.AppChannel) + p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCTMInfos), pack) + logger.Logger.Trace("SCTMInfos ", pack) return nil } -// 排行榜 -type CSTMRankListPacketFactory struct { -} -type CSTMRankListHandler struct { -} - -func (this *CSTMRankListPacketFactory) CreatePacket() interface{} { - pack := &tournament.CSTMRankList{} - return pack -} - -func (this *CSTMRankListHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSTMRankListHandler Process recv ", data) - if msg, ok := data.(*tournament.CSTMRankList); ok { - p := PlayerMgrSington.GetPlayer(sid) - if p == nil { - logger.Logger.Warnf("CSTMRankList p == nil.") - return nil - } - pack := &tournament.SCTMRankList{ - TMId: msg.TMId, - TimeRange: "9.1-9.30", - TMRank: []*tournament.TMRank{ - {RankId: 1, RankName: "rankNo.1", WinnerNum: 5}, - {RankId: 2, RankName: "rankNo.2", WinnerNum: 4}, - {RankId: 3, RankName: "rankNo.3", WinnerNum: 2}}, - } - proto.SetDefaults(pack) - logger.Logger.Trace("CSTMRankList:", pack) - p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCTMRankList), pack) +func CSSignRace(s *netlib.Session, packetid int, data interface{}, sid int64) error { + logger.Logger.Trace("CSSignRaceHandler ", data) + msg, ok := data.(*tournament.CSSignRace) + if !ok { + return nil } - return nil -} - -// 报名 -type CSSignRacePacketFactory struct { -} -type CSSignRaceHandler struct { -} - -func (this *CSSignRacePacketFactory) CreatePacket() interface{} { - pack := &tournament.CSSignRace{} - return pack -} - -func (this *CSSignRaceHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSSignRaceHandler Process recv ", data) - if msg, ok := data.(*tournament.CSSignRace); ok { - p := PlayerMgrSington.GetPlayer(sid) - if p == nil { - logger.Logger.Warnf("CSSignRace p == nil.") - return nil - } - if p.scene != nil { - logger.Logger.Warnf("CSSignRace p.scene != nil.") - return nil - } - if p.IsRob { - logger.Logger.Warnf("CSSignRace p.IsRob.") - return nil - } - platform := p.Platform - tmid := msg.TMId - pack := &tournament.SCSignRace{} - switch msg.GetOpCode() { - case 0: - ok, code := TournamentMgr.SignUp(tmid, p) - if !ok { - logger.Logger.Infof("player(%v) match(%v) SignUp is fail.", p.SnId, tmid) - pack.RetCode = code //0成功 1重复报名 2比赛没有开启 3道具不足 4不在报名时间段 5金币不足 6钻石不足 - } - - if code == int32(tournament.SignRaceCode_OPRC_Close) || - code == int32(tournament.SignRaceCode_OPRC_Time) { - TournamentMgr.CancelSignUpAll(platform, tmid) - } - - waitStart := TournamentMgr.playerWaitStart[p.SnId] - if pack.RetCode == 0 && waitStart != 0 { - pack.WaitStartTime = waitStart - } - - proto.SetDefaults(pack) - logger.Logger.Trace("SCSignRace:", pack) - signSucc := p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCSignRace), pack) - // 检查是否可以开始比赛(关闭机器人时,比赛开赛) - if msg.GetOpCode() == 0 && pack.RetCode == 0 && signSucc && !TournamentMgr.IsUseRobot(platform, tmid) { - if TournamentMgr.CanStart(platform, tmid) { - TournamentMgr.Start(platform, tmid) - } - } - - default: - if TournamentMgr.IsMatching(p.SnId) { - logger.Logger.Infof("player(%v) IsMatching.", p.SnId) - } else { - //取消报名 - TournamentMgr.CancelSignUp(platform, tmid, p.SnId) - } - return nil - } + p := PlayerMgrSington.GetPlayer(sid) + if p == nil { + logger.Logger.Warnf("CSSignRace p == nil.") + return nil + } + if p.scene != nil { + logger.Logger.Warnf("CSSignRace p.scene != nil.") + return nil + } + if p.IsRob { + logger.Logger.Warnf("CSSignRace p.IsRob.") + return nil } - return nil -} -// 赛季信息 -type CSTMSeasonInfoPacketFactory struct { -} -type CSTMSeasonInfoHandler struct { -} + platform := p.Platform + tmId := msg.TMId + pack := &tournament.SCSignRace{} -func (this *CSTMSeasonInfoPacketFactory) CreatePacket() interface{} { - pack := &tournament.CSTMSeasonInfo{} - return pack -} + switch msg.GetOpCode() { + case 0: // 报名 + ok, code := TournamentMgr.SignUp(tmId, p) + if !ok { + logger.Logger.Infof("player(%v) match(%v) SignUp is fail.", p.SnId, tmId) + pack.RetCode = code //0成功 1重复报名 2比赛没有开启 3道具不足 4不在报名时间段 5金币不足 6钻石不足 + } -func (this *CSTMSeasonInfoHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSTMSeasonInfoHandler Process recv ", data) - if _, ok := data.(*tournament.CSTMSeasonInfo); ok { - p := PlayerMgrSington.GetPlayer(sid) - if p == nil { - logger.Logger.Warnf("CSTMSeasonInfoHandler p == nil.") - return nil + if code == int32(tournament.SignRaceCode_OPRC_Close) || + code == int32(tournament.SignRaceCode_OPRC_Time) { + TournamentMgr.CancelSignUpAll(platform, tmId) } - if p.Platform == DefaultPlatform { - logger.Logger.Warnf("CSTMSeasonInfoHandler Platform == Default_Platform.") - return nil + + waitStart := TournamentMgr.playerWaitStart[p.SnId] + if pack.RetCode == 0 && waitStart != 0 { + pack.WaitStartTime = waitStart } - msid := MatchSeasonMgrSington.GetMatchSeasonId(p.Platform) - if msid == nil { - logger.Logger.Warnf("CSTMSeasonInfoHandler msid == nil.") - return nil - } - send := func(ms *MatchSeason) { - pack := &tournament.SCTMSeasonInfo{ - Id: msid.SeasonId, - SeasonTimeStamp: []int64{msid.StartStamp, msid.EndStamp}, - Lv: ms.Lv, - LastLv: ms.LastLv, - IsAward: ms.IsAward, + + signSucc := p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCSignRace), pack) + logger.Logger.Trace("SCSignRace ", pack) + + // 检查是否可以开始比赛(关闭机器人时,比赛开赛) + if code == 0 && signSucc && !TournamentMgr.IsUseRobot(platform, tmId) { + if TournamentMgr.CanStart(platform, tmId) { + TournamentMgr.Start(platform, tmId) } - proto.SetDefaults(pack) - logger.Logger.Trace("CSTMSeasonInfoHandler:", pack) - p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCTMSeasonInfo), pack) } - snid := p.SnId - ms := MatchSeasonMgrSington.GetMatchSeason(snid) - if ms == nil { - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - ret, err := model.QueryMatchSeasonBySnid(p.Platform, snid) - if err != nil { - return nil - } - return ret - }), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { - var ret *model.MatchSeason - dirty := false - if data == nil || data.(*model.MatchSeason) == nil { //新数据 - player := PlayerMgrSington.GetPlayerBySnId(snid) - if player != nil { - ret = model.NewMatchSeason(player.Platform, snid, player.Name, msid.SeasonId, 1) - dirty = true - } else { - logger.Logger.Trace("CSTMSeasonInfoHandler error: player==nil ", snid) - } - } else { - ret = data.(*model.MatchSeason) - if ret.SeasonId < msid.SeasonId { //不同赛季段位继承 - num := msid.SeasonId - ret.SeasonId - finalLv := ret.Lv - for i := 0; i < int(num); i++ { //继承几次 - if i == int(num)-1 { //上个赛季 - ret.LastLv = finalLv - } - finalLv = MatchSeasonMgrSington.MatchSeasonInherit(finalLv) - } - ret.Lv = finalLv - ret.SeasonId = msid.SeasonId - ret.IsAward = false - ret.UpdateTs = time.Now().Unix() - dirty = true - } - } - ms = MatchSeasonMgrSington.exchangeModel2Cache(ret) - ms.dirty = dirty - MatchSeasonMgrSington.SetMatchSeason(ms) - send(ms) - })).StartByFixExecutor("SnId:" + strconv.Itoa(int(snid))) + + default: // 取消报名 + if TournamentMgr.IsMatching(p.SnId) { + logger.Logger.Warnf("player(%v) IsMatching.", p.SnId) } else { - if ms.SeasonId < msid.SeasonId { //不同赛季段位继承 - num := msid.SeasonId - ms.SeasonId - finalLv := ms.Lv - for i := 0; i < int(num); i++ { //继承几次 - if i == int(num)-1 { //上个赛季 - ms.LastLv = finalLv - } - finalLv = MatchSeasonMgrSington.MatchSeasonInherit(finalLv) - } - ms.Lv = finalLv - ms.SeasonId = msid.SeasonId - ms.IsAward = false - ms.UpdateTs = time.Now().Unix() - ms.dirty = true - MatchSeasonMgrSington.SetMatchSeason(ms) - } - send(ms) + //取消报名 + TournamentMgr.CancelSignUp(platform, tmId, p.SnId) } + return nil } - return nil -} -// 赛季排行榜 -type CSTMSeasonRankPacketFactory struct { -} -type CSTMSeasonRankHandler struct { -} - -func (this *CSTMSeasonRankPacketFactory) CreatePacket() interface{} { - pack := &tournament.CSTMSeasonRank{} - return pack -} - -func (this *CSTMSeasonRankHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSTMSeasonRankHandler Process recv ", data) - if _, ok := data.(*tournament.CSTMSeasonRank); ok { - p := PlayerMgrSington.GetPlayer(sid) - if p == nil { - logger.Logger.Warnf("CSTMSeasonRankHandler p == nil.") - return nil - } - platform := p.Platform - if platform == DefaultPlatform { - logger.Logger.Warnf("CSTMSeasonRankHandler Platform == Default_Platform.") - return nil - } - pack := &tournament.SCTMSeasonRank{} - tmpMsrs := []*MatchSeasonRank{} - msr := MatchSeasonRankMgrSington.GetMatchSeasonRank(platform) - if msr != nil { - for _, ms := range msr { - sr := &MatchSeasonRank{ - SnId: ms.SnId, - Name: ms.Name, - Lv: ms.Lv, - } - tmpMsrs = append(tmpMsrs, sr) - } - } - robotmsr := MatchSeasonRankMgrSington.GetRobotMatchSeasonRank(platform) - if robotmsr != nil { - for _, ms := range robotmsr { - sr := &MatchSeasonRank{ - SnId: ms.SnId, - Name: ms.Name, - Lv: ms.Lv, - } - tmpMsrs = append(tmpMsrs, sr) - } - } - if tmpMsrs != nil && len(tmpMsrs) > 0 { - sort.Slice(tmpMsrs, func(i, j int) bool { - return tmpMsrs[i].Lv > tmpMsrs[j].Lv - }) - if len(tmpMsrs) > model.GameParamData.MatchSeasonRankMaxNum { - tmpMsrs = append(tmpMsrs[:model.GameParamData.MatchSeasonRankMaxNum]) - } - for i := 0; i < len(tmpMsrs); i++ { - ms := tmpMsrs[i] - sr := &tournament.SeasonRank{ - Snid: ms.SnId, - Name: ms.Name, - Lv: ms.Lv, - Rank: int32(i) + 1, - } - pack.ReasonRanks = append(pack.ReasonRanks, sr) - } - } - proto.SetDefaults(pack) - logger.Logger.Trace("CSTMSeasonRankHandler:", pack) - p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCTMSeasonRank), pack) - } - return nil -} - -// 领取赛季奖励 -type CSTMSeasonAwardPacketFactory struct { -} -type CSTMSeasonAwardHandler struct { -} - -func (this *CSTMSeasonAwardPacketFactory) CreatePacket() interface{} { - pack := &tournament.CSTMSeasonAward{} - return pack -} - -func (this *CSTMSeasonAwardHandler) Process(s *netlib.Session, packetid int, data interface{}, sid int64) error { - logger.Logger.Trace("CSTMSeasonAwardHandler Process recv ", data) - if msg, ok := data.(*tournament.CSTMSeasonAward); ok { - p := PlayerMgrSington.GetPlayer(sid) - if p == nil { - logger.Logger.Warnf("CSTMSeasonAwardHandler p == nil.") - return nil - } - if p.Platform == DefaultPlatform { - logger.Logger.Warnf("CSTMSeasonInfoHandler Platform == Default_Platform.") - return nil - } - lv := msg.GetLv() - logger.Logger.Trace("CSTMSeasonAwardHandler lv: ", lv) - pack := &tournament.SCTMSeasonAward{ - Lv: lv, - Code: 1, - } - ms := MatchSeasonMgrSington.GetMatchSeason(p.SnId) - msi := MatchSeasonMgrSington.GetMatchSeasonId(p.Platform) - if ms != nil && msi != nil { - if !ms.IsAward && ms.LastLv == lv && msi.SeasonId > 1 { //领取上赛季奖励 - for _, v := range srvdata.PBDB_GamMatchLVMgr.Datas.GetArr() { - if v.Star != nil && len(v.Star) > 1 { - startStar := v.Star[0] - endStar := v.Star[1] - if lv >= startStar && lv <= endStar { //匹配段位 - pack.Code = 0 - MatchSeasonMgrSington.UpdateMatchSeasonAward(p.SnId) - if v.Number1 > 0 { - switch v.AwardType1 { - case 1: //金币 - p.AddCoin(int64(v.Number1), 0, common.GainWay_MatchSeason, "system", "赛季奖励") - if !p.IsRob { - LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(p.SnId, p.Name, p.Platform, p.Channel, model.SystemFreeGive_GiveType_MatchSeason, model.SystemFreeGive_CoinType_Coin, int64(v.Number1))) - } - case 2: //钻石 - p.AddDiamond(int64(v.Number1), 0, common.GainWay_MatchSeason, "system", "赛季奖励") - if !p.IsRob { - LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(p.SnId, p.Name, p.Platform, p.Channel, model.SystemFreeGive_GiveType_MatchSeason, model.SystemFreeGive_CoinType_Diamond, int64(v.Number1))) - } - case 3: //道具 - item := &Item{ - ItemId: v.AwardId1, - ItemNum: int64(v.Number1), - } - BagMgrSingleton.AddItems(p, []*Item{item}, 0, common.GainWay_MatchSeason, "system", "赛季奖励", 0, 0, false) - } - } - if v.Number2 > 0 { - switch v.AwardType2 { - case 1: //金币 - p.AddCoin(int64(v.Number2), 0, common.GainWay_MatchSeason, "system", "赛季奖励") - if !p.IsRob { - LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(p.SnId, p.Name, p.Platform, p.Channel, model.SystemFreeGive_GiveType_MatchSeason, model.SystemFreeGive_CoinType_Coin, int64(v.Number2))) - } - case 2: //钻石 - p.AddDiamond(int64(v.Number2), 0, common.GainWay_MatchSeason, "system", "赛季奖励") - if !p.IsRob { - LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(p.SnId, p.Name, p.Platform, p.Channel, model.SystemFreeGive_GiveType_MatchSeason, model.SystemFreeGive_CoinType_Diamond, int64(v.Number2))) - } - case 3: //道具 - item := &Item{ - ItemId: v.AwardId2, - ItemNum: int64(v.Number2), - } - BagMgrSingleton.AddItems(p, []*Item{item}, 0, common.GainWay_MatchSeason, "system", "赛季奖励", 0, 0, false) - } - } - if v.Number3 > 0 { - switch v.AwardType3 { - case 1: //金币 - p.AddCoin(int64(v.Number3), 0, common.GainWay_MatchSeason, "system", "赛季奖励") - if !p.IsRob { - LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(p.SnId, p.Name, p.Platform, p.Channel, model.SystemFreeGive_GiveType_MatchSeason, model.SystemFreeGive_CoinType_Coin, int64(v.Number3))) - } - case 2: //钻石 - p.AddDiamond(int64(v.Number3), 0, common.GainWay_MatchSeason, "system", "赛季奖励") - if !p.IsRob { - LogChannelSingleton.WriteMQData(model.GenerateSystemFreeGive(p.SnId, p.Name, p.Platform, p.Channel, model.SystemFreeGive_GiveType_MatchSeason, model.SystemFreeGive_CoinType_Diamond, int64(v.Number3))) - } - case 3: //道具 - item := &Item{ - ItemId: v.AwardId3, - ItemNum: int64(v.Number3), - } - BagMgrSingleton.AddItems(p, []*Item{item}, 0, common.GainWay_MatchSeason, "system", "赛季奖励", 0, 0, false) - } - } - break - } - } - } - } - } - if pack.Code != 0 { - logger.Logger.Trace("CSTMSeasonAwardHandler ms: ", ms) - logger.Logger.Trace("CSTMSeasonAwardHandler msi: ", msi) - } - proto.SetDefaults(pack) - logger.Logger.Trace("SCTMSeasonAward:", pack) - p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCTMSeasonAward), pack) - } return nil } func init() { - common.RegisterHandler(int(tournament.TOURNAMENTID_PACKET_TM_CSTMInfo), &CSTMInfoHandler{}) - netlib.RegisterFactory(int(tournament.TOURNAMENTID_PACKET_TM_CSTMInfo), &CSTMInfoPacketFactory{}) - - common.RegisterHandler(int(tournament.TOURNAMENTID_PACKET_TM_CSTMRankList), &CSTMRankListHandler{}) - netlib.RegisterFactory(int(tournament.TOURNAMENTID_PACKET_TM_CSTMRankList), &CSTMRankListPacketFactory{}) - + // 比赛信息列表 + common.Register(int(tournament.TOURNAMENTID_PACKET_TM_CSTMInfo), tournament.CSTMInfo{}, CSTMInfo) // 比赛报名 - common.RegisterHandler(int(tournament.TOURNAMENTID_PACKET_TM_CSSignRace), &CSSignRaceHandler{}) - netlib.RegisterFactory(int(tournament.TOURNAMENTID_PACKET_TM_CSSignRace), &CSSignRacePacketFactory{}) - - common.RegisterHandler(int(tournament.TOURNAMENTID_PACKET_TM_CSTMSeasonInfo), &CSTMSeasonInfoHandler{}) - netlib.RegisterFactory(int(tournament.TOURNAMENTID_PACKET_TM_CSTMSeasonInfo), &CSTMSeasonInfoPacketFactory{}) - - common.RegisterHandler(int(tournament.TOURNAMENTID_PACKET_TM_CSTMSeasonRank), &CSTMSeasonRankHandler{}) - netlib.RegisterFactory(int(tournament.TOURNAMENTID_PACKET_TM_CSTMSeasonRank), &CSTMSeasonRankPacketFactory{}) - - common.RegisterHandler(int(tournament.TOURNAMENTID_PACKET_TM_CSTMSeasonAward), &CSTMSeasonAwardHandler{}) - netlib.RegisterFactory(int(tournament.TOURNAMENTID_PACKET_TM_CSTMSeasonAward), &CSTMSeasonAwardPacketFactory{}) + common.Register(int(tournament.TOURNAMENTID_PACKET_TM_CSSignRace), tournament.CSSignRace{}, CSSignRace) } diff --git a/worldsrv/coinscenepool_base.go b/worldsrv/coinscenepool_base.go index 991c646..fdab485 100644 --- a/worldsrv/coinscenepool_base.go +++ b/worldsrv/coinscenepool_base.go @@ -224,7 +224,7 @@ func (this *BaseCoinScenePool) NewScene(pool *CoinScenePool, p *Player) *Scene { } gameMode := pool.dbGameRule.GetGameMode() - params := pool.dbGameRule.GetParams() + params := common.CopySliceInt32ToInt64(pool.dbGameRule.GetParams()) var platformName string limitPlatform := PlatformMgrSingleton.GetPlatform(pool.platform) if limitPlatform == nil || !limitPlatform.Isolated { diff --git a/worldsrv/coinscenepool_local.go b/worldsrv/coinscenepool_local.go index bc8f9b4..f726859 100644 --- a/worldsrv/coinscenepool_local.go +++ b/worldsrv/coinscenepool_local.go @@ -234,7 +234,7 @@ func (this *CoinScenePoolLocal) NewScene(pool *CoinScenePool, p *Player) *Scene return nil } - scene := SceneMgrSingleton.CreateLocalGameScene(p.SnId, sceneId, gameId, gameSite, common.SceneMode_Public, 1, params, + scene := SceneMgrSingleton.CreateLocalGameScene(p.SnId, sceneId, gameId, gameSite, common.SceneMode_Public, 1, common.CopySliceInt32ToInt64(params), gs, limitPlatform, 0, pool.dbGameFree, baseScore, pool.groupId, pool.id) if scene != nil { scene.hallId = pool.id @@ -296,7 +296,7 @@ func (this *CoinScenePoolLocal) NewPreCreateScene(pool *CoinScenePool) *Scene { gameSite = int(dbCreateRoom.GetGameSite()) } if baseScore != 0 { - scene = SceneMgrSingleton.CreateLocalGameScene(0, sceneId, gameId, gameSite, common.SceneMode_Public, 1, params, + scene = SceneMgrSingleton.CreateLocalGameScene(0, sceneId, gameId, gameSite, common.SceneMode_Public, 1, common.CopySliceInt32ToInt64(params), gs, limitPlatform, playerNum, pool.dbGameFree, baseScore, pool.groupId, pool.id) if scene != nil { logger.Logger.Tracef("CreateLocalGameScene success.gameId:%v gameSite:%v baseScore:%v randIdx:%v", scene.gameId, scene.gameSite, baseScore, randIdx) diff --git a/worldsrv/hundredscenemgr.go b/worldsrv/hundredscenemgr.go index cda150f..2e9940e 100644 --- a/worldsrv/hundredscenemgr.go +++ b/worldsrv/hundredscenemgr.go @@ -395,7 +395,7 @@ func (this *HundredSceneMgr) CreateNewScene(id, groupId int32, limitPlatform *Pl if gs != nil { sceneId := SceneMgrSingleton.GenOneHundredSceneId() gameMode := dbGameRule.GetGameMode() - params := dbGameRule.GetParams() + params := common.CopySliceInt32ToInt64(dbGameRule.GetParams()) //SceneType := dbGameFree.GetSceneType() scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), common.SceneMode_Public, 1, -1, params, gs, limitPlatform, groupId, dbGameFree, id) diff --git a/worldsrv/matchscenemgr.go b/worldsrv/matchscenemgr.go index fe12860..e77b607 100644 --- a/worldsrv/matchscenemgr.go +++ b/worldsrv/matchscenemgr.go @@ -56,7 +56,7 @@ func (ms *MatchSceneMgr) NewScene(tm *TmMatch, isFinals bool, round int32) *Scen groupId := PlatformMgrSingleton.GetGameFreeGroup(tm.Platform, tm.dbGameFree.Id) // 建房参数 // 比赛唯一索引,是否决赛,第几轮,本轮总人数,下一轮总人数,赛制类型 - params := []int32{tm.SortId, finals, round, curPlayerNum, nextNeed, tm.gmd.MatchType} + params := []int64{tm.SortId, int64(finals), int64(round), int64(curPlayerNum), int64(nextNeed), int64(tm.gmd.MatchType)} scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, gameId, int(gameMode), common.SceneMode_Match, 1, 0, params, gs, limitPlatform, groupId, tm.dbGameFree, tm.dbGameFree.GetId()) diff --git a/worldsrv/player.go b/worldsrv/player.go index 284b7ae..b7a779c 100644 --- a/worldsrv/player.go +++ b/worldsrv/player.go @@ -1462,6 +1462,7 @@ func (this *Player) Kickout(reason int32) { this.DropLine() this.DgGameLogout() } + TournamentMgr.ForceQuit(this.Platform, this.SnId) } // DropLine 掉线 @@ -2328,7 +2329,7 @@ func (this *Player) GetIP() string { return this.Ip } -func (this *Player) CreateScene(sceneId, gameId, gameMode, sceneMode int, numOfGames int32, params []int32, dbGameFree *server_proto.DB_GameFree) (*Scene, hall_proto.OpResultCode_Game) { +func (this *Player) CreateScene(sceneId, gameId, gameMode, sceneMode int, numOfGames int32, params []int64, dbGameFree *server_proto.DB_GameFree) (*Scene, hall_proto.OpResultCode_Game) { gs := GameSessMgrSington.GetMinLoadSess(gameId) if gs == nil { logger.Logger.Warnf("(this *Player) EnterScene %v, %v GameSessMgrSington.GetMinLoadSess() = nil ", this.SnId, gameId) @@ -2343,7 +2344,7 @@ func (this *Player) CreateScene(sceneId, gameId, gameMode, sceneMode int, numOfG return s, hall_proto.OpResultCode_Game_OPRC_Sucess_Game } -func (this *Player) CreateLocalGameScene(sceneId, gameId, gameSite, sceneMode, playerNum int, params []int32, +func (this *Player) CreateLocalGameScene(sceneId, gameId, gameSite, sceneMode, playerNum int, params []int64, dbGameFree *server_proto.DB_GameFree, baseScore, groupId int32) (*Scene, hall_proto.OpResultCode_Game) { gs := GameSessMgrSington.GetMinLoadSess(gameId) if gs == nil { diff --git a/worldsrv/scene.go b/worldsrv/scene.go index e0d9da7..2700637 100644 --- a/worldsrv/scene.go +++ b/worldsrv/scene.go @@ -52,7 +52,7 @@ type Scene struct { gameId int //游戏id gameMode int //游戏模式 sceneMode int //房间模式,参考common.SceneMode_XXX - params []int32 //场景参数 + params []int64 //场景参数 paramsEx []int32 //其他扩展参数 playerNum int //人数 robotNum int //机器人数量 @@ -104,13 +104,13 @@ type Scene struct { quitMatchSnids []int32 //退赛玩家id gameSite int //tienlen游戏场次区分 1.初级 2.中级 3.高级场 BaseScore int32 //tienlen游戏底分 - matchId int32 //比赛场id + matchId int64 //比赛场id csp *CoinScenePool // 所在场景池 } // NewScene 创建房间 -func NewScene(agentor, creator int32, id, gameId, gameMode, sceneMode int, clycleTimes, numOfGames int32, params []int32, +func NewScene(agentor, creator int32, id, gameId, gameMode, sceneMode int, clycleTimes, numOfGames int32, params []int64, gs *GameSession, limitPlatform *Platform, groupId int32, dbGameFree *serverproto.DB_GameFree, paramsEx ...int32) *Scene { sp := GetScenePolicy(gameId, gameMode) if sp == nil { @@ -159,7 +159,7 @@ func NewScene(agentor, creator int32, id, gameId, gameMode, sceneMode int, clycl return s } -func NewLocalGameScene(creator int32, sceneId, gameId, gameSite, sceneMode int, clycleTimes int32, params []int32, +func NewLocalGameScene(creator int32, sceneId, gameId, gameSite, sceneMode int, clycleTimes int32, params []int64, gs *GameSession, limitPlatform *Platform, playerNum int, dbGameFree *serverproto.DB_GameFree, baseScore, groupId int32, paramsEx ...int32) *Scene { sp := GetScenePolicy(gameId, 0) if sp == nil { diff --git a/worldsrv/scenemgr.go b/worldsrv/scenemgr.go index cc9ce6f..1641571 100644 --- a/worldsrv/scenemgr.go +++ b/worldsrv/scenemgr.go @@ -131,7 +131,7 @@ func (m *SceneMgr) MarshalAllRoom(platform string, groupId, gameId int, gameMode Creator: s.creator, Agentor: s.agentor, ReplayCode: s.replayCode, - Params: s.params, + Params: common.CopySliceInt64ToInt32(s.params), PlayerCnt: int32(len(s.players) - s.robotNum), RobotCnt: int32(s.robotNum), CreateTime: s.createTime.Unix(), @@ -225,7 +225,7 @@ func (m *SceneMgr) MarshalAllRoom(platform string, groupId, gameId int, gameMode // CreateScene 创建房间 func (m *SceneMgr) CreateScene(agentor, creator int32, sceneId, gameId, gameMode, sceneMode int, clycleTimes int32, - numOfGames int32, params []int32, gs *GameSession, limitPlatform *Platform, groupId int32, dbGameFree *serverproto.DB_GameFree, + numOfGames int32, params []int64, gs *GameSession, limitPlatform *Platform, groupId int32, dbGameFree *serverproto.DB_GameFree, paramsEx ...int32) *Scene { logger.Logger.Trace("(this *SceneMgr) CreateScene ") s := NewScene(agentor, creator, sceneId, gameId, gameMode, sceneMode, clycleTimes, numOfGames, params, gs, limitPlatform, groupId, @@ -251,7 +251,7 @@ func (m *SceneMgr) CreateScene(agentor, creator int32, sceneId, gameId, gameMode } // CreateLocalGameScene 创建本地游戏房间 -func (m *SceneMgr) CreateLocalGameScene(creator int32, sceneId, gameId, gameSite, sceneMode int, clycleTimes int32, params []int32, +func (m *SceneMgr) CreateLocalGameScene(creator int32, sceneId, gameId, gameSite, sceneMode int, clycleTimes int32, params []int64, gs *GameSession, limitPlatform *Platform, playerNum int, dbGameFree *serverproto.DB_GameFree, baseScore, groupId int32, paramsEx ...int32) *Scene { logger.Logger.Trace("(this *SceneMgr) CreateLocalGameScene gameSite: ", gameSite, " sceneMode: ", sceneMode) @@ -352,7 +352,7 @@ func (m *SceneMgr) GetThirdScene(i webapi.IThirdPlatform) *Scene { var gameMode = common.SceneMode_Thr dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(i.GetPlatformBase().VultGameID) scene := SceneMgrSingleton.CreateScene(0, 0, sceneId, i.GetPlatformBase().BaseGameID, gameMode, int(common.SceneMode_Thr), 1, -1, - []int32{}, gs, limitPlatform, 0, dbGameFree, i.GetPlatformBase().VultGameID) + []int64{}, gs, limitPlatform, 0, dbGameFree, i.GetPlatformBase().VultGameID) return scene } else { logger.Logger.Errorf("Get %v game min session failed.", i.GetPlatformBase().BaseGameID) diff --git a/worldsrv/scenepolicydata.go b/worldsrv/scenepolicydata.go index 0cdc3cb..09f183f 100644 --- a/worldsrv/scenepolicydata.go +++ b/worldsrv/scenepolicydata.go @@ -3,6 +3,7 @@ package main import ( "time" + "mongo.games.com/game/common" hall_proto "mongo.games.com/game/protocol/gamehall" "mongo.games.com/goserver/core/logger" ) @@ -290,7 +291,7 @@ func (spd *ScenePolicyData) getPlayerNum(params []int32) int32 { func (spd *ScenePolicyData) GetPlayerNum(s *Scene) int32 { if s != nil { - return spd.getPlayerNum(s.params) + return spd.getPlayerNum(common.CopySliceInt64ToInt32(s.params)) } return spd.DefaultPlayerCnt } @@ -311,7 +312,7 @@ func (spd *ScenePolicyData) getBaseCoin(params []int32) int { func (spd *ScenePolicyData) GetBaseCoin(s *Scene) int { if s != nil { - return spd.getBaseCoin(s.params) + return spd.getBaseCoin(common.CopySliceInt64ToInt32(s.params)) } return 0 } diff --git a/worldsrv/tmmatch.go b/worldsrv/tmmatch.go index 2d261a8..ab745a0 100644 --- a/worldsrv/tmmatch.go +++ b/worldsrv/tmmatch.go @@ -16,6 +16,7 @@ import ( "mongo.games.com/game/protocol/server" "mongo.games.com/game/protocol/tournament" webapi_proto "mongo.games.com/game/protocol/webapi" + "mongo.games.com/game/srvdata" ) type TmPlayer struct { @@ -23,8 +24,15 @@ type TmPlayer struct { seq int // 报名序号(第几个报名的) } +type TmGradeInfo struct { + grade int32 + copySnid int32 + copyLv int32 + copyRoleId int32 +} + type TmMatch struct { - SortId int32 // 比赛开始时间戳,纳秒 + SortId int64 // 比赛开始时间戳,纳秒 TMId int32 // 比赛配置Id TmPlayer map[int32]*TmPlayer // 比赛玩家 Platform string // 平台 @@ -37,23 +45,34 @@ type TmMatch struct { StartTime int64 // 本场比赛开始时间 } -type TmGradeInfo struct { - grade int32 - copySnid int32 - copyLv int32 - copyRoleId int32 +func NewTmMatch(platform string, match *webapi_proto.GameMatchDate, players map[int32]*TmPlayer) *TmMatch { + ret := &TmMatch{ + SortId: time.Now().UnixNano(), + TMId: match.Id, + TmPlayer: make(map[int32]*TmPlayer), + Platform: platform, + gmd: match, + gml: srvdata.MatchLevelMgr.Get(match.GameFreeId, match.MatchLevel), + dbGameFree: srvdata.PBDB_GameFreeMgr.GetData(match.GameFreeId), + robotGrades: make(map[int][]*TmGradeInfo), + useRobot: match.UseRobot, + StartTime: time.Now().Unix(), + } + + ret.copyPlayers(players) + + return ret } func (tm *TmMatch) Start() { - logger.Logger.Trace("(this *TmMatch) Start()") + logger.Logger.Trace("TmMatch Start") //通知客户端比赛开始 pack := &tournament.SCTMStart{ MatchId: proto.Int32(tm.TMId), } - proto.SetDefaults(pack) - logger.Logger.Trace("SCTMStart:", pack) tm.BroadcastMessage(int(tournament.TOURNAMENTID_PACKET_TM_SCTMStart), pack) - tm.StartTime = time.Now().Unix() + logger.Logger.Trace("SCTMStart ", pack) + //创建房间 timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool { MatchSceneMgrSingleton.MatchStart(tm) @@ -62,7 +81,7 @@ func (tm *TmMatch) Start() { } func (tm *TmMatch) Stop() { - //销毁房间 + // 销毁房间 MatchSceneMgrSingleton.MatchStop(tm) logger.Logger.Trace("(this *TmMatch) Stop()") } @@ -90,7 +109,7 @@ func (tm *TmMatch) BroadcastMessage(packetId int, rawPack interface{}) { } } -func (tm *TmMatch) CopyMap(b map[int32]*TmPlayer) { +func (tm *TmMatch) copyPlayers(b map[int32]*TmPlayer) { tm.TmPlayer = make(map[int32]*TmPlayer) for _, v := range b { var tmp TmPlayer @@ -114,9 +133,9 @@ func (tm *TmMatch) CreateRobotGrades(round int) { // 上一轮数据,用在线玩家数据填充包含机器人,如果不够填充假数据 if tm.robotGrades[round-1] == nil { //初始化数据 tm.robotGrades[round-1] = []*TmGradeInfo{} - snids := []int32{} - lvs := []int32{} - roleIds := []int32{} + var snids []int32 + var lvs []int32 + var roleIds []int32 for _, player := range PlayerMgrSington.snidMap { if len(snids) > int(lastPromotionNum) { break @@ -234,12 +253,12 @@ func (tm *TmMatch) CreateRobotGrades(round int) { if tm.robotGrades[round-2] != nil { delete(tm.robotGrades, round-2) } - for i, infos := range tm.robotGrades { - logger.Logger.Tracef(">>>积分历史>>> 第 %v 轮", i) - for _, info := range infos { - logger.Logger.Trace("Snid: ", info.copySnid, " grade: ", info.grade, " copyLv: ", info.copyLv, " copyRoleId: ", info.copyRoleId) - } - } + //for i, infos := range tm.robotGrades { + // logger.Logger.Tracef(">>>积分历史>>> 第 %v 轮", i) + // for _, info := range infos { + // logger.Logger.Trace("Snid: ", info.copySnid, " grade: ", info.grade, " copyLv: ", info.copyLv, " copyRoleId: ", info.copyRoleId) + // } + //} } // RobotGradesDecline 假积分衰减 @@ -250,12 +269,15 @@ func (tm *TmMatch) RobotGradesDecline(round int) { if tm.robotGrades == nil { tm.robotGrades = make(map[int][]*TmGradeInfo) } + // 初始化第一轮积分 if round == 1 { tm.CreateRobotGrades(1) } - if tm.robotGrades[lastRound] == nil { //生成假数据 + // 生成当前轮积分 + if tm.robotGrades[lastRound] == nil { tm.CreateRobotGrades(lastRound) } + // 按规则积分衰减 if tm.robotGrades[lastRound] != nil { for i, info := range tm.robotGrades[lastRound] { declineGrade := info.grade @@ -275,11 +297,11 @@ func (tm *TmMatch) RobotGradesDecline(round int) { } } } - logger.Logger.Tracef("======积分衰减======当前第 %v 轮============", round) - for i, infos := range tm.robotGrades { - logger.Logger.Tracef(">>>积分历史>>> 第 %v 轮", i) - for _, info := range infos { - logger.Logger.Trace("Snid: ", info.copySnid, " grade: ", info.grade, " copyLv: ", info.copyLv, " copyRoleId: ", info.copyRoleId) - } - } + //logger.Logger.Tracef("======积分衰减======当前第 %v 轮============", round) + //for i, infos := range tm.robotGrades { + // logger.Logger.Tracef(">>>积分历史>>> 第 %v 轮", i) + // for _, info := range infos { + // logger.Logger.Trace("Snid: ", info.copySnid, " grade: ", info.grade, " copyLv: ", info.copyLv, " copyRoleId: ", info.copyRoleId) + // } + //} } diff --git a/worldsrv/tournament.go b/worldsrv/tournament.go index 071e910..4b51d27 100644 --- a/worldsrv/tournament.go +++ b/worldsrv/tournament.go @@ -4,7 +4,6 @@ import ( "fmt" "math/rand" "sort" - "strconv" "sync" "time" @@ -19,11 +18,15 @@ import ( "mongo.games.com/game/model" "mongo.games.com/game/proto" "mongo.games.com/game/protocol/tournament" - webapi_proto "mongo.games.com/game/protocol/webapi" + webapiproto "mongo.games.com/game/protocol/webapi" "mongo.games.com/game/srvdata" "mongo.games.com/game/webapi" ) +func init() { + module.RegisteModule(TournamentMgr, time.Second, 0) +} + const ( MatchTypeNormal = 1 // 锦标赛 MatchTypeChampion = 2 // 冠军赛 @@ -40,40 +43,13 @@ const ( MatchNotUserRobot = 1 // 关闭机器人 ) -// tournament +const ( + JinJi = 0 // 晋级 + TaoTai = 1 // 淘汰 + DaiDing = 2 // 待定 +) -var TournamentMgr = &Tournament{ - 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), - roundOverPlayerNum: make(map[int32]map[int32]int32), - finalPerRank: make(map[int32][]*PerRankInfo), - playerSignUpTime: make(map[int32]int64), - playerWaitStart: make(map[int32]int64), - singleSignupPlayers: make(map[int32]*SignupInfo), - singleFinalGrades: make(map[int32]map[int32]int32), -} - -type Tournament struct { - GameMatchDateList map[string]map[int32]*webapi_proto.GameMatchDate // 比赛配置,platform:比赛场配置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 - roundOverPlayerNum map[int32]map[int32]int32 // 完成比赛人数 比赛序号:轮次:人数 - finalPerRank map[int32][]*PerRankInfo //本场比赛最后排名,每淘汰一位记录一位,最后记录决赛玩家 - playerWaitStart map[int32]int64 // 等待时间 玩家Id:等待时长秒 - singleFinalGrades map[int32]map[int32]int32 //使用机器人模式最后一轮分数 - - // UseRobot - playerSignUpTime map[int32]int64 //玩家报名时间 玩家Id:报名时间戳 - singleSignupPlayers map[int32]*SignupInfo //报名的玩家,玩家Id:报名信息 - // UseRobot -} +var TournamentMgr = NewTournament() type PerRankInfo struct { Name string @@ -90,12 +66,44 @@ type SignInfo struct { type SignupInfo struct { Platform string - Tmid int32 - Snid int32 + TmId int32 + SnId int32 + Ts int64 // 报名时间 +} + +type PlayerRoundInfo struct { + players []*PlayerMatchContext // 本轮结算信息 + ranks []*PlayerMatchContext // 本来排名 + num int // 本来完成人数 +} + +type Tournament struct { + GameMatchDateList map[string]map[int32]*webapiproto.GameMatchDate // 比赛配置,platform:比赛场配置id:比赛配置 + singleSignupPlayers map[int32]*SignupInfo // 开启机器人时,报名的玩家,玩家Id:报名信息 + signupPlayers map[string]map[int32]*SignInfo // 报名的玩家 platform:比赛配置id:报名人 + 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 // 每轮比赛数据 比赛顺序序号:第几轮 + finalPerRank map[int64][]*PerRankInfo // 本场比赛排名,每淘汰一位记录一位,最后记录决赛玩家 比赛顺序序号 +} + +func NewTournament() *Tournament { + ret := &Tournament{ + GameMatchDateList: make(map[string]map[int32]*webapiproto.GameMatchDate), + singleSignupPlayers: make(map[int32]*SignupInfo), + signupPlayers: make(map[string]map[int32]*SignInfo), + playerWaitStart: make(map[int32]int64), + matches: make(map[int32]map[int64]*TmMatch), + players: make(map[int64]map[int32]*PlayerMatchContext), + roundPlayers: make(map[int64]map[int32]*PlayerRoundInfo), + finalPerRank: make(map[int64][]*PerRankInfo), + } + return ret } // 检查下数据是否合法(主要检查报名人数和晋级方式) n n|...|4|1 -func (this *Tournament) checkData(cfg *webapi_proto.GameMatchDate) bool { +func (this *Tournament) checkData(cfg *webapiproto.GameMatchDate) bool { if cfg == nil { return false } @@ -104,13 +112,16 @@ func (this *Tournament) checkData(cfg *webapi_proto.GameMatchDate) bool { return false } if cfg.MatchPromotion[0] != cfg.MatchNumebr { //第一位必须和报名人数相同 - return false + //return false + cfg.MatchNumebr = cfg.MatchPromotion[0] } if cfg.MatchPromotion[l-1] != 1 { //最后一位必须是1 - return false + //return false + cfg.MatchPromotion[l-1] = 1 } if cfg.MatchPromotion[l-2] != 4 { //倒数第二位必须是4 - return false + //return false + cfg.MatchPromotion[l-2] = 4 } for i, num := range cfg.MatchPromotion { if i < l-1 { //除了最后一位 @@ -126,72 +137,112 @@ func (this *Tournament) checkData(cfg *webapi_proto.GameMatchDate) bool { return true } +func (this *Tournament) addFinalPlayer(sortId int64, p *PerRankInfo) { + if this.finalPerRank[sortId] == nil { + this.finalPerRank[sortId] = []*PerRankInfo{} + } + this.finalPerRank[sortId] = append(this.finalPerRank[sortId], p) +} + +func (this *Tournament) getRoundPlayer(sortId int64, round int32) *PlayerRoundInfo { + _, ok := this.roundPlayers[sortId] + if !ok { + return nil + } + if this.roundPlayers[sortId] == nil { + this.roundPlayers[sortId] = make(map[int32]*PlayerRoundInfo) + } + v, ok := this.roundPlayers[sortId][round] + if !ok || v == nil { + return nil + } + return v +} + +func (this *Tournament) GetSignUpPlayers(platform string, id int32) map[int32]*TmPlayer { + v, ok := this.signupPlayers[platform] + if !ok { + return nil + } + vv, ok := v[id] + if !ok { + return nil + } + return vv.signup +} + // UpdateData 更新配置 // init: 通知客户端配置变更 -func (this *Tournament) UpdateData(init bool, cfgs *webapi_proto.GameMatchDateList) { - //logger.Logger.Trace("(this *Tournament) UpdateData:", cfgs) - if cfgs.Platform == "0" { +func (this *Tournament) UpdateData(init bool, data *webapiproto.GameMatchDateList) { + if data.Platform == "0" { return } - gmds := make(map[int32]*webapi_proto.GameMatchDate) - for _, v := range cfgs.List { + + // 参数校验 + configs := make(map[int32]*webapiproto.GameMatchDate) + for _, v := range data.List { if this.checkData(v) { - gmds[v.Id] = v + configs[v.Id] = v } else { logger.Logger.Error("GameMatchDate error: ", v) } } - oldgmds := this.GameMatchDateList[cfgs.Platform] - //旧配置关闭踢人 --旧配置关闭不影响已经开始的只取消报名未开始的 - for _, v := range oldgmds { - gmd := gmds[v.Id] - if (gmd != nil && v.MatchSwitch == MatchSwitchStart && gmd.MatchSwitch != v.MatchSwitch) || //配置关闭 + + oldConfigs := this.GameMatchDateList[data.Platform] + // 配置修改取消报名 + // 1.比赛开启变关闭 + // 2.比赛不在时间段内 + // 3.机器人开关有修改 + // 4.删除配置 + for _, v := range oldConfigs { + gmd := configs[v.Id] + if (gmd != nil && v.MatchSwitch == MatchSwitchStart && gmd.MatchSwitch != v.MatchSwitch) || //配置开启变关闭 (gmd != nil && !this.IsTimeRange(gmd)) || //或者不在时间段内 - (gmd != nil && v.UseRobot != gmd.UseRobot) || //或者匹配模式有修改 + (gmd != nil && v.UseRobot != gmd.UseRobot) || //或者机器人开关有修改 gmd == nil { //或者删除 - signInfo := this.signUpPlayers[cfgs.Platform][v.Id] - if signInfo != nil && len(signInfo.signup) > 0 { + signInfo := this.GetSignUpPlayers(data.Platform, v.Id) + if signInfo != nil && len(signInfo) > 0 { // 取消报名 - this.CancelSignUpAll(cfgs.Platform, v.Id) + this.CancelSignUpAll(data.Platform, v.Id) } } } - //新配置增加更新 - for _, v := range gmds { - oldgmd := oldgmds[v.Id] - if oldgmd == nil || v.MatchSwitch == MatchSwitchStart { - if this.signUpPlayers[cfgs.Platform] == nil { - this.signUpPlayers[cfgs.Platform] = make(map[int32]*SignInfo) + + // 新配置增加更新 + for _, v := range configs { + oldConfig := oldConfigs[v.Id] + if oldConfig == nil || v.MatchSwitch == MatchSwitchStart { + if this.signupPlayers[data.Platform] == nil { + this.signupPlayers[data.Platform] = make(map[int32]*SignInfo) } - this.signUpPlayers[cfgs.Platform][v.Id] = &SignInfo{ + this.signupPlayers[data.Platform][v.Id] = &SignInfo{ signup: make(map[int32]*TmPlayer), - Platform: cfgs.Platform, + Platform: data.Platform, MaxCnt: int(v.MatchNumebr), } } if v.MatchSwitch == MatchSwitchClose || !this.IsTimeRange(v) { - this.CancelSignUpAll(cfgs.Platform, v.Id) + this.CancelSignUpAll(data.Platform, v.Id) if v.MatchSwitch == MatchSwitchClose { - delete(this.signUpPlayers[cfgs.Platform], v.Id) + delete(this.signupPlayers[data.Platform], v.Id) } } } - this.GameMatchDateList[cfgs.Platform] = gmds + this.GameMatchDateList[data.Platform] = configs + // 通知平台玩家数据更新 if !init { //todo 优化 - for _, v := range PlayerMgrSington.playerOfPlatform[cfgs.Platform] { - //通知平台玩家数据更新 - pack := TournamentMgr.GetSCTMInfosPack(cfgs.Platform, v.AppChannel) - proto.SetDefaults(pack) - logger.Logger.Trace("SCTMInfos++++++++++++:", pack) + for _, v := range PlayerMgrSington.playerOfPlatform[data.Platform] { + pack := TournamentMgr.GetSCTMInfosPack(data.Platform, v.AppChannel) v.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCTMInfos), pack) + logger.Logger.Trace("SCTMInfos ", pack) } } } // GetMatchInfo 比赛配置 -func (this *Tournament) GetMatchInfo(platform string, tmId int32) *webapi_proto.GameMatchDate { +func (this *Tournament) GetMatchInfo(platform string, tmId int32) *webapiproto.GameMatchDate { if list, ok := this.GameMatchDateList[platform]; ok { if gmd, ok1 := list[tmId]; ok1 { return gmd @@ -202,68 +253,79 @@ func (this *Tournament) GetMatchInfo(platform string, tmId int32) *webapi_proto. // MatchSwitch 比赛开关 func (this *Tournament) MatchSwitch(platform string, tmId int32) bool { - info := this.GetMatchInfo(platform, tmId) - return info != nil && info.MatchSwitch == MatchSwitchStart + return this.IsMatchOn(this.GetMatchInfo(platform, tmId)) +} + +// IsMatchOn 比赛开关 +func (this *Tournament) IsMatchOn(match *webapiproto.GameMatchDate) bool { + return match != nil && match.MatchSwitch == MatchSwitchStart } // IsUseRobot 是否用机器人 func (this *Tournament) IsUseRobot(platform string, tmId int32) bool { - info := this.GetMatchInfo(platform, tmId) - return info != nil && info.UseRobot == MatchUseRobot + return this.IsRobotOn(this.GetMatchInfo(platform, tmId)) } -// 周几 -func getWeekNum(t time.Time) int { - strWeek := []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} - week := t.Weekday() - for i, s := range strWeek { - if week.String() == s { - return i - } - } - return 0 +// IsRobotOn 是否用机器人 +func (this *Tournament) IsRobotOn(match *webapiproto.GameMatchDate) bool { + return match != nil && match.UseRobot == MatchUseRobot } // IsTimeRange 判断是否在比赛时间段内 // 在时间段内才能报名 -func (this *Tournament) IsTimeRange(gmd *webapi_proto.GameMatchDate) bool { - if gmd != nil { - if gmd.MatchType == 2 { //冠军赛 - tNow := time.Now() - switch gmd.MatchTimeType { // 0无时效 1重复时间段 2一次性时间段 - case 0: - return true - case 1: - nowWeek := getWeekNum(tNow) - hms := int32(tNow.Hour()*10000 + tNow.Minute()*100 + tNow.Second()) - if gmd.MatchTimeWeek != nil && len(gmd.MatchTimeWeek) > 0 { - for _, week := range gmd.MatchTimeWeek { - if nowWeek == int(week) { - if hms >= gmd.MatchTimeStartHMS && hms <= gmd.MatchTimeEndHMS { - return true - } - } - } - } - case 2: - if gmd.MatchTimeStamp != nil && len(gmd.MatchTimeStamp) > 1 { - startStamp := gmd.MatchTimeStamp[0] - endStamp := gmd.MatchTimeStamp[1] - if tNow.Unix() >= startStamp && tNow.Unix() <= endStamp { +func (this *Tournament) IsTimeRange(gmd *webapiproto.GameMatchDate) bool { + getWeekNum := func(t time.Time) int { + strWeek := []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} + week := t.Weekday() + for i, s := range strWeek { + if week.String() == s { + return i + } + } + return 0 + } + + if gmd == nil { + return false + } + + if gmd.MatchType != MatchTypeChampion { + return true + } + + // 冠军赛有时间限制 + tNow := time.Now() + switch gmd.MatchTimeType { // 0无时效 1重复时间段 2一次性时间段 + case 0: + return true + case 1: + nowWeek := getWeekNum(tNow) + hms := int32(tNow.Hour()*10000 + tNow.Minute()*100 + tNow.Second()) + if gmd.MatchTimeWeek != nil && len(gmd.MatchTimeWeek) > 0 { + for _, week := range gmd.MatchTimeWeek { + if nowWeek == int(week) { + if hms >= gmd.MatchTimeStartHMS && hms <= gmd.MatchTimeEndHMS { return true } } } - } else { //锦标赛没有时间限制 - return true + } + case 2: + if gmd.MatchTimeStamp != nil && len(gmd.MatchTimeStamp) > 1 { + startStamp := gmd.MatchTimeStamp[0] + endStamp := gmd.MatchTimeStamp[1] + if tNow.Unix() >= startStamp && tNow.Unix() <= endStamp { + return true + } } } + return false } -// IsOutTime 是否过期 -func (this *Tournament) IsOutTime(gmd *webapi_proto.GameMatchDate) bool { - if gmd == nil || gmd.MatchSwitch != MatchSwitchStart { +// IsOutTime 是否过期,一次性比赛才有过期,一次性冠军赛 +func (this *Tournament) IsOutTime(gmd *webapiproto.GameMatchDate) bool { + if !this.IsMatchOn(gmd) { return true } if gmd.MatchType == MatchTypeChampion { //冠军赛的一次性时间段才有过期可能 @@ -281,8 +343,8 @@ func (this *Tournament) IsOutTime(gmd *webapi_proto.GameMatchDate) bool { return false } -// GetAllMatchInfo 比赛配置数据 -func (this *Tournament) GetAllMatchInfo(platform string) map[int32]*webapi_proto.GameMatchDate { +// GetAllMatchInfo 所有比赛配置数据 +func (this *Tournament) GetAllMatchInfo(platform string) map[int32]*webapiproto.GameMatchDate { if list, ok := this.GameMatchDateList[platform]; ok { return list } @@ -290,12 +352,12 @@ func (this *Tournament) GetAllMatchInfo(platform string) map[int32]*webapi_proto } // IsMatching 判断是否在比赛中 -func (this *Tournament) IsMatching(snid int32) bool { +func (this *Tournament) IsMatching(snId int32) bool { if this.players != nil { for _, v := range this.players { if v != nil { for k := range v { - if k == snid { + if k == snId { return true } } @@ -305,200 +367,180 @@ func (this *Tournament) IsMatching(snid int32) bool { return false } -// IsMatchWaiting 判断是否在匹配中 -func (this *Tournament) IsMatchWaiting(platform string, snid int32) (bool, int32) { +// IsMatchWaiting 判断是否在匹配中,已报名 +func (this *Tournament) IsMatchWaiting(platform string, snId int32) (bool, int32) { // 未使用机器人 - if this.signUpPlayers != nil && this.signUpPlayers[platform] != nil { - for tmid, info := range this.signUpPlayers[platform] { - if info.signup != nil { - for sid, _ := range info.signup { - if sid == snid { - return true, tmid - } - } - } + for k, v := range this.signupPlayers[platform] { + if v.signup != nil { + _, ok := v.signup[snId] + return ok, k } } + // 使用机器人了 - if v, ok := this.singleSignupPlayers[snid]; ok { - return true, v.Tmid + if v, ok := this.singleSignupPlayers[snId]; ok { + return true, v.TmId } return false, 0 } -// Quit 如果正在等待比赛,退赛 -func (this *Tournament) Quit(platform string, snid int32) { - isWaiting, tmid := this.IsMatchWaiting(platform, snid) - if isWaiting { - this.CancelSignUp(platform, tmid, snid) - } -} - -// signUpCost 报名 +// signUpCost 报名消耗 // tmId 比赛配置id // cost true报名、false取消报名 // 报名费用 0成功 3道具不足 5金币不足 6钻石不足 7免费次数不足 -func (this *Tournament) signUpCost(tmId int32, p *Player, cost bool) (bool, int32) { - logger.Logger.Trace("报名费用 signUpCost: ", tmId, " snid: ", p.SnId, " cost: ", cost) - if p == nil { - return false, int32(tournament.SignRaceCode_OPRC_NoItem) - } +func (this *Tournament) signUpCost(p *Player, tmId int32, cost bool) (bool, int32) { + logger.Logger.Tracef("signUpCost 比赛id:%v 玩家:%v 报名:%v", tmId, p.SnId, cost) gmd := this.GetMatchInfo(p.Platform, tmId) - if gmd != nil && !p.IsRob { //真人费用检测 - if gmd.MatchType == MatchTypeVIP { //VIP比赛场 - freeTimes := p.GetVIPPrivilege1() // VIP比赛场免费次数 - logger.Logger.Trace("报名费用免费次数: freeTimes: ", freeTimes, " p.VipMatchTimes: ", p.VipMatchTimes) - if freeTimes > 0 { - if cost { - if p.VipMatchTimes < freeTimes { //参与次数<免费次数 - p.VipMatchTimes++ - } else { - logger.Logger.Trace("免费次数不足1") - return false, int32(tournament.SignRaceCode_OPRC_Free) - } - } else { - if p.VipMatchTimes > 0 { - p.VipMatchTimes-- - } else { - p.VipMatchTimes = 0 - } - } - } else { - logger.Logger.Trace("免费次数不足2") - return false, int32(tournament.SignRaceCode_OPRC_Free) - } - } - if gmd.SignupCostCoin > 0 { - logger.Logger.Trace("比赛场报名消耗金币", cost, gmd.SignupCostCoin) + if gmd == nil || p.IsRob { + return true, 0 + } + + // 真人费用检测 + + // VIP比赛场 + if gmd.MatchType == MatchTypeVIP { + freeTimes := p.GetVIPPrivilege1() // VIP比赛场免费次数 + logger.Logger.Trace("报名费用免费次数: freeTimes: ", freeTimes, " p.VipMatchTimes: ", p.VipMatchTimes) + if freeTimes > 0 { if cost { - if p.Coin < gmd.SignupCostCoin { //金币不足 - logger.Logger.Trace("金币不足") - return false, int32(tournament.SignRaceCode_OPRC_Coin) + if p.VipMatchTimes < freeTimes { //参与次数<免费次数 + p.VipMatchTimes++ } else { - p.AddCoin(-gmd.SignupCostCoin, 0, common.GainWay_MatchSignup, "system", gmd.MatchName+"-报名消耗") + logger.Logger.Trace("免费次数不足1") + return false, int32(tournament.SignRaceCode_OPRC_Free) } } else { - p.AddCoin(gmd.SignupCostCoin, 0, common.GainWay_MatchSignup, "system", gmd.MatchName+"-报名退还") - } - } - if gmd.SignupCostDiamond > 0 { - logger.Logger.Trace("比赛场报名消耗钻石", cost, gmd.SignupCostDiamond) - if cost { - if p.Diamond < gmd.SignupCostDiamond { //钻石不足 - logger.Logger.Trace("钻石不足") - return false, int32(tournament.SignRaceCode_OPRC_Diamond) + if p.VipMatchTimes > 0 { + p.VipMatchTimes-- } else { - p.AddDiamond(-gmd.SignupCostDiamond, 0, common.GainWay_MatchSignup, "system", gmd.MatchName+"-报名消耗") + p.VipMatchTimes = 0 } - } else { - p.AddDiamond(gmd.SignupCostDiamond, 0, common.GainWay_MatchSignup, "system", gmd.MatchName+"-报名退还") - } - } - if gmd.SignupCostItem != nil && gmd.SignupCostItem.ItemNum > 0 { - //背包数据处理 - logger.Logger.Trace("比赛场报名消耗道具", cost, gmd.SignupCostItem.ItemNum) - item := BagMgrSingleton.GetItem(p.SnId, gmd.SignupCostItem.ItemId) - if item != nil { - gameId := int64(0) - gf := PlatformMgrSingleton.GetGameFree(p.Platform, gmd.GameFreeId) - if gf != nil && gf.GetDbGameFree() != nil { - gameId = int64(gf.GetDbGameFree().GameId) - } - if cost { - if item.ItemNum < gmd.SignupCostItem.ItemNum { - logger.Logger.Trace("道具不足") - return false, int32(tournament.SignRaceCode_OPRC_NoItem) - } else { - BagMgrSingleton.AddItem(p, int64(item.ItemId), -gmd.SignupCostItem.ItemNum, 0, common.GainWay_MatchSignup, - "player", gmd.MatchName+"-报名消耗", gameId, int64(gmd.GameFreeId), false) - } - } else { - BagMgrSingleton.AddItem(p, int64(item.ItemId), gmd.SignupCostItem.ItemNum, 0, common.GainWay_MatchSignup, - "player", gmd.MatchName+"-报名退还", gameId, int64(gmd.GameFreeId), false) - } - } else { - logger.Logger.Trace("道具不足") - return false, int32(tournament.SignRaceCode_OPRC_NoItem) } + } else { + logger.Logger.Trace("免费次数不足2") + return false, int32(tournament.SignRaceCode_OPRC_Free) } } + // 金币 + if gmd.SignupCostCoin > 0 { + logger.Logger.Tracef("比赛场报名消耗金币 报名:%v 金币:%v", cost, gmd.SignupCostCoin) + if cost { + if p.Coin < gmd.SignupCostCoin { //金币不足 + logger.Logger.Trace("金币不足") + return false, int32(tournament.SignRaceCode_OPRC_Coin) + } else { + p.AddCoin(-gmd.SignupCostCoin, 0, common.GainWay_MatchSignup, "system", gmd.MatchName+"-报名消耗") + } + } else { + p.AddCoin(gmd.SignupCostCoin, 0, common.GainWay_MatchSignup, "system", gmd.MatchName+"-报名退还") + } + } + // 钻石 + if gmd.SignupCostDiamond > 0 { + logger.Logger.Tracef("比赛场报名消耗钻石 报名:%v 钻石:%v", cost, gmd.SignupCostDiamond) + if cost { + if p.Diamond < gmd.SignupCostDiamond { //钻石不足 + logger.Logger.Trace("钻石不足") + return false, int32(tournament.SignRaceCode_OPRC_Diamond) + } else { + p.AddDiamond(-gmd.SignupCostDiamond, 0, common.GainWay_MatchSignup, "system", gmd.MatchName+"-报名消耗") + } + } else { + p.AddDiamond(gmd.SignupCostDiamond, 0, common.GainWay_MatchSignup, "system", gmd.MatchName+"-报名退还") + } + } + // 道具 + if gmd.SignupCostItem != nil && gmd.SignupCostItem.ItemNum > 0 { + logger.Logger.Tracef("比赛场报名消耗道具 报名:%v 道具:%v", cost, gmd.SignupCostItem.String()) + item := BagMgrSingleton.GetItem(p.SnId, gmd.SignupCostItem.ItemId) + if item != nil { + gameId := int64(0) + gf := PlatformMgrSingleton.GetGameFree(p.Platform, gmd.GameFreeId) + if gf != nil && gf.GetDbGameFree() != nil { + gameId = int64(gf.GetDbGameFree().GameId) + } + if cost { + if item.ItemNum < gmd.SignupCostItem.ItemNum { + logger.Logger.Trace("道具不足") + return false, int32(tournament.SignRaceCode_OPRC_NoItem) + } else { + BagMgrSingleton.AddItem(p, int64(item.ItemId), -gmd.SignupCostItem.ItemNum, 0, common.GainWay_MatchSignup, + "player", gmd.MatchName+"-报名消耗", gameId, int64(gmd.GameFreeId), false) + } + } else { + BagMgrSingleton.AddItem(p, int64(item.ItemId), gmd.SignupCostItem.ItemNum, 0, common.GainWay_MatchSignup, + "player", gmd.MatchName+"-报名退还", gameId, int64(gmd.GameFreeId), false) + } + } else { + logger.Logger.Trace("道具不足") + return false, int32(tournament.SignRaceCode_OPRC_NoItem) + } + } + return true, 0 } // SignUp 报名 // 0成功 1重复报名 2比赛没有开启 3道具不足 4不在报名时间段 5金币不足 6钻石不足 7免费次数不足 func (this *Tournament) SignUp(tmId int32, p *Player) (bool, int32) { - logger.Logger.Trace("(this *Tournament) SignUp:", tmId, p.SnId) + logger.Logger.Tracef("报名 比赛id:%v 玩家:%v", tmId, p.SnId) // 开启 info := this.GetMatchInfo(p.Platform, tmId) - if info == nil || info.GetMatchSwitch() == MatchSwitchClose { + if !this.IsMatchOn(info) { return false, int32(tournament.SignRaceCode_OPRC_Close) } // 报名时间 - if !TournamentMgr.IsTimeRange(info) { + if !this.IsTimeRange(info) { return false, int32(tournament.SignRaceCode_OPRC_Time) } // 已报名 - isWaiting, _ := TournamentMgr.IsMatchWaiting(p.Platform, p.SnId) - if TournamentMgr.IsMatching(p.SnId) || isWaiting { + isWaiting, _ := this.IsMatchWaiting(p.Platform, p.SnId) + if this.IsMatching(p.SnId) || isWaiting { return false, int32(tournament.SignRaceCode_OPRC_Repeat) } + // 扣报名费 - ok, code := this.signUpCost(tmId, p, true) + ok, code := this.signUpCost(p, tmId, true) if !ok { return false, code } - var signInfo *SignInfo - gmd := this.GetMatchInfo(p.Platform, tmId) - if gmd == nil { - logger.Logger.Errorf("GetMatchInfo is nil. id=%v", tmId) - return false, int32(tournament.SignRaceCode_OPRC_Repeat) - } - - if this.IsUseRobot(p.Platform, tmId) { + if this.IsRobotOn(info) { + // 开启机器人时 signupInfo := &SignupInfo{ Platform: p.Platform, - Tmid: tmId, - Snid: p.SnId, + TmId: tmId, + SnId: p.SnId, + Ts: time.Now().Unix(), } this.singleSignupPlayers[p.SnId] = signupInfo - this.playerSignUpTime[p.SnId] = time.Now().Unix() } else { - signInfo = &SignInfo{ - signup: make(map[int32]*TmPlayer), - Platform: p.Platform, - MaxCnt: int(gmd.MatchNumebr), - } + // 不开机器人时 var platform = p.Platform - gps := PlatformMgrSingleton.GetGameFree(p.Platform, gmd.GameFreeId) - if gps != nil && gps.GroupId != 0 { - for plt := range this.signUpPlayers { - gps2 := PlatformMgrSingleton.GetGameFree(plt, gmd.GameFreeId) - if gps.GroupId == gps2.GroupId { - platform = plt - break - } + signInfo, ok := this.signupPlayers[platform][tmId] + if !ok { + signInfo = &SignInfo{ + signup: make(map[int32]*TmPlayer), + Platform: platform, + MaxCnt: int(info.MatchNumebr), } - } - if _, ok := this.signUpPlayers[platform][tmId]; !ok { - this.signUpPlayers[platform][tmId] = signInfo - } else { - signInfo = this.signUpPlayers[platform][tmId] + this.signupPlayers[platform][tmId] = signInfo } - if _, ok := signInfo.signup[p.SnId]; !ok { - n := len(signInfo.signup) + 1 - signInfo.signup[p.SnId] = &TmPlayer{SnId: p.SnId, seq: n} - logger.Logger.Trace("没使用机器人,真人 报名.............", n, " p.SnId: ", p.SnId) - } else { + _, ok = signInfo.signup[p.SnId] + if ok { return false, int32(tournament.SignRaceCode_OPRC_Repeat) } + + n := len(signInfo.signup) + 1 + signInfo.signup[p.SnId] = &TmPlayer{SnId: p.SnId, seq: n} + logger.Logger.Tracef("没使用机器人,真人报名,报名人数 %v 玩家:%v", n, p.SnId) } + //(报名人数/20,报名人数/10) - minTime := gmd.MatchNumebr / 20 - maxTime := gmd.MatchNumebr / 10 - if gmd.MatchNumebr > 20 { + minTime := info.MatchNumebr / 20 + maxTime := info.MatchNumebr / 10 + if info.MatchNumebr > 20 { this.playerWaitStart[p.SnId] = int64(minTime + rand.Int31n(maxTime-minTime)) } else { this.playerWaitStart[p.SnId] = 1 @@ -509,41 +551,40 @@ func (this *Tournament) SignUp(tmId int32, p *Player) (bool, int32) { // CancelSignUp 取消玩家报名 func (this *Tournament) CancelSignUp(platform string, tmid, snid int32) { delete(this.playerWaitStart, snid) - if this.signUpPlayers[platform] != nil && this.signUpPlayers[platform][tmid] != nil { - signInfo := this.signUpPlayers[platform][tmid] + + if this.signupPlayers[platform] != nil && this.signupPlayers[platform][tmid] != nil { + signInfo := this.signupPlayers[platform][tmid] if _, ok := signInfo.signup[snid]; ok { p := PlayerMgrSington.GetPlayerBySnId(snid) if p != nil && p.scene == nil { //退费 - this.signUpCost(tmid, p, false) - delete(this.signUpPlayers[platform][tmid].signup, snid) + this.signUpCost(p, tmid, false) + delete(this.signupPlayers[platform][tmid].signup, snid) //通知取消报名 pack := &tournament.SCSignRace{ OpCode: 1, RetCode: 0, } - proto.SetDefaults(pack) - logger.Logger.Trace("signUpPlayers: ", pack) p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCSignRace), pack) + logger.Logger.Trace("SCSignRace ", pack) return } } } - if signupinfo, ok := this.singleSignupPlayers[snid]; ok { + + if v, ok := this.singleSignupPlayers[snid]; ok { p := PlayerMgrSington.GetPlayerBySnId(snid) if p != nil && p.scene == nil { //退费 - this.signUpCost(signupinfo.Tmid, p, false) + this.signUpCost(p, v.TmId, false) delete(this.singleSignupPlayers, snid) - delete(this.playerSignUpTime, snid) //通知取消报名 pack := &tournament.SCSignRace{ OpCode: 1, RetCode: 0, } - proto.SetDefaults(pack) - logger.Logger.Trace("singleSignupPlayers: ", pack) p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCSignRace), pack) + logger.Logger.Trace("SCSignRace ", pack) return } } @@ -551,25 +592,53 @@ func (this *Tournament) CancelSignUp(platform string, tmid, snid int32) { // CancelSignUpAll 取消所有报名 func (this *Tournament) CancelSignUpAll(platform string, tmId int32) { - if this.signUpPlayers[platform] != nil && this.signUpPlayers[platform][tmId] != nil { - for _, tmp := range this.signUpPlayers[platform][tmId].signup { + if this.signupPlayers[platform] != nil && this.signupPlayers[platform][tmId] != nil { + for _, tmp := range this.signupPlayers[platform][tmId].signup { this.CancelSignUp(platform, tmId, tmp.SnId) } } if this.singleSignupPlayers != nil { for _, signupInfo := range this.singleSignupPlayers { - if signupInfo.Tmid == tmId { - this.CancelSignUp(signupInfo.Platform, tmId, signupInfo.Snid) + if signupInfo.TmId == tmId { + this.CancelSignUp(signupInfo.Platform, tmId, signupInfo.SnId) } } } } +// Quit 如果正在等待比赛,退赛 +func (this *Tournament) Quit(platform string, snid int32) { + logger.Logger.Tracef("TournamentMgr.Quit: snId:%d", snid) + isWaiting, tmid := this.IsMatchWaiting(platform, snid) + if isWaiting && !this.IsMatching(snid) { + this.CancelSignUp(platform, tmid, snid) + } +} + +// ForceQuit 强制退赛 +func (this *Tournament) ForceQuit(platform string, snId int32) { + logger.Logger.Tracef("TournamentMgr.ForceQuit: snId:%d", snId) + this.Quit(platform, snId) + + var info *PlayerMatchContext + var ok bool + for _, v := range this.players { + info, ok = v[snId] + if ok { + break + } + } + if info != nil && info.tm != nil { + this.StopMatch(info.tm.TMId, info.tm.SortId) + MatchSceneMgrSingleton.MatchStop(info.tm) + } +} + // CanStart 是否开赛 // 没有开机器人走这个判断 func (this *Tournament) CanStart(platform string, tmId int32) bool { - if this.signUpPlayers != nil && this.signUpPlayers[platform] != nil { - if signInfo, ok := this.signUpPlayers[platform][tmId]; ok { + if this.signupPlayers != nil && this.signupPlayers[platform] != nil { + if signInfo, ok := this.signupPlayers[platform][tmId]; ok { matchInfo := this.GetMatchInfo(signInfo.Platform, tmId) if matchInfo != nil { n := 0 @@ -596,372 +665,455 @@ func (this *Tournament) CanStart(platform string, tmId int32) bool { // Start 开赛 func (this *Tournament) Start(platform string, tmId int32) { - if this.signUpPlayers[platform] == nil { - this.signUpPlayers[platform] = make(map[int32]*SignInfo) + if this.signupPlayers[platform] == nil { + this.signupPlayers[platform] = make(map[int32]*SignInfo) } - matchInfo := this.GetMatchInfo(platform, tmId) - signInfo := this.signUpPlayers[platform][tmId] - sortId := int32(time.Now().Nanosecond()) - tm := &TmMatch{ - 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) - tm.CopyMap(signInfo.signup) if this.matches[tmId] == nil { - this.matches[tmId] = make(map[int32]*TmMatch) + this.matches[tmId] = make(map[int64]*TmMatch) } + + matchInfo := this.GetMatchInfo(platform, tmId) + signInfo := this.signupPlayers[platform][tmId] + + if matchInfo == nil || signInfo == nil || len(signInfo.signup) == 0 { + return + } + + tm := NewTmMatch(platform, matchInfo, signInfo.signup) + this.matches[tmId][tm.SortId] = tm + logger.Logger.Tracef("开赛:%+v, 难度:%v", tm, tm.gml) - // 开始比赛,清除报名数据 - this.matches[tmId][sortId] = tm tm.Start() - this.signUpPlayers[platform][tmId].signup = make(map[int32]*TmPlayer) + + // 开始比赛,清除报名数据 + for _, v := range signInfo.signup { + delete(this.singleSignupPlayers, v.SnId) + } + this.signupPlayers[platform][tmId].signup = make(map[int32]*TmPlayer) +} + +// StopMatch 比赛结束 +func (this *Tournament) StopMatch(tmId int32, sortId int64) { + logger.Logger.Tracef("StopMatch:%v, %v", tmId, sortId) + //房间清理 + if this.matches[tmId] != nil && this.matches[tmId][sortId] != nil { + tm := this.matches[tmId][sortId] + matchLog := this.MakeMatchLog(tm.Platform, tmId, sortId) + this.saveMatchLog(matchLog) + tm.Stop() + } + + if this.matches[tmId] != nil { + delete(this.matches[tmId], sortId) + } + + //数据清理 + delete(this.players, sortId) + delete(this.roundPlayers, sortId) + delete(this.finalPerRank, sortId) +} + +// GetTm 获取比赛信息 +func (this *Tournament) GetTm(sortId int64) *TmMatch { + for _, v := range this.matches { + if v == nil { + continue + } + if vv, ok := v[sortId]; ok { + return vv + } + } + return nil +} + +// CreatePlayerMatchContext 创建玩家比赛信息 +func (this *Tournament) CreatePlayerMatchContext(p *Player, m *TmMatch, seq int) *PlayerMatchContext { + ms := MatchSeasonMgrSington.GetMatchSeason(p.SnId) + var lv int32 + if ms != nil { + lv = ms.Lv + } + roleId := int32(2000001) + if p.Roles != nil { + roleId = p.Roles.ModId + } + + mc := NewMatchContext(p, m, 1000, p.SnId, lv, roleId, seq) + if mc != nil { + if this.players[m.SortId] == nil { + this.players[m.SortId] = make(map[int32]*PlayerMatchContext) + } + this.players[m.SortId][p.SnId] = mc + p.matchCtx = mc + return mc + } + return nil +} + +func (this *Tournament) isOut(sortId int64, snid int32) bool { + if this.finalPerRank[sortId] != nil { + for _, info := range this.finalPerRank[sortId] { + if info.SnId == snid { + return true + } + } + } + return false +} + +// getRank 获取本轮排名 +// 不适用机器人时 +func (this *Tournament) getRank(sortId int64, round, snid int32, isFinals bool) int32 { + if _, ok := this.roundPlayers[sortId]; ok { + if rps, ok1 := this.roundPlayers[sortId][round]; ok1 && rps != nil { + MatchContextSlice(rps.ranks).Sort(isFinals) + for _, rp := range rps.ranks { + if rp.p.SnId == snid { + return rp.rank + } + } + } + } + return 0 +} + +// 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) + if this.GetTm(sortId) == nil { + logger.Logger.Tracef("UpdateMatchInfo: 比赛已经结束") + return + } + + if _, ok := this.players[sortId]; !ok { + this.players[sortId] = make(map[int32]*PlayerMatchContext) + } + info, ok := this.players[sortId][p.SnId] + if !ok { + return + } + + if _, ok = this.roundPlayers[sortId]; !ok { + this.roundPlayers[sortId] = make(map[int32]*PlayerRoundInfo) + } + if this.roundPlayers[sortId][info.round] == nil { + this.roundPlayers[sortId][info.round] = &PlayerRoundInfo{} + } + + // 积分 + info.grade = grade + // 完成人数 + this.roundPlayers[sortId][info.round].num++ + // 输赢统计 + if info.record == nil { + info.record = make(map[int32]int32) + } + info.record[isWin]++ + //轮数增加 + info.round++ + info.gaming = false + + // 备份本轮比赛结算信息 + mc := *info + if this.roundPlayers[sortId][info.round] == nil { + this.roundPlayers[sortId][info.round] = &PlayerRoundInfo{} + } + this.roundPlayers[sortId][info.round].players = append(this.roundPlayers[sortId][info.round].players, &mc) + // 计算排名用 + this.roundPlayers[sortId][info.round].ranks = append(this.roundPlayers[sortId][info.round].ranks, &mc) + + // 检查是否开始下一局 + if this.IsRobotOn(info.tm.gmd) { + this.NextRoundStartSingle(sortId, info, matchRobotGrades) + } else { + this.NextRoundStart(sortId, info) + } +} + +func (this *Tournament) stopMatch(matchId int32, sortId int64) (isOver bool) { + 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 { + isOver = true + logger.Logger.Trace("没有真人比赛解散") + this.StopMatch(matchId, sortId) + } + } + return } // NextRoundStartSingle 下一轮是否开始 -func (this *Tournament) NextRoundStartSingle(sortId int32, mtp *PlayerMatchContext, matchRobotGrades map[int32]int32) { - logger.Logger.Tracef("================NextRoundStart_Single==========当前第 %v 轮============", mtp.round) - if _, ok := this.copyPlayers[sortId]; ok { - if _, ok1 := this.copyPlayers[sortId][mtp.round]; ok1 { - gmd := mtp.tm.gmd - //需要晋级的人数 - promotionNum := gmd.MatchPromotion[mtp.round] // 晋级人数 - if promotionNum != 1 { // 非决赛 - if mtp.tm.robotGrades == nil || mtp.tm.robotGrades[int(mtp.round)] == nil { - mtp.tm.CreateRobotGrades(int(mtp.round)) - } - if mtp.tm.robotGrades != nil && mtp.tm.robotGrades[int(mtp.round)] != nil { - robotGrades := mtp.tm.robotGrades[int(mtp.round)] - // 修改陪真人玩的机器人积分 - if matchRobotGrades != nil { - logger.Logger.Trace("matchRobotGrades: ", matchRobotGrades) - for _, gradeInfo := range robotGrades { - if grade, ok := matchRobotGrades[gradeInfo.copySnid]; ok { - gradeInfo.grade = grade - } - } - } - //非决赛淘汰后开始配桌 - logger.Logger.Trace("需要晋级的人数 promotionNum: ", promotionNum) - logger.Logger.Trace("非决赛开始淘汰晋级 grade: ", mtp.grade) - // 记录真人积分 - findMe := false - for _, gradeinfo := range robotGrades { - if gradeinfo.copySnid == 0 { - gradeinfo.grade = mtp.grade - findMe = true - break - } - } - if !findMe { - gradeInfo := &TmGradeInfo{ - grade: mtp.grade, - copySnid: 0, - } - robotGrades = append(robotGrades, gradeInfo) // 添加了真人数据 - } - sort.Slice(robotGrades, func(i, j int) bool { - return robotGrades[i].grade > robotGrades[j].grade - }) - for _, info := range robotGrades { - logger.Logger.Trace("Snid: ", info.copySnid, " grade: ", info.grade, " copyLv: ", info.copyLv, " copyRoleId: ", info.copyRoleId) - } - // 获取排名 - index := int32(0) //晋级淘汰 - for i, gradeinfo := range robotGrades { - if mtp.grade >= gradeinfo.grade { - index = int32(i) + 1 - break - } - } - robotGrades = append(robotGrades[:promotionNum]) - mtp.tm.robotGrades[int(mtp.round)] = robotGrades +// 开启机器人时使用 +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) + if info == nil { + return + } - if index == 0 { // 是最后一名 - index = gmd.MatchPromotion[mtp.round-1] - } - if index <= promotionNum { - // 晋级 - mtp.rank = index - this.sendPromotionInfo(mtp, sortId, JinJi, false, false) //晋级 + gmd := playerCtx.tm.gmd + // 需要晋级的人数 + promotionNum := gmd.MatchPromotion[playerCtx.round] - mct := []*PlayerMatchContext{mtp} - finals := false - if mtp.round == int32(len(gmd.MatchPromotion)-2) { - finals = true - } - timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool { - MatchSceneMgrSingleton.NewRoundStart(mtp.tm, mct, finals, mtp.round+1) - return true - }), nil, time.Second*7, 1) - } else { - // 淘汰 - mtp.rank = index - pri := &PerRankInfo{ - Name: mtp.p.Name, - SnId: mtp.p.SnId, - RankId: mtp.rank, - Grade: mtp.grade, - } - this.finalPerRank[sortId] = append(this.finalPerRank[sortId], pri) - this.sendPromotionInfo(mtp, sortId, TaoTai, true, false) //淘汰 - } + updateRobotGrades := func() { + round := playerCtx.round + if promotionNum == 1 { // 决赛 + round = playerCtx.round - 1 + } + arr := playerCtx.tm.robotGrades[int(round)] + + // 修改陪真人玩的机器人积分 + if matchRobotGrades != nil { + logger.Logger.Trace("和真人比赛的机器人使用真实积分: ", matchRobotGrades) + for _, gradeInfo := range arr { + if grade, ok := matchRobotGrades[gradeInfo.copySnid]; ok { + gradeInfo.grade = grade } + } + } + + findMe := false + for _, v := range arr { + if v.copySnid == 0 { // 真人 + v.grade = playerCtx.grade + findMe = true + break + } + } + if !findMe { + gradeInfo := &TmGradeInfo{ + grade: playerCtx.grade, + copySnid: 0, + } + arr = append(arr, gradeInfo) // 添加了真人数据 + } + + sort.Slice(arr, func(i, j int) bool { + return arr[i].grade > arr[j].grade + }) + + 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) + } + + // 获取排名 + index := int32(0) //晋级淘汰 + for i, v := range arr { + if playerCtx.grade >= v.grade { + index = int32(i) + 1 + break + } + } + + if promotionNum != 1 { + arr = append(arr[:promotionNum]) + playerCtx.tm.robotGrades[int(round)] = arr + } + + if index == 0 { // 是最后一名 + index = gmd.MatchPromotion[round] + } + playerCtx.rank = index + } + + if promotionNum != 1 { + // 非决赛 + if playerCtx.tm.robotGrades == nil || playerCtx.tm.robotGrades[int(playerCtx.round)] == nil { + playerCtx.tm.CreateRobotGrades(int(playerCtx.round)) + } + + if playerCtx.tm.robotGrades != nil && playerCtx.tm.robotGrades[int(playerCtx.round)] != nil { + updateRobotGrades() + if playerCtx.rank <= promotionNum { + // 晋级 + this.sendPromotionInfo(playerCtx, sortId, JinJi, false, false) //晋级 + + // 开始下一轮 + mct := []*PlayerMatchContext{playerCtx} + finals := false + if playerCtx.round == int32(len(gmd.MatchPromotion)-2) { + finals = true + } + timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool { + MatchSceneMgrSingleton.NewRoundStart(playerCtx.tm, mct, finals, playerCtx.round+1) + return true + }), nil, time.Second*7, 1) } else { - // 比赛结束 - // 修改陪真人玩的机器人积分 - robotGrades := mtp.tm.robotGrades[int(mtp.round-1)] - if matchRobotGrades != nil { - logger.Logger.Trace("matchRobotGrades: ", matchRobotGrades) - for snid, grade := range matchRobotGrades { - logger.Logger.Trace("Snid: ", snid, " grade: ", grade) - } - for _, gradeInfo := range robotGrades { - if grade, ok := matchRobotGrades[gradeInfo.copySnid]; ok { - gradeInfo.grade = grade - } + // 淘汰 + this.sendPromotionInfo(playerCtx, sortId, TaoTai, true, false) //淘汰 + } + } + } else { + // 比赛结束 + updateRobotGrades() + outCode := TaoTai + if playerCtx.rank == 1 { + outCode = JinJi + } + this.sendPromotionInfo(playerCtx, sortId, outCode, true, true) //晋级 + logger.Logger.Trace("比赛结束!!! ") + + // 比赛结束 + this.StopMatch(playerCtx.tm.TMId, sortId) + } +} + +// NextRoundStart 下一轮是否开始 +// 关闭机器时使用 +func (this *Tournament) NextRoundStart(sortId int64, playerCtx *PlayerMatchContext) { + logger.Logger.Tracef("NextRoundStart 当前第 %v 轮", playerCtx.round) + info := this.getRoundPlayer(sortId, playerCtx.round) + if info == nil { + return + } + + gmd := playerCtx.tm.gmd + // 需要晋级的人数 + promotionNum1 := int(gmd.MatchPromotion[playerCtx.round-1]) + promotionNum := int(gmd.MatchPromotion[playerCtx.round]) + n := len(info.players) + outNum := promotionNum1 - promotionNum + + if promotionNum != 1 { + // 非决赛淘汰后开始配桌 + // 已经晋级的人数减去一桌之后 剩余人数还能够满足本轮淘汰 + logger.Logger.Tracef("非决赛开始淘汰晋级 等待人数: %v 淘汰人数:%v", n, outNum) + if n-4 >= outNum { + // 提前晋级的开始凑桌 + MatchContextSlice(info.players).Sort(false) + // 晋级 + var ps []*PlayerMatchContext + finals := false // 是否最后一局 + meIn := false // 自己是否晋级 + for i := 0; i < n-outNum; i++ { + this.sendPromotionInfo(info.players[i], sortId, JinJi, false, false) //晋级 + + v := *info.players[i] + v.rank = this.getRank(sortId, info.players[i].round, info.players[i].p.SnId, false) + ps = append(ps, &v) + logger.Logger.Tracef("凑桌成功:%+v", v) + + if !finals && v.round == int32(len(gmd.MatchPromotion)-2) { + finals = true + } + if v.p.SnId == playerCtx.p.SnId { + meIn = true + } + } + info.players = info.players[len(ps):] + + willOut := false + if promotionNum1 == this.getRoundPlayer(sortId, playerCtx.round-1).num { + // 最后一个人打完了,确定要淘汰的人 + willOut = true + } else { + if !meIn { //自己暂时没晋级 + this.sendPromotionInfo(playerCtx, sortId, DaiDing, false, false) //待定 + } + } + + isOver := false + if willOut { + for _, v := range info.players { + logger.Logger.Tracef("淘汰 %+v", *v) + this.sendPromotionInfo(v, sortId, TaoTai, true, false) //淘汰 + + //真人被淘汰,如果剩下的都是机器人,比赛解散 + if !v.p.IsRob { + isOver = this.stopMatch(playerCtx.tm.TMId, sortId) } } - // 记录真人积分 - for _, gradeinfo := range robotGrades { - if gradeinfo.copySnid == 0 { - gradeinfo.grade = mtp.grade - break - } - } - sort.Slice(robotGrades, func(i, j int) bool { - return robotGrades[i].grade > robotGrades[j].grade - }) - logger.Logger.Trace("robotGrades: ") - for _, info := range robotGrades { - logger.Logger.Trace("Snid: ", info.copySnid, " grade: ", info.grade, " copyLv: ", info.copyLv, " copyRoleId: ", info.copyRoleId) - } - // 获取真人名次 - index := int32(0) //晋级淘汰 - for i, gradeinfo := range robotGrades { - if mtp.grade >= gradeinfo.grade { - index = int32(i) + 1 - break - } - } - if index == 0 { - index = gmd.MatchPromotion[mtp.round-1] //最后一名 - } - mtp.rank = index - if this.finalPerRank[sortId] == nil { - this.finalPerRank[sortId] = []*PerRankInfo{} - } - pri := &PerRankInfo{ - Name: mtp.p.Name, - SnId: mtp.p.SnId, - RankId: mtp.rank, - Grade: mtp.grade, - } - this.finalPerRank[sortId] = append(this.finalPerRank[sortId], pri) //把决赛的玩家记录在排行榜 + } + + if !isOver { + timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool { + MatchSceneMgrSingleton.NewRoundStart(playerCtx.tm, ps, finals, playerCtx.round+1) + return true + }), nil, time.Second*7, 1) + } + } else { + this.sendPromotionInfo(playerCtx, sortId, DaiDing, false, false) //待定 + } + } else { + if len(info.players) == 4 { + MatchContextSlice(info.players).Sort(true) + for _, mc := range info.players { outCode := TaoTai - if mtp.rank == 1 { + if mc.rank == 1 { outCode = JinJi } - this.sendPromotionInfo(mtp, sortId, outCode, true, true) //晋级 - logger.Logger.Trace("比赛结束!!! ") - // 比赛结束 - this.StopMatch(mtp.tm.TMId, sortId) + this.sendPromotionInfo(mc, sortId, outCode, true, true) //晋级 } + logger.Logger.Trace("比赛结束!!! ") + + // 比赛结束 + this.StopMatch(playerCtx.tm.TMId, sortId) } } } -// 下一轮是否开始 -func (this *Tournament) NextRoundStart(sortId int32, mtp *PlayerMatchContext) { - logger.Logger.Tracef("================NextRoundStart==========当前第 %v 轮============", mtp.round) - if _, ok := this.copyPlayers[sortId]; ok { - if mcs, ok1 := this.copyPlayers[sortId][mtp.round]; ok1 { - gmd := mtp.tm.gmd - //需要晋级的人数 - promotionNum1 := gmd.MatchPromotion[mtp.round-1] - promotionNum := gmd.MatchPromotion[mtp.round] - //通知晋级信息:0.晋级等待匹配 1.失败退出 2.等待判断是否晋级 - pack := &tournament.SCPromotionInfo{} - if promotionNum != 1 { - n := int32(len(mcs)) - //非决赛淘汰后开始配桌 - logger.Logger.Trace("非决赛开始淘汰晋级") - outNum := promotionNum1 - promotionNum - //已经晋级的人数减去一桌之后 剩余人数还能够满足本轮淘汰 - logger.Logger.Trace("n: ", n, " outNum: ", outNum) - if n-4 >= outNum { - //提前晋级的开始凑桌 - MatchContextSlice(mcs).Sort(false) - //挑选出晋级的玩家 - meIn := false //自己晋级 - for k, v := range mcs { - if mtp.p.SnId == v.p.SnId { - meIn = true - } - logger.Logger.Trace("排序之后=========== ", k, v.p.SnId, v.round, v.seq, v.grade) - } - mct := []*PlayerMatchContext{} - finals := false - for i := 0; i < len(mcs)-int(outNum); i++ { - var mc PlayerMatchContext - mc = *mcs[i] - this.sendPromotionInfo(mcs[i], sortId, JinJi, false, false) //晋级 - mc.rank = mcs[i].rank - mct = append(mct, &mc) - logger.Logger.Trace("======凑桌==========mc=================", mc) - if !finals && mc.round == int32(len(gmd.MatchPromotion)-2) { - finals = true - } - } - mcs = mcs[len(mct):] - this.copyPlayers[sortId][mtp.round] = this.copyPlayers[sortId][mtp.round][len(mct):] - willOut := false - if promotionNum1 == this.roundOverPlayerNum[sortId][mtp.round-1] { - //最后一个人打完了,确定要淘汰的人 - willOut = true - } else { - if !meIn { //自己暂时没晋级 - this.sendPromotionInfo(mtp, sortId, DaiDing, false, false) //待定 - } - } - if this.finalPerRank[sortId] == nil { - this.finalPerRank[sortId] = []*PerRankInfo{} - } - isOver := false - for k, v := range this.copyPlayers[sortId][mtp.round] { - logger.Logger.Trace("凑桌之后剩余===2======== ", k, v.p.SnId, v.round, v.seq, v.grade) - if willOut { - this.sendPromotionInfo(v, sortId, TaoTai, true, false) //淘汰 - //把淘汰的玩家记录在排行榜 - pri := &PerRankInfo{ - Name: v.p.Name, - SnId: v.p.SnId, - RankId: pack.RankId, - Grade: v.grade, - } - this.finalPerRank[sortId] = append(this.finalPerRank[sortId], pri) - //真人被淘汰,如果剩下的都是机器人,比赛解散 - if !v.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 { - isOver = true - logger.Logger.Trace("没有真人比赛解散") - this.StopMatch(mtp.tm.TMId, sortId) - } - } - } - } - } - if !isOver { - timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool { - MatchSceneMgrSingleton.NewRoundStart(mtp.tm, mct, finals, mtp.round+1) - return true - }), nil, time.Second*7, 1) - } - } else { - this.sendPromotionInfo(mtp, sortId, DaiDing, false, false) //待定 - } - } else { - if len(mcs) == 4 { - MatchContextSlice(mcs).Sort(true) - if this.finalPerRank[sortId] == nil { - this.finalPerRank[sortId] = []*PerRankInfo{} - } - for _, mc := range mcs { - pri := &PerRankInfo{ - Name: mc.p.Name, - SnId: mc.p.SnId, - RankId: mc.rank, - Grade: mc.grade, - } - this.finalPerRank[sortId] = append(this.finalPerRank[sortId], pri) //把决赛的玩家记录在排行榜 - outCode := TaoTai - if mc.rank == 1 { - outCode = JinJi - } - this.sendPromotionInfo(mc, sortId, outCode, true, true) //晋级 - } - logger.Logger.Trace("比赛结束!!! ") - // 比赛结束 - this.StopMatch(mtp.tm.TMId, sortId) - } - } - } - } -} - -const ( - JinJi = 0 // 晋级 - TaoTai = 1 // 淘汰 - DaiDing = 2 // 待定 -) - // 发送晋级信息 // outCode 0晋级 1淘汰 2待定 // isOver 玩家比赛结束 // isFinals 比赛结束 -func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int32, outCode int, isOver, isFinals bool) { - if mc == nil { +func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int64, outCode int, isOver, isFinals bool) { + logger.Logger.Tracef("sendPromotionInfo %+v sortId:%v outCode:%v isOver:%v isFinals:%v", mc, sortId, outCode, isOver, isFinals) + if mc == nil || mc.tm == nil || mc.tm.gmd == nil { return } - rankId := mc.rank - if mc.tm.useRobot == MatchNotUserRobot { // 不使用机器人 - rankId = this.getRank(sortId, mc.round, mc.p.SnId, isFinals) - mc.rank = rankId + + // 淘汰或最后一局,记录排名 + if outCode == TaoTai || isFinals { + pri := &PerRankInfo{ + Name: mc.p.Name, + SnId: mc.p.SnId, + RankId: mc.rank, + Grade: mc.grade, + } + this.addFinalPlayer(sortId, pri) } - //通知晋级信息:0.晋级等待匹配 1.失败退出 2.等待判断是否晋级 - pack := &tournament.SCPromotionInfo{} - pack.RetCode = int32(outCode) - pack.Round = mc.round - pack.RankId = rankId - pack.RoundCoin = 100 //暂时用不到先写死 - pack.Record = mc.record - if mc.tm != nil { - pack.MatchId = mc.tm.TMId + + if !this.IsRobotOn(mc.tm.gmd) { // 不使用机器人 + mc.rank = this.getRank(sortId, mc.round, mc.p.SnId, isFinals) } - if mc.tm != nil && mc.tm.gmd != nil { - pack.MatchPromotion = mc.tm.gmd.GetMatchPromotion() - pack.MatchName = mc.tm.gmd.GetMatchName() - if !mc.p.IsRob && isOver { //真人发奖 - if mc.tm.gmd.Award != nil { - for _, award := range mc.tm.gmd.Award { - if rankId >= award.UpLimit && rankId <= award.DownLimit { //上下限是反的,我也是醉了 - rankAward := &tournament.RankAward{ - Coin: proto.Int64(award.Coin), - Diamond: proto.Int64(award.Diamond), + + // 通知晋级信息:0.晋级等待匹配 1.失败退出 2.等待判断是否晋级 + pack := &tournament.SCPromotionInfo{ + RetCode: int32(outCode), + Round: mc.round, + RankId: mc.rank, + RoundCoin: 100, //暂时用不到先写死 + Record: mc.record, + MatchId: mc.tm.TMId, + MatchPromotion: mc.tm.gmd.GetMatchPromotion(), + MatchName: mc.tm.gmd.GetMatchName(), + } + // 真人发奖 + if !mc.p.IsRob && isOver { + for _, award := range mc.tm.gmd.Award { + if mc.rank >= award.UpLimit && mc.rank <= award.DownLimit { //上下限是反的,我也是醉了 + rankAward := &tournament.RankAward{ + Coin: proto.Int64(award.Coin), + Diamond: proto.Int64(award.Diamond), + } + if award.ItemId != nil { + for _, info := range award.ItemId { + item := &tournament.ItemInfo{ + ItemId: proto.Int32(info.ItemId), + ItemNum: proto.Int32(int32(info.ItemNum)), + Name: proto.String(info.Name), } - if award.ItemId != nil { - for _, info := range award.ItemId { - item := &tournament.ItemInfo{ - ItemId: proto.Int32(info.ItemId), - ItemNum: proto.Int32(int32(info.ItemNum)), - Name: proto.String(info.Name), - } - rankAward.ItemInfo = append(rankAward.ItemInfo, item) - } - } - // test - //rankAward.ItemInfo = append(rankAward.ItemInfo, &tournament.ItemInfo{ - // ItemId: 30003, - // ItemNum: 1, - // Name: "1元话费兑换码", - //}) - // test - pack.RankAward = rankAward + rankAward.ItemInfo = append(rankAward.ItemInfo, item) } } + pack.RankAward = rankAward } } } @@ -974,9 +1126,9 @@ func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int32, case 2: outStr = "待定" } - proto.SetDefaults(pack) - logger.Logger.Trace("sendPromotionInfo: ", outStr, " snid: ", mc.p.SnId, " pack: ", pack) ok := mc.p.SendToClient(int(tournament.TOURNAMENTID_PACKET_TM_SCPromotionInfo), pack) + logger.Logger.Trace("sendPromotionInfo: ", outStr, " snid: ", mc.p.SnId, " pack: ", pack) + if ok && !mc.p.IsRob && isOver { if pack.RankAward != nil { if pack.RankAward.Coin != 0 { //金币 @@ -999,29 +1151,12 @@ func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int32, } } } - if isOver && mc.tm != nil { // 自己比赛结束 - if !mc.p.IsRob { - this.CheckAddMatchSeasonLv(mc) - } + if isOver { // 自己比赛结束 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) - } - } + this.stopMatch(mc.tm.TMId, sortId) } - } } @@ -1038,10 +1173,10 @@ func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int32, // 兑换码奖品 var err error var newMsg *model.Message - res := &webapi_proto.SAGetMatchAwardCode{} + res := &webapiproto.SAGetMatchAwardCode{} task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { // 获取兑换码 - pack := &webapi_proto.ASGetMatchAwardCode{ + pack := &webapiproto.ASGetMatchAwardCode{ Platform: mc.p.Platform, Snid: mc.p.SnId, ItemID: data.GetId(), @@ -1059,7 +1194,7 @@ func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int32, return err } - if res.GetCode() == "" || res.GetTag() != webapi_proto.TagCode_SUCCESS { + if res.GetCode() == "" || res.GetTag() != webapiproto.TagCode_SUCCESS { return nil } @@ -1080,7 +1215,7 @@ func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int32, return nil }), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { defer wg.Done() - if err != nil || res.GetCode() == "" || res.GetTag() != webapi_proto.TagCode_SUCCESS { + if err != nil || res.GetCode() == "" || res.GetTag() != webapiproto.TagCode_SUCCESS { logger.Logger.Errorf("获取兑换码失败 snid:%v itemID:%v res:%v err:%v", mc.p.SnId, data.Id, res, err) return } @@ -1104,224 +1239,106 @@ func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int32, return nil }), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { sendFunc() - })).Start() + }), "sendPromotionInfo").Start() } // 更新段位 -func (this *Tournament) CheckAddMatchSeasonLv(mc *PlayerMatchContext) { - if mc == nil { - return - } - platform := mc.p.Platform - if platform == DefaultPlatform { - return - } - rank := mc.rank - maxPlayerNum := mc.tm.gmd.MatchNumebr - upLine := maxPlayerNum * 33 / 100 - downLine := maxPlayerNum * 67 / 100 - snid := mc.p.SnId - ms := MatchSeasonMgrSington.GetMatchSeason(mc.p.SnId) - msid := MatchSeasonMgrSington.GetMatchSeasonId(platform) - if msid == nil { - MatchSeasonMgrSington.UpdateMatchSeasonId(platform) - } - if ms == nil { - task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { - ret, err := model.QueryMatchSeasonBySnid(platform, snid) - if err != nil { - return nil - } - return ret - }), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { - var ret *model.MatchSeason - dirty := false - seasonId := int32(1) - if msid != nil { - seasonId = msid.SeasonId - } - if data == nil || data.(*model.MatchSeason) == nil { - player := PlayerMgrSington.GetPlayerBySnId(snid) - if player != nil { - ret = model.NewMatchSeason(player.Platform, snid, player.Name, seasonId, 1) - dirty = true - } else { - logger.Logger.Error("CSTMSeasonInfoHandler error: player == nil or msi == nil", snid) - } - } else { - ret = data.(*model.MatchSeason) - if ret.SeasonId < seasonId { //不同赛季段位继承 - num := seasonId - ret.SeasonId - finalLv := ret.Lv - for i := 0; i < int(num); i++ { //继承几次 - if i == int(num)-1 { //上个赛季 - ret.LastLv = finalLv - } - finalLv = MatchSeasonMgrSington.MatchSeasonInherit(finalLv) - } - ret.Lv = finalLv - ret.SeasonId = seasonId - ret.IsAward = false - dirty = true - } - } - ms = MatchSeasonMgrSington.exchangeModel2Cache(ret) - ms.dirty = dirty - MatchSeasonMgrSington.SetMatchSeason(ms) - if rank <= upLine { //加分 - MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, 1, dirty) - } else if rank >= downLine && ms.Lv > 75 { //白银以上才触发减分 - MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, -1, dirty) - } else { - MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, 0, dirty) - } - })).StartByFixExecutor("SnId:" + strconv.Itoa(int(snid))) - } else { - dirty := false - if ms.SeasonId < msid.SeasonId { //不同赛季段位继承 - num := msid.SeasonId - ms.SeasonId - finalLv := ms.Lv - for i := 0; i < int(num); i++ { //继承几次 - if i == int(num)-1 { //上个赛季 - ms.LastLv = finalLv - } - finalLv = MatchSeasonMgrSington.MatchSeasonInherit(finalLv) - } - ms.Lv = finalLv - ms.SeasonId = msid.SeasonId - ms.IsAward = false - ms.UpdateTs = time.Now().Unix() - ms.dirty = true - dirty = true - MatchSeasonMgrSington.SetMatchSeason(ms) - } - if rank <= upLine { //加分 - MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, 1, dirty) - } else if rank >= downLine && ms.Lv > 75 { //白银以上才触发减分 - MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, -1, dirty) - } else { - MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, 0, dirty) - } - } -} - -// 比赛结束 -func (this *Tournament) StopMatch(tmId, sortId int32) { - //房间清理 - 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() - delete(this.matches[tmId], sortId) - } - //数据清理 - delete(this.players, sortId) - delete(this.copyPlayers, sortId) - delete(this.rankPlayers, sortId) - delete(this.roundOverPlayerNum, sortId) - delete(this.finalPerRank, sortId) -} - -func (this *Tournament) getRank(sortId, round, snid int32, isFinals bool) int32 { - if _, ok := this.rankPlayers[sortId]; ok { - if rps, ok1 := this.rankPlayers[sortId][round]; ok1 { - MatchContextSlice(rps).Sort(isFinals) - for _, rp := range rps { - if rp.p.SnId == snid { - return rp.rank - } - } - } - } - return 0 -} - -func (this *Tournament) isOut(sortId, snid int32) bool { - out := false - if this.finalPerRank[sortId] != nil { - for _, info := range this.finalPerRank[sortId] { - if info.SnId == snid { - out = true - } - } - } - return out -} - -func (this *Tournament) GetTm(sortId int32) *TmMatch { - if this.matches != nil { - for _, sortTms := range this.matches { - for id, match := range sortTms { - if id == sortId { - return match - } - } - } - } - return nil -} - -// 玩家比赛结束 更新积分 -func (this *Tournament) UpdateMatchInfo(p *Player, sortId, grade, isWin int32, matchRobotGrades map[int32]int32) { - logger.Logger.Trace("=========== UpdateMatchInfo ==============") - logger.Logger.Tracef("UpdateMatchInfo: sortId:%v, grade:%v, isWin: %v, matchRobotGrades:%v", sortId, grade, isWin, matchRobotGrades) - if _, ok := this.players[sortId]; !ok { - this.players[sortId] = make(map[int32]*PlayerMatchContext) - } - if mtp, ok := this.players[sortId][p.SnId]; ok { - mtp.grade = grade - if this.roundOverPlayerNum[sortId] == nil { - this.roundOverPlayerNum[sortId] = make(map[int32]int32) - } - this.roundOverPlayerNum[sortId][mtp.round]++ - if mtp.record == nil { - mtp.record = make(map[int32]int32) - } - mtp.record[isWin]++ - //轮数增加 - mtp.round++ - mtp.gaming = false - if this.copyPlayers[sortId] == nil { - this.copyPlayers[sortId] = make(map[int32][]*PlayerMatchContext) - } - var mc PlayerMatchContext - mc = *mtp - this.copyPlayers[sortId][mtp.round] = append(this.copyPlayers[sortId][mtp.round], &mc) - if this.rankPlayers[sortId] == nil { - this.rankPlayers[sortId] = make(map[int32][]*PlayerMatchContext) - } - 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.useRobot == MatchUseRobot { // 使用机器人 - this.NextRoundStartSingle(sortId, mtp, matchRobotGrades) - } else { - this.NextRoundStart(sortId, mtp) - } - } -} - -func (this *Tournament) CreatePlayerMatchContext(p *Player, m *TmMatch, seq int) *PlayerMatchContext { - ms := MatchSeasonMgrSington.GetMatchSeason(p.SnId) - var lv int32 - if ms != nil { - lv = ms.Lv - } - roleId := int32(2000001) - if p.Roles != nil { - roleId = p.Roles.ModId - } - - mc := NewMatchContext(p, m, 1000, p.SnId, lv, roleId, seq) - if mc != nil { - if this.players[m.SortId] == nil { - this.players[m.SortId] = make(map[int32]*PlayerMatchContext) - } - this.players[m.SortId][p.SnId] = mc - p.matchCtx = mc - return mc - } - return nil -} +//func (this *Tournament) CheckAddMatchSeasonLv(mc *PlayerMatchContext) { +// if mc == nil { +// return +// } +// platform := mc.p.Platform +// if platform == DefaultPlatform { +// return +// } +// rank := mc.rank +// maxPlayerNum := mc.tm.gmd.MatchNumebr +// upLine := maxPlayerNum * 33 / 100 +// downLine := maxPlayerNum * 67 / 100 +// snid := mc.p.SnId +// ms := MatchSeasonMgrSington.GetMatchSeason(mc.p.SnId) +// msid := MatchSeasonMgrSington.GetMatchSeasonId(platform) +// if msid == nil { +// MatchSeasonMgrSington.UpdateMatchSeasonId(platform) +// } +// if ms == nil { +// task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { +// ret, err := model.QueryMatchSeasonBySnid(platform, snid) +// if err != nil { +// return nil +// } +// return ret +// }), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { +// var ret *model.MatchSeason +// dirty := false +// seasonId := int32(1) +// if msid != nil { +// seasonId = msid.SeasonId +// } +// if data == nil || data.(*model.MatchSeason) == nil { +// player := PlayerMgrSington.GetPlayerBySnId(snid) +// if player != nil { +// ret = model.NewMatchSeason(player.Platform, snid, player.Name, seasonId, 1) +// dirty = true +// } else { +// logger.Logger.Error("CSTMSeasonInfoHandler error: player == nil or msi == nil", snid) +// } +// } else { +// ret = data.(*model.MatchSeason) +// if ret.SeasonId < seasonId { //不同赛季段位继承 +// num := seasonId - ret.SeasonId +// finalLv := ret.Lv +// for i := 0; i < int(num); i++ { //继承几次 +// if i == int(num)-1 { //上个赛季 +// ret.LastLv = finalLv +// } +// finalLv = MatchSeasonMgrSington.MatchSeasonInherit(finalLv) +// } +// ret.Lv = finalLv +// ret.SeasonId = seasonId +// ret.IsAward = false +// dirty = true +// } +// } +// ms = MatchSeasonMgrSington.exchangeModel2Cache(ret) +// ms.dirty = dirty +// MatchSeasonMgrSington.SetMatchSeason(ms) +// if rank <= upLine { //加分 +// MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, 1, dirty) +// } else if rank >= downLine && ms.Lv > 75 { //白银以上才触发减分 +// MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, -1, dirty) +// } else { +// MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, 0, dirty) +// } +// })).StartByFixExecutor("SnId:" + strconv.Itoa(int(snid))) +// } else { +// dirty := false +// if ms.SeasonId < msid.SeasonId { //不同赛季段位继承 +// num := msid.SeasonId - ms.SeasonId +// finalLv := ms.Lv +// for i := 0; i < int(num); i++ { //继承几次 +// if i == int(num)-1 { //上个赛季 +// ms.LastLv = finalLv +// } +// finalLv = MatchSeasonMgrSington.MatchSeasonInherit(finalLv) +// } +// ms.Lv = finalLv +// ms.SeasonId = msid.SeasonId +// ms.IsAward = false +// ms.UpdateTs = time.Now().Unix() +// ms.dirty = true +// dirty = true +// MatchSeasonMgrSington.SetMatchSeason(ms) +// } +// if rank <= upLine { //加分 +// MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, 1, dirty) +// } else if rank >= downLine && ms.Lv > 75 { //白银以上才触发减分 +// MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, -1, dirty) +// } else { +// MatchSeasonMgrSington.UpdateMatchSeasonLv(mc.p, 0, dirty) +// } +// } +//} // GetSCTMInfosPack 发送比赛配置数据 func (this *Tournament) GetSCTMInfosPack(platform, channelName string) *tournament.SCTMInfos { @@ -1399,88 +1416,54 @@ func (this *Tournament) GetSCTMInfosPack(platform, channelName string) *tourname return pack } -func (this *Tournament) ModuleName() string { - return "Tournament" -} - -// 初始化 -func (this *Tournament) Init() { - logger.Logger.Trace("(this *Tournament) Init()") -} - -func (this *Tournament) Update() { - // 使用机器人的情况 - for snid, info := range this.singleSignupPlayers { - if this.playerSignUpTime[snid] != 0 { - matchInfo := this.GetMatchInfo(info.Platform, info.Tmid) - if matchInfo.MatchSwitch == MatchSwitchStart && !this.IsOutTime(matchInfo) && this.IsUseRobot(info.Platform, info.Tmid) { - needTime := this.playerWaitStart[snid] - if time.Now().Unix()-this.playerSignUpTime[snid] > needTime { - delete(this.singleSignupPlayers, snid) - delete(this.playerSignUpTime, snid) - signInfo := &SignInfo{ - signup: make(map[int32]*TmPlayer), - Platform: info.Platform, - MaxCnt: int(matchInfo.MatchNumebr), - } - seq := rand.Intn(int(matchInfo.MatchNumebr)) + 1 - signInfo.signup[snid] = &TmPlayer{SnId: snid, seq: seq} - this.signUpPlayers[info.Platform][info.Tmid] = signInfo - //倒计时结束 开始比赛 - this.Start(info.Platform, info.Tmid) - } - } else { - this.CancelSignUpAll(info.Platform, info.Tmid) - } - } - } -} - -func (this *Tournament) Shutdown() { -} -func init() { - module.RegisteModule(TournamentMgr, time.Second, 0) -} -func (this *Tournament) MakeMatchLog(platform string, tmId, sortId int32) *model.MatchLog { +func (this *Tournament) MakeMatchLog(platform string, tmId int32, sortId int64) *model.MatchLog { gameMatchDate := this.GetMatchInfo(platform, tmId) matchLog := model.NewMatchLog() - players := this.copyPlayers[sortId][1] - for _, player := range players { - if !player.p.IsRob { + _, ok := this.roundPlayers[sortId] + if !ok { + return nil + } + info := this.roundPlayers[sortId][1] + if info == nil { + return nil + } + for _, v := range info.players { + if v == nil || v.p == nil || v.p.IsRob { + continue + } - 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 - } + var coin, diamond int64 + items := make(map[int32]int64) + rankId := int32(-1) + perRankInfo := this.finalPerRank[sortId] + for _, info := range perRankInfo { + if info.SnId == v.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 - } + } + 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.Players = append(matchLog.Players, &model.MatchPlayer{ + SnId: v.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 @@ -1492,6 +1475,9 @@ func (this *Tournament) MakeMatchLog(platform string, tmId, sortId int32) *model } func (this *Tournament) saveMatchLog(matchLog *model.MatchLog) { + if matchLog == nil { + return + } task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { err := model.InsertMatchLogs(matchLog) if err != nil { @@ -1502,3 +1488,54 @@ func (this *Tournament) saveMatchLog(matchLog *model.MatchLog) { }), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { })).StartByFixExecutor("saveMatchLogTask") } + +func (this *Tournament) ModuleName() string { + return "Tournament" +} + +func (this *Tournament) Init() { + logger.Logger.Trace("Tournament Init") +} + +func (this *Tournament) Update() { + // 使用机器人的情况 + for snId, info := range this.singleSignupPlayers { + if info == nil || info.Ts <= 0 { + continue + } + matchInfo := this.GetMatchInfo(info.Platform, info.TmId) + if this.IsMatchOn(matchInfo) && !this.IsOutTime(matchInfo) && this.IsRobotOn(matchInfo) { + needTime := this.playerWaitStart[snId] + if time.Now().Unix()-info.Ts > needTime { + signInfo := &SignInfo{ + signup: make(map[int32]*TmPlayer), + Platform: info.Platform, + MaxCnt: int(matchInfo.MatchNumebr), + } + seq := rand.Intn(int(matchInfo.MatchNumebr)) + 1 + signInfo.signup[snId] = &TmPlayer{SnId: snId, seq: seq} + this.signupPlayers[info.Platform][info.TmId] = signInfo + + //倒计时结束 开始比赛 + this.Start(info.Platform, info.TmId) + } + } else { + this.CancelSignUpAll(info.Platform, info.TmId) + } + } + + // 防止内存泄露 + now := time.Now().Unix() + for _, v := range this.matches { + for _, vv := range v { + if vv != nil && now-vv.StartTime > int64(time.Hour.Seconds()*5) { + for _, p := range vv.TmPlayer { + this.ForceQuit(vv.Platform, p.SnId) + break + } + } + } + } +} + +func (this *Tournament) Shutdown() {} diff --git a/worldsrv/trascate_webapi.go b/worldsrv/trascate_webapi.go index 834d88a..58dad72 100644 --- a/worldsrv/trascate_webapi.go +++ b/worldsrv/trascate_webapi.go @@ -2279,7 +2279,7 @@ func init() { Creator: s.creator, Agentor: s.agentor, ReplayCode: s.replayCode, - Params: s.params, + Params: common.CopySliceInt64ToInt32(s.params), PlayerCnt: int32(len(s.players) - s.robotNum), RobotCnt: int32(s.robotNum), CreateTime: s.createTime.Unix(),