Skip to content

Commit d77b8cf

Browse files
authored
Refactor upgrade logic and improve reporting
1 parent 319c690 commit d77b8cf

File tree

1 file changed

+58
-74
lines changed

1 file changed

+58
-74
lines changed

plugin/mcfish/pole.go

Lines changed: 58 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -458,87 +458,71 @@ func init() {
458458
}
459459
}
460460
}
461-
groupCount := len(list) / 3
462-
successCount := 0
463-
failCount := 0
464-
successAttributes := []string{}
461+
upgradeNum := len(list)
462+
if upgradeNum == 0 || upgradeNum%3 != 0 {
463+
ctx.SendChain(message.At(uid), message.Text("❌ 合成失败:材料数量必须是 3 的倍数(当前选择了 ", upgradeNum, " 个)"))
464+
return
465+
}
465466

466-
for g := 0; g < groupCount; g++ {
467-
idx1 := list[g*3]
468-
idx2 := list[g*3+1]
469-
idx3 := list[g*3+2]
467+
groupCount := upgradeNum / 3
468+
var successCount, failCount int
469+
var reportDetails []string
470470

471-
thingInfo1 := articles[idx1]
472-
thingInfo2 := articles[idx2]
473-
thingInfo3 := articles[idx3]
471+
baseTime := time.Now().Unix()
474472

475-
thingInfo1.Number = 0
476-
thingInfo2.Number = 0
477-
thingInfo3.Number = 0
473+
for g := 0; g < groupCount; g++ {
474+
var groupInduce, groupFavor int
478475

479-
err = dbdata.updateUserThingInfo(uid, thingInfo1)
480-
if err != nil {
481-
ctx.SendChain(message.Text("[ERROR at pole.go.12]:", err))
482-
return
483-
}
484-
err = dbdata.updateUserThingInfo(uid, thingInfo2)
485-
if err != nil {
486-
ctx.SendChain(message.Text("[ERROR at pole.go.12]:", err))
487-
return
488-
}
489-
err = dbdata.updateUserThingInfo(uid, thingInfo3)
490-
if err != nil {
491-
ctx.SendChain(message.Text("[ERROR at pole.go.12]:", err))
492-
return
493-
}
476+
for i := 0; i < 3; i++ {
477+
idx := list[g*3+i]
478+
thingInfo := articles[idx]
479+
thingInfo.Number = 0
480+
_ = dbdata.updateUserThingInfo(uid, thingInfo)
481+
482+
groupInduce += poles[idx].Induce
483+
groupFavor += poles[idx].Favor
484+
}
494485

495-
if rand.Intn(100) >= 90 {
496-
failCount++
497-
continue
498-
}
486+
if rand.Intn(100) >= 90 {
487+
failCount++
488+
continue
489+
}
499490

500-
favorLevel := (poles[idx1].Favor + poles[idx2].Favor + poles[idx3].Favor) / 3
501-
induceLevel := (poles[idx1].Induce + poles[idx2].Induce + poles[idx3].Induce) / 3
502-
attribute := strconv.Itoa(durationList[thingName]) + "/0/" + strconv.Itoa(induceLevel) + "/" + strconv.Itoa(favorLevel)
491+
successCount++
492+
avgInduce := groupInduce / 3
493+
avgFavor := groupFavor / 3
494+
attribute := strconv.Itoa(durationList[thingName]) + "/0/" + strconv.Itoa(avgInduce) + "/" + strconv.Itoa(avgFavor)
495+
496+
newthing := article{
497+
Duration: baseTime + int64(g*10) + int64(rand.Intn(100)),
498+
Type: "pole",
499+
Name: thingName,
500+
Number: 1,
501+
Other: attribute,
502+
}
503+
504+
err = dbdata.updateUserThingInfo(uid, newthing)
505+
if err != nil {
506+
failCount++
507+
continue
508+
}
503509

504-
newthing := article{
505-
Duration: time.Now().Unix() + int64(g*10),
506-
Type: "pole",
507-
Name: thingName,
508-
Number: 1,
509-
Other: attribute,
510-
}
511-
err = dbdata.updateUserThingInfo(uid, newthing)
512-
if err != nil {
513-
ctx.SendChain(message.Text("[ERROR at pole.go.12]:", err))
514-
return
515-
}
516-
successCount++
517-
successAttributes = append(successAttributes, attribute)
518-
}
510+
if successCount <= 5 {
511+
reportDetails = append(reportDetails, "✨ 第 "+strconv.Itoa(successCount)+" 支: [诱钓"+strconv.Itoa(avgInduce)+" 海眷"+strconv.Itoa(avgFavor)+"]")
512+
}
513+
}
519514

520-
resultMsg := ""
521-
if successCount > 0 {
522-
resultMsg += "成功合成 " + strconv.Itoa(successCount) + " 个" + thingName + "\n"
523-
if len(successAttributes) <= 5 {
524-
for _, attr := range successAttributes {
525-
resultMsg += "属性: " + attr + "\n"
526-
}
527-
} else {
528-
resultMsg += "属性示例: " + successAttributes[0] + " 等\n"
529-
}
530-
}
531-
if failCount > 0 {
532-
resultMsg += "失败 " + strconv.Itoa(failCount) + " 次,材料已销毁。"
533-
}
534-
if resultMsg == "" {
535-
resultMsg = "没有进行任何合成?"
536-
}
515+
finalReport := " 合成报告 \n"
516+
finalReport += "消耗材料: " + strconv.Itoa(upgradeNum) + " 个\n"
517+
finalReport += "成功产出: " + strconv.Itoa(successCount) + " 支 | 失败: " + strconv.Itoa(failCount) + " 组\n"
518+
519+
if successCount > 0 {
520+
finalReport += "----\n" + strings.Join(reportDetails, "\n")
521+
if successCount > 5 {
522+
finalReport += "\n...以及其余 " + strconv.Itoa(successCount-5) + " 支属性已略过"
523+
}
524+
}
537525

538-
ctx.Send(
539-
message.ReplyWithMessage(ctx.Event.MessageID,
540-
message.Text(resultMsg),
541-
),
542-
)
543-
})
526+
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text(strings.TrimSpace(finalReport))))
527+
})
544528
}

0 commit comments

Comments
 (0)