|
|
|
@ -12,6 +12,7 @@ import (
|
|
|
|
|
"dcg/game/svc"
|
|
|
|
|
"dcg/pkg/cmd"
|
|
|
|
|
"git.noahlan.cn/northlan/ntools-go/logger"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
@ -30,16 +31,18 @@ func (h *ZhgmangGameLogic) WithGameType() LogicOption {
|
|
|
|
|
return WithGameType(pbRoom.GameType_name[int32(pbRoom.GameType_ZHGMang)])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *ZhgmangGameLogic) WithPreDanmakuHandler() LogicOption {
|
|
|
|
|
return func(logic LiveLogic) {
|
|
|
|
|
logic.SetPreDanmakuHandler(h.preDanmakuHandler)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *ZhgmangGameLogic) WithCmdParserLogic(p []cmd.Pattern) LogicOption {
|
|
|
|
|
pattern := []cmd.Pattern{
|
|
|
|
|
{
|
|
|
|
|
Prefix: "j",
|
|
|
|
|
Alias: []string{"加入", "加入游戏"},
|
|
|
|
|
ContentMaxLen: 1,
|
|
|
|
|
}, {
|
|
|
|
|
Prefix: "c",
|
|
|
|
|
Alias: []string{"抽卡"},
|
|
|
|
|
ContentMaxLen: 1,
|
|
|
|
|
}, {
|
|
|
|
|
Prefix: "w",
|
|
|
|
|
Alias: []string{"我在哪"},
|
|
|
|
@ -67,7 +70,6 @@ func (h *ZhgmangGameLogic) WithCmdParserLogic(p []cmd.Pattern) LogicOption {
|
|
|
|
|
func (h *ZhgmangGameLogic) WithCmdHandlers() LogicOption {
|
|
|
|
|
return func(logic LiveLogic) {
|
|
|
|
|
logic.RegisterCMDHandler(h.handleJoinGame, "j")
|
|
|
|
|
logic.RegisterCMDHandler(h.handleAddUnit, "c")
|
|
|
|
|
logic.RegisterCMDHandler(h.handleWai, "w")
|
|
|
|
|
logic.RegisterCMDHandler(h.handleMockGift, "n")
|
|
|
|
|
}
|
|
|
|
@ -82,6 +84,29 @@ func (h *ZhgmangGameLogic) WithGiftHandler() LogicOption {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *ZhgmangGameLogic) preDanmakuHandler(liveRoom *LiveRoom, user *pbCommon.PbUser, dm *pbMq.MqDanmaku) PreDanmakuHandlerResp {
|
|
|
|
|
matching, err := regexp.MatchString("^[1-5]*$", dm.Msg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return PreDanmakuHandlerResp{
|
|
|
|
|
PushDanmaku: true,
|
|
|
|
|
Parsing: true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !matching {
|
|
|
|
|
return PreDanmakuHandlerResp{
|
|
|
|
|
PushDanmaku: true,
|
|
|
|
|
Parsing: true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// add unit
|
|
|
|
|
h.handleAddUnit(liveRoom, dm.Msg, []rune(dm.Msg), user)
|
|
|
|
|
|
|
|
|
|
return PreDanmakuHandlerResp{
|
|
|
|
|
PushDanmaku: false,
|
|
|
|
|
Parsing: false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *ZhgmangGameLogic) handleJoinGame(liveRoom *LiveRoom, _ string, _ []rune, user *pbCommon.PbUser) {
|
|
|
|
|
room, err := manager.GameManager.RoomByLiveRoom(liveRoom.RoomId, liveRoom.Platform)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -114,22 +139,18 @@ func (h *ZhgmangGameLogic) handleAddUnit(liveRoom *LiveRoom, _ string, content [
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, r := range content {
|
|
|
|
|
var card int32
|
|
|
|
|
if len(content) > 0 {
|
|
|
|
|
t, err := strconv.ParseInt(string(content[0]), 10, 32)
|
|
|
|
|
t, err := strconv.ParseInt(string(r), 10, 32)
|
|
|
|
|
if err == nil {
|
|
|
|
|
card = int32(t)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if card > 5 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.SLog.Debugf("用户 [%s] 抽卡 [%d]", user.Username, card)
|
|
|
|
|
room.Broadcast(pb.PushZhgmangAddUnit, &pbGameZhgMang.AddUnit{
|
|
|
|
|
User: user,
|
|
|
|
|
Card: card,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *ZhgmangGameLogic) handleWai(liveRoom *LiveRoom, _ string, _ []rune, user *pbCommon.PbUser) {
|
|
|
|
|