Skip to content

Commit 863f99c

Browse files
authored
fix&feat(niuniu): 添加新玩法赎牛牛 (#970)
1 parent badd65a commit 863f99c

File tree

4 files changed

+103
-21
lines changed

4 files changed

+103
-21
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,8 @@ print("run[CQ:image,file="+j["img"]+"]")
10371037

10381038
- [x] jj[@xxx]
10391039

1040+
- [x] 赎牛牛
1041+
10401042
- [x] 注册牛牛
10411043

10421044
- [x] 注销牛牛

plugin/niuniu/main.go

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,28 @@ import (
88
"strings"
99
"time"
1010

11+
"github.com/FloatTech/AnimeAPI/wallet"
1112
ctrl "github.com/FloatTech/zbpctrl"
1213
"github.com/FloatTech/zbputils/control"
1314
"github.com/FloatTech/zbputils/ctxext"
15+
"github.com/RomiChan/syncx"
1416
zero "github.com/wdvxdr1123/ZeroBot"
1517
"github.com/wdvxdr1123/ZeroBot/extension/rate"
1618
"github.com/wdvxdr1123/ZeroBot/message"
1719
)
1820

21+
type lastLength struct {
22+
TimeLimit time.Time
23+
Count int
24+
Length float64
25+
}
26+
1927
var (
2028
en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
2129
DisableOnDefault: false,
2230
Brief: "牛牛大作战",
2331
Help: "- 打胶\n" +
32+
"- 赎牛牛 (cd:30分钟)\n" +
2433
"- 注册牛牛\n" +
2534
"- 注销牛牛\n" +
2635
"- 查看我的牛牛\n" +
@@ -31,9 +40,50 @@ var (
3140
})
3241
dajiaoLimiter = rate.NewManager[string](time.Second*90, 1)
3342
jjLimiter = rate.NewManager[string](time.Second*150, 1)
43+
jjCount = syncx.Map[string, *lastLength]{}
3444
)
3545

3646
func init() {
47+
en.OnFullMatch("赎牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
48+
gid := ctx.Event.GroupID
49+
uid := ctx.Event.UserID
50+
last, ok := jjCount.Load(fmt.Sprintf("%d_%d", gid, uid))
51+
if !ok {
52+
ctx.SendChain(message.Text("你还没有被厥呢"))
53+
return
54+
}
55+
if time.Since(last.TimeLimit) > time.Minute*30 {
56+
ctx.SendChain(message.Text("时间已经过期了,牛牛已被收回!"))
57+
jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid))
58+
return
59+
}
60+
if last.Count < 6 {
61+
ctx.SendChain(message.Text("你还没有被厥够6次呢,不能赎牛牛"))
62+
return
63+
}
64+
money := wallet.GetWalletOf(uid)
65+
if money < 100 {
66+
ctx.SendChain(message.Text("赎牛牛需要100ATRI币,快去赚钱吧"))
67+
return
68+
}
69+
err := wallet.InsertWalletOf(uid, -100)
70+
if err != nil {
71+
ctx.SendChain(message.Text("ERROR:", err))
72+
return
73+
}
74+
u := &userInfo{
75+
UID: uid,
76+
Length: last.Length,
77+
UserCount: 0,
78+
}
79+
err = db.insertniuniu(u, gid)
80+
if err != nil {
81+
ctx.SendChain(message.Text("ERROR:", err))
82+
return
83+
}
84+
jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid))
85+
ctx.SendChain(message.At(uid), message.Text(fmt.Sprintf("恭喜你!成功赎回牛牛,当前长度为:%.2fcm", last.Length)))
86+
})
3787
en.OnFullMatch("牛子长度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
3888
gid := ctx.Event.GroupID
3989
niuniuList, err := db.readAllTable(gid)
@@ -47,8 +97,8 @@ func init() {
4797
return
4898
}
4999
var messages strings.Builder
50-
messages.WriteString("牛子长度排行\n")
51-
for i, user := range niuniuList.sort(true) {
100+
messages.WriteString("牛子长度排行榜\n")
101+
for i, user := range m.sort(true) {
52102
messages.WriteString(fmt.Sprintf("第%d名 id:%s 长度:%.2fcm\n", i+1,
53103
ctx.CardOrNickName(user.UID), user.Length))
54104
}
@@ -71,7 +121,7 @@ func init() {
71121
}
72122
var messages strings.Builder
73123
messages.WriteString("牛牛深度排行榜\n")
74-
for i, user := range niuniuList.sort(false) {
124+
for i, user := range m.sort(false) {
75125
messages.WriteString(fmt.Sprintf("第%d名 id:%s 长度:%.2fcm\n", i+1,
76126
ctx.CardOrNickName(user.UID), user.Length))
77127
}
@@ -210,17 +260,45 @@ func init() {
210260
return
211261
}
212262
fencingResult, f, f1 := fencing(myniuniu, adduserniuniu)
213-
err = db.insertniuniu(&userInfo{UID: uid, Length: f}, gid)
263+
err = db.insertniuniu(&userInfo{UID: uid, Length: f, UserCount: 0}, gid)
214264
if err != nil {
215265
ctx.SendChain(message.Text("ERROR:", err))
216266
return
217267
}
218-
err = db.insertniuniu(&userInfo{UID: adduser, Length: f1}, gid)
268+
err = db.insertniuniu(&userInfo{UID: adduser, Length: f1, UserCount: 0}, gid)
219269
if err != nil {
220270
ctx.SendChain(message.Text("ERROR:", err))
221271
return
222272
}
223-
ctx.SendChain(message.At(uid), message.Text(fencingResult))
273+
ctx.SendChain(message.At(uid), message.Text(" ", fencingResult))
274+
j := fmt.Sprintf("%d_%d", gid, adduser)
275+
count, ok := jjCount.Load(j)
276+
var c lastLength
277+
if !ok {
278+
c = lastLength{
279+
TimeLimit: time.Now(),
280+
Count: 1,
281+
Length: adduserniuniu,
282+
}
283+
} else {
284+
c = lastLength{
285+
TimeLimit: c.TimeLimit,
286+
Count: count.Count + 1,
287+
Length: count.Length,
288+
}
289+
}
290+
jjCount.Store(j, &c)
291+
if c.Count > 5 {
292+
ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count),
293+
"你们不要再找ta🤺啦!"})))
294+
if c.Count < 7 {
295+
id := ctx.SendPrivateMessage(adduser,
296+
message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid)))
297+
if id == 0 {
298+
ctx.SendChain(message.At(adduser), message.Text("快发送`赎牛牛`来赎回你原本的牛牛!"))
299+
}
300+
}
301+
}
224302
})
225303
en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
226304
uid := ctx.Event.UserID

