diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index f1c9e16194..22d7cb33cc 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -106,7 +106,7 @@ func init() { for { select { case <-timer.C: - ctx.SendChain(message.At(uid), message.Text("超时,已自动取消")) + ctx.SendChain(message.At(uid), message.Text(" 超时,已自动取消")) return case r := <-recv: answer = r.Event.Message.String() @@ -122,7 +122,7 @@ func init() { return } - u, money, err := purchaseItem(n, info) + money, err := purchaseItem(n, info) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -138,7 +138,7 @@ func init() { return } - if err = db.insertNiuNiu(u, gid); err != nil { + if err = db.insertNiuNiu(&info, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } @@ -266,7 +266,7 @@ func init() { result.WriteString(fmt.Sprintf("\n📛%s<%s>的牛牛信息\n⭕性别:%s\n⭕%s度:%.2fcm\n⭕排行:%d\n⭕%s ", ctx.CardOrNickName(uid), strconv.FormatInt(uid, 10), sex, sexLong, niuniu, niuniuList.ranking(niuniu, uid), generateRandomString(niuniu))) - ctx.SendChain(message.At(uid), message.Text(&result)) + ctx.SendChain(message.Text(&result)) }) en.OnRegex(`^(?:.*使用(.*))??打胶$`, zero.OnlyGroup, getdb).SetBlock(true).Limit(func(ctx *zero.Ctx) *rate.Limiter { @@ -288,22 +288,25 @@ func init() { t := fmt.Sprintf("%d_%d", gid, uid) fiancee := ctx.State["regex_matched"].([]string) updateMap(t, false) + niuniu, err := db.findNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("请先注册牛牛!")) dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) return } - messages, err := processNiuniuAction(t, niuniu, fiancee[1]) + + messages, err := processNiuniuAction(t, &niuniu, fiancee[1]) if err != nil { ctx.SendChain(message.Text(err)) return } - ctx.SendChain(message.Text(messages)) if err = db.insertNiuNiu(&niuniu, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } + + ctx.SendChain(message.Text(messages)) }) en.OnFullMatch("注册牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID @@ -375,7 +378,7 @@ func init() { jjLimiter.Delete(t) return } - fencingResult, f1, err := processJJuAction(myniuniu, adduserniuniu, t, fiancee[1]) + fencingResult, f1, err := processJJuAction(&myniuniu, &adduserniuniu, t, fiancee[1]) if err != nil { ctx.SendChain(message.Text(err)) return diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index d33749482b..a3d444555d 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -29,6 +29,11 @@ type userInfo struct { Philter int // 媚药 Artifact int // 击剑神器 ShenJi int // 击剑神稽 + Buff1 int // 暂定 + Buff2 int // 暂定 + Buff3 int // 暂定 + Buff4 int // 暂定 + Buff5 int // 暂定 } type users []*userInfo diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index a14faa9bb3..9ab6297269 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -9,7 +9,7 @@ import ( "time" ) -func createUserInfoByProps(props string, niuniu userInfo) error { +func createUserInfoByProps(props string, niuniu *userInfo) error { var ( err error ) @@ -46,7 +46,7 @@ func createUserInfoByProps(props string, niuniu userInfo) error { // 接收值依次是 自己和被jj用户的信息 一个包含gid和uid的字符串 道具名称 // 返回值依次是 要发生的消息 错误信息 -func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string) (string, float64, error) { +func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) (string, float64, error) { var ( fencingResult string f float64 @@ -55,7 +55,7 @@ func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string) err error ) v, ok := prop.Load(t) - u = myniuniu + u = *myniuniu if props != "" { if props != "击剑神器" && props != "击剑神稽" { return "", 0, errors.New("道具不存在") @@ -84,15 +84,15 @@ func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string) } return fencingResult, f1, err } -func processNiuniuAction(t string, niuniu userInfo, props string) (string, error) { +func processNiuniuAction(t string, niuniu *userInfo, props string) (string, error) { var ( messages string - f float64 u userInfo err error + f float64 ) load, ok := prop.Load(t) - u = niuniu + u = *niuniu if props != "" { if props != "伟哥" && props != "媚药" { return "", errors.New("道具不存在") @@ -126,7 +126,7 @@ func processNiuniuAction(t string, niuniu userInfo, props string) (string, error return messages, err } -func purchaseItem(n int, info userInfo) (*userInfo, int, error) { +func purchaseItem(n int, info userInfo) (int, error) { var ( money int err error @@ -147,7 +147,7 @@ func purchaseItem(n int, info userInfo) (*userInfo, int, error) { default: err = errors.New("无效的选择") } - return &info, money, err + return money, err } func generateRandomStingTwo(niuniu float64) (string, float64) { @@ -293,6 +293,7 @@ func calculateWinProbability(heightA, heightB float64) float64 { // applySkill 应用击剑技巧并生成结果 func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, float64, float64) { reduce := fence(oppoLength) + //兜底操作 if reduce == 0 { reduce = rand.Float64() + float64(rand.Intn(3)) } @@ -314,10 +315,12 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo // fence 根据长度计算减少的长度 func fence(rd float64) float64 { - r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd) - if rand.Intn(2) == 1 { - return rd - rand.Float64()*r + rd = math.Abs(rd) + if rd == 0 { + rd = 1 } + r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd) + return float64(int(r * rand.Float64())) }