Browse Source

1 21点修改下注负数导致的问题

2 21点修改记录没上传
3 21点修改机器人首次进入时间过快的错误
4 龙虎修改下注负数的问题
5 德州改版成新版本
dev
MoQingYu 3 months ago
parent
commit
31f2bd57e8
  1. 8
      game-server/game/21Game/app/core/game/game_bet.go
  2. 6
      game-server/game/21Game/app/core/game/game_over.go
  3. 20
      game-server/game/21Game/app/core/game/game_robot.go
  4. 2
      game-server/game/21Game/config/blood.json
  5. 1
      game-server/game/DZ/app/config/config.go
  6. 1
      game-server/game/DZ/app/core/core.go
  7. 129
      game-server/game/DZ/app/core/game/game.go
  8. 2
      game-server/game/DZ/app/core/game/game_comm.go
  9. 136
      game-server/game/DZ/app/core/game/game_get_room_info.go
  10. 7
      game-server/game/DZ/app/core/game/game_init.go
  11. 28
      game-server/game/DZ/app/core/game/game_join_room.go
  12. 177
      game-server/game/DZ/app/core/game/game_logic.go
  13. 1
      game-server/game/DZ/app/core/game/game_new.go
  14. 70
      game-server/game/DZ/app/core/game/game_next_player.go
  15. 368
      game-server/game/DZ/app/core/game/game_operate.go
  16. 269
      game-server/game/DZ/app/core/game/game_over.go
  17. 40
      game-server/game/DZ/app/core/game/game_player.go
  18. 19
      game-server/game/DZ/app/core/game/game_repeat_room.go
  19. 134
      game-server/game/DZ/app/core/game/game_robot.go
  20. 30
      game-server/game/DZ/app/core/game/game_robot_timer.go
  21. 53
      game-server/game/DZ/app/core/game/game_select_banker.go
  22. 236
      game-server/game/DZ/app/core/game/game_start.go
  23. 6
      game-server/game/DZ/app/core/game/game_table_take.go
  24. 18
      game-server/game/DZ/app/core/game/game_watch.go
  25. 61
      game-server/game/DZ/app/core/protocol/protocol_msg.go
  26. 82
      game-server/game/DZ/app/core/protocol/protocol_struct.go
  27. 2
      game-server/game/DZ/app/core/room/base.go
  28. 6
      game-server/game/DZ/app/core/room/roommgr.go
  29. 54
      game-server/game/DZ/app/core/types/poker.go
  30. 28
      game-server/game/DZ/app/gamemanage/gamemanage.go
  31. 6
      game-server/game/DZ/app/route/route.go
  32. 80
      game-server/game/DZ/config/blood.json
  33. 2
      game-server/game/DZ/game_test.go
  34. 17
      game-server/game/dragonTiger/app/core/game/game_bet.go

8
game-server/game/21Game/app/core/game/game_bet.go

@ -70,6 +70,14 @@ func (rr *Room) OnUserBet(uid int64, msg interface{}) { // 用户下注
return
}
if message.BetAmount <= 0 {
log.Debug("玩家", ChairId, "个人下注总值", message.BetAmount, " 拥有的钱: ", rr.PlayerMap[ChairId].Gold.IntPart())
BetRes.Code = protocol.ErrorBet
BetRes.CodeMsg = "下注额异常 " + strconv.Itoa(int(message.BetAmount))
rr.Send(rr.PlayerMap[ChairId], route.BetRes, BetRes)
return
}
rr.UserScore[ChairId] = rr.UserScore[ChairId].Sub(decimal.NewFromInt(message.BetAmount))
rr.PlayerMap[ChairId].Gold = rr.PlayerMap[ChairId].Gold.Sub(decimal.NewFromInt(message.BetAmount))

6
game-server/game/21Game/app/core/game/game_over.go

