up
This commit is contained in:
parent
03a6aef4fc
commit
e127da154d
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
EntryMsgTemplate = "庄家手牌: %s\n玩家手牌: %s\n庄家点数: %d+?, 玩家点数: %d\n是否继续要牌? (hit/stand)"
|
||||
EntryMsgTemplate = "庄家手牌: %s\n玩家手牌: %s\n庄家点数: %d+?, 玩家点数: %d\n是否继续要牌? (hit/stand)\n加倍下注且仅要一张牌(double)"
|
||||
PlayerTakeCardMsgTemplate = "玩家手牌: %s\n玩家点数: %d\n庄家点数: %d+?\n是否继续要牌? (hit/stand)"
|
||||
DealerHitMsgTemplate = "庄家点数小于17, 继续要牌\n抽出了一张牌: %s, 总点数: %d"
|
||||
GameOverMsg = "%s\n游戏结束\n庄家手牌: %s\n玩家手牌: %s\n庄家点数: %d, 玩家点数: %d\n%s"
|
||||
@ -34,38 +34,6 @@ func BlackJackEntry(ctx *zero.Ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
userBalance, err := redisrepo.GetUserBalance(ctx.Event.UserID)
|
||||
if err != nil {
|
||||
if err == rueidis.Nil {
|
||||
userBalance = common.Config.Game.Balance
|
||||
redisrepo.Register(ctx.Event.UserID)
|
||||
} else {
|
||||
ctx.Send("获取用户余额失败")
|
||||
return
|
||||
}
|
||||
}
|
||||
if userBalance <= 0 {
|
||||
ctx.Send("你的余额不足, 请等待次日发放")
|
||||
return
|
||||
}
|
||||
ctx.Send("请发送下注金额 (例: bet 1000)")
|
||||
return
|
||||
}
|
||||
|
||||
// Bet 下注
|
||||
func Bet(ctx *zero.Ctx) {
|
||||
if ctx.Event.GroupID == 0 {
|
||||
ctx.Send("请在群聊中使用")
|
||||
return
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("%d_%d", ctx.Event.GroupID, ctx.Event.UserID)
|
||||
_, ok := RoundMap.Load(key)
|
||||
if ok {
|
||||
ctx.Send("你已经在游戏中了, 请继续游戏(hit/stand)")
|
||||
return
|
||||
}
|
||||
|
||||
msg := strings.Split(ctx.Event.Message.String(), " ")
|
||||
if len(msg) != 2 {
|
||||
ctx.Send("下注金额格式错误, 请重新下注")
|
||||
@ -131,6 +99,42 @@ func StartGame(ctx *zero.Ctx, key string, bet int64) {
|
||||
ctx.Send(fmt.Sprintf(EntryMsgTemplate, dealerHand, round.PlayerHand, CalculateCardPoint(dealerHandT), playerPoint))
|
||||
}
|
||||
|
||||
// Double 加倍下注
|
||||
func Double(ctx *zero.Ctx) {
|
||||
key := fmt.Sprintf("%d_%d", ctx.Event.GroupID, ctx.Event.UserID)
|
||||
roundUnload, ok := RoundMap.Load(key)
|
||||
if !ok {
|
||||
ctx.Send("你不在游戏中, 请先开始游戏")
|
||||
return
|
||||
}
|
||||
round := roundUnload.(*Round)
|
||||
|
||||
if len(round.PlayerHand) > 2 {
|
||||
ctx.Send("只能在第一次要牌时加倍下注")
|
||||
return
|
||||
}
|
||||
|
||||
round.Bet = decimal.NewFromInt(round.Bet).Mul(decimal.NewFromInt(2)).IntPart()
|
||||
round.PlayerHand = append(round.PlayerHand, round.Deck.Pop())
|
||||
playerPoint := CalculateCardPoint(round.PlayerHand)
|
||||
|
||||
if playerPoint > 21 {
|
||||
redisrepo.SubUserBalance(ctx.Event.UserID, round.Bet)
|
||||
ctx.Send(fmt.Sprintf("玩家抽出了一张 %s\n玩家爆点, 庄家胜\n玩家手牌: %s\n玩家点数: %d\n庄家手牌: %s\n庄家点数: %d\n游戏结束, 庄家胜", round.PlayerHand[len(round.PlayerHand)-1].String(), round.PlayerHand, CalculateCardPoint(round.PlayerHand), round.DealerHand, CalculateCardPoint(round.DealerHand)))
|
||||
RoundMap.Delete(key)
|
||||
return
|
||||
}
|
||||
if playerPoint == 21 {
|
||||
redisrepo.AddUserBalance(ctx.Event.UserID, decimal.NewFromInt(round.Bet).Mul(decimal.NewFromFloat(1.5)).IntPart())
|
||||
ctx.Send(fmt.Sprintf("玩家抽出了一张 %s\n玩家21点, 玩家胜\n玩家手牌: %s\n玩家点数: %d\n庄家手牌: %s\n庄家点数: %d\n游戏结束, 玩家胜", round.PlayerHand[len(round.PlayerHand)-1].String(), round.PlayerHand, CalculateCardPoint(round.PlayerHand), round.DealerHand, CalculateCardPoint(round.DealerHand)))
|
||||
RoundMap.Delete(key)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Send(fmt.Sprintf("玩家抽出了一张 %s\n玩家手牌: %s\n玩家点数: %d\n庄家点数: %d+?\n到庄家回合", round.PlayerHand[len(round.PlayerHand)-1].String(), round.PlayerHand, playerPoint, CalculateCardPoint(round.DealerHand)))
|
||||
Stand(ctx)
|
||||
}
|
||||
|
||||
// Hit 玩家要牌
|
||||
func Hit(ctx *zero.Ctx) {
|
||||
key := fmt.Sprintf("%d_%d", ctx.Event.GroupID, ctx.Event.UserID)
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"amor/proto"
|
||||
redisrepo "amor/repository/redisRepo"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/redis/rueidis"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
@ -53,7 +54,8 @@ func Rank(ctx *zero.Ctx) {
|
||||
|
||||
var msg string
|
||||
for i, rank := range rankList {
|
||||
msg += "第" + string(i+1) + "名: " + rank.Nickname + " 余额: " + string(rank.Balance) + "\n"
|
||||
// msg += "第" + string(i+1) + "名: " + rank.Nickname + " 余额: " + string(rank.Balance) + "\n"
|
||||
msg += fmt.Sprintf("第%d名: %s 余额: %d\n", i+1, rank.Nickname, rank.Balance)
|
||||
}
|
||||
ctx.Send(msg)
|
||||
}
|
||||
|
@ -10,5 +10,5 @@ func Help(ctx *zero.Ctx) {
|
||||
ctx.Send(fmt.Sprintf(`欢迎使用NothBot
|
||||
chips 查看剩余筹码
|
||||
register 注册会员
|
||||
21点/bj 开始21点游戏`))
|
||||
bj 下注 开始21点游戏`))
|
||||
}
|
||||
|
@ -10,15 +10,21 @@ import (
|
||||
)
|
||||
|
||||
func Router() {
|
||||
// 注册
|
||||
zero.OnFullMatch("register").Handle(member.Register)
|
||||
|
||||
// 筹码余额
|
||||
zero.OnFullMatch("chips").Handle(member.GetBalance)
|
||||
|
||||
// 群内筹码排名
|
||||
zero.OnFullMatch("rank").Handle(chips.Rank)
|
||||
|
||||
// 帮助
|
||||
zero.OnFullMatch("help").Handle(plugin.Help)
|
||||
|
||||
// 21点游戏
|
||||
zero.OnFullMatch("21点").Handle(blackjack.BlackJackEntry)
|
||||
zero.OnFullMatch("bj").Handle(blackjack.BlackJackEntry)
|
||||
zero.OnCommand("bet").Handle(blackjack.Bet)
|
||||
zero.OnCommand("bj").Handle(blackjack.BlackJackEntry)
|
||||
zero.OnFullMatch("hit").Handle(blackjack.Hit)
|
||||
zero.OnFullMatch("stand").Handle(blackjack.Stand)
|
||||
zero.OnFullMatch("double").Handle(blackjack.Double)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user