Skip to content

Commit c008214

Browse files
authored
fix: 牛牛为负数时jj时的错误 (#984)
1 parent 54471d1 commit c008214

3 files changed

Lines changed: 29 additions & 18 deletions

File tree

plugin/niuniu/main.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func init() {
106106
for {
107107
select {
108108
case <-timer.C:
109-
ctx.SendChain(message.At(uid), message.Text("超时,已自动取消"))
109+
ctx.SendChain(message.At(uid), message.Text(" 超时,已自动取消"))
110110
return
111111
case r := <-recv:
112112
answer = r.Event.Message.String()
@@ -122,7 +122,7 @@ func init() {
122122
return
123123
}
124124

125-
u, money, err := purchaseItem(n, info)
125+
money, err := purchaseItem(n, info)
126126
if err != nil {
127127
ctx.SendChain(message.Text("ERROR:", err))
128128
return
@@ -138,7 +138,7 @@ func init() {
138138
return
139139
}
140140

141-
if err = db.insertNiuNiu(u, gid); err != nil {
141+
if err = db.insertNiuNiu(&info, gid); err != nil {
142142
ctx.SendChain(message.Text("ERROR:", err))
143143
return
144144
}
@@ -266,7 +266,7 @@ func init() {
266266
result.WriteString(fmt.Sprintf("\n📛%s<%s>的牛牛信息\n⭕性别:%s\n⭕%s度:%.2fcm\n⭕排行:%d\n⭕%s ",
267267
ctx.CardOrNickName(uid), strconv.FormatInt(uid, 10),
268268
sex, sexLong, niuniu, niuniuList.ranking(niuniu, uid), generateRandomString(niuniu)))
269-
ctx.SendChain(message.At(uid), message.Text(&result))
269+
ctx.SendChain(message.Text(&result))
270270
})
271271
en.OnRegex(`^(?:.*使用(.*))??打胶$`, zero.OnlyGroup,
272272
getdb).SetBlock(true).Limit(func(ctx *zero.Ctx) *rate.Limiter {
@@ -288,22 +288,25 @@ func init() {
288288
t := fmt.Sprintf("%d_%d", gid, uid)
289289
fiancee := ctx.State["regex_matched"].([]string)
290290
updateMap(t, false)
291+
291292
niuniu, err := db.findNiuNiu(gid, uid)
292293
if err != nil {
293294
ctx.SendChain(message.Text("请先注册牛牛!"))
294295
dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
295296
return
296297
}
297-
messages, err := processNiuniuAction(t, niuniu, fiancee[1])
298+
299+
messages, err := processNiuniuAction(t, &niuniu, fiancee[1])
298300
if err != nil {
299301
ctx.SendChain(message.Text(err))
300302
return
301303
}
302-
ctx.SendChain(message.Text(messages))
303304
if err = db.insertNiuNiu(&niuniu, gid); err != nil {
304305
ctx.SendChain(message.Text("ERROR:", err))
305306
return
306307
}
308+
309+
ctx.SendChain(message.Text(messages))
307310
})
308311
en.OnFullMatch("注册牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
309312
gid := ctx.Event.GroupID
@@ -375,7 +378,7 @@ func init() {
375378
jjLimiter.Delete(t)
376379
return
377380
}
378-
fencingResult, f1, err := processJJuAction(myniuniu, adduserniuniu, t, fiancee[1])
381+
fencingResult, f1, err := processJJuAction(&myniuniu, &adduserniuniu, t, fiancee[1])
379382
if err != nil {
380383
ctx.SendChain(message.Text(err))
381384
return

plugin/niuniu/model.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ type userInfo struct {
2929
Philter int // 媚药
3030
Artifact int // 击剑神器
3131
ShenJi int // 击剑神稽
32+
Buff1 int // 暂定
33+
Buff2 int // 暂定
34+
Buff3 int // 暂定
35+
Buff4 int // 暂定
36+
Buff5 int // 暂定
3237
}
3338

3439
type users []*userInfo

plugin/niuniu/utils.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010
)
1111

12-
func createUserInfoByProps(props string, niuniu userInfo) error {
12+
func createUserInfoByProps(props string, niuniu *userInfo) error {
1313
var (
1414
err error
1515
)
@@ -46,7 +46,7 @@ func createUserInfoByProps(props string, niuniu userInfo) error {
4646

4747
// 接收值依次是 自己和被jj用户的信息 一个包含gid和uid的字符串 道具名称
4848
// 返回值依次是 要发生的消息 错误信息
49-
func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string) (string, float64, error) {
49+
func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) (string, float64, error) {
5050
var (
5151
fencingResult string
5252
f float64
@@ -55,7 +55,7 @@ func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string)
5555
err error
5656
)
5757
v, ok := prop.Load(t)
58-
u = myniuniu
58+
u = *myniuniu
5959
if props != "" {
6060
if props != "击剑神器" && props != "击剑神稽" {
6161
return "", 0, errors.New("道具不存在")
@@ -84,15 +84,15 @@ func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string)
8484
}
8585
return fencingResult, f1, err
8686
}
87-
func processNiuniuAction(t string, niuniu userInfo, props string) (string, error) {
87+
func processNiuniuAction(t string, niuniu *userInfo, props string) (string, error) {
8888
var (
8989
messages string
90-
f float64
9190
u userInfo
9291
err error
92+
f float64
9393
)
9494
load, ok := prop.Load(t)
95-
u = niuniu
95+
u = *niuniu
9696
if props != "" {
9797
if props != "伟哥" && props != "媚药" {
9898
return "", errors.New("道具不存在")
@@ -126,7 +126,7 @@ func processNiuniuAction(t string, niuniu userInfo, props string) (string, error
126126
return messages, err
127127
}
128128

129-
func purchaseItem(n int, info userInfo) (*userInfo, int, error) {
129+
func purchaseItem(n int, info userInfo) (int, error) {
130130
var (
131131
money int
132132
err error
@@ -147,7 +147,7 @@ func purchaseItem(n int, info userInfo) (*userInfo, int, error) {
147147
default:
148148
err = errors.New("无效的选择")
149149
}
150-
return &info, money, err
150+
return money, err
151151
}
152152

153153
func generateRandomStingTwo(niuniu float64) (string, float64) {
@@ -293,6 +293,7 @@ func calculateWinProbability(heightA, heightB float64) float64 {
293293
// applySkill 应用击剑技巧并生成结果
294294
func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, float64, float64) {
295295
reduce := fence(oppoLength)
296+
//兜底操作
296297
if reduce == 0 {
297298
reduce = rand.Float64() + float64(rand.Intn(3))
298299
}
@@ -314,10 +315,12 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo
314315

315316
// fence 根据长度计算减少的长度
316317
func fence(rd float64) float64 {
317-
r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd)
318-
if rand.Intn(2) == 1 {
319-
return rd - rand.Float64()*r
318+
rd = math.Abs(rd)
319+
if rd == 0 {
320+
rd = 1
320321
}
322+
r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd)
323+
321324
return float64(int(r * rand.Float64()))
322325
}
323326

0 commit comments

Comments
 (0)