Skip to content

Commit

Permalink
fix: 修复[mcfish]交易检测逻辑的bug
Browse files Browse the repository at this point in the history
- 修复出售限制不更新的bug
- 修改商品价格浮动区间
  • Loading branch information
vatebur committed Nov 29, 2024
1 parent 83037f6 commit a032ee8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
32 changes: 19 additions & 13 deletions plugin/mcfish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type buffInfo struct {
Coupon int `db:"Buff1"` // 优惠卷
SalesPole int `db:"Buff2"` // 卖鱼竿上限
BuyTing int `db:"Buff3"` // 购买上限
SalesFish int `db:"Buff4"` // 卖鱼次数
Buff4 int `db:"Buff4"` // 暂定
Buff5 int `db:"Buff5"` // 暂定
Buff6 int `db:"Buff6"` // 暂定
Buff7 int `db:"Buff7"` // 暂定
Expand Down Expand Up @@ -148,7 +148,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" +
" 每天可交易鱼竿10个,物品200件.",
" 每天可交易鱼竿10个,物品150件(垃圾除外).",
PublicDataFolder: "McFish",
}).ApplySingle(ctxext.DefaultSingle)
getdb = fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
Expand Down Expand Up @@ -592,8 +592,8 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) {
thingInfo := store{}
_ = sql.db.Find("store", &thingInfo, "WHERE Name = ?", name)
if thingInfo.Number > 150 {
// 商品贬值,价格区间 -50%到0%
thing.Discount = 50 + rand.Intn(50)
// 控制价格浮动区间: -10%到10%
thing.Discount = 90 + rand.Intn(20)
}
err = sql.db.Insert("stroeDiscount", &thing)
if err != nil {
Expand Down Expand Up @@ -776,7 +776,7 @@ func (sql *fishdb) useCouponAt(uid int64, times int) (int, error) {
}

// 买卖上限检测
func (sql *fishdb) checkCanSalesFor(uid int64, saleType string, salesNum int) (int, error) {
func (sql *fishdb) checkCanSalesFor(uid int64, saleName string, salesNum int) (int, error) {
sql.Lock()
defer sql.Unlock()
userInfo := buffInfo{ID: uid}
Expand All @@ -789,15 +789,17 @@ func (sql *fishdb) checkCanSalesFor(uid int64, saleType string, salesNum int) (i
userInfo.Duration = time.Now().Unix()
userInfo.SalesPole = 0
userInfo.BuyTing = 0
userInfo.SalesFish = 0
err := sql.db.Insert("buff", &userInfo)
if err != nil {
return salesNum, err
}
}
if strings.Contains(saleType, "竿") {
if strings.Contains(saleName, "竿") {
if userInfo.SalesPole >= 10 {
salesNum = -1
}
userInfo.SalesPole++
} else {
maxSales := 200 - userInfo.SalesFish
maxSales := 150 - userInfo.BuyTing
if maxSales < 0 {
salesNum = 0
}
Expand All @@ -806,7 +808,7 @@ func (sql *fishdb) checkCanSalesFor(uid int64, saleType string, salesNum int) (i
}
}

return salesNum, sql.db.Insert("buff", &userInfo)
return salesNum, err
}

// 检测物品是否是鱼
Expand All @@ -819,8 +821,8 @@ func checkIsFish(thing string) bool {
return false
}

// 更新买卖鱼上限,假定sales变量已经在 selectCanSalesFishFor 进行了防护
func (sql *fishdb) updateCanSalesFishFor(uid int64, sales int) error {
// 更新买卖鱼上限,假定sales变量已经在 checkCanSalesFor 进行了防护
func (sql *fishdb) updateCanSalesFor(uid int64, saleName string, sales int) error {
sql.Lock()
defer sql.Unlock()
userInfo := buffInfo{ID: uid}
Expand All @@ -829,6 +831,10 @@ func (sql *fishdb) updateCanSalesFishFor(uid int64, sales int) error {
return err
}
_ = sql.db.Find("buff", &userInfo, "WHERE ID = ?", uid)
userInfo.SalesFish += sales
if strings.Contains(saleName, "竿") {
userInfo.SalesPole++
} else {
userInfo.BuyTing += sales
}
return sql.db.Insert("buff", &userInfo)
}
20 changes: 9 additions & 11 deletions plugin/mcfish/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func init() {
if strings.Contains(thingName, "竿") {
msg = "一天只能交易10把鱼竿,明天再来售卖吧"
} else {
msg = "一天只能交易200次物品,明天再来吧~"
msg = "一天只能交易150次物品(垃圾除外),明天再来吧~"
}
ctx.SendChain(message.Text(msg))
return
Expand Down Expand Up @@ -313,9 +313,9 @@ func init() {
logrus.Warnln(err)
}
}
// 更新交易鱼类数量
if checkIsFish(thingName) {
err := dbdata.updateCanSalesFishFor(uid, number)
// 更新交易限制(商店不卖垃圾)
if newCommodity.Type != "waste" {
err := dbdata.updateCanSalesFor(uid, thingName, number)
if err != nil {
ctx.SendChain(message.Text("[ERROR,记录鱼类交易数量失败,此次交易不记录]:", err))
}
Expand Down Expand Up @@ -428,7 +428,7 @@ func init() {
if strings.Contains(thingName, "竿") {
msg = "一天只能交易10把鱼竿,明天再来售卖吧"
} else {
msg = "一天只能交易200次物品,明天再来吧~"
msg = "一天只能交易150次物品,明天再来吧~"
}
ctx.SendChain(message.Text(msg))
return
Expand Down Expand Up @@ -651,12 +651,10 @@ func init() {
logrus.Warnln(err)
}
}
// 更新交易鱼类数量
if checkIsFish(thingName) {
err := dbdata.updateCanSalesFishFor(uid, number)
if err != nil {
ctx.SendChain(message.Text("[ERROR,更新鱼类交易数量失败,此次交易不记录]:", err))
}
// 更新交易限制(商店不卖垃圾)
err = dbdata.updateCanSalesFor(uid, thingName, number)
if err != nil {
ctx.SendChain(message.Text("[ERROR,更新鱼类交易数量失败,此次交易不记录]:", err))
}
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("你用", price, "购买了", number, thingName)))
})
Expand Down

0 comments on commit a032ee8

Please sign in to comment.