package zhg import ( "dcg/config" "dcg/game/logic" pbCommon "dcg/game/pb/common" pbGameZhg "dcg/game/pb/game/zhg" pbMq "dcg/game/pb/mq" pbRoom "dcg/game/pb/room" "dcg/pkg/cmd" ) type ZhgGameLogic struct { *logic.LiveGameLogic } func NewZhgLiveGameLogic() *ZhgGameLogic { resp := &ZhgGameLogic{ LiveGameLogic: logic.NewLiveGameLogic(pbRoom.GameType_ZHG, cmd.NewCMDParser(config.Config.Game.Zhg.Commands)), } resp.RegisterCMDHandler(resp.handleJoinGame, "j", "加入", "加入游戏") resp.RegisterCMDHandler(resp.handleOutbreak, "s") 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 } func (h *ZhgGameLogic) handleJoinGame(roomId int64, _ string, user *pbCommon.PbUser) { room, err := logic.GameLogic.RoomManager.RoomByLiveRoomId(roomId) if err != nil { return } room.PushToLiveRoom(roomId, "game.join", &pbGameZhg.JoinGame{User: user}) } func (h *ZhgGameLogic) handleOutbreak(roomId int64, _ string, user *pbCommon.PbUser) { room, err := logic.GameLogic.RoomManager.RoomByLiveRoomId(roomId) if err != nil { return } room.PushToLiveRoom(roomId, "game.outbreak", &pbGameZhg.Outbreak{User: user}) } func (h *ZhgGameLogic) handleCreateUnit(roomId int64, cmd string, user *pbCommon.PbUser) { if len(cmd) < 2 { return } unit := cmd[1] room, err := logic.GameLogic.RoomManager.RoomByLiveRoomId(roomId) if err != nil { return } room.PushToLiveRoom(roomId, "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 := logic.GameLogic.RoomManager.RoomByLiveRoomId(roomId) if err != nil { return } room.PushToLiveRoom(roomId, "game.move", &pbGameZhg.Move{ User: user, Line: string(line), }) } func (h *ZhgGameLogic) handleWai(roomId int64, _ string, user *pbCommon.PbUser) { room, err := logic.GameLogic.RoomManager.RoomByLiveRoomId(roomId) if err != nil { return } room.PushToLiveRoom(roomId, "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 := logic.GameLogic.RoomManager.RoomByLiveRoomId(roomId) if err != nil { return } room.PushToLiveRoom(roomId, "game.mode", &pbGameZhg.BuildingMode{ User: user, Mode: string(line), }) } func (h *ZhgGameLogic) handleGift(roomId int64, user *pbCommon.PbUser, gift *pbMq.MqGift) { // TODO live.gift 已经发出,这里暂时不需要 }