From 73c6f4795e61de8498bb9ce57f84ac0af1a0bda1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E6=9F=B3=E7=85=9C?= <101934327+fangliuyu@users.noreply.github.com> Date: Wed, 6 Sep 2023 21:33:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=92=93=E9=B1=BC=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E4=B8=80=E4=BA=9B=E9=80=BB=E8=BE=91=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#726)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update main.go * Update pole.go * Update store.go * Update main.go * Update store.go * Update store.go --- plugin/mcfish/main.go | 40 ++++++++++++++++++++++++++++++++++++---- plugin/mcfish/pole.go | 4 ++-- plugin/mcfish/store.go | 17 +++++++++++++---- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/plugin/mcfish/main.go b/plugin/mcfish/main.go index ed37939df5..ef64bcfd7a 100644 --- a/plugin/mcfish/main.go +++ b/plugin/mcfish/main.go @@ -341,18 +341,22 @@ func (sql *fishdb) pickFishFor(uid int64, number int) (fishNames map[string]int, if max < number { number = max } - for i := number; i > 0; i-- { + for i := number; i > 0; { randNumber := rand.Intn(len(fishTypes)) if fishTypes[randNumber].Number <= 0 { - i++ continue } fishTypes[randNumber].Number-- - err = sql.db.Insert(name, &fishTypes[randNumber]) + if fishTypes[randNumber].Number <= 0 { + err = sql.db.Del(name, "where Duration = "+strconv.FormatInt(fishTypes[randNumber].Duration, 10)) + } else { + err = sql.db.Insert(name, &fishTypes[randNumber]) + } if err != nil { return } fishNames[fishTypes[randNumber].Name]++ + i-- } return } @@ -481,7 +485,7 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) { } refresh = true } - for name := range priceList { + for _, name := range thingList { thing := storeDiscount{} switch refresh { case true: @@ -575,6 +579,34 @@ func (sql *fishdb) getStoreThingInfo(thing string) (thingInfos []store, err erro return } +// 获取商店物品信息 +func (sql *fishdb) checkStoreFor(thing store, number int) (ok bool, err error) { + sql.Lock() + defer sql.Unlock() + err = sql.db.Create("store", &thing) + if err != nil { + return + } + count, err := sql.db.Count("store") + if err != nil { + return + } + if count == 0 { + return false, nil + } + if !sql.db.CanFind("store", "where Duration = "+strconv.FormatInt(thing.Duration, 10)) { + return false, nil + } + err = sql.db.Find("store", &thing, "where Duration = "+strconv.FormatInt(thing.Duration, 10)) + if err != nil { + return + } + if thing.Number < number { + return false, nil + } + return true, nil +} + // 更新商店信息 func (sql *fishdb) updateStoreInfo(thingInfo store) (err error) { sql.Lock() diff --git a/plugin/mcfish/pole.go b/plugin/mcfish/pole.go index 3cf1a5fad2..ec4e08fdbe 100644 --- a/plugin/mcfish/pole.go +++ b/plugin/mcfish/pole.go @@ -157,7 +157,7 @@ func init() { ctx.SendChain(message.Text("[ERROR at pole.go.5]:", err)) return } - if equipInfo.Equip == "" || equipInfo.Equip == "美西螈" || equipInfo.Equip == "三叉戟" { + if equipInfo.Equip == "" || equipInfo.Equip == "美西螈" { ctx.SendChain(message.Text("仅能修复装备中的鱼竿")) return } @@ -247,7 +247,7 @@ func init() { number = 10 } equipInfo.Durable += newEquipInfo.Durable * number / 10 - if equipInfo.Durable > durationList[equipInfo.Equip] { + if equipInfo.Durable > durationList[equipInfo.Equip] || equipInfo.Equip == "三叉戟" { equipInfo.Durable = durationList[equipInfo.Equip] } msg := "" diff --git a/plugin/mcfish/store.go b/plugin/mcfish/store.go index 2f2eff265f..094458a862 100644 --- a/plugin/mcfish/store.go +++ b/plugin/mcfish/store.go @@ -385,6 +385,15 @@ func init() { } } + ok, err := dbdata.checkStoreFor(thing, number) + if err != nil { + ctx.SendChain(message.Text("[ERROR at store.go.11]:", err)) + return + } + if !ok { + ctx.SendChain(message.Reply(ctx.Event.MessageID),message.Text("你慢了一步,物品被别人买走了")) + return + } thing.Number -= number err = dbdata.updateStoreInfo(thing) if err != nil { @@ -520,7 +529,7 @@ func drawStroeInfoImage(stroeInfo []store) (picImage image.Image, err error) { textDx, textDh := canvas.MeasureString("下界合金竿(均价1000)") valueDx, _ := canvas.MeasureString("+100%") i := 0 - for name, info := range discountList { + for _, name := range thingList { text := name + "(均价" + strconv.Itoa(priceList[name]) + ") " if i == 2 { @@ -529,12 +538,12 @@ func drawStroeInfoImage(stroeInfo []store) (picImage image.Image, err error) { } canvas.SetColor(color.Black) canvas.DrawStringAnchored(text, 20+(textDx+valueDx+10)*float64(i)+10, textDy+textDh/2, 0, 0.5) - if info-100 > 0 { + if discountList[name]-100 > 0 { canvas.SetRGBA255(200, 50, 50, 255) - text = "+" + strconv.Itoa(info-100) + "%" + text = "+" + strconv.Itoa(discountList[name]-100) + "%" } else { canvas.SetRGBA255(63, 133, 55, 255) - text = strconv.Itoa(info-100) + "%" + text = strconv.Itoa(discountList[name]-100) + "%" } canvas.DrawStringAnchored(text, 20+(textDx+valueDx+10)*float64(i)+10+textDx+10, textDy+textDh/2, 0, 0.5) i++