feat: 添加游戏模式:指挥官-莽!
parent
38956fbc72
commit
1b06af241c
@ -0,0 +1,40 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
// Zhgmang 指挥官-莽
|
||||||
|
type (
|
||||||
|
Zhgmang struct {
|
||||||
|
GiftEffect struct {
|
||||||
|
Free []int64 // 免费礼物
|
||||||
|
ClearScreen []int64 // 清屏礼物
|
||||||
|
RandomAddon []int64 // 随机加成礼物
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ZhgmangGiftType int32
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ZhgmangGiftUnknown ZhgmangGiftType = iota
|
||||||
|
ZhgmangGiftFree
|
||||||
|
ZhgmangGiftClearScreen
|
||||||
|
ZhgmangGiftRandomAddon
|
||||||
|
)
|
||||||
|
|
||||||
|
func (z Zhgmang) ParseGiftType(id int64) ZhgmangGiftType {
|
||||||
|
if z.isContains(id, z.GiftEffect.Free) {
|
||||||
|
return ZhgmangGiftFree
|
||||||
|
} else if z.isContains(id, z.GiftEffect.ClearScreen) {
|
||||||
|
return ZhgmangGiftClearScreen
|
||||||
|
} else if z.isContains(id, z.GiftEffect.RandomAddon) {
|
||||||
|
return ZhgmangGiftRandomAddon
|
||||||
|
}
|
||||||
|
return ZhgmangGiftUnknown
|
||||||
|
}
|
||||||
|
|
||||||
|
func (z Zhgmang) isContains(id int64, arr []int64) bool {
|
||||||
|
for _, s := range arr {
|
||||||
|
if s == id {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
@ -0,0 +1,278 @@
|
|||||||
|
package live_logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dcg/app/user_center/usercenter"
|
||||||
|
"dcg/config"
|
||||||
|
"dcg/game/manager"
|
||||||
|
"dcg/game/pb"
|
||||||
|
pbCommon "dcg/game/pb/common"
|
||||||
|
pbGameZhgMang "dcg/game/pb/game/zhgmang"
|
||||||
|
pbMq "dcg/game/pb/mq"
|
||||||
|
pbRoom "dcg/game/pb/room"
|
||||||
|
"dcg/game/svc"
|
||||||
|
"dcg/pkg/cmd"
|
||||||
|
"git.noahlan.cn/northlan/ntools-go/logger"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ZhgmangGameLogic struct {
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewZhgmangLiveGameLogic(svcCtx *svc.ServiceContext) *ZhgmangGameLogic {
|
||||||
|
return &ZhgmangGameLogic{
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ZhgmangGameLogic) WithGameType() LogicOption {
|
||||||
|
return WithGameType(pbRoom.GameType_name[int32(pbRoom.GameType_ZHGMang)])
|
||||||
|
}
|
||||||
|
|
||||||
|
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{"我在哪"},
|
||||||
|
ContentMaxLen: 0,
|
||||||
|
}, {
|
||||||
|
Prefix: "g",
|
||||||
|
Alias: []string{"苟"},
|
||||||
|
ContentMaxLen: 0,
|
||||||
|
}, {
|
||||||
|
Prefix: "m",
|
||||||
|
Alias: []string{"莽"},
|
||||||
|
ContentMaxLen: 0,
|
||||||
|
}, {
|
||||||
|
Prefix: "l",
|
||||||
|
Alias: []string{"升级"},
|
||||||
|
ContentMaxLen: 0,
|
||||||
|
}, {
|
||||||
|
Prefix: "n",
|
||||||
|
ContentMaxLen: 8,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pattern = append(pattern, p...)
|
||||||
|
cmdParser := cmd.NewCMDParser(pattern...)
|
||||||
|
cmdParser.SetDistinct(false)
|
||||||
|
|
||||||
|
return WithCmdParser(cmdParser)
|
||||||
|
}
|
||||||
|
|
||||||
|
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.handleLevelUp, "l")
|
||||||
|
logic.RegisterCMDHandler(h.handleMockGift, "n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ZhgmangGameLogic) WithGiftHandler() LogicOption {
|
||||||
|
return WithGiftHandler(func(next GiftHandlerFunc) GiftHandlerFunc {
|
||||||
|
return func(liveRoom *LiveRoom, user *pbCommon.PbUser, gift *pbMq.MqGift) {
|
||||||
|
h.handleGift(liveRoom, user, gift)
|
||||||
|
next(liveRoom, user, gift)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ZhgmangGameLogic) handleJoinGame(liveRoom *LiveRoom, _ string, _ []rune, user *pbCommon.PbUser) {
|
||||||
|
room, err := manager.GameManager.RoomByLiveRoom(liveRoom.RoomId, liveRoom.Platform)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
details, err := h.svcCtx.UserCenterRpc.GetUserDetails(h.svcCtx.Ctx, &usercenter.UserIdReq{
|
||||||
|
UserId: user.UserId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := &pbGameZhgMang.JoinGame{
|
||||||
|
User: user,
|
||||||
|
NobilityLevel: details.NobilityLevel,
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.SLog.Debugf("用户 [%s] 加入游戏", user.Username)
|
||||||
|
room.Broadcast(pb.PushZhgmangJoinGame, resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ZhgmangGameLogic) handleAddUnit(liveRoom *LiveRoom, _ string, content []rune, user *pbCommon.PbUser) {
|
||||||
|
room, err := manager.GameManager.RoomByLiveRoom(liveRoom.RoomId, liveRoom.Platform)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(content) < 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var card int32
|
||||||
|
if len(content) > 0 {
|
||||||
|
t, err := strconv.ParseInt(string(content[0]), 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) {
|
||||||
|
room, err := manager.GameManager.RoomByLiveRoom(liveRoom.RoomId, liveRoom.Platform)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.SLog.Debugf("用户 [%s] 我在哪", user.Username)
|
||||||
|
|
||||||
|
room.Broadcast(pb.PushZhgmangWai, &pbGameZhgMang.Wai{User: user})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ZhgmangGameLogic) handleLevelUp(liveRoom *LiveRoom, _ string, _ []rune, user *pbCommon.PbUser) {
|
||||||
|
room, err := manager.GameManager.RoomByLiveRoom(liveRoom.RoomId, liveRoom.Platform)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.SLog.Debugf("用户 [%s] 基地升级", user.Username)
|
||||||
|
|
||||||
|
room.Broadcast(pb.PushZhgmangLevelUp, &pbGameZhgMang.LevelUp{
|
||||||
|
User: user,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ZhgmangGameLogic) handleMockGift(liveRoom *LiveRoom, _ string, content []rune, user *pbCommon.PbUser) {
|
||||||
|
var err error
|
||||||
|
room, err := manager.GameManager.RoomByLiveRoom(liveRoom.RoomId, liveRoom.Platform)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var isAdminUser bool
|
||||||
|
for _, i := range h.svcCtx.Config.Game.AdminUserId {
|
||||||
|
if user.UserId == i {
|
||||||
|
isAdminUser = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !isAdminUser {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(content) < 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
contentStr := string(content)
|
||||||
|
spaceIdx := strings.Index(contentStr, " ")
|
||||||
|
if spaceIdx < 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
giftType := contentStr[:spaceIdx]
|
||||||
|
var count int64 = 1
|
||||||
|
if count, err = strconv.ParseInt(contentStr[spaceIdx+1:], 10, 32); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if count <= 0 {
|
||||||
|
count = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.SLog.Debugf("用户 [%s] gift [%s] count [%d]", user.Username, giftType, count)
|
||||||
|
// 禁止 c w l n j
|
||||||
|
switch giftType {
|
||||||
|
case "tt":
|
||||||
|
h.goldSpeedUp(room, user, float64(count)*0.1)
|
||||||
|
case "qp":
|
||||||
|
h.clearScreen(room, user)
|
||||||
|
case "rd":
|
||||||
|
h.randomAddon(room, user)
|
||||||
|
case "hb":
|
||||||
|
h.redPackAddon(room, user)
|
||||||
|
default:
|
||||||
|
h.goldSpeedUp(room, user, float64(count))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*/
|
||||||
|
func (h *ZhgmangGameLogic) handleGift(liveRoom *LiveRoom, user *pbCommon.PbUser, gift *pbMq.MqGift) {
|
||||||
|
room, err := manager.GameManager.RoomByLiveRoom(liveRoom.RoomId, liveRoom.Platform)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := h.svcCtx.Config.Game.Zhgmang
|
||||||
|
cfgGiftType := cfg.ParseGiftType(gift.GiftId)
|
||||||
|
switch gift.Type {
|
||||||
|
case pbMq.MqGift_NORMAL:
|
||||||
|
switch cfgGiftType {
|
||||||
|
case config.ZhgmangGiftFree:
|
||||||
|
h.goldSpeedUp(room, user, float64(gift.GiftNum)*0.1)
|
||||||
|
case config.ZhgmangGiftClearScreen:
|
||||||
|
for i := 0; i < int(gift.GiftNum); i++ {
|
||||||
|
h.clearScreen(room, user)
|
||||||
|
}
|
||||||
|
case config.ZhgmangGiftRandomAddon:
|
||||||
|
for i := 0; i < int(gift.GiftNum); i++ {
|
||||||
|
h.randomAddon(room, user)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
h.goldSpeedUp(room, user, float64(gift.GiftNum*gift.Price)*0.01)
|
||||||
|
}
|
||||||
|
case pbMq.MqGift_PACK:
|
||||||
|
if cfgGiftType == config.ZhgmangGiftClearScreen {
|
||||||
|
for i := 0; i < int(gift.GiftNum); i++ {
|
||||||
|
h.clearScreen(room, user)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
h.goldSpeedUp(room, user, float64(gift.GiftNum)*0.01)
|
||||||
|
}
|
||||||
|
case pbMq.MqGift_RED_PACK:
|
||||||
|
// 红包
|
||||||
|
h.redPackAddon(room, user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ZhgmangGameLogic) goldSpeedUp(room *manager.Room, user *pbCommon.PbUser, battery float64) {
|
||||||
|
room.Broadcast(pb.PushZhgmangGoldSpeedUp, &pbGameZhgMang.SpeedUp{
|
||||||
|
User: user,
|
||||||
|
Second: int32(battery * 10),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ZhgmangGameLogic) clearScreen(room *manager.Room, user *pbCommon.PbUser) {
|
||||||
|
room.Broadcast(pb.PushZhgmangClearScreen, &pbGameZhgMang.ClearScreen{
|
||||||
|
User: user,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ZhgmangGameLogic) randomAddon(room *manager.Room, user *pbCommon.PbUser) {
|
||||||
|
room.Broadcast(pb.PushZhgmangRandomAddon, &pbGameZhgMang.RandomAddon{
|
||||||
|
User: user,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ZhgmangGameLogic) redPackAddon(room *manager.Room, user *pbCommon.PbUser) {
|
||||||
|
room.Broadcast(pb.PushZhgmangRedPackAddon, &pbGameZhgMang.RedPackAddon{
|
||||||
|
User: user,
|
||||||
|
})
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,13 @@
|
|||||||
|
2022-10-03 13:51:10.687+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:弹幕对应直播间未加入游戏房间
|
||||||
|
2022-10-03 13:53:46.344+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:弹幕对应直播间未加入游戏房间
|
||||||
|
2022-10-03 13:54:34.097+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:弹幕对应直播间未加入游戏房间
|
||||||
|
2022-10-03 13:54:37.909+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:弹幕对应直播间未加入游戏房间
|
||||||
|
2022-10-03 13:54:43.738+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:弹幕对应直播间未加入游戏房间
|
||||||
|
2022-10-03 13:55:33.699+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:弹幕对应直播间未加入游戏房间
|
||||||
|
2022-10-03 13:55:34.421+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:弹幕对应直播间未加入游戏房间
|
||||||
|
2022-10-03 13:55:51.325+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:弹幕对应直播间未加入游戏房间
|
||||||
|
2022-10-03 13:55:58.791+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:弹幕对应直播间未加入游戏房间
|
||||||
|
2022-10-03 13:57:39.824+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:未找到当前直播间支持的游戏逻辑
|
||||||
|
2022-10-03 13:57:43.134+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:未找到当前直播间支持的游戏逻辑
|
||||||
|
2022-10-03 13:58:02.000+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:未找到当前直播间支持的游戏逻辑
|
||||||
|
2022-10-03 13:59:32.995+08 error E:/Projects/dm-game/dcg/game/live_logic/manager.go:104 获取游戏逻辑失败, err:弹幕对应直播间未加入游戏房间
|
Loading…
Reference in New Issue