/
rsc.go
86 lines (80 loc) · 2.36 KB
/
rsc.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
// Package gamesystem 基于zbp的猜歌插件
package gamesystem
import (
"math/rand"
"github.com/FloatTech/AnimeAPI/wallet"
"github.com/FloatTech/floatbox/math"
"github.com/FloatTech/zbputils/ctxext"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
// 载入游戏系统
"github.com/FloatTech/ZeroBot-Plugin-Playground/plugin/games/gamesystem" // 游戏系统
)
var point = map[string]int{
"石头": 1,
"剪刀": 2,
"布": 3,
}
func init() {
// 注册游戏信息
engine, gameManager, err := gamesystem.Register("石头剪刀布", &gamesystem.GameInfo{
Command: "- @bot[石头|剪刀|布]",
Help: "和机器人进行猜拳,如果机器人开心了会得到ATRI币",
Rewards: "奖励范围在0~10之间",
})
if err != nil {
panic(err)
}
engine.OnFullMatchGroup([]string{"石头", "剪刀", "布"}, zero.OnlyToMe, func(ctx *zero.Ctx) bool {
if gameManager.PlayIn(ctx.Event.GroupID) {
return true
}
ctx.SendChain(message.Text("游戏已下架,无法游玩"))
return false
}).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
botchoose := 1 + rand.Intn(3)
switch botchoose {
case 1:
ctx.SendChain(message.Text("石头"))
case 2:
ctx.SendChain(message.Text("剪刀"))
case 3:
ctx.SendChain(message.Text("布"))
}
model := ctx.State["matched"].(string)
result := point[model] - botchoose
// 如果是石头和布的比较,比较值正负取反
if math.Abs(result) == 2 {
result = -(result)
}
switch {
case result < 0:
ctx.SendChain(message.Text("可恶,你赢了"))
case result > 0:
if rand.Intn(5) == 1 {
money := rand.Intn(11)
if money > 0 {
err := wallet.InsertWalletOf(ctx.Event.UserID, money)
if err == nil {
ctx.SendChain(message.Text("哈哈,你输了。嗯!~今天运气不错,我很高兴,奖励你 ", money, " 枚ATRI币吧"))
return
}
}
}
ctx.SendChain(message.Text("哈哈,你输了"))
default:
if rand.Intn(10) == 1 {
money := rand.Intn(11)
if money > 0 {
err := wallet.InsertWalletOf(ctx.Event.UserID, money)
if err == nil {
ctx.SendChain(message.Text("你实力不错,我很欣赏你,奖励你 ", money, " 枚ATRI币吧"))
return
}
}
}
ctx.SendChain(message.Text("实力可以啊,希望下次再来和我玩"))
}
})
}