@ -404,7 +404,7 @@ func (rr *Room) OnEventGameSingeConclude(SingleChairID int32) { // 结束-单独
rr.UserScore[BankerPlayer.ChairId] = rr.UserScore[BankerPlayer.ChairId].Add(decimal.NewFromInt(TempRateAfter))
if !BankerPlayer.IsRobot && (BankerPlayer.EndScore != 0) && (BankerPlayer.Ctx != nil) {
AfterGold, BloodPool, StockNum := rr.WriteUserScore(BankerPlayer, 3, 0, WinBetScore, WinGold, rr.ReasonString, "", sPlayers, UserRealBet)
AfterGold, BloodPool, StockNum := rr.WriteUserScore(BankerPlayer, 3, 0, WinBetScore, WinGold, rr.ReasonString, sArea, sPlayers, UserRealBet)
log.Debug("WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum, " GameID", rr.GameID, " RoomID", rr.RoomID)
rr.UserScore[BankerPlayer.ChairId] = decimal.NewFromInt(AfterGold)
BankerPlayer.Gold = decimal.NewFromInt(AfterGold)
@ -610,7 +610,7 @@ func (rr *Room) OnEventGameConclude() { // 结束-结算
rr.UserScore[BankerPlayer.ChairId] = rr.UserScore[BankerPlayer.ChairId].Add(decimal.NewFromInt(TempRateAfter))
if !BankerPlayer.IsRobot && (BankerPlayer.EndScore != 0) && (BankerPlayer.Ctx != nil) {
AfterGold, BloodPool, StockNum := rr.WriteUserScore(BankerPlayer, 3, 0, WinBetScore, WinGold, rr.ReasonString, "", sPlayers, UserRealBet)
AfterGold, BloodPool, StockNum := rr.WriteUserScore(BankerPlayer, 3, 0, WinBetScore, WinGold, rr.ReasonString, sArea, sPlayers, UserRealBet)
log.Debug("WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum, " GameID", rr.GameID, " RoomID", rr.RoomID)
rr.UserScore[BankerPlayer.ChairId] = decimal.NewFromInt(AfterGold)
BankerPlayer.Gold = decimal.NewFromInt(AfterGold)
@ -792,7 +792,7 @@ func (rr *Room) OnEventGameConcludeBX() { // 结束-保险结算
rr.UserScore[BankerPlayer.ChairId] = rr.UserScore[BankerPlayer.ChairId].Add(decimal.NewFromInt(TempRateAfter))
if !BankerPlayer.IsRobot && (BankerPlayer.EndScore != 0) && (BankerPlayer.Ctx != nil) {
AfterGold, BloodPool, StockNum := rr.WriteUserScore(BankerPlayer, 3, 0, WinBetScore, WinGold, rr.ReasonString, "", sPlayers, UserRealBet)
AfterGold, BloodPool, StockNum := rr.WriteUserScore(BankerPlayer, 3, 0, WinBetScore, WinGold, rr.ReasonString, sArea, sPlayers, UserRealBet)
log.Debug("WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum, " GameID", rr.GameID, " RoomID", rr.RoomID)
rr.UserScore[BankerPlayer.ChairId] = decimal.NewFromInt(AfterGold)
BankerPlayer.Gold = decimal.NewFromInt(AfterGold)

20
game-server/game/21Game/app/core/game/game_robot.go

@ -85,8 +85,8 @@ func (r *RobotManager) OnInit(conf string, GameRoom *Room) {
// 第一个进入的机器人 只判断一次
r.FirstEnterTimer = 0
if r.GameRoom.CreatorId != 0 {
FirstMinTime := r.GameRoom.TableConfig.FirstRobotCheckMinFrequency
FirstMaxTime := r.GameRoom.TableConfig.FirstRobotCheckMaxFrequency
FirstMinTime := r.GameRoom.TableConfig.FirstRobotCheckMinFrequency * 1000
FirstMaxTime := r.GameRoom.TableConfig.FirstRobotCheckMaxFrequency * 1000
if FirstMaxTime <= FirstMinTime {
r.FirstEnterTimer = nowMilliSeconds + FirstMaxTime
} else {
@ -123,11 +123,21 @@ func (r *RobotManager) OnInit(conf string, GameRoom *Room) {
if GameRoom.TableConfig != nil {
r.MaxCount = 0
if GameRoom.TableConfig.ZeroMaxNum <= GameRoom.TableConfig.ZeroMinNum {
r.MaxCount = int(GameRoom.TableConfig.ZeroMinNum)
if GameRoom.TableConfig.TableType == 2 {
if GameRoom.TableConfig.OneMaxNum <= GameRoom.TableConfig.OneMinNum {
r.MaxCount = int(GameRoom.TableConfig.OneMinNum)
} else {
r.MaxCount = int(rand.Int63n(GameRoom.TableConfig.OneMaxNum-GameRoom.TableConfig.OneMinNum+1) + GameRoom.TableConfig.OneMinNum)
}
} else {
r.MaxCount = int(rand.Int63n(GameRoom.TableConfig.ZeroMaxNum-GameRoom.TableConfig.ZeroMinNum+1) + GameRoom.TableConfig.ZeroMinNum)
if GameRoom.TableConfig.ZeroMaxNum <= GameRoom.TableConfig.ZeroMinNum {
r.MaxCount = int(GameRoom.TableConfig.ZeroMinNum)
} else {
r.MaxCount = int(rand.Int63n(GameRoom.TableConfig.ZeroMaxNum-GameRoom.TableConfig.ZeroMinNum+1) + GameRoom.TableConfig.ZeroMinNum)
}
}
r.FlushCountTimer = nowMilliSeconds + GameRoom.TableConfig.CheckFrequency*1000
log.Debug("从后台配置 最大机器人数 ", r.MaxCount, " 刷新时间 ", GameRoom.TableConfig.CheckFrequency)

2
game-server/game/21Game/config/blood.json

@ -1,4 +1,6 @@
{
"CommentGameRound": "一次大局有多少小局",
"GameRound" : 10,
"CommentRechargeLimit": "低于多少钱弹充值",
"RechargeLimit" : 10000,
"CommentChipList": "默认的底注 后台有按后台的来",

1
game-server/game/DZ/app/config/config.go

@ -20,6 +20,7 @@ type BloodCtrl struct {
ChipList []int64 `json:"ChipList"`
GearConfig []struct {
GearID int `json:"GearID"`
ChipPro int `json:"ChipPro"`
WinPro int `json:"WinPro"`
UserWinPokerPro [][]int `json:"UserWinPokerPro"`
RobotWinPokerPro [][]int `json:"RobotWinPokerPro"`

1
game-server/game/DZ/app/core/core.go

@ -39,6 +39,7 @@ func (c *Core) Init() {
group.AddRouteHandler(route.LogoutTable, false, gamemanage.LogoutTable) // 退出游戏请求
group.AddRouteHandler(route.AllTable, false, gamemanage.AllTable) // 进入游戏
group.AddRouteHandler(route.WatchToDown, false, gamemanage.WatchToDown) // 主动观战转坐下
group.AddRouteHandler(route.TableTake, false, gamemanage.TableTake) // 带入金币
})
// 断线重连-好像没用

129
game-server/game/DZ/app/core/game/game.go

@ -59,8 +59,9 @@ const (
)
type PokerUserType struct { // 用户牌型排序
ChairId int32
HandPoker types.PokerSlice // 玩家手牌
ChairId int32
TableScoreIndex int
HandPoker types.PokerSlice // 玩家手牌
}
type Room struct {
@ -83,6 +84,7 @@ type Room struct {
RoomRate int64 // 房间倍率
RoomLimit decimal.Decimal //int64// 房间进入条件
PlayerMap map[int32]*Player //
NeedOutPlayer map[int32]int64 // 需要判断退出的人 退出的时间
PlayerWatchMap []*Player //
MaxPlayerNum int32 //
State int32 //房间状态 0空闲,1准备开始,2花色下注,3花色结算,4二轮下注,5二轮结算
@ -110,17 +112,20 @@ type Room struct {
BetList []int64 //筹码列表
UserScore map[int32]decimal.Decimal //本局总输赢
CardList types.PokerSlice // 牌堆
DropCardList types.PokerSlice // 弃牌堆
HandPoker types.PokerSlice // 公共牌
CanCheck bool // 是否可以过牌
CellScore int64 // 当前下注
BetCRF int32 // 0 跟注+加注+弃牌 1 跟注+弃牌
CurrGameRound int32 // 当前游戏轮数 总共三轮下注
TableScore int64 //桌子上已结束轮总的钱
BloodCtrl conf.BloodCtrl //血池控制
isUserCtl bool //本桌是否人物点控
UserCtlGear int64 //人物点控档位
CardList types.PokerSlice // 牌堆
DropCardList types.PokerSlice // 弃牌堆
HandPoker types.PokerSlice // 公共牌
RoundSubBet bool // 第一轮是否加注过
CanCheck bool // 是否可以过牌
bUserAllIn bool // 是否有人已经ALLIN
CellScore int64 // 当前下注
BetCRF int32 // 0 跟注+加注+弃牌 1 跟注+弃牌
CurrGameRound int32 // 当前游戏轮数 总共三轮下注
TableScore []protocol.UserTableScore //桌子上的分池和属于的玩家
TableCurrentScore int64 //桌子上最新的总钱
BloodCtrl conf.BloodCtrl //血池控制
isUserCtl bool //本桌是否人物点控
UserCtlGear int64 //人物点控档位
MinGameScore int64 //最低能玩的金额
TimeOutBegin int64 //开始倒计时
@ -177,6 +182,18 @@ func (rr *Room) GetRoomPlayerCount() int32 {
return int32(len(rr.PlayerMap))
}
func (rr *Room) GetRoomCanPlayPlayerCount() int32 { // 可以游戏的房间人数
count := int32(0)
for _, v := range rr.PlayerMap {
//玩家掉线也好还是主动退出房间也好,并不会在房间中消除该玩家对象,一律视为掉线状态
//掉线状态表示不在房间
if v.TableScore >= rr.Opt.MinTableTake {
count++
}
}
return count
}
func (rr *Room) GetRoomCanBetPlayerCount() int32 {
count := int32(0)
for _, v := range rr.PlayerMap {
@ -635,13 +652,14 @@ func (rr *Room) SearchWinHandCard(WinType int) (types.PokerSlice, []int, types.P
log.Debug("加上最后两张牌 最后找到的扑克 ", ResultPokers)
var AllKind []types.PokerSlice
var TableHandPoker types.PokerSlice
var UserHandPoker types.PokerSlice
UserHandPoker = append(UserHandPoker, ResultPokers[0])
UserHandPoker = append(UserHandPoker, ResultPokers[1])
TableHandPoker = ResultPokers[2:]
//var UserHandPoker types.PokerSlice
//UserHandPoker = append(UserHandPoker, ResultPokers[0])
//UserHandPoker = append(UserHandPoker, ResultPokers[1])
//TableHandPoker = ResultPokers[2:]
TableHandPoker = ResultPokers
for _, OneKindIndex := range types.AllKindIndex {
var OnePokerList types.PokerSlice
OnePokerList = append(OnePokerList, UserHandPoker...)
//OnePokerList = append(OnePokerList, UserHandPoker...)
for _, OneIndex := range OneKindIndex {
OnePokerList = append(OnePokerList, TableHandPoker[OneIndex])
}
@ -657,10 +675,59 @@ func (rr *Room) SearchWinHandCard(WinType int) (types.PokerSlice, []int, types.P
continue
}
return ResultPokers, TempAllCardIndex, ResultMaxPoker
// 重新组装下
NewResultPokers := make(types.PokerSlice, 0)
NewResultPokers = AllKind[0]
for _, poker := range ResultPokers {
for Index, poker2 := range AllKind[0] {
if poker == poker2 {
break
}
if Index == len(AllKind[0])-1 {
NewResultPokers = append(NewResultPokers, poker)
}
}
}
log.Debug(" 桌子号", rr.RId, " 找到牌 ResultPokers ", ResultPokers, " 重新排列后的牌 :", NewResultPokers)
return NewResultPokers, TempAllCardIndex, ResultMaxPoker
}
return ResultPokers, TempAllCardIndex, ResultMaxPoker
var AllKind []types.PokerSlice
var TableHandPoker types.PokerSlice
TableHandPoker = ResultPokers
for _, OneKindIndex := range types.AllKindIndex {
var OnePokerList types.PokerSlice
for _, OneIndex := range OneKindIndex {
OnePokerList = append(OnePokerList, TableHandPoker[OneIndex])
}
AllKind = append(AllKind, OnePokerList)
}
sort.Slice(AllKind, func(i, j int) bool {
return AllKind[i].Compare(AllKind[j]) == 1
})
// 重新组装下
NewResultPokers := make(types.PokerSlice, 0)
NewResultPokers = AllKind[0]
for _, poker := range ResultPokers {
for Index, poker2 := range AllKind[0] {
if poker == poker2 {
break
}
if Index == len(AllKind[0])-1 {
NewResultPokers = append(NewResultPokers, poker2)
}
}
}
log.Error(" 桌子号", rr.RId, " 没有找到可以用的 最后只能用的找到牌 ResultPokers ", ResultPokers, " 重新排列后的牌 :", NewResultPokers)
return NewResultPokers, TempAllCardIndex, ResultMaxPoker
}
func (rr *Room) SearchTypeHandCard(WinType int, Count int32) []types.PokerSlice { // 计算一个获胜类型的牌组出来
@ -711,7 +778,7 @@ func (rr *Room) SearchTypeHandCard(WinType int, Count int32) []types.PokerSlice
TempHandPokerSlice = append(TempHandPokerSlice, OnePoker[3])
ResultPokerList = append(ResultPokerList, TempHandPokerSlice)
log.Debug("公牌是 ", rr.HandPoker, " 手牌是 ", ResultPokerList[0])
log.Debug(" 桌子号", rr.RId, "公牌是 ", rr.HandPoker, " 手牌是 ", ResultPokerList[0])
// 找剩余几家的牌
for tempCount := int32(0); tempCount < Count-1; tempCount++ {
@ -823,11 +890,15 @@ func (rr *Room) SearchTypeHandCard(WinType int, Count int32) []types.PokerSlice
// 判断大小
var AllKind []types.PokerSlice
var tempHandPokerList types.PokerSlice
tempHandPokerList = append(tempHandPokerList, OtherHandPoker...)
tempHandPokerList = append(tempHandPokerList, rr.HandPoker...)
for _, OneKindIndex := range types.AllKindIndex {
var OnePokerList types.PokerSlice
OnePokerList = append(OnePokerList, OtherHandPoker...)
//OnePokerList = append(OnePokerList, OtherHandPoker...)
for _, OneIndex := range OneKindIndex {
OnePokerList = append(OnePokerList, rr.HandPoker[OneIndex])
//OnePokerList = append(OnePokerList, rr.HandPoker[OneIndex])
OnePokerList = append(OnePokerList, tempHandPokerList[OneIndex])
}
AllKind = append(AllKind, OnePokerList)
}
@ -839,18 +910,22 @@ func (rr *Room) SearchTypeHandCard(WinType int, Count int32) []types.PokerSlice
// TODO: 测试过后要加个次数限制 防止一直随不到 还要打乱一下桌子上的五张牌
if TheBestHandPoker.Compare(AllKind[0]) != 1 {
// 第一手不是最大 要重新来
log.Debug("第一手不是最大 要重新来 生成第 ", tempCount, " 家牌 BestKind:", AllKind[0], " 赢的牌:", TheBestHandPoker)
log.Debug(" 桌子号", rr.RId, "第一手不是最大 要重新来 生成第 ", tempCount, " 家牌 BestKind:", AllKind[0], " 赢的牌:", TheBestHandPoker)
tempCount--
continue
}
log.Debug(" 生成第 ", tempCount, " 家牌 BestKind:", AllKind[0], " 手牌:", OtherHandPoker)
log.Debug(" 桌子号", rr.RId, " 生成第 ", tempCount, " 家牌 BestKind:", AllKind[0], " 手牌:", OtherHandPoker)
ResultPokerList = append(ResultPokerList, OtherHandPoker)
sort.Ints(OtherAllCardIndex)
log.Debug(" 桌子号", rr.RId, " 牌的索引 ", OtherAllCardIndex, " AllCard =", AllCard)
// 去掉已经给了的牌
for i := len(OtherAllCardIndex); i > 0; i-- {
if OtherAllCardIndex[i-1] == (len(AllCard) - 1) {
AllCard = (AllCard)[:OtherAllCardIndex[i-1]]
if OtherAllCardIndex[i-1] >= (len(AllCard) - 1) {
// AllCard = (AllCard)[:OtherAllCardIndex[i-1]]
AllCard = (AllCard)[:(len(AllCard) - 1)]
} else {
AllCard = append((AllCard)[:OtherAllCardIndex[i-1]], (AllCard)[OtherAllCardIndex[i-1]+1:]...)
}

2
game-server/game/DZ/app/core/game/game_comm.go

@ -32,7 +32,7 @@ func (rr *Room) GetInRoomRobotCount() int32 {
unm := int32(0)
for _, player := range rr.PlayerMap {
if player.IsRobot == true {
if player.IsRobot == true && player.IsRobotNeedLeave == false {
unm++
}
}

136
game-server/game/DZ/app/core/game/game_get_room_info.go

@ -3,6 +3,7 @@ package game
import (
"base/cluster/node"
"base/log"
"math"
"time"
"xgame/game/DZ/app/core/protocol"
"xgame/game/DZ/app/route"
@ -19,29 +20,34 @@ func (rr *Room) OnGetRoomInfo(uid int64, ctx *node.Context) interface{} {
TableInfo.ServerTimestamp = now.UnixMilli()
TableInfo.RoomStatus = rr.CurrentGameState
TableInfo.StatusChangeTimestamp = rr.CurrentOperationTimer
TableInfo.TableScore = rr.TableScore
for _, tempTableScore := range rr.TableScore {
TableInfo.TableScore = append(TableInfo.TableScore, tempTableScore.Score)
}
TableInfo.RoomConfig = &protocol.TableConfig{
RechargeLimit: rr.BloodCtrl.RechargeLimit,
CellScore: rr.Opt.MinBetAsset,
AlwaysBet: rr.Opt.AlwaysBet,
TaxMing: rr.Opt.BrightRate,
MinTableTake: rr.Opt.MinTableTake,
MaxTableTake: rr.Opt.MaxTableTake,
}
if rr.CurrentGameState == protocol.STATE_INVALUE || rr.CurrentGameState > protocol.STATE_BEGIN {
if rr.CurrGameRound == 0 {
if rr.CurrGameRound == 1 {
for Index, poker := range rr.HandPoker {
if Index >= 3 {
continue
}
TableInfo.Poker = append(TableInfo.Poker, int32(poker))
}
} else if rr.CurrGameRound == 1 {
} else if rr.CurrGameRound == 2 {
for Index, poker := range rr.HandPoker {
if Index >= 4 {
continue
}
TableInfo.Poker = append(TableInfo.Poker, int32(poker))
}
} else if rr.CurrGameRound == 2 {
} else if rr.CurrGameRound == 3 {
for _, poker := range rr.HandPoker {
TableInfo.Poker = append(TableInfo.Poker, int32(poker))
}
@ -52,11 +58,11 @@ func (rr *Room) OnGetRoomInfo(uid int64, ctx *node.Context) interface{} {
if player.Uid == uid {
pPlayer = player
// 还没开场可以参与游戏
if (rr.CurrentGameState != protocol.STATE_INVALUE) && (rr.CurrentGameState < protocol.STATE_BEGIN || rr.CurrentGameState == protocol.STATE_RESULT) {
log.Debug("还没开场可以参与游戏 ", player.Uid, " 当前阶段 ", rr.CurrentGameState)
pPlayer.CanBet = true
}
//// 还没开场可以参与游戏
//if (rr.CurrentGameState != protocol.STATE_INVALUE) && (rr.CurrentGameState < protocol.STATE_BEGIN || rr.CurrentGameState == protocol.STATE_RESULT) {
// log.Debug("还没开场可以参与游戏 ", player.Uid, " 当前阶段 ", rr.CurrentGameState)
// pPlayer.CanBet = true
//}
}
TableSeat := &protocol.RoomPlayer{}
@ -64,6 +70,7 @@ func (rr *Room) OnGetRoomInfo(uid int64, ctx *node.Context) interface{} {
TableSeat.ChairID = player.ChairId
TableSeat.State = rr.CurrentGameState
TableSeat.Avatar = player.Avatar
TableSeat.BetType = player.BetType
TableSeat.Gold = player.Gold.IntPart()
TableSeat.Nickname = player.Nickname
TableSeat.Sex = player.Sex
@ -75,7 +82,11 @@ func (rr *Room) OnGetRoomInfo(uid int64, ctx *node.Context) interface{} {
TableSeat.EndScore = player.EndScore
TableSeat.CanBet = player.CanBet
TableSeat.GameState = player.GameState
if player.ChairId == rr.CurrBanker {
TableSeat.TableScore = player.TableScore
if _, bHave := rr.NeedOutPlayer[TableSeat.ChairID]; bHave {
TableSeat.NextTimestamp = rr.NeedOutPlayer[TableSeat.ChairID]
}
if player.ChairId == rr.CurrBanker && rr.CurrentGameState != protocol.STATE_RESULT {
TableSeat.IsBanker = 1
}
for _, poker := range player.HandPoker {
@ -83,21 +94,23 @@ func (rr *Room) OnGetRoomInfo(uid int64, ctx *node.Context) interface{} {
}
log.Debug(" player.ChairId ", player.ChairId, " HandPoker ", TableSeat.HandPoker)
TableSeat.PokerType = 0
if player.CanBet && player.GameState != 1 {
//if player.CanBet && player.GameState != 1 {
if player.CanBet {
PokerType := int32(0)
if rr.CurrGameRound == 0 {
if rr.CurrGameRound == 1 {
PokerType = int32(player.ThreeKind.GetCardType())
for _, poker := range player.ThreeKind {
TableSeat.BestPoker = append(TableSeat.BestPoker, int32(poker))
}
log.Debug("UID ", player.Uid, " PokerType=", PokerType, " tempPlayer.ThreeKind=", player.ThreeKind)
} else if rr.CurrGameRound == 1 {
} else if rr.CurrGameRound == 2 {
PokerType = int32(player.FourKind.GetCardType())
for _, poker := range player.FourKind {
TableSeat.BestPoker = append(TableSeat.BestPoker, int32(poker))
}
log.Debug("UID ", player.Uid, " PokerType=", PokerType, " tempPlayer.FourKind=", player.FourKind)
} else if rr.CurrGameRound == 2 {
} else if rr.CurrGameRound == 3 {
PokerType = int32(player.BestKind.GetCardType())
for _, poker := range player.BestKind {
TableSeat.BestPoker = append(TableSeat.BestPoker, int32(poker))
@ -128,6 +141,7 @@ func (rr *Room) OnGetRoomInfo(uid int64, ctx *node.Context) interface{} {
TableSeat.CellScore = player.CellScore
TableSeat.RoundScore = 0
TableSeat.EndScore = player.EndScore
TableSeat.GameCurrenRoundState = player.GameCurrenRoundState
TableSeat.CanBet = player.CanBet
TableSeat.GameState = player.GameState
if player.ChairId == rr.CurrBanker {
@ -153,24 +167,58 @@ func (rr *Room) OnGetRoomInfo(uid int64, ctx *node.Context) interface{} {
}
if pPlayer != nil {
if pPlayer.Gold.IntPart() >= rr.CellScore-pPlayer.RoundScore {
UserBetCRF = append(UserBetCRF, protocol.OperateGen)
UserCellScore = append(UserCellScore, rr.CellScore-pPlayer.RoundScore)
if rr.BetCRF == 0 {
if pPlayer.Gold.IntPart() >= rr.CellScore*2-pPlayer.RoundScore {
UserBetCRF = append(UserBetCRF, protocol.OperateJia)
UserCellScore = append(UserCellScore, rr.CellScore*2-pPlayer.RoundScore)
} else {
UserBetCRF = append(UserBetCRF, protocol.OperateAll)
}
}
//if pPlayer.TableScore >= rr.CellScore-pPlayer.RoundScore {
UserBetCRF = append(UserBetCRF, protocol.OperateGen)
UserCellScore = append(UserCellScore, rr.CellScore-pPlayer.RoundScore)
//if rr.BetCRF == 0 && !rr.bUserAllIn {
if rr.CurrGameRound == 0 && !rr.RoundSubBet {
// 0第一轮 2 3 4 All
UserCellScore = append(UserCellScore, rr.Opt.MinBetAsset*2)
UserCellScore = append(UserCellScore, rr.Opt.MinBetAsset*3)
UserCellScore = append(UserCellScore, rr.Opt.MinBetAsset*4)
UserCellScore = append(UserCellScore, pPlayer.TableScore)
} else {
UserBetCRF = append(UserBetCRF, protocol.OperateAll)
// 1 正常 1/3 1/2 2/3 1
if rr.TableCurrentScore/3 < rr.CellScore-pPlayer.RoundScore {
UserCellScore = append(UserCellScore, rr.CellScore-pPlayer.RoundScore)
} else {
UserCellScore = append(UserCellScore, int64(math.Ceil(float64(rr.TableCurrentScore)/3)))
}
if rr.TableCurrentScore/2 < rr.CellScore-pPlayer.RoundScore {
UserCellScore = append(UserCellScore, rr.CellScore-pPlayer.RoundScore)
} else {
UserCellScore = append(UserCellScore, int64(math.Ceil(float64(rr.TableCurrentScore)/2)))
}
if rr.TableCurrentScore*2/3 < rr.CellScore-pPlayer.RoundScore {
UserCellScore = append(UserCellScore, rr.CellScore-pPlayer.RoundScore)
} else {
UserCellScore = append(UserCellScore, int64(math.Ceil(float64(rr.TableCurrentScore)*2/3)))
}
UserCellScore = append(UserCellScore, rr.TableCurrentScore)
}
//if player.Gold.IntPart() >= rr.CellScore*2-player.RoundScore {
// UserBetCRF = append(UserBetCRF, protocol.OperateJia)
// UserCellScore = append(UserCellScore, rr.CellScore*2-player.RoundScore)
//} else {
// UserBetCRF = append(UserBetCRF, protocol.OperateAll)
//}
//}
//} else {
UserBetCRF = append(UserBetCRF, protocol.OperateAll)
//}
}
TableInfo.CurrentOperateUser = rr.CurrOperationPlayer
TableInfo.BetCRF = UserBetCRF
if rr.CurrGameRound == 0 && !rr.RoundSubBet {
TableInfo.Type = 0
} else {
TableInfo.Type = 1
}
TableInfo.CellScore = UserCellScore
pPlayer.Ctx = ctx
@ -179,23 +227,23 @@ func (rr *Room) OnGetRoomInfo(uid int64, ctx *node.Context) interface{} {
// 发送完桌子消息 再激活用户状态
pPlayer.OnlineState = USER_ON_LINE
//判断开场
if rr.State < EN_TABLE_STATE_PLAYING && rr.GetRoomPlayerCount() > 2 {
rr.State = EN_TABLE_STATE_PLAYING
milliseconds := time.Now().UnixMilli()
rr.CurrentGameState = protocol.STATE_GET_BANKER
rr.CurrentOperationTimer = milliseconds + rr.TimeOutGetBanker
rr.RepeatRoomUser()
log.Debug(" 桌子号", rr.RId, " 开始游戏 抢庄倒计时 ", rr.TimeOutGetBanker)
rr.SendAllMessage(route.NotifyStateTime, &protocol.NotifyStateTime{
NextState: protocol.STATE_GET_BANKER,
NextTimestamp: rr.CurrentOperationTimer,
})
// 抢庄做了加一秒的容错判断
rr.CurrentOperationTimer += 1000
}
////判断开场
//if rr.State < EN_TABLE_STATE_PLAYING && rr.GetRoomPlayerCount() > 2 {
// rr.State = EN_TABLE_STATE_PLAYING
// milliseconds := time.Now().UnixMilli()
// rr.CurrentGameState = protocol.STATE_GET_BANKER
// rr.CurrentOperationTimer = milliseconds + rr.TimeOutGetBanker
// rr.RepeatRoomUser()
//
// log.Debug(" 桌子号", rr.RId, " 开始游戏 抢庄倒计时 ", rr.TimeOutGetBanker)
//
// rr.SendAllMessage(route.NotifyStateTime, &protocol.NotifyStateTime{
// NextState: protocol.STATE_GET_BANKER,
// NextTimestamp: rr.CurrentOperationTimer,
// })
// // 抢庄做了加一秒的容错判断
// rr.CurrentOperationTimer += 1000
//}
return TableInfo
}

7
game-server/game/DZ/app/core/game/game_init.go

@ -59,7 +59,11 @@ func (rr *Room) OnInit() bool {
rr.InitBloodControl()
var gameTableConfig *gamepb.FetchGameTableTotalsReply
gameTableConfig = rpc_client.GetTableCtrlConfig(rr.RoomProxy, int64(rr.GameID), strconv.Itoa(int(rr.RoomID)))
TableType := int64(1) //1 系统 2玩家
if rr.CreatorId != 0 {
TableType = 2
}
gameTableConfig = rpc_client.GetTableCtrlConfig(rr.RoomProxy, int64(rr.GameID), strconv.Itoa(int(rr.RoomID)), TableType)
if len(gameTableConfig.List) == 0 {
log.Error(" 21点后台获取桌子配置 无配置 房间等级 ", rr.RoomID)
} else {
@ -110,6 +114,7 @@ func (rr *Room) OnInit() bool {
rr.RoomLimit = decimal.NewFromFloat(float64(rr.Opt.MinEnterAsset))
// 底注
rr.BetList = rr.Opt.BetAssetOptions
rr.CurrBanker = INVALID_VALUE //
//new一个定时器
if rr.GronTimer != nil {

28
game-server/game/DZ/app/core/game/game_join_room.go

@ -2,7 +2,7 @@ package game
import (
"base/log"
"github.com/shopspring/decimal"
"time"
"xgame/game/DZ/app/core/protocol"
"xgame/game/DZ/app/route"
)
@ -29,13 +29,13 @@ func (rr *Room) JoinRoom(pPlayer *Player, isWatching int32) int32 {
// return -1
//}
//钱不够 不能进
if pPlayer.Gold.LessThan(rr.RoomLimit) {
return -2
}
////钱不够 不能进
//if pPlayer.Gold.LessThan(rr.RoomLimit) {
// return -2
//}
//钱不够 直接观战
if pPlayer.Gold.LessThan(decimal.NewFromInt(MIN_GAME_SCORE)) {
//钱不够 观战
if pPlayer.Gold.LessThan(rr.RoomLimit) {
chairId = -1
}
@ -53,6 +53,7 @@ func (rr *Room) JoinRoom(pPlayer *Player, isWatching int32) int32 {
rr.isUserCtl = false
pPlayer.CheatType = 0
pPlayer.CheatValue = 0
rr.NeedOutPlayer[pPlayer.ChairId] = time.Now().UnixMilli() + 60*1000
if !pPlayer.IsRobot {
Reply := rr.GetUserGameControl(rr.RoomProxy, pPlayer.Uid, int64(rr.GameID), 0)
@ -75,11 +76,11 @@ func (rr *Room) JoinRoom(pPlayer *Player, isWatching int32) int32 {
rr.PlayerMap[pPlayer.ChairId] = pPlayer
}
// 还没开场可以参与游戏
if (rr.CurrentGameState != protocol.STATE_INVALUE) && (rr.CurrentGameState < protocol.STATE_BEGIN || rr.CurrentGameState == protocol.STATE_RESULT) {
log.Debug("加入房间 还没开场可以参与游戏 ", pPlayer.Uid, " 当前阶段 ", rr.CurrentGameState)
pPlayer.CanBet = true
}
//// 还没开场可以参与游戏
//if (rr.CurrentGameState != protocol.STATE_INVALUE) && (rr.CurrentGameState < protocol.STATE_BEGIN || rr.CurrentGameState == protocol.STATE_RESULT) {
// log.Debug("加入房间 还没开场可以参与游戏 ", pPlayer.Uid, " 当前阶段 ", rr.CurrentGameState)
// pPlayer.CanBet = true
//}
SitDownRes := &protocol.SitDownRes{
Code: 0,
@ -109,6 +110,9 @@ func (rr *Room) JoinRoom(pPlayer *Player, isWatching int32) int32 {
TableSeat.CanBet = pPlayer.CanBet
TableSeat.BetType = pPlayer.BetType
TableSeat.GameState = pPlayer.GameState
if _, bHave := rr.NeedOutPlayer[TableSeat.ChairID]; bHave {
TableSeat.NextTimestamp = rr.NeedOutPlayer[TableSeat.ChairID]
}
SitDownRes.PlayerInfo = TableSeat
NotifySitDown.PlayerInfo = TableSeat

177
game-server/game/DZ/app/core/game/game_logic.go

@ -15,7 +15,7 @@ func (rr *Room) UpdateCtx(uid int64, ctx *node.Context) {
for Index, p := range rr.PlayerMap {
if p.Uid == uid {
log.Debug("桌子ID", rr.RId, "PlayerMap User ", uid, " 用户名字 ", p.Nickname, "原来的 ", p.Ctx, "新的 Ctx", ctx)
log.Debug(" 桌子号", rr.RId, "PlayerMap User ", uid, " 用户名字 ", p.Nickname, "原来的 ", p.Ctx, "新的 Ctx", ctx)
rr.PlayerMap[Index].OnlineState = USER_ON_LINE
rr.PlayerMap[Index].Ctx = ctx
break
@ -24,7 +24,7 @@ func (rr *Room) UpdateCtx(uid int64, ctx *node.Context) {
for Index, p := range rr.PlayerWatchMap {
if p.Uid == uid {
log.Debug("桌子ID", rr.RId, "PlayerWatchMap User ", uid, " 用户名字 ", p.Nickname, "原来的 ", p.Ctx, "新的 Ctx", ctx)
log.Debug(" 桌子号", rr.RId, "PlayerWatchMap User ", uid, " 用户名字 ", p.Nickname, "原来的 ", p.Ctx, "新的 Ctx", ctx)
rr.PlayerWatchMap[Index].OnlineState = USER_ON_LINE
rr.PlayerWatchMap[Index].Ctx = ctx
break
@ -32,6 +32,19 @@ func (rr *Room) UpdateCtx(uid int64, ctx *node.Context) {
}
}
func (rr *Room) UpdateUserOut(uid int64) { // 更新用户退出状态
rr.roomRWLock.Lock()
defer rr.roomRWLock.Unlock()
for Index, p := range rr.PlayerMap {
if p.Uid == uid {
rr.PlayerMap[Index].UserNeedOut = true
break
}
}
}
func (rr *Room) run() {
milliseconds := time.Now().UnixMilli()
@ -59,11 +72,11 @@ func (rr *Room) run() {
}
}
}
//随机一个庄
//随机一个庄 弃用
case protocol.STATE_GET_BANKER:
{
// 等待过程中人数又不足了 重新等待开场
if rr.GetRoomPlayerCount() <= 2 {
if rr.GetRoomCanPlayPlayerCount() <= 2 {
rr.State = EN_TABLE_STATE_READY_TO_START
rr.CurrentGameState = protocol.STATE_WAIT
rr.CurrentOperationTimer = milliseconds + rr.TimeoutDestroy
@ -94,8 +107,26 @@ func (rr *Room) run() {
}
case protocol.STATE_BEGIN:
{
// 等待过程中人数又不足了 重新等待开场
if rr.GetRoomCanPlayPlayerCount() <= 2 {
rr.State = EN_TABLE_STATE_READY_TO_START
rr.CurrentGameState = protocol.STATE_WAIT
rr.CurrentOperationTimer = milliseconds + rr.TimeoutDestroy
rr.SendAllMessage(route.NotifyStateTime, &protocol.NotifyStateTime{
NextState: protocol.STATE_WAIT,
NextTimestamp: rr.CurrentOperationTimer,
})
break
}
if milliseconds >= rr.CurrentOperationTimer {
rr.CurrentGameState = protocol.STATE_INVALUE
//设置游戏状态
rr.State = EN_TABLE_STATE_PLAYING
rr.CurrentGameState = protocol.STATE_OPERATE
rr.CurrentOperationTimer = milliseconds + 60*1000
rr.Round++ //轮数+1
rr.OnGameStart()
}
return
@ -118,7 +149,7 @@ func (rr *Room) run() {
// 先弄个长点的时间防止结算时间出问题
rr.CurrentOperationTimer = milliseconds + 30000
rr.OnEventGameConclude()
rr.OnEventGameConclude(255)
// 重新读取下配置文件
rr.InitBloodControl()
@ -141,6 +172,11 @@ func (rr *Room) run() {
log.Debug(" 桌子号", rr.RId, " 用户 ", player.Nickname, " 不在线 ", rr.RId)
rr.OnGetOutRoom(player.Uid, protocol.ErrorKickUserOFFLine)
}
if player.UserNeedOut {
log.Debug(" 桌子号", rr.RId, " 用户 ", player.Nickname, " 需要退出 ")
rr.OnGetOutRoom(player.Uid, 0)
}
}
for _, player := range rr.PlayerWatchMap {
if player.IsRobot {
@ -151,38 +187,65 @@ func (rr *Room) run() {
log.Debug(" 桌子号", rr.RId, " 观战用户 ", player.Nickname, " 不在线 ", rr.RId)
rr.OnGetOutRoom(player.Uid, protocol.ErrorKickUserOFFLine)
} else if !player.IsRobot && player.PlayWatchCount >= int(3) {
log.Debug("用户 ", player.Nickname, " 连续观战了3局 ", rr.RId)
log.Debug(" 桌子号", rr.RId, "用户 ", player.Nickname, " 连续观战了3局 ", rr.RId)
rr.OnGetOutRoom(player.Uid, protocol.ErrorKickUserWatchingTimes)
}
}
// 钱不够转为观战 然后观战人替补进来一个
for _, player := range rr.PlayerMap {
if player.IsRobot {
continue
}
if player.Gold.IntPart() <= MIN_GAME_SCORE {
log.Debug(" 桌子号", rr.RId, " 用户 ", player.Nickname, " 钱不够转为观战 拥有钱:", player.Gold.IntPart(), " 需要的钱:", MIN_GAME_SCORE)
TempChairID := player.ChairId
player.ChairId = -1
rr.SendAllMessage(route.NotifyDownToWatch, &protocol.NotifyDownToWatch{
ChairID: TempChairID,
})
// 通知大厅有人离开或观战
NotifySitDown := &protocol.NotifyDTSitDown{
Uid: player.Uid,
RoomID: rr.RoomID,
TableID: rr.RId,
ChairID: TempChairID,
Avatar: player.Avatar,
State: rr.CurrentGameState,
// 钱不够通知充钱
for Index, player := range rr.PlayerMap {
//if player.IsRobot {
// continue
//}
//if player.Gold.IntPart() <= MIN_GAME_SCORE {
if player.TableScore < rr.Opt.MinTableTake {
log.Debug(" 桌子号", rr.RId, " 用户 ", player.Nickname, " 钱不够转为等待入金:", player.TableScore, " 需要的钱:", rr.Opt.MinTableTake)
//TempChairID := player.ChairId
//player.ChairId = -1
//rr.SendAllMessage(route.NotifyDownToWatch, &protocol.NotifyDownToWatch{
// ChairID: TempChairID,
//})
//
//// 通知大厅有人离开或观战
//NotifySitDown := &protocol.NotifyDTSitDown{
// Uid: player.Uid,
// RoomID: rr.RoomID,
// TableID: rr.RId,
// ChairID: TempChairID,
// Avatar: player.Avatar,
// State: rr.CurrentGameState,
//}
//rr.NotifyFunc(route.NotifyDTStandUp, NotifySitDown)
//
//delete(rr.PlayerMap, TempChairID)
//rr.PlayerWatchMap = append(rr.PlayerWatchMap, player)
// 通知需要入金的人
NotifyNeedTableTake := &protocol.NotifyNeedTableTake{
ChairID: player.ChairId,
MinTableTake: rr.Opt.MinTableTake,
MaxTableTake: rr.Opt.MaxTableTake,
NextTimestamp: milliseconds + 60*1000,
}
rr.Send(player, route.NotifyNeedTake, NotifyNeedTableTake)
rr.NeedOutPlayer[player.ChairId] = milliseconds + 60*1000
rr.PlayerMap[Index].CanBet = false
// 通知其它人谁需要入金了
for _, player2 := range rr.PlayerMap {
if player2.IsRobot || player.ChairId == player2.ChairId {
continue
}
NotifyNeedTableTake2 := &protocol.NotifyNeedTableTake{
ChairID: player.ChairId,
MinTableTake: rr.Opt.MinTableTake,
MaxTableTake: rr.Opt.MaxTableTake,
NextTimestamp: milliseconds + 60*1000,
}
rr.Send(player2, route.NotifyNeedTake, NotifyNeedTableTake2)
}
rr.NotifyFunc(route.NotifyDTStandUp, NotifySitDown)
delete(rr.PlayerMap, TempChairID)
rr.PlayerWatchMap = append(rr.PlayerWatchMap, player)
}
}
@ -225,18 +288,18 @@ func (rr *Room) run() {
// }
//}
//设置游戏状态
rr.State = EN_TABLE_STATE_READY_TO_START
//设置游戏状态 这儿不能设置 还是在游戏中
// rr.State = EN_TABLE_STATE_READY_TO_START
rr.CurrentGameState = protocol.STATE_GET_BANKER
rr.CurrentOperationTimer = milliseconds + rr.TimeOutGetBanker
rr.CurrentGameState = protocol.STATE_BEGIN
rr.CurrentOperationTimer = milliseconds + rr.TimeOutBegin
//0.复位房间一些相关数据
rr.RepeatRoom()
rr.RepeatRoomUser()
rr.SendAllMessage(route.NotifyStateTime, &protocol.NotifyStateTime{
NextState: protocol.STATE_GET_BANKER,
NextState: rr.CurrentGameState,
NextTimestamp: rr.CurrentOperationTimer,
})
// 抢庄做了加一秒的容错判断
@ -244,6 +307,44 @@ func (rr *Room) run() {
}
}
}
if len(rr.NeedOutPlayer) != 0 {
for iChairID, iTime := range rr.NeedOutPlayer {
if milliseconds >= iTime {
rr.NeedOutPlayer[iChairID] = iTime + 10*1000
// 需要转为观战
CurrentPlayer := rr.PlayerMap[iChairID]
if CurrentPlayer == nil {
log.Debug(" 桌子号", rr.RId, "用户椅子号 ", iChairID, " 已不在桌子上了")
delete(rr.NeedOutPlayer, iChairID)
continue
}
log.Debug(" 桌子号", rr.RId, "用户 ", CurrentPlayer.Nickname, " 60秒没有入金 转为观战")
TempChairID := CurrentPlayer.ChairId
CurrentPlayer.ChairId = -1
rr.SendAllMessage(route.NotifyDownToWatch, &protocol.NotifyDownToWatch{
ChairID: TempChairID,
})
// 通知大厅有人离开或观战
NotifySitDown := &protocol.NotifyDTSitDown{
Uid: CurrentPlayer.Uid,
RoomID: rr.RoomID,
TableID: rr.RId,
ChairID: TempChairID,
Avatar: CurrentPlayer.Avatar,
State: rr.CurrentGameState,
}
rr.NotifyFunc(route.NotifyDTStandUp, NotifySitDown)
delete(rr.PlayerMap, TempChairID)
rr.PlayerWatchMap = append(rr.PlayerWatchMap, CurrentPlayer)
delete(rr.NeedOutPlayer, iChairID)
}
}
}
}
func (rr *Room) Send(player *Player, msgId int32, message interface{}) {

1
game-server/game/DZ/app/core/game/game_new.go

@ -20,6 +20,7 @@ func New(Uid, rid int64, RoomID, GameID, AgentID int32, destory comm.DestoryCB,
ReasonString: strconv.Itoa(int(GameID)) + "|" + strconv.Itoa(int(RoomID)),
AgentID: AgentID,
PlayerMap: make(map[int32]*Player),
NeedOutPlayer: make(map[int32]int64),
PlayerWatchMap: make([]*Player, 0),
RobotMgr: NewRobotManager(),
Round: 0,

70
game-server/game/DZ/app/core/game/game_next_player.go

@ -2,6 +2,7 @@ package game
import (
"base/log"
"math"
"time"
"xgame/game/DZ/app/core/protocol"
"xgame/game/DZ/app/route"
@ -18,7 +19,7 @@ func (rr *Room) NextPLayer() { // 切换下一家
}
if _, exist := rr.PlayerMap[TempChairID]; exist {
if rr.PlayerMap[TempChairID].CanBet && rr.PlayerMap[TempChairID].GameState == 0 {
if rr.PlayerMap[TempChairID].CanBet && rr.PlayerMap[TempChairID].TableScore != 0 && rr.PlayerMap[TempChairID].GameState == 0 {
player := rr.PlayerMap[TempChairID]
rr.CurrOperationPlayer = TempChairID
log.Debug(" 桌子号", rr.RId, " 找到了下一家 当前庄家 ", rr.CurrBanker, " 当前操作玩家", rr.CurrOperationPlayer)
@ -34,30 +35,69 @@ func (rr *Room) NextPLayer() { // 切换下一家
UserBetCRF = append(UserBetCRF, protocol.OperateCheck)
}
if player.Gold.IntPart() >= rr.CellScore-player.RoundScore {
UserBetCRF = append(UserBetCRF, protocol.OperateGen)
UserCellScore = append(UserCellScore, rr.CellScore-player.RoundScore)
if rr.BetCRF == 0 {
if player.Gold.IntPart() >= rr.CellScore*2-player.RoundScore {
UserBetCRF = append(UserBetCRF, protocol.OperateJia)
UserCellScore = append(UserCellScore, rr.CellScore*2-player.RoundScore)
} else {
UserBetCRF = append(UserBetCRF, protocol.OperateAll)
}
if rr.CurrGameRound == 0 {
UserBetCRF = append(UserBetCRF, protocol.OperateBet)
}
//if player.TableScore >= rr.CellScore-player.RoundScore {
UserCellScore = append(UserCellScore, rr.CellScore-player.RoundScore)
if rr.CellScore-player.RoundScore == 0 {
if !rr.CanCheck {
UserBetCRF = append(UserBetCRF, protocol.OperateCheck)
}
} else {
UserBetCRF = append(UserBetCRF, protocol.OperateAll)
UserBetCRF = append(UserBetCRF, protocol.OperateGen)
}
log.Debug(" 桌子号", rr.RId, " 桌子上总钱 ", rr.TableCurrentScore, " rr.CellScore ", rr.CellScore, " RoundScore", player.RoundScore)
//if rr.BetCRF == 0 && !rr.bUserAllIn {
if rr.CurrGameRound == 0 && !rr.RoundSubBet {
// 0第一轮 2 3 4 All
UserCellScore = append(UserCellScore, rr.Opt.MinBetAsset*2)
UserCellScore = append(UserCellScore, rr.Opt.MinBetAsset*3)
UserCellScore = append(UserCellScore, rr.Opt.MinBetAsset*4)
UserCellScore = append(UserCellScore, player.TableScore)
} else {
// 1 正常 1/3 1/2 2/3 1
if rr.TableCurrentScore/3 < rr.CellScore-player.RoundScore {
UserCellScore = append(UserCellScore, rr.CellScore-player.RoundScore)
} else {
UserCellScore = append(UserCellScore, int64(math.Ceil(float64(rr.TableCurrentScore)/3)))
}
if rr.TableCurrentScore/2 < rr.CellScore-player.RoundScore {
UserCellScore = append(UserCellScore, rr.CellScore-player.RoundScore)
} else {
UserCellScore = append(UserCellScore, int64(math.Ceil(float64(rr.TableCurrentScore)/2)))
}
if rr.TableCurrentScore*2/3 < rr.CellScore-player.RoundScore {
UserCellScore = append(UserCellScore, rr.CellScore-player.RoundScore)
} else {
UserCellScore = append(UserCellScore, int64(math.Ceil(float64(rr.TableCurrentScore)*2/3)))
}
UserCellScore = append(UserCellScore, rr.TableCurrentScore)
}
log.Debug("通知到 ", rr.CurrOperationPlayer, " 椅子操作 BetCRF(1跟2加3弃4All5过) ", UserBetCRF, " 本轮最高下注 ", rr.CellScore, " 玩家当前圈下注", player.RoundScore, " UserCellScore ", UserCellScore)
log.Debug("通知到 ", rr.CurrOperationPlayer, " player.BetType: ", player.BetType, " player.CellScore: ", player.CellScore, " 玩家当前圈下注", player.RoundScore, " UserCellScore ", UserCellScore)
//}
//} else {
UserBetCRF = append(UserBetCRF, protocol.OperateAll)
//}
log.Debug(" 桌子号", rr.RId, "通知到 ", rr.CurrOperationPlayer, " 椅子操作 BetCRF(1跟2加3弃4All5过) ", UserBetCRF, " 本轮最高下注 ", rr.CellScore, " 玩家当前圈下注", player.RoundScore, " UserCellScore ", UserCellScore)
log.Debug(" 桌子号", rr.RId, "通知到 ", rr.CurrOperationPlayer, " player.BetType: ", player.BetType, " player.CellScore: ", player.CellScore, " 玩家当前圈下注", player.RoundScore, " UserCellScore ", UserCellScore)
NotifyWhoOperate := &protocol.NotifyWhoOperate{
ChairID: rr.CurrOperationPlayer,
BetCRF: UserBetCRF,
CellScore: UserCellScore,
NextTimestamp: rr.CurrentOperationTimer,
}
if rr.CurrGameRound == 0 && !rr.RoundSubBet {
NotifyWhoOperate.Type = 0
} else {
NotifyWhoOperate.Type = 1
}
rr.SendAllMessage(route.NotifyWhoOperate, NotifyWhoOperate)
return

368
game-server/game/DZ/app/core/game/game_operate.go

@ -3,6 +3,7 @@ package game
import (
"base/log"
"github.com/shopspring/decimal"
"sort"
"strconv"
"time"
"xgame/game/DZ/app/core/protocol"
@ -43,14 +44,33 @@ func (rr *Room) OnUserOperate(uid int64, msg interface{}) { // 用户操作
return
}
if message.UserScore < 0 {
log.Debug("玩家", ChairId, "个人下注总值", message.UserScore, " 拥有的钱: ", rr.PlayerMap[ChairId].Gold.IntPart())
OperateRes.Code = protocol.ErrorCodeOperateError
OperateRes.CodeMsg = "下注额异常 " + strconv.Itoa(int(message.UserScore))
rr.Send(rr.PlayerMap[ChairId], route.OperateRes, OperateRes)
return
}
player := rr.PlayerMap[ChairId]
player.GameCurrenRoundState = message.OperateCode
log.Debug(" 桌子号", rr.RId, " 当前操作玩家", rr.CurrOperationPlayer, " 操作(1跟2加3弃4All5过) ", message.OperateCode)
log.Debug(" 桌子号", rr.RId, " 当前第几轮 ", rr.CurrGameRound, " 本轮需要下注", rr.CellScore, " 本轮下注 ", player.RoundScore, " 要加注的钱", message.UserScore)
TempCellScore := int64(0)
switch message.OperateCode {
case protocol.OperateGen:
rr.CanCheck = false
TempCellScore = rr.CellScore - player.RoundScore
// 判断和操作是否相符
if player.TableScore < TempCellScore || TempCellScore < 0 {
log.Debug("玩家", ChairId, "桌子上的前", player.TableScore, " 要跟注的钱: ", TempCellScore)
OperateRes.Code = protocol.ErrorCodeOperateError
OperateRes.CodeMsg = "下注额异常 " + strconv.Itoa(int(player.TableScore))
rr.Send(rr.PlayerMap[ChairId], route.OperateRes, OperateRes)
return
}
rr.CanCheck = false
player.CellScore += TempCellScore
player.RoundScore += TempCellScore
@ -58,14 +78,29 @@ func (rr *Room) OnUserOperate(uid int64, msg interface{}) { // 用户操作
player.Gold = player.Gold.Sub(decimal.NewFromInt(TempCellScore))
if !player.IsRobot && (player.Ctx != nil) && (TempCellScore != 0) {
AfterGold, BloodPool, StockNum := rr.WriteUserScore(player, 1, TempCellScore, 0, 0, rr.ReasonString, "", "", 0)
AfterGold, BloodPool, StockNum := rr.WriteUserScore(player, 1, TempCellScore, 0, 0, rr.ReasonString, "", "", 0, 0)
log.Debug(" 桌子号", rr.RId, " 跟注 WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum)
}
rr.TableCurrentScore += TempCellScore
player.TableScore -= TempCellScore
log.Debug(" 桌子号", rr.RId, " 跟注 当前操作玩家", rr.CurrOperationPlayer, " TempCellScore ", TempCellScore, " TableScore ", player.TableScore)
case protocol.OperateJia:
rr.RoundSubBet = true
TempCellScore = message.UserScore
// 判断和操作是否相符
if player.TableScore < TempCellScore || TempCellScore <= 0 {
log.Debug("玩家", ChairId, "桌子上的前", player.TableScore, " 要加注的钱: ", TempCellScore)
OperateRes.Code = protocol.ErrorCodeOperateError
OperateRes.CodeMsg = "下注额异常 " + strconv.Itoa(int(player.TableScore))
rr.Send(rr.PlayerMap[ChairId], route.OperateRes, OperateRes)
return
}
rr.CanCheck = false
rr.CellScore *= 2
TempCellScore = rr.CellScore - player.RoundScore
rr.CellScore = player.RoundScore + message.UserScore
player.CellScore += TempCellScore
player.RoundScore += TempCellScore
@ -73,52 +108,75 @@ func (rr *Room) OnUserOperate(uid int64, msg interface{}) { // 用户操作
player.Gold = player.Gold.Sub(decimal.NewFromInt(TempCellScore))
if !player.IsRobot && (player.Ctx != nil) {
AfterGold, BloodPool, StockNum := rr.WriteUserScore(player, 1, TempCellScore, 0, 0, rr.ReasonString, "", "", 0)
AfterGold, BloodPool, StockNum := rr.WriteUserScore(player, 1, TempCellScore, 0, 0, rr.ReasonString, "", "", 0, 0)
log.Debug(" 桌子号", rr.RId, " 定庄后 下注 WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum)
}
rr.TableCurrentScore += TempCellScore
player.TableScore -= TempCellScore
log.Debug(" 桌子号", rr.RId, " 加注 当前操作玩家", rr.CurrOperationPlayer, " TempCellScore ", TempCellScore, " TableScore ", player.TableScore)
case protocol.OperateGaveUp:
// 玩家标识为已放弃
player.GameState = 1
case protocol.OperateAll:
rr.RoundSubBet = true
rr.CanCheck = false
rr.bUserAllIn = true
player.GameState = 2
// TODO: 这儿怎么处理
TempCellScore = player.Gold.IntPart()
TempCellScore = player.TableScore
player.CellScore += TempCellScore
player.RoundScore += TempCellScore
if player.Gold.IntPart() > rr.CellScore {
rr.CellScore *= 2
}
// 计算分池
for _, tempPlayer := range rr.PlayerMap {
if tempPlayer.CanBet {
player.WinTableScore += tempPlayer.CellScore
}
if player.RoundScore > rr.CellScore {
rr.CellScore = player.RoundScore
}
rr.UserScore[player.ChairId] = rr.UserScore[player.ChairId].Sub(decimal.NewFromInt(TempCellScore))
player.Gold = player.Gold.Sub(decimal.NewFromInt(TempCellScore))
if !player.IsRobot && (player.Ctx != nil) {
AfterGold, BloodPool, StockNum := rr.WriteUserScore(player, 1, TempCellScore, 0, 0, rr.ReasonString, "", "", 0)
AfterGold, BloodPool, StockNum := rr.WriteUserScore(player, 1, TempCellScore, 0, 0, rr.ReasonString, "", "", 0, 0)
log.Debug(" 桌子号", rr.RId, " 定庄后 下注 WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum)
}
rr.TableCurrentScore += TempCellScore
player.TableScore -= TempCellScore
log.Debug(" 桌子号", rr.RId, " ALLIn 当前操作玩家", rr.CurrOperationPlayer, " TempCellScore ", TempCellScore, " TableScore ", player.TableScore)
case protocol.OperateCheck:
// 不操作 切换下一家
}
// 最后结束的玩家 弃牌或allin了 最后的人要变
if message.OperateCode == protocol.OperateGaveUp || message.OperateCode == protocol.OperateAll {
if player.ChairId == rr.CurrEndUser {
for i := int32(1); i < 6; i++ {
tempChairId := rr.CurrEndUser - i
if tempChairId < 0 {
tempChairId += 6
}
if _, exist := rr.PlayerMap[tempChairId]; exist {
if rr.PlayerMap[tempChairId].CanBet && rr.PlayerMap[tempChairId].GameState == 0 {
rr.CurrEndUser = tempChairId
}
}
}
}
}
OperateRes.OperateCode = message.OperateCode
OperateRes.UserScore = TempCellScore
OperateRes.RoundScore = player.RoundScore
OperateRes.CellScore = player.CellScore
OperateRes.TableScore = player.TableScore
NotifyOperate.ChairID = ChairId
NotifyOperate.OperateCode = message.OperateCode
NotifyOperate.UserScore = TempCellScore
NotifyOperate.RoundScore = player.RoundScore
NotifyOperate.CellScore = player.CellScore
NotifyOperate.TableScore = player.TableScore
NoGameOverUserCount := 0
for _, TempPlayer := range rr.PlayerMap {
@ -136,18 +194,7 @@ func (rr *Room) OnUserOperate(uid int64, msg interface{}) { // 用户操作
rr.Send(TempPlayer, route.NotifyOperate, NotifyOperate)
}
// 只剩最后一家
if NoGameOverUserCount == 1 {
// 1秒后结算
go func() {
time.Sleep(1000 * time.Millisecond)
rr.OnEventGameConclude()
}()
return
}
log.Debug(" 用户 ", player.ChairId, " 当前轮数 ", rr.CurrGameRound, " 本轮需要下注 ", rr.CellScore, " 本轮已下注 ", player.RoundScore, " 总下注 ", player.CellScore)
log.Debug(" 桌子号", rr.RId, " 用户 ", player.ChairId, " 当前轮数 ", rr.CurrGameRound, " 本轮需要下注 ", rr.CellScore, " 本轮已下注 ", player.RoundScore, " 总下注 ", player.CellScore)
// 庄家判断
bNextRound := true
@ -159,19 +206,43 @@ func (rr *Room) OnUserOperate(uid int64, msg interface{}) { // 用户操作
}
}
// 只剩最后一家 且这家本轮已经操作完
if NoGameOverUserCount == 1 {
bNextRound = true
}
CanGoOnUserCount := 0
// 计算还能继续玩的人数
for _, tempPlayer := range rr.PlayerMap {
if tempPlayer.CanBet && tempPlayer.GameState == 0 {
CanGoOnUserCount++
}
}
// 最后一个操作完 且能操作的人数不足 才会结束这轮
if player.ChairId == rr.CurrEndUser && CanGoOnUserCount < 2 {
bNextRound = true
}
if rr.CurrEndUser == player.ChairId {
log.Debug(" 转了一轮 当前最后玩家 ", rr.CurrEndUser, " 当前庄家 ", rr.CurrBanker)
log.Debug(" 桌子号", rr.RId, " 转了一轮 当前最后玩家 ", rr.CurrEndUser, " 当前庄家 ", rr.CurrBanker)
// 转了一轮
// 全过也进入下一轮
if rr.CanCheck {
log.Debug(" 全过进入下一轮 ")
log.Debug(" 桌子号", rr.RId, " 全过进入下一轮 ")
bNextRound = true
}
//// 有人All了也进入下一轮
//if rr.bUserAllIn {
// log.Debug(" 桌子号", rr.RId, " 有人All了进入下一轮 ")
// bNextRound = true
//}
// 不能进入下一阶段则进入补注阶段
if !bNextRound {
log.Debug(" 进入补注阶段 ")
log.Debug(" 桌子号", rr.RId, " 进入补注阶段 ")
rr.BetCRF = 1
}
//} else if rr.CurrEndUser == player.ChairId {
@ -184,39 +255,241 @@ func (rr *Room) OnUserOperate(uid int64, msg interface{}) { // 用户操作
//}
if bNextRound {
log.Debug(" 进入下一轮 ")
log.Debug(" 桌子号", rr.RId, " 进入下一轮 ")
rr.BetCRF = 0
rr.CurrGameRound++
rr.CanCheck = true // 每一轮都可以check
if len(rr.TableScore) == 0 {
log.Debug(" 桌子号", rr.RId, " 这里为什么是空的?")
rr.TableScore = append(rr.TableScore, protocol.UserTableScore{Score: 0, Used: false})
}
if rr.bUserAllIn {
// 有人ALL 计算分池
var tempTableScore []protocol.UserTableScore
var tempAllINScore []protocol.UserTableScore
var tempAllScore int64
var CurrentRoundCount int
for _, tempPlayer := range rr.PlayerMap {
log.Debug(" 桌子号", rr.RId, " 有人all了 ChairId = ", tempPlayer.ChairId, " RoundScore = ", tempPlayer.RoundScore, " GameState = ", tempPlayer.GameState)
log.Debug(" 桌子号", rr.RId, " 有人all了 tempPlayer = ", tempPlayer)
if tempPlayer.CanBet {
tempAllScore += tempPlayer.CellScore
CurrentRoundCount++
if tempPlayer.GameState == 2 {
tempAllINScore = append(tempAllINScore, protocol.UserTableScore{
ChairID: []int32{tempPlayer.ChairId},
Score: tempPlayer.CellScore,
})
}
}
}
sort.Slice(tempAllINScore, func(i, j int) bool {
return tempAllINScore[i].Score < tempAllINScore[j].Score
})
log.Debug(" 桌子号", rr.RId, " 有人all了 tempAllINScore = ", tempAllINScore)
// 看分几个池子
for _, AllINScore := range tempAllINScore {
CurrentTableScore := int64(0)
for _, tempPlayer := range rr.PlayerMap {
if tempPlayer.CanBet && tempPlayer.CellScore > 0 {
if tempPlayer.CellScore <= AllINScore.Score {
CurrentTableScore += tempPlayer.CellScore
} else {
CurrentTableScore += AllINScore.Score
}
}
}
tempTableScore = append(tempTableScore, protocol.UserTableScore{
ChairID: AllINScore.ChairID,
Score: CurrentTableScore,
})
}
log.Debug(" 桌子号", rr.RId, " 有人all了 tempTableScore = ", tempTableScore)
rr.TableScore = rr.TableScore[:0]
for Index, TableScore := range tempTableScore {
if Index == 0 {
rr.TableScore = append(rr.TableScore, TableScore)
} else {
rr.TableScore = append(rr.TableScore, protocol.UserTableScore{
ChairID: TableScore.ChairID,
Score: TableScore.Score - tempTableScore[Index-1].Score,
})
}
}
// 如果计算完了 还有剩余池子
if len(tempTableScore) > 0 && tempAllScore > tempTableScore[len(tempTableScore)-1].Score {
//tempTableScore = append(tempTableScore, protocol.UserTableScore{
// Score: tempAllScore - tempTableScore[len(tempTableScore)-1].Score,
//})
rr.TableScore = append(rr.TableScore, protocol.UserTableScore{
Score: tempAllScore - tempTableScore[len(tempTableScore)-1].Score,
})
}
log.Debug(" 桌子号", rr.RId, " 有人all了 rr.TableScore = ", rr.TableScore)
}
// 开下一轮清空上一轮总投注
RoundTotalScore := int64(0)
for index, _ := range rr.PlayerMap {
rr.TableScore += rr.PlayerMap[index].RoundScore
if !rr.bUserAllIn {
rr.TableScore[len(rr.TableScore)-1].Score += rr.PlayerMap[index].RoundScore
}
rr.PlayerMap[index].RoundScore = 0
rr.PlayerMap[index].GameCurrenRoundState = 0
RoundTotalScore += rr.PlayerMap[index].CellScore
}
if rr.CurrGameRound == 3 {
// 开下一轮重置本轮有人All的状态
rr.bUserAllIn = false
log.Debug(" 桌子号", rr.RId, " 开下一轮清空上一轮总投注后 rr.TableScore = ", rr.TableScore)
// 开下一轮重置底注
rr.CellScore = rr.Opt.MinBetAsset
// 只剩最后一家 且这家本轮已经操作完
if NoGameOverUserCount == 1 {
// 1秒后结算
go func() {
time.Sleep(1000 * time.Millisecond)
rr.OnEventGameConclude()
rr.OnEventGameConclude(2)
}()
return
}
// 不够两个人 就开始结算了
if CanGoOnUserCount < 2 {
log.Debug(" 桌子号", rr.RId, " 全部弃牌或AllIn 直接结算 ")
//发牌
var SendPoker []int32
switch rr.CurrGameRound {
case 1:
////全发
//for i := 0; i < 5; i++ {
// SendPoker = append(SendPoker, int32(rr.HandPoker[i]))
//}
//发前三张牌
for i := 0; i < 3; i++ {
SendPoker = append(SendPoker, int32(rr.HandPoker[i]))
}
NotifyPoker := &protocol.NotifyPoker{
Poker: SendPoker,
}
for _, tempTableScore := range rr.TableScore {
NotifyPoker.TableScore = append(NotifyPoker.TableScore, tempTableScore.Score)
}
rr.SendAllMessage(route.NotifyPoker, NotifyPoker)
for _, tempPlayer := range rr.PlayerMap {
if tempPlayer.CanBet && tempPlayer.GameState != 1 {
PokerType := int32(0)
NotifyPokerType := &protocol.NotifyPokerType{}
PokerType = int32(tempPlayer.ThreeKind.GetCardType())
log.Debug("UID ", tempPlayer.Uid, " PokerType=", PokerType, " tempPlayer.ThreeKind=", tempPlayer.ThreeKind)
NotifyPokerType.PokerType = PokerType
for _, poker := range tempPlayer.ThreeKind {
NotifyPokerType.BestPoker = append(NotifyPokerType.BestPoker, int32(poker))
}
rr.Send(tempPlayer, route.NotifyPokerType, NotifyPokerType)
log.Debug("UID ", tempPlayer.Uid, " CurrGameRound=", rr.CurrGameRound, " PokerType=", NotifyPokerType.PokerType)
}
}
//发第四张
NotifyPoker2 := &protocol.NotifyPoker{
Poker: []int32{int32(rr.HandPoker[3])},
}
for _, tempTableScore := range rr.TableScore {
NotifyPoker2.TableScore = append(NotifyPoker2.TableScore, tempTableScore.Score)
}
rr.SendAllMessage(route.NotifyPoker, NotifyPoker2)
case 2:
////发第四 五张牌
//SendPoker = append(SendPoker, int32(rr.HandPoker[3]))
//SendPoker = append(SendPoker, int32(rr.HandPoker[4]))
//发第四张
SendPoker = append(SendPoker, int32(rr.HandPoker[3]))
NotifyPoker := &protocol.NotifyPoker{
Poker: SendPoker,
}
for _, tempTableScore := range rr.TableScore {
NotifyPoker.TableScore = append(NotifyPoker.TableScore, tempTableScore.Score)
}
rr.SendAllMessage(route.NotifyPoker, NotifyPoker)
//case 3:
// //发第五张牌
// SendPoker = append(SendPoker, int32(rr.HandPoker[4]))
}
for _, tempPlayer := range rr.PlayerMap {
if tempPlayer.CanBet && tempPlayer.GameState != 1 {
PokerType := int32(0)
NotifyPokerType := &protocol.NotifyPokerType{}
PokerType = int32(tempPlayer.FourKind.GetCardType())
log.Debug("UID ", tempPlayer.Uid, " PokerType=", PokerType, " tempPlayer.FourKind=", tempPlayer.FourKind)
NotifyPokerType.PokerType = PokerType
for _, poker := range tempPlayer.FourKind {
NotifyPokerType.BestPoker = append(NotifyPokerType.BestPoker, int32(poker))
}
rr.Send(tempPlayer, route.NotifyPokerType, NotifyPokerType)
log.Debug("UID ", tempPlayer.Uid, " CurrGameRound=", rr.CurrGameRound, " PokerType=", NotifyPokerType.PokerType)
}
}
// 1秒后结算
go func() {
time.Sleep(2000 * time.Millisecond)
rr.OnEventGameConclude(1)
}()
return
}
if rr.CurrGameRound == 4 {
// 1秒后结算
go func() {
time.Sleep(1000 * time.Millisecond)
rr.OnEventGameConclude(0)
}()
} else {
//发牌
var SendPoker []int32
switch rr.CurrGameRound {
case 1:
//发前三张牌
for i := 0; i < 3; i++ {
SendPoker = append(SendPoker, int32(rr.HandPoker[i]))
}
case 2:
//发第四张牌
SendPoker = append(SendPoker, int32(rr.HandPoker[3]))
case 2:
case 3:
//发第五张牌
SendPoker = append(SendPoker, int32(rr.HandPoker[4]))
}
NotifyPoker := &protocol.NotifyPoker{
Poker: SendPoker,
TableScore: RoundTotalScore,
Poker: SendPoker,
}
for _, tempTableScore := range rr.TableScore {
NotifyPoker.TableScore = append(NotifyPoker.TableScore, tempTableScore.Score)
}
rr.SendAllMessage(route.NotifyPoker, NotifyPoker)
@ -225,34 +498,43 @@ func (rr *Room) OnUserOperate(uid int64, msg interface{}) { // 用户操作
PokerType := int32(0)
NotifyPokerType := &protocol.NotifyPokerType{}
if rr.CurrGameRound == 1 {
PokerType = int32(tempPlayer.ThreeKind.GetCardType())
log.Debug(" 桌子号", rr.RId, "UID ", tempPlayer.Uid, " PokerType=", PokerType, " tempPlayer.ThreeKind=", tempPlayer.ThreeKind)
NotifyPokerType.PokerType = PokerType
for _, poker := range tempPlayer.ThreeKind {
NotifyPokerType.BestPoker = append(NotifyPokerType.BestPoker, int32(poker))
}
} else if rr.CurrGameRound == 2 {
PokerType = int32(tempPlayer.FourKind.GetCardType())
log.Debug("UID ", tempPlayer.Uid, " PokerType=", PokerType, " tempPlayer.ThreeKind=", tempPlayer.FourKind)
log.Debug(" 桌子号", rr.RId, "UID ", tempPlayer.Uid, " PokerType=", PokerType, " tempPlayer.FourKind=", tempPlayer.FourKind)
NotifyPokerType.PokerType = PokerType
for _, poker := range tempPlayer.FourKind {
NotifyPokerType.BestPoker = append(NotifyPokerType.BestPoker, int32(poker))
}
} else if rr.CurrGameRound == 2 {
} else if rr.CurrGameRound == 3 {
PokerType = int32(tempPlayer.BestKind.GetCardType())
log.Debug("UID ", tempPlayer.Uid, " PokerType=", PokerType, " tempPlayer.BestKind=", tempPlayer.BestKind)
log.Debug(" 桌子号", rr.RId, "UID ", tempPlayer.Uid, " PokerType=", PokerType, " tempPlayer.BestKind=", tempPlayer.BestKind)
NotifyPokerType.PokerType = PokerType
for _, poker := range tempPlayer.BestKind {
NotifyPokerType.BestPoker = append(NotifyPokerType.BestPoker, int32(poker))
}
}
rr.Send(tempPlayer, route.NotifyPokerType, NotifyPokerType)
log.Debug("UID ", tempPlayer.Uid, " CurrGameRound=", rr.CurrGameRound, " PokerType=", NotifyPokerType.PokerType)
log.Debug(" 桌子号", rr.RId, "UID ", tempPlayer.Uid, " CurrGameRound=", rr.CurrGameRound, " PokerType=", NotifyPokerType.PokerType)
}
}
// 1秒后下一个人操作
go func() {
time.Sleep(2000 * time.Millisecond)
rr.CurrOperationPlayer = rr.CurrBanker // 这需要重置操作玩家 好从小盲注重新开始下一轮
rr.NextPLayer()
}()
}
} else {
// 1秒后下一个人操作
go func() {
rr.CurrentOperationTimer = time.Now().UnixMilli() + 30000
time.Sleep(2000 * time.Millisecond)
rr.NextPLayer()
}()

269
game-server/game/DZ/app/core/game/game_over.go

@ -77,6 +77,10 @@ func (rr *Room) OnBuildOtherResultPoker() { //计算扑克
}
if _, exists := rr.PlayerMap[tempCurrentChair]; exists {
tempPlayer := rr.PlayerMap[tempCurrentChair]
if !tempPlayer.CanBet {
continue
}
if !tempPlayer.IsRobot && !HaveWin {
tempPlayer.NeedWinLose = protocol.Win
tempPlayer.RobotWin = true
@ -99,6 +103,10 @@ func (rr *Room) OnBuildOtherResultPoker() { //计算扑克
}
if _, exists := rr.PlayerMap[tempCurrentChair]; exists {
tempPlayer := rr.PlayerMap[tempCurrentChair]
if !tempPlayer.CanBet {
continue
}
if tempPlayer.IsRobot && !HaveWin {
tempPlayer.NeedWinLose = protocol.Win
tempPlayer.RobotWin = true
@ -185,6 +193,7 @@ func (rr *Room) OnBuildOtherResultPoker() { //计算扑克
}
tempHandCard := rr.SearchTypeHandCard(tempWinType, rr.GetRoomCanBetPlayerCount())
log.Debug(" 桌子号", rr.RId, " 生成了几副牌 :", rr.GetRoomCanBetPlayerCount(), " 牌是 :", tempHandCard)
LoseIndex := 1
for tempIndex, tempPlayer := range rr.PlayerMap {
@ -215,19 +224,26 @@ func (rr *Room) OnBuildOtherResultPoker() { //计算扑克
var AllKindFour []types.PokerSlice
AllKindThree = append(AllKindThree, rr.PlayerMap[tempIndex].HandPoker...)
AllKindThree = append(AllKindThree, rr.HandPoker[:3]...)
var tempHandPokerList types.PokerSlice
tempHandPokerList = append(tempHandPokerList, rr.PlayerMap[tempIndex].HandPoker...)
tempHandPokerList = append(tempHandPokerList, rr.HandPoker...)
for IndexIndex, OneKindIndex := range types.AllKindIndex {
var OnePokerList types.PokerSlice
var FourPokerList types.PokerSlice
OnePokerList = append(OnePokerList, rr.PlayerMap[tempIndex].HandPoker...)
FourPokerList = append(FourPokerList, rr.PlayerMap[tempIndex].HandPoker...)
//OnePokerList = append(OnePokerList, rr.PlayerMap[tempIndex].HandPoker...)
//FourPokerList = append(FourPokerList, rr.PlayerMap[tempIndex].HandPoker...)
for _, OneIndex := range OneKindIndex {
OnePokerList = append(OnePokerList, rr.HandPoker[OneIndex])
if IndexIndex < 4 {
FourPokerList = append(FourPokerList, rr.HandPoker[OneIndex])
//OnePokerList = append(OnePokerList, rr.HandPoker[OneIndex])
//if IndexIndex < 4 {
// FourPokerList = append(FourPokerList, rr.HandPoker[OneIndex])
//}
OnePokerList = append(OnePokerList, tempHandPokerList[OneIndex])
if IndexIndex < 6 {
FourPokerList = append(FourPokerList, tempHandPokerList[OneIndex])
}
}
rr.PlayerMap[tempIndex].AllKind = append(rr.PlayerMap[tempIndex].AllKind, OnePokerList)
if IndexIndex < 4 {
if IndexIndex < 6 {
AllKindFour = append(AllKindFour, FourPokerList)
}
}
@ -273,14 +289,35 @@ func (rr *Room) insertIntoSlice(slice types.PokerSlice, index int, value types.P
return newSlice
}
func (rr *Room) OnEventGameConclude() { // 结束-结算
func (rr *Room) OnEventGameConclude(EndType int32) { // 结束-结算
log.Debug(" 桌子号", rr.RId, "整体结算 ")
milliseconds := time.Now().UnixMilli()
// 结算展示时间
rr.CurrentGameState = protocol.STATE_RESULT
rr.CurrentOperationTimer = milliseconds + rr.TimeOutFinalResult + 2000
MoreTime := int64(0)
switch rr.CurrGameRound {
case 1:
MoreTime = 5
case 2:
MoreTime = 2
case 3:
MoreTime = 1
}
// 分池导致的时间延长
MoreSecondTime := int64(0)
for _, player := range rr.PlayerMap {
if !player.CanBet {
continue
}
if player.GameState == 2 {
MoreSecondTime += 3000
}
}
rr.CurrentOperationTimer = milliseconds + rr.TimeOutFinalResult + 2000*MoreTime + MoreSecondTime
rr.SendAllMessage(route.NotifyStateTime, &protocol.NotifyStateTime{
NextState: protocol.STATE_RESULT,
@ -289,6 +326,7 @@ func (rr *Room) OnEventGameConclude() { // 结束-结算
//结算
GameOver := &protocol.NotifyGameConclude{}
GameOver.EndType = EndType
var sArea string
sArea = ""
@ -313,16 +351,24 @@ func (rr *Room) OnEventGameConclude() { // 结束-结算
}
RecordInfoPlayer.PokerType = int32(player.BestKind.GetCardType())
RecordInfoPlayer.IsWin = false
RecordInfo.Player = append(RecordInfo.Player, RecordInfoPlayer)
}
options, err := json.Marshal(RecordInfo)
if err != nil {
log.Debug("RecordInfo 序列化失败")
}
sArea = string(options)
var sPlayers string
for _, player := range rr.PlayerMap {
if !player.IsRobot {
if len(sPlayers) == 0 {
sPlayers = sPlayers + player.UserNo
} else {
sPlayers = sPlayers + "," + player.UserNo
}
}
}
var UserList []int32
// 找到赢家
var WinPlayer []PokerUserType
TotalBet := int64(0)
@ -334,29 +380,157 @@ func (rr *Room) OnEventGameConclude() { // 结束-结算
TotalBet += player.CellScore
if player.GameState != 1 {
UserList = append(UserList, player.ChairId)
// 找到这个人的奖池
MaxWinTableScore := 0xFF
for i, score := range rr.TableScore {
for _, iChairID := range score.ChairID {
if iChairID == player.ChairId {
MaxWinTableScore = i
break
}
}
}
WinPlayer = append(WinPlayer, PokerUserType{
ChairId: Index,
HandPoker: player.BestKind,
ChairId: Index,
HandPoker: player.BestKind,
TableScoreIndex: MaxWinTableScore,
})
}
}
log.Debug(" 桌子号", rr.RId, "rr.TableScore = ", rr.TableScore)
log.Debug(" 桌子号", rr.RId, "UserList = ", UserList)
sort.Slice(WinPlayer, func(i, j int) bool {
return WinPlayer[i].HandPoker.Compare(WinPlayer[j].HandPoker) == 1
})
log.Debug(" 桌子号", rr.RId, "WinPlayer = ", WinPlayer)
// 标识赢家
WinMaxTableScoreIndex := 0
for _, tempUser := range WinPlayer {
if tempUser.TableScoreIndex != 0xFF && tempUser.TableScoreIndex < WinMaxTableScoreIndex {
continue
}
tempPlayer := rr.PlayerMap[tempUser.ChairId]
tempPlayer.WinLose = protocol.Win
if tempPlayer.GameState == 2 {
tempPlayer.EndScore = tempPlayer.WinTableScore
TotalBet -= tempPlayer.EndScore
} else {
tempPlayer.EndScore = TotalBet
WinMaxTableScoreIndex = tempUser.TableScoreIndex
for index, i2 := range RecordInfo.Player {
if i2.ChairID == tempUser.ChairId {
RecordInfo.Player[index].IsWin = true
break
}
}
if tempPlayer.GameState != 2 {
break
}
}
options, err := json.Marshal(RecordInfo)
if err != nil {
log.Debug("RecordInfo 序列化失败")
}
sArea = string(options)
log.Debug(" 桌子号", rr.RId, "分配好最后一个池子前 rr.TableScore = ", rr.TableScore)
// 如果最后一个池子还没人 需要计算最后一个池子都归谁
MostAllInScore := int64(0)
if len(rr.TableScore[len(rr.TableScore)-1].ChairID) == 0 {
// 先选出allin的最高的钱
for _, tempPlayer := range rr.PlayerMap {
if tempPlayer.CanBet && tempPlayer.GameState == 2 {
if tempPlayer.CellScore > MostAllInScore {
MostAllInScore = tempPlayer.CellScore
}
}
}
if MostAllInScore == 0 {
// 没有allin的人 池子属于所有没弃牌的人
for _, tempPlayer := range rr.PlayerMap {
if tempPlayer.CanBet && tempPlayer.GameState != 1 {
rr.TableScore[len(rr.TableScore)-1].ChairID = append(rr.TableScore[len(rr.TableScore)-1].ChairID, tempPlayer.ChairId)
}
}
} else {
// 有allin的人 池子属于所有超过最高allin且没弃牌的人
for _, tempPlayer := range rr.PlayerMap {
if tempPlayer.CanBet && tempPlayer.GameState != 1 && tempPlayer.CellScore > MostAllInScore {
rr.TableScore[len(rr.TableScore)-1].ChairID = append(rr.TableScore[len(rr.TableScore)-1].ChairID, tempPlayer.ChairId)
}
}
//如果没有玩家 说明剩下池子是弃牌玩家的 需要退给他们
if len(rr.TableScore[len(rr.TableScore)-1].ChairID) == 0 {
for _, tempPlayer := range rr.PlayerMap {
if tempPlayer.CanBet && tempPlayer.CellScore > MostAllInScore {
rr.TableScore[len(rr.TableScore)-1].ChairID = append(rr.TableScore[len(rr.TableScore)-1].ChairID, tempPlayer.ChairId)
}
}
}
}
}
log.Debug(" 桌子号", rr.RId, "分配好最后一个池子后 rr.TableScore = ", rr.TableScore)
for iIndex, tempTableScore := range rr.TableScore {
WinChairID := int32(0xFF)
for _, iChairID := range tempTableScore.ChairID {
if !rr.TableScore[iIndex].Used && rr.PlayerMap[iChairID].WinLose == protocol.Win {
tempWinEndScore := int64(0)
if iIndex == 0 {
tempWinEndScore = tempTableScore.Score
rr.TableScore[iIndex].Used = true
GameOver.TableScoreUser = append(GameOver.TableScoreUser, iChairID)
} else {
for i := 0; i <= iIndex; i++ {
if !rr.TableScore[i].Used {
tempWinEndScore += rr.TableScore[i].Score
rr.TableScore[i].Used = true
GameOver.TableScoreUser = append(GameOver.TableScoreUser, iChairID)
}
}
}
rr.PlayerMap[iChairID].EndScore = tempWinEndScore
WinChairID = iChairID
break
}
}
if WinChairID != 0xFF && rr.PlayerMap[WinChairID].GameState == 0 {
// 正常人赢了 就不用再分配了
for iIndex2, tempTableScore2 := range rr.TableScore {
if !rr.TableScore[iIndex2].Used {
rr.TableScore[iIndex2].Used = true
rr.PlayerMap[WinChairID].EndScore += tempTableScore2.Score
GameOver.TableScoreUser = append(GameOver.TableScoreUser, WinChairID)
}
}
}
}
// 如果还有池子没分出去 说明需要回退钱
for iIndex, tempTableScore := range rr.TableScore {
if !tempTableScore.Used {
for _, iChairID := range tempTableScore.ChairID {
if rr.TableScore[iIndex].Score >= rr.PlayerMap[iChairID].CellScore-MostAllInScore {
rr.PlayerMap[iChairID].EndScore += rr.PlayerMap[iChairID].CellScore - MostAllInScore
} else {
rr.PlayerMap[iChairID].EndScore = rr.TableScore[iIndex].Score
}
GameOver.TableScoreUser = append(GameOver.TableScoreUser, iChairID)
rr.TableScore[iIndex].Score -= rr.PlayerMap[iChairID].EndScore
}
rr.TableScore[iIndex].Used = true
}
}
for _, player := range rr.PlayerMap {
player.PlayWatchCount = 0
if !player.CanBet {
@ -375,18 +549,22 @@ func (rr *Room) OnEventGameConclude() { // 结束-结算
//记录输赢并写分
UserRealBet := player.CellScore // 计算打码量
WinBetScore := int64(0)
WinScore := int64(0)
WinScore := player.EndScore
if player.EndScore > 0 {
TempRateAfter := int64(float64(player.EndScore-player.CellScore) * (1 - rr.Opt.BrightRate))
TempRateAfter := int64(0)
if player.EndScore > player.CellScore {
TempRateAfter = int64(float64(player.EndScore-player.CellScore)*(1-rr.Opt.BrightRate)) + player.CellScore
} else {
TempRateAfter = player.EndScore
}
rr.UserScore[player.ChairId] = rr.UserScore[player.ChairId].Add(decimal.NewFromInt(TempRateAfter))
player.Gold = rr.UserScore[player.ChairId].Add(decimal.NewFromInt(TempRateAfter))
WinBetScore = player.CellScore
WinScore = player.EndScore - player.CellScore
player.EndScore = TempRateAfter + player.CellScore
player.TableScore += TempRateAfter
player.EndScore = TempRateAfter
}
if !player.IsRobot && (player.Ctx != nil) {
AfterGold, BloodPool, StockNum := rr.WriteUserScore(player, 2, player.CellScore, WinBetScore, WinScore, rr.ReasonString, sArea, sPlayers, UserRealBet)
AfterGold, BloodPool, StockNum := rr.WriteUserScore(player, 2, player.CellScore, WinBetScore, WinScore, rr.ReasonString, sArea, sPlayers, UserRealBet, TotalBet)
log.Debug("WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum, " GameID", rr.GameID, " RoomID", rr.RoomID)
rr.UserScore[player.ChairId] = decimal.NewFromInt(AfterGold)
player.Gold = decimal.NewFromInt(AfterGold)
@ -410,12 +588,27 @@ func (rr *Room) OnEventGameConclude() { // 结束-结算
TableSeat.CanBet = player.CanBet
TableSeat.BetType = player.BetType
TableSeat.WinLose = player.WinLose
TableSeat.TableScore = player.TableScore
for _, TempPoker := range player.HandPoker {
TableSeat.HandPoker = append(TableSeat.HandPoker, int32(TempPoker))
}
for _, poker := range player.BestKind {
TableSeat.BestPoker = append(TableSeat.BestPoker, int32(poker))
}
TableSeat.PokerType = int32(player.BestKind.GetCardType())
log.Debug(" player.ChairId ", player.ChairId, " HandPoker ", TableSeat.HandPoker)
for _, poker := range player.ThreeKind {
TableSeat.ThreePoker = append(TableSeat.ThreePoker, int32(poker))
}
TableSeat.ThreeKindType = int32(player.ThreeKind.GetCardType())
for _, poker := range player.FourKind {
TableSeat.FourPoker = append(TableSeat.FourPoker, int32(poker))
}
TableSeat.FourKindType = int32(player.FourKind.GetCardType())
TableSeat.GameState = player.GameState
log.Debug(" player.ChairId ", player.ChairId, " TableSeat ", TableSeat)
GameOver.PlayerList = append(GameOver.PlayerList, TableSeat)
}
@ -423,14 +616,30 @@ func (rr *Room) OnEventGameConclude() { // 结束-结算
player.PlayWatchCount++
}
//RoundTotalScore := int64(0)
//for index, _ := range rr.PlayerMap {
// RoundTotalScore += rr.PlayerMap[index].CellScore
//}
//GameOver.TableScore = RoundTotalScore
for _, tempTableScore := range rr.TableScore {
GameOver.TableScore = append(GameOver.TableScore, tempTableScore.Score)
}
for _, tempHandPoker := range rr.HandPoker {
GameOver.PokerList = append(GameOver.PokerList, int32(tempHandPoker))
}
rr.State = EN_TABLE_STATE_FINISH //结算状态
rr.SendAllMessage(route.NotifyGameConclude, GameOver)
log.Debug(rr.TimeOutFinalResult/1000+2, ":秒后开始下一局倒计时")
//0.复位房间一些相关数据
rr.RepeatRoom()
rr.RepeatRoomUser()
}
func (rr *Room) WriteUserScore(User *Player, BetType int32, BetGold int64, WinBetGold int64, WinGold int64, reason string, Area string, Players string, UserRealBet int64) (int64, float64, int64) {
func (rr *Room) WriteUserScore(User *Player, BetType int32, BetGold int64, WinBetGold int64, WinGold int64, reason string, Area string, Players string, UserRealBet int64, AllBetGold int64) (int64, float64, int64) {
currentDate := time.Now().Format("20060102")
roundNo := fmt.Sprintf(fmt.Sprintf("%s%s%s", currentDate, strconv.Itoa(int(rr.RoomID)), rpc_client.GenerateRoundNo()))
Req := writeUserScorepb.WriteUserScoreArgs{
@ -454,7 +663,7 @@ func (rr *Room) WriteUserScore(User *Player, BetType int32, BetGold int64, WinBe
StockThresholdValue: tools.Int64ToStr(rr.BoolePool.NowTurnPoint),
IsCtrl: User.IsCheat,
AssetKind: 1,
BetAmount: BetGold,
BetAmount: AllBetGold,
WinAmount: WinGold,
BeforeBalance: 0,
AfterBalance: 0,
@ -467,6 +676,8 @@ func (rr *Room) WriteUserScore(User *Player, BetType int32, BetGold int64, WinBe
Area: Area,
Players: Players,
UserRealBet: UserRealBet,
TableId: rr.RId,
RobotCount: int64(rr.GetRoomPlayerCount() - rr.GetRoomRealPlayerCount()),
}
if BetType == 3 {
Req.UserAmount = 0

40
game-server/game/DZ/app/core/game/game_player.go

@ -17,6 +17,7 @@ type Player struct {
AgentID int32 //代理ID
ChairId int32 //椅子号
IsRobot bool //是否是机器人
IsRobotNeedLeave bool //是否需要离开
Gold decimal.Decimal // 玩家金币
Diamond decimal.Decimal // 玩家钻石
Ticket decimal.Decimal // 玩家点券
@ -32,21 +33,26 @@ type Player struct {
CheatValue int64 //控制值[CheatValue这个是数据库取出来的,石总那边配置]
CurrCheatValue decimal.Decimal //当前控制值[CheatValue这个是数据库取出来的,石总那边配置,CurrCheatValue这个是每局输赢计算,游戏开始之前都要与CheatValue比较用于确定是否点控该玩家]
PlayCount int //在桌子上呆了几局
PlayWatchCount int //在桌子连续观战了几局
CellScore int64 // 底注
WinTableScore int64 // 赢了的分池
RoundScore int64 // 用户本轮下注
EndScore int64 // 本次结算分数
CanBet bool // 玩家是否需要等待下一局开始
WinLose int32 // 1赢 2输 3和
NeedWinLose int32 // 1赢 2输 3和
GameState int32 // 1 玩家已弃牌 2 玩家已Allin
BetType int32 // 1 小盲注 2 大盲注
HandPoker types.PokerSlice // 玩家手牌
AllKind []types.PokerSlice // 玩家手牌加公牌的所有组合
BestKind types.PokerSlice // 最佳组合手牌
ThreeKind types.PokerSlice // 三张公牌的组合牌
FourKind types.PokerSlice // 四张公牌的最佳组合牌
RobotWin bool // true 赢 false 输
PlayCount int //在桌子上呆了几局
PlayWatchCount int //在桌子连续观战了几局
AlwaysBet int64 //强制底注
CellScore int64 // 底注
WinTableScore int64 // 赢了的分池
RoundScore int64 // 用户本轮下注
EndScore int64 // 本次结算分数
CanBet bool // 玩家是否需要等待下一局开始
WinLose int32 // 1赢 2输 3和
NeedWinLose int32 // 1赢 2输 3和
GameState int32 // 1 玩家已弃牌 2 玩家已Allin
GameCurrenRoundState int32 // 1 跟注 2 加注 3 玩家已弃牌 4 玩家已Allin 5 过牌
BetType int32 // 1 小盲注 2 大盲注
HandPoker types.PokerSlice // 玩家手牌
AllKind []types.PokerSlice // 玩家手牌加公牌的所有组合
BestKind types.PokerSlice // 最佳组合手牌
ThreeKind types.PokerSlice // 三张公牌的组合牌
FourKind types.PokerSlice // 四张公牌的最佳组合牌
RobotWin bool // true 赢 false 输
TableScore int64 // 用户在桌子上的钱
UserNeedOut bool //退出状态
}

19
game-server/game/DZ/app/core/game/game_repeat_room.go

@ -10,12 +10,15 @@ func (rr *Room) RepeatRoom() {
rr.HandPoker = rr.HandPoker[:0]
rr.CurrGameRound = 0
rr.CellScore = 0
rr.TableScore = 0
rr.CanCheck = true
rr.TableScore = rr.TableScore[:0]
rr.TableCurrentScore = 0
rr.bUserAllIn = false
rr.RoundSubBet = false
rr.CanCheck = false //初始化第一轮不能过
rr.PokersCount = 0 //
rr.CurrOperationPlayer = 0xFF //
rr.CurrBanker = INVALID_VALUE //
rr.IsP2pControls = false //点控
//rr.CurrBanker = INVALID_VALUE //
rr.IsP2pControls = false //点控
// 重新获得血池 测试关闭
if rr.BoolePool.SetBoole(rr.RoomProxy, rr.Opt.BloodId) == false {
@ -26,7 +29,11 @@ func (rr *Room) RepeatRoom() {
func (rr *Room) RepeatRoomUser() { //复位玩家的数据
for index, _ := range rr.PlayerMap {
rr.PlayerMap[index].CanBet = true
if rr.PlayerMap[index].TableScore >= rr.Opt.MinTableTake {
rr.PlayerMap[index].CanBet = true
} else {
rr.PlayerMap[index].CanBet = false
}
rr.PlayerMap[index].WinLose = 0
rr.PlayerMap[index].NeedWinLose = 0
rr.PlayerMap[index].NeedWinLose = 0
@ -38,6 +45,7 @@ func (rr *Room) RepeatRoomUser() { //复位玩家的数据
rr.PlayerMap[index].CellScore = 0
rr.PlayerMap[index].WinTableScore = 0
rr.PlayerMap[index].RoundScore = 0
rr.PlayerMap[index].AlwaysBet = 0
rr.PlayerMap[index].BetType = 0
rr.PlayerMap[index].EndScore = 0
rr.PlayerMap[index].GameState = 0
@ -57,6 +65,7 @@ func (rr *Room) RepeatRoomUser() { //复位玩家的数据
rr.PlayerWatchMap[index].CellScore = 0
rr.PlayerWatchMap[index].WinTableScore = 0
rr.PlayerWatchMap[index].RoundScore = 0
rr.PlayerWatchMap[index].AlwaysBet = 0
rr.PlayerWatchMap[index].BetType = 0
rr.PlayerWatchMap[index].EndScore = 0
rr.PlayerWatchMap[index].GameState = 0

134
game-server/game/DZ/app/core/game/game_robot.go

@ -29,6 +29,7 @@ type RobotManager struct {
GronTimer *gron.Cron
Lock sync.RWMutex
GameRoom *Room
FirstEnterTimer int64 //首个机器人进入时间
NextEnterTimer int64 //下个机器人进入时间
FlushCountTimer int64 //下次刷新机器人数量的时间
MaxCount int //机器人数量
@ -81,8 +82,45 @@ func (r *RobotManager) OnInit(conf string, GameRoom *Room) {
nowUnixNano := time.Now().UnixNano()
nowMilliSeconds := nowUnixNano / 1e6
// 这里现在修改立马进入一个机器人
r.NextEnterTimer = nowMilliSeconds + 100
// 第一个进入的机器人 只判断一次
r.FirstEnterTimer = 0
if r.GameRoom.CreatorId != 0 {
FirstMinTime := r.GameRoom.TableConfig.FirstRobotCheckMinFrequency * 1000
FirstMaxTime := r.GameRoom.TableConfig.FirstRobotCheckMaxFrequency * 1000
if FirstMaxTime <= FirstMinTime {
r.FirstEnterTimer = nowMilliSeconds + FirstMaxTime
} else {
r.FirstEnterTimer = nowMilliSeconds + rand.Int63n(FirstMaxTime-FirstMinTime) + FirstMinTime
}
}
// 间隔多少时间正常进个机器人
MinInterTime := 0
MaxInterTime := 0
if r.GameRoom.TableConfig != nil {
MinInterTime = int(r.GameRoom.TableConfig.RobotCheckMinFrequency) * 1000
MaxInterTime = int(r.GameRoom.TableConfig.RobotCheckMaxFrequency) * 1000
log.Debug(" 后台配置 机器人进入频率 最小 ", MinInterTime, " 最大 ", MaxInterTime)
} else {
MinInterTime = r.GameRoom.BloodCtrl.AndroidOperateConfig.JoinHZ[0] * 1000
MaxInterTime = r.GameRoom.BloodCtrl.AndroidOperateConfig.JoinHZ[1] * 1000
}
rTime := int64(0)
if MaxInterTime <= MinInterTime {
rTime = int64(MinInterTime)
} else {
rTime = int64(rand.Intn(MaxInterTime-MinInterTime) + MinInterTime)
}
//处理个意外
if rTime == 0 {
rTime = 2000
log.Error(" 出现0了 是不行的 ", r.GameRoom.RoomID)
}
r.NextEnterTimer = nowMilliSeconds + rTime
//MinInterTime := GameRoom.BloodCtrl.AndroidOperateConfig.JoinHZ[0] * 1000
//MaxInterTime := GameRoom.BloodCtrl.AndroidOperateConfig.JoinHZ[1] * 1000
//rTime := int64(rand.Intn(MaxInterTime-MinInterTime) + MinInterTime)
@ -90,11 +128,21 @@ func (r *RobotManager) OnInit(conf string, GameRoom *Room) {
if GameRoom.TableConfig != nil {
r.MaxCount = 0
if GameRoom.TableConfig.ZeroMaxNum <= GameRoom.TableConfig.ZeroMinNum {
r.MaxCount = int(GameRoom.TableConfig.ZeroMinNum)
if GameRoom.TableConfig.TableType == 2 {
if GameRoom.TableConfig.OneMaxNum <= GameRoom.TableConfig.OneMinNum {
r.MaxCount = int(GameRoom.TableConfig.OneMinNum)
} else {
r.MaxCount = int(rand.Int63n(GameRoom.TableConfig.OneMaxNum-GameRoom.TableConfig.OneMinNum+1) + GameRoom.TableConfig.OneMinNum)
}
} else {
r.MaxCount = int(rand.Int63n(GameRoom.TableConfig.ZeroMaxNum-GameRoom.TableConfig.ZeroMinNum+1) + GameRoom.TableConfig.ZeroMinNum)
if GameRoom.TableConfig.ZeroMaxNum <= GameRoom.TableConfig.ZeroMinNum {
r.MaxCount = int(GameRoom.TableConfig.ZeroMinNum)
} else {
r.MaxCount = int(rand.Int63n(GameRoom.TableConfig.ZeroMaxNum-GameRoom.TableConfig.ZeroMinNum+1) + GameRoom.TableConfig.ZeroMinNum)
}
}
r.FlushCountTimer = nowMilliSeconds + GameRoom.TableConfig.CheckFrequency*1000
log.Debug("从后台配置 最大机器人数 ", r.MaxCount, " 刷新时间 ", GameRoom.TableConfig.CheckFrequency)
@ -168,17 +216,29 @@ func (r *RobotManager) RobotsEnterGameRoom() {
}
r.GameRoom.NotifyFunc(route.NotifyDTSitDown, NotifySitDown)
// 随机桌子上的钱
RoundScore := int64(0)
if r.GameRoom.Opt.MaxTableTake <= r.GameRoom.Opt.MinTableTake {
RoundScore = r.GameRoom.Opt.MinTableTake
} else {
RoundScore = r.GameRoom.Opt.MinTableTake + rand.Int63n(r.GameRoom.Opt.MaxTableTake-r.GameRoom.Opt.MinTableTake)
}
r.GameRoom.OnUserTableTake(pPlayer.Uid, &protocol.TableTakeReq{
Score: RoundScore,
})
//判断开场
if r.GameRoom.State < EN_TABLE_STATE_PLAYING && r.GameRoom.GetRoomPlayerCount() > 2 {
log.Debug(" 桌子号", r.GameRoom.RId, " 可以开场当前人数", r.GameRoom.GetRoomPlayerCount(), " 抢庄时间", r.GameRoom.TimeOutGetBanker)
if r.GameRoom.State < EN_TABLE_STATE_PLAYING && r.GameRoom.GetRoomCanPlayPlayerCount() > 2 {
log.Debug(" 桌子号", r.GameRoom.RId, " 可以开场当前人数", r.GameRoom.GetRoomCanPlayPlayerCount(), " 抢庄时间", r.GameRoom.TimeOutGetBanker)
r.GameRoom.State = EN_TABLE_STATE_PLAYING
milliseconds := time.Now().UnixMilli()
r.GameRoom.CurrentGameState = protocol.STATE_GET_BANKER
r.GameRoom.CurrentGameState = protocol.STATE_BEGIN
r.GameRoom.CurrentOperationTimer = milliseconds + r.GameRoom.TimeOutGetBanker
r.GameRoom.RepeatRoomUser()
r.GameRoom.SendAllMessage(route.NotifyStateTime, &protocol.NotifyStateTime{
NextState: protocol.STATE_GET_BANKER,
NextState: r.GameRoom.CurrentGameState,
NextTimestamp: r.GameRoom.CurrentOperationTimer,
})
// 抢庄做了加一秒的容错判断
@ -266,6 +326,53 @@ func (r *RobotManager) OnRobotMessage(msgId int32, player *Player, msg interface
return
}
if message.NextState == protocol.STATE_BEGIN {
//结束时候判断是否机器人要离开 如果人多了 或者桌子上钱太多了
if r.GameRoom.GetInRoomRobotCount() > int32(r.MaxCount) || player.TableScore > r.GameRoom.Opt.MaxTableTake*2 {
player.IsRobotNeedLeave = true
go func() {
time.Sleep(1500 * time.Millisecond)
r.GameRoom.OnGetOutRoom(player.Uid, 0)
log.Debug(r.GameRoom.RId, " 机器人 ", player.Uid, " 需要离开 当前机器人个数", r.GameRoom.GetInRoomRobotCount(), "需要的人数", r.MaxCount)
}()
} else {
// 不离开如果钱不够了 就要入金
if player.TableScore < r.GameRoom.Opt.MinTableTake {
go func() {
time.Sleep(1500 * time.Millisecond)
//log.Debug(" 桌子号", r.GameRoom.RId, " 机器人 ", player.Uid, " 要入金 TableScore", player.TableScore, " 最低带入 ", r.GameRoom.Opt.MinTableTake)
// 随机桌子上的钱
RoundScore := int64(0)
if r.GameRoom.Opt.MaxTableTake <= r.GameRoom.Opt.MinTableTake {
RoundScore = r.GameRoom.Opt.MinTableTake
} else {
tempMinTableTake := r.GameRoom.Opt.MinTableTake - player.TableScore
tempMaxTableTake := r.GameRoom.Opt.MaxTableTake - player.TableScore
RoundScore = tempMinTableTake + rand.Int63n(tempMaxTableTake-tempMinTableTake)
}
log.Debug(r.GameRoom.RId, " 机器人 ", player.Uid, " 桌子上钱不够了 入金", RoundScore)
r.GameRoom.OnUserTableTake(player.Uid, &protocol.TableTakeReq{
Score: RoundScore,
})
}()
}
MinGold := r.GameRoom.BloodCtrl.AndroidOperateConfig.InGold[r.GameRoom.RoomID][0]
MaxGold := r.GameRoom.BloodCtrl.AndroidOperateConfig.InGold[r.GameRoom.RoomID][1]
log.Debug(" 桌子号", r.GameRoom.RId, " 机器人 ", player.Uid, " 当前钱 ", player.Gold, " 最低 ", MinGold, " 最高 ", MaxGold)
if player.Gold.LessThan(decimal.NewFromInt(int64(MinGold))) {
gold := rand.Intn(MaxGold-MinGold) + MinGold
player.Gold = decimal.NewFromFloat(float64(gold))
log.Debug(" 桌子号", r.GameRoom.RId, " 机器人 ", player.Uid, " 钱不够最低了 ", MinGold, " 当前钱 ", player.Gold)
} else if decimal.NewFromInt(int64(MaxGold * 2)).LessThan(player.Gold) {
gold := rand.Intn(MaxGold-MinGold) + MinGold
player.Gold = decimal.NewFromFloat(float64(gold))
log.Debug(" 桌子号", r.GameRoom.RId, " 机器人 ", player.Uid, " 钱超过最高了 ", MaxGold, " 当前钱 ", player.Gold)
}
}
}
break
}
case route.NotifyWhoOperate: //
@ -357,15 +464,6 @@ func (r *RobotManager) OnRobotMessage(msgId int32, player *Player, msg interface
log.Debug("结算==>解析 NotifyGameConclude 结构体失败")
return
}
//结束时候判断是否机器人要离开
if r.GameRoom.GetInRoomRobotCount() > int32(r.MaxCount) {
go func() {
time.Sleep(1500 * time.Millisecond)
r.GameRoom.OnGetOutRoom(player.Uid, 0)
log.Debug(r.GameRoom.RId, " 机器人 ", player.Uid, " 需要离开 当前机器人个数", r.GameRoom.GetInRoomRobotCount(), "需要的人数", r.MaxCount)
}()
}
}
case route.LogoutTableRes:
if player == nil {

30
game-server/game/DZ/app/core/game/game_robot_timer.go

@ -16,8 +16,17 @@ func (r *RobotManager) KickRobotTimer() {
func (r *RobotManager) run() {
milliseconds := time.Now().UnixMilli()
if r.FirstEnterTimer != 0 && milliseconds >= r.FirstEnterTimer {
r.FirstEnterTimer = 0
if r.GameRoom.GetInRoomRobotCount() < int32(r.MaxCount) {
//r.Lock.Lock()
r.RobotsEnterGameRoom()
}
}
if milliseconds >= r.NextEnterTimer {
if r.GameRoom.CreatorId == 0 && r.GameRoom.GetInRoomRobotCount() < int32(r.MaxCount) {
//if r.GameRoom.CreatorId == 0 && r.GameRoom.GetInRoomRobotCount() < int32(r.MaxCount) {
if r.GameRoom.GetInRoomRobotCount() < int32(r.MaxCount) {
//r.Lock.Lock()
r.RobotsEnterGameRoom()
@ -200,14 +209,26 @@ func (r *RobotManager) run() {
}
// 先判断是不是要弃牌
var UserScore int64
if rand.Intn(10000) < CurrentDropPro {
CurrentOperate = protocol.OperateGaveUp
} else {
// 再判断是不是要加注 否则跟注
if r.GameRoom.BetCRF == 0 && rand.Intn(10000) < CurrentJiaPro {
CurrentOperate = protocol.OperateJia
if player.TableScore < r.GameRoom.CellScore-player.RoundScore {
CurrentOperate = protocol.OperateAll
} else {
CurrentOperate = protocol.OperateGen
if r.GameRoom.BetCRF == 0 && rand.Intn(10000) < CurrentJiaPro {
CurrentOperate = protocol.OperateJia
if r.GameRoom.CellScore > player.RoundScore {
UserScore = (player.TableScore-(r.GameRoom.CellScore-player.RoundScore))/2 + (r.GameRoom.CellScore - player.RoundScore)
} else if r.GameRoom.CellScore != 0 && player.TableScore > r.GameRoom.CellScore {
UserScore = r.GameRoom.CellScore
} else {
CurrentOperate = protocol.OperateGen
}
} else {
CurrentOperate = protocol.OperateGen
}
}
}
@ -217,6 +238,7 @@ func (r *RobotManager) run() {
// 操作阶段且 是 这个机器人操作
req := &protocol.OperateReq{
OperateCode: CurrentOperate,
UserScore: UserScore,
}
r.GameRoom.OnUserOperate(player.Uid, req)
} else {

53
game-server/game/DZ/app/core/game/game_select_banker.go

@ -3,7 +3,6 @@ package game
import (
"base/log"
"math/rand"
"strconv"
"xgame/game/DZ/app/core/protocol"
"xgame/game/DZ/app/route"
)
@ -13,24 +12,52 @@ func (rr *Room) OnGameSelectBanker() { // 定庄
var GetBankerList []int32
// 抢庄时候重置一下所有可下注的状态
var AllChairID []int32
for index, _ := range rr.PlayerMap {
rr.PlayerMap[index].CanBet = true
if rr.PlayerMap[index].TableScore >= rr.Opt.MinTableTake {
AllChairID = append(AllChairID, index)
rr.PlayerMap[index].CanBet = true
}
}
for _, player := range rr.PlayerMap {
GetBankerList = append(GetBankerList, player.ChairId)
}
NotifyCurrentBanker.ChairID = GetBankerList[rand.Intn(len(GetBankerList))]
NotifyCurrentBanker.CellScore = rr.Opt.MinBetAsset
rr.CurrBanker = NotifyCurrentBanker.ChairID
NotifyCurrentBanker.AllChairID = AllChairID
if rr.CurrBanker == INVALID_VALUE {
// 第一把随机庄
for _, player := range rr.PlayerMap {
GetBankerList = append(GetBankerList, player.ChairId)
}
NotifyCurrentBanker.ChairID = GetBankerList[rand.Intn(len(GetBankerList))]
NotifyCurrentBanker.CellScore = rr.Opt.MinBetAsset
NotifyCurrentBanker.Type = 0
rr.CurrBanker = NotifyCurrentBanker.ChairID
} else {
// 之后下一个座位庄
TempCurrentPlayer := rr.CurrBanker
for i := TempCurrentPlayer + 1; i < MAX_USER_NUM+TempCurrentPlayer; i++ {
TempChairID := i
if TempChairID >= MAX_USER_NUM {
TempChairID -= MAX_USER_NUM
}
CurrentGears := 0
TempRoomGears, err := strconv.Atoi(rr.BoolePool.RoomGears)
if err == nil {
CurrentGears = TempRoomGears
log.Debug(" 桌子号", rr.RId, "房间当前血池档位1 :", TempRoomGears, " CurrentGears :", CurrentGears)
if _, exist := rr.PlayerMap[TempChairID]; exist {
if rr.PlayerMap[TempChairID].CanBet && rr.PlayerMap[TempChairID].TableScore >= rr.Opt.MinTableTake && rr.PlayerMap[TempChairID].GameState == 0 {
NotifyCurrentBanker.ChairID = TempChairID
break
}
}
}
NotifyCurrentBanker.CellScore = rr.Opt.MinBetAsset
NotifyCurrentBanker.Type = 1
}
//CurrentGears := 0
//TempRoomGears, err := strconv.Atoi(rr.BoolePool.RoomGears)
//if err == nil {
// CurrentGears = TempRoomGears
// log.Debug(" 桌子号", rr.RId, "房间当前血池档位1 :", TempRoomGears, " CurrentGears :", CurrentGears)
//}
//// 测试真人当庄
//for _, tempChairID := range rr.GetBankerList {
// if !rr.PlayerMap[tempChairID].IsRobot {

236
game-server/game/DZ/app/core/game/game_start.go

@ -3,6 +3,7 @@ package game
import (
"base/log"
"github.com/shopspring/decimal"
"math/rand"
"time"
"xgame/game/DZ/app/core/protocol"
"xgame/game/DZ/app/route"
@ -15,6 +16,69 @@ func (rr *Room) GetRoomCreator() int64 {
// OnGameStart 开始游戏
func (rr *Room) OnGameStart() bool {
NotifyGameStart := &protocol.NotifyGameStart{}
var GetBankerList []int32
// 抢庄时候重置一下所有可下注的状态
var AllChairID []int32
for index, _ := range rr.PlayerMap {
if rr.PlayerMap[index].TableScore >= rr.Opt.MinTableTake {
AllChairID = append(AllChairID, index)
rr.PlayerMap[index].CanBet = true
}
}
NotifyGameStart.AllChairID = AllChairID
if rr.CurrBanker == INVALID_VALUE {
// 第一把随机庄
for _, player := range rr.PlayerMap {
GetBankerList = append(GetBankerList, player.ChairId)
}
NotifyGameStart.ChairID = GetBankerList[rand.Intn(len(GetBankerList))]
NotifyGameStart.Type = 0
} else {
// 之后下一个座位庄
TempCurrentPlayer := rr.CurrBanker
for i := TempCurrentPlayer + 1; i < MAX_USER_NUM+TempCurrentPlayer; i++ {
TempChairID := i
if TempChairID >= MAX_USER_NUM {
TempChairID -= MAX_USER_NUM
}
if _, exist := rr.PlayerMap[TempChairID]; exist {
if rr.PlayerMap[TempChairID].CanBet && rr.PlayerMap[TempChairID].TableScore >= rr.Opt.MinTableTake && rr.PlayerMap[TempChairID].GameState == 0 {
NotifyGameStart.ChairID = TempChairID
break
}
}
}
NotifyGameStart.Type = 1
}
//CurrentGears := 0
//TempRoomGears, err := strconv.Atoi(rr.BoolePool.RoomGears)
//if err == nil {
// CurrentGears = TempRoomGears
// log.Debug(" 桌子号", rr.RId, "房间当前血池档位1 :", TempRoomGears, " CurrentGears :", CurrentGears)
//}
//// 测试真人当庄
//for _, tempChairID := range rr.GetBankerList {
// if !rr.PlayerMap[tempChairID].IsRobot {
// NotifyCurrentBanker.ChairID = tempChairID
// break
// }
//}
rr.CurrBanker = NotifyGameStart.ChairID
rr.CurrEndUser = rr.CurrBanker
rr.CurrOperationPlayer = 0xFF
//rr.SendAllMessage(route.NotifyCurrentBanker, NotifyCurrentBanker)
log.Debug(" 桌子号", rr.RId, "确定庄家 :", rr.CurrBanker)
//// 洗牌
//rr.InitCardList(1)
//
@ -37,7 +101,7 @@ func (rr *Room) OnGameStart() bool {
p.IsCheat = false
playerControl := rpc_client.GetUserGameControl(p.Ctx, int64(rr.GameID), int64(rr.RoomID))
if playerControl != nil {
log.Debug("获取到的玩家点控 玩家 ", p.Uid, " 名字:", p.Nickname, " 点控", playerControl)
log.Debug(" 桌子号", rr.RId, "获取到的玩家点控 玩家 ", p.Uid, " 名字:", p.Nickname, " 点控", playerControl)
if playerControl.CheatType != 0 {
rr.isUserCtl = true
rr.UserCtlGear = playerControl.CheatType
@ -45,15 +109,68 @@ func (rr *Room) OnGameStart() bool {
p.CheatValue = playerControl.CheatValue
p.CheatType = playerControl.CheatType
p.CheatValueBefore = p.CheatValue
log.Debug("设置点控成功 点控类型 ", p.CheatType, " 点控值:", p.CheatValueBefore)
log.Debug(" 桌子号", rr.RId, "设置点控成功 点控类型 ", p.CheatType, " 点控值:", p.CheatValueBefore)
}
}
}
// 小盲和大盲下注
//// 小盲和大盲下注
//rr.CellScore = rr.Opt.MinBetAsset
//TempCurrentPlayer := rr.CurrBanker + 1
//CurrentIndex := int32(0)
//for i := TempCurrentPlayer; i < MAX_USER_NUM+TempCurrentPlayer; i++ {
// TempChairID := i
//
// if TempChairID >= MAX_USER_NUM {
// TempChairID -= MAX_USER_NUM
// }
//
// if _, exist := rr.PlayerMap[TempChairID]; exist {
// if rr.PlayerMap[TempChairID].CanBet && rr.PlayerMap[TempChairID].GameState == 0 {
// rr.CurrOperationPlayer = TempChairID
// CurrentIndex++
//
// if CurrentIndex == 1 {
// // 小盲
// rr.PlayerMap[TempChairID].BetType = CurrentIndex
// rr.PlayerMap[TempChairID].CellScore = rr.Opt.MinBetAsset / 2
// rr.PlayerMap[TempChairID].RoundScore += rr.PlayerMap[TempChairID].CellScore
//
// rr.UserScore[TempChairID] = rr.UserScore[TempChairID].Sub(decimal.NewFromInt(rr.Opt.MinBetAsset / 2))
// rr.PlayerMap[TempChairID].Gold = rr.PlayerMap[TempChairID].Gold.Sub(decimal.NewFromInt(rr.Opt.MinBetAsset / 2))
//
// if !rr.PlayerMap[TempChairID].IsRobot && (rr.PlayerMap[TempChairID].Ctx != nil) {
// AfterGold, BloodPool, StockNum := rr.WriteUserScore(rr.PlayerMap[TempChairID], 1, rr.Opt.MinBetAsset/2, 0, 0, rr.ReasonString, "", "", 0)
// log.Debug("开始游戏 下注 WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum)
// }
//
// } else if CurrentIndex == 2 {
// // 大盲
// rr.PlayerMap[TempChairID].BetType = CurrentIndex
// rr.PlayerMap[TempChairID].CellScore = rr.Opt.MinBetAsset
// rr.PlayerMap[TempChairID].RoundScore += rr.PlayerMap[TempChairID].CellScore
//
// rr.UserScore[TempChairID] = rr.UserScore[TempChairID].Sub(decimal.NewFromInt(rr.Opt.MinBetAsset))
// rr.PlayerMap[TempChairID].Gold = rr.PlayerMap[TempChairID].Gold.Sub(decimal.NewFromInt(rr.Opt.MinBetAsset))
//
// if !rr.PlayerMap[TempChairID].IsRobot && (rr.PlayerMap[TempChairID].Ctx != nil) {
// AfterGold, BloodPool, StockNum := rr.WriteUserScore(rr.PlayerMap[TempChairID], 1, rr.Opt.MinBetAsset, 0, 0, rr.ReasonString, "", "", 0)
// log.Debug("开始游戏 下注 WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum)
// }
//
// break
// }
// }
// }
//}
// 所有人下底注
rr.CellScore = rr.Opt.MinBetAsset
TempCurrentPlayer := rr.CurrBanker + 1
CurrentIndex := int32(0)
OneTableALLScore := int64(0)
var DXChairID []int32
rr.TableCurrentScore = 0
for i := TempCurrentPlayer; i < MAX_USER_NUM+TempCurrentPlayer; i++ {
TempChairID := i
@ -62,97 +179,98 @@ func (rr *Room) OnGameStart() bool {
}
if _, exist := rr.PlayerMap[TempChairID]; exist {
if rr.PlayerMap[TempChairID].CanBet && rr.PlayerMap[TempChairID].GameState == 0 {
if rr.PlayerMap[TempChairID].CanBet && rr.PlayerMap[TempChairID].TableScore >= rr.Opt.MinTableTake && rr.PlayerMap[TempChairID].GameState == 0 {
var OnePlayer protocol.GameStartPlayer
rr.CurrOperationPlayer = TempChairID
CurrentIndex++
OneTableALLScore += rr.Opt.AlwaysBet
if CurrentIndex == 1 {
// 小盲
DXChairID = append(DXChairID, TempChairID)
rr.PlayerMap[TempChairID].BetType = CurrentIndex
rr.PlayerMap[TempChairID].CellScore = rr.Opt.MinBetAsset / 2
rr.PlayerMap[TempChairID].RoundScore += rr.PlayerMap[TempChairID].CellScore
rr.UserScore[TempChairID] = rr.UserScore[TempChairID].Sub(decimal.NewFromInt(rr.Opt.MinBetAsset / 2))
rr.PlayerMap[TempChairID].Gold = rr.PlayerMap[TempChairID].Gold.Sub(decimal.NewFromInt(rr.Opt.MinBetAsset / 2))
if !rr.PlayerMap[TempChairID].IsRobot && (rr.PlayerMap[TempChairID].Ctx != nil) {
AfterGold, BloodPool, StockNum := rr.WriteUserScore(rr.PlayerMap[TempChairID], 1, rr.Opt.MinBetAsset/2, 0, 0, rr.ReasonString, "", "", 0)
log.Debug("开始游戏 下注 WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum)
}
} else if CurrentIndex == 2 {
// 大盲
DXChairID = append(DXChairID, TempChairID)
rr.PlayerMap[TempChairID].BetType = CurrentIndex
rr.PlayerMap[TempChairID].CellScore = rr.Opt.MinBetAsset
rr.PlayerMap[TempChairID].RoundScore += rr.PlayerMap[TempChairID].CellScore
} else {
rr.PlayerMap[TempChairID].CellScore = 0
}
rr.UserScore[TempChairID] = rr.UserScore[TempChairID].Sub(decimal.NewFromInt(rr.Opt.MinBetAsset))
rr.PlayerMap[TempChairID].Gold = rr.PlayerMap[TempChairID].Gold.Sub(decimal.NewFromInt(rr.Opt.MinBetAsset))
rr.PlayerMap[TempChairID].AlwaysBet = rr.Opt.AlwaysBet
rr.PlayerMap[TempChairID].RoundScore += rr.PlayerMap[TempChairID].CellScore
rr.PlayerMap[TempChairID].CellScore += rr.PlayerMap[TempChairID].AlwaysBet
if !rr.PlayerMap[TempChairID].IsRobot && (rr.PlayerMap[TempChairID].Ctx != nil) {
AfterGold, BloodPool, StockNum := rr.WriteUserScore(rr.PlayerMap[TempChairID], 1, rr.Opt.MinBetAsset, 0, 0, rr.ReasonString, "", "", 0)
log.Debug("开始游戏 下注 WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum)
}
rr.UserScore[TempChairID] = rr.UserScore[TempChairID].Sub(decimal.NewFromInt(rr.PlayerMap[TempChairID].RoundScore))
rr.PlayerMap[TempChairID].Gold = rr.PlayerMap[TempChairID].Gold.Sub(decimal.NewFromInt(rr.PlayerMap[TempChairID].RoundScore))
break
if !rr.PlayerMap[TempChairID].IsRobot && (rr.PlayerMap[TempChairID].Ctx != nil) {
AfterGold, BloodPool, StockNum := rr.WriteUserScore(rr.PlayerMap[TempChairID], 1, rr.PlayerMap[TempChairID].RoundScore, 0, 0, rr.ReasonString, "", "", 0, 0)
log.Debug(" 桌子号", rr.RId, "开始游戏 下注 WriteUserScore 后 AfterGold=", AfterGold, " BloodPool=", BloodPool, " StockNum=", StockNum)
}
rr.PlayerMap[TempChairID].TableScore -= rr.PlayerMap[TempChairID].RoundScore + rr.PlayerMap[TempChairID].AlwaysBet
rr.TableCurrentScore += rr.PlayerMap[TempChairID].RoundScore + rr.PlayerMap[TempChairID].AlwaysBet
OnePlayer.BetType = rr.PlayerMap[TempChairID].BetType
OnePlayer.ChairID = rr.PlayerMap[TempChairID].ChairId
OnePlayer.CellScore = rr.PlayerMap[TempChairID].RoundScore
OnePlayer.TableScore = rr.PlayerMap[TempChairID].TableScore
NotifyGameStart.PlayerList = append(NotifyGameStart.PlayerList, OnePlayer)
} else {
log.Debug(" 桌子号", rr.RId, "没参与游戏的人 ", TempChairID, " CanBet=", rr.PlayerMap[TempChairID].CanBet, " TableScore=", rr.PlayerMap[TempChairID].TableScore, " GameState=", rr.PlayerMap[TempChairID].GameState)
}
}
}
rr.OnBuildOtherResultPoker()
rr.TableScore = append(rr.TableScore, protocol.UserTableScore{Score: OneTableALLScore, Used: false})
for _, tempTableScore := range rr.TableScore {
NotifyGameStart.TableScore = append(NotifyGameStart.TableScore, tempTableScore.Score)
}
for _, tempPlayer := range rr.PlayerMap {
var UserPoker []int32
for _, tempPoker := range tempPlayer.HandPoker {
UserPoker = append(UserPoker, int32(tempPoker))
}
rr.Send(tempPlayer, route.NotifyGameStart, &protocol.NotifyGameStart{
BetType: tempPlayer.BetType,
CellScore: tempPlayer.CellScore,
HandPoker: UserPoker,
})
}
for _, tempPlayer := range rr.PlayerWatchMap {
rr.Send(tempPlayer, route.NotifyGameStart, &protocol.NotifyGameStart{})
}
// 1秒后发三张牌
go func() {
time.Sleep(1000 * time.Millisecond)
//发三张牌
var SendPoker []int32
for i := 0; i < 3; i++ {
SendPoker = append(SendPoker, int32(rr.HandPoker[i]))
for tempIndex, tempPlayerL := range NotifyGameStart.PlayerList {
NotifyGameStart.PlayerList[tempIndex].HandPoker = NotifyGameStart.PlayerList[tempIndex].HandPoker[:0]
if tempPlayerL.ChairID == tempPlayer.ChairId {
NotifyGameStart.PlayerList[tempIndex].HandPoker = UserPoker
}
}
NotifyPoker := &protocol.NotifyPoker{
Poker: SendPoker,
}
rr.SendAllMessage(route.NotifyPoker, NotifyPoker)
rr.Send(tempPlayer, route.NotifyGameStart, NotifyGameStart)
}
for _, tempPlayer := range rr.PlayerMap {
if tempPlayer.CanBet && tempPlayer.GameState != 1 {
NotifyPokerType := &protocol.NotifyPokerType{
PokerType: int32(tempPlayer.ThreeKind.GetCardType()),
}
for _, poker := range tempPlayer.ThreeKind {
NotifyPokerType.BestPoker = append(NotifyPokerType.BestPoker, int32(poker))
}
rr.Send(tempPlayer, route.NotifyPokerType, NotifyPokerType)
log.Debug("UID ", tempPlayer.Uid, " PokerType=", NotifyPokerType.PokerType, " tempPlayer.ThreeKind=", tempPlayer.ThreeKind)
}
}
for tempIndex, _ := range NotifyGameStart.PlayerList {
NotifyGameStart.PlayerList[tempIndex].HandPoker = NotifyGameStart.PlayerList[tempIndex].HandPoker[:0]
}
for _, tempPlayer := range rr.PlayerWatchMap {
rr.Send(tempPlayer, route.NotifyGameStart, NotifyGameStart)
}
// 1秒后开始第一个人操作
if rr.PlayerMap[rr.CurrBanker].IsRobot {
// 2秒后开始第一个人操作
go func() {
rr.CurrOperationPlayer = rr.CurrBanker
time.Sleep(2000 * time.Millisecond)
time.Sleep(5000 * time.Millisecond)
rr.NextPLayer()
}()
}()
} else {
//// 1秒后开始第一个人操作
//go func() {
rr.CurrOperationPlayer = rr.CurrBanker
//time.Sleep(2000 * time.Millisecond)
rr.NextPLayer()
//}()
}
return true
}

6
game-server/game/DZ/app/core/game/game_table_take.go

@ -21,7 +21,7 @@ func (rr *Room) OnUserTableTake(uid int64, msg interface{}) { // 带入金币
}
if ChairId == -1 {
log.Debug(" 桌子号", rr.RId, " ChairId == -1")
log.Debug(" 桌子号", rr.RId, " OnUserTableTake uid= ", uid, " ChairId == -1")
return
}
@ -67,14 +67,14 @@ func (rr *Room) OnUserTableTake(uid int64, msg interface{}) { // 带入金币
if rr.State < EN_TABLE_STATE_PLAYING && rr.GetRoomCanPlayPlayerCount() > 2 {
rr.State = EN_TABLE_STATE_PLAYING
milliseconds := time.Now().UnixMilli()
rr.CurrentGameState = protocol.STATE_GET_BANKER
rr.CurrentGameState = protocol.STATE_BEGIN
rr.CurrentOperationTimer = milliseconds + rr.TimeOutGetBanker
rr.RepeatRoomUser()
log.Debug(" 桌子号", rr.RId, " 开始游戏 抢庄倒计时 ", rr.TimeOutGetBanker)
rr.SendAllMessage(route.NotifyStateTime, &protocol.NotifyStateTime{
NextState: protocol.STATE_GET_BANKER,
NextState: rr.CurrentGameState,
NextTimestamp: rr.CurrentOperationTimer,
})
// 抢庄做了加一秒的容错判断

18
game-server/game/DZ/app/core/game/game_watch.go

@ -43,7 +43,7 @@ func (rr *Room) OnUserWatchToDown(uid int64, msg interface{}) { // 主动观战
//临时修改为找一个空位
TempChairId := rr.MakeChairId()
if TempChairId == -1 {
log.Debug("没有空座位")
log.Debug(" 桌子号", rr.RId, "没有空座位")
WatchToDownRes.Code = protocol.ErrorWatchToDownPlayerExist
WatchToDownRes.CodeMsg = "没有空座位"
rr.Send(WToDUser, route.WatchToDownRes, WatchToDownRes)
@ -55,8 +55,9 @@ func (rr *Room) OnUserWatchToDown(uid int64, msg interface{}) { // 主动观战
for TempIndex, TempWatchPlayer := range rr.PlayerWatchMap {
if TempWatchPlayer.Uid == uid {
//判断钱是否够
if TempWatchPlayer.Gold.IntPart() <= MIN_GAME_SCORE {
log.Debug("玩家", uid, "钱不够 不能坐下 ", TempWatchPlayer.Gold.IntPart(), " 需要的钱:", MIN_GAME_SCORE)
//if TempWatchPlayer.Gold.IntPart() <= MIN_GAME_SCORE {
if TempWatchPlayer.Gold.LessThan(rr.RoomLimit) {
log.Debug(" 桌子号", rr.RId, "玩家", uid, "钱不够 不能坐下 ", TempWatchPlayer.Gold.IntPart(), " 需要的钱:", MIN_GAME_SCORE)
WatchToDownRes.Code = protocol.ErrorWatchToDownGoldLess
WatchToDownRes.CodeMsg = "钱不够 不能坐下"
rr.Send(TempWatchPlayer, route.WatchToDownRes, WatchToDownRes)
@ -65,10 +66,11 @@ func (rr *Room) OnUserWatchToDown(uid int64, msg interface{}) { // 主动观战
WatchUser := rr.PlayerWatchMap[TempIndex]
WatchUser.ChairId = message.ChairID
rr.NeedOutPlayer[TempWatchPlayer.ChairId] = time.Now().UnixMilli() + 60*1000
rr.SendAllMessage(route.NotifyWatchToDown, &protocol.NotifyWatchToDown{
Uid: WatchUser.Uid,
ChairID: message.ChairID,
NextTimestamp: time.Now().UnixMilli(),
NextTimestamp: rr.NeedOutPlayer[TempWatchPlayer.ChairId],
})
// 通知大厅有人坐下
@ -98,14 +100,14 @@ func (rr *Room) OnUserWatchToDown(uid int64, msg interface{}) { // 主动观战
if rr.State < EN_TABLE_STATE_PLAYING && rr.GetRoomPlayerCount() > 2 {
rr.State = EN_TABLE_STATE_PLAYING
milliseconds := time.Now().UnixMilli()
rr.CurrentGameState = protocol.STATE_GET_BANKER
rr.CurrentOperationTimer = milliseconds + rr.TimeOutGetBanker
rr.CurrentGameState = protocol.STATE_BEGIN
rr.CurrentOperationTimer = milliseconds + rr.TimeOutBegin
rr.RepeatRoomUser()
log.Debug(" 桌子号", rr.RId, " 开始游戏 抢庄倒计时 ", rr.TimeOutGetBanker)
log.Debug(" 桌子号", rr.RId, " 开始游戏 倒计时 ", rr.TimeOutBegin)
rr.SendAllMessage(route.NotifyStateTime, &protocol.NotifyStateTime{
NextState: protocol.STATE_GET_BANKER,
NextState: rr.CurrentGameState,
NextTimestamp: rr.CurrentOperationTimer,
})
// 抢庄做了加一秒的容错判断

61
game-server/game/DZ/app/core/protocol/protocol_msg.go

@ -48,10 +48,11 @@ type RoomInfoRes struct {
PlayerWatchMap []*RoomPlayer `json:"playerWatchMap,omitempty"` //观战用户列表
RoomStatus int32 `json:"roomStatus"` //房间的状态
CurrentOperateUser int32 `json:"currentOperateUser"` //当前操作用户
Type int32 `json:"type"` // 0第一轮 2 3 4 All 1 正常 1/3 1/2 2/3 1
BetCRF []int32 `json:"betCRF,omitempty"` // 1 跟注 2 加注 3 弃牌 4 AllIn
CellScore []int64 `json:"cellScore,omitempty"` // 跟注 加注
Poker []int32 `json:"poker"` //桌子上当前的扑克
TableScore int64 `json:"tableScore"` //桌子上总的钱
TableScore []int64 `json:"tableScore,omitempty"` //桌子上总的钱
StatusChangeTimestamp int64 `json:"statusChangeTimestamp"` //下一次变更状态的时间戳
}
@ -63,6 +64,7 @@ type ResumeGameNotice struct {
type OperateReq struct { //操作请求
OperateCode int32 `json:"operateCode"` //操作码
UserScore int64 `json:"userScore"` //操作的钱
}
type OperateRes struct { //操作返回
@ -72,6 +74,7 @@ type OperateRes struct { //操作返回
UserScore int64 `json:"userScore"` //操作的钱
RoundScore int64 `json:"roundScore"` //当轮的钱
CellScore int64 `json:"chipScore"` //用户当前下注
TableScore int64 `json:"tableScore"` // 用户在桌子上的钱
}
type NotifyOperate struct { //通知操作
@ -80,6 +83,7 @@ type NotifyOperate struct { //通知操作
UserScore int64 `json:"userScore"` //操作的钱
RoundScore int64 `json:"roundScore"` //当轮的钱
CellScore int64 `json:"chipScore"` //用户当前下注
TableScore int64 `json:"tableScore"` // 用户在桌子上的钱
}
type NotifyRoomDestroy struct { // 通知房间销毁
@ -105,14 +109,26 @@ type WatchToDownRes struct { //主动观战转坐下返回
}
type NotifyCurrentBanker struct { // 通知庄家
ChairID int32 `json:"chairId"` // 座位ID
CellScore int64 `json:"cellScore"` // 底注 小盲注扣一半 大盲注正常扣 其它玩家不扣
Type int32 `json:"type"` // 庄家类型 0随机 1下一家
ChairID int32 `json:"chairId"` // 座位ID
AllChairID []int32 `json:"allChairID"` // 所有参与本局游戏的玩家的座位号
CellScore int64 `json:"cellScore"` // 底注 小盲注扣一半 大盲注正常扣 其它玩家不扣
}
type GameStartPlayer struct {
ChairID int32 `json:"chairId"` // 座位号
CellScore int64 `json:"chipScore"` // 用户当前下注 不包含底注
BetType int32 `json:"betType"` // 1 小盲注 2 大盲注
HandPoker []int32 `json:"handPoker,omitempty"` // 用户当前手牌
TableScore int64 `json:"tableScore"` // 用户在桌子上的钱
}
type NotifyGameStart struct { // 通知开始游戏的第一轮数据
BetType int32 `json:"betType"` // 1 小盲注 2 大盲注
CellScore int64 `json:"cellScore"` // 下注金币
HandPoker []int32 `json:"handPoker,omitempty"` // 用户当前手牌
Type int32 `json:"type"` // 庄家类型 0随机 1下一家
ChairID int32 `json:"chairId"` // 庄家座位ID
AllChairID []int32 `json:"allChairID"` // 所有参与本局游戏的玩家的座位号
TableScore []int64 `json:"tableScore,omitempty"` // 桌子上总的钱
PlayerList []GameStartPlayer `json:"playerList,omitempty"` //用户列表
}
type NotifyLeaveRoomRes struct { // 通知退出桌子
@ -127,8 +143,8 @@ type NotifyStateTime struct { // 通知阶段倒计时
}
type NotifyPoker struct { // 通知翻牌
Poker []int32 `json:"poker"` // 扑克
TableScore int64 `json:"tableScore"` // 桌子上总的钱
Poker []int32 `json:"poker,omitempty"` // 扑克
TableScore []int64 `json:"tableScore,omitempty"` // 桌子上总的钱
}
type NotifyPokerType struct { // 通知牌类型
@ -138,6 +154,7 @@ type NotifyPokerType struct { // 通知牌类型
type NotifyWhoOperate struct { // 通知到谁操作
ChairID int32 `json:"chairId"` // 椅子号
Type int32 `json:"type"` // 0第一轮 2 3 4 All 1 正常 1/3 1/2 2/3 1
BetCRF []int32 `json:"betCRF,omitempty"` // 1 跟注 2 加注 3 弃牌 4 AllIn
CellScore []int64 `json:"cellScore,omitempty"` // 跟注 加注
NextTimestamp int64 `json:"nextTimestamp"` // 可操作时间
@ -149,7 +166,11 @@ type NotifyUserOutGameConclude struct { // 通知游戏逃跑结算
}
type NotifyGameConclude struct { // 通知游戏结束结算
PlayerList []*RoomPlayer `json:"playerList,omitempty"` //结算用户信息
EndType int32 `json:"endType"` // 结束类型 0 正常结束 1开牌结束 2不开牌结束
PlayerList []*RoomPlayer `json:"playerList,omitempty"` // 结算用户信息
TableScore []int64 `json:"tableScore,omitempty"` // 桌子上总的钱
TableScoreUser []int32 `json:"tableScoreUser" ` // 池子第几个池子被谁赢走了
PokerList []int32 `json:"pokerList,omitempty"` // 扑克列表
}
type NotifyDownToWatch struct { // 通知玩家坐下转观战
@ -225,9 +246,31 @@ type RecordInfoPlayer struct { // 存储的结构显示
HandPoker []int32 `json:"handPoker,omitempty"` // 用户当前手牌
BestPoker []int32 `json:"bestPoker,omitempty"` // 最佳排列
PokerType int32 `json:"pokerType" ` // 牌类型
IsWin bool `json:"isWin"`
}
type RecordInfo struct { // 存储的结构显示
TableHandPoker []int32 `json:"tableHandPoker,omitempty"` // 公牌
Player []RecordInfoPlayer `json:"player,omitempty"` // 单独用户信息
}
type TableTakeReq struct { //带入金币
Score int64 `json:"score"` //带入多少金币
}
type TableTakeRes struct { //带入金币返回
Code int32 `json:"code"` //错误码
CodeMsg string `json:"codeMsg"` //错误内容
}
type NotifyNeedTableTake struct { // 通知需要带入金币
ChairID int32 `json:"chairId"` //座位ID
MinTableTake int64 `json:"minTableTake"` // 最低带入金币
MaxTableTake int64 `json:"maxTableTake"` // 最高带入金币
NextTimestamp int64 `json:"nextTimestamp"` // 可操作时间
}
type NotifyTableTake struct { // 通知带入金币
ChairID int32 `json:"chairId"` //座位ID
Score int64 `json:"score"` //带入多少金币
}

82
game-server/game/DZ/app/core/protocol/protocol_struct.go

@ -1,16 +1,19 @@
package protocol
const (
ErrorCodeLessThanMinEnter = 20010001 //低于最小进入条件
ErrorCodeGameNoStart = 20010002 //游戏未开启
ErrorCodeOperateError = 20010003 //操作失败
ErrorWatchToDownGoldLess = 20010004 //观战转坐下 钱不够
ErrorWatchToDownNoExist = 20010005 //观战转坐下 座位不存在
ErrorWatchToDownPlayerExist = 20010006 //观战转坐下 座位已经有人
ErrorIsPlaying = 20010007 //游戏过程中不能离开房间
ErrorKickUserOFFLine = 20010008 //用户离开-离线
ErrorKickUserDestroyTable = 20010009 //用户离开-解散桌子
ErrorKickUserWatchingTimes = 20010010 //用户离开-观战次数过多
ErrorCodeLessThanMinEnter = 20010001 //低于最小进入条件
ErrorCodeGameNoStart = 20010002 //游戏未开启
ErrorCodeOperateError = 20010003 //操作失败
ErrorWatchToDownGoldLess = 20010004 //观战转坐下 钱不够
ErrorWatchToDownNoExist = 20010005 //观战转坐下 座位不存在
ErrorWatchToDownPlayerExist = 20010006 //观战转坐下 座位已经有人
ErrorIsPlaying = 20010007 //游戏过程中不能离开房间
ErrorKickUserOFFLine = 20010008 //用户离开-离线
ErrorKickUserDestroyTable = 20010009 //用户离开-解散桌子
ErrorKickUserWatchingTimes = 20010010 //用户离开-观战次数过多
ErrorTableTakeNotEnoughScore = 20010011 //带入金币-超过自身持有金币
ErrorTableTakeNotLimitScore = 20010012 //带入金币-不符合带入限制
ErrorNeedLeaveKickUser = 20010013 //标记了离开 结束正常离开
)
const (
@ -19,6 +22,7 @@ const (
OperateGaveUp = 3 //弃牌
OperateAll = 4 //AllIn
OperateCheck = 5 //过牌
OperateBet = 6 //下注
)
const (
@ -41,27 +45,34 @@ const (
)
type RoomPlayer struct { //房间的用户信息
Uid int64 `json:"uid"` // userId
ChairID int32 `json:"chairId"` // 座位号
IsBanker int32 `json:"isBanker"` // 0 非庄 1 庄
State int32 `json:"state"` // 状态
Avatar string `json:"avatar"` // 玩家头像
Gold int64 `json:"gold"` // 玩家金币
Nickname string `json:"nickname"` // 姓名
Sex int32 `json:"sex"` // 性别
Vip int32 `json:"vip"` // VIP
Level int32 `json:"level"` // 等级
Exp int32 `json:"exp"` // 经验
CellScore int64 `json:"chipScore"` // 用户当前下注
RoundScore int64 `json:"roundScore"` // 用户本轮下注
EndScore int64 `json:"endScore"` // 本次结算分数(这个只有赢的值 如果需要总值 要减去CellScore 和 BXScore)
WinLose int32 `json:"winLose"` // 本轮输赢 0 无效 1 赢 2 输 3 和
CanBet bool `json:"canBet"` // 玩家是否需要等待下一局开始
BetType int32 `json:"betType"` // 1 小盲注 2 大盲注
GameState int32 `json:"gameState"` // 1 玩家已弃牌 2 玩家已Allin
HandPoker []int32 `json:"handPoker,omitempty"` // 用户当前手牌
PokerType int32 `json:"pokerType" ` // 牌类型
BestPoker []int32 `json:"bestPoker,omitempty"` // 最佳排列
Uid int64 `json:"uid"` // userId
ChairID int32 `json:"chairId"` // 座位号
IsBanker int32 `json:"isBanker"` // 0 非庄 1 庄
State int32 `json:"state"` // 状态
Avatar string `json:"avatar"` // 玩家头像
Gold int64 `json:"gold"` // 玩家金币
Nickname string `json:"nickname"` // 姓名
Sex int32 `json:"sex"` // 性别
Vip int32 `json:"vip"` // VIP
Level int32 `json:"level"` // 等级
Exp int32 `json:"exp"` // 经验
CellScore int64 `json:"chipScore"` // 用户当前下注
RoundScore int64 `json:"roundScore"` // 用户本轮下注
EndScore int64 `json:"endScore"` // 本次结算分数(这个只有赢的值 如果需要总值 要减去CellScore 和 BXScore)
WinLose int32 `json:"winLose"` // 本轮输赢 0 无效 1 赢 2 输 3 和
CanBet bool `json:"canBet"` // 玩家是否需要等待下一局开始
BetType int32 `json:"betType"` // 1 小盲注 2 大盲注
GameState int32 `json:"gameState"` // 1 玩家已弃牌 2 玩家已Allin
GameCurrenRoundState int32 `json:"gameCurrenRoundState"` // 1 跟注 2 加注 3 玩家已弃牌 4 玩家已Allin 5 过牌
HandPoker []int32 `json:"handPoker,omitempty"` // 用户当前手牌
ThreeKindType int32 `json:"threeKindType" ` // 三张公牌的牌类型
ThreePoker []int32 `json:"threePoker,omitempty"` // 三张公牌的组合牌
FourKindType int32 `json:"fourKindType" ` // 四张公牌的牌类型
FourPoker []int32 `json:"fourPoker,omitempty"` // 四张公牌的最佳组合牌
PokerType int32 `json:"pokerType" ` // 牌类型
BestPoker []int32 `json:"bestPoker,omitempty"` // 最佳排列
TableScore int64 `json:"tableScore"` // 用户在桌子上的钱
NextTimestamp int64 `json:"nextTimestamp"` // 可操作时间 用于倒计时带入金币
}
type TablePlayer struct { //桌子的用户信息
@ -82,7 +93,10 @@ const (
type TableConfig struct { // 桌子配置
RechargeLimit int64 `json:"rechargeLimit"` // 弹充值限制
CellScore int64 `json:"cellScore"` // 房间底注
AlwaysBet int64 `json:"alwaysBet"` // 强制下注
TaxMing float64 `json:"taxMing"` // 明税
MinTableTake int64 `json:"minTableTake"` // 最低带入金币
MaxTableTake int64 `json:"maxTableTake"` // 最高带入金币
}
type TableInfo struct { // 桌子信息
@ -93,3 +107,9 @@ type TableInfo struct { // 桌子信息
State int32 `json:"state"` // 房间状态 STATE_
TablePlayer []TablePlayer `json:"playerList"` // 桌子上的用户信息
}
type UserTableScore struct {
ChairID []int32 `json:"chairID,omitempty"` //椅子号
Score int64 `json:"score"` //分数
Used bool `json:"used"` //true 就是分配出去了
}

2
game-server/game/DZ/app/core/room/base.go

@ -29,6 +29,7 @@ type HomeBase interface {
GetRoomCreator() int64 // 获取房主
IsCanDissolution() bool // 是否能解散房间
UpdateCtx(uid int64, ctx *node.Context) // 无奈加的,更新node.Context
UpdateUserOut(uid int64) // 更新用户退出状态
OnUserOperate(uid int64, msg interface{}) // 用户操作
OnUserWatchToDown(uid int64, msg interface{}) // 用户观战转坐下
OnResumeGameData(uid int64) //
@ -36,6 +37,7 @@ type HomeBase interface {
OnGetRoomInfo(uid int64, ctx *node.Context) interface{} //
IsJoinRoom() bool //
OnUpdateGold(userId int64) // 更新用户的钱
OnUserTableTake(uid int64, msg interface{}) // 带入金币
}
var (

6
game-server/game/DZ/app/core/room/roommgr.go

@ -88,12 +88,12 @@ func (h *Home) InitBloodControl() {
func (h *Home) InitBloodControlByBackend() {
// 按等级从后台获取到配置
var replyOpt *gamepb.FetchGameTableTotalsReply
replyOpt = rpc_client.GetTableCtrlConfig(h.GameProxy, game.GAME_ID, "")
replyOpt = rpc_client.GetTableCtrlConfig(h.GameProxy, game.GAME_ID, "", 1)
h.TableConfig = replyOpt.List
if len(h.TableConfig) == 0 {
log.Error(game.GAME_ID, " 21点后台获取桌子配置 无配置")
log.Error(game.GAME_ID, " 德州后台获取桌子配置 无配置")
} else {
log.Debug(" 21点获取后台桌子配置 ", h.TableConfig)
log.Debug(" 德州获取后台桌子配置 ", h.TableConfig)
}
}

54
game-server/game/DZ/app/core/types/poker.go

@ -36,17 +36,40 @@ var OnePokers = [52]Poker{
// 95 111 小大 王
}
//var AllKindIndex = [][]int{
// {0, 1, 2},
// {0, 1, 3},
// {0, 2, 3},
// {1, 2, 3},
// {0, 1, 4},
// {0, 2, 4},
// {0, 3, 4},
// {1, 2, 4},
// {1, 3, 4},
// {2, 3, 4},
//}
var AllKindIndex = [][]int{
{0, 1, 2},
{0, 1, 3},
{0, 2, 3},
{1, 2, 3},
{0, 1, 4},
{0, 2, 4},
{0, 3, 4},
{1, 2, 4},
{1, 3, 4},
{2, 3, 4},
{0, 1, 2, 3, 4},
{0, 1, 2, 3, 5},
{0, 1, 2, 4, 5},
{0, 1, 3, 4, 5},
{0, 2, 3, 4, 5},
{1, 2, 3, 4, 5},
{0, 1, 2, 3, 6},
{0, 1, 2, 4, 6},
{0, 1, 2, 5, 6},
{0, 1, 3, 4, 6},
{0, 1, 3, 5, 6},
{0, 1, 4, 5, 6},
{0, 2, 3, 4, 6},
{0, 2, 3, 5, 6},
{0, 2, 4, 5, 6},
{0, 3, 4, 5, 6},
{1, 2, 3, 4, 6},
{1, 2, 3, 5, 6},
{1, 3, 4, 5, 6},
{2, 3, 4, 5, 6},
}
// Point 点数
@ -84,6 +107,11 @@ func (p Poker) Point() Point {
}
}
// Point 获取点数
func (p Poker) RealPoint() Point {
return Point(p & 0x0F)
}
// IsValidValue 判断是否是有效值
func (p Poker) IsValidValue() bool {
for _, poker := range OnePokers {
@ -375,8 +403,8 @@ func isStraight(pokers []Poker, WildJokerCard Poker) bool {
wildCount := 0
ranks := make([]int, 0)
for _, p := range pokers {
if p.Point() != WildJokerCard.Point() && !p.IsJoker() {
ranks = append(ranks, int(p.Point()))
if p.RealPoint() != WildJokerCard.RealPoint() && !p.IsJoker() {
ranks = append(ranks, int(p.RealPoint()))
} else {
wildCount++
}
@ -390,7 +418,7 @@ func isStraight(pokers []Poker, WildJokerCard Poker) bool {
}
// 判断A如果不是百搭也不足以当最小就放到最后
if WildJokerCard.Point() != 1 && ranks[0] == 1 {
if WildJokerCard.RealPoint() != 1 && ranks[0] == 1 {
if ranks[1] > ranks[0] && ranks[1]-ranks[0]-1 > wildCount {
// 删除第一位元素,使用切片的切片语法
ranks = ranks[1:]

28
game-server/game/DZ/app/gamemanage/gamemanage.go

@ -9,6 +9,7 @@ import (
"xgame/game/DZ/app/core/protocol"
"xgame/game/DZ/app/core/room"
"xgame/game/DZ/app/route"
"xgame/internal/code"
accountservice "xgame/internal/service/account"
accountpb "xgame/internal/service/account/pb"
assetservice "xgame/internal/service/asset"
@ -337,7 +338,7 @@ func LogoutTable(ctx *node.Context) { // 用户退出游戏请求
if RoomInfo != nil && TempPlayer.CanBet && (RoomInfo.CurrentGameState == protocol.STATE_INVALUE || (RoomInfo.CurrentGameState > protocol.STATE_GET_BANKER && RoomInfo.CurrentGameState != protocol.STATE_RESULT)) {
log.Debug("LogoutTable 游戏过程中不能离开房间 ", " Request", ctx.Request)
LeaveTableRes := &protocol.LeaveTableRes{
Code: protocol.ErrorIsPlaying,
Code: code.ErrorWaitGameEndOut.Code(),
CodeMsg: "游戏过程中不能离开房间",
}
@ -345,6 +346,8 @@ func LogoutTable(ctx *node.Context) { // 用户退出游戏请求
if err := Ctx.Response(LeaveTableRes); err != nil {
log.Debugf("游戏过程中不能离开房间出错了: %v", err)
}
RoomInfo.UpdateUserOut(Ctx.Request.UID)
return
}
@ -395,3 +398,26 @@ func AllTable(ctx *node.Context) { // 用户下注
}
})
}
func TableTake(ctx *node.Context) { // 用户带入金币
Ctx := ctx.Clone()
task.AddTask(func() {
r := room.Gh.GetRoomObject(Ctx.Request.UID)
if r == nil {
log.Error("StrokeCard==>>>>>>,不在该房间")
return
}
req := &protocol.TableTakeReq{}
if err := Ctx.Request.Parse(req); err != nil {
log.Errorf("Parse TableTake failed. %v", err)
return
}
log.Debug("UpdateCtx TableTake ", Ctx.Request.UID, " UserId", ctx.Request.UserId, " UID", ctx.Request.UID, " Request", ctx.Request)
r.UpdateCtx(Ctx.Request.UID, Ctx)
r.OnUserTableTake(Ctx.Request.UID, req)
})
}

6
game-server/game/DZ/app/route/route.go

@ -8,6 +8,7 @@ const (
AllTable int32 = 2001004 // 获取所有桌子
JoinTable int32 = 2001005 // 加入桌子
WatchToDown int32 = 2001006 // 主动观战转坐下
TableTake int32 = 2001007 // 带入金币
// 服务端返回
OperateRes int32 = 2001011 // 操作返回
@ -16,6 +17,7 @@ const (
RoomInfoRes int32 = 2001014 // 房间的信息返回
AllTableInfoRes int32 = 2001015 // 所有桌子的信息返回
WatchToDownRes int32 = 2001016 // 主动观战转坐下返回
TableTakeRes int32 = 2001017 // 带入金币返回
// 服务端通知
NotifyPokerType int32 = 2001020 // 通知牌类型
@ -35,5 +37,7 @@ const (
NotifyDownToWatch int32 = 2001033 // 通知玩家坐下转观战
NotifyRoomDestroy int32 = 2001034 // 通知房间销毁
NotifyWhoOperate int32 = 2001037 // 通知到谁操作
NotifyWhoOperate int32 = 2001037 // 通知到谁操作
NotifyWhoTableTake int32 = 2001038 // 通知谁带入了金币
NotifyNeedTake int32 = 2001039 // 通知钱不够需要入金
)

80
game-server/game/DZ/config/blood.json

@ -10,6 +10,8 @@
{
"GearIDComment": "GearID 【输 3000档】",
"GearID": 3000,
"CommentChipPro": "机器人下注的概率",
"ChipPro": [4000,2000,2000,1000,1000],
"WinProComment": "赢得概率 万分率",
"WinPro": 9000,
"UserWinPokerProComment": "玩家获胜抽牌权重",
@ -28,6 +30,8 @@
{
"GearIDComment": "GearID 【输 2000档】",
"GearID": 2000,
"CommentChipPro": "机器人下注的概率",
"ChipPro": [4000,2000,2000,1000,1000],
"WinProComment": "赢得概率 万分率",
"WinPro": 8350,
"UserWinPokerProComment": "玩家获胜抽牌权重",
@ -46,6 +50,8 @@
{
"GearIDComment": "GearID 【输 1000档】",
"GearID": 1000,
"CommentChipPro": "机器人下注的概率",
"ChipPro": [4000,2000,2000,1000,1000],
"WinProComment": "赢得概率 万分率",
"WinPro": 7100,
"UserWinPokerProComment": "玩家获胜抽牌权重",
@ -64,6 +70,8 @@
{
"GearIDComment": "GearID 【赢 1000档】",
"GearID": -1000,
"CommentChipPro": "机器人下注的概率",
"ChipPro": [4000,2000,2000,1000,1000],
"WinProComment": "赢得概率 万分率",
"WinPro": 5700,
"UserWinPokerProComment": "玩家获胜抽牌权重",
@ -82,6 +90,8 @@
{
"GearIDComment": "GearID 【赢 2000档】",
"GearID": -2000,
"CommentChipPro": "机器人下注的概率",
"ChipPro": [4000,2000,2000,1000,1000],
"WinProComment": "赢得概率 万分率",
"WinPro": 5500,
"UserWinPokerProComment": "玩家获胜抽牌权重",
@ -100,6 +110,8 @@
{
"GearIDComment": "GearID 【赢 3000档】",
"GearID": -3000,
"CommentChipPro": "机器人下注的概率",
"ChipPro": [4000,2000,2000,1000,1000],
"WinProComment": "赢得概率 万分率",
"WinPro": 4300,
"UserWinPokerProComment": "玩家获胜抽牌权重",
@ -114,38 +126,38 @@
"RobotLoseDropPro": [[1,850],[2,500],[3,1700],[4,2300],[5,8499]],
"RobotLoseJiaProComment": "机器人输的加注概率 1:小盲注 2:大盲注 3:翻牌圈 4 转牌圈 5河牌圈",
"RobotLoseJiaPro": [[1,2000],[2,1800],[3,1683],[4,1400],[5,500]]
}
],
"CommentAndroidOperateConfig": "机器人的配置",
"AndroidOperateConfig": {
"CommentInGold": "场次携带金币上下范围",
"InGold": [[1000000,3000000],[2000000,6000000],[5000000,20000000],[20000000,50000000],[20000000,50000000],[20000000,50000000]],
"CommentCreateTableHZ": "创建桌子的频率",
"CreateTableHZ": 30000,
"CommentTableCreatePro": "低于多少桌时创建桌子的概率 高于最后一个配置不再创建桌子",
"TableCreatePro": [[1,10000],[7,6000],[10,3000]],
"CommentCountMax": "房间多少个真实玩家情况下 机器人的个数概率",
"CountMax0": [[0,0],[1,0],[2,30],[3,50000],[4,15],[5,0]],
"CountMax1": [[0,0],[1,3000],[2,3000],[3,5000],[4,1500],[5,500]],
"CountMax2": [[0,0],[1,5000],[2,2000],[3,1000],[4,500],[5,0]],
"CountMax3": [[0,3000],[1,5000],[2,50],[3,0],[4,0],[5,0]],
"CountMax4": [[0,8000],[1,2000],[2,0],[3,0],[4,0],[5,0]],
"CountMax5": [[0,0],[1,0],[2,0],[3,0],[4,0],[5,0]],
"CommentJoinHZ": "机器人加入房间的时间间隔",
"JoinHZ": [1,3],
"CommentFlushHZ": "刷新机器人进房间的频率",
"FlushHZ": 300
},
"CommentTimeoutDestroy": "创建房间后没人的销毁时间",
"TimeoutDestroy": 60000,
"CommentTimeOutGetBanker": "等待随机庄时间",
"TimeOutGetBanker" : 2000,
"CommentTimeOutBegin": "抢庄后到开始操作等待时间",
"TimeOutBegin" : 3000,
"CommentTimeOutOperate": "操作的时间",
"TimeOutOperate" : 20000,
"CommentTimeOutFinalResult": "最终结算倒计时",
"TimeOutFinalResult" : 2000,
"CommentTimeKickTimes": "多少次不下注踢出房间",
"TimeKickTimes" :5
}
],
"CommentAndroidOperateConfig": "机器人的配置",
"AndroidOperateConfig": {
"CommentInGold": "场次携带金币上下范围",
"InGold": [[1000000,3000000],[2000000,6000000],[5000000,20000000],[20000000,50000000],[20000000,50000000],[20000000,50000000]],
"CommentCreateTableHZ": "创建桌子的频率",
"CreateTableHZ": 30000,
"CommentTableCreatePro": "低于多少桌时创建桌子的概率 高于最后一个配置不再创建桌子",
"TableCreatePro": [[1,10000],[7,6000],[10,3000]],
"CommentCountMax": "房间多少个真实玩家情况下 机器人的个数概率",
"CountMax0": [[0,0],[1,0],[2,30],[3,50000],[4,15],[5,0]],
"CountMax1": [[0,0],[1,3000],[2,3000],[3,5000],[4,1500],[5,500]],
"CountMax2": [[0,0],[1,5000],[2,2000],[3,1000],[4,500],[5,0]],
"CountMax3": [[0,3000],[1,5000],[2,50],[3,0],[4,0],[5,0]],
"CountMax4": [[0,8000],[1,2000],[2,0],[3,0],[4,0],[5,0]],
"CountMax5": [[0,0],[1,0],[2,0],[3,0],[4,0],[5,0]],
"CommentJoinHZ": "机器人加入房间的时间间隔",
"JoinHZ": [1,3],
"CommentFlushHZ": "刷新机器人进房间的频率",
"FlushHZ": 300
},
"CommentTimeoutDestroy": "创建房间后没人的销毁时间",
"TimeoutDestroy": 60000,
"CommentTimeOutGetBanker": "等待随机庄时间",
"TimeOutGetBanker" : 5000,
"CommentTimeOutBegin": "抢庄后到开始操作等待时间",
"TimeOutBegin" : 3000,
"CommentTimeOutOperate": "操作的时间",
"TimeOutOperate" : 20000,
"CommentTimeOutFinalResult": "最终结算倒计时",
"TimeOutFinalResult" : 10000,
"CommentTimeKickTimes": "多少次不下注踢出房间",
"TimeKickTimes" :5
}

2
game-server/game/DZ/game_test.go

@ -106,7 +106,7 @@ func TestTable11_test(T *testing.T) {
log.Debug("已经跑了 ", i, " 次了")
}
rr.RepeatRoom()
rr.OnEventGameConclude()
rr.OnEventGameConclude(0)
rr.OnBuildOtherResultPoker()
}

17
game-server/game/dragonTiger/app/core/game/game_bet.go

@ -67,6 +67,14 @@ func (rr *Room) OnUserBet(uid int64, msg interface{}) { // 用户下注
return
}
if UserCurrentBet <= 0 {
log.Debug("玩家", ChairId, "个人下注总值", UserCurrentBet, " 拥有的钱: ", rr.PlayerMap[ChairId].Gold.IntPart())
BetRes.Code = protocol.ErrorCodeBetError
BetRes.CodeMsg = "下注额异常 " + strconv.Itoa(int(UserCurrentBet))
rr.Send(player, route.BetRes, BetRes)
return
}
if !player.IsRobot && UserCurrentBet > rr.PlayerMap[ChairId].Gold.IntPart() {
log.Debug("玩家", ChairId, "个人下注总值", UserCurrentBet, " 拥有的钱: ", rr.PlayerMap[ChairId].Gold.IntPart())
BetRes.Code = protocol.ErrorCodeBetError
@ -149,11 +157,14 @@ func (rr *Room) OnUserBet(uid int64, msg interface{}) { // 用户下注
for _, TempPlayer := range rr.PlayerMap {
if TempPlayer.ChairId == ChairId {
if !player.IsRobot {
log.Info(" 桌子号", rr.RId, "Nickname==", player.Nickname, " BetRes ChairId ==", ChairId, " rr.PlayerMap :", rr.PlayerMap)
}
//if !TempPlayer.IsRobot {
// log.Info(" 桌子号", rr.RId, "Nickname==", player.Nickname, " BetRes ChairId ==", ChairId, " BetRes :", BetRes)
//}
rr.Send(TempPlayer, route.BetRes, BetRes)
} else {
//if !TempPlayer.IsRobot {
// log.Info(" 桌子号", rr.RId, "Nickname==", player.Nickname, " NotifyBet ChairId ==", ChairId, " NotifyBet :", NotifyBet)
//}
rr.Send(TempPlayer, route.NotifyBet, NotifyBet)
}
}

Loading…
Cancel
Save