Skip to content

Commit

Permalink
fix: mcfish (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
fangliuyu committed Sep 19, 2023
1 parent cb52bf6 commit 99b14e1
Show file tree
Hide file tree
Showing 8 changed files with 333 additions and 98 deletions.
2 changes: 1 addition & 1 deletion data
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordle" // 猜单词
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ygo" // 游戏王相关插件
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal" // 月幕galgame

// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/wtf" // 鬼东西

// ^^^^ //
Expand Down
41 changes: 40 additions & 1 deletion plugin/mcfish/fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ import (
func init() {
engine.OnRegex(`^进行(([1-5]\d|[1-9])次)?钓鱼$`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
numberOfPole, err := dbdata.getNumberFor(uid, "竿")
if err != nil {
ctx.SendChain(message.Text("[ERROR at store.go.9.3]:", err))
return
}
if numberOfPole > 30 {
ctx.SendChain(message.Text("你有", numberOfPole, "支鱼竿,大于30支的玩家不允许钓鱼"))
return
}
fishNumber := 1
info := ctx.State["regex_matched"].([]string)[2]
if info != "" {
Expand Down Expand Up @@ -114,7 +123,10 @@ func init() {
if equipInfo.Durable < 10 && equipInfo.Durable > 0 {
msg = "(你的鱼竿耐久仅剩" + strconv.Itoa(equipInfo.Durable) + ")"
} else if equipInfo.Durable <= 0 {
msg = "(你的鱼竿耐已销毁)"
msg = "(你的鱼竿已销毁)"
}
if equipInfo.Equip == "三叉戟" {
fishNumber *= 3
}
} else {
fishNmaes, err := dbdata.pickFishFor(uid, fishNumber)
Expand All @@ -138,6 +150,7 @@ func init() {
msg += strconv.Itoa(number) + name + "、"
}
msg += ")"
fishNumber /= 2
}
waitTime := 120 / (equipInfo.Induce + 1)
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你开始去钓鱼了,请耐心等待鱼上钩(预计要", time.Second*time.Duration(waitTime), ")"))
Expand All @@ -153,6 +166,11 @@ func init() {
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
return
}
number2, err := dbdata.getNumberFor(uid, "海豚")
if err != nil {
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
return
}
if number > 100 || equipInfo.Equip == "美西螈" { // 放大概率
probabilities["treasure"] = probabilityLimit{
Min: 0,
Expand All @@ -171,6 +189,11 @@ func init() {
Max: 90,
}
}
if number2 != 0 {
info := probabilities["waste"]
info.Max = 100
probabilities["waste"] = info
}
for name, info := range probabilities {
switch name {
case "treasure":
Expand Down Expand Up @@ -217,6 +240,18 @@ func init() {
typeOfThing = "article"
picName = "book"
thingName = "海之眷顾"
case dice >= probabilities["净化书"].Min && dice < probabilities["净化书"].Max:
typeOfThing = "article"
picName = "book"
thingName = "净化书"
case dice >= probabilities["宝藏诅咒"].Min && dice < probabilities["宝藏诅咒"].Max:
typeOfThing = "article"
picName = "book"
thingName = "宝藏诅咒"
case dice >= probabilities["海豚"].Min && dice < probabilities["海豚"].Max:
typeOfThing = "fish"
picName = "海豚"
thingName = "海豚"
default:
typeOfThing = "article"
picName = "book"
Expand Down Expand Up @@ -300,6 +335,10 @@ func init() {
thingNameList[thingName] += number
}
}
err = dbdata.updateCurseFor(uid, "fish", fishNumber)
if err != nil {
logrus.Warnln(err)
}
if len(thingNameList) == 1 {
thingName := ""
numberOfFish := 0
Expand Down
166 changes: 120 additions & 46 deletions plugin/mcfish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type fishdb struct {
// FishLimit 钓鱼次数上限
const FishLimit = 50

// version 规则版本号
const version = "5.4.1"

// 各物品信息
type jsonInfo struct {
ZoneInfo []zoneInfo `json:"分类"` // 区域概率
Expand Down Expand Up @@ -79,6 +82,8 @@ type fishState struct {
Duration int64
Fish int
Equip int
Curse int // 功德--(x)
Bless int // 功德++(x)
}

type storeDiscount struct {
Expand Down Expand Up @@ -109,18 +114,23 @@ var (
Brief: "钓鱼",
Help: "一款钓鱼模拟器\n----------指令----------\n" +
"- 钓鱼看板/钓鱼商店\n- 购买xxx\n- 购买xxx [数量]\n- 出售xxx\n- 出售xxx [数量]\n" +
"- 钓鱼背包\n- 装备[xx竿|三叉戟|美西螈]\n- 附魔[诱钓|海之眷顾]\n- 修复鱼竿\n- 合成[xx竿|三叉戟]\n" +
"- 钓鱼背包\n- 装备[xx竿|三叉戟|美西螈]\n- 附魔[诱钓|海之眷顾]\n- 修复鱼竿\n- 合成[xx竿|三叉戟]\n- 消除绑定诅咒\n- 消除绑定诅咒 [数量]\n" +
"- 进行钓鱼\n- 进行n次钓鱼\n- 当前装备概率明细\n" +
"规则:\n1.每日的商店价格是波动的!!如何最大化收益自己考虑一下喔\n" +
"规则V" + version + ":\n" +
"1.每日的商店价格是波动的!!如何最大化收益自己考虑一下喔\n" +
"2.装备信息:\n-> 木竿 : 耐久上限:30 均价:100 上钩概率:0.7%\n-> 铁竿 : 耐久上限:50 均价:300 上钩概率:0.2%\n-> 金竿 : 耐久上限:70 均价700 上钩概率:0.06%\n" +
"-> 钻石竿 : 耐久上限:100 均价1500 上钩概率:0.03%\n-> 下界合金竿 : 耐久上限:150 均价3100 上钩概率:0.01%\n-> 三叉戟 : 可使钓的鱼类物品数量变成3 耐久上限:300 均价4000 只能合成和交易\n" +
"3.附魔书信息:\n-> 诱钓 : 减少上钩时间. 均价:1000, 上钩概率:0.59%\n-> 海之眷顾 : 增加宝藏上钩概率. 均价:2500, 上钩概率:0.39%\n" +
"4.稀有物品:\n-> 唱片 : 出售物品时使用该物品使价格翻倍. 均价:3000, 上钩概率:0.01%\n-> 美西螈 : 可装备,获得隐形[钓鱼佬]buff,并让钓到除鱼竿和美西螈外的物品数量变成3,无耐久上限.不可修复/附魔,每次钓鱼消耗任意一鱼类物品. 均价:3000, 上钩概率:0.01%\n" +
"-> 钻石竿 : 耐久上限:100 均价1500 上钩概率:0.03%\n-> 下界合金竿 : 耐久上限:150 均价3100 上钩概率:0.01%\n-> 三叉戟 : 可使1次钓鱼视为3次钓鱼. 耐久上限:300 均价4000 只能合成、修复和交易\n" +
"3.附魔书信息:\n-> 诱钓 : 减少上钩时间. 均价:1000, 上钩概率:0.25%\n-> 海之眷顾 : 增加宝藏上钩概率. 均价:2500, 上钩概率:0.10%\n" +
"4.稀有物品:\n-> 唱片 : 出售物品时使用该物品使价格翻倍. 均价:3000, 上钩概率:0.01%\n" +
"-> 美西螈 : 可装备,获得隐形[钓鱼佬]buff,并让钓到除鱼竿和美西螈外的物品数量变成3,无耐久上限.不可修复/附魔,每次钓鱼消耗两任意鱼类物品. 均价:3000, 上钩概率:0.01%\n" +
"-> 海豚 : 使空竿概率变成垃圾概率. 均价:1000, 上钩概率:0.19%\n" +
"-> 宝藏诅咒 : 无法交易,每一层就会增加购买时10%价格和减少出售时10%价格(超过10层会变为倒贴钱). 上钩概率:0.25%\n-> 净化书 : 用于消除宝藏诅咒. 均价:5000, 上钩概率:0.19%\n" +
"5.鱼类信息:\n-> 鳕鱼 : 均价:10 上钩概率:0.69%\n-> 鲑鱼 : 均价:50 上钩概率:0.2%\n-> 热带鱼 : 均价:100 上钩概率:0.06%\n-> 河豚 : 均价:300 上钩概率:0.03%\n-> 鹦鹉螺 : 均价:500 上钩概率:0.01%\n-> 墨鱼 : 均价:500 上钩概率:0.01%\n" +
"6.垃圾:\n-> 均价:10 上钩概率:30%\n" +
"7.物品BUFF:\n-> 钓鱼佬 : 当背包名字含有'鱼'的物品数量超过100时激活,钓到物品概率提高至90%\n-> 修复大师 : 当背包鱼竿数量超过10时激活,修复物品时耐久百分百继承\n" +
"8.合成:\n-> 铁竿 : 3x木竿\n-> 金竿 : 3x铁竿\n-> 钻石竿 : 3x金竿\n-> 下界合金竿 : 3x钻石竿\n-> 三叉戟 : 3x下界合金竿\n注:合成成功率90%,继承附魔等级合/3的等级\n" +
"9.杂项:\n-> 无装备的情况下,每人最多可以购买3次100块钱的鱼竿\n-> 默认状态钓鱼上钩概率为60%(理论值!!!)\n-> 附魔的鱼竿会因附魔变得昂贵,每个附魔最高3级\n-> 三叉戟不算鱼竿",
"9.杂项:\n-> 无装备的情况下,每人最多可以购买3次100块钱的鱼竿\n-> 默认状态钓鱼上钩概率为60%(理论值!!!)\n-> 附魔的鱼竿会因附魔变得昂贵,每个附魔最高3级\n-> 三叉戟不算鱼竿,修复时可直接满耐久\n" +
"-> 鱼竿数量大于50的不能买东西;\n 鱼竿数量大于30的不能钓鱼;\n 每购/售10次物品获得1层宝藏诅咒;\n 每钓鱼75次获得1本净化书",
PublicDataFolder: "McFish",
}).ApplySingle(ctxext.DefaultSingle)
getdb = fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
Expand Down Expand Up @@ -184,15 +194,17 @@ func init() {
switch {
case info.Type == "pole" || info.Name == "美西螈":
poleList = append(poleList, info.Name)
case info.Type == "fish":
case info.Type == "fish" || info.Name == "海豚":
fishList = append(fishList, info.Name)
case info.Type == "waste":
wasteList = append(wasteList, info.Name)
case info.Type == "treasure":
treasureList = append(treasureList, info.Name)
}
thingList = append(thingList, info.Name)
priceList[info.Name] = info.Price
if info.Name != "宝藏诅咒" {
thingList = append(thingList, info.Name)
priceList[info.Name] = info.Price
}
if info.Durable != 0 {
durationList[info.Name] = info.Durable
}
Expand Down Expand Up @@ -232,6 +244,56 @@ func (sql *fishdb) updateFishInfo(uid int64, number int) (residue int, err error
return
}

// 更新buff
func (sql *fishdb) updateCurseFor(uid int64, info string, number int) (err error) {
if number < 1 {
return
}
sql.Lock()
defer sql.Unlock()
userInfo := fishState{ID: uid}
err = sql.db.Create("fishState", &userInfo)
if err != nil {
return err
}
changeCheck := false
add := 0
buffName := "宝藏诅咒"
_ = sql.db.Find("fishState", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
if info == "fish" {
userInfo.Bless += number
for userInfo.Bless >= 75 {
add++
changeCheck = true
buffName = "净化书"
userInfo.Bless -= 75
}
} else {
userInfo.Curse += number
for userInfo.Curse >= 10 {
add++
changeCheck = true
userInfo.Curse -= 10
}
}
err = sql.db.Insert("fishState", &userInfo)
if err != nil {
return err
}
if changeCheck {
table := strconv.FormatInt(uid, 10) + "Pack"
thing := article{
Duration: time.Now().Unix(),
Name: buffName,
Type: "treasure",
}
_ = sql.db.Find(table, &thing, "where Name = '"+buffName+"'")
thing.Number += add
return sql.db.Insert(table, &thing)
}
return
}

/*********************************************************/
/************************装备相关函数***********************/
/*********************************************************/
Expand Down Expand Up @@ -322,41 +384,32 @@ func (sql *fishdb) pickFishFor(uid int64, number int) (fishNames map[string]int,
if !sql.db.CanFind(name, "where Type is 'fish'") {
return
}
fishTypes := make([]article, 0, count)
fishInfo := article{}
err = sql.db.FindFor(name, &fishInfo, "where Type is 'fish'", func() error {
fishTypes = append(fishTypes, fishInfo)
return nil
})
if err != nil {
return
}
if len(fishTypes) == 0 {
return
}
max := 0
for _, info := range fishTypes {
max += info.Number
}
if max < number {
number = max
}
for i := number; i > 0; {
randNumber := rand.Intn(len(fishTypes))
if fishTypes[randNumber].Number <= 0 {
k := 0
for i := number * 2; i > 0 && k < len(fishList); {
_ = sql.db.Find(name, &fishInfo, "where Name is '"+fishList[k]+"'")
if fishInfo.Number <= 0 {
k++
continue
}
fishTypes[randNumber].Number--
if fishTypes[randNumber].Number <= 0 {
err = sql.db.Del(name, "where Duration = "+strconv.FormatInt(fishTypes[randNumber].Duration, 10))
if fishInfo.Number < i {
k++
fishInfo.Number = 0
i -= fishInfo.Number
fishNames[fishInfo.Name] += fishInfo.Number
} else {
err = sql.db.Insert(name, &fishTypes[randNumber])
fishNames[fishInfo.Name] += i
fishInfo.Number -= i
i = 0
}
if fishInfo.Number <= 0 {
err = sql.db.Del(name, "where Duration = "+strconv.FormatInt(fishInfo.Duration, 10))
} else {
err = sql.db.Insert(name, &fishInfo)
}
if err != nil {
return
}
fishNames[fishTypes[randNumber].Name]++
i--
}
return
}
Expand Down Expand Up @@ -507,24 +560,45 @@ func (sql *fishdb) refreshStroeInfo() (ok bool, err error) {
discountList[name] = 100
}
}
if refresh { // 每天调控1种鱼
thingInfo := store{}
err = sql.db.Create("store", &thingInfo)
thing := store{}
oldThing := []store{}
_ = sql.db.FindFor("stroeDiscount", &thing, "where type = 'pole'", func() error {
if time.Since(time.Unix(thing.Duration, 0)) > 24 {
oldThing = append(oldThing, thing)
}
return nil
})
for _, info := range oldThing {
_ = 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))]
_ = sql.db.Find("store", &thingInfo, "where Name = '"+fish+"'")
if thingInfo == (store{}) {
thingInfo.Duration = time.Now().Unix()
thingInfo.Type = "fish"
thingInfo.Name = fish
thingInfo.Price = priceList[fish] * discountList[fish] / 100
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 = 1
thingInfo.Number = 100
}
_ = sql.db.Insert("store", &thingInfo)
// 每天上架20本净化书
thingInfo = store{
Duration: time.Now().Unix(),
Name: "净化书",
Type: "article",
Price: priceList["净化书"] * discountList["净化书"] / 100,
}
_ = sql.db.Find("store", &thingInfo, "where Name = '净化书'")
thingInfo.Number = 20
_ = sql.db.Insert("store", &thingInfo)
}
return true, nil
Expand Down

0 comments on commit 99b14e1

Please sign in to comment.