|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package live_logic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"database/sql"
|
|
|
|
|
"dcg/app/user_center/usercenter"
|
|
|
|
|
"dcg/config"
|
|
|
|
|
"dcg/game/manager"
|
|
|
|
@ -16,6 +17,7 @@ import (
|
|
|
|
|
"git.noahlan.cn/northlan/ntools-go/logger"
|
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ZhgGameLogic struct {
|
|
|
|
@ -24,57 +26,60 @@ type ZhgGameLogic struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewZhgLiveGameLogic(svcCtx *svc.ServiceContext) *LiveGameLogic {
|
|
|
|
|
cmdParser := cmd.NewCMDParser(
|
|
|
|
|
cmd.Pattern{
|
|
|
|
|
Prefix: "q",
|
|
|
|
|
Alias: []string{"查询"},
|
|
|
|
|
ContentMaxLen: 0,
|
|
|
|
|
},
|
|
|
|
|
cmd.Pattern{
|
|
|
|
|
Prefix: "j",
|
|
|
|
|
Alias: []string{"加入", "加入游戏"},
|
|
|
|
|
ContentMaxLen: 0,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "c",
|
|
|
|
|
Alias: []string{"换兵"},
|
|
|
|
|
ContentMaxLen: 1,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "w",
|
|
|
|
|
Alias: []string{"我在哪"},
|
|
|
|
|
ContentMaxLen: 0,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "s",
|
|
|
|
|
ContentMaxLen: 4,
|
|
|
|
|
Distinct: sql.NullBool{Bool: false, Valid: true},
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "m",
|
|
|
|
|
ContentMaxLen: 1,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "r",
|
|
|
|
|
ContentMaxLen: 1,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "bq",
|
|
|
|
|
Alias: []string{"购买粮草", "买粮草"},
|
|
|
|
|
ContentMaxLen: 2,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "bw",
|
|
|
|
|
Alias: []string{"购买精英", "买精英"},
|
|
|
|
|
ContentMaxLen: 2,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "zw",
|
|
|
|
|
Alias: []string{"装备精英"},
|
|
|
|
|
ContentMaxLen: 2,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "zz",
|
|
|
|
|
Alias: []string{"使用称号"},
|
|
|
|
|
ContentMaxLen: 2,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "结算",
|
|
|
|
|
Alias: nil,
|
|
|
|
|
ContentMaxLen: 2,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
cmdParser.SetDistinct(true)
|
|
|
|
|
resp := &ZhgGameLogic{
|
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
|
LiveGameLogic: NewLiveGameLogic(pbRoom.GameType_ZHG, cmd.NewCMDParser(
|
|
|
|
|
cmd.Pattern{
|
|
|
|
|
Prefix: "q",
|
|
|
|
|
Alias: []string{"查询"},
|
|
|
|
|
ContentMaxLen: 0,
|
|
|
|
|
},
|
|
|
|
|
cmd.Pattern{
|
|
|
|
|
Prefix: "j",
|
|
|
|
|
Alias: []string{"加入", "加入游戏"},
|
|
|
|
|
ContentMaxLen: 0,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "c",
|
|
|
|
|
Alias: []string{"换兵"},
|
|
|
|
|
ContentMaxLen: 1,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "w",
|
|
|
|
|
Alias: []string{"我在哪"},
|
|
|
|
|
ContentMaxLen: 0,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "s",
|
|
|
|
|
ContentMaxLen: 1,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "m",
|
|
|
|
|
ContentMaxLen: 1,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "r",
|
|
|
|
|
ContentMaxLen: 1,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "bq",
|
|
|
|
|
Alias: []string{"购买粮草", "买粮草"},
|
|
|
|
|
ContentMaxLen: 2,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "bw",
|
|
|
|
|
Alias: []string{"购买精英", "买精英"},
|
|
|
|
|
ContentMaxLen: 2,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "zw",
|
|
|
|
|
Alias: []string{"装备精英"},
|
|
|
|
|
ContentMaxLen: 2,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "zz",
|
|
|
|
|
Alias: []string{"使用称号"},
|
|
|
|
|
ContentMaxLen: 2,
|
|
|
|
|
}, cmd.Pattern{
|
|
|
|
|
Prefix: "结算",
|
|
|
|
|
Alias: nil,
|
|
|
|
|
ContentMaxLen: 2,
|
|
|
|
|
},
|
|
|
|
|
)),
|
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
|
LiveGameLogic: NewLiveGameLogic(pbRoom.GameType_ZHG, cmdParser),
|
|
|
|
|
}
|
|
|
|
|
resp.RegisterCMDHandler(resp.handleQuery, "q")
|
|
|
|
|
resp.RegisterCMDHandler(resp.handleJoinGame, "j")
|
|
|
|
@ -219,26 +224,54 @@ func (h *ZhgGameLogic) handleOutbreakFood(room *manager.Room, content []rune, us
|
|
|
|
|
if len(content) < 1 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
zhgCfg := config.Config.Game.Zhg
|
|
|
|
|
// s1,10s2,10s3,10s4,10 11,0 111,
|
|
|
|
|
contentStr := string(content)
|
|
|
|
|
|
|
|
|
|
var unitTypeStr string
|
|
|
|
|
var count int64
|
|
|
|
|
var err error
|
|
|
|
|
idxSplit := strings.IndexRune(contentStr, ',')
|
|
|
|
|
if idxSplit == -1 {
|
|
|
|
|
// 没有分隔符,判断内容位数?
|
|
|
|
|
unitTypeStr = string(content)
|
|
|
|
|
count = zhgCfg.OutbreakCount
|
|
|
|
|
} else {
|
|
|
|
|
unitTypeStr = string(content[:idxSplit])
|
|
|
|
|
if idxSplit == len(content)-1 {
|
|
|
|
|
count = zhgCfg.OutbreakCount
|
|
|
|
|
} else {
|
|
|
|
|
count, err = strconv.ParseInt(string(content[idxSplit+1:]), 10, 0)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if count > zhgCfg.OutbreakMaxCount {
|
|
|
|
|
count = zhgCfg.OutbreakMaxCount
|
|
|
|
|
}
|
|
|
|
|
if count <= 0 {
|
|
|
|
|
count = zhgCfg.OutbreakCount
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.SLog.Debugf("用户 [%s] 粮草暴兵", user.Username)
|
|
|
|
|
|
|
|
|
|
unitTypeStr := string(content[0])
|
|
|
|
|
unitType, err := strconv.Atoi(unitTypeStr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
zhgCfg := config.Config.Game.Zhg
|
|
|
|
|
var cost int64
|
|
|
|
|
if unitCost, ok := zhgCfg.OutbreakCostDict[unitType]; ok {
|
|
|
|
|
cost = unitCost
|
|
|
|
|
// 四舍五入计算
|
|
|
|
|
cost = decimal.NewFromInt(count).Mul(decimal.NewFromFloat(unitCost)).Round(0).IntPart()
|
|
|
|
|
} else {
|
|
|
|
|
cost = zhgCfg.OutbreakBaseCost
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.SLog.Debugf("用户 [%s] 粮草暴兵", user.Username)
|
|
|
|
|
|
|
|
|
|
room.Broadcast(pb.PushZhgOutbreakFood, &pbGameZhg.OutbreakFood{
|
|
|
|
|
User: user,
|
|
|
|
|
UnitType: unitTypeStr,
|
|
|
|
|
Count: int32(zhgCfg.OutbreakCount),
|
|
|
|
|
Count: int32(count),
|
|
|
|
|
Cost: cost,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|