plugin/niuniu/model.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type userInfo struct {
2424
Length float64
2525
UserCount int
2626
}
27+
2728
type users []*userInfo
2829

2930
var (
@@ -39,29 +40,29 @@ var (
3940
})
4041
)
4142

42-
func (m users) positive() []userInfo {
43-
var m1 []userInfo
43+
func (m users) positive() users {
44+
var m1 []*userInfo
4445
for _, i2 := range m {
4546
if i2.Length > 0 {
46-
m1 = append(m1, *i2)
47+
m1 = append(m1, i2)
4748
}
4849
}
4950
return m1
5051
}
5152

52-
func (m users) negative() []userInfo {
53-
var m1 []userInfo
53+
func (m users) negative() users {
54+
var m1 []*userInfo
5455
for _, i2 := range m {
5556
if i2.Length <= 0 {
56-
m1 = append(m1, *i2)
57+
m1 = append(m1, i2)
5758
}
5859
}
5960
return m1
6061
}
6162

6263
func (m users) sort(isDesc bool) users {
6364
t := func(i, j int) bool {
64-
return m[i].UserCount < m[j].UserCount
65+
return m[i].Length < m[j].Length
6566
}
6667
if isDesc {
6768
t = func(i, j int) bool {

plugin/niuniu/utils.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,26 @@ func fencing(myLength, oppoLength float64) (string, float64, float64) {
107107
switch {
108108
case oppoLength <= -100 && myLength > 0 && 10 < probability && probability <= 20:
109109
oppoLength *= 0.85
110-
change := -math.Min(math.Abs(lossLimit*myLength), math.Abs(1.5*myLength))
110+
change := math.Min(math.Abs(lossLimit*myLength), math.Abs(1.5*myLength))
111111
myLength += change
112-
return fmt.Sprintf("对方身为魅魔诱惑了你,你同化成魅魔!当前长度%.2fcm!", myLength), myLength, oppoLength
112+
return fmt.Sprintf("对方身为魅魔诱惑了你,你同化成魅魔!当前长度%.2fcm!", -myLength), -myLength, oppoLength
113113
case oppoLength >= 100 && myLength > 0 && 10 < probability && probability <= 20:
114114
oppoLength *= 0.85
115-
change := -math.Min(math.Abs(devourLimit*myLength), math.Abs(1.5*myLength))
115+
change := math.Min(math.Abs(devourLimit*myLength), math.Abs(1.5*myLength))
116116
myLength += change
117-
return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength
117+
return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength-oppoLength), myLength - oppoLength, oppoLength
118118

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

125126
case myLength >= 100 && oppoLength > 0 && 10 < probability && probability <= 20:
126127
myLength *= 0.85
127-
change := math.Min(math.Abs(devourLimit*oppoLength), math.Abs(1.5*oppoLength))
128-
oppoLength += change
128+
oppoLength -= 0.8 * myLength
129129
return fmt.Sprintf("你以牛头人的荣誉摧毁了对方的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength
130-
131130
default:
132131
return determineResultBySkill(myLength, oppoLength)
133132
}
@@ -166,13 +165,15 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo
166165
return fmt.Sprintf("哦吼!?你的牛牛在长大欸!长大了%.2fcm!", reduce), myLength, oppoLength
167166
}
168167
return fmt.Sprintf("你以绝对的长度让对方屈服了呢!你的长度增加%.2fcm,当前长度%.2fcm!", reduce, myLength), myLength, oppoLength
168+
169169
}
170170
myLength -= reduce
171171
oppoLength += 0.8 * reduce
172172
if myLength < 0 {
173173
return fmt.Sprintf("哦吼!?看来你的牛牛因为击剑而凹进去了呢🤣🤣🤣!凹进去了%.2fcm!", reduce), myLength, oppoLength
174174
}
175175
return fmt.Sprintf("对方以绝对的长度让你屈服了呢!你的长度减少%.2fcm,当前长度%.2fcm!", reduce, myLength), myLength, oppoLength
176+
176177
}
177178

178179
// fence

0 commit comments

Comments
 (0)