package main import "mongo.games.com/game/protocol/webapi" // ScenePolicyPool 根据不同的房间模式,选择不同的房间业务策略 var ScenePolicyPool = make(map[int]map[int]ScenePolicy) type ScenePolicyConfig interface { // GetPlayerNum 获取玩家数量 GetPlayerNum() int // GetBaseScore 获取底分 GetBaseScore() int } type ScenePolicy interface { ScenePolicyConfig // OnStart 场景开启事件 // 游戏开始前 OnStart(s *Scene) // OnStop 场景关闭事件 // 房间关闭前 OnStop(s *Scene) // OnTick 场景心跳事件 OnTick(s *Scene) // OnPlayerEnter 玩家进入事件 // 玩家进入后 OnPlayerEnter(s *Scene, snid int32) // OnPlayerLeave 玩家离开事件 // 玩家离开后 OnPlayerLeave(s *Scene, snid int32) // OnSceneState 房间状态变更 OnSceneState(s *Scene, state int) // CanEnter 能否进入 CanEnter(s *Scene, snid int32) int // CostEnough 房费是否足够 // costType 付费方式 // playerNum 玩家数量 // roomConfig 房间配置 CostEnough(costType, playerNum int, roomConfig *webapi.RoomConfig, snid int32) bool // CostPayment 房费支付 CostPayment(s *Scene, snid int32) bool // GiveCostPayment 房费返还 GiveCostPayment(s *Scene, snid int32) 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 } }