优化钓鱼插件一些逻辑问题 (#726)

* Update main.go

* Update pole.go

* Update store.go

* Update main.go

* Update store.go

* Update store.go
This commit is contained in:
方柳煜
2023-09-06 21:33:47 +08:00
committed by GitHub
parent 598efe182c
commit 73c6f4795e
3 changed files with 51 additions and 10 deletions

View File

@@ -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()