Esempio n. 1
0
    private void onConnect(Socket socket, Packet packet, params object[] args)
    {
        _.Log("Unity: 连接建立成功,执行login逻辑……");

        logining = false;
        Emit(new Dictionary <string, object> {
            { "f", "login" },
            { "args", new Dictionary <string, object> {
                  { "sid", GameData.Shared.Sid }
              } }
        }, (json) => {
            _.Log("Unity: 登陆成功,准备进入房间……");

            logining = false;

            // 登陆成功,写用户数据
            saveUserInfo(json);


            // 进入房间
            EnterGame();
        }, () => {
            logining = false;
            PokerUI.ToastThenExit("连接服务器超时,请稍后再试~");
        });

        logining = true;
    }
Esempio n. 2
0
    private void registerEvents()
    {
        RxSubjects.MatchLook.Subscribe((e) => {
            var state = e.Data.Int("match_state");
            if (state >= 10)
            {
                PokerUI.ToastThenExit("未匹配到您的比赛信息");
                return;
            }

            Loading.SetActive(false);
            MTT.SetActive(true);
            MTT.GetComponent <MTTWaiting>().Init(e.Data);
        }).AddTo(this);

        RxSubjects.Look.Subscribe((e) => {
            if (loadingScene.activeInHierarchy)
            {
                loadingScene.SetActive(false);
                gameScene.transform.parent.gameObject.SetActive(true);
                gameScene.SetActive(true);

                gameScene.GetComponent <Controller>().ReEnter();

                // 打开声音发送按钮
                Commander.Shared.VoiceIconToggle(true);
            }
        }).AddTo(this);

        RxSubjects.GameReset.Subscribe((_) => {
            back2LoadingScene();
        }).AddTo(this);
    }
Esempio n. 3
0
    public void EnterGame(Action cb = null)
    {
        if (GameData.Shared.GameEnd)
        {
            return;
        }

        Dictionary <string, object> data;

        if (GameData.Shared.IsMatchState && !string.IsNullOrEmpty(GameData.Shared.MatchID))
        {
            data = new Dictionary <string, object> {
                { "matchid", GameData.Shared.MatchID },
                { "ver", Application.version },
                { "club_id", GameData.Shared.ClubID }
            };
        }
        else
        {
            data = new Dictionary <string, object> {
                { "roomid", GameData.Shared.Room.Value },
                { "ver", Application.version },
                { "club_id", GameData.Shared.ClubID }
            };
        }

        Emit(new Dictionary <string, object> {
            { "f", "entergame" },
            { "args", data }
        }, (json, err) => {
            _.Log("Unity: 进入房间逻辑执行完毕");

            if (err == 1301)
            {
                PokerUI.ToastThenExit("您被房主限制进入牌局");
            }
            else if (err != 0)
            {
                PokerUI.ToastThenExit("牌局不存在");
            }

            // 取消2s内的loading提示
            if (connectDisposa != null)
            {
                connectDisposa.Dispose();
            }

            RxSubjects.Connecting.OnNext(false);

            if (cb != null && err == 0)
            {
                cb();
            }
        }, () => {
            // PokerUI.DisAlert("连接服务器超时");
        });
    }
Esempio n. 4
0
    private void subsRpcRet()
    {
        manager.Socket.On("rpc_ret", (socket, packet, args) => {
            if (args.Length == 0)
            {
                return;
            }

            var json = args[0] as Dictionary <string, object>;

            if (json == null)
            {
                return;
            }

            var rid = json.String("roomid");
            if (!string.IsNullOrEmpty(rid) && rid != GameData.Shared.Room.Value)
            {
                return;
            }

            // @FIXME: ret可能是string?
            var ret = json.Dict("ret");
            if (ret.ContainsKey("cmds"))
            {
                GameData.MyCmd.SetCmd(ret.Dict("cmds"));
            }

            if (ret.ContainsKey("coins"))
            {
                GameData.Shared.Coins = ret.Int("coins");
            }

            var err = json.Int("err");

            // 公共错误处理
            if (err == 403)
            {
                PokerUI.ConflictAlert();
            }
            else if (err == 406 && !MatchWinner.IsSpawned)                 // 弹出获奖框时,不能提示
            {
                PokerUI.ToastThenExit("牌局不存在!");
            }
            else
            {
                int seq = json.Int("seq");
                if (instance.successCallbacks.ContainsKey(seq))
                {
                    instance.successCallbacks[seq](ret, err);
                }
            }
        });
    }
