package live_logic import ( "dcg/config" "dcg/game/manager" pbCommon "dcg/game/pb/common" pbGameZhg "dcg/game/pb/game/zhg" pbMq "dcg/game/pb/mq" pbRoom "dcg/game/pb/room" "dcg/game/svc" "dcg/pkg/cmd" "strconv" ) type ZhgGameLogic struct { svcCtx *svc.ServiceContext *LiveGameLogic } func NewZhgLiveGameLogic(svcCtx *svc.ServiceContext) *LiveGameLogic { resp := &ZhgGameLogic{ svcCtx: svcCtx, LiveGameLogic: NewLiveGameLogic(pbRoom.GameType_ZHG, cmd.NewCMDParser(false, config.Config.Game.Zhg.Commands...)), } resp.RegisterCMDHandler(resp.handleJoinGame, "j", "加入", "加入游戏") resp.RegisterCMDHandler(resp.handleOutbreak, "s") resp.RegisterCMDHandler(resp.handleOutbreakIntegral, "s1", "s2", "s3", "s4") resp.RegisterCMDHandler(resp.handleWai, "w", "我在哪") resp.RegisterCMDHandler(resp.handleCreateUnit, "c1", "c2", "c3", "c4") resp.RegisterCMDHandler(resp.handleMove, "m1", "m2", "m3") resp.RegisterCMDHandler(resp.handleMode, "r1", "r2", "r3") // gift resp.RegisterGiftHandler(resp.handleGift) return resp.LiveGameLogic } func (h *ZhgGameLogic) handleJoinGame(roomId int64, _ string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } room.Broadcast("game.join", &pbGameZhg.JoinGame{User: user}) } func (h *ZhgGameLogic) handleOutbreak(roomId int64, _ string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } room.Broadcast("game.outbreak", &pbGameZhg.Outbreak{User: user}) } func (h *ZhgGameLogic) handleOutbreakIntegral(roomId int64, cmd string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } cmdRune := []rune(cmd) if len(cmdRune) < 2 { return } var unitTypeInt int unitTypeInt, _ = strconv.Atoi(string(cmdRune[1])) zhgCfg := config.Config.Game.Zhg // 根据unitType计算 消耗积分 costIntegral, ok := zhgCfg.OutbreakCostDict[unitTypeInt] if !ok { costIntegral = zhgCfg.OutbreakBaseCost } room.Broadcast("game.outbreak.integral", &pbGameZhg.OutbreakIntegral{ User: user, UnitType: string(cmdRune[1]), Count: int32(zhgCfg.OutbreakCount), CostIntegral: -costIntegral, }) } func (h *ZhgGameLogic) handleCreateUnit(roomId int64, cmd string, user *pbCommon.PbUser) { if len(cmd) < 2 { return } unit := cmd[1] room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } room.Broadcast("game.createUnit", &pbGameZhg.CreateUnit{ User: user, Unit: string(unit), }) } func (h *ZhgGameLogic) handleMove(roomId int64, cmd string, user *pbCommon.PbUser) { if len(cmd) < 2 { return } line := cmd[1] room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } room.Broadcast("game.move", &pbGameZhg.Move{ User: user, Line: string(line), }) } func (h *ZhgGameLogic) handleWai(roomId int64, _ string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } room.Broadcast("game.wai", &pbGameZhg.Wai{User: user}) } func (h *ZhgGameLogic) handleMode(roomId int64, cmd string, user *pbCommon.PbUser) { if len(cmd) < 2 { return } line := cmd[1] room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } room.Broadcast("game.mode", &pbGameZhg.BuildingMode{ User: user, Mode: string(line), }) } func (h *ZhgGameLogic) handleGift(roomId int64, user *pbCommon.PbUser, gift *pbMq.MqGift) { // TODO 暂时没有特殊礼物需求,留空 }