mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-18 20:50:12 +08:00
fix: mcfish (#743)
This commit is contained in:
parent
cb52bf6af7
commit
99b14e183a
2
data
2
data
@ -1 +1 @@
|
||||
Subproject commit 32dffa9c507055b583935a94712ea8b8c79100e6
|
||||
Subproject commit 8a233fd72f682cb48966fc30a1c14761ca76e1f2
|
||||
1
main.go
1
main.go
@ -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" // 鬼东西
|
||||
|
||||
// ^^^^ //
|
||||
|
||||
@ -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 != "" {
|
||||
@ -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)
|
||||
@ -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), ")"))
|
||||
@ -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,
|
||||
@ -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":
|
||||
@ -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"
|
||||
@ -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
|
||||
|
||||
@ -26,6 +26,9 @@ type fishdb struct {
|
||||
// FishLimit 钓鱼次数上限
|
||||
const FishLimit = 50
|
||||
|
||||
// version 规则版本号
|
||||
const version = "5.4.1"
|
||||
|
||||
// 各物品信息
|
||||
type jsonInfo struct {
|
||||
ZoneInfo []zoneInfo `json:"分类"` // 区域概率
|
||||
@ -79,6 +82,8 @@ type fishState struct {
|
||||
Duration int64
|
||||
Fish int
|
||||
Equip int
|
||||
Curse int // 功德--(x)
|
||||
Bless int // 功德++(x)
|
||||
}
|
||||
|
||||
type storeDiscount struct {
|
||||
@ -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 {
|
||||
@ -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
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/************************装备相关函数***********************/
|
||||
/*********************************************************/
|
||||
@ -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
|
||||
}
|
||||
@ -507,25 +560,46 @@ 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
|
||||
}
|
||||
|
||||
@ -42,6 +42,57 @@ func init() {
|
||||
}
|
||||
ctx.SendChain(message.ImageBytes(pic))
|
||||
})
|
||||
engine.OnRegex(`^消除绑定诅咒(\d*)$`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[1])
|
||||
if number == 0 {
|
||||
number = 1
|
||||
}
|
||||
number1, err := dbdata.getNumberFor(uid, "宝藏诅咒")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.3.1]:", err))
|
||||
return
|
||||
}
|
||||
if number1 == 0 {
|
||||
ctx.SendChain(message.Text("你没有绑定任何诅咒"))
|
||||
return
|
||||
}
|
||||
if number1 < number {
|
||||
number = number1
|
||||
}
|
||||
number2, err := dbdata.getNumberFor(uid, "净化书")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.3.2]:", err))
|
||||
return
|
||||
}
|
||||
if number2 < number {
|
||||
ctx.SendChain(message.Text("你没有足够的解除诅咒的道具"))
|
||||
return
|
||||
}
|
||||
articles, err := dbdata.getUserThingInfo(uid, "净化书")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.3.3]:", err))
|
||||
return
|
||||
}
|
||||
articles[0].Number -= number
|
||||
err = dbdata.updateUserThingInfo(uid, articles[0])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.3.4]:", err))
|
||||
return
|
||||
}
|
||||
articles, err = dbdata.getUserThingInfo(uid, "宝藏诅咒")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("消除失败,净化书销毁了\n[ERROR at store.go.3.5]:", err))
|
||||
return
|
||||
}
|
||||
articles[0].Number -= number
|
||||
err = dbdata.updateUserThingInfo(uid, articles[0])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.3.5]:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("消除成功"))
|
||||
})
|
||||
engine.OnFullMatch("当前装备概率明细", getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
equipInfo, err := dbdata.getUserEquip(uid)
|
||||
@ -95,15 +146,27 @@ func init() {
|
||||
}
|
||||
msg = append(msg, message.Text("-----------\n鱼竿概率:\n"))
|
||||
for _, name := range poleList {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[1])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
if name != "美西螈" {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[1])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
} else if name == "美西螈" {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[0])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
}
|
||||
}
|
||||
msg = append(msg, message.Text("-----------\n鱼类概率:\n"))
|
||||
for _, name := range fishList {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[2])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
if name != "海豚" {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[2])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
} else if name == "海豚" {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[0])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
}
|
||||
}
|
||||
msg = append(msg, message.Text("-----------"))
|
||||
ctx.Send(msg)
|
||||
|
||||
@ -411,10 +411,6 @@ func init() {
|
||||
return
|
||||
}
|
||||
chooseList := strings.Split(nextcmd, " ")
|
||||
if list[0] == list[1] || list[0] == list[2] || list[1] == list[2] {
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text("[0]请输入正确的序号\n", list))
|
||||
continue
|
||||
}
|
||||
first, err := strconv.Atoi(chooseList[0])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.11.1]:", err))
|
||||
@ -430,11 +426,15 @@ func init() {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.11.3]:", err))
|
||||
return
|
||||
}
|
||||
list = []int{first, second, third}
|
||||
if first == second || first == third || second == third {
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text("[0]请输入正确的序号\n", list))
|
||||
continue
|
||||
}
|
||||
if first > max || second > max || third > max {
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text("[", max, "]请输入正确的序号\n", list))
|
||||
continue
|
||||
}
|
||||
list = []int{first, second, third}
|
||||
check = true
|
||||
}
|
||||
if check {
|
||||
@ -478,7 +478,7 @@ func init() {
|
||||
}
|
||||
ctx.Send(
|
||||
message.ReplyWithMessage(ctx.Event.MessageID,
|
||||
message.Text(thingName, "合成成功\n属性: ", attribute),
|
||||
message.Text(thingName, "合成成功", list, "\n属性: ", attribute),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/img/text"
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
@ -65,7 +66,7 @@ func init() {
|
||||
uid := ctx.Event.UserID
|
||||
thingName := ctx.State["regex_matched"].([]string)[1]
|
||||
number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[2])
|
||||
if number == 0 {
|
||||
if number == 0 || strings.Contains(thingName, "竿") {
|
||||
number = 1
|
||||
}
|
||||
articles, err := dbdata.getUserThingInfo(uid, thingName)
|
||||
@ -90,7 +91,7 @@ func init() {
|
||||
"[", i, "]", info.Name, " 数量: ", info.Number, "\n"))
|
||||
}
|
||||
}
|
||||
msg = append(msg, message.Reply(ctx.Event.MessageID), message.Text("————————\n输入对应序号进行装备,或回复“取消”取消"))
|
||||
msg = append(msg, message.Text("————————\n输入对应序号进行装备,或回复“取消”取消"))
|
||||
ctx.Send(msg)
|
||||
// 等待用户下一步选择
|
||||
sell := false
|
||||
@ -158,7 +159,7 @@ func init() {
|
||||
case e := <-recv:
|
||||
nextcmd := e.Event.Message.String()
|
||||
if nextcmd == "否" {
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("已取消购买")))
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("已取消出售")))
|
||||
return
|
||||
}
|
||||
buy = true
|
||||
@ -212,6 +213,16 @@ func init() {
|
||||
}
|
||||
}
|
||||
}
|
||||
msg := ""
|
||||
curse, err := dbdata.getNumberFor(uid, "宝藏诅咒")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.9.3]:", err))
|
||||
return
|
||||
}
|
||||
if curse != 0 {
|
||||
msg = "\n(你身上绑定了" + strconv.Itoa(curse) + "层诅咒)"
|
||||
pice = pice * (100 - 10*curse) / 100
|
||||
}
|
||||
thing.Number -= number
|
||||
err = dbdata.updateUserThingInfo(uid, thing)
|
||||
if err != nil {
|
||||
@ -219,16 +230,20 @@ func init() {
|
||||
return
|
||||
}
|
||||
newCommodity := store{}
|
||||
if strings.Contains(thingName, "竿") || thingName == "三叉戟" {
|
||||
if pice >= priceList[thingName]*4/5 { // 不值钱的删了
|
||||
if strings.Contains(thing.Name, "竿") || thing.Name == "三叉戟" {
|
||||
if pice >= priceList[thing.Name]*2 { // 无附魔的不要
|
||||
newCommodity = store{
|
||||
Duration: time.Now().Unix(),
|
||||
Type: "pole",
|
||||
Name: thingName,
|
||||
Name: thing.Name,
|
||||
Number: 1,
|
||||
Price: pice,
|
||||
Other: thing.Other,
|
||||
}
|
||||
polelist, _ := dbdata.getStoreThingInfo(thing.Name)
|
||||
if len(polelist) > 5 { // 超出上限的不要
|
||||
newCommodity.Type = "waste"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
things, err1 := dbdata.getStoreThingInfo(thingName)
|
||||
@ -239,26 +254,25 @@ func init() {
|
||||
if len(things) == 0 {
|
||||
things = append(things, store{
|
||||
Duration: time.Now().Unix(),
|
||||
Name: thingName,
|
||||
Number: 0,
|
||||
Name: thing.Name,
|
||||
Price: pice,
|
||||
Type: thing.Type,
|
||||
})
|
||||
switch {
|
||||
case thingName == "海之眷顾" || thingName == "诱钓" || thingName == "唱片":
|
||||
things[0].Type = "article"
|
||||
case thingName == "美西螈":
|
||||
things[0].Type = "pole"
|
||||
default:
|
||||
things[0].Type = "fish"
|
||||
}
|
||||
}
|
||||
newCommodity = things[0]
|
||||
newCommodity.Number += number
|
||||
if newCommodity.Number < 255 {
|
||||
newCommodity.Number += number
|
||||
if newCommodity.Number > 255 {
|
||||
newCommodity.Number = 255
|
||||
}
|
||||
}
|
||||
}
|
||||
err = dbdata.updateStoreInfo(newCommodity)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.9]:", err))
|
||||
return
|
||||
if newCommodity != (store{}) && newCommodity.Type != "waste" { // 不收垃圾
|
||||
err = dbdata.updateStoreInfo(newCommodity)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.9]:", err))
|
||||
return
|
||||
}
|
||||
}
|
||||
pice = pice * 8 / 10
|
||||
err = wallet.InsertWalletOf(uid, pice*number)
|
||||
@ -266,10 +280,23 @@ func init() {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.10]:", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("出售成功,你赚到了", pice*number)))
|
||||
err = dbdata.updateCurseFor(uid, "sell", 1)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("出售成功,你赚到了", pice*number, msg)))
|
||||
})
|
||||
engine.OnRegex(`^购买(`+strings.Join(thingList, "|")+`)\s*(\d*)$`, getdb, refreshFish).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 > 50 {
|
||||
ctx.SendChain(message.Text("你有", numberOfPole, "支鱼竿,大于50支的玩家不允许购买东西"))
|
||||
return
|
||||
}
|
||||
thingName := ctx.State["regex_matched"].([]string)[1]
|
||||
number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[2])
|
||||
if number == 0 {
|
||||
@ -284,6 +311,29 @@ func init() {
|
||||
ctx.SendChain(message.Text("当前商店并没有上架该物品"))
|
||||
return
|
||||
}
|
||||
if thingName == "净化书" {
|
||||
curse, err := dbdata.getNumberFor(uid, "宝藏诅咒")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.303]:", err))
|
||||
return
|
||||
}
|
||||
if curse == 0 {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你身上没有诅咒,不能购买该商品"))
|
||||
return
|
||||
}
|
||||
bless, err := dbdata.getNumberFor(uid, "净化书")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.303]:", err))
|
||||
return
|
||||
}
|
||||
if bless >= curse {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你身上净化书已足够,不能购买该商品"))
|
||||
return
|
||||
}
|
||||
if curse < number {
|
||||
number = curse
|
||||
}
|
||||
}
|
||||
index := 0
|
||||
pice := make([]int, 0, len(thingInfos))
|
||||
for _, info := range thingInfos {
|
||||
@ -355,14 +405,26 @@ func init() {
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("商店数量不足")))
|
||||
return
|
||||
}
|
||||
price := pice[index] * number
|
||||
|
||||
curse, err := dbdata.getNumberFor(uid, "宝藏诅咒")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.9.3]:", err))
|
||||
return
|
||||
}
|
||||
msg := ""
|
||||
if curse != 0 {
|
||||
msg = "\n(你身上绑定了" + strconv.Itoa(curse) + "层诅咒)"
|
||||
price = price * (100 + 10*curse) / 100
|
||||
}
|
||||
|
||||
money := wallet.GetWalletOf(uid)
|
||||
if money < pice[index]*number {
|
||||
ctx.SendChain(message.Text("你身上的钱(", money, ")不够支付"))
|
||||
if money < price {
|
||||
ctx.SendChain(message.Text("你身上的钱(", money, ")不够支付", msg))
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("你确定花费", pice[index]*number, "购买", number, "个", thingName, "?\n回答\"是\"或\"否\"")))
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("你确定花费", price, "购买", number, "个", thingName, "?", msg, "\n回答\"是\"或\"否\"")))
|
||||
// 等待用户下一步选择
|
||||
recv, cancel1 := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(是|否)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
|
||||
defer cancel1()
|
||||
@ -400,7 +462,7 @@ func init() {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.12]:", err))
|
||||
return
|
||||
}
|
||||
err = wallet.InsertWalletOf(uid, -pice[index]*number)
|
||||
err = wallet.InsertWalletOf(uid, -price)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.13]:", err))
|
||||
return
|
||||
@ -409,8 +471,8 @@ func init() {
|
||||
if strings.Contains(thingName, "竿") || thingName == "三叉戟" {
|
||||
newCommodity = article{
|
||||
Duration: time.Now().Unix(),
|
||||
Type: "pole",
|
||||
Name: thingName,
|
||||
Type: thing.Type,
|
||||
Name: thing.Name,
|
||||
Number: 1,
|
||||
Other: thing.Other,
|
||||
}
|
||||
@ -423,17 +485,9 @@ func init() {
|
||||
if len(things) == 0 {
|
||||
things = append(things, article{
|
||||
Duration: time.Now().Unix(),
|
||||
Name: thingName,
|
||||
Number: 0,
|
||||
Name: thing.Name,
|
||||
Type: thing.Type,
|
||||
})
|
||||
switch {
|
||||
case thingName == "海之眷顾" || thingName == "诱钓" || thingName == "唱片":
|
||||
things[0].Type = "article"
|
||||
case thingName == "美西螈":
|
||||
things[0].Type = "pole"
|
||||
default:
|
||||
things[0].Type = "fish"
|
||||
}
|
||||
}
|
||||
newCommodity = things[0]
|
||||
newCommodity.Number += number
|
||||
@ -443,6 +497,10 @@ func init() {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.14]:", err))
|
||||
return
|
||||
}
|
||||
err = dbdata.updateCurseFor(uid, "buy", 1)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("购买成功")))
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user