Esempio n. 5
0
 void Awake()
 {
     RxSubjects.MTTMatch.Subscribe((e) => {
         var type = e.Data.Int("type");
         if (type == 2)
         {
             PokerUI.ToastThenExit("报名人数不足,比赛已取消");
         }
         else if (type == 5)
         {
             PokerUI.ToastThenExit("比赛已取消");
         }
     }).AddTo(this);
 }
Esempio n. 6
0
    private void registerEvents()
    {
        // 只允许初始化一次
        if (isReady)
        {
            return;
        }

        GameData.Shared.LeftTime.Subscribe((value) => {
            if (!GameData.Shared.GameStarted.Value)
            {
                setText(TimeLeftGo, "未开始");
                return;
            }

            setText(TimeLeftGo, _.SecondStr(value));

            if (GameData.Shared.IsMatch())
            {
                return;
            }

            if (value > 5 * 60)
            {
                hasShowEnding = false;
            }
            else
            {
                if (!hasShowEnding)
                {
                    PokerUI.Toast("牌局将在5分钟内结束");
                }

                hasShowEnding = true;
            }
        }).AddTo(this);

        RxSubjects.UnSeat.Subscribe((e) => {
            var uid = e.Data.String("uid");
            if (uid == GameData.Shared.Uid && e.Data.Int("type") == 2)
            {
                PokerUI.Alert("您已连续3次超时,先站起来休息下吧~");
            }
        }).AddTo(this);

        GameData.Shared.Ante.Subscribe((value) => {
            setBBText();
        }).AddTo(this);

        GameData.Shared.Straddle.Subscribe((value) => {
            setBBText();
        }).AddTo(this);

        GameData.Shared.PlayerCount.Where((value) => value > 0).Subscribe((value) => {
            setupSeats(value);
        }).AddTo(this);

        RxSubjects.Connecting.Subscribe((stat) => {
            LoadingModal.transform.SetAsLastSibling();
            LoadingModal.SetActive(stat);
        }).AddTo(this);

        RxSubjects.Seating.Subscribe((action) =>
        {
            foreach (var go in Seats)
            {
                var seat = go.GetComponent <Seat>();
                if (action)
                {
                    seat.Hide();
                }
                else if (!GameData.Shared.Players.ContainsKey(seat.Index))
                {
                    seat.Show();
                }
            }
            ExpressionButton.SetActive(action);
        }).AddTo(this);

        subsPublicCards();
        subsPlayer();
        subsRoomSetting();

        RxSubjects.GameReset.Subscribe((_) => {
            infoGo.SetActive(false);
            PokerUI.DestroyElements();
        }).AddTo(this);

        RxSubjects.Emoticon.Subscribe((e) =>
        {
            if (GameSetting.emoticonClose)
            {
                return;
            }

            int fromSeatIndex = e.Data.Int("seat");
            int toSeatIndex   = e.Data.Int("toseat");
            int pid           = e.Data.Int("pid");
            int[] canTurnEmo  = { 4, 5, 6, 7, 10, 12 };
            bool isToMe       = false;

            var fromSeatPos = new Vector2(0, 1920);
            var toSeat      = Seats[0];

            foreach (var seat in Seats)
            {
                if (seat.GetComponent <Seat>().Index == fromSeatIndex && fromSeatIndex > -1)
                {
                    fromSeatPos = seat.GetComponent <RectTransform>().anchoredPosition;
                }

                if (seat.GetComponent <Seat>().Index == toSeatIndex)
                {
                    toSeat = seat;

                    if (toSeatIndex == GameData.Shared.FindPlayerIndex(GameData.Shared.Uid))
                    {
                        isToMe = true;
                    }
                }
            }
            var em = PoolMan.Spawn("Emoticon/Emo" + pid);
            em.GetComponent <Emoticon>().Init(fromSeatPos, toSeat, isToMe, canTurnEmo.Contains(pid));
        }).AddTo(this);

        var expressions = new Dictionary <string, Transform>();

        RxSubjects.Expression.Subscribe((e) => {
            var expressionName = e.Data.String("expression");
            var uid            = e.Data.String("uid");

            if (expressions.ContainsKey(uid))
            {
                PoolMan.Despawn(expressions[uid]);
                expressions.Remove(uid);
            }

            var expression   = PoolMan.Spawn("Expression");
            expressions[uid] = expression;             // 保存起来

            Transform parent;

            if (uid == GameData.Shared.Uid)
            {
                parent = ExpressionButton.transform;
                //有可能出现点击表情时,玩家已经站起的现象
                if (!parent.gameObject.activeInHierarchy)
                {
                    return;
                }
            }
            else
            {
                var seatIndex = e.Data.Int("seat");
                var aimSeat   = Seats[0];

                foreach (var seat in Seats)
                {
                    if (seat.GetComponent <Seat>().Index == seatIndex)
                    {
                        aimSeat = seat;
                        break;
                    }
                }

                parent = aimSeat.GetComponentInChildren <PlayerOppo>().transform;
            }

            expression.GetComponent <Expression>().SetTrigger(expressionName, parent, () => {
                expressions.Remove(uid);
            });
        }).AddTo(this);

        RxSubjects.MatchLook.Subscribe((e) => {
            if (GameData.Shared.Type.Value != GameType.MTT)
            {
                return;
            }

            var state = e.Data.Int("match_state");

            // 比赛未开始
            if (state < 10)
            {
                return;
            }

            var myself = e.Data.Dict("myself");
            if (myself.Int("rank") >= 0)
            {
                PokerUI.ToastThenExit("您已被淘汰");
            }
        }).AddTo(this);

        RxSubjects.MatchRank.Subscribe((json) => {
            // 输了之后以游客身份旁观
            GameData.Shared.IsMatchState = false;

            var SNGWinner = PoolMan.Spawn("MatchWinner");
            SNGWinner.GetComponent <DOPopup>().ShowModal(new Color(0, 0, 0, 0.6f), closeOnClick: false);
            SNGWinner.GetComponent <MatchWinner>().Init(json.Data);
        }).AddTo(this);

        RxSubjects.ShowAudio.Where(isGuest).Subscribe((json) => {
            var N    = JSON.Parse(json);
            var name = N["name"].Value;
            SpkText.ShowMessage(String.Format("{0}发送了一段语音", name));
        }).AddTo(this);

        RxSubjects.SendChat.Where(isGuest).Subscribe((json) => {
            var N    = JSON.Parse(json);
            var name = N["name"].Value;
            var text = N["text"].Value;

            SpkText.ShowMessage(String.Format("{0}: {1}", name, text));
        }).AddTo(this);

        RxSubjects.Award27.Subscribe((e) => {
            var win27Emo = PoolMan.Spawn("Win27Emo");
            win27Emo.transform.SetParent(G.UICvs.transform, false);
            win27Emo.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
        }).AddTo(this);

        RxSubjects.GameOver.Subscribe((e) => {
            if (GameData.Shared.IsMatch())
            {
                return;
            }

            var type  = GameData.Shared.Type.Value;
            var count = GameData.Shared.PublicCards.Count;

            if (count < 5 && type != GameType.KingThree)
            {
                SeeLeftCard.SetActive(true);
            }
            else if (count < 3 && type == GameType.KingThree)
            {
                SeeLeftCard.SetActive(true);
            }
        }).AddTo(this);

        RxSubjects.GameStart.Subscribe((e) => {
            gameReload();
            infoGo.SetActive(false);
        }).AddTo(this);

        RxSubjects.Look.Subscribe((e) => {
            gameReload();

            if (GameData.Shared.InGame)
            {
                infoGo.SetActive(false);
            }
        }).AddTo(this);

        RxSubjects.Pass.Subscribe((e) => {
            var type = GameData.Shared.Type.Value;

            if (!GameData.Shared.IsMatch())
            {
                var msg = "记分牌带入成功";

                if (GameData.Shared.InGame)
                {
                    msg += "(下一手生效)";
                }
                PokerUI.Toast(msg);
            }
            else if (type == GameType.SNG)
            {
                PokerUI.Toast("报名成功");
            }
            else if (type == GameType.MTT)
            {
                var inc = e.Data.Int("inc_bankroll");
                PokerUI.Toast(string.Format("成功购买{0}记分牌(下一手生效)", inc));
            }
        }).AddTo(this);

        RxSubjects.SomeOneSeeCard.Subscribe((e) => {
            var name = e.Data.String("name");

            var go   = (GameObject)GameObject.Instantiate(SeeCardTips, G.UICvs.transform);
            var cvg  = go.GetComponent <CanvasGroup>();
            var text = go.transform.Find("Text").GetComponent <Text>();

            text.text = String.Format("<color=#4FC3F7FF>{0}</color>看了剩余公共牌", name);

            go.SetActive(true);
            cvg.alpha = 0;
            go.transform.SetParent(SeeCardTable.transform);

            cvg.DOFade(1, 0.2f).OnComplete(() => {
                Observable.Timer(TimeSpan.FromSeconds(2.5)).Subscribe((tmp) => {
                    cvg.DOFade(0, 0.2f).OnComplete(() => {
                        Destroy(go);
                    });
                }).AddTo(this);
            });
        }).AddTo(this);

        RxSubjects.ToInsurance.Subscribe((e) =>
        {
            GameData.Shared.InsuranceState.Value = true;

            var InsurancePopup = PoolMan.Spawn("Insurance");
            InsurancePopup.GetComponent <Insurance>().Init(e.Data, true);
        }).AddTo(this);

        RxSubjects.ShowInsurance.Subscribe((e) =>
        {
            var InsurancePopup = PoolMan.Spawn("Insurance");
            InsurancePopup.GetComponent <Insurance>().Init(e.Data, false);
        }).AddTo(this);

        RxSubjects.RaiseBlind.Subscribe((e) => {
            var bb = e.Data.Int("big_blind");
            var cd = e.Data.Int("blind_countdown");

            GameData.Shared.BB = bb;
            GameData.Shared.LeftTime.OnNext(cd);
            GameData.Shared.Ante.Value = e.Data.Int("ante");
            setBBText();

            PokerUI.Toast(string.Format("盲注已升至{0}/{1}", bb / 2, bb));

            if (GameData.Shared.Type.Value == GameType.MTT)
            {
                var lv = e.Data.Int("blind_lv");

                // 下一级别无法重购
                if (lv == GameData.MatchData.LimitLv - 2)
                {
                    PokerUI.Toast("本级别过后将无法再重购");
                }
                else if (lv == GameData.MatchData.LimitLv - 1)
                {
                    PokerUI.Toast("本级别过后将无法再增购");
                }
            }
        }).AddTo(this);

        RxSubjects.OffScore.Subscribe((e) => {
            var type = e.Data.Int("type");
            if (type == 0)
            {
                PokerUI.Toast("您已提前下分,将在本局结束后结算");
                return;
            }

            if (type != 1)
            {
                return;
            }

            var name   = e.Data.String("name");
            var avatar = e.Data.String("avatar");

            var dt       = e.Data.Dict("data");
            var takecoin = dt.Int("takecoin");
            var profit   = dt.Int("bankroll") - takecoin;

            PoolMan.Spawn("OffScore").GetComponent <OffScore>().Show(avatar, takecoin, profit);

            // 已下分,bankroll为0
            GameData.Shared.Bankroll.Value = 0;
        }).AddTo(this);

        RxSubjects.ToAddOn.Subscribe((e) => {
            var go = PoolMan.Spawn("RebuyOrAddon");
            go.GetComponent <DOPopup>().Show(closeOnClick: false);
            go.GetComponent <RebuyOrAddon>().AddOn(true);
        }).AddTo(this);

        RxSubjects.ToRebuy.Subscribe((e) =>
        {
            var go = PoolMan.Spawn("RebuyOrAddon");
            go.GetComponent <DOPopup>().Show(closeOnClick: false);
            go.GetComponent <RebuyOrAddon>().Rebuy(true);
        }).AddTo(this);

        RxSubjects.GameEnd.Subscribe((e) => {
            // 关闭连接
            Connect.Shared.CloseImmediate();

            if (MatchWinner.IsSpawned)
            {
                return;
            }

            // 获取roomID,调用ExitCb后无法获取
            var roomID  = GameData.Shared.Room.Value;
            var matchID = GameData.Shared.MatchID;
            var ID      = "";
            var page    = "";
            // 清理
            External.Instance.ExitCb(() => {
                switch (GameData.Shared.Type.Value)
                {
                case GameType.SNG:
                    ID   = roomID;
                    page = "record_sng.html";
                    break;

                case GameType.MTT:
                    ID   = matchID;
                    page = "record_mtt.html";
                    break;

                default:
                    ID   = roomID;
                    page = "record.html";
                    break;
                }

                Commander.Shared.GameEnd(ID, page);
            });
        }).AddTo(this);

        RxSubjects.MTTMatch.Subscribe((e) => {
            if (GameData.Shared.Type.Value != GameType.MTT)
            {
                return;
            }

            var type = e.Data.Int("type");

            if (type == 3)
            {
                var player = GameData.Shared.GetMyPlayer();

                if (player.IsValid())
                {
                    return;
                }

                var roomId = e.Data.String("data");
                Connect.Shared.Enter(roomId, () => {
                    getRoomEnter();
                });
            }
            else if (type == 6)
            {
                PokerUI.Toast("即将进入钱圈");
            }
        }).AddTo(this);
        // Connect.Shared.Enter(GameData.Shared.Room.Value, () => {
        //  getRoomEnter();
        // });
    }