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