@@ -342,154 +342,213 @@ func init() {
342342 }
343343 ctx .SendChain (message .Text ("附魔成功," , book , "等级提高至" , enchantLevel [number ]))
344344 })
345- engine .OnRegex (`^合成(.+竿|三叉戟)$` , getdb ).SetBlock (true ).Limit (ctxext .LimitByUser ).Handle (func (ctx * zero.Ctx ) {
346- uid := ctx .Event .UserID
347- thingList := []string {"木竿" , "铁竿" , "金竿" , "钻石竿" , "下界合金竿" , "三叉戟" }
348- thingName := ctx .State ["regex_matched" ].([]string )[1 ]
349- indexOfMaterial := - 1
350- for i , name := range thingList {
351- if thingName == name {
352- indexOfMaterial = (i - 1 )
353- break
354- }
355- }
356- if indexOfMaterial < 0 {
357- return
358- }
359- articles , err := dbdata .getUserThingInfo (uid , thingList [indexOfMaterial ])
360- if err != nil {
361- ctx .SendChain (message .Text ("[ERROR at pole.go.10]:" , err ))
362- return
363- }
364- maxCount := len (articles )
365- if maxCount < 3 {
366- ctx .SendChain (message .Reply (ctx .Event .MessageID ), message .Text ("你的合成材料不足" ))
367- return
368- }
369-
370- poles := make ([]equip , 0 , maxCount )
371- for _ , info := range articles {
372- poleInfo := strings .Split (info .Other , "/" )
373- durable , _ := strconv .Atoi (poleInfo [0 ])
374- maintenance , _ := strconv .Atoi (poleInfo [1 ])
375- induceLevel , _ := strconv .Atoi (poleInfo [2 ])
376- favorLevel , _ := strconv .Atoi (poleInfo [3 ])
377- poles = append (poles , equip {
378- ID : uid ,
379- Equip : info .Name ,
380- Durable : durable ,
381- Maintenance : maintenance ,
382- Induce : induceLevel ,
383- Favor : favorLevel ,
384- })
385- }
386- var list []int
387- check := false
388- msg := make (message.Message , 0 , 3 + len (articles ))
389- msg = append (msg , message .Text ("找到以下材料 (" + thingList [indexOfMaterial ]+ "):\n " ))
390- for i , info := range poles {
391- msg = append (msg , message .Text ("[" , i , "] " , info .Equip , " : 耐" , info .Durable , "/修" , info .Maintenance ,
392- "/诱" , enchantLevel [info .Induce ], "/眷顾" , enchantLevel [info .Favor ], "\n " ))
393- }
394- msg = append (msg , message .Text ("————————\n " ))
395- msg = append (msg , message .Text ("- 输入3个序号进行合成(用空格分割)\n " ))
396- msg = append (msg , message .Text ("- 输入“取消”,终止本次合成\n " ))
397- msg = append (msg , message .Text ("- 输入“梭哈“,合成所有鱼竿" ))
398- ctx .Send (message .ReplyWithMessage (ctx .Event .MessageID , msg ... ))
399- recv , cancel := zero .NewFutureEvent ("message" , 999 , false , zero .RegexRule (`^(梭哈|取消|(?:\d+\s*)+)$` ), zero .CheckUser (ctx .Event .UserID )).Repeat ()
400- defer cancel ()
401- for {
402- select {
403- case <- time .After (time .Second * 120 ):
404- ctx .Send (message .ReplyWithMessage (ctx .Event .MessageID , message .Text ("等待超时,取消合成" )))
405- return
406- case e := <- recv :
407- nextcmd := strings .TrimSpace (e .Event .Message .String ())
408- if nextcmd == "取消" {
409- ctx .Send (message .ReplyWithMessage (ctx .Event .MessageID , message .Text ("已取消合成" )))
410- return
411- }
412- if nextcmd == "梭哈" {
413- for i := 0 ; i < (len (articles )/ 3 )* 3 ; i ++ {
414- list = append (list , i )
415- }
416- check = true
417- } else {
418- parts := strings .Fields (nextcmd )
419- if len (parts )% 3 != 0 {
420- ctx .SendChain (message .At (ctx .Event .UserID ), message .Text ("\n 合成失败:材料数量必须是 3 的倍数(当前输入了 " , len (parts ), " 个)" ))
421- continue
422- }
423- tempList := []int {}
424- valid := true
425- for _ , p := range parts {
426- idx , err := strconv .Atoi (p )
427- if err != nil || idx < 0 || idx >= maxCount {
428- ctx .SendChain (message .At (ctx .Event .UserID ), message .Text ("\n 序号 [" , p , "] 超出范围,请重新输入" ))
429- valid = false
430- break
431- }
432- tempList = append (tempList , idx )
433- }
434- if valid {
435- list = tempList
436- check = true
437- }
438- }
439- }
440- if check {
441- break
442- }
443- }
444- upgradeNum := len (list )
445- groupCount := upgradeNum / 3
446- var successCount , failCount int
447- var reportDetails []string
448- baseTime := time .Now ().Unix ()
449- for g := 0 ; g < groupCount ; g ++ {
450- var groupInduce , groupFavor int
451- for i := 0 ; i < 3 ; i ++ {
452- idx := list [g * 3 + i ]
453- thingInfo := articles [idx ]
454- thingInfo .Number = 0
455- _ = dbdata .updateUserThingInfo (uid , thingInfo )
456-
457- groupInduce += poles [idx ].Induce
458- groupFavor += poles [idx ].Favor
345+ engine .OnRegex (`^合成(.+竿|三叉戟)$` , getdb ).SetBlock (true ).Limit (ctxext .LimitByUser ).Handle (func (ctx * zero.Ctx ) {
346+ uid := ctx .Event .UserID
347+ thingList := []string {"木竿" , "铁竿" , "金竿" , "钻石竿" , "下界合金竿" , "三叉戟" }
348+ thingName := ctx .State ["regex_matched" ].([]string )[1 ]
349+ indexOfMaterial := - 1
350+ for i , name := range thingList {
351+ if thingName == name {
352+ indexOfMaterial = (i - 1 )
353+ break
459354 }
460- if rand .Intn (100 ) >= 90 {
461- failCount ++
462- continue
355+ }
356+ if indexOfMaterial < 0 {
357+ return
358+ }
359+ articles , err := dbdata .getUserThingInfo (uid , thingList [indexOfMaterial ])
360+ if err != nil {
361+ ctx .SendChain (message .Text ("[ERROR at pole.go.10]:" , err ))
362+ return
363+ }
364+ maxCount := len (articles )
365+ if maxCount < 3 {
366+ ctx .SendChain (message .Reply (ctx .Event .MessageID ), message .Text ("你的合成材料不足" ))
367+ return
368+ }
369+ poles := make ([]equip , 0 , maxCount )
370+ for _ , info := range articles {
371+ poleInfo := strings .Split (info .Other , "/" )
372+ durable , _ := strconv .Atoi (poleInfo [0 ])
373+ maintenance , _ := strconv .Atoi (poleInfo [1 ])
374+ induceLevel , _ := strconv .Atoi (poleInfo [2 ])
375+ favorLevel , _ := strconv .Atoi (poleInfo [3 ])
376+ poles = append (poles , equip {
377+ ID : uid ,
378+ Equip : info .Name ,
379+ Durable : durable ,
380+ Maintenance : maintenance ,
381+ Induce : induceLevel ,
382+ Favor : favorLevel ,
383+ })
384+ }
385+ list := []int {0 , 1 , 2 }
386+ check := false
387+ if len (articles ) > 3 {
388+ msg := make (message.Message , 0 , 3 + len (articles ))
389+ msg = append (msg , message .Text ("找到以下鱼竿:\n " ))
390+ for i , info := range poles {
391+ msg = append (msg , message .Text ("[" , i , "] " , info .Equip , " : 耐" , info .Durable , "/修" , info .Maintenance ,
392+ "/诱" , enchantLevel [info .Induce ], "/眷顾" , enchantLevel [info .Favor ], "\n " ))
463393 }
464- successCount ++
465- avgInduce := groupInduce / 3
466- avgFavor := groupFavor / 3
467- attribute := strconv .Itoa (durationList [thingName ]) + "/0/" + strconv .Itoa (avgInduce ) + "/" + strconv .Itoa (avgFavor )
468- newthing := article {
469- Duration : baseTime + int64 (g * 10 ) + int64 (rand .Intn (100 )),
470- Type : "pole" ,
471- Name : thingName ,
472- Number : 1 ,
473- Other : attribute ,
394+ msg = append (msg , message .Text ("————————\n " ))
395+ msg = append (msg , message .Text ("- 输入3个序号进行合成(用空格分割)\n " ))
396+ msg = append (msg , message .Text ("- 输入“取消”,终止本次合成\n " ))
397+ msg = append (msg , message .Text ("- 输入“梭哈“,合成所有鱼竿" ))
398+ ctx .Send (message .ReplyWithMessage (ctx .Event .MessageID , msg ... ))
399+ // 等待用户下一步选择
400+ recv , cancel := zero .NewFutureEvent ("message" , 999 , false , zero .RegexRule (`^(梭哈|取消|\d+ \d+ \d+)$` ), zero .CheckUser (ctx .Event .UserID )).Repeat ()
401+ defer cancel ()
402+ for {
403+ select {
404+ case <- time .After (time .Second * 120 ):
405+ ctx .Send (
406+ message .ReplyWithMessage (ctx .Event .MessageID ,
407+ message .Text ("等待超时,取消合成" ),
408+ ),
409+ )
410+ return
411+ case e := <- recv :
412+ nextcmd := e .Event .Message .String ()
413+ if nextcmd == "取消" {
414+ ctx .Send (
415+ message .ReplyWithMessage (ctx .Event .MessageID ,
416+ message .Text ("已取消合成" ),
417+ ),
418+ )
419+ return
420+ }
421+ if nextcmd == "梭哈" {
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+ }
463+ }
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
475+ }
476+ chooseList := strings .Split (nextcmd , " " )
477+ first , err := strconv .Atoi (chooseList [0 ])
478+ if err != nil {
479+ ctx .SendChain (message .Text ("[ERROR at pole.go.11.1]:" , err ))
480+ return
481+ }
482+ second , err := strconv .Atoi (chooseList [1 ])
483+ if err != nil {
484+ ctx .SendChain (message .Text ("[ERROR at pole.go.11.2]:" , err ))
485+ return
486+ }
487+ third , err := strconv .Atoi (chooseList [2 ])
488+ if err != nil {
489+ ctx .SendChain (message .Text ("[ERROR at pole.go.11.3]:" , err ))
490+ return
491+ }
492+ list = []int {first , second , third }
493+ if first == second || first == third || second == third {
494+ ctx .SendChain (message .At (ctx .Event .UserID ), message .Text ("[0]请输入正确的序号\n " , list ))
495+ continue
496+ }
497+ if first >= maxCount || second >= maxCount || third >= maxCount {
498+ ctx .SendChain (message .At (ctx .Event .UserID ), message .Text ("[" , maxCount , "]请输入正确的序号\n " , list ))
499+ continue
500+ }
501+ check = true
502+ }
503+ if check {
504+ break
505+ }
474506 }
475- err = dbdata .updateUserThingInfo (uid , newthing )
507+ }
508+ upgradeNum := len (list )
509+ favorLevel := 0
510+ induceLevel := 0
511+ for _ , index := range list {
512+ thingInfo := articles [index ]
513+ thingInfo .Number = 0
514+ err = dbdata .updateUserThingInfo (uid , thingInfo )
476515 if err != nil {
477- failCount ++
478- continue
479- }
480- if successCount <= 5 {
481- reportDetails = append (reportDetails , "第 " + strconv .Itoa (successCount )+ " 支: [诱钓" + strconv .Itoa (avgInduce )+ " 海眷" + strconv .Itoa (avgFavor )+ "]" )
516+ ctx .SendChain (message .Text ("[ERROR at pole.go.12]:" , err ))
517+ return
482518 }
519+ favorLevel += poles [index ].Favor
520+ induceLevel += poles [index ].Induce
521+ }
522+ if rand .Intn (100 ) >= 90 {
523+ ctx .Send (
524+ message .ReplyWithMessage (ctx .Event .MessageID ,
525+ message .Text ("合成失败,材料已销毁" ),
526+ ),
527+ )
528+ return
483529 }
484- finalReport := "合成报告\n "
485- finalReport += "消耗材料: " + strconv .Itoa (upgradeNum ) + " 个\n "
486- finalReport += "成功产出: " + strconv .Itoa (successCount ) + " 支 | 失败: " + strconv .Itoa (failCount ) + " 组\n "
487- if successCount > 0 {
488- finalReport += "----\n " + strings .Join (reportDetails , "\n " )
489- if successCount > 5 {
490- finalReport += "\n ...以及其余 " + strconv .Itoa (successCount - 5 ) + " 支属性已略过"
530+ attribute := strconv .Itoa (durationList [thingName ]) + "/0/" + strconv .Itoa (induceLevel / upgradeNum ) + "/" + strconv .Itoa (favorLevel / upgradeNum )
531+ newthing := article {
532+ Duration : time .Now ().Unix (),
533+ Type : "pole" ,
534+ Name : thingName ,
535+ Number : 1 ,
536+ Other : attribute ,
537+ }
538+ // 代码未对article.Number>1的情况做处理,直接生成多个Number=1的鱼竿
539+ for i := 0 ; i < upgradeNum / 3 ; i ++ {
540+ // 使用时间戳作为主键,增加固定值避免主键冲突
541+ newthing .Duration += int64 (i * 10 )
542+ err = dbdata .updateUserThingInfo (uid , newthing )
543+ if err != nil {
544+ ctx .SendChain (message .Text ("[ERROR at pole.go.12]:" , err ))
545+ return
491546 }
492547 }
493- ctx .Send (message .ReplyWithMessage (ctx .Event .MessageID , message .Text (strings .TrimSpace (finalReport ))))
548+ ctx .Send (
549+ message .ReplyWithMessage (ctx .Event .MessageID ,
550+ message .Text ("成功合成:" , upgradeNum / 3 , "个" , thingName , "\n 属性: " , attribute ),
551+ ),
552+ )
494553 })
495554}
0 commit comments