| 14 | ) |
| 15 | |
| 16 | func init() { |
| 17 | // 注册游戏信息 |
| 18 | engine, gameManager, err := gamesystem.Register("骰子壶", &gamesystem.GameInfo{ |
| 19 | Command: "- 骰子壶@对方QQ", |
| 20 | Help: "保证ATRI币大于20的双方玩家各自投掷1个骰子。\n平局的场合再掷一次直到数目不一样。", |
| 21 | Rewards: "投掷出来的数目低的玩家将另一方投掷出的数目x2的ATRI币交给对方。\n" + |
| 22 | "如果输给投掷出来的数目为6的场合,移交的ATRI币变成20。", |
| 23 | }) |
| 24 | if err != nil { |
| 25 | panic(err) |
| 26 | } |
| 27 | engine.OnRegex(`^骰子壶\s*?\[CQ:at,qq=(\d+).*`, zero.OnlyGroup, func(ctx *zero.Ctx) bool { |
| 28 | if gameManager.PlayIn(ctx.Event.GroupID) { |
| 29 | return true |
| 30 | } |
| 31 | ctx.SendChain(message.Text("游戏已下架,无法游玩")) |
| 32 | return false |
| 33 | }).SetBlock(true).Handle(func(ctx *zero.Ctx) { |
| 34 | duelUser, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64) |
| 35 | uid := ctx.Event.UserID |
| 36 | if duelUser == uid { |
| 37 | ctx.SendChain(message.Text("禁止左右手互博")) |
| 38 | return |
| 39 | } |
| 40 | userScore := wallet.GetWalletOf(uid) |
| 41 | if userScore < 20 { |
| 42 | ctx.SendChain(message.Text("你的ATRI币不足以满足该游戏")) |
| 43 | return |
| 44 | } |
| 45 | challengScore := wallet.GetWalletOf(duelUser) |
| 46 | if challengScore < 20 { |
| 47 | ctx.SendChain(message.Text("他的ATRI币不足以满足该游戏")) |
| 48 | return |
| 49 | } |
| 50 | // 等待对方响应 |
| 51 | ctx.SendChain(message.Text("等待对方发送“开玩|拒绝”进行回复")) |
| 52 | recv, cancel := zero.NewFutureEvent("message", 999, false, zero.OnlyGroup, zero.FullMatchRule("开玩", "拒绝"), zero.CheckUser(duelUser), zero.CheckGroup(ctx.Event.GroupID)).Repeat() |
| 53 | defer cancel() |
| 54 | answer := "" |
| 55 | wait := time.NewTimer(120 * time.Second) |
| 56 | for { |
| 57 | select { |
| 58 | case <-wait.C: |
| 59 | ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, |
| 60 | message.Text("时间超时,游戏取消"))) |
| 61 | return |
| 62 | case c := <-recv: |
| 63 | answer = c.Event.Message.String() |
| 64 | if answer == "拒绝" { |
| 65 | ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, |
| 66 | message.Text("对方拒绝了你的邀请,游戏结束"))) |
| 67 | return |
| 68 | } |
| 69 | } |
| 70 | if answer == "开玩" { |
| 71 | break |
| 72 | } |
| 73 | } |