Skip to content

Commit 9c7f64e

Browse files
committed
抽老婆下载失败时使用本地文件,修复钓鱼概率问题,修改梭哈合成方式,删除娶群友多余文本.
Use local probabilities to avoid global state issues Refactor to use local variables for probabilities in fishing logic to prevent global state issues in multiplayer scenarios. Refactor synthesis process for grouped materials Refactor synthesis logic to group materials and determine success rate individually. Update database and construct result message based on synthesis outcomes. Update function.go Improve error handling and logging for wife data Implement fallback for image loading in wifegame Added a fallback mechanism for loading images in the guessing game, attempting local file retrieval if remote download fails. Fix error message for image generation failure 更新 fish.go 更新 wifegame.go 更新 main.go 更新 pole.go 更新 pole.go 更新 fish.go 更新 main.go 更新 wifegame.go Refactor upgrade logic and improve reporting Refactor synthesis handling for fishing rods 待定
1 parent 992204d commit 9c7f64e

File tree

5 files changed

+105
-46
lines changed

5 files changed

+105
-46
lines changed

plugin/mcfish/fish.go

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -171,45 +171,51 @@ func init() {
171171
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
172172
return
173173
}
174+
175+
localProbabilities := make(map[string]probabilityLimit, len(probabilities))
176+
for k, v := range probabilities {
177+
localProbabilities[k] = v
178+
}
179+
174180
if number > 100 || equipInfo.Equip == "美西螈" { // 放大概率
175-
probabilities["treasure"] = probabilityLimit{
181+
localProbabilities["treasure"] = probabilityLimit{
176182
Min: 0,
177183
Max: 2,
178184
}
179-
probabilities["pole"] = probabilityLimit{
185+
localProbabilities["pole"] = probabilityLimit{
180186
Min: 2,
181187
Max: 10,
182188
}
183-
probabilities["fish"] = probabilityLimit{
189+
localProbabilities["fish"] = probabilityLimit{
184190
Min: 10,
185191
Max: 45,
186192
}
187-
probabilities["waste"] = probabilityLimit{
193+
localProbabilities["waste"] = probabilityLimit{
188194
Min: 45,
189195
Max: 90,
190196
}
191197
}
192198
if number2 != 0 {
193-
info := probabilities["waste"]
199+
info := localProbabilities["waste"]
194200
info.Max = 100
195-
probabilities["waste"] = info
201+
localProbabilities["waste"] = info
196202
}
197-
for name, info := range probabilities {
203+
for name, info := range localProbabilities {
198204
switch name {
199205
case "treasure":
200206
info.Max += equipInfo.Favor
201-
probabilities[name] = info
207+
localProbabilities[name] = info
202208
case "pole":
203209
info.Min += equipInfo.Favor
204210
info.Max += equipInfo.Favor * 2
205-
probabilities[name] = info
211+
localProbabilities[name] = info
206212
case "fish":
207213
info.Min += equipInfo.Favor * 2
208214
info.Max += equipInfo.Favor * 3
209-
probabilities[name] = info
215+
localProbabilities[name] = info
210216
case "waste":
211217
info.Min += equipInfo.Favor * 3
212-
probabilities[name] = info
218+
localProbabilities[name] = info
213219
}
214220
}
215221
// 钓鱼结算
@@ -221,34 +227,34 @@ func init() {
221227
number := 1
222228
dice := rand.Intn(100)
223229
switch {
224-
case dice >= probabilities["waste"].Min && dice < probabilities["waste"].Max: // 垃圾
230+
case dice >= localProbabilities["waste"].Min && dice < localProbabilities["waste"].Max: // 垃圾
225231
typeOfThing = "waste"
226232
thingName = wasteList[rand.Intn(len(wasteList))]
227233
picName = thingName
228-
case dice >= probabilities["treasure"].Min && dice < probabilities["treasure"].Max: // 宝藏
234+
case dice >= localProbabilities["treasure"].Min && dice < localProbabilities["treasure"].Max: // 宝藏
229235
dice = rand.Intn(100)
230236
switch {
231-
case dice >= probabilities["美西螈"].Min && dice < probabilities["美西螈"].Max:
237+
case dice >= localProbabilities["美西螈"].Min && dice < localProbabilities["美西螈"].Max:
232238
typeOfThing = "pole"
233239
picName = "美西螈"
234240
thingName = "美西螈"
235-
case dice >= probabilities["唱片"].Min && dice < probabilities["唱片"].Max:
241+
case dice >= localProbabilities["唱片"].Min && dice < localProbabilities["唱片"].Max:
236242
typeOfThing = "article"
237243
picName = "唱片"
238244
thingName = "唱片"
239-
case dice >= probabilities["海之眷顾"].Min && dice < probabilities["海之眷顾"].Max:
245+
case dice >= localProbabilities["海之眷顾"].Min && dice < localProbabilities["海之眷顾"].Max:
240246
typeOfThing = "article"
241247
picName = "book"
242248
thingName = "海之眷顾"
243-
case dice >= probabilities["净化书"].Min && dice < probabilities["净化书"].Max:
249+
case dice >= localProbabilities["净化书"].Min && dice < localProbabilities["净化书"].Max:
244250
typeOfThing = "article"
245251
picName = "book"
246252
thingName = "净化书"
247-
case dice >= probabilities["宝藏诅咒"].Min && dice < probabilities["宝藏诅咒"].Max:
253+
case dice >= localProbabilities["宝藏诅咒"].Min && dice < localProbabilities["宝藏诅咒"].Max:
248254
typeOfThing = "article"
249255
picName = "book"
250256
thingName = "宝藏诅咒"
251-
case dice >= probabilities["海豚"].Min && dice < probabilities["海豚"].Max:
257+
case dice >= localProbabilities["海豚"].Min && dice < localProbabilities["海豚"].Max:
252258
typeOfThing = "fish"
253259
picName = "海豚"
254260
thingName = "海豚"
@@ -257,35 +263,35 @@ func init() {
257263
picName = "book"
258264
thingName = "诱钓"
259265
}
260-
case dice >= probabilities["pole"].Min && dice < probabilities["pole"].Max: // 宝藏
266+
case dice >= localProbabilities["pole"].Min && dice < localProbabilities["pole"].Max: // 鱼竿
261267
typeOfThing = "pole"
262268
dice := rand.Intn(100)
263269
switch {
264-
case dice >= probabilities["铁竿"].Min && dice < probabilities["铁竿"].Max:
270+
case dice >= localProbabilities["铁竿"].Min && dice < localProbabilities["铁竿"].Max:
265271
thingName = "铁竿"
266-
case dice >= probabilities["金竿"].Min && dice < probabilities["金竿"].Max:
272+
case dice >= localProbabilities["金竿"].Min && dice < localProbabilities["金竿"].Max:
267273
thingName = "金竿"
268-
case dice >= probabilities["钻石竿"].Min && dice < probabilities["钻石竿"].Max:
274+
case dice >= localProbabilities["钻石竿"].Min && dice < localProbabilities["钻石竿"].Max:
269275
thingName = "钻石竿"
270-
case dice >= probabilities["下界合金竿"].Min && dice < probabilities["下界合金竿"].Max:
276+
case dice >= localProbabilities["下界合金竿"].Min && dice < localProbabilities["下界合金竿"].Max:
271277
thingName = "下界合金竿"
272278
default:
273279
thingName = "木竿"
274280
}
275281
picName = thingName
276-
case dice >= probabilities["fish"].Min && dice < probabilities["fish"].Max:
282+
case dice >= localProbabilities["fish"].Min && dice < localProbabilities["fish"].Max: // 鱼类
277283
typeOfThing = "fish"
278284
dice = rand.Intn(100)
279285
switch {
280-
case dice >= probabilities["墨鱼"].Min && dice < probabilities["墨鱼"].Max:
286+
case dice >= localProbabilities["墨鱼"].Min && dice < localProbabilities["墨鱼"].Max:
281287
thingName = "墨鱼"
282-
case dice >= probabilities["鳕鱼"].Min && dice < probabilities["鳕鱼"].Max:
288+
case dice >= localProbabilities["鳕鱼"].Min && dice < localProbabilities["鳕鱼"].Max:
283289
thingName = "鳕鱼"
284-
case dice >= probabilities["鲑鱼"].Min && dice < probabilities["鲑鱼"].Max:
290+
case dice >= localProbabilities["鲑鱼"].Min && dice < localProbabilities["鲑鱼"].Max:
285291
thingName = "鲑鱼"
286-
case dice >= probabilities["热带鱼"].Min && dice < probabilities["热带鱼"].Max:
292+
case dice >= localProbabilities["热带鱼"].Min && dice < localProbabilities["热带鱼"].Max:
287293
thingName = "热带鱼"
288-
case dice >= probabilities["河豚"].Min && dice < probabilities["河豚"].Max:
294+
case dice >= localProbabilities["河豚"].Min && dice < localProbabilities["河豚"].Max:
289295
thingName = "河豚"
290296
default:
291297
thingName = "鹦鹉螺"

plugin/mcfish/pole.go

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,59 @@ func init() {
419419
return
420420
}
421421
if nextcmd == "梭哈" {
422-
// len(list)取3的倍数,表示能够用于合成鱼竿的最大数量,note:此处未对article.Number>1的情况做处理
423-
for i := 3; i < (len(articles)/3)*3; i++ {
424-
list = append(list, i)
422+
totalBatches := maxCount / 3
423+
success := 0
424+
fail := 0
425+
for batch := 0; batch < totalBatches; batch++ {
426+
base := batch * 3
427+
indices := []int{base, base + 1, base + 2}
428+
sumInduce := 0
429+
sumFavor := 0
430+
for _, idx := range indices {
431+
sumInduce += poles[idx].Induce
432+
sumFavor += poles[idx].Favor
433+
}
434+
avgInduce := sumInduce / 3
435+
avgFavor := sumFavor / 3
436+
for _, idx := range indices {
437+
thingInfo := articles[idx]
438+
thingInfo.Number = 0
439+
err = dbdata.updateUserThingInfo(uid, thingInfo)
440+
if err != nil {
441+
ctx.SendChain(message.Text("[ERROR at pole.go.12]:", err))
442+
return
443+
}
444+
}
445+
if rand.Intn(100) < 90 {
446+
attribute := strconv.Itoa(durationList[thingName]) + "/0/" + strconv.Itoa(avgInduce) + "/" + strconv.Itoa(avgFavor)
447+
newthing := article{
448+
Duration: time.Now().Unix() + int64(batch*10),
449+
Type: "pole",
450+
Name: thingName,
451+
Number: 1,
452+
Other: attribute,
453+
}
454+
err = dbdata.updateUserThingInfo(uid, newthing)
455+
if err != nil {
456+
ctx.SendChain(message.Text("[ERROR at pole.go.12]:", err))
457+
return
458+
}
459+
success++
460+
} else {
461+
fail++
462+
}
425463
}
426-
check = true
427-
break
464+
remaining := maxCount % 3
465+
msgText := "合成完成,成功:" + strconv.Itoa(success) + " 个,失败:" + strconv.Itoa(fail) + " 个"
466+
if remaining > 0 {
467+
msgText += ",剩余 " + strconv.Itoa(remaining) + " 根材料未参与合成"
468+
}
469+
ctx.Send(
470+
message.ReplyWithMessage(ctx.Event.MessageID,
471+
message.Text(msgText),
472+
),
473+
)
474+
return
428475
}
429476
chooseList := strings.Split(nextcmd, " ")
430477
first, err := strconv.Atoi(chooseList[0])

plugin/qqwife/function.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ func init() {
162162
message.Text(
163163
"\n",
164164
"[", ctx.CardOrNickName(fiancee), "]",
165-
"(", fiancee, ")哒",
166165
"(", fiancee, ")哒\n当前你们好感度为", favor,
167166
),
168167
)

plugin/wife/main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@ var (
2929
func(ctx *zero.Ctx) bool {
3030
data, err := engine.GetLazyData("wife.json", true)
3131
if err != nil {
32-
ctx.SendChain(message.Text("ERROR: ", err))
33-
return false
32+
logrus.Warnf("[wife] 远程同步 wife.json 失败: %v,正在尝试读取本地缓存...", err)
33+
data, err = engine.GetLazyData("wife.json", false)
34+
if err != nil {
35+
ctx.SendChain(message.Text("ERROR: 无法获取老婆库数据(同步及本地读取均失败): ", err))
36+
return false
37+
}
3438
}
3539
err = json.Unmarshal(data, &cards)
3640
if err != nil {
37-
ctx.SendChain(message.Text("ERROR: ", err))
41+
ctx.SendChain(message.Text("ERROR: 老婆库格式解析失败: ", err))
3842
return false
3943
}
40-
logrus.Infof("[wife]加载%d个老婆", len(cards))
44+
logrus.Infof("[wife] 已成功加载 %d 个老婆", len(cards))
4145
return true
4246
},
4347
)

plugin/wife/wifegame.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/wdvxdr1123/ZeroBot/message"
1616

1717
"github.com/FloatTech/imgfactory"
18+
"github.com/sirupsen/logrus"
1819
)
1920

2021
var (
@@ -33,22 +34,26 @@ func init() {
3334
card := cards[rand.Intn(len(cards))]
3435
pic, err := engine.GetLazyData("wives/"+card, true)
3536
if err != nil {
36-
ctx.SendChain(message.Text("[猜老婆]error:\n", err))
37-
return
37+
logrus.Warnf("[wife] 猜老婆图片同步失败: %v,尝试读取本地文件...", err)
38+
pic, err = engine.GetLazyData("wives/"+card, false)
39+
if err != nil {
40+
ctx.SendChain(message.Text("[猜老婆] 远程下载及本地读取图片均失败:\n", err))
41+
return
42+
}
3843
}
3944
work, name := card2name(card)
4045
name = strings.ToLower(name)
4146
img, _, err := image.Decode(bytes.NewReader(pic))
4247
if err != nil {
43-
ctx.SendChain(message.Text("[猜老婆]error:\n", err))
48+
ctx.SendChain(message.Text("[猜老婆] 图片解码失败:\n", err))
4449
return
4550
}
4651
dst := imgfactory.Size(img, img.Bounds().Dx(), img.Bounds().Dy())
4752
q, err := mosaic(dst, class)
4853
if err != nil {
4954
ctx.SendChain(
5055
message.Reply(ctx.Event.MessageID),
51-
message.Text("[猜老婆]图片生成失败:\n", err),
56+
message.Text("[猜老婆] 图片生成失败:\n", err),
5257
)
5358
return
5459
}
@@ -80,8 +85,6 @@ func init() {
8085
)
8186
return
8287
case c := <-recv:
83-
// tick.Reset(105 * time.Second)
84-
// after.Reset(120 * time.Second)
8588
msg := strings.ReplaceAll(c.Event.Message.String(), "酱", "")
8689
if msg == "" {
8790
continue

0 commit comments

Comments
 (0)