mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
fix: 牛牛为负数时jj时的错误 (#984)
This commit is contained in:
parent
54471d16e4
commit
c008214be4
@ -122,7 +122,7 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
u, money, err := purchaseItem(n, info)
|
money, err := purchaseItem(n, info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
return
|
||||||
@ -138,7 +138,7 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = db.insertNiuNiu(u, gid); err != nil {
|
if err = db.insertNiuNiu(&info, gid); err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -266,7 +266,7 @@ func init() {
|
|||||||
result.WriteString(fmt.Sprintf("\n📛%s<%s>的牛牛信息\n⭕性别:%s\n⭕%s度:%.2fcm\n⭕排行:%d\n⭕%s ",
|
result.WriteString(fmt.Sprintf("\n📛%s<%s>的牛牛信息\n⭕性别:%s\n⭕%s度:%.2fcm\n⭕排行:%d\n⭕%s ",
|
||||||
ctx.CardOrNickName(uid), strconv.FormatInt(uid, 10),
|
ctx.CardOrNickName(uid), strconv.FormatInt(uid, 10),
|
||||||
sex, sexLong, niuniu, niuniuList.ranking(niuniu, uid), generateRandomString(niuniu)))
|
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,
|
en.OnRegex(`^(?:.*使用(.*))??打胶$`, zero.OnlyGroup,
|
||||||
getdb).SetBlock(true).Limit(func(ctx *zero.Ctx) *rate.Limiter {
|
getdb).SetBlock(true).Limit(func(ctx *zero.Ctx) *rate.Limiter {
|
||||||
@ -288,22 +288,25 @@ func init() {
|
|||||||
t := fmt.Sprintf("%d_%d", gid, uid)
|
t := fmt.Sprintf("%d_%d", gid, uid)
|
||||||
fiancee := ctx.State["regex_matched"].([]string)
|
fiancee := ctx.State["regex_matched"].([]string)
|
||||||
updateMap(t, false)
|
updateMap(t, false)
|
||||||
|
|
||||||
niuniu, err := db.findNiuNiu(gid, uid)
|
niuniu, err := db.findNiuNiu(gid, uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("请先注册牛牛!"))
|
ctx.SendChain(message.Text("请先注册牛牛!"))
|
||||||
dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
|
dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
messages, err := processNiuniuAction(t, niuniu, fiancee[1])
|
|
||||||
|
messages, err := processNiuniuAction(t, &niuniu, fiancee[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text(err))
|
ctx.SendChain(message.Text(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.SendChain(message.Text(messages))
|
|
||||||
if err = db.insertNiuNiu(&niuniu, gid); err != nil {
|
if err = db.insertNiuNiu(&niuniu, gid); err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.SendChain(message.Text(messages))
|
||||||
})
|
})
|
||||||
en.OnFullMatch("注册牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
en.OnFullMatch("注册牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
gid := ctx.Event.GroupID
|
gid := ctx.Event.GroupID
|
||||||
@ -375,7 +378,7 @@ func init() {
|
|||||||
jjLimiter.Delete(t)
|
jjLimiter.Delete(t)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fencingResult, f1, err := processJJuAction(myniuniu, adduserniuniu, t, fiancee[1])
|
fencingResult, f1, err := processJJuAction(&myniuniu, &adduserniuniu, t, fiancee[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text(err))
|
ctx.SendChain(message.Text(err))
|
||||||
return
|
return
|
||||||
|
|||||||
@ -29,6 +29,11 @@ type userInfo struct {
|
|||||||
Philter int // 媚药
|
Philter int // 媚药
|
||||||
Artifact int // 击剑神器
|
Artifact int // 击剑神器
|
||||||
ShenJi int // 击剑神稽
|
ShenJi int // 击剑神稽
|
||||||
|
Buff1 int // 暂定
|
||||||
|
Buff2 int // 暂定
|
||||||
|
Buff3 int // 暂定
|
||||||
|
Buff4 int // 暂定
|
||||||
|
Buff5 int // 暂定
|
||||||
}
|
}
|
||||||
|
|
||||||
type users []*userInfo
|
type users []*userInfo
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createUserInfoByProps(props string, niuniu userInfo) error {
|
func createUserInfoByProps(props string, niuniu *userInfo) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
@ -46,7 +46,7 @@ func createUserInfoByProps(props string, niuniu userInfo) error {
|
|||||||
|
|
||||||
// 接收值依次是 自己和被jj用户的信息 一个包含gid和uid的字符串 道具名称
|
// 接收值依次是 自己和被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 (
|
var (
|
||||||
fencingResult string
|
fencingResult string
|
||||||
f float64
|
f float64
|
||||||
@ -55,7 +55,7 @@ func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string)
|
|||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
v, ok := prop.Load(t)
|
v, ok := prop.Load(t)
|
||||||
u = myniuniu
|
u = *myniuniu
|
||||||
if props != "" {
|
if props != "" {
|
||||||
if props != "击剑神器" && props != "击剑神稽" {
|
if props != "击剑神器" && props != "击剑神稽" {
|
||||||
return "", 0, errors.New("道具不存在")
|
return "", 0, errors.New("道具不存在")
|
||||||
@ -84,15 +84,15 @@ func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string)
|
|||||||
}
|
}
|
||||||
return fencingResult, f1, err
|
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 (
|
var (
|
||||||
messages string
|
messages string
|
||||||
f float64
|
|
||||||
u userInfo
|
u userInfo
|
||||||
err error
|
err error
|
||||||
|
f float64
|
||||||
)
|
)
|
||||||
load, ok := prop.Load(t)
|
load, ok := prop.Load(t)
|
||||||
u = niuniu
|
u = *niuniu
|
||||||
if props != "" {
|
if props != "" {
|
||||||
if props != "伟哥" && props != "媚药" {
|
if props != "伟哥" && props != "媚药" {
|
||||||
return "", errors.New("道具不存在")
|
return "", errors.New("道具不存在")
|
||||||
@ -126,7 +126,7 @@ func processNiuniuAction(t string, niuniu userInfo, props string) (string, error
|
|||||||
return messages, err
|
return messages, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func purchaseItem(n int, info userInfo) (*userInfo, int, error) {
|
func purchaseItem(n int, info userInfo) (int, error) {
|
||||||
var (
|
var (
|
||||||
money int
|
money int
|
||||||
err error
|
err error
|
||||||
@ -147,7 +147,7 @@ func purchaseItem(n int, info userInfo) (*userInfo, int, error) {
|
|||||||
default:
|
default:
|
||||||
err = errors.New("无效的选择")
|
err = errors.New("无效的选择")
|
||||||
}
|
}
|
||||||
return &info, money, err
|
return money, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRandomStingTwo(niuniu float64) (string, float64) {
|
func generateRandomStingTwo(niuniu float64) (string, float64) {
|
||||||
@ -293,6 +293,7 @@ func calculateWinProbability(heightA, heightB float64) float64 {
|
|||||||
// applySkill 应用击剑技巧并生成结果
|
// applySkill 应用击剑技巧并生成结果
|
||||||
func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, float64, float64) {
|
func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, float64, float64) {
|
||||||
reduce := fence(oppoLength)
|
reduce := fence(oppoLength)
|
||||||
|
//兜底操作
|
||||||
if reduce == 0 {
|
if reduce == 0 {
|
||||||
reduce = rand.Float64() + float64(rand.Intn(3))
|
reduce = rand.Float64() + float64(rand.Intn(3))
|
||||||
}
|
}
|
||||||
@ -314,10 +315,12 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo
|
|||||||
|
|
||||||
// fence 根据长度计算减少的长度
|
// fence 根据长度计算减少的长度
|
||||||
func fence(rd float64) float64 {
|
func fence(rd float64) float64 {
|
||||||
r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd)
|
rd = math.Abs(rd)
|
||||||
if rand.Intn(2) == 1 {
|
if rd == 0 {
|
||||||
return rd - rand.Float64()*r
|
rd = 1
|
||||||
}
|
}
|
||||||
|
r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd)
|
||||||
|
|
||||||
return float64(int(r * rand.Float64()))
|
return float64(int(r * rand.Float64()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user