Skip to content

Commit

Permalink
fix: 牛牛逻辑问题 (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy0411 authored Oct 9, 2024
1 parent 147ebb0 commit 410dd05
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 147 deletions.
9 changes: 4 additions & 5 deletions plugin/niuniu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func init() {
return
}

money, err := purchaseItem(n, info)
money, err := info.purchaseItem(n)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
Expand Down Expand Up @@ -296,7 +296,7 @@ func init() {
return
}

messages, err := processNiuniuAction(t, &niuniu, fiancee[1])
messages, err := niuniu.processNiuNiuAction(t, fiancee[1])
if err != nil {
ctx.SendChain(message.Text(err))
return
Expand Down Expand Up @@ -378,7 +378,7 @@ func init() {
jjLimiter.Delete(t)
return
}
fencingResult, f1, err := processJJuAction(&myniuniu, &adduserniuniu, t, fiancee[1])
fencingResult, err := myniuniu.processJJuAction(&adduserniuniu, t, fiancee[1])
if err != nil {
ctx.SendChain(message.Text(err))
return
Expand All @@ -388,7 +388,6 @@ func init() {
ctx.SendChain(message.Text("ERROR:", err))
return
}
adduserniuniu.Length = f1

if err = db.insertNiuNiu(&adduserniuniu, gid); err != nil {
ctx.SendChain(message.Text("ERROR:", err))
Expand Down Expand Up @@ -425,7 +424,7 @@ func init() {
if c.Count > 5 {
ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count),
"你们不要再找ta🤺啦!"})))
// 保证只发生一次
// 保证只发送一次
if c.Count < 7 {
id := ctx.SendPrivateMessage(adduser,
message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid)))
Expand Down
146 changes: 146 additions & 0 deletions plugin/niuniu/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package niuniu

import (
"errors"
"fmt"
"math"
"math/rand"
Expand Down Expand Up @@ -129,6 +130,151 @@ func (u *userInfo) useShenJi(adduserniuniu float64) (string, float64, float64) {
return r, myLength, adduserniuniu + 0.7*change
}

func (u *userInfo) processNiuNiuAction(t string, props string) (string, error) {
var (
messages string
info userInfo
err error
f float64
)
load, ok := prop.Load(t)
info = *u
if props != "" {
if !contains(t, dajiaoProp) {
return "", errors.New("道具不能混着用哦")
}
if err = u.createUserInfoByProps(props); err != nil {
return "", err
}
}
switch {
case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8:
messages, f = generateRandomStingTwo(u.Length)
u.Length = f
errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit))
err = errors.New(errMessage)

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

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

default:
messages, f = generateRandomStingTwo(u.Length)
u.Length = f
}
return messages, err
}

func (u *userInfo) createUserInfoByProps(props string) error {
var (
err error
)
switch props {
case "伟哥":
if u.WeiGe > 0 {
u.WeiGe--
} else {
err = errors.New("你还没有伟哥呢,不能使用")
}
case "媚药":
if u.Philter > 0 {
u.Philter--
} else {
err = errors.New("你还没有媚药呢,不能使用")
}
case "击剑神器":
if u.Artifact > 0 {
u.Artifact--
} else {
err = errors.New("你还没有击剑神器呢,不能使用")
}
case "击剑神稽":
if u.ShenJi > 0 {
u.ShenJi--
} else {
err = errors.New("你还没有击剑神稽呢,不能使用")
}
default:
err = errors.New("道具不存在")
}
return err
}

// 接收值依次是 被jj用户的信息 记录gid和uid的字符串 道具名称
// 返回值依次是 要发送的消息 错误信息
func (u *userInfo) processJJuAction(adduserniuniu *userInfo, t string, props string) (string, error) {
var (
fencingResult string
f float64
f1 float64
info userInfo
err error
)
v, ok := prop.Load(t)
info = *u
if props != "" {
if !contains(t, jjProp) {
return "", errors.New("道具不能混着用哦")
}
if err = u.createUserInfoByProps(props); err != nil {
return "", err
}
}
switch {
case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8:
fencingResult, f, f1 = fencing(u.Length, adduserniuniu.Length)
u.Length = f
adduserniuniu.Length = f1
errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit))
err = errors.New(errMessage)
case u.ShenJi-info.ShenJi != 0:
fencingResult, f, f1 = u.useShenJi(adduserniuniu.Length)
u.Length = f
adduserniuniu.Length = f1
updateMap(t, true)
case u.Artifact-info.Artifact != 0:
fencingResult, f, f1 = u.useArtifact(adduserniuniu.Length)
u.Length = f
adduserniuniu.Length = f1
updateMap(t, true)
default:
fencingResult, f, f1 = fencing(u.Length, adduserniuniu.Length)
u.Length = f
adduserniuniu.Length = f1
}
return fencingResult, err
}

func (u *userInfo) purchaseItem(n int) (int, error) {
var (
money int
err error
)
switch n {
case 1:
money = 300
u.WeiGe += 5
case 2:
money = 300
u.Philter += 5
case 3:
money = 500
u.Artifact += 2
case 4:
money = 500
u.ShenJi += 2
default:
err = errors.New("无效的选择")
}
return money, err
}

func (m users) positive() users {
var m1 []*userInfo
for _, i2 := range m {
Expand Down
157 changes: 15 additions & 142 deletions plugin/niuniu/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,153 +2,16 @@
package niuniu

import (
"errors"
"fmt"
"math"
"math/rand"
"time"
"strings"
)

func createUserInfoByProps(props string, niuniu *userInfo) error {
var (
err error
)
switch props {
case "伟哥":
if niuniu.WeiGe > 0 {
niuniu.WeiGe--
} else {
err = errors.New("你还没有伟哥呢,不能使用")
}
case "媚药":
if niuniu.Philter > 0 {
niuniu.Philter--
} else {
err = errors.New("你还没有媚药呢,不能使用")
}
case "击剑神器":
if niuniu.Artifact > 0 {
niuniu.Artifact--
} else {
err = errors.New("你还没有击剑神器呢,不能使用")
}
case "击剑神稽":
if niuniu.ShenJi > 0 {
niuniu.ShenJi--
} else {
err = errors.New("你还没有击剑神稽呢,不能使用")
}
default:
err = errors.New("道具不存在")
}
return err
}

// 接收值依次是 自己和被jj用户的信息 一个包含gid和uid的字符串 道具名称
// 返回值依次是 要发生的消息 错误信息
func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) (string, float64, error) {
var (
fencingResult string
f float64
f1 float64
u userInfo
err error
)
v, ok := prop.Load(t)
u = *myniuniu
if props != "" {
if props != "击剑神器" && props != "击剑神稽" {
return "", 0, errors.New("道具不存在")
}
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)
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)
myniuniu.Length = f
updateMap(t, true)
case myniuniu.Artifact-u.Artifact != 0:
fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length)
myniuniu.Length = f
updateMap(t, true)
default:
fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length)
myniuniu.Length = f
}
return fencingResult, f1, err
}
func processNiuniuAction(t string, niuniu *userInfo, props string) (string, error) {
var (
messages string
u userInfo
err error
f float64
)
load, ok := prop.Load(t)
u = *niuniu
if props != "" {
if props != "伟哥" && props != "媚药" {
return "", errors.New("道具不存在")
}

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)
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()
niuniu.Length = f
updateMap(t, true)

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

default:
messages, f = generateRandomStingTwo(niuniu.Length)
niuniu.Length = f
}
return messages, err
}

func purchaseItem(n int, info userInfo) (int, error) {
var (
money int
err error
)
switch n {
case 1:
money = 300
info.WeiGe += 5
case 2:
money = 300
info.Philter += 5
case 3:
money = 500
info.Artifact += 2
case 4:
money = 500
info.ShenJi += 2
default:
err = errors.New("无效的选择")
}
return money, err
}
var (
jjProp = []string{"击剑神器", "击剑神稽"}
dajiaoProp = []string{"伟哥", "媚药"}
)

func generateRandomStingTwo(niuniu float64) (string, float64) {
probability := rand.Intn(100 + 1)
Expand Down Expand Up @@ -342,3 +205,13 @@ func hitGlue(l float64) float64 {
return rand.Float64()
}
}

// 检查字符串是否在切片中
func contains(s string, array []string) bool {
for _, item := range array {
if strings.EqualFold(item, s) {
return true
}
}
return false
}

0 comments on commit 410dd05

Please sign in to comment.