竞技馆招募功能
This commit is contained in:
parent
9f35e077f0
commit
848d7485a7
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 创建房间
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue