9
9
"image/jpeg"
10
10
"image/png"
11
11
"math/rand"
12
+ "regexp"
12
13
"strings"
13
14
"sync/atomic"
14
15
29
30
totl uint64 // 累计抽奖次数
30
31
filetree = make (zipfilestructure , 32 )
31
32
starN3 , starN4 , starN5 * zip.File
33
+ namereg = regexp .MustCompile (`_(.*)\.png` )
32
34
)
33
35
34
36
func init () {
@@ -91,18 +93,24 @@ func init() {
91
93
gid = - ctx .Event .UserID
92
94
}
93
95
store := (storage )(c .GetData (gid ))
94
- img , err := randnums (10 , store )
96
+ img , str , mode , err := randnums (10 , store )
95
97
if err != nil {
96
98
ctx .SendChain (message .Text ("ERROR:" , err ))
97
99
return
98
100
}
99
101
b , cl := writer .ToBytes (img )
100
- ctx .Send (message .ReplyWithMessage (ctx .Event .MessageID , message .ImageBytes (b )))
102
+ if mode {
103
+ ctx .Send (message .ReplyWithMessage (ctx .Event .MessageID ,
104
+ message .Text ("恭喜你抽到了: \n " , str ), message .ImageBytes (b )))
105
+ } else {
106
+ ctx .Send (message .ReplyWithMessage (ctx .Event .MessageID ,
107
+ message .Text ("十连成功~" ), message .ImageBytes (b )))
108
+ }
101
109
cl ()
102
110
})
103
111
}
104
112
105
- func randnums (nums int , store storage ) (rgba * image.RGBA , err error ) {
113
+ func randnums (nums int , store storage ) (rgba * image.RGBA , str string , replyMode bool , err error ) {
106
114
var (
107
115
fours , fives = make ([]* zip.File , 0 , 10 ), make ([]* zip.File , 0 , 10 ) // 抽到 四, 五星角色
108
116
threeArms , fourArms , fiveArms = make ([]* zip.File , 0 , 10 ), make ([]* zip.File , 0 , 10 ), make ([]* zip.File , 0 , 10 ) // 抽到 三 , 四, 五星武器
@@ -145,18 +153,18 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
145
153
}
146
154
} else { // 默认模式
147
155
for i := 0 ; i < nums ; i ++ {
148
- a := rand .Intn (1000 )
149
- switch { // 抽卡几率 三星75% 四星18% 五星7%
150
- case a >= 0 && a <= 750 :
156
+ a := rand .Intn (1000 ) // 抽卡几率 三星80% 四星17% 五星3%
157
+ switch {
158
+ case a >= 0 && a <= 800 :
151
159
threeN2 ++
152
160
threeArms = append (threeArms , filetree ["Three" ][rand .Intn (threelen )])
153
- case a > 750 && a <= 840 :
161
+ case a > 800 && a <= 885 :
154
162
fourN ++
155
163
fours = append (fours , filetree ["four" ][rand .Intn (fourlen )]) // 随机角色
156
- case a > 840 && a <= 930 :
164
+ case a > 885 && a <= 970 :
157
165
fourN2 ++
158
166
fourArms = append (fourArms , filetree ["four2" ][rand .Intn (four2len )]) // 随机武器
159
- case a > 930 && a <= 965 :
167
+ case a > 970 && a <= 985 :
160
168
fiveN ++
161
169
fives = append (fives , filetree ["five" ][rand .Intn (fivelen )])
162
170
default :
@@ -210,12 +218,16 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
210
218
211
219
if fiveN > 0 { // 按顺序加入
212
220
he (fiveN , 5 , starN5 , fivebg ) // 五星角色
221
+ str += reply (fives , 1 , str )
222
+ replyMode = true
213
223
}
214
224
if fourN > 0 {
215
225
he (fourN , 3 , starN4 , fourbg ) // 四星角色
216
226
}
217
227
if fiveN2 > 0 {
218
228
he (fiveN2 , 4 , starN5 , fivebg ) // 五星武器
229
+ str += reply (fiveArms , 2 , str )
230
+ replyMode = true
219
231
}
220
232
if fourN2 > 0 {
221
233
he (fourN2 , 2 , starN4 , fourbg ) // 四星武器
@@ -256,7 +268,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
256
268
257
269
imgs , err := bgs [i ].Open () // 取出背景图片
258
270
if err != nil {
259
- return nil , err
271
+ return nil , "" , false , err
260
272
}
261
273
defer imgs .Close ()
262
274
@@ -266,7 +278,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
266
278
267
279
imgs1 , err := hero [i ].Open () // 取出图片名
268
280
if err != nil {
269
- return nil , err
281
+ return nil , "" , false , err
270
282
}
271
283
defer imgs1 .Close ()
272
284
@@ -276,7 +288,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
276
288
277
289
imgs2 , err := stars [i ].Open () // 取出星级图标
278
290
if err != nil {
279
- return nil , err
291
+ return nil , "" , false , err
280
292
}
281
293
defer imgs2 .Close ()
282
294
@@ -286,7 +298,7 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
286
298
287
299
imgs3 , err := cicon [i ].Open () // 取出类型图标
288
300
if err != nil {
289
- return nil , err
301
+ return nil , "" , false , err
290
302
}
291
303
defer imgs3 .Close ()
292
304
@@ -296,12 +308,12 @@ func randnums(nums int, store storage) (rgba *image.RGBA, err error) {
296
308
}
297
309
imgs4 , err := filetree ["Reply.png" ][0 ].Open () // "分享" 图标
298
310
if err != nil {
299
- return nil , err
311
+ return nil , "" , false , err
300
312
}
301
313
defer imgs4 .Close ()
302
314
img4 , err := png .Decode (imgs4 )
303
315
if err != nil {
304
- return nil , err
316
+ return nil , "" , false , err
305
317
}
306
318
offset4 := image .Pt (1270 , 945 ) // 宽, 高
307
319
draw .Draw (rgba , img4 .Bounds ().Add (offset4 ), img4 , image.Point {}, draw .Over )
@@ -343,3 +355,21 @@ func parsezip(zipFile string) error {
343
355
}
344
356
return nil
345
357
}
358
+
359
+ // 取出角色武器名
360
+ func reply (z []* zip.File , num int , nameStr string ) string {
361
+ var tmp strings.Builder
362
+ tmp .Grow (128 )
363
+ switch {
364
+ case num == 1 :
365
+ tmp .WriteString ("★五星角色★\n " )
366
+ case num == 2 && len (nameStr ) > 0 :
367
+ tmp .WriteString ("\n ★五星武器★\n " )
368
+ default :
369
+ tmp .WriteString ("★五星武器★\n " )
370
+ }
371
+ for i := range z {
372
+ tmp .WriteString (namereg .FindStringSubmatch (z [i ].Name )[1 ] + " * " )
373
+ }
374
+ return tmp .String ()
375
+ }
0 commit comments