package live_logic import ( "dcg/config" "dcg/game/manager" pbCommon "dcg/game/pb/common" pbGameZhghz "dcg/game/pb/game/zhghz" pbMq "dcg/game/pb/mq" pbRoom "dcg/game/pb/room" "dcg/pkg/cmd" "fmt" "strconv" ) type ( ZhghzGameLogic struct { *LiveGameLogic // giftLogics 礼物处理 platform-cmd:logic giftLogics map[string]GiftLogic } ) func NewZhghzLiveGameLogic() *ZhghzGameLogic { resp := &ZhghzGameLogic{ LiveGameLogic: NewLiveGameLogic(pbRoom.GameType_ZHGHZ, cmd.NewCMDParser(false, config.Config.Game.Zhghz.Commands...)), giftLogics: make(map[string]GiftLogic), } resp.RegisterCMDHandler(resp.handleJoinGame, "j", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8") resp.RegisterCMDHandler(resp.handleMove, "m1", "m2", "m3", "m4") resp.RegisterCMDHandler(resp.handleShoot, "f") resp.RegisterCMDHandler(resp.handleWai, "w", "我在哪") // gift | game.chargeShield | game.giftShoot resp.RegisterGiftHandler(resp.handleGift) return resp } func (h *ZhghzGameLogic) handleJoinGame(roomId int64, cmd string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } var team int32 if len(cmd) >= 2 { v, _ := strconv.Atoi(string(cmd[1])) team = int32(v) } room.Broadcast("game.join", &pbGameZhghz.JoinGame{ User: user, Team: team, }) } func (h *ZhghzGameLogic) handleMove(roomId int64, cmd string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } if len(cmd) < 2 { return } v, _ := strconv.Atoi(string(cmd[1])) room.Broadcast("game.move", &pbGameZhghz.Move{ User: user, Direction: int32(v), }) } func (h *ZhghzGameLogic) handleShoot(roomId int64, _ string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } room.Broadcast("game.shoot", &pbGameZhghz.Shoot{ User: user, }) } func (h *ZhghzGameLogic) handleWai(roomId int64, _ string, user *pbCommon.PbUser) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } room.Broadcast("game.wai", &pbGameZhghz.Where{User: user}) } func (h *ZhghzGameLogic) handleGiftLogic(cmd string, roomId int64, user *pbCommon.PbUser, gift *pbMq.MqGift) bool { if gl, ok := h.giftLogics[cmd]; ok { for _, id := range gl.GiftIds { if gift.GiftId == id { gl.Fn(roomId, user, gift) return true } } return true } else { return false } } func (h *ZhghzGameLogic) handleGift(roomId int64, user *pbCommon.PbUser, gift *pbMq.MqGift) { room, err := manager.GameManager.RoomByLiveRoomId(roomId) if err != nil { return } // bilibili { logicKey := fmt.Sprintf("%s-game.chargeShield", gift.Platform) if ok := h.handleGiftLogic(logicKey, roomId, user, gift); !ok { // 1 辣条 | 30607 小心心 > 魔法护盾 h.giftLogics[logicKey] = GiftLogic{ GiftIds: []int64{1, 30607}, Fn: func(roomId int64, user *pbCommon.PbUser, gift *pbMq.MqGift) { room.Broadcast("game.chargeShield", &pbGameZhghz.ChargeShield{ User: user, Points: int32(gift.Num * 1), }) }, } } logicKey = fmt.Sprintf("%s-game.giftShoot", gift.Platform) if ok := h.handleGiftLogic(logicKey, roomId, user, gift); !ok { // 31036 小花花 | 31039 牛哇牛哇 > 魔法飞弹 h.giftLogics[logicKey] = GiftLogic{ GiftIds: []int64{31036, 31039}, Fn: func(roomId int64, user *pbCommon.PbUser, gift *pbMq.MqGift) { room.Broadcast("game.giftShoot", &pbGameZhghz.ChargeShield{ User: user, Points: int32(gift.Num * 1), }) }, } } } }