mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
fix: 修正niuniu的部分逻辑 (#981)
This commit is contained in:
parent
2cee275771
commit
6f7d4beb17
@ -294,13 +294,13 @@ func init() {
|
|||||||
dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
|
dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
messages, u, 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))
|
ctx.SendChain(message.Text(messages))
|
||||||
if err = db.insertNiuNiu(&u, 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
|
||||||
}
|
}
|
||||||
@ -313,14 +313,14 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 获取初始长度
|
// 获取初始长度
|
||||||
long := db.randLength()
|
length := db.randLength()
|
||||||
u := userInfo{
|
u := userInfo{
|
||||||
UID: uid,
|
UID: uid,
|
||||||
Length: long,
|
Length: length,
|
||||||
UserCount: 0,
|
|
||||||
}
|
}
|
||||||
// 添加数据进入表
|
// 添加数据进入表
|
||||||
if err := db.insertNiuNiu(&u, gid); err != nil {
|
if err := db.insertNiuNiu(&u, gid); err != nil {
|
||||||
|
|
||||||
if err = db.createGIDTable(gid); err != nil {
|
if err = db.createGIDTable(gid); err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
return
|
||||||
@ -330,8 +330,9 @@ func init() {
|
|||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
ctx.SendChain(message.Reply(ctx.Event.GroupID),
|
ctx.SendChain(message.At(uid),
|
||||||
message.Text("注册成功,你的牛牛现在有", u.Length, "cm"))
|
message.Text("注册成功,你的牛牛现在有", u.Length, "cm"))
|
||||||
})
|
})
|
||||||
en.OnRegex(`^(?:.*使用(.*))??jj\s?(\[CQ:at,(?:\S*,)?qq=(\d+)(?:,\S*)?\]|(\d+))$`, getdb,
|
en.OnRegex(`^(?:.*使用(.*))??jj\s?(\[CQ:at,(?:\S*,)?qq=(\d+)(?:,\S*)?\]|(\d+))$`, getdb,
|
||||||
@ -376,18 +377,19 @@ func init() {
|
|||||||
jjLimiter.Delete(t)
|
jjLimiter.Delete(t)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fencingResult, f1, u, 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
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = db.insertNiuNiu(&u, gid); err != nil {
|
if err = db.insertNiuNiu(&myniuniu, gid); err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
adduserniuniu.Length = f1
|
||||||
|
|
||||||
if err = db.insertNiuNiu(&userInfo{UID: adduser, Length: f1}, gid); err != nil {
|
if err = db.insertNiuNiu(&adduserniuniu, gid); err != nil {
|
||||||
ctx.SendChain(message.Text("ERROR:", err))
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -431,6 +433,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
uid := ctx.Event.UserID
|
uid := ctx.Event.UserID
|
||||||
@ -458,6 +461,7 @@ func updateMap(t string, d bool) {
|
|||||||
if value == nil {
|
if value == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 检查一次是否已经过期
|
||||||
if !d {
|
if !d {
|
||||||
if time.Since(value.TimeLimit) > time.Minute*8 {
|
if time.Since(value.TimeLimit) > time.Minute*8 {
|
||||||
prop.Delete(t)
|
prop.Delete(t)
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createUserInfoByProps(props string, niuniu *userInfo) (userInfo, error) {
|
func createUserInfoByProps(props string, niuniu userInfo) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
@ -41,12 +41,12 @@ func createUserInfoByProps(props string, niuniu *userInfo) (userInfo, error) {
|
|||||||
default:
|
default:
|
||||||
err = errors.New("道具不存在")
|
err = errors.New("道具不存在")
|
||||||
}
|
}
|
||||||
return *niuniu, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 接收值依次是 自己和被jj用户的信息 一个包含gid和uid的字符串 道具名称
|
// 接收值依次是 自己和被jj用户的信息 一个包含gid和uid的字符串 道具名称
|
||||||
// 返回值依次是 要发生的消息 被jj用户的niuniu 用户的信息 错误信息
|
// 返回值依次是 要发生的消息 错误信息
|
||||||
func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) (string, float64, userInfo, error) {
|
func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string) (string, float64, error) {
|
||||||
var (
|
var (
|
||||||
fencingResult string
|
fencingResult string
|
||||||
f float64
|
f float64
|
||||||
@ -55,36 +55,36 @@ 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
|
||||||
if props != "" {
|
if props != "" {
|
||||||
if props != "击剑神器" && props != "击剑神稽" {
|
if props != "击剑神器" && props != "击剑神稽" {
|
||||||
return "", 0, userInfo{}, errors.New("道具不存在")
|
return "", 0, errors.New("道具不存在")
|
||||||
}
|
}
|
||||||
u, err = createUserInfoByProps(props, myniuniu)
|
if err = createUserInfoByProps(props, myniuniu); err != nil {
|
||||||
if err != nil {
|
return "", 0, err
|
||||||
return "", 0, userInfo{}, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8:
|
case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8:
|
||||||
fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length)
|
fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length)
|
||||||
u.Length = f
|
myniuniu.Length = f
|
||||||
errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit))
|
errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit))
|
||||||
err = errors.New(errMessage)
|
err = errors.New(errMessage)
|
||||||
case myniuniu.ShenJi-u.ShenJi != 0:
|
case myniuniu.ShenJi-u.ShenJi != 0:
|
||||||
fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length)
|
fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length)
|
||||||
u.Length = f
|
myniuniu.Length = f
|
||||||
updateMap(t, true)
|
updateMap(t, true)
|
||||||
case myniuniu.Artifact-u.Artifact != 0:
|
case myniuniu.Artifact-u.Artifact != 0:
|
||||||
fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length)
|
fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length)
|
||||||
u.Length = f
|
myniuniu.Length = f
|
||||||
updateMap(t, true)
|
updateMap(t, true)
|
||||||
default:
|
default:
|
||||||
fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length)
|
fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length)
|
||||||
u.Length = f
|
myniuniu.Length = f
|
||||||
}
|
}
|
||||||
return fencingResult, f1, u, err
|
return fencingResult, f1, err
|
||||||
}
|
}
|
||||||
func processNiuniuAction(t string, niuniu *userInfo, props string) (string, userInfo, error) {
|
func processNiuniuAction(t string, niuniu userInfo, props string) (string, error) {
|
||||||
var (
|
var (
|
||||||
messages string
|
messages string
|
||||||
f float64
|
f float64
|
||||||
@ -92,36 +92,41 @@ func processNiuniuAction(t string, niuniu *userInfo, props string) (string, user
|
|||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
load, ok := prop.Load(t)
|
load, ok := prop.Load(t)
|
||||||
|
u = niuniu
|
||||||
if props != "" {
|
if props != "" {
|
||||||
|
|
||||||
if props != "伟哥" && props != "媚药" {
|
if props != "伟哥" && props != "媚药" {
|
||||||
return "", u, errors.New("道具不存在")
|
return "", errors.New("道具不存在")
|
||||||
}
|
}
|
||||||
u, err = createUserInfoByProps(props, niuniu)
|
|
||||||
if err != nil {
|
if err = createUserInfoByProps(props, niuniu); err != nil {
|
||||||
return "", userInfo{}, err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8:
|
case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8:
|
||||||
messages, f = generateRandomStingTwo(niuniu.Length)
|
messages, f = generateRandomStingTwo(niuniu.Length)
|
||||||
u.Length = f
|
niuniu.Length = f
|
||||||
u.UID = niuniu.UID
|
|
||||||
errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit))
|
errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit))
|
||||||
err = errors.New(errMessage)
|
err = errors.New(errMessage)
|
||||||
|
|
||||||
case niuniu.WeiGe-u.WeiGe != 0:
|
case niuniu.WeiGe-u.WeiGe != 0:
|
||||||
messages, f = niuniu.useWeiGe()
|
messages, f = niuniu.useWeiGe()
|
||||||
u.Length = f
|
niuniu.Length = f
|
||||||
updateMap(t, true)
|
updateMap(t, true)
|
||||||
|
|
||||||
case niuniu.Philter-u.Philter != 0:
|
case niuniu.Philter-u.Philter != 0:
|
||||||
messages, f = niuniu.usePhilter()
|
messages, f = niuniu.usePhilter()
|
||||||
u.Length = f
|
niuniu.Length = f
|
||||||
updateMap(t, true)
|
updateMap(t, true)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
messages, f = generateRandomStingTwo(niuniu.Length)
|
messages, f = generateRandomStingTwo(niuniu.Length)
|
||||||
u.Length = f
|
niuniu.Length = f
|
||||||
u.UID = niuniu.UID
|
|
||||||
}
|
}
|
||||||
return messages, u, err
|
return messages, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func purchaseItem(n int, info userInfo) (*userInfo, int, error) {
|
func purchaseItem(n int, info userInfo) (*userInfo, int, error) {
|
||||||
@ -244,19 +249,16 @@ func fencing(myLength, oppoLength float64) (string, float64, float64) {
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case oppoLength <= -100 && myLength > 0 && 10 < probability && probability <= 20:
|
case oppoLength <= -100 && myLength > 0 && 10 < probability && probability <= 20:
|
||||||
oppoLength *= 0.85
|
|
||||||
change := hitGlue(oppoLength) + rand.Float64()*math.Log2(math.Abs(0.5*(myLength+oppoLength)))
|
change := hitGlue(oppoLength) + rand.Float64()*math.Log2(math.Abs(0.5*(myLength+oppoLength)))
|
||||||
myLength = change
|
myLength += change
|
||||||
return fmt.Sprintf("对方身为魅魔诱惑了你,你同化成魅魔!当前长度%.2fcm!", -myLength), -myLength, oppoLength
|
return fmt.Sprintf("对方身为魅魔诱惑了你,你同化成魅魔!当前长度%.2fcm!", -myLength), -myLength, oppoLength
|
||||||
|
|
||||||
case oppoLength >= 100 && myLength > 0 && 10 < probability && probability <= 20:
|
case oppoLength >= 100 && myLength > 0 && 10 < probability && probability <= 20:
|
||||||
oppoLength *= 0.85
|
|
||||||
change := math.Min(math.Abs(devourLimit*myLength), math.Abs(1.5*myLength))
|
change := math.Min(math.Abs(devourLimit*myLength), math.Abs(1.5*myLength))
|
||||||
myLength += change
|
myLength += change
|
||||||
return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength
|
return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength
|
||||||
|
|
||||||
case myLength <= -100 && oppoLength > 0 && 10 < probability && probability <= 20:
|
case myLength <= -100 && oppoLength > 0 && 10 < probability && probability <= 20:
|
||||||
myLength *= 0.85
|
|
||||||
change := hitGlue(myLength+oppoLength) + rand.Float64()*math.Log2(math.Abs(0.5*(myLength+oppoLength)))
|
change := hitGlue(myLength+oppoLength) + rand.Float64()*math.Log2(math.Abs(0.5*(myLength+oppoLength)))
|
||||||
oppoLength -= change
|
oppoLength -= change
|
||||||
myLength -= change
|
myLength -= change
|
||||||
@ -277,20 +279,16 @@ func determineResultBySkill(myLength, oppoLength float64) (string, float64, floa
|
|||||||
probability := rand.Intn(100) + 1
|
probability := rand.Intn(100) + 1
|
||||||
winProbability := calculateWinProbability(myLength, oppoLength) * 100
|
winProbability := calculateWinProbability(myLength, oppoLength) * 100
|
||||||
return applySkill(myLength, oppoLength,
|
return applySkill(myLength, oppoLength,
|
||||||
0 < probability && float64(probability) <= winProbability)
|
float64(probability) <= winProbability)
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculateWinProbability 计算胜率
|
// calculateWinProbability 计算胜率
|
||||||
func calculateWinProbability(heightA, heightB float64) float64 {
|
func calculateWinProbability(heightA, heightB float64) float64 {
|
||||||
var pA float64
|
pA := 0.9
|
||||||
if heightA > heightB {
|
|
||||||
pA = 0.7 + 0.2*(heightA-heightB)/heightA
|
|
||||||
} else {
|
|
||||||
pA = 0.7 - 0.2*(heightB-heightA)/heightB
|
|
||||||
}
|
|
||||||
heightRatio := math.Max(heightA, heightB) / math.Min(heightA, heightB)
|
heightRatio := math.Max(heightA, heightB) / math.Min(heightA, heightB)
|
||||||
reductionRate := 0.1 * (heightRatio - 1)
|
reductionRate := 0.1 * (heightRatio - 1)
|
||||||
reduction := pA * reductionRate
|
reduction := pA * reductionRate
|
||||||
|
|
||||||
adjustedPA := pA - reduction
|
adjustedPA := pA - reduction
|
||||||
return math.Max(adjustedPA, 0.01)
|
return math.Max(adjustedPA, 0.01)
|
||||||
}
|
}
|
||||||
@ -298,6 +296,9 @@ 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 {
|
||||||
|
reduce = rand.Float64() + float64(rand.Intn(3))
|
||||||
|
}
|
||||||
if increaseLength1 {
|
if increaseLength1 {
|
||||||
myLength += reduce
|
myLength += reduce
|
||||||
oppoLength -= 0.8 * reduce
|
oppoLength -= 0.8 * reduce
|
||||||
@ -305,6 +306,7 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo
|
|||||||
return fmt.Sprintf("哦吼!?你的牛牛在长大欸!长大了%.2fcm!", reduce), myLength, oppoLength
|
return fmt.Sprintf("哦吼!?你的牛牛在长大欸!长大了%.2fcm!", reduce), myLength, oppoLength
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("你以绝对的长度让对方屈服了呢!你的长度增加%.2fcm,当前长度%.2fcm!", reduce, myLength), myLength, oppoLength
|
return fmt.Sprintf("你以绝对的长度让对方屈服了呢!你的长度增加%.2fcm,当前长度%.2fcm!", reduce, myLength), myLength, oppoLength
|
||||||
|
|
||||||
}
|
}
|
||||||
myLength -= reduce
|
myLength -= reduce
|
||||||
oppoLength += 0.8 * reduce
|
oppoLength += 0.8 * reduce
|
||||||
@ -312,9 +314,10 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo
|
|||||||
return fmt.Sprintf("哦吼!?看来你的牛牛因为击剑而凹进去了呢🤣🤣🤣!凹进去了%.2fcm!", reduce), myLength, oppoLength
|
return fmt.Sprintf("哦吼!?看来你的牛牛因为击剑而凹进去了呢🤣🤣🤣!凹进去了%.2fcm!", reduce), myLength, oppoLength
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("对方以绝对的长度让你屈服了呢!你的长度减少%.2fcm,当前长度%.2fcm!", reduce, myLength), myLength, oppoLength
|
return fmt.Sprintf("对方以绝对的长度让你屈服了呢!你的长度减少%.2fcm,当前长度%.2fcm!", reduce, myLength), myLength, oppoLength
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fence
|
// fence 根据长度计算减少的长度
|
||||||
func fence(rd float64) float64 {
|
func fence(rd float64) float64 {
|
||||||
r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd)
|
r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd)
|
||||||
if rand.Intn(2) == 1 {
|
if rand.Intn(2) == 1 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user