fix&feat(niuniu): 添加新玩法赎牛牛 (#970)

This commit is contained in:
小宇宇 2024-09-03 23:22:09 +08:00 committed by GitHub
parent badd65a207
commit 863f99cb05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 103 additions and 21 deletions

View File

@ -1037,6 +1037,8 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] jj[@xxx]
- [x] 赎牛牛
- [x] 注册牛牛
- [x] 注销牛牛

View File

@ -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" +
"- 赎牛牛 cd30分钟\n" +
"- 注册牛牛\n" +
"- 注销牛牛\n" +
"- 查看我的牛牛\n" +
@ -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)
@ -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))
}
@ -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))
}
@ -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

View File

@ -24,6 +24,7 @@ type userInfo struct {
Length float64
UserCount int
}
type users []*userInfo
var (
@ -39,21 +40,21 @@ 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
@ -61,7 +62,7 @@ func (m users) negative() []userInfo {
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 {

View File

@ -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)
}
@ -166,6 +165,7 @@ 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
@ -173,6 +173,7 @@ 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
}
// fence