Skip to content

Commit 95451f9

Browse files
authored
optimize(mcfish): 限制鱼贩的垄断 (#992)
1 parent f3a841f commit 95451f9

File tree

2 files changed

+84
-13
lines changed

2 files changed

+84
-13
lines changed

plugin/mcfish/main.go

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type fishdb struct {
2828
const FishLimit = 50
2929

3030
// version 规则版本号
31-
const version = "5.4.2"
31+
const version = "5.5.8"
3232

3333
// 各物品信息
3434
type jsonInfo struct {
@@ -101,7 +101,7 @@ type buffInfo struct {
101101
Coupon int `db:"Buff1"` // 优惠卷
102102
SalesPole int `db:"Buff2"` // 卖鱼竿上限
103103
BuyTing int `db:"Buff3"` // 购买上限
104-
Buff4 int `db:"Buff4"` // 暂定
104+
SalesFish int `db:"Buff4"` // 卖鱼次数
105105
Buff5 int `db:"Buff5"` // 暂定
106106
Buff6 int `db:"Buff6"` // 暂定
107107
Buff7 int `db:"Buff7"` // 暂定
@@ -149,7 +149,7 @@ var (
149149
"8.合成:\n-> 铁竿 : 3x木竿\n-> 金竿 : 3x铁竿\n-> 钻石竿 : 3x金竿\n-> 下界合金竿 : 3x钻石竿\n-> 三叉戟 : 3x下界合金竿\n注:合成成功率90%(包括梭哈),合成鱼竿的附魔等级=(附魔等级合/合成鱼竿数量)\n" +
150150
"9.杂项:\n-> 无装备的情况下,每人最多可以购买3次100块钱的鱼竿\n-> 默认状态钓鱼上钩概率为60%(理论值!!!)\n-> 附魔的鱼竿会因附魔变得昂贵,每个附魔最高3级\n-> 三叉戟不算鱼竿,修复时可直接满耐久\n" +
151151
"-> 鱼竿数量大于50的不能买东西;\n 鱼竿数量大于30的不能钓鱼;\n 每购/售10次鱼竿获得1层宝藏诅咒;\n 每购买20次物品将获得3次价格减半福利;\n 每钓鱼75次获得1本净化书;\n" +
152-
" 每天最多只可出售5个鱼竿和购买15次物品;",
152+
" 每天最多只可出售5个鱼竿和购买15次物品;鱼类交易每天最多100条.",
153153
PublicDataFolder: "McFish",
154154
}).ApplySingle(ctxext.DefaultSingle)
155155
getdb = fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
@@ -562,6 +562,10 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) {
562562
if err != nil {
563563
return false, err
564564
}
565+
err = sql.db.Create("store", &store{})
566+
if err != nil {
567+
return false, err
568+
}
565569
lastTime := storeDiscount{}
566570
_ = sql.db.Find("stroeDiscount", &lastTime, "where Name = 'lastTime'")
567571
refresh := false
@@ -586,6 +590,12 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) {
586590
Name: name,
587591
Discount: thingDiscount,
588592
}
593+
thingInfo := store{}
594+
_ = sql.db.Find("store", &thingInfo, "where Name = '"+name+"'")
595+
if thingInfo.Number > 150 {
596+
// 通货膨胀
597+
thing.Discount = (1000 - 5*(thingInfo.Number-150)) / 10
598+
}
589599
err = sql.db.Insert("stroeDiscount", &thing)
590600
if err != nil {
591601
return
@@ -611,10 +621,6 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) {
611621
_ = sql.db.Del("stroeDiscount", "where Duration = "+strconv.FormatInt(info.Duration, 10))
612622
}
613623
if refresh {
614-
err = sql.db.Create("store", &store{})
615-
if err != nil {
616-
return
617-
}
618624
// 每天调控1种鱼
619625
fish := fishList[rand.Intn(len(fishList))]
620626
thingInfo := store{
@@ -770,7 +776,7 @@ func (sql *fishdb) useCouponAt(uid int64, times int) (int, error) {
770776
return useTimes, sql.db.Insert("buff", &userInfo)
771777
}
772778

773-
// 检测上限
779+
// 检测卖鱼竿上限
774780
func (sql *fishdb) checkCanSalesFor(uid int64, sales bool) (int, error) {
775781
residue := 0
776782
sql.Lock()
@@ -782,15 +788,52 @@ func (sql *fishdb) checkCanSalesFor(uid int64, sales bool) (int, error) {
782788
}
783789
_ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
784790
if time.Now().Day() != time.Unix(userInfo.Duration, 0).Day() {
791+
userInfo.Duration = time.Now().Unix()
785792
userInfo.SalesPole = 0
786793
userInfo.BuyTing = 0
787794
}
788795
if sales && userInfo.SalesPole < 5 {
789796
residue = 5 - userInfo.SalesPole
790797
userInfo.SalesPole++
791798
} else if userInfo.BuyTing < 15 {
792-
residue = 15 - userInfo.SalesPole
793-
userInfo.SalesPole++
799+
residue = 15 - userInfo.BuyTing
800+
userInfo.BuyTing++
794801
}
795802
return residue, sql.db.Insert("buff", &userInfo)
796803
}
804+
805+
// 检测物品是否是鱼
806+
func checkIsFish(thing string) bool {
807+
for _, v := range fishList {
808+
if v == thing {
809+
return true
810+
}
811+
}
812+
return false
813+
}
814+
815+
// 检测买卖鱼上限
816+
func (sql *fishdb) checkCanSalesFishFor(uid int64, sales int) (int, error) {
817+
residue := 0
818+
sql.Lock()
819+
defer sql.Unlock()
820+
userInfo := buffInfo{ID: uid}
821+
err := sql.db.Create("buff", &userInfo)
822+
if err != nil {
823+
return residue, err
824+
}
825+
_ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
826+
if time.Now().Day() != time.Unix(userInfo.Duration, 0).Day() {
827+
userInfo.Duration = time.Now().Unix()
828+
userInfo.SalesFish = 0
829+
}
830+
maxSales := 100 - userInfo.SalesFish
831+
if maxSales < 0 {
832+
maxSales = 0
833+
}
834+
if sales > maxSales {
835+
sales = maxSales
836+
}
837+
userInfo.SalesFish += sales
838+
return sales, sql.db.Insert("buff", &userInfo)
839+
}

plugin/mcfish/store.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ func init() {
8585
if number == 0 || strings.Contains(thingName, "竿") {
8686
number = 1
8787
}
88+
if checkIsFish(thingName) {
89+
residue, err := dbdata.checkCanSalesFishFor(uid, number)
90+
if err != nil {
91+
ctx.SendChain(message.Text("[ERROR]:", err))
92+
return
93+
}
94+
if residue <= 0 {
95+
ctx.SendChain(message.Text("今天你已经超出了鱼交易数量上限,明天再来买鱼吧"))
96+
return
97+
}
98+
number = residue
99+
}
88100
articles, err := dbdata.getUserThingInfo(uid, thingName)
89101
if err != nil {
90102
ctx.SendChain(message.Text("[ERROR at store.go.5]:", err))
@@ -157,7 +169,9 @@ func init() {
157169
maintenance, _ := strconv.Atoi(poleInfo[1])
158170
induceLevel, _ := strconv.Atoi(poleInfo[2])
159171
favorLevel, _ := strconv.Atoi(poleInfo[3])
160-
pice = (priceList[thingName] - (durationList[thingName] - durable) - maintenance*2 + induceLevel*600 + favorLevel*1800) * discountList[thingName] / 100
172+
pice = (priceList[thingName] - (durationList[thingName] - durable) - maintenance*2 +
173+
induceLevel*600*discountList["诱钓"]/100 +
174+
favorLevel*1800*discountList["海之眷顾"]/100) * discountList[thingName] / 100
161175
} else {
162176
pice = priceList[thingName] * discountList[thingName] / 100
163177
}
@@ -399,14 +413,26 @@ func init() {
399413
return
400414
}
401415
if buytimes <= 0 {
402-
ctx.SendChain(message.Text("出售次数已达到上限,明天再来购买吧"))
416+
ctx.SendChain(message.Text("购买次数已达到上限,明天再来购买吧"))
403417
return
404418
}
405419
thingName := ctx.State["regex_matched"].([]string)[1]
406420
number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[2])
407421
if number == 0 {
408422
number = 1
409423
}
424+
if checkIsFish(thingName) {
425+
residue, err := dbdata.checkCanSalesFishFor(uid, number)
426+
if err != nil {
427+
ctx.SendChain(message.Text("[ERROR]:", err))
428+
return
429+
}
430+
if residue <= 0 {
431+
ctx.SendChain(message.Text("今天你已经超出了鱼交易数量上限,明天再来买鱼吧"))
432+
return
433+
}
434+
number = residue
435+
}
410436
thingInfos, err := dbdata.getStoreThingInfo(thingName)
411437
if err != nil {
412438
ctx.SendChain(message.Text("[ERROR at store.go.11]:", err))
@@ -448,7 +474,9 @@ func init() {
448474
maintenance, _ := strconv.Atoi(poleInfo[1])
449475
induceLevel, _ := strconv.Atoi(poleInfo[2])
450476
favorLevel, _ := strconv.Atoi(poleInfo[3])
451-
thingPice := (priceList[info.Name] - (durationList[info.Name] - durable) - maintenance*2 + induceLevel*600 + favorLevel*1800) * discountList[info.Name] / 100
477+
thingPice := (priceList[info.Name] - (durationList[info.Name] - durable) - maintenance*2 +
478+
induceLevel*600*discountList["诱钓"]/100 +
479+
favorLevel*1800*discountList["海之眷顾"]/100) * discountList[info.Name] / 100
452480
pice = append(pice, thingPice)
453481
} else {
454482
thingPice := priceList[info.Name] * discountList[info.Name] / 100

0 commit comments

Comments
 (0)