Skip to content

Commit

Permalink
优化钓鱼插件一些逻辑问题 (#726)
Browse files Browse the repository at this point in the history
* Update main.go

* Update pole.go

* Update store.go

* Update main.go

* Update store.go

* Update store.go
  • Loading branch information
fangliuyu authored Sep 6, 2023
1 parent 598efe1 commit 73c6f47
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
40 changes: 36 additions & 4 deletions plugin/mcfish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions plugin/mcfish/pole.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 := ""
Expand Down
17 changes: 13 additions & 4 deletions plugin/mcfish/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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++
Expand Down

0 comments on commit 73c6f47

Please sign in to comment.