package live_logic import ( "dcg/config" "dcg/game/manager" pbCommon "dcg/game/pb/common" pbGameZhgzd "dcg/game/pb/game/zhgzd" pbMq "dcg/game/pb/mq" pbRoom "dcg/game/pb/room" "dcg/game/svc" "dcg/pkg/cmd" "math/rand" "time" ) type ZhgzdGameLogic struct { svcCtx *svc.ServiceContext *LiveGameLogic } func NewZhgzdLiveGameLogic(svcCtx *svc.ServiceContext) *LiveGameLogic { resp := &ZhgzdGameLogic{ svcCtx: svcCtx, LiveGameLogic: NewLiveGameLogic(pbRoom.GameType_ZHGZD, cmd.NewCMDParser(false, config.Config.Game.Zhgzd.Commands...)), } resp.RegisterCMDHandler(resp.handleJoinGame, "j", "加入", "加入游戏") resp.RegisterCMDHandler(resp.handleDispatch, "s1", "s2", "s3", "s4") resp.RegisterCMDHandler(resp.handleChangeUnit, "c1", "c2", "c3", "c4") resp.RegisterCMDHandler(resp.handleOutbreak, "s") resp.RegisterCMDHandler(resp.handlePosition, "p0", "p1", "p2", "p3", "p4", "p5") resp.RegisterCMDHandler(resp.handleWhere, "w", "我在哪") resp.RegisterCMDHandler(resp.handleMode, "r1", "r2", "r3", "r4") // gift resp.RegisterGiftHandler(resp.handleGift) return resp.LiveGameLogic } func (h *ZhgzdGameLogic) handleJoinGame(roomId int64, _ string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } room.Broadcast("game.join", &pbGameZhgzd.JoinGame{User: user}) } func (h *ZhgzdGameLogic) handleDispatch(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 } cmdType := string(cmdRune[0]) unitType := string(cmdRune[1]) cfg := config.Config.Game.Zhgzd unitId := cfg.CommandUnitDict[unitType] count := cfg.DispatchCountDict[unitType] var costSp int32 if costCfg, ok := cfg.CommandCostDict[cmdType]; ok { costSp = costCfg.Units[unitType] } room.Broadcast("game.unit.dispatch", &pbGameZhgzd.DispatchUnit{ User: user, CostSp: costSp, Id: unitId, Count: count, }) } func (h *ZhgzdGameLogic) handleChangeUnit(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 } cmdType := string(cmdRune[0]) unitType := string(cmdRune[1]) cfg := config.Config.Game.Zhgzd unitId := cfg.CommandUnitDict[unitType] var costSp int32 if costCfg, ok := cfg.CommandCostDict[cmdType]; ok { costSp = costCfg.Common } room.Broadcast("game.unit.change", &pbGameZhgzd.ChangeUnit{ User: user, CostSp: costSp, Id: unitId, }) } func (h *ZhgzdGameLogic) handleOutbreak(roomId int64, cmd string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } cmdRune := []rune(cmd) if len(cmdRune) < 1 { return } cmdType := string(cmdRune[0]) cfg := config.Config.Game.Zhgzd var costSp int32 if costCfg, ok := cfg.CommandCostDict[cmdType]; ok { costSp = costCfg.Common } room.Broadcast("game.outbreak", &pbGameZhgzd.Outbreak{ User: user, CostSp: costSp, }) } func (h *ZhgzdGameLogic) handlePosition(roomId int64, cmd string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } if len(cmd) < 2 { return } pos := cmd[1] room.Broadcast("game.pos", &pbGameZhgzd.Position{ User: user, Position: string(pos), }) } func (h *ZhgzdGameLogic) handleWhere(roomId int64, _ string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } room.Broadcast("game.where", &pbGameZhgzd.Where{User: user}) } func (h *ZhgzdGameLogic) handleMode(roomId int64, cmd string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } cmdRune := []rune(cmd) if len(cmdRune) < 1 { return } cmdType := string(cmdRune[0]) cfg := config.Config.Game.Zhgzd var costSp int32 if costCfg, ok := cfg.CommandCostDict[cmdType]; ok { costSp = costCfg.Common } room.Broadcast("game.mode", &pbGameZhgzd.PlayerMode{ User: user, Mode: string(cmdRune[1]), CostSp: costSp, }) } func (h *ZhgzdGameLogic) handleGift(roomId int64, user *pbCommon.PbUser, gift *pbMq.MqGift) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } cfg := config.Config.Game.Zhgzd.GiftEffect // 战略点回复速度 for _, id := range cfg.StrategicRecover.GiftIds { if gift.GiftId == id { room.Broadcast("game.sp", &pbGameZhgzd.StrategicPoint{ User: user, AddSpeed: cfg.StrategicRecover.Addon, AddSpeedDuration: cfg.StrategicRecover.Duration, }) break } } // 战略点上限 for _, id := range cfg.StrategicMaximal.GiftIds { if gift.GiftId == id { room.Broadcast("game.sp", &pbGameZhgzd.StrategicPoint{ User: user, AddLimit: cfg.StrategicMaximal.Addon, }) break } } // 支援技能 for _, sCfg := range cfg.SupportSkill { for _, id := range sCfg.GiftIds { if gift.GiftId == id && len(sCfg.SkillIds) > 0 { // skill 随机 tmpSkill := sCfg.SkillIds[0] if len(sCfg.SkillIds) > 1 { rand.Seed(time.Now().UnixNano()) tmpSkill = sCfg.SkillIds[rand.Intn(len(sCfg.SkillIds))] } room.Broadcast("game.support", &pbGameZhgzd.SupportSkill{ User: user, Id: tmpSkill, }) break } } } }