From 95451f96d8055ceba26c72182aa5ecad52b340ae 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: Sat, 5 Oct 2024 20:10:30 +0800 Subject: [PATCH] =?UTF-8?q?optimize(mcfish):=20=E9=99=90=E5=88=B6=E9=B1=BC?= =?UTF-8?q?=E8=B4=A9=E7=9A=84=E5=9E=84=E6=96=AD=20(#992)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/mcfish/main.go | 63 +++++++++++++++++++++++++++++++++++------- plugin/mcfish/store.go | 34 +++++++++++++++++++++-- 2 files changed, 84 insertions(+), 13 deletions(-) diff --git a/plugin/mcfish/main.go b/plugin/mcfish/main.go index b3ce1a64c9..1a28d36aae 100644 --- a/plugin/mcfish/main.go +++ b/plugin/mcfish/main.go @@ -28,7 +28,7 @@ type fishdb struct { const FishLimit = 50 // version 规则版本号 -const version = "5.4.2" +const version = "5.5.8" // 各物品信息 type jsonInfo struct { @@ -101,7 +101,7 @@ type buffInfo struct { Coupon int `db:"Buff1"` // 优惠卷 SalesPole int `db:"Buff2"` // 卖鱼竿上限 BuyTing int `db:"Buff3"` // 购买上限 - Buff4 int `db:"Buff4"` // 暂定 + SalesFish int `db:"Buff4"` // 卖鱼次数 Buff5 int `db:"Buff5"` // 暂定 Buff6 int `db:"Buff6"` // 暂定 Buff7 int `db:"Buff7"` // 暂定 @@ -149,7 +149,7 @@ var ( "8.合成:\n-> 铁竿 : 3x木竿\n-> 金竿 : 3x铁竿\n-> 钻石竿 : 3x金竿\n-> 下界合金竿 : 3x钻石竿\n-> 三叉戟 : 3x下界合金竿\n注:合成成功率90%(包括梭哈),合成鱼竿的附魔等级=(附魔等级合/合成鱼竿数量)\n" + "9.杂项:\n-> 无装备的情况下,每人最多可以购买3次100块钱的鱼竿\n-> 默认状态钓鱼上钩概率为60%(理论值!!!)\n-> 附魔的鱼竿会因附魔变得昂贵,每个附魔最高3级\n-> 三叉戟不算鱼竿,修复时可直接满耐久\n" + "-> 鱼竿数量大于50的不能买东西;\n 鱼竿数量大于30的不能钓鱼;\n 每购/售10次鱼竿获得1层宝藏诅咒;\n 每购买20次物品将获得3次价格减半福利;\n 每钓鱼75次获得1本净化书;\n" + - " 每天最多只可出售5个鱼竿和购买15次物品;", + " 每天最多只可出售5个鱼竿和购买15次物品;鱼类交易每天最多100条.", PublicDataFolder: "McFish", }).ApplySingle(ctxext.DefaultSingle) getdb = fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { @@ -562,6 +562,10 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) { if err != nil { return false, err } + err = sql.db.Create("store", &store{}) + if err != nil { + return false, err + } lastTime := storeDiscount{} _ = sql.db.Find("stroeDiscount", &lastTime, "where Name = 'lastTime'") refresh := false @@ -586,6 +590,12 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) { Name: name, Discount: thingDiscount, } + thingInfo := store{} + _ = sql.db.Find("store", &thingInfo, "where Name = '"+name+"'") + if thingInfo.Number > 150 { + // 通货膨胀 + thing.Discount = (1000 - 5*(thingInfo.Number-150)) / 10 + } err = sql.db.Insert("stroeDiscount", &thing) if err != nil { return @@ -611,10 +621,6 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) { _ = sql.db.Del("stroeDiscount", "where Duration = "+strconv.FormatInt(info.Duration, 10)) } if refresh { - err = sql.db.Create("store", &store{}) - if err != nil { - return - } // 每天调控1种鱼 fish := fishList[rand.Intn(len(fishList))] thingInfo := store{ @@ -770,7 +776,7 @@ func (sql *fishdb) useCouponAt(uid int64, times int) (int, error) { return useTimes, sql.db.Insert("buff", &userInfo) } -// 检测上限 +// 检测卖鱼竿上限 func (sql *fishdb) checkCanSalesFor(uid int64, sales bool) (int, error) { residue := 0 sql.Lock() @@ -782,6 +788,7 @@ func (sql *fishdb) checkCanSalesFor(uid int64, sales bool) (int, error) { } _ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10)) if time.Now().Day() != time.Unix(userInfo.Duration, 0).Day() { + userInfo.Duration = time.Now().Unix() userInfo.SalesPole = 0 userInfo.BuyTing = 0 } @@ -789,8 +796,44 @@ func (sql *fishdb) checkCanSalesFor(uid int64, sales bool) (int, error) { residue = 5 - userInfo.SalesPole userInfo.SalesPole++ } else if userInfo.BuyTing < 15 { - residue = 15 - userInfo.SalesPole - userInfo.SalesPole++ + residue = 15 - userInfo.BuyTing + userInfo.BuyTing++ } return residue, sql.db.Insert("buff", &userInfo) } + +// 检测物品是否是鱼 +func checkIsFish(thing string) bool { + for _, v := range fishList { + if v == thing { + return true + } + } + return false +} + +// 检测买卖鱼上限 +func (sql *fishdb) checkCanSalesFishFor(uid int64, sales int) (int, error) { + residue := 0 + sql.Lock() + defer sql.Unlock() + userInfo := buffInfo{ID: uid} + err := sql.db.Create("buff", &userInfo) + if err != nil { + return residue, err + } + _ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10)) + if time.Now().Day() != time.Unix(userInfo.Duration, 0).Day() { + userInfo.Duration = time.Now().Unix() + userInfo.SalesFish = 0 + } + maxSales := 100 - userInfo.SalesFish + if maxSales < 0 { + maxSales = 0 + } + if sales > maxSales { + sales = maxSales + } + userInfo.SalesFish += sales + return sales, sql.db.Insert("buff", &userInfo) +} diff --git a/plugin/mcfish/store.go b/plugin/mcfish/store.go index 848d4be7ce..75f632bd45 100644 --- a/plugin/mcfish/store.go +++ b/plugin/mcfish/store.go @@ -85,6 +85,18 @@ func init() { if number == 0 || strings.Contains(thingName, "竿") { number = 1 } + if checkIsFish(thingName) { + residue, err := dbdata.checkCanSalesFishFor(uid, number) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + if residue <= 0 { + ctx.SendChain(message.Text("今天你已经超出了鱼交易数量上限,明天再来买鱼吧")) + return + } + number = residue + } articles, err := dbdata.getUserThingInfo(uid, thingName) if err != nil { ctx.SendChain(message.Text("[ERROR at store.go.5]:", err)) @@ -157,7 +169,9 @@ func init() { maintenance, _ := strconv.Atoi(poleInfo[1]) induceLevel, _ := strconv.Atoi(poleInfo[2]) favorLevel, _ := strconv.Atoi(poleInfo[3]) - pice = (priceList[thingName] - (durationList[thingName] - durable) - maintenance*2 + induceLevel*600 + favorLevel*1800) * discountList[thingName] / 100 + pice = (priceList[thingName] - (durationList[thingName] - durable) - maintenance*2 + + induceLevel*600*discountList["诱钓"]/100 + + favorLevel*1800*discountList["海之眷顾"]/100) * discountList[thingName] / 100 } else { pice = priceList[thingName] * discountList[thingName] / 100 } @@ -399,7 +413,7 @@ func init() { return } if buytimes <= 0 { - ctx.SendChain(message.Text("出售次数已达到上限,明天再来购买吧")) + ctx.SendChain(message.Text("购买次数已达到上限,明天再来购买吧")) return } thingName := ctx.State["regex_matched"].([]string)[1] @@ -407,6 +421,18 @@ func init() { if number == 0 { number = 1 } + if checkIsFish(thingName) { + residue, err := dbdata.checkCanSalesFishFor(uid, number) + if err != nil { + ctx.SendChain(message.Text("[ERROR]:", err)) + return + } + if residue <= 0 { + ctx.SendChain(message.Text("今天你已经超出了鱼交易数量上限,明天再来买鱼吧")) + return + } + number = residue + } thingInfos, err := dbdata.getStoreThingInfo(thingName) if err != nil { ctx.SendChain(message.Text("[ERROR at store.go.11]:", err)) @@ -448,7 +474,9 @@ func init() { maintenance, _ := strconv.Atoi(poleInfo[1]) induceLevel, _ := strconv.Atoi(poleInfo[2]) favorLevel, _ := strconv.Atoi(poleInfo[3]) - thingPice := (priceList[info.Name] - (durationList[info.Name] - durable) - maintenance*2 + induceLevel*600 + favorLevel*1800) * discountList[info.Name] / 100 + thingPice := (priceList[info.Name] - (durationList[info.Name] - durable) - maintenance*2 + + induceLevel*600*discountList["诱钓"]/100 + + favorLevel*1800*discountList["海之眷顾"]/100) * discountList[info.Name] / 100 pice = append(pice, thingPice) } else { thingPice := priceList[info.Name] * discountList[info.Name] / 100