mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 15:20:22 +00:00
fix: mcfish (#743)
This commit is contained in:
@@ -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("购买成功")))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user