package richblessed import ( "encoding/json" "fmt" "math" "math/rand" "time" "mongo.games.com/goserver/core/logger" "mongo.games.com/game/common" "mongo.games.com/game/gamerule/richblessed" "mongo.games.com/game/gamesrv/base" "mongo.games.com/game/model" "mongo.games.com/game/proto" protocol "mongo.games.com/game/protocol/richblessed" "mongo.games.com/game/protocol/server" "mongo.games.com/game/srvdata" ) type RichBlessedSceneData struct { *base.Scene //场景 players map[int32]*RichBlessedPlayerData //玩家信息 jackpot *base.SlotJackpotPool //奖池 levelRate [][]int32 //调控概率区间 slotRateWeight []int32 //调控权重 sysProfitCoinKey string mqLogTime time.Time } func NewRichBlessedSceneData(s *base.Scene) *RichBlessedSceneData { sceneEx := &RichBlessedSceneData{ Scene: s, players: make(map[int32]*RichBlessedPlayerData), } sceneEx.Init() return sceneEx } func (s *RichBlessedSceneData) Init() { s.LoadJackPotData() //for _, data := range srvdata.PBDB_SlotRateMgr.Datas.Arr { // if int(data.GetGameId()) == common.GameId_Fruits { // s.levelRate = append(s.levelRate, data.RateSection) // s.slotRateWeight = append(s.slotRateWeight, data.GetWeight()) // } //} s.sysProfitCoinKey = fmt.Sprintf("%v_%v", s.Platform, s.GetGameFreeId()) s.mqLogTime = time.Now() } func (s *RichBlessedSceneData) Clear() { } func (s *RichBlessedSceneData) SceneDestroy(force bool) { //销毁房间 s.Scene.Destroy(force) } func (s *RichBlessedSceneData) AddPrizeCoin(playerEx *RichBlessedPlayerData) { val := playerEx.betCoin tax := int64(math.Ceil(float64(val) * float64(s.GetDBGameFree().GetTaxRate()) / 10000)) //playerEx.taxCoin = tax //playerEx.AddServiceFee(tax) val -= tax addPrizeCoin := val * richblessed.NowByte * int64(s.GetDBGameFree().GetJackpotRatio()) //扩大10000倍 jk1 := int64(math.Floor(float64(addPrizeCoin) / 1000 / 4)) //千分之奖池比例 分四份 s.jackpot.AddToGrand(playerEx.IsRob, jk1) s.jackpot.AddToBig(playerEx.IsRob, jk1) s.jackpot.AddToMiddle(playerEx.IsRob, jk1) s.jackpot.AddToSmall(playerEx.IsRob, jk1) logger.Logger.Tracef("[Rich] 奖池增加...AddPrizeCoin... %f", float64(jk1*4)/float64(richblessed.NowByte)) base.SlotsPoolMgr.SetPool(s.GetGameFreeId(), s.Platform, s.jackpot) if !s.Testing { base.CoinPoolMgr.PushCoin(s.GetGameFreeId(), s.GroupId, s.Platform, val*richblessed.NowByte-jk1*4) } } func (s *RichBlessedSceneData) DelPrizeCoin(isRob bool, win int64, jackpotEle int32) { if win > 0 { switch jackpotEle { case richblessed.GoldBoy: s.jackpot.AddToGrand(isRob, -win*richblessed.NowByte) case richblessed.GoldGirl: s.jackpot.AddToBig(isRob, -win*richblessed.NowByte) case richblessed.BlueBoy: s.jackpot.AddToMiddle(isRob, -win*richblessed.NowByte) default: s.jackpot.AddToSmall(isRob, -win*richblessed.NowByte) } logger.Logger.Tracef("[Rich] 奖池减少...DelPrizeCoin... %d", win) base.SlotsPoolMgr.SetPool(s.GetGameFreeId(), s.Platform, s.jackpot) } } func (s *RichBlessedSceneData) delPlayer(SnId int32) { if _, exist := s.players[SnId]; exist { delete(s.players, SnId) } } func (s *RichBlessedSceneData) OnPlayerLeave(p *base.Player, reason int) { if playerEx, ok := p.ExtraData.(*RichBlessedPlayerData); ok { if playerEx.freeTimes > 0 || playerEx.isFWinJackpot { if playerEx.isFWinJackpot { // 小游戏 s.JACKPOTWin(playerEx) a1 := rand.Int63n(3) a2 := rand.Int63n(3) + 3 a3 := rand.Int63n(2) + 6 playerEx.JackMidCards = append(playerEx.JackMidCards, a1, a2, a3) //发送结算 //s.SendJACKPOTBilled(playerEx) s.SaveLog(playerEx, 1) playerEx.Clear() } //freenum := playerEx.freeTimes //for i := int32(0); i < freenum; i++ { // playerEx.Clear() // gameRand, _ := s.GetFreeWeight() // playerEx.CreateLevResult(gameRand) // 没有铜锣概率 // s.Win(playerEx) // s.SaveLog(playerEx, 1) //} } s.delPlayer(p.SnId) } } // 是否中奖 func (s *RichBlessedSceneData) CanJACKPOT(p *RichBlessedPlayerData, bet int64, big int64, JACKRand []int32) bool { ret := p.result.CanJACKPOT(bet, big) logger.Logger.Tracef("RichBlessedSceneData CanJACKPOT %v %v", ret, p.result.EleValue) if ret || p.isJk { WinJackPot := int64(0) ele := p.result.CreateJACKPOT(JACKRand) if p.isJk { ele = rand.Int31n(richblessed.JackMax) p.result.JackpotEle = ele } switch ele { case richblessed.GoldBoy: WinJackPot = s.jackpot.GetTotalGrand() case richblessed.GoldGirl: WinJackPot = s.jackpot.GetTotalBig() case richblessed.BlueBoy: WinJackPot = s.jackpot.GetTotalMiddle() case richblessed.BlueGirl: WinJackPot = s.jackpot.GetTotalSmall() } if WinJackPot > 0 { jkWin := int64(math.Floor(float64(WinJackPot) / float64(richblessed.NowByte))) if jkWin > (richblessed.JkEleNumRate[int(ele)]*p.oneBetCoin) || p.isJk { p.isFWinJackpot = true return true } } //不能中奖 p.result.JackpotEle = -1 p.result.JackpotRate = 0 } return false } func (s *RichBlessedSceneData) Win(p *RichBlessedPlayerData) { p.result.Win(p.betCoin, p.maxbetCoin) if p.result.FreeNum != 0 { p.addfreeTimes = p.result.FreeNum p.freeTimes += p.addfreeTimes } p.winLineRate = p.result.AllRate p.winCoin += p.oneBetCoin * p.winLineRate if p.gameState == richblessed.FreeGame { p.freewinCoin += p.winCoin } if p.winCoin != 0 { p.noWinTimes = 0 //SysProfitCoinMgr.Add(s.sysProfitCoinKey, 0, p.winCoin) p.Statics(s.KeyGameId, s.KeyGamefreeId, p.winCoin, false) //tax := int64(math.Ceil(float64(p.winCoin) * float64(s.GetDBGameFree().GetTaxRate()) / 10000)) //p.taxCoin = tax //p.winCoin -= tax //p.AddServiceFee(tax) p.AddCoin(p.winCoin, common.GainWay_HundredSceneWin, 0, "system", s.GetSceneName()) if !s.Testing && p.winCoin != 0 { base.CoinPoolMgr.PushCoin(s.GetGameFreeId(), s.GroupId, s.Platform, -(p.winCoin)*richblessed.NowByte) } //p.isReportGameEvent = true } } func (s *RichBlessedSceneData) JACKPOTWin(p *RichBlessedPlayerData) { p.result.JACKPOTWin() p.JackwinCoin = p.result.JackpotRate * p.oneBetCoin if p.JackwinCoin > 0 { s.DelPrizeCoin(p.IsRob, p.JackwinCoin, p.result.JackpotEle) p.noWinTimes = 0 //SysProfitCoinMgr.Add(s.sysProfitCoinKey, 0, p.JackwinCoin) p.Statics(s.KeyGameId, s.KeyGamefreeId, p.JackwinCoin, false) //tax := int64(math.Ceil(float64(p.JackwinCoin) * float64(s.GetDBGameFree().GetTaxRate()) / 10000)) //p.taxCoin = tax //p.JackwinCoin -= tax //p.AddServiceFee(tax) p.AddCoin(p.JackwinCoin, common.GainWay_HundredSceneWin, 0, "system", s.GetSceneName()) if !s.Testing && p.JackwinCoin != 0 { base.CoinPoolMgr.PushCoin(s.GetGameFreeId(), s.GroupId, s.Platform, -(p.JackwinCoin)*richblessed.NowByte) } // p.JackpotEle = -1 //p.isReportGameEvent = true } } func (s *RichBlessedSceneData) SendBilled(p *RichBlessedPlayerData) { //正常游戏 免费游戏 pack := &protocol.SCRBBilled{ NowGameState: proto.Int(p.gameState), BetIdx: proto.Int(p.betIdx), Coin: proto.Int64(p.Coin), Cards: p.result.EleValue, FreeAllWin: proto.Int64(p.freewinCoin), // //SmallJackpot: proto.Int64(s.jackpot.GetTotalSmall() / 10000), //MiddleJackpot: proto.Int64(s.jackpot.GetTotalMiddle() / 10000), //BigJackpot: proto.Int64(s.jackpot.GetTotalBig() / 10000), //GrandJackpot: proto.Int64(s.jackpot.GetTotalGrand() / 10000), WinEleCoin: proto.Int64(p.winCoin), WinRate: proto.Int64(p.winLineRate), FreeNum: proto.Int64(int64(p.freeTimes)), AddFreeNum: proto.Int64(int64(p.addfreeTimes)), JackpotEle: proto.Int32(p.result.JackpotEle), WinFreeTimes: proto.Int32(int32(p.nowFreeTimes)), } var wl []*protocol.RichWinLine for _, r := range p.result.WinLine { wl = append(wl, &protocol.RichWinLine{ Poss: r.Poss, }) } pack.WinLines = wl logger.Logger.Trace("SCRBBilled:", pack) p.SendToClient(int(protocol.RBPID_PACKET_RICHBLESSED_SCRBBilled), pack) } func (s *RichBlessedSceneData) SendJACKPOTBilled(p *RichBlessedPlayerData) { pack := &protocol.SCRBBilled{ NowGameState: proto.Int(p.gameState), BetIdx: proto.Int(p.betIdx), Coin: proto.Int64(p.Coin), //SmallJackpot: proto.Int64(s.jackpot.GetTotalSmall() / 10000), //MiddleJackpot: proto.Int64(s.jackpot.GetTotalMiddle() / 10000), //BigJackpot: proto.Int64(s.jackpot.GetTotalBig() / 10000), //GrandJackpot: proto.Int64(s.jackpot.GetTotalGrand() / 10000), WinJackpot: proto.Int64(p.JackwinCoin), } logger.Logger.Trace("SendJACKPOTBilled:", pack) p.SendToClient(int(protocol.RBPID_PACKET_RICHBLESSED_SCRBJACKBilled), pack) } func (s *RichBlessedSceneData) LoadJackPotData() { str := base.SlotsPoolMgr.GetPool(s.GetGameFreeId(), s.Platform) if str != "" { jackpot := &base.SlotJackpotPool{} err := json.Unmarshal([]byte(str), jackpot) if err == nil { s.jackpot = jackpot } } if s.jackpot != nil { base.SlotsPoolMgr.SetPool(s.GetGameFreeId(), s.Platform, s.jackpot) } else { s.jackpot = &base.SlotJackpotPool{} jp := s.GetDBGameFree().GetJackpot() if len(jp) > 0 { s.jackpot.Small += int64(jp[0] * 10000) } } } func (s *RichBlessedSceneData) SaveLog(p *RichBlessedPlayerData, isOffline int) { if s.Testing { return } s.SendPlayerBet(p) var betCoin int64 var nowNRound int var nowGetCoin int64 if p.gameState == richblessed.Normal { betCoin = p.betCoin nowGetCoin = p.winCoin } else if p.gameState == richblessed.FreeGame { nowNRound = p.nowFreeTimes nowGetCoin = p.winCoin } else { nowGetCoin = p.JackwinCoin } RichBlessed := model.RichBlessedType{ RoomId: int(s.SceneId), BasicScore: int32(p.oneBetCoin), PlayerSnId: p.SnId, BeforeCoin: p.startCoin, AfterCoin: p.Coin, ChangeCoin: p.Coin - p.startCoin, TotalBetCoin: betCoin, TotalLine: 9, TotalWinCoin: nowGetCoin, NowGameState: p.gameState, NowNRound: nowNRound, IsOffline: isOffline, FirstFreeTimes: int(p.freeTimes), TaxCoin: p.taxCoin, WBLevel: p.WBLevel, RealCtrl: s.RealCtrl, WBState: p.WBState, WeightKey: p.weightPos + 1, } var winLine []model.RichBlessedWinLine if p.gameState == richblessed.JackGame { // jack小游戏 RichBlessed.JackEleValue = p.result.JackpotEle RichBlessed.JackMidCards = append(RichBlessed.JackMidCards, p.JackMidCards...) } RichBlessed.Cards = p.result.EleValue RichBlessed.WinLineNum = len(p.result.WinLine) RichBlessed.WinLineRate = p.winLineRate RichBlessed.WinLineCoin = p.winLineRate * p.oneBetCoin for _, line := range p.result.WinLine { if len(line.Lines) > 0 { flag := line.Lines[0] fw := model.RichBlessedWinLine{ Id: line.LineId, Num: len(line.Lines), EleValue: flag, Rate: line.Rate, WinCoin: line.Rate * p.oneBetCoin, } winLine = append(winLine, fw) } } RichBlessed.WinLine = winLine info, err := model.MarshalGameNoteByROLL(&RichBlessed) if err == nil { logId, _ := model.AutoIncGameLogId() s.SaveGameDetailedLog(&base.SaveGameDetailedParam{ LogId: logId, Detail: info, GameTime: 2, }) //水池上下文环境s s.CpCtx = p.cpCtx var totalIn, totalOut int64 if betCoin > 0 { totalIn = betCoin } if nowGetCoin > 0 { totalOut = p.Coin - p.startCoin + betCoin /*+ p.taxCoin*/ } s.SaveGamePlayerListLog(&base.SaveGamePlayerListLogParam{ LogId: logId, Platform: p.Platform, Snid: p.SnId, PlayerName: p.Name, Channel: p.Channel, ChannelId: p.ChannelId, TotalIn: totalIn, TotalOut: totalOut, TaxCoin: p.taxCoin, BetAmount: totalIn, WinAmountNoAnyTax: p.Coin - p.startCoin, IsFirstGame: s.IsPlayerFirst(p.Player), IsFree: totalIn == 0, GameTime: 2, }) } s.GameNowTime = time.Now() if s.CheckNeedDestroy() && p.freeTimes == 0 { s.PlayerLeave(p.Player, common.PlayerLeaveReason_OnDestroy, true) } } func (s *RichBlessedSceneData) GetEleWeight(needpos int32) (norms, frees [][]int32, jk []int32, key int32) { if needpos < 0 || needpos > 7 || !s.RealCtrl { needpos = 0 } if needpos == 0 { curCoin := base.CoinPoolMgr.GetCoin(s.GetGameFreeId(), s.Platform, s.GroupId) curCoin = int64(math.Floor(float64(curCoin) / float64(richblessed.NowByte))) for i := len(s.GetDBGameFree().BalanceLine) - 1; i >= 0; i-- { balance := s.GetDBGameFree().BalanceLine[i] if curCoin >= int64(balance) { key = int32(i) break } } } else { key = needpos - 1 } for _, ele := range srvdata.PBDB_SlotRateWeightMgr.Datas.GetArr() { if ele.GameFreeId == s.GetGameFreeId() && ele.Pos == key { norms = append(norms, ele.NormCol1) norms = append(norms, ele.NormCol2) norms = append(norms, ele.NormCol3) norms = append(norms, ele.NormCol4) norms = append(norms, ele.NormCol5) frees = append(frees, ele.FreeCol1) frees = append(frees, ele.FreeCol2) frees = append(frees, ele.FreeCol3) frees = append(frees, ele.FreeCol4) frees = append(frees, ele.FreeCol5) jk = ele.JackPot break } } if norms == nil { norms = richblessed.EleWeight[:5] frees = richblessed.EleWeight[5:10] jk = richblessed.EleWeight[10] key = 0 } return } func (s *RichBlessedSceneData) CreateResult(eleLineAppearRate [][]int32, playerEx *RichBlessedPlayerData) { //if s.GetDBGameFree().GetId() == 3070004 { // playerEx.TestCode(eleLineAppearRate) //} else { playerEx.result.CreateLine(eleLineAppearRate) //} } func (s *RichBlessedSceneData) SendPlayerBet(p *RichBlessedPlayerData) { //统计输下注金币数 if !p.IsRob && !s.Testing { betCoin := p.betCoin if p.gameState != richblessed.Normal { betCoin = 0 } playerBet := &server.PlayerData{ SnId: proto.Int32(p.SnId), Bet: proto.Int64(betCoin), Gain: proto.Int64(p.Coin - p.startCoin), Tax: proto.Int64(p.taxCoin), Coin: p.Coin, GameCoinTs: p.GameCoinTs, } gwPlayerBet := &server.GWPlayerData{ GameFreeId: proto.Int32(s.GetDBGameFree().GetId()), SceneId: int32(s.SceneId), } gwPlayerBet.Datas = append(gwPlayerBet.Datas, playerBet) s.SyncPlayerDatas(&base.PlayerDataParam{ HasRobotGaming: false, Data: gwPlayerBet, }) } }