From 848d7485a72e1b6c09ffebcb0dd04f9545639465 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Fri, 1 Nov 2024 14:44:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E6=8A=80=E9=A6=86=E6=8B=9B=E5=8B=9F?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/config.go | 4 +- worldsrv/action_game.go | 76 ++++++++++++++++++++++++++++++++ worldsrv/customroommgr.go | 1 + worldsrv/scene.go | 87 ++++++++++++++++++++----------------- worldsrv/scenemgr.go | 59 +++++++++++++++++++++++++ worldsrv/scenepolicydata.go | 2 + 6 files changed, 188 insertions(+), 41 deletions(-) diff --git a/model/config.go b/model/config.go index cca3281..cf916cc 100644 --- a/model/config.go +++ b/model/config.go @@ -196,8 +196,8 @@ func (cm *ConfigMgr) GetConfig(platform string) *AllConfig { RoomConfig: make(map[int32]*webapi.RoomConfig), RoomTypeMap: make(map[int32][]*webapi.RoomConfig), RoomConfigSystem: make(map[int32]*webapi.RoomConfigSystem), - LotteryUser: make(map[int64]*webapi.UserLottery), - LotteryShows: make(map[int64]*webapi.ShowLottery), + LotteryUser: make(map[int64]*webapi.UserLottery), + LotteryShows: make(map[int64]*webapi.ShowLottery), } cm.platform[platform] = c } diff --git a/worldsrv/action_game.go b/worldsrv/action_game.go index 8f82868..0c8ebf4 100644 --- a/worldsrv/action_game.go +++ b/worldsrv/action_game.go @@ -1467,6 +1467,78 @@ func CSTouchTypeHandler(s *netlib.Session, packetId int, data interface{}, sid i return nil } +func CSRoomRecruitHandler(s *netlib.Session, packetId int, data interface{}, sid int64) error { + logger.Logger.Trace("CSRoomRecruitHandler Process recv ", data) + msg, ok := data.(*gamehall.CSRoomRecruit) + if !ok { + return nil + } + + p := PlayerMgrSington.GetPlayer(sid) + if p == nil { + return nil + } + + scene := SceneMgrSingleton.GetScene(int(msg.GetRoomId())) + if scene == nil || !scene.IsCustom() || scene.creator != p.SnId { + return nil + } + + // 标记招募状态 + scene.IsRecruit = true + scene.RecruitTimes++ + + pack := &gamehall.SCRoomRecruit{ + RoomId: msg.GetRoomId(), + On: 1, + } + p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SCRoomRecruit), pack) + logger.Logger.Tracef("SCRoomRecruit: %v", pack) + return nil +} + +func CSInviteJoinRoomHandler(s *netlib.Session, packetId int, data interface{}, sid int64) error { + logger.Logger.Trace("CSInviteJoinRoomHandler Process recv ", data) + _, ok := data.(*gamehall.CSInviteJoinRoom) + if !ok { + return nil + } + + p := PlayerMgrSington.GetPlayer(sid) + if p == nil { + return nil + } + + pack := &gamehall.SCInviteJoinRoom{} + + scene := SceneMgrSingleton.FindCustomInviteRoom(p) + if scene != nil { + pack.RoomId = int32(scene.sceneId) + pack.IsSystem = scene.creator == 0 + pack.SnId = scene.creator + if scene.creator > 0 { + player := PlayerMgrSington.GetPlayerBySnId(scene.creator) + if player != nil { + pack.Name = player.GetName() + pack.UseRoleId = player.Roles.ModId + } + cfg := PlatformMgrSingleton.GetConfig(p.Platform).RoomConfig[scene.CustomParam.GetRoomConfigId()] + if cfg != nil { + pack.RoomName = cfg.GetName() + } + } else { + cfg := PlatformMgrSingleton.GetConfig(p.Platform).RoomConfig[scene.RoomConfigSystem.GetRoomConfigId()] + if cfg != nil { + pack.RoomName = cfg.GetName() + } + } + } + + p.SendToClient(int(gamehall.GameHallPacketID_PACKET_SCInviteJoinRoom), pack) + logger.Logger.Tracef("SCInviteJoinRoom: %v", pack) + return nil +} + func init() { // 返回房间 common.RegisterHandler(int(gamehall.GameHallPacketID_PACKET_CS_RETURNROOM), &CSReturnRoomHandler{}) @@ -1506,4 +1578,8 @@ func init() { common.Register(int(gamehall.GameHallPacketID_PACKET_CS_GETPRIVATEROOMLIST), &gamehall.CSGetPrivateRoomList{}, CSGetPrivateRoomListHandler) // 保持刷新 common.Register(int(gamehall.GameHallPacketID_PACKET_CSTouchType), &gamehall.CSTouchType{}, CSTouchTypeHandler) + // 设置招募状态 + common.Register(int(gamehall.GameHallPacketID_PACKET_CSRoomRecruit), &gamehall.CSRoomRecruit{}, CSRoomRecruitHandler) + // 推荐房间 + common.Register(int(gamehall.GameHallPacketID_PACKET_CSInviteJoinRoom), &gamehall.CSInviteJoinRoom{}, CSInviteJoinRoomHandler) } diff --git a/worldsrv/customroommgr.go b/worldsrv/customroommgr.go index 84e4c44..0a25ebe 100644 --- a/worldsrv/customroommgr.go +++ b/worldsrv/customroommgr.go @@ -298,6 +298,7 @@ func (c *CustomRoomMgr) UpdateCreate(plt string, configId int32, mustCreate bool Voice: cfg.GetVoice(), }, RoomConfigSystem: cfg, + IsRecruit: true, }) if scene != nil { logger.Logger.Tracef("竞技馆系统房间创建成功 roomId:%v", scene.sceneId) diff --git a/worldsrv/scene.go b/worldsrv/scene.go index 1ac0c7d..2c6971f 100644 --- a/worldsrv/scene.go +++ b/worldsrv/scene.go @@ -30,46 +30,50 @@ type PlayerGameCtx struct { // Scene 场景(房间) type Scene struct { - sceneId int // 场景id - gameId int // 游戏id - gameMode int // 废弃,游戏模式(玩法) - sceneMode int // 房间模式,参考common.SceneMode_XXX - params []int64 // 场景参数 - playerNum int // 房间最大人数 - robotNum int // 机器人数量 - robotLimit int // 最大限制机器人数量 - creator int32 // 创建者账号id - replayCode string // 回放码 - currRound int32 // 当前第几轮 - totalRound int32 // 总共几轮,小于等于0表示无限轮 - cycleTimes int32 // 循环次数,未使用 - deleting bool // 正在删除 - starting bool // 正在开始 - closed bool // 房间已关闭 - force bool // 强制删除 - players map[int32]*Player // 玩家 - audiences map[int32]*Player // 观众 - seats [9]*Player // 座位 - gameSess *GameSession // 所在gameserver - sp ScenePolicy // 场景上的一些业务策略 - createTime time.Time // 创建时间 - lastTime time.Time // 最后活跃时间 - startTime time.Time // 游戏开始时间 - platform *Platform // 限制平台 - groupId int32 // 组id - dbGameFree *serverproto.DB_GameFree // 场次配置 - gameCtx map[int32]*PlayerGameCtx // 进入房间的环境,没有机器人数据 SnId - BaseScore int32 // 游戏底分,优先级,创建参数>本地配置>场次配置 - SceneState int32 // 房间当前状态 - Channel []string // 客户端类型 - *serverproto.CustomParam // 房卡场参数 - *serverproto.MatchParam // 比赛场参数 - *webapiproto.RoomConfigSystem // 系统竞技馆房间 - CloseCtrl bool // 调控开关 - CustomWinSnId int32 // 房卡场胜利者 + sceneId int // 场景id + gameId int // 游戏id + gameMode int // 废弃,游戏模式(玩法) + sceneMode int // 房间模式,参考common.SceneMode_XXX + params []int64 // 场景参数 + playerNum int // 房间最大人数 + robotNum int // 机器人数量 + robotLimit int // 最大限制机器人数量 + creator int32 // 创建者账号id + replayCode string // 回放码 + currRound int32 // 当前第几轮 + totalRound int32 // 总共几轮,小于等于0表示无限轮 + cycleTimes int32 // 循环次数,未使用 + deleting bool // 正在删除 + starting bool // 正在开始 + closed bool // 房间已关闭 + force bool // 强制删除 + players map[int32]*Player // 玩家 + audiences map[int32]*Player // 观众 + seats [9]*Player // 座位 + gameSess *GameSession // 所在gameserver + sp ScenePolicy // 场景上的一些业务策略 + createTime time.Time // 创建时间 + lastTime time.Time // 最后活跃时间 + startTime time.Time // 游戏开始时间 + platform *Platform // 限制平台 + groupId int32 // 组id + dbGameFree *serverproto.DB_GameFree // 场次配置 + gameCtx map[int32]*PlayerGameCtx // 进入房间的环境,没有机器人数据 SnId + BaseScore int32 // 游戏底分,优先级,创建参数>本地配置>场次配置 + SceneState int32 // 房间当前状态 + Channel []string // 客户端类型 + csp *CoinScenePool // 所在场景池 + hp *HundredSceneMgr // 百人场房间池 - csp *CoinScenePool // 所在场景池 - hp *HundredSceneMgr // 百人场房间池 + // 以下为自定义字段 + + CloseCtrl bool // 调控开关 + *serverproto.CustomParam // 房卡场参数 + *serverproto.MatchParam // 比赛场参数 + *webapiproto.RoomConfigSystem // 系统竞技馆房间 + CustomWinSnId int32 // 房卡场胜利者 + IsRecruit bool // 招募中 + RecruitTimes int // 招募次数 } // NewScene 创建房间 @@ -108,6 +112,7 @@ func NewScene(args *CreateSceneParam) *Scene { CustomParam: args.CustomParam, MatchParam: args.MatchParam, RoomConfigSystem: args.RoomConfigSystem, + IsRecruit: args.IsRecruit, } // 最大房间人数 if s.playerNum <= 0 { @@ -648,6 +653,10 @@ func (this *Scene) GetPlayerCnt() int { return len(this.players) } +func (this *Scene) GetMaxPlayerNum() int { + return this.playerNum +} + func (this *Scene) GetAudienceCnt() int { return len(this.audiences) } diff --git a/worldsrv/scenemgr.go b/worldsrv/scenemgr.go index 3699a4e..a546d0b 100644 --- a/worldsrv/scenemgr.go +++ b/worldsrv/scenemgr.go @@ -371,6 +371,64 @@ func (m *SceneMgr) FindRoomList(args *FindRoomParam) []*Scene { return ret } +// FindCustomInviteRoom 竞技馆房间推荐 +func (m *SceneMgr) FindCustomInviteRoom(p *Player) *Scene { + // 无密码,未满人,未开始 + // 玩家房间 > 系统房间 + // 人数 > 招募次数 > 创建时间 + var ret []*Scene + for _, v := range m.scenes { + if v.deleting || v.force || v.closed { + continue + } + if !v.IsCustom() { + continue + } + if v.GetPassword() != "" { + continue + } + if v.IsFull() { + continue + } + if !v.IsRecruit { + continue + } + if len(v.Channel) > 0 && !slices.Contains(v.Channel, p.AppChannel) { + continue + } + ret = append(ret, v) + } + + sort.Slice(ret, func(i, j int) bool { + if ret[i].creator > 0 && ret[j].creator == 0 { + return true + } + if ret[i].creator == 0 && ret[j].creator > 0 { + return false + } + iN, jN := ret[i].GetMaxPlayerNum()-ret[i].GetPlayerCnt(), ret[j].GetMaxPlayerNum()-ret[j].GetPlayerCnt() + if iN > jN { + return true + } + if iN < jN { + return false + } + if ret[i].RecruitTimes > ret[j].RecruitTimes { + return true + } + if ret[i].RecruitTimes < ret[j].RecruitTimes { + return false + } + return ret[i].createTime.Unix() < ret[j].createTime.Unix() + }) + + if len(ret) > 0 { + return ret[0] + } + + return nil +} + type CreateSceneParam struct { CreateId int32 // 创建者id RoomId int // 房间id @@ -387,6 +445,7 @@ type CreateSceneParam struct { *serverproto.CustomParam // 房卡场参数 *serverproto.MatchParam // 比赛场参数 *webapiproto.RoomConfigSystem // 竞技管系统房参数 + IsRecruit bool // 是否招募 } // CreateScene 创建房间 diff --git a/worldsrv/scenepolicydata.go b/worldsrv/scenepolicydata.go index 20886e8..3feba77 100644 --- a/worldsrv/scenepolicydata.go +++ b/worldsrv/scenepolicydata.go @@ -86,6 +86,8 @@ func (spd *ScenePolicyData) OnSceneState(s *Scene, state int) { } LotteryMgrInst.AddCostRoomCard(s.platform.IdStr, s.creator, int64(n)) } + s.IsRecruit = false + s.RecruitTimes = 0 } case common.SceneStateEnd: