Exemple #1
0
        /// <summary>
        /// 游戏数据重置
        /// </summary>
        /// <param name="init">是否直接清理玩家手牌,不播放动画</param>
        public virtual void Reset(bool init = false)
        {
            PublicPokers = new List <PokerCard>();

            DealPokerMgr.Reset();
            SpeakMgr.Reset();
            BetMgr.Reset();
            YxClockManager.StopToCountDown();

            var gdata      = App.GetGameData <BlackJackGameData>();
            var playerList = gdata.PlayerList;

            foreach (GameObject bet in Bets)
            {
                Destroy(bet);
            }
            Bets.Clear();

            if (init)
            {
                YxDebug.LogError("Reset but && Init");
                foreach (var yxBaseGamePlayer in playerList)
                {
                    var player = (BjPlayerPanel)yxBaseGamePlayer;
                    player.Reset();
                }
                foreach (PokerCard publicPoker in PublicPokers)
                {
                    Destroy(publicPoker.gameObject);
                }
                PublicPokers.Clear();
                gdata.BjBankerBanker.Reset();
            }
            else
            {
                foreach (var yxBaseGamePlayer in playerList)
                {
                    var player = (BjPlayerPanel)yxBaseGamePlayer;
                    player.ThrowPokersWithAnim();
                    player.Reset();
                }
                var banker = gdata.BjBankerBanker;
                banker.ThrowPokersWithAnim();
                banker.Reset();
            }
            SelfPlayer.SetReadyBtnActive(true);
        }
        public override void GameResponseStatus(int type, ISFSObject response)
        {
            var gdata = App.GetGameData <TexasGameData>();

            switch ((GameRequestType)type)
            {
            case GameRequestType.Bet:

                var bseat = response.GetInt("seat");
                var bgold = response.GetInt("gold");
                if (bseat == gdata.SelfSeat)
                {
                    gdata.GStatus = YxEGameStatus.PlayAndConfine;
                }
                var bplayer = gdata.GetPlayer <PlayerPanel>(bseat, true);
                bplayer.PlayerBet(bgold);
                YxClockManager.StopToCountDown();
                SpeakMagr.PoolNum += bgold;

                if (bplayer.CurGameType != PlayerGameType.AllIn && bplayer.BetMoney > SpeakMagr.MaxBetNum)
                {
                    Facade.Instance <MusicManager>().Play("addBet");
                }
                else if (bplayer.CurGameType != PlayerGameType.AllIn && bplayer.BetMoney == SpeakMagr.MaxBetNum)
                {
                    bool isCall = bgold > 0;
                    Facade.Instance <MusicManager>().Play(isCall
                            ? "call"
                            : "seePoker");
                    bplayer.CurGameType = isCall ? PlayerGameType.Call : PlayerGameType.SeePoker;
                }

                //设置最大下注
                SpeakMagr.MaxBetNum = bplayer.BetMoney >
                                      SpeakMagr.MaxBetNum
                        ? bplayer.BetMoney
                        : SpeakMagr.MaxBetNum;

                YxDebug.Log("玩家 " + bseat + " 下注 : " + bgold);

                if (response.ContainsKey("speaker"))
                {
                    StartCoroutine(Speaker(response.GetInt("speaker"),
                                           response.ContainsKey("cd")
                                ? response.GetInt("cd")
                                : App.GetGameData <TexasGameData>().SpeakCd));
                }

                break;

            case GameRequestType.Fold:
            {
                var fseat   = response.GetInt("seat");
                var fplayer = gdata.GetPlayer <PlayerPanel>(fseat, true);
                YxClockManager.StopWaitPlayer();
                fplayer.CurGameType = PlayerGameType.Fold;
                //fplayer.ReadyState = false;
                Facade.Instance <MusicManager>().Play("fold");
                if (fseat == gdata.SelfSeat)
                {
                    SpeakMagr.ShowNothing();
                    gdata.GStatus = YxEGameStatus.Normal;
                }
                YxDebug.Log("玩家 " + fseat + " 弃牌!!");

                if (response.ContainsKey("speaker"))
                {
                    StartCoroutine(Speaker(response.GetInt("speaker"),
                                           response.ContainsKey("cd")
                                    ? response.GetInt("cd")
                                    : App.GetGameData <TexasGameData>().SpeakCd));
                }
            }
            break;

            case GameRequestType.HandCard:
                //游戏开始
                gdata.IsGameStart = true;

                //设置自己的状态
                var self = gdata.GetPlayer <SelfPanel>();
                self.SetReadyBtnActive(false);

                //游戏开始要隐藏微信邀请按钮
                if (gdata.IsRoomGame)
                {
                    RModelMagr.OnGameStart();
                    gdata.IsPlayed = true;
                }

                //下大小盲注时,游戏开始
                if (response.ContainsKey("bkp"))
                {
                    int round = ++gdata.CurRound;

                    RModelMagr.UpDataRoundValue(round);
                    IsResultDone = false;

                    //小盲注 在下一家为大盲注
                    var bkp = response.GetInt("bkp");

                    if (gdata.GetPlayer().ReadyState)
                    {
                        gdata.GStatus = self.ReadyState ? YxEGameStatus.PlayAndConfine : YxEGameStatus.Play;
                    }

                    var playerList  = gdata.PlayerList;
                    var playerCount = playerList.Length;
                    var maxCount    = playerCount + bkp;
                    for (var i = bkp; i < maxCount; i++)
                    {
                        var index  = i % playerCount;
                        var player = gdata.GetPlayer <PlayerPanel>(index, true);
                        if (player.Info == null || !player.ReadyState)
                        {
                            continue;
                        }

                        if (SmallBanker == -1)
                        {
                            //小盲下注
                            var xmz = player.RoomCoin >= gdata.Ante
                                    ? gdata.Ante : player.RoomCoin;
                            player.PlayerBet(xmz);
                            SmallBanker         = index;
                            SpeakMagr.MaxBetNum = xmz;
                            SpeakMagr.PoolNum  += xmz;
                        }
                        else if (BigBanker == -1)
                        {
                            //大盲下注
                            var dmz = player.RoomCoin >= gdata.Ante * 2
                                    ? gdata.Ante * 2
                                    : player.RoomCoin;
                            player.Blinds.SetActive(true);
                            player.PlayerBet(dmz);
                            BigBanker           = i;
                            SpeakMagr.MaxBetNum = dmz > SpeakMagr.MaxBetNum
                                    ? dmz
                                    : SpeakMagr.MaxBetNum;
                            SpeakMagr.PoolNum += dmz;
                        }
                    }

                    //获得手牌
                    if (response.ContainsKey(RequestKey.KeyCards))
                    {
                        DealerMagr.BeginSmallDeal(SmallBanker, response.GetIntArray(RequestKey.KeyCards));
                    }

                    if (HistoryResultMgr != null)
                    {
                        HistoryResultMgr.CreateHistoryItem(response);
                    }
                }
                else
                {
                    SpeakMagr.MaxBetNum = 0;         //每轮开始清除最大下注

                    BetMagr.Invoke("CollectBet", 0.5f);

                    //发公共牌
                    DealerMagr.BeginBigDeal(response.GetIntArray(RequestKey.KeyCards));

                    if (response.ContainsKey("speaker"))
                    {
                        StartCoroutine(Speaker(response.GetInt("speaker"), gdata.SpeakCd, 0.7f));
                    }
                    HideAllPlayersGameType();
                }

                break;


            case GameRequestType.Request:
            {
                gdata.GStatus = YxEGameStatus.Normal;
                SpeakMagr.ShowNothing();
                HideAllPlayersGameType();
                YxClockManager.StopWaitPlayer();

                //每轮开始清除最大下注
                BetMagr.CollectBet();

                var players = response.GetSFSArray("players");

                ResultCd = response.GetInt("cd");

                if (response.ContainsKey("croomct"))
                {
                    RModelMagr.CalibrationTime((int)response.GetLong("croomct"));
                }

                var idxIndex        = 0;
                var playerDataCount = players.Count;
                for (var i = 0; i < playerDataCount; i++)
                {
                    var playerData = players.GetSFSObject(i);
                    //没有参与游戏的玩家直接跳过
                    if (!playerData.ContainsKey("isPlayed") || !playerData.GetBool("isPlayed"))
                    {
                        continue;
                    }
                    //弃牌玩家不会设置数据
                    bool isFold = playerData.ContainsKey("isGiveUp") && playerData.GetBool("isGiveUp");
                    if (isFold)
                    {
                        continue;
                    }

                    //座位号
                    var seat = playerData.GetInt("seat");

                    //玩家输赢
                    var winGold = Math.Abs(playerData.GetInt("xz")) + playerData.GetInt("gold");

                    var p = gdata.GetPlayer <PlayerPanel>(seat, true);
                    p.Blinds.SetActive(false);
                    if (seat != gdata.SelfSeat)
                    {
                        var cardArray = playerData.GetIntArray("cardArr");
                        p.ShowHandCards(cardArray);
                        p.UserBetPoker.TurnOverCard();
                    }

                    if (p.Info == null)
                    {
                        continue;
                    }

                    if (playerData.ContainsKey("roomGold"))
                    {
                        p.RoomCoin = playerData.GetInt("roomGold");
                    }

                    if (winGold <= 0)
                    {
                        continue;
                    }

                    ISFSObject teax;
                    if (playerData.ContainsKey("teax"))
                    {
                        teax = playerData.GetSFSObject("teax");
                    }
                    else
                    {
                        teax = new SFSObject();
                        teax.PutInt("idx", idxIndex);
                        idxIndex++;
                    }
                    teax.PutInt("seat", seat);
                    teax.PutInt("gold", winGold);
                    teax.PutBool("isGiveUp", false);
                    teax.PutIntArray("cardArr", playerData.GetIntArray("cardArr"));

                    ////赢家拿钱
                    var teaxIndex = teax.GetInt("idx");
                    var wins      = ResultData.ContainsKey(teaxIndex) ? ResultData[teaxIndex] : new List <ISFSObject>();
                    wins.Add(teax);
                    ResultData[teaxIndex] = wins;
                }

                if (HistoryResultMgr != null)
                {
                    if (response.ContainsKey("curTime"))
                    {
                        HistoryResultMgr.SetHistoryItemTime(response.GetUtfString("curTime"));
                    }
                    HistoryResultMgr.GetHistoryInfo(response);         //获取战绩信息
                }

                BeginResult();
                if (TotalScoreView != null)
                {
                    TotalScoreView.OnGetGameResultInfo(response);
                }
            }
            break;

            case GameRequestType.Speaker:
                var speakCd = response.GetInt("cd");
                gdata.SpeakCd = speakCd;
                StartCoroutine(Speaker(response.GetInt("speaker"), speakCd));
                break;

            case GameRequestType.SetGold:

                var setPlayer = gdata.GetPlayer <PlayerPanel>(response.GetInt("seat"), true);
                var gold      = response.GetInt(RequestKey.KeyGold);
                setPlayer.Coin    -= gold - setPlayer.RoomCoin;
                setPlayer.RoomCoin = gold;
                break;

            case GameRequestType.AllowReady:
                gdata.GStatus     = YxEGameStatus.Normal;
                gdata.IsGameStart = false;
                //清空准备列表开始接收准备信息
                //如果仍在结算则提前结算完成
                {
                    if (IsResultDone)
                    {
                        ResultDone();
                    }
                    var playerList  = gdata.PlayerList;
                    var playerCount = playerList.Length;
                    for (var i = 0; i < playerCount; i++)
                    {
                        var player = gdata.GetPlayer <PlayerPanel>(i);
                        if (player.Info != null && player.RoomCoin <= 0)
                        {
                            player.ReadyState = false;
                        }
                    }

                    CheckSelfGold();
                }
                break;

            default:
                YxDebug.Log("不存在的服务器交互!");
                break;
            }
        }
Exemple #3
0
        public override void GameResponseStatus(int type, ISFSObject data)
        {
            var gdata = App.GetGameData <BlackJackGameData>();

            if (!gdata.IsGameInfo)
            {
                YxDebug.LogError("GameInfo还没有初始化!!");
                return;
            }

            switch ((GameRequestType)type)
            {
            case GameRequestType.StartAnte:

                DealPokerMgr.CleanPokers();            //清理掉上一把没有清理掉的手牌
                //ClockCd.BeginCountDown(data.GetInt("cd"));
                YxClockManager.BeginToCountDown(data.GetInt("cd"));
                SpeakMgr.BetViewActive(true);

                //游戏开始,隐藏准备按键和标志
                var anteUsers = gdata.PlayerList;
                foreach (var yxBaseGamePlayer in anteUsers)
                {
                    var anteUser = (BjPlayerPanel)yxBaseGamePlayer;
                    anteUser.SetReadyBtnActive(false);
                    anteUser.SetReadyMarkActive(false);
                }
                break;


            case GameRequestType.EndAnte:

                SpeakMgr.ShowNothing();
                YxClockManager.StopToCountDown();
                break;


            case GameRequestType.Ante:

                int anteSeat = data.GetInt("seat");
                int anteGold = data.GetInt("gold");
                gdata.GetPlayer <BjPlayerPanel>(anteSeat, true).PlayerBet(anteGold);
                if (anteSeat == SelfSeat && anteGold > 0)
                {
                    gdata.IsPlaying = true;
                    BetBtnMgr.CheckColdClickAnte();
                }
                break;


            case GameRequestType.Allocate:

                if (data.ContainsKey("cards"))
                {
                    ISFSArray allocateArray = data.GetSFSArray("cards");

                    foreach (ISFSObject player in allocateArray)
                    {
                        int[] allocateSeat   = { player.GetInt("seat") };
                        int[] allowcateCards = player.GetIntArray("cards");
                        DealPokerMgr.EnqueueCardInfo(allocateSeat, allowcateCards);
                        DealPokerMgr.BeginDealCards();          //开始发牌
                    }
                }

                if (data.ContainsKey("bankcards"))
                {
                    int[] albankerCards = data.GetIntArray("bankcards");

                    DealPokerMgr.EnqueueCardInfo(gdata.BjBankerBanker, albankerCards);
                    DealPokerMgr.BeginDealCards();
                }

                if (data.ContainsKey("card"))
                {
                    int cardSeat = data.GetInt("seat");
                    DealPokerMgr.EnqueueCardInfo(cardSeat, data.GetInt("card"));
                    gdata.GetPlayer <BjPlayerPanel>(cardSeat, true).StopCountDown();

                    if (gdata.IsMyTurn(cardSeat))
                    {
                        SpeakMgr.DoubleBtnEnable(false);
                        SpeakMgr.InsuranceBtnEnable(false);
                    }
                }
                SpeakMgr.ShowNothing();
                break;


            case GameRequestType.Result:
                gdata.IsGameing = false;
                gdata.IsPlaying = false;
                ResultMgr.InitResultView(data);
                ResultMgr.ShowResultView();

                if (data.ContainsKey("users"))
                {
                    ISFSArray resultUsers = data.GetSFSArray("users");
                    foreach (ISFSObject resultUser in resultUsers)
                    {
                        int resultSeat = resultUser.GetInt("seat");
                        var panel      = gdata.GetPlayer <BjPlayerPanel>(resultSeat, true);
                        if (panel.Info == null)
                        {
                            continue;
                        }
                        panel.Coin = resultUser.GetLong("ttgold");

                        if (resultSeat == SelfSeat)
                        {
                            ResultMgr.InitResultView(resultUser);
                        }
                    }
                }
                Invoke("ResetGame", 6);
                break;


            case GameRequestType.Speak:

                int   speakSeat = data.GetInt("seat");
                float speakCd   = data.GetInt("cd");
                gdata.GetPlayer <BjPlayerPanel>(speakSeat, true).BeginCountDown(speakCd);

                if (speakSeat != SelfSeat)
                {
                    YxDebug.Log(" === no my self === " + SelfSeat);
                    SpeakMgr.ShowNothing();
                    break;
                }

                SpeakMgr spkMgr = SpeakMgr;
                spkMgr.SpeakViewActive(true);

                //显示双倍和保险按键
                if (data.ContainsKey("addrate"))
                {
                    //双倍按钮的显示和是否能按
                    spkMgr.DoubleBtn.SetActive(data.GetBool("addrate"));
                    spkMgr.DoubleBtnEnable(SelfPlayer.BetMoney / 2 <= gdata.GetSelfPanel().Coin);

                    //保险按钮的显示和是否能按
                    spkMgr.InsuranceBtn.SetActive(data.GetBool("insurance"));
                    spkMgr.InsuranceBtnEnable(SelfPlayer.BetMoney <= gdata.GetSelfPanel().Coin);
                }

                break;


            case GameRequestType.Stand:

                int standSeat = data.GetInt("seat");
                gdata.GetPlayer <BjPlayerPanel>(standSeat).StopCountDown();
                if (standSeat == SelfSeat)
                {
                    SpeakMgr.ShowNothing();
                }

                break;


            case GameRequestType.AddRate:

                if (data.ContainsKey("seat"))
                {
                    int addRateSeat = data.GetInt("seat");
                    gdata.GetPlayer <BjPlayerPanel>(addRateSeat).BuyDouble(data.GetInt("gold"));
                    if (addRateSeat == SelfSeat)
                    {
                        SpeakMgr.SpeakViewActive(true);
                        SpeakMgr.DoubleBtnEnable(false);
                    }
                }
                break;

            case GameRequestType.BankerAllocate:

                SpeakMgr.ShowNothing();

                if (data.ContainsKey("cards"))
                {
                    gdata.BjBankerBanker.ShowBankerCard0(data.GetIntArray("cards")[0]);
                    DealPokerMgr.DealAllPoker();
                }

                //庄家要牌
                if (data.ContainsKey("card"))
                {
                    DealPokerMgr.EnqueueCardInfo(gdata.BjBankerBanker, data.GetInt("card"));
                    DealPokerMgr.BeginDealCards();
                }

                break;

            case GameRequestType.Insurance:

                if (data.ContainsKey("seat"))
                {
                    int insuranceSeat = data.GetInt("seat");
                    gdata.GetPlayer <BjPlayerPanel>(insuranceSeat).BuyInsurance(data.GetInt("gold"));

                    if (insuranceSeat == SelfSeat)
                    {
                        SpeakMgr.SpeakViewActive(true);
                        SpeakMgr.InsuranceBtnEnable(false);
                    }
                }

                break;
            }
        }