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

修改牛牛大作战的部分问题,添加新玩法赎牛牛 #970

Merged
merged 12 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] jj[@xxx]

- [x] 赎牛牛

- [x] 注册牛牛

- [x] 注销牛牛
Expand Down
90 changes: 84 additions & 6 deletions plugin/niuniu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@ import (
"strings"
"time"

"github.com/FloatTech/AnimeAPI/wallet"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/RomiChan/syncx"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
)

type lastLength struct {
TimeLimit time.Time
Count int
Length float64
}

var (
en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "牛牛大作战",
Help: "- 打胶\n" +
"- 赎牛牛 (cd:30分钟)\n" +
"- 注册牛牛\n" +
"- 注销牛牛\n" +
"- 查看我的牛牛\n" +
Expand All @@ -31,9 +40,50 @@ var (
})
dajiaoLimiter = rate.NewManager[string](time.Second*90, 1)
jjLimiter = rate.NewManager[string](time.Second*150, 1)
jjCount = syncx.Map[string, *lastLength]{}
)

func init() {
en.OnFullMatch("赎牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
last, ok := jjCount.Load(fmt.Sprintf("%d_%d", gid, uid))
if !ok {
ctx.SendChain(message.Text("你还没有被厥呢"))
return
}
if time.Since(last.TimeLimit) > time.Minute*30 {
ctx.SendChain(message.Text("时间已经过期了,牛牛已被收回!"))
jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid))
return
}
if last.Count < 6 {
ctx.SendChain(message.Text("你还没有被厥够6次呢,不能赎牛牛"))
return
}
money := wallet.GetWalletOf(uid)
if money < 100 {
ctx.SendChain(message.Text("赎牛牛需要100ATRI币,快去赚钱吧"))
return
}
err := wallet.InsertWalletOf(uid, -100)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
u := &userInfo{
UID: uid,
Length: last.Length,
UserCount: 0,
}
err = db.insertniuniu(u, gid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid))
ctx.SendChain(message.At(uid), message.Text(fmt.Sprintf("恭喜你!成功赎回牛牛,当前长度为:%.2fcm", last.Length)))
})
en.OnFullMatch("牛子长度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
niuniuList, err := db.readAllTable(gid)
Expand All @@ -47,8 +97,8 @@ func init() {
return
}
var messages strings.Builder
messages.WriteString("牛子长度排行\n")
for i, user := range niuniuList.sort(true) {
messages.WriteString("牛子长度排行榜\n")
for i, user := range m.sort(true) {
messages.WriteString(fmt.Sprintf("第%d名 id:%s 长度:%.2fcm\n", i+1,
ctx.CardOrNickName(user.UID), user.Length))
}
Expand All @@ -71,7 +121,7 @@ func init() {
}
var messages strings.Builder
messages.WriteString("牛牛深度排行榜\n")
for i, user := range niuniuList.sort(false) {
for i, user := range m.sort(false) {
messages.WriteString(fmt.Sprintf("第%d名 id:%s 长度:%.2fcm\n", i+1,
ctx.CardOrNickName(user.UID), user.Length))
}
Expand Down Expand Up @@ -210,17 +260,45 @@ func init() {
return
}
fencingResult, f, f1 := fencing(myniuniu, adduserniuniu)
err = db.insertniuniu(&userInfo{UID: uid, Length: f}, gid)
err = db.insertniuniu(&userInfo{UID: uid, Length: f, UserCount: 0}, gid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
err = db.insertniuniu(&userInfo{UID: adduser, Length: f1}, gid)
err = db.insertniuniu(&userInfo{UID: adduser, Length: f1, UserCount: 0}, gid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
ctx.SendChain(message.At(uid), message.Text(fencingResult))
ctx.SendChain(message.At(uid), message.Text(" ", fencingResult))
j := fmt.Sprintf("%d_%d", gid, adduser)
count, ok := jjCount.Load(j)
var c lastLength
if !ok {
c = lastLength{
TimeLimit: time.Now(),
Count: 1,
Length: adduserniuniu,
}
} else {
c = lastLength{
TimeLimit: c.TimeLimit,
Count: count.Count + 1,
Length: count.Length,
}
}
jjCount.Store(j, &c)
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)))
if id == 0 {
ctx.SendChain(message.At(adduser), message.Text("快发送`赎牛牛`来赎回你原本的牛牛!"))
}
}
}
})
en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
Expand Down
15 changes: 8 additions & 7 deletions plugin/niuniu/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type userInfo struct {
Length float64
UserCount int
}

type users []*userInfo

var (
Expand All @@ -39,29 +40,29 @@ var (
})
)

func (m users) positive() []userInfo {
var m1 []userInfo
func (m users) positive() users {
var m1 []*userInfo
for _, i2 := range m {
if i2.Length > 0 {
m1 = append(m1, *i2)
m1 = append(m1, i2)
}
}
return m1
}

func (m users) negative() []userInfo {
var m1 []userInfo
func (m users) negative() users {
var m1 []*userInfo
for _, i2 := range m {
if i2.Length <= 0 {
m1 = append(m1, *i2)
m1 = append(m1, i2)
}
}
return m1
}

func (m users) sort(isDesc bool) users {
t := func(i, j int) bool {
return m[i].UserCount < m[j].UserCount
return m[i].Length < m[j].Length
}
if isDesc {
t = func(i, j int) bool {
Expand Down
17 changes: 9 additions & 8 deletions plugin/niuniu/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,26 @@ func fencing(myLength, oppoLength float64) (string, float64, float64) {
switch {
case oppoLength <= -100 && myLength > 0 && 10 < probability && probability <= 20:
oppoLength *= 0.85
change := -math.Min(math.Abs(lossLimit*myLength), math.Abs(1.5*myLength))
change := math.Min(math.Abs(lossLimit*myLength), math.Abs(1.5*myLength))
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:
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
return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength
return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength-oppoLength), myLength - oppoLength, oppoLength

case myLength <= -100 && oppoLength > 0 && 10 < probability && probability <= 20:
myLength *= 0.85
change := math.Min(math.Abs(lossLimit*oppoLength), math.Abs(1.5*oppoLength))
change := oppoLength * 0.7
oppoLength -= change
myLength -= change
return fmt.Sprintf("你身为魅魔诱惑了对方,吞噬了对方部分长度!当前长度%.2fcm!", myLength), myLength, oppoLength

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

default:
return determineResultBySkill(myLength, oppoLength)
}
Expand Down Expand Up @@ -166,13 +165,15 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo
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
Expand Down
Loading