mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
优化钓鱼插件一些逻辑问题 (#726)
* Update main.go * Update pole.go * Update store.go * Update main.go * Update store.go * Update store.go
This commit is contained in:
parent
598efe182c
commit
73c6f4795e
@ -341,18 +341,22 @@ func (sql *fishdb) pickFishFor(uid int64, number int) (fishNames map[string]int,
|
|||||||
if max < number {
|
if max < number {
|
||||||
number = max
|
number = max
|
||||||
}
|
}
|
||||||
for i := number; i > 0; i-- {
|
for i := number; i > 0; {
|
||||||
randNumber := rand.Intn(len(fishTypes))
|
randNumber := rand.Intn(len(fishTypes))
|
||||||
if fishTypes[randNumber].Number <= 0 {
|
if fishTypes[randNumber].Number <= 0 {
|
||||||
i++
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fishTypes[randNumber].Number--
|
fishTypes[randNumber].Number--
|
||||||
|
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])
|
err = sql.db.Insert(name, &fishTypes[randNumber])
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fishNames[fishTypes[randNumber].Name]++
|
fishNames[fishTypes[randNumber].Name]++
|
||||||
|
i--
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -481,7 +485,7 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) {
|
|||||||
}
|
}
|
||||||
refresh = true
|
refresh = true
|
||||||
}
|
}
|
||||||
for name := range priceList {
|
for _, name := range thingList {
|
||||||
thing := storeDiscount{}
|
thing := storeDiscount{}
|
||||||
switch refresh {
|
switch refresh {
|
||||||
case true:
|
case true:
|
||||||
@ -575,6 +579,34 @@ func (sql *fishdb) getStoreThingInfo(thing string) (thingInfos []store, err erro
|
|||||||
return
|
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) {
|
func (sql *fishdb) updateStoreInfo(thingInfo store) (err error) {
|
||||||
sql.Lock()
|
sql.Lock()
|
||||||
|
|||||||
@ -157,7 +157,7 @@ func init() {
|
|||||||
ctx.SendChain(message.Text("[ERROR at pole.go.5]:", err))
|
ctx.SendChain(message.Text("[ERROR at pole.go.5]:", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if equipInfo.Equip == "" || equipInfo.Equip == "美西螈" || equipInfo.Equip == "三叉戟" {
|
if equipInfo.Equip == "" || equipInfo.Equip == "美西螈" {
|
||||||
ctx.SendChain(message.Text("仅能修复装备中的鱼竿"))
|
ctx.SendChain(message.Text("仅能修复装备中的鱼竿"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ func init() {
|
|||||||
number = 10
|
number = 10
|
||||||
}
|
}
|
||||||
equipInfo.Durable += newEquipInfo.Durable * 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]
|
equipInfo.Durable = durationList[equipInfo.Equip]
|
||||||
}
|
}
|
||||||
msg := ""
|
msg := ""
|
||||||
|
|||||||
@ -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
|
thing.Number -= number
|
||||||
err = dbdata.updateStoreInfo(thing)
|
err = dbdata.updateStoreInfo(thing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -520,7 +529,7 @@ func drawStroeInfoImage(stroeInfo []store) (picImage image.Image, err error) {
|
|||||||
textDx, textDh := canvas.MeasureString("下界合金竿(均价1000)")
|
textDx, textDh := canvas.MeasureString("下界合金竿(均价1000)")
|
||||||
valueDx, _ := canvas.MeasureString("+100%")
|
valueDx, _ := canvas.MeasureString("+100%")
|
||||||
i := 0
|
i := 0
|
||||||
for name, info := range discountList {
|
for _, name := range thingList {
|
||||||
text := name + "(均价" + strconv.Itoa(priceList[name]) + ") "
|
text := name + "(均价" + strconv.Itoa(priceList[name]) + ") "
|
||||||
|
|
||||||
if i == 2 {
|
if i == 2 {
|
||||||
@ -529,12 +538,12 @@ func drawStroeInfoImage(stroeInfo []store) (picImage image.Image, err error) {
|
|||||||
}
|
}
|
||||||
canvas.SetColor(color.Black)
|
canvas.SetColor(color.Black)
|
||||||
canvas.DrawStringAnchored(text, 20+(textDx+valueDx+10)*float64(i)+10, textDy+textDh/2, 0, 0.5)
|
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)
|
canvas.SetRGBA255(200, 50, 50, 255)
|
||||||
text = "+" + strconv.Itoa(info-100) + "%"
|
text = "+" + strconv.Itoa(discountList[name]-100) + "%"
|
||||||
} else {
|
} else {
|
||||||
canvas.SetRGBA255(63, 133, 55, 255)
|
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)
|
canvas.DrawStringAnchored(text, 20+(textDx+valueDx+10)*float64(i)+10+textDx+10, textDy+textDh/2, 0, 0.5)
|
||||||
i++
|
i++
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user