Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正niuniu的部分逻辑 #981

Merged
merged 40 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a29bbec
Update main.go
xyy0411 Aug 31, 2024
c22079e
Update model.go
xyy0411 Aug 31, 2024
78e9d1a
Update utils.go
xyy0411 Aug 31, 2024
4f9c58f
Update README.md
xyy0411 Aug 31, 2024
66afee9
Update main.go
xyy0411 Aug 31, 2024
be5ec00
Update main.go
xyy0411 Sep 1, 2024
22e2447
Update model.go
xyy0411 Sep 1, 2024
05a28c9
Update main.go
xyy0411 Sep 2, 2024
fa0c9d8
Update main.go
xyy0411 Sep 2, 2024
83ee8b6
Update main.go
xyy0411 Sep 2, 2024
dd676ad
Update main.go
xyy0411 Sep 3, 2024
85ca08a
Update main.go
xyy0411 Sep 3, 2024
52d5e87
Merge branch 'FloatTech:master' into master
xyy0411 Sep 8, 2024
2cde59d
Update main.go
xyy0411 Sep 8, 2024
e06ece6
Update utils.go
xyy0411 Sep 8, 2024
8b862fa
Update model.go
xyy0411 Sep 8, 2024
d2f4a29
Update README.md
xyy0411 Sep 8, 2024
4e222f4
Update main.go
xyy0411 Sep 10, 2024
acc2fc4
修改了一些问题
xyy0411 Sep 13, 2024
a74efd7
修改了一些问题
xyy0411 Sep 13, 2024
75c77f1
修改了一些问题
xyy0411 Sep 13, 2024
09a24f7
修改了一些问题
xyy0411 Sep 14, 2024
9bac2a7
Merge remote-tracking branch 'origin/master'
xyy0411 Sep 14, 2024
da37ca6
修改了一些问题
xyy0411 Sep 14, 2024
40e77d8
牛牛商店改面向对象形式,加入NiuNiuPlugin接口
xyy0411 Sep 15, 2024
704f2e8
修改了一些问题
xyy0411 Sep 15, 2024
ffcede5
修改了一些问题
xyy0411 Sep 17, 2024
0c817c9
修改了一些问题
xyy0411 Sep 21, 2024
2b4d380
修复lint
xyy0411 Sep 21, 2024
531da5a
修复一些逻辑问题
xyy0411 Sep 25, 2024
7f4adce
修lint
xyy0411 Sep 25, 2024
6ab034d
Merge branch 'master' into master
fumiama Sep 26, 2024
f9819c7
修正逻辑
xyy0411 Sep 26, 2024
185f857
修正逻辑
xyy0411 Sep 26, 2024
9b9a17f
修正逻辑
xyy0411 Sep 26, 2024
12bc059
Merge remote-tracking branch 'origin/master'
xyy0411 Sep 26, 2024
9ce8dc2
修正逻辑
xyy0411 Sep 26, 2024
5651011
Merge remote-tracking branch 'origin/master'
xyy0411 Sep 26, 2024
d68d6af
修正逻辑
xyy0411 Sep 26, 2024
05e18c7
修正逻辑
xyy0411 Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions plugin/niuniu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ func init() {
dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
return
}
messages, u, 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(&u, gid); err != nil {
if err = db.insertNiuNiu(&niuniu, gid); err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
Expand All @@ -313,14 +313,14 @@ func init() {
return
}
// 获取初始长度
long := db.randLength()
length := db.randLength()
u := userInfo{
UID: uid,
Length: long,
UserCount: 0,
UID: uid,
Length: length,
}
// 添加数据进入表
if err := db.insertNiuNiu(&u, gid); err != nil {

if err = db.createGIDTable(gid); err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
Expand All @@ -330,8 +330,9 @@ func init() {
ctx.SendChain(message.Text("ERROR:", err))
return
}

}
ctx.SendChain(message.Reply(ctx.Event.GroupID),
ctx.SendChain(message.At(uid),
message.Text("注册成功,你的牛牛现在有", u.Length, "cm"))
})
en.OnRegex(`^(?:.*使用(.*))??jj\s?(\[CQ:at,(?:\S*,)?qq=(\d+)(?:,\S*)?\]|(\d+))$`, getdb,
Expand Down Expand Up @@ -376,18 +377,19 @@ func init() {
jjLimiter.Delete(t)
return
}
fencingResult, f1, u, 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
}

if err = db.insertNiuNiu(&u, gid); err != nil {
if err = db.insertNiuNiu(&myniuniu, gid); err != nil {
ctx.SendChain(message.Text("ERROR:", err))
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))
return
}
Expand Down Expand Up @@ -431,6 +433,7 @@ func init() {
}
}
}

})
en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
Expand Down Expand Up @@ -458,6 +461,7 @@ func updateMap(t string, d bool) {
if value == nil {
return
}
// 检查一次是否已经过期
if !d {
if time.Since(value.TimeLimit) > time.Minute*8 {
prop.Delete(t)
Expand Down
77 changes: 40 additions & 37 deletions plugin/niuniu/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"
)

func createUserInfoByProps(props string, niuniu *userInfo) (userInfo, error) {
func createUserInfoByProps(props string, niuniu userInfo) error {
var (
err error
)
Expand Down Expand Up @@ -41,12 +41,12 @@ func createUserInfoByProps(props string, niuniu *userInfo) (userInfo, error) {
default:
err = errors.New("道具不存在")
}
return *niuniu, err
return err
}

// 接收值依次是 自己和被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 (
fencingResult string
f float64
Expand All @@ -55,73 +55,78 @@ func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string)
err error
)
v, ok := prop.Load(t)
u = myniuniu
if props != "" {
if props != "击剑神器" && props != "击剑神稽" {
return "", 0, userInfo{}, errors.New("道具不存在")
return "", 0, errors.New("道具不存在")
}
u, err = createUserInfoByProps(props, myniuniu)
if err != nil {
return "", 0, userInfo{}, err
if err = createUserInfoByProps(props, myniuniu); err != nil {
return "", 0, err
}
}
switch {
case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8:
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))
err = errors.New(errMessage)
case myniuniu.ShenJi-u.ShenJi != 0:
fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length)
u.Length = f
myniuniu.Length = f
updateMap(t, true)
case myniuniu.Artifact-u.Artifact != 0:
fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length)
u.Length = f
myniuniu.Length = f
updateMap(t, true)
default:
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 (
messages string
f float64
u userInfo
err error
)
load, ok := prop.Load(t)
u = niuniu
if props != "" {

if props != "伟哥" && props != "媚药" {
return "", u, errors.New("道具不存在")
return "", errors.New("道具不存在")
}
u, err = createUserInfoByProps(props, niuniu)
if err != nil {
return "", userInfo{}, err

if err = createUserInfoByProps(props, niuniu); err != nil {
return "", err
}

}
switch {
case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8:
messages, f = generateRandomStingTwo(niuniu.Length)
u.Length = f
u.UID = niuniu.UID
niuniu.Length = f
errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit))
err = errors.New(errMessage)

case niuniu.WeiGe-u.WeiGe != 0:
messages, f = niuniu.useWeiGe()
u.Length = f
niuniu.Length = f
updateMap(t, true)

case niuniu.Philter-u.Philter != 0:
messages, f = niuniu.usePhilter()
u.Length = f
niuniu.Length = f
updateMap(t, true)

default:
messages, f = generateRandomStingTwo(niuniu.Length)
u.Length = f
u.UID = niuniu.UID
niuniu.Length = f

}
return messages, u, err
return messages, err
}

func purchaseItem(n int, info userInfo) (*userInfo, int, error) {
Expand Down Expand Up @@ -244,19 +249,16 @@ func fencing(myLength, oppoLength float64) (string, float64, float64) {

switch {
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)))
myLength = change
myLength += change
return fmt.Sprintf("对方身为魅魔诱惑了你,你同化成魅魔!当前长度%.2fcm!", -myLength), -myLength, oppoLength

case oppoLength >= 100 && myLength > 0 && 10 < probability && probability <= 20:
oppoLength *= 0.85
change := math.Min(math.Abs(devourLimit*myLength), math.Abs(1.5*myLength))
myLength += change
return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength

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)))
oppoLength -= change
myLength -= change
Expand All @@ -277,44 +279,45 @@ func determineResultBySkill(myLength, oppoLength float64) (string, float64, floa
probability := rand.Intn(100) + 1
winProbability := calculateWinProbability(myLength, oppoLength) * 100
return applySkill(myLength, oppoLength,
0 < probability && float64(probability) <= winProbability)
float64(probability) <= winProbability)
}

// calculateWinProbability 计算胜率
func calculateWinProbability(heightA, heightB float64) float64 {
var pA float64
if heightA > heightB {
pA = 0.7 + 0.2*(heightA-heightB)/heightA
} else {
pA = 0.7 - 0.2*(heightB-heightA)/heightB
}
pA := 0.9
heightRatio := math.Max(heightA, heightB) / math.Min(heightA, heightB)
reductionRate := 0.1 * (heightRatio - 1)
reduction := pA * reductionRate

adjustedPA := pA - reduction
return math.Max(adjustedPA, 0.01)
}

// applySkill 应用击剑技巧并生成结果
func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, float64, float64) {
reduce := fence(oppoLength)
if reduce == 0 {
reduce = rand.Float64() + float64(rand.Intn(3))
}
if increaseLength1 {
myLength += reduce
oppoLength -= 0.8 * reduce
if myLength < 0 {
return fmt.Sprintf("哦吼!?你的牛牛在长大欸!长大了%.2fcm!", reduce), myLength, oppoLength
}
return fmt.Sprintf("你以绝对的长度让对方屈服了呢!你的长度增加%.2fcm,当前长度%.2fcm!", reduce, myLength), myLength, oppoLength

}
myLength -= reduce
oppoLength += 0.8 * reduce
if myLength < 0 {
return fmt.Sprintf("哦吼!?看来你的牛牛因为击剑而凹进去了呢🤣🤣🤣!凹进去了%.2fcm!", reduce), myLength, oppoLength
}
return fmt.Sprintf("对方以绝对的长度让你屈服了呢!你的长度减少%.2fcm,当前长度%.2fcm!", reduce, myLength), myLength, oppoLength

}

// fence
// fence 根据长度计算减少的长度
func fence(rd float64) float64 {
r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd)
if rand.Intn(2) == 1 {
Expand Down
Loading