package game import ( "server/call" "server/common" "server/db" "server/pb" "server/util" "time" "github.com/liangdas/mqant/log" ) const ( MillionMaxSeat = 4 ) // MillionSubTable 百人场子游戏数据 type MillionSubTable struct { Table *Table History []int64 TotalBet []int64 Jackpot *common.Jackpot MillionSubTableInter } type MillionSubTableInter interface { GetResult() (string, string) } func (t *Table) NewMillionSubTable() { t.MillionSubTable = &MillionSubTable{Table: t} db.Redis().GetJsonData(common.GetRedisKeyGameResult(ThisGameID, t.Room.RoomId()), &t.History) } func (t *MillionSubTable) GetTotal() (total int64) { for _, v := range t.TotalBet { total += v } return } func (t *MillionSubTable) Reset() { t.Table.ResetTimeOut() // 如果配置有改动,重新加载配置,广播告知客户端 if t.Table.ConfigChange { t.Table.ConfigChange = false t.Table.Config = *t.Table.Room.Config for _, v := range t.Table.GetSeats() { p := v.(*Player) if p.IsRobot() { continue } p.SubPlayer.TableInfo() } } t.TotalBet = make([]int64, len(t.Table.Config.BetLimit)) for _, v := range t.Table.GetSeats() { p := v.(*Player) if p.IsLeave || p.WatchCount >= MaxWatchCount { p.TotalBet = 0 p.Status = pb.PlayerStatus_PlayerStatusNormal p.Leave() continue } p.Reset() // if !t.Table.IsSingle && !p.IsRobot() && call.ShouldMillionBlack(p.UID, t.Table.GameID) { // p.IsLeave = true // p.Leave() // InnerActionGame(&pb.ActionGame{ // Action: 0, // UID: int32(p.UID), // GameKind: common.GetGameKindByID(ThisGameID), // }) // } } t.Table.StartGame() } type MillionSubPlayerInter interface { GetHistory() } // MillionSubPlayer 百人场子游戏玩家数据 type MillionSubPlayer struct { *Player AreaBet []int64 AreaWin []int64 // 每个区域输赢 WatchCount int // 观看不下注局数 MillionSubPlayerInter } func NewMillionSubPlayer(player *Player, sp MillionSubPlayerInter) *MillionSubPlayer { p := &MillionSubPlayer{Player: player, MillionSubPlayerInter: sp} p.AreaBet = make([]int64, len(p.Player.T.Config.BetLimit)) p.AreaWin = make([]int64, len(p.Player.T.Config.BetLimit)) return p } func (sp *MillionSubPlayer) Reset() { sp.AreaBet = make([]int64, len(sp.Player.T.Config.BetLimit)) sp.AreaWin = make([]int64, len(sp.Player.T.Config.BetLimit)) } func (sp *MillionSubPlayer) Settle() { if sp.T.Room.RoomType == RoomTypePractice { return } ct := sp.GameCurrencyType settle := sp.FinalSettle update := &common.UpdateCurrency{ NotNotify: true, CurrencyBalance: &common.CurrencyBalance{ UID: sp.UID, Type: ct, Value: settle, }, } sp.PackUpdate(update) util.Go(func() { call.UpdateCurrencyPro(update) }) } func (p *MillionSubPlayer) MillionLeave() bool { t := p.T p.Debug("leave table,totalBet:%v", p.TotalBet) resp := &pb.GameLeaveResp{Result: CodeOk} if p.WatchCount >= MaxWatchCount { resp.Reason = 1 } p.SendReal(int(pb.GameProtocol_LeaveResp), resp) if p.TotalBet > 0 || (t.IsSingle && t.Status != pb.GameStatus_GameStatusNormal) { p.IsLeave = true return false } // if p.SeatID >= 0 { // t.SeatPlayers[p.SeatID] = nil // t.Broadcast(int(pb.MillionProtocol_MillionSitdownResp), &pb.GameSitdownResp{Index: uint32(p.SeatID), Opt: 2}) // } return true } func (p *MillionSubPlayer) MillionBet(area, amount int64) { t := p.T p.Debug("Bet area %v amount %v", area, amount) code := CodeOk defer func() { p.DeferBet(area, amount, code) }() if t.Status != pb.GameStatus_GameStatusPlaying || int(area) > len(t.Config.BetLimit)-1 { p.Debug("bet area:%v,areaBet:%v", area, len(t.Config.BetLimit)) code = CodeBetInvalid return } if p.AreaBet[area]+int64(amount) > t.Config.BetLimit[area] { code = CodeBetLimit return } update := &common.UpdateCurrency{ CurrencyBalance: &common.CurrencyBalance{ Type: p.GameCurrencyType, Value: -amount, Event: common.CurrencyEventGameBet, }, } p.PackUpdate(update) pro := call.MineCurrencyProReal(update) if pro.Err != nil { log.Error("err:%v", pro.Err) code = CodeSeverError return } // p.Currency.SetBalance(p.GameCurrencyType, pro.Balance) p.Balance = pro.Balance p.Status = pb.PlayerStatus_PlayerStatusPlaying t.TotalBet[area] += int64(amount) p.AreaBet[area] += int64(amount) p.TotalBet += int64(amount) // 更新排行榜 p.UpdateBetList() } // MillionSettle 百人场结算逻辑 func (p *Player) MillionSettle() { if p.Status == pb.PlayerStatus_PlayerStatusNormal { p.WatchCount++ } else { p.WatchCount = 0 p.Settle() } } func (mt *MillionSubTable) Settle() { t := mt.Table now := time.Now().Unix() records := map[int]*common.ESMillionGameRecord{} for _, v := range t.GetSeats() { p := v.(*Player) if p.Status == pb.PlayerStatus_PlayerStatusNormal || p.IsRobot() || p.TotalBet == 0 { continue } record := records[p.ChannelID] if record == nil { record = &common.ESMillionGameRecord{ Time: now, GameID: ThisGameID, RoomID: t.Room.RoomId(), UUID: t.UUID, Channel: p.ChannelID, } record.Result, record.ResultDetail = mt.GetResult() } doc := &common.ESMillionPlayerRecord{ UID: p.UID, Time: now, GameID: ThisGameID, RoomID: t.Room.RoomId(), UUID: t.UUID, Settle: p.FinalSettle, Result: record.Result, Channel: p.ChannelID, Bets: p.AreaBet, } db.ES().InsertToESGO(common.ESIndexBackMillionPlayerRecord, doc) record.PlayerCount++ record.PlayerBet += p.MillionSubPlayer.TotalBet if p.FinalSettle > 0 { record.Reward += p.FinalSettle } record.Profit += p.FinalSettle records[p.ChannelID] = record } for i := range records { db.ES().InsertToESGO(common.ESIndexBackMillionGameRecord, records[i]) } } func (p *MillionSubPlayer) DeferBet(area, amount int64, code int) { t := p.T resp := &pb.GameMsgBetResp{ Code: int64(code), CurrencyType: int64(p.GameCurrencyType), Amount: amount, Balance: p.Balance, Area: area, } p.Send(int(pb.GameProtocol_BetResp), resp) if code != CodeOk { return } respBroadcast := &pb.GameMsgBetBroadcastResp{ UID: int64(p.UID), CurrencyType: int64(p.GameCurrencyType), Amount: amount, Area: area, } t.Broadcast(int(pb.GameProtocol_BetBroadcast), respBroadcast, p.UID) }