You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.6 KiB
Go

package live
import (
"dcg/game"
"dcg/game/logic"
"dcg/game/logic/zhg"
"dcg/game/logic/zhghz"
pbCommon "dcg/game/pb/common"
pbMq "dcg/game/pb/mq"
pbRoom "dcg/game/pb/room"
"dcg/game/svc"
"errors"
"git.noahlan.cn/northlan/ntools-go/logger"
)
var LiveManager *Manager
type (
Manager struct {
gameLogics map[pbRoom.GameType]*logic.LiveGameLogic
}
)
func InitLiveManager(svcCtx *svc.ServiceContext) {
LiveManager = newManager()
// zhg
LiveManager.RegisterLogic(zhg.NewZhgLiveGameLogic().LiveGameLogic)
LiveManager.RegisterLogic(zhghz.NewZhghzLiveGameLogic().LiveGameLogic)
}
func newManager() *Manager {
return &Manager{
gameLogics: make(map[pbRoom.GameType]*logic.LiveGameLogic),
}
}
func (m *Manager) RegisterLogic(h *logic.LiveGameLogic) {
m.gameLogics[h.GameType] = h
}
func (m *Manager) logicByLiveRoomId(roomId int64) (*logic.LiveGameLogic, error) {
gameType, err := game.GameTypeByLiveRoomId(roomId)
if err != nil {
return nil, errors.New("当前直播间未加入游戏房间")
}
if l, ok := m.gameLogics[gameType]; ok {
return l, nil
}
return nil, errors.New("未找到当前直播间支持的游戏逻辑")
}
func (m *Manager) HandleDanmaku(user *pbCommon.PbUser, dm *pbMq.MqDanmaku) {
l, err := m.logicByLiveRoomId(dm.LiveRoomId)
if err != nil {
logger.SLog.Errorf("获取游戏逻辑失败, err:%+v", err)
return
}
l.HandleDanmaku(user, dm)
}
func (m *Manager) HandleGift(roomId int64, user *pbCommon.PbUser, gift *pbMq.MqGift) {
l, err := m.logicByLiveRoomId(roomId)
if err != nil {
logger.SLog.Errorf("获取游戏逻辑失败, err:%+v", err)
return
}
l.HandleGift(roomId, user, gift)
}