Skip to content

Commit

Permalink
optimize(mcfish): 限制鱼贩的垄断 (#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
fangliuyu authored Oct 5, 2024
1 parent f3a841f commit 95451f9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 13 deletions.
63 changes: 53 additions & 10 deletions plugin/mcfish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type fishdb struct {
const FishLimit = 50

// version 规则版本号
const version = "5.4.2"
const version = "5.5.8"

// 各物品信息
type jsonInfo struct {
Expand Down Expand Up @@ -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"` // 暂定
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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{
Expand Down Expand Up @@ -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()
Expand All @@ -782,15 +788,52 @@ 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
}
if sales && userInfo.SalesPole < 5 {
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)
}
34 changes: 31 additions & 3 deletions plugin/mcfish/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -399,14 +413,26 @@ func init() {
return
}
if buytimes <= 0 {
ctx.SendChain(message.Text("出售次数已达到上限,明天再来购买吧"))
ctx.SendChain(message.Text("购买次数已达到上限,明天再来购买吧"))
return
}
thingName := ctx.State["regex_matched"].([]string)[1]
number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[2])
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))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 95451f9

Please sign in to comment.