Skip to content

Commit b7e21fc

Browse files
authored
[新增插件]钓鱼模拟器 (#721)
* Add files via upload * Update README.md * Add files via upload * Add files via upload * Update pole.go * Update pole.go * Update main.go * Add files via upload * Add files via upload * Update main.go * Update pack.go * Add files via upload
1 parent 6bff62b commit b7e21fc

File tree

6 files changed

+2464
-0
lines changed

6 files changed

+2464
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,23 @@ print("run[CQ:image,file="+j["img"]+"]")
959959

960960
- [x] 吟唱提示[xxxx]
961961

962+
</details>
963+
<details>
964+
<summary>钓鱼模拟器</summary>
965+
966+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/mcfish"`
967+
968+
- [x] 钓鱼商店
969+
- [x] 购买xxx [数量]
970+
- [x] 出售xxx [数量]
971+
- [x] 钓鱼背包
972+
- [x] 装备[xx竿|三叉戟|美西螈]
973+
- [x] 附魔[诱钓|海之眷顾]
974+
- [x] 修复鱼竿
975+
- [x] 合成[xx竿|三叉戟]
976+
- [x] 进行钓鱼
977+
- [x] 进行n次钓鱼
978+
962979
</details>
963980
<details>
964981
<summary>简易midi音乐制作</summary>

plugin/mcfish/fish.go

Lines changed: 329 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
1+
// Package mcfish 钓鱼模拟器
2+
package mcfish
3+
4+
import (
5+
"math/rand"
6+
"strconv"
7+
"strings"
8+
"time"
9+
10+
"github.com/FloatTech/AnimeAPI/wallet"
11+
"github.com/FloatTech/zbputils/ctxext"
12+
"github.com/sirupsen/logrus"
13+
zero "github.com/wdvxdr1123/ZeroBot"
14+
"github.com/wdvxdr1123/ZeroBot/message"
15+
)
16+
17+
func init() {
18+
engine.OnRegex(`^进行(([1-5]\d|[1-9])次)?钓鱼$`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
19+
uid := ctx.Event.UserID
20+
fishNumber := 1
21+
info := ctx.State["regex_matched"].([]string)[2]
22+
if info != "" {
23+
number, err := strconv.Atoi(info)
24+
if err != nil || number > FishLimit {
25+
ctx.SendChain(message.Text("请输入正确的次数"))
26+
return
27+
}
28+
fishNumber = number
29+
}
30+
equipInfo, err := dbdata.getUserEquip(uid)
31+
if err != nil {
32+
ctx.SendChain(message.Text("[ERROR at fish.go.2]:", err))
33+
return
34+
}
35+
if equipInfo == (equip{}) {
36+
ok, err := dbdata.checkEquipFor(uid)
37+
if err != nil {
38+
ctx.SendChain(message.Text("[ERROR at fish.go.2.1]:", err))
39+
return
40+
}
41+
if !ok {
42+
ctx.SendChain(message.At(uid), message.Text("请装备鱼竿后钓鱼", err))
43+
return
44+
}
45+
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你尚未装备鱼竿,是否花费100购买鱼竿?\n回答\"\"\"\""))
46+
// 等待用户下一步选择
47+
recv, cancel := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(是|否)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
48+
defer cancel()
49+
buy := false
50+
for {
51+
select {
52+
case <-time.After(time.Second * 120):
53+
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("等待超时,取消钓鱼")))
54+
return
55+
case e := <-recv:
56+
nextcmd := e.Event.Message.String()
57+
if nextcmd == "否" {
58+
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("已取消购买")))
59+
return
60+
}
61+
money := wallet.GetWalletOf(uid)
62+
if money < 100 {
63+
ctx.SendChain(message.Text("你钱包当前只有", money, "ATRI币,无法完成支付"))
64+
return
65+
}
66+
err = wallet.InsertWalletOf(uid, -100)
67+
if err != nil {
68+
ctx.SendChain(message.Text("[ERROR at fish.go.3]:", err))
69+
return
70+
}
71+
equipInfo = equip{
72+
ID: uid,
73+
Equip: "木竿",
74+
Durable: 30,
75+
}
76+
err = dbdata.updateUserEquip(equipInfo)
77+
if err != nil {
78+
ctx.SendChain(message.Text("[ERROR at fish.go.4]:", err))
79+
return
80+
}
81+
err = dbdata.setEquipFor(uid)
82+
if err != nil {
83+
ctx.SendChain(message.Text("[ERROR at fish.go.4]:", err))
84+
return
85+
}
86+
buy = true
87+
}
88+
if buy {
89+
break
90+
}
91+
}
92+
}
93+
if equipInfo.Durable < fishNumber {
94+
fishNumber = equipInfo.Durable
95+
}
96+
residue, err := dbdata.updateFishInfo(uid, fishNumber)
97+
if err != nil {
98+
ctx.SendChain(message.Text("[ERROR at fish.go.1]:", err))
99+
return
100+
}
101+
if residue == 0 {
102+
ctx.SendChain(message.Text("今天你已经进行", FishLimit, "次钓鱼了.\n游戏虽好,但请不要沉迷。"))
103+
return
104+
}
105+
fishNumber = residue
106+
msg := ""
107+
if equipInfo.Equip != "美西螈" {
108+
equipInfo.Durable -= fishNumber
109+
err = dbdata.updateUserEquip(equipInfo)
110+
if err != nil {
111+
ctx.SendChain(message.Text("[ERROR at fish.go.5]:", err))
112+
return
113+
}
114+
if equipInfo.Durable < 10 || equipInfo.Durable > 0 {
115+
msg = "(你的鱼竿耐久仅剩" + strconv.Itoa(equipInfo.Durable) + ")"
116+
} else if equipInfo.Durable <= 0 {
117+
msg = "(你的鱼竿耐已销毁)"
118+
}
119+
} else {
120+
fishNmaes, err := dbdata.pickFishFor(uid, fishNumber)
121+
if err != nil {
122+
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
123+
return
124+
}
125+
if len(fishNmaes) == 0 {
126+
equipInfo.Durable = 0
127+
err = dbdata.updateUserEquip(equipInfo)
128+
if err != nil {
129+
ctx.SendChain(message.Text("[ERROR at fish.go.5]:", err))
130+
}
131+
ctx.SendChain(message.Text("美西螈因为没吃到鱼,钓鱼时一直没回来,你失去了美西螈"))
132+
return
133+
}
134+
msg = "(美西螈吃掉了"
135+
fishNumber = 0
136+
for name, number := range fishNmaes {
137+
fishNumber += number
138+
msg += strconv.Itoa(number) + name + "、"
139+
}
140+
msg += ")"
141+
}
142+
waitTime := 120 / (equipInfo.Induce + 1)
143+
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你开始去钓鱼了,请耐心等待鱼上钩(预计要", time.Second*time.Duration(waitTime), ")"))
144+
timer := time.NewTimer(time.Second * time.Duration(rand.Intn(waitTime)+1))
145+
for {
146+
<-timer.C
147+
timer.Stop()
148+
break
149+
}
150+
// 钓到鱼的范围
151+
number, err := dbdata.getNumberFor(uid, "鱼")
152+
if err != nil {
153+
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
154+
return
155+
}
156+
if number > 100 || equipInfo.Equip == "美西螈" { //放大概率
157+
probabilities["treasure"] = probabilityLimit{
158+
Min: 0,
159+
Max: 2,
160+
}
161+
probabilities["pole"] = probabilityLimit{
162+
Min: 2,
163+
Max: 10,
164+
}
165+
probabilities["fish"] = probabilityLimit{
166+
Min: 10,
167+
Max: 45,
168+
}
169+
probabilities["waste"] = probabilityLimit{
170+
Min: 45,
171+
Max: 90,
172+
}
173+
}
174+
for name, info := range probabilities {
175+
switch name {
176+
case "treasure":
177+
info.Max += equipInfo.Favor
178+
probabilities[name] = info
179+
case "pole":
180+
info.Min += equipInfo.Favor
181+
info.Max += equipInfo.Favor * 2
182+
probabilities[name] = info
183+
case "fish":
184+
info.Min += equipInfo.Favor * 2
185+
info.Max += equipInfo.Favor * 3
186+
probabilities[name] = info
187+
case "waste":
188+
info.Min += equipInfo.Favor * 3
189+
probabilities[name] = info
190+
}
191+
}
192+
// 钓鱼结算
193+
picName := ""
194+
thingNameList := make(map[string]int)
195+
for i := fishNumber; i > 0; i-- {
196+
thingName := ""
197+
typeOfThing := ""
198+
number := 1
199+
dice := rand.Intn(100)
200+
switch {
201+
case dice <= probabilities["waste"].Min && dice < probabilities["waste"].Max: // 垃圾
202+
typeOfThing = "waste"
203+
thingName = wasteList[rand.Intn(len(wasteList))]
204+
picName = thingName
205+
case dice <= probabilities["treasure"].Min && dice < probabilities["treasure"].Max: // 宝藏
206+
dice = rand.Intn(100)
207+
switch {
208+
case dice <= probabilities["美西螈"].Min && dice < probabilities["美西螈"].Max:
209+
typeOfThing = "pole"
210+
picName = "美西螈"
211+
thingName = "美西螈"
212+
case dice <= probabilities["唱片"].Min && dice < probabilities["唱片"].Max:
213+
typeOfThing = "article"
214+
picName = "唱片"
215+
thingName = "唱片"
216+
case dice <= probabilities["海之眷顾"].Min && dice < probabilities["海之眷顾"].Max:
217+
typeOfThing = "article"
218+
picName = "book"
219+
thingName = "海之眷顾"
220+
default:
221+
typeOfThing = "article"
222+
picName = "book"
223+
thingName = "诱钓"
224+
}
225+
case dice <= probabilities["pole"].Min && dice < probabilities["pole"].Max: // 宝藏
226+
typeOfThing = "pole"
227+
dice := rand.Intn(100)
228+
switch {
229+
case dice <= probabilities["铁竿"].Min && dice < probabilities["铁竿"].Max:
230+
thingName = "铁竿"
231+
case dice <= probabilities["金竿"].Min && dice < probabilities["金竿"].Max:
232+
thingName = "金竿"
233+
case dice <= probabilities["钻石竿"].Min && dice < probabilities["钻石竿"].Max:
234+
thingName = "钻石竿"
235+
case dice <= probabilities["下界合金竿竿竿"].Min && dice < probabilities["下界合金竿竿竿"].Max:
236+
thingName = "下界合金竿竿竿"
237+
default:
238+
thingName = "木竿"
239+
}
240+
picName = thingName
241+
case dice <= probabilities["fish"].Min && dice < probabilities["fish"].Max:
242+
typeOfThing = "fish"
243+
dice = rand.Intn(100)
244+
switch {
245+
case dice <= probabilities["墨鱼"].Min && dice < probabilities["墨鱼"].Max:
246+
thingName = "墨鱼"
247+
case dice <= probabilities["鳕鱼"].Min && dice < probabilities["鳕鱼"].Max:
248+
thingName = "鳕鱼"
249+
case dice <= probabilities["鲑鱼"].Min && dice < probabilities["鲑鱼"].Max:
250+
thingName = "鲑鱼"
251+
case dice <= probabilities["热带鱼"].Min && dice < probabilities["热带鱼"].Max:
252+
thingName = "热带鱼"
253+
case dice <= probabilities["河豚"].Min && dice < probabilities["河豚"].Max:
254+
thingName = "河豚"
255+
default:
256+
thingName = "鹦鹉螺"
257+
}
258+
picName = thingName
259+
default:
260+
thingNameList["赛博空气"]++
261+
}
262+
if thingName != "" {
263+
newThing := article{}
264+
if strings.Contains(thingName, "竿") {
265+
info := strconv.Itoa(rand.Intn(discountList[thingName])+1) +
266+
"/" + strconv.Itoa(rand.Intn(10)) + "/" +
267+
strconv.Itoa(rand.Intn(3)) + "/" + strconv.Itoa(rand.Intn(2))
268+
newThing = article{
269+
Duration: time.Now().Unix()*100 + int64(i),
270+
Type: typeOfThing,
271+
Name: thingName,
272+
Number: number,
273+
Other: info,
274+
}
275+
} else {
276+
thingInfo, err := dbdata.getUserThingInfo(uid, thingName)
277+
if err != nil {
278+
ctx.SendChain(message.Text("[ERROR at fish.go.6]:", err))
279+
return
280+
}
281+
if len(thingInfo) == 0 {
282+
newThing = article{
283+
Duration: time.Now().Unix()*100 + int64(i),
284+
Type: typeOfThing,
285+
Name: thingName,
286+
}
287+
} else {
288+
newThing = thingInfo[0]
289+
}
290+
if equipInfo.Equip == "美西螈" && thingName != "美西螈" {
291+
number += 2
292+
}
293+
newThing.Number += number
294+
}
295+
err = dbdata.updateUserThingInfo(uid, newThing)
296+
if err != nil {
297+
ctx.SendChain(message.Text("[ERROR at fish.go.7]:", err))
298+
return
299+
}
300+
thingNameList[thingName] += number
301+
}
302+
}
303+
if len(thingNameList) == 1 {
304+
thingName := ""
305+
for name := range thingNameList {
306+
thingName = name
307+
}
308+
if picName != "" {
309+
pic, err := engine.GetLazyData(picName+".png", false)
310+
if err != nil {
311+
logrus.Warnln("[mcfish]error:", err)
312+
ctx.SendChain(message.At(uid), message.Text("恭喜你钓到了", thingName, "\n", msg))
313+
return
314+
}
315+
ctx.SendChain(message.At(uid), message.Text("恭喜你钓到了", thingName, "\n", msg), message.ImageBytes(pic))
316+
return
317+
}
318+
ctx.SendChain(message.At(uid), message.Text("恭喜你钓到了", thingName, "\n", msg))
319+
return
320+
}
321+
msgInfo := make(message.Message, 0, 3+len(thingNameList))
322+
msgInfo = append(msgInfo, message.Reply(ctx.Event.MessageID), message.Text("你进行了", fishNumber, "次钓鱼,结果如下:\n"))
323+
for name, number := range thingNameList {
324+
msgInfo = append(msgInfo, message.Text(name, " : ", number, "\n"))
325+
}
326+
msgInfo = append(msgInfo, message.Text(msg))
327+
ctx.Send(msgInfo)
328+
})
329+
}

0 commit comments

Comments
 (0)