Skip to content

Commit 73c6f47

Browse files
authored
优化钓鱼插件一些逻辑问题 (#726)
* Update main.go * Update pole.go * Update store.go * Update main.go * Update store.go * Update store.go
1 parent 598efe1 commit 73c6f47

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

plugin/mcfish/main.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,18 +341,22 @@ func (sql *fishdb) pickFishFor(uid int64, number int) (fishNames map[string]int,
341341
if max < number {
342342
number = max
343343
}
344-
for i := number; i > 0; i-- {
344+
for i := number; i > 0; {
345345
randNumber := rand.Intn(len(fishTypes))
346346
if fishTypes[randNumber].Number <= 0 {
347-
i++
348347
continue
349348
}
350349
fishTypes[randNumber].Number--
351-
err = sql.db.Insert(name, &fishTypes[randNumber])
350+
if fishTypes[randNumber].Number <= 0 {
351+
err = sql.db.Del(name, "where Duration = "+strconv.FormatInt(fishTypes[randNumber].Duration, 10))
352+
} else {
353+
err = sql.db.Insert(name, &fishTypes[randNumber])
354+
}
352355
if err != nil {
353356
return
354357
}
355358
fishNames[fishTypes[randNumber].Name]++
359+
i--
356360
}
357361
return
358362
}
@@ -481,7 +485,7 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) {
481485
}
482486
refresh = true
483487
}
484-
for name := range priceList {
488+
for _, name := range thingList {
485489
thing := storeDiscount{}
486490
switch refresh {
487491
case true:
@@ -575,6 +579,34 @@ func (sql *fishdb) getStoreThingInfo(thing string) (thingInfos []store, err erro
575579
return
576580
}
577581

582+
// 获取商店物品信息
583+
func (sql *fishdb) checkStoreFor(thing store, number int) (ok bool, err error) {
584+
sql.Lock()
585+
defer sql.Unlock()
586+
err = sql.db.Create("store", &thing)
587+
if err != nil {
588+
return
589+
}
590+
count, err := sql.db.Count("store")
591+
if err != nil {
592+
return
593+
}
594+
if count == 0 {
595+
return false, nil
596+
}
597+
if !sql.db.CanFind("store", "where Duration = "+strconv.FormatInt(thing.Duration, 10)) {
598+
return false, nil
599+
}
600+
err = sql.db.Find("store", &thing, "where Duration = "+strconv.FormatInt(thing.Duration, 10))
601+
if err != nil {
602+
return
603+
}
604+
if thing.Number < number {
605+
return false, nil
606+
}
607+
return true, nil
608+
}
609+
578610
// 更新商店信息
579611
func (sql *fishdb) updateStoreInfo(thingInfo store) (err error) {
580612
sql.Lock()

plugin/mcfish/pole.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func init() {
157157
ctx.SendChain(message.Text("[ERROR at pole.go.5]:", err))
158158
return
159159
}
160-
if equipInfo.Equip == "" || equipInfo.Equip == "美西螈" || equipInfo.Equip == "三叉戟" {
160+
if equipInfo.Equip == "" || equipInfo.Equip == "美西螈" {
161161
ctx.SendChain(message.Text("仅能修复装备中的鱼竿"))
162162
return
163163
}
@@ -247,7 +247,7 @@ func init() {
247247
number = 10
248248
}
249249
equipInfo.Durable += newEquipInfo.Durable * number / 10
250-
if equipInfo.Durable > durationList[equipInfo.Equip] {
250+
if equipInfo.Durable > durationList[equipInfo.Equip] || equipInfo.Equip == "三叉戟" {
251251
equipInfo.Durable = durationList[equipInfo.Equip]
252252
}
253253
msg := ""

plugin/mcfish/store.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,15 @@ func init() {
385385
}
386386
}
387387

388+
ok, err := dbdata.checkStoreFor(thing, number)
389+
if err != nil {
390+
ctx.SendChain(message.Text("[ERROR at store.go.11]:", err))
391+
return
392+
}
393+
if !ok {
394+
ctx.SendChain(message.Reply(ctx.Event.MessageID),message.Text("你慢了一步,物品被别人买走了"))
395+
return
396+
}
388397
thing.Number -= number
389398
err = dbdata.updateStoreInfo(thing)
390399
if err != nil {
@@ -520,7 +529,7 @@ func drawStroeInfoImage(stroeInfo []store) (picImage image.Image, err error) {
520529
textDx, textDh := canvas.MeasureString("下界合金竿(均价1000)")
521530
valueDx, _ := canvas.MeasureString("+100%")
522531
i := 0
523-
for name, info := range discountList {
532+
for _, name := range thingList {
524533
text := name + "(均价" + strconv.Itoa(priceList[name]) + ") "
525534

526535
if i == 2 {
@@ -529,12 +538,12 @@ func drawStroeInfoImage(stroeInfo []store) (picImage image.Image, err error) {
529538
}
530539
canvas.SetColor(color.Black)
531540
canvas.DrawStringAnchored(text, 20+(textDx+valueDx+10)*float64(i)+10, textDy+textDh/2, 0, 0.5)
532-
if info-100 > 0 {
541+
if discountList[name]-100 > 0 {
533542
canvas.SetRGBA255(200, 50, 50, 255)
534-
text = "+" + strconv.Itoa(info-100) + "%"
543+
text = "+" + strconv.Itoa(discountList[name]-100) + "%"
535544
} else {
536545
canvas.SetRGBA255(63, 133, 55, 255)
537-
text = strconv.Itoa(info-100) + "%"
546+
text = strconv.Itoa(discountList[name]-100) + "%"
538547
}
539548
canvas.DrawStringAnchored(text, 20+(textDx+valueDx+10)*float64(i)+10+textDx+10, textDy+textDh/2, 0, 0.5)
540549
i++

0 commit comments

Comments
 (0)