package main import "mongo.games.com/game/protocol/webapi" // ScenePolicyPool 根据不同的房间模式,选择不同的房间业务策略 var ScenePolicyPool = make(map[int]map[int]ScenePolicy) type ScenePolicy interface { // OnStart 场景开启事件 OnStart(s *Scene) // OnStop 场景关闭事件 OnStop(s *Scene) // OnTick 场景心跳事件 OnTick(s *Scene) // OnPlayerEnter 玩家进入事件 OnPlayerEnter(s *Scene, p *Player) // OnPlayerLeave 玩家离开事件 OnPlayerLeave(s *Scene, p *Player) // OnShutdown 系统维护关闭事件 OnShutdown(s *Scene) // OnSceneState 房间状态变更 OnSceneState(s *Scene, state int) // OnGameState 游戏状态变更 OnGameState(s *Scene, state int) // CanEnter 能否进入 CanEnter(s *Scene, p *Player) int // GetBetState 获取下注状态 GetBetState() int32 // GetPlayerNum 获取玩家数量 GetPlayerNum() int // GetBaseScore 获取底分 GetBaseScore() int // CostEnough 房费是否足够 // costType 付费方式 // playerNum 玩家数量 // roomConfig 房间配置 CostEnough(costType, playerNum int, roomConfig *webapi.RoomConfig, p *Player) bool // CostPayment 房费支付 CostPayment(s *Scene, p *Player) bool } func GetScenePolicy(gameId, mode int) ScenePolicy { if g, exist := ScenePolicyPool[gameId]; exist { if p, exist := g[mode]; exist { return p } } return nil } func RegisterScenePolicy(gameId, mode int, sp ScenePolicy) { pool := ScenePolicyPool[gameId] if pool == nil { pool = make(map[int]ScenePolicy) ScenePolicyPool[gameId] = pool } if pool != nil { pool[mode] = sp } }