From feb738147d3509117184a05701f8e58317a945df Mon Sep 17 00:00:00 2001 From: fangliuyu <1725453672@qq.com> Date: Wed, 2 Oct 2024 22:51:30 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E3=80=8Cmcfish=E3=80=8D=E9=99=90=E5=88=B6?= =?UTF-8?q?=E9=B1=BC=E8=B4=A9=E7=9A=84=E5=9E=84=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/mcfish/main.go | 69 +++++++++++++++++++++++++++++++++++++----- plugin/mcfish/store.go | 36 +++++++++++++++++++--- 2 files changed, 94 insertions(+), 11 deletions(-) diff --git a/plugin/mcfish/main.go b/plugin/mcfish/main.go index b3ce1a64c9..e63e6a2686 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.1" // 各物品信息 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 { @@ -615,6 +615,24 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) { if err != nil { return } + for _, fish := range fishList { + thingInfo := store{ + Duration: time.Now().Unix(), + Name: fish, + Type: "fish", + Price: priceList[fish] * discountList[fish] / 100, + } + _ = sql.db.Find("store", &thingInfo, "where Name = '"+fish+"'") + thingInfo.Number += (100 - discountList[fish]) + if thingInfo.Number < 1 { + thingInfo.Number = 100 + } else if thingInfo.Number > 150 { + // 通货膨胀 + discountList[fish] = (1000 - 5*(thingInfo.Number-150)) / 10 + thingInfo.Price = priceList[fish] * discountList[fish] / 100 + } + _ = sql.db.Insert("store", &thingInfo) + } // 每天调控1种鱼 fish := fishList[rand.Intn(len(fishList))] thingInfo := store{ @@ -634,7 +652,7 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) { Duration: time.Now().Unix(), Name: "净化书", Type: "article", - Price: priceList["净化书"] * discountList["净化书"] / 100, + Price: priceList["净化书"] * (discountList["净化书"]) / 100, } _ = sql.db.Find("store", &thingInfo, "where Name = '净化书'") thingInfo.Number = 20 @@ -770,7 +788,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 +800,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 +808,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 + } + max := 100 - userInfo.SalesFish + if max < 0 { + max = 0 + } + if sales > max { + sales = max + } + userInfo.SalesFish += sales + return sales, sql.db.Insert("buff", &userInfo) +} diff --git a/plugin/mcfish/store.go b/plugin/mcfish/store.go index 848d4be7ce..95f89802fb 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)) @@ -161,7 +173,8 @@ func init() { } else { pice = priceList[thingName] * discountList[thingName] / 100 } - ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否接受商店将以", pice*number*8/10, "收购", number, "个", thingName, "?\n回答\"是\"或\"否\""))) + pice = pice * 6 * 8 / 100 + ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否接受商店将以", pice*number, "收购", number, "个", thingName, "?\n回答\"是\"或\"否\""))) // 等待用户下一步选择 recv, cancel1 := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(是|否)$`), zero.CheckUser(ctx.Event.UserID)).Repeat() defer cancel1() @@ -399,7 +412,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 +420,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 +473,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 @@ -729,7 +756,8 @@ func drawStroeInfoImage(stroeInfo []store) (picImage image.Image, err error) { } canvas.SetColor(color.Black) textDy += textDh * 2 - canvas.DrawStringAnchored("注:出售商品将会额外扣除20%的税收,附魔鱼竿请按实际价格", 10, textDy+10+textDh/2, 0, 0.5) + canvas.DrawStringAnchored("注:出售商品 = 价格*60% * (1-20%)", 10, textDy+textDh/2, 0, 0.5) + canvas.DrawStringAnchored(" 鱼竿价格 = 原价-耐久度-维修*2+诱钓*600+眷顾*1000", 10, textDy+20+textDh+10, 0, 0.5) textDy += textH * 2 err = canvas.ParseFontFace(fontdata, 100) From 58bd32a31450839a264c1ed01ad230353ee6dda2 Mon Sep 17 00:00:00 2001 From: fangliuyu <1725453672@qq.com> Date: Wed, 2 Oct 2024 23:01:54 +0800 Subject: [PATCH 2/9] make lint happy --- plugin/mcfish/main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin/mcfish/main.go b/plugin/mcfish/main.go index e63e6a2686..568e317c1e 100644 --- a/plugin/mcfish/main.go +++ b/plugin/mcfish/main.go @@ -839,12 +839,12 @@ func (sql *fishdb) checkCanSalesFishFor(uid int64, sales int) (int, error) { userInfo.Duration = time.Now().Unix() userInfo.SalesFish = 0 } - max := 100 - userInfo.SalesFish - if max < 0 { - max = 0 + maxSales := 100 - userInfo.SalesFish + if maxSales < 0 { + maxSales = 0 } - if sales > max { - sales = max + if sales > maxSales { + sales = maxSales } userInfo.SalesFish += sales return sales, sql.db.Insert("buff", &userInfo) From d102b6def26412350087767c435169b0ed7c8ea1 Mon Sep 17 00:00:00 2001 From: fangliuyu <1725453672@qq.com> Date: Wed, 2 Oct 2024 23:08:28 +0800 Subject: [PATCH 3/9] fix --- plugin/mcfish/store.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/mcfish/store.go b/plugin/mcfish/store.go index 95f89802fb..93a58f218d 100644 --- a/plugin/mcfish/store.go +++ b/plugin/mcfish/store.go @@ -173,8 +173,7 @@ func init() { } else { pice = priceList[thingName] * discountList[thingName] / 100 } - pice = pice * 6 * 8 / 100 - ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否接受商店将以", pice*number, "收购", number, "个", thingName, "?\n回答\"是\"或\"否\""))) + ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否接受商店将以", pice*number*8/100, "收购", number, "个", thingName, "?\n回答\"是\"或\"否\""))) // 等待用户下一步选择 recv, cancel1 := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(是|否)$`), zero.CheckUser(ctx.Event.UserID)).Repeat() defer cancel1() From 8c02b8347da507c5ddf26d7cb69b76d25f1597a0 Mon Sep 17 00:00:00 2001 From: fangliuyu <1725453672@qq.com> Date: Wed, 2 Oct 2024 23:10:44 +0800 Subject: [PATCH 4/9] fix --- plugin/mcfish/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/mcfish/store.go b/plugin/mcfish/store.go index 93a58f218d..f380557521 100644 --- a/plugin/mcfish/store.go +++ b/plugin/mcfish/store.go @@ -173,7 +173,7 @@ func init() { } else { pice = priceList[thingName] * discountList[thingName] / 100 } - ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否接受商店将以", pice*number*8/100, "收购", number, "个", thingName, "?\n回答\"是\"或\"否\""))) + ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否接受商店将以", pice*number*8/10, "收购", number, "个", thingName, "?\n回答\"是\"或\"否\""))) // 等待用户下一步选择 recv, cancel1 := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(是|否)$`), zero.CheckUser(ctx.Event.UserID)).Repeat() defer cancel1() From cfdfc9e74321ec951717991b691c52995cf3116e Mon Sep 17 00:00:00 2001 From: fangliuyu <1725453672@qq.com> Date: Wed, 2 Oct 2024 23:33:24 +0800 Subject: [PATCH 5/9] fix --- plugin/mcfish/main.go | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/plugin/mcfish/main.go b/plugin/mcfish/main.go index 568e317c1e..f20ecc0751 100644 --- a/plugin/mcfish/main.go +++ b/plugin/mcfish/main.go @@ -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,14 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) { Name: name, Discount: thingDiscount, } + if checkIsFish(name) { + 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,28 +623,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 - } - for _, fish := range fishList { - thingInfo := store{ - Duration: time.Now().Unix(), - Name: fish, - Type: "fish", - Price: priceList[fish] * discountList[fish] / 100, - } - _ = sql.db.Find("store", &thingInfo, "where Name = '"+fish+"'") - thingInfo.Number += (100 - discountList[fish]) - if thingInfo.Number < 1 { - thingInfo.Number = 100 - } else if thingInfo.Number > 150 { - // 通货膨胀 - discountList[fish] = (1000 - 5*(thingInfo.Number-150)) / 10 - thingInfo.Price = priceList[fish] * discountList[fish] / 100 - } - _ = sql.db.Insert("store", &thingInfo) - } // 每天调控1种鱼 fish := fishList[rand.Intn(len(fishList))] thingInfo := store{ From 02c85bcae69595825220bf125832eb51ac9c8607 Mon Sep 17 00:00:00 2001 From: fangliuyu <1725453672@qq.com> Date: Wed, 2 Oct 2024 23:36:30 +0800 Subject: [PATCH 6/9] fix --- plugin/mcfish/main.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plugin/mcfish/main.go b/plugin/mcfish/main.go index f20ecc0751..bc74bd6162 100644 --- a/plugin/mcfish/main.go +++ b/plugin/mcfish/main.go @@ -590,13 +590,11 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) { Name: name, Discount: thingDiscount, } - if checkIsFish(name) { - thingInfo := store{} - _ = sql.db.Find("store", &thingInfo, "where Name = '"+name+"'") - if thingInfo.Number > 150 { - // 通货膨胀 - thing.Discount = (1000 - 5*(thingInfo.Number-150)) / 10 - } + 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 { From 9ebcd0e67518f60d6d3cf9b1909f2d5a77cfff10 Mon Sep 17 00:00:00 2001 From: fangliuyu <1725453672@qq.com> Date: Wed, 2 Oct 2024 23:39:25 +0800 Subject: [PATCH 7/9] fix --- plugin/mcfish/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/mcfish/main.go b/plugin/mcfish/main.go index bc74bd6162..928d86d02f 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.5.1" +const version = "5.5.7" // 各物品信息 type jsonInfo struct { @@ -640,7 +640,7 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) { Duration: time.Now().Unix(), Name: "净化书", Type: "article", - Price: priceList["净化书"] * (discountList["净化书"]) / 100, + Price: priceList["净化书"] * discountList["净化书"] / 100, } _ = sql.db.Find("store", &thingInfo, "where Name = '净化书'") thingInfo.Number = 20 From b10b8f31ea327397af4a646239fe83d583338373 Mon Sep 17 00:00:00 2001 From: fangliuyu <1725453672@qq.com> Date: Wed, 2 Oct 2024 23:52:11 +0800 Subject: [PATCH 8/9] fix --- plugin/mcfish/store.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/mcfish/store.go b/plugin/mcfish/store.go index f380557521..eab180b3c1 100644 --- a/plugin/mcfish/store.go +++ b/plugin/mcfish/store.go @@ -755,8 +755,7 @@ func drawStroeInfoImage(stroeInfo []store) (picImage image.Image, err error) { } canvas.SetColor(color.Black) textDy += textDh * 2 - canvas.DrawStringAnchored("注:出售商品 = 价格*60% * (1-20%)", 10, textDy+textDh/2, 0, 0.5) - canvas.DrawStringAnchored(" 鱼竿价格 = 原价-耐久度-维修*2+诱钓*600+眷顾*1000", 10, textDy+20+textDh+10, 0, 0.5) + canvas.DrawStringAnchored("注:出售商品将会额外扣除20%的税收,附魔鱼竿请按实际价格", 10, textDy+10+textDh/2, 0, 0.5) textDy += textH * 2 err = canvas.ParseFontFace(fontdata, 100) From ac4ce76c4a5ad34234d59027391b558b3bfb9ae5 Mon Sep 17 00:00:00 2001 From: fangliuyu <1725453672@qq.com> Date: Thu, 3 Oct 2024 00:00:52 +0800 Subject: [PATCH 9/9] fix --- plugin/mcfish/main.go | 2 +- plugin/mcfish/store.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin/mcfish/main.go b/plugin/mcfish/main.go index 928d86d02f..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.5.7" +const version = "5.5.8" // 各物品信息 type jsonInfo struct { diff --git a/plugin/mcfish/store.go b/plugin/mcfish/store.go index eab180b3c1..75f632bd45 100644 --- a/plugin/mcfish/store.go +++ b/plugin/mcfish/store.go @@ -169,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 }