Example #1
0
    public void reset()
    {
        info      = new RoomInfo();
        conf      = new RoomConf();
        players   = new List <PlayerInfo> ();
        state     = new GameState();
        seats     = new List <SeatInfo> ();
        action    = new GameAction();
        overinfo  = new GameOverInfo();
        histories = new List <GameOverInfo>();

        dissolve = null;
    }
Example #2
0
    void InitHandler()
    {
        NetMgr       net = NetMgr.GetInstance();
        RoomMgr      rm  = RoomMgr.GetInstance();
        PomeloClient pc  = net.pc;

        pc.on("login_result", data => {
            Debug.Log("login_result");

            object ob;
            if (!data.TryGetValue("errcode", out ob))
            {
                return;
            }

            int ret = Convert.ToInt32(ob);
            if (ret != 0)
            {
                Debug.Log("login_result ret=" + ret);
                return;
            }

            JsonObject room = (JsonObject)data["data"];

            rm.updateRoom(room);

            DispatchEvent("game_reset");
        });

        pc.on("login_finished", data => {
            Debug.Log("login_finished");

            string table = "04.table3d";
            string name  = SceneManager.GetActiveScene().name;

            if (name != table)
            {
                mHandlerMap.Clear();
                LoadingScene.LoadNewScene(table);
            }
            else
            {
                if (rm.isPlaying())
                {
                    net.send("ready");
                }
            }
        });

        pc.on("exit_result", data => {
            string reason = (string)data["reason"];

            if (reason == "kick")
            {
                GameAlert.GetInstance().show("您已被管理员请出房间", () => {
                    GameManager.GetInstance().exit();
                });
            }
            else if (reason == "request")
            {
                GameManager.GetInstance().exit();
            }
        });

        pc.on("exit_notify_push", data => {
            int uid       = Convert.ToInt32(data["value"]);
            int seatindex = rm.userExit(uid);

            DispatchEvent("user_state_changed", seatindex);
        });

        pc.on("dispress_push", data => {
            GameManager.GetInstance().exit();
        });

        pc.on("new_user_comes_push", data => {
            int seatindex = rm.newUserCome(data);

            DispatchEvent("user_state_changed", seatindex);
        });

        pc.on("user_state_push", data => {
            int seatindex = rm.updateUser(data);

            DispatchEvent("user_state_changed", seatindex);
        });

        pc.on("game_wait_maima_push", data => {
            rm.updateMaima(data);

            DispatchEvent("game_wait_maima");
        });

        pc.on("game_maima_push", data => {
            rm.updateMaima(data);

            DispatchEvent("game_maima");
        });

        pc.on("user_ready_push", data => {
            int seatindex = rm.updateUser(data);

            DispatchEvent("user_state_changed", seatindex);
        });

        pc.on("game_dice_push", data => {
            rm.updateState(data);

            DispatchEvent("game_dice");
        });

        pc.on("game_holds_push", data => {
            Debug.Log("get game_holds_push");

            int si = rm.updateSeat(data);
            DispatchEvent("game_holds", si);
        });

        pc.on("game_holds_len_push", data => {
            Debug.Log("get game_holds_len_push");

            int si = rm.updateSeat(data);

            DispatchEvent("game_holds_len", si);
        });

        pc.on("game_state_push", data => {
            rm.updateState(data);

            DispatchEvent("game_state");
        });

        pc.on("game_begin_push", data => {
            Debug.Log("get game_begin_push");

            rm.newRound();
            rm.updateState(data);

            foreach (PlayerInfo p in rm.players)
            {
                p.ready = false;
                DispatchEvent("user_state_changed", p.seatindex);
            }

            DispatchEvent("game_begin");
        });

        pc.on("game_playing_push", data => {
            Debug.Log("get game_playing_push");
            rm.updateState(data);

            DispatchEvent("game_playing");
        });

        pc.on("game_sync_push", data => {
            Debug.Log("get game_sync_push");

            if (!data.ContainsKey("pseudo"))
            {
                rm.updateState(data);
                rm.updateSeats((JsonArray)data["seats"]);
            }

            DispatchEvent("user_hf_updated");
            DispatchEvent("game_sync");
        });

        pc.on("hangang_notify_push", data => {
            int seatindex = Convert.ToInt32(data["seatindex"]);
            DispatchEvent("hangang_notify", seatindex);
        });

        pc.on("game_action_push", data => {
            Debug.Log("get game_action_push");
            rm.updateAction(data);

            DispatchEvent("game_action");
        });

        pc.on("game_chupai_push", data => {
            Debug.Log("get game_chupai_push");
            rm.updateState(data);

            ChupaiPush cp = JsonUtility.FromJson <ChupaiPush> (data.ToString());
            rm.updateLimit(cp.turn, cp.limit);

            if (cp.bg == true)
            {
                return;
            }

            DispatchEvent("game_turn_change");
        });

        pc.on("game_num_push", data => {
            rm.updateRoomInfo(data);

            DispatchEvent("game_num");
        });

        pc.on("game_over_push", data => {
            rm.updateOverInfo(data);

            DispatchEvent("game_over");
        });

        pc.on("mj_count_push", data => {
            rm.updateState(data);

            if (data.ContainsKey("bg"))
            {
                return;
            }

            DispatchEvent("mj_count");
        });

        pc.on("hu_push", data => {
            HuPushInfo info = rm.updateHu(data);

            if (info.bg)
            {
                return;
            }

            DispatchEvent("hupai", info);
        });

        pc.on("game_chupai_notify_push", data => {
            Debug.Log("get game_chupai_notify_push");
            ActionInfo info = rm.doChupai(data);

            if (info.bg == true)
            {
                return;
            }

            DispatchEvent("game_chupai_notify", info);
        });

        pc.on("game_hf_push", data => {
            rm.updateFlowers(data);

            Debug.Log("get game_hf_push");

            DispatchEvent("user_hf_updated");
        });

        pc.on("game_af_push", data => {
            ActionInfo info = rm.doAddFlower(data);

            if (info.bg == true)
            {
                return;
            }

            DispatchEvent("user_hf_updated", info);
        });

        pc.on("game_mopai_push", data => {
            Debug.Log("get game_mopai_push");
            ActionInfo info = rm.doMopai(data);

            if (info.bg == true)
            {
                return;
            }

            DispatchEvent("game_mopai", info);
        });

        pc.on("guo_notify_push", data => {
            Debug.Log("get guo_notify_push");
            ActionInfo info = rm.doGuo(data);

            if (info.bg == true)
            {
                return;
            }

            DispatchEvent("guo_notify", info);
        });

        pc.on("guo_result", data => {
            Debug.Log("get guo_result");
            DispatchEvent("guo_result");
        });

        pc.on("peng_notify_push", data => {
            ActionInfo info = rm.doPeng(data);

            if (info.bg == true)
            {
                return;
            }

            DispatchEvent("peng_notify", info);
        });

        pc.on("chi_notify_push", data => {
            ActionInfo info = rm.doChi(data);

            if (info.bg == true)
            {
                return;
            }

            DispatchEvent("chi_notify", info);
        });

        pc.on("gang_notify_push", data => {
            GangInfo info = rm.doGang(data);

            if (info.bg == true)
            {
                return;
            }

            DispatchEvent("gang_notify", info);
        });

        pc.on("ting_notify_push", data => {
            TingInfo info = rm.doTing(data);

            if (info.bg == true)
            {
                return;
            }

            DispatchEvent("ting_notify", info.seatindex);
        });

        pc.on("chat_push", data => {
            ChatInfo info = JsonUtility.FromJson <ChatInfo>(data.ToString());

            DispatchEvent("chat", info);
        });

        pc.on("quick_chat_push", data => {
            QuickChatInfo info = JsonUtility.FromJson <QuickChatInfo>(data.ToString());

            DispatchEvent("quick_chat_push", info);
        });

        pc.on("emoji_push", data => {
            EmojiPush info = JsonUtility.FromJson <EmojiPush>(data.ToString());
            DispatchEvent("emoji_push", info);
        });

        pc.on("demoji_push", data => {
            Debug.Log("get demoji_push");
            DEmojiPush info = JsonUtility.FromJson <DEmojiPush>(data.ToString());
            DispatchEvent("demoji_push", info);
        });

        pc.on("dissolve_notice_push", data => {
            DissolveInfo dv = JsonUtility.FromJson <DissolveInfo>(data.ToString());
            rm.dissolve     = dv;

            DispatchEvent("dissolve_notice", dv);
        });

        pc.on("dissolve_done_push", data => {
            Debug.Log("dissolve_done_push");
            DispatchEvent("dissolve_done");
        });

        pc.on("dissolve_cancel_push", data => {
            Debug.Log("dissolve_cancel_push");

            DissolveCancel dc = JsonUtility.FromJson <DissolveCancel>(data.ToString());

            DispatchEvent("dissolve_cancel", dc);
        });

        pc.on("voice_msg_push", data => {
            VoiceMsgPush vm = JsonUtility.FromJson <VoiceMsgPush>(data.ToString());
            DispatchEvent("voice_msg", vm);
        });

        pc.on("start_club_room", data => {
        });

        pc.on("club_room_updated", data => {
            DispatchEvent("club_room_updated", data);
        });

        pc.on("clu_room_removed", data => {
            DispatchEvent("clu_room_removed", data);
        });

        pc.on("club_message_notify", data => {
            ClubMessageNotify ret = JsonUtility.FromJson <ClubMessageNotify>(data.ToString());

            sclub_message_notify = ret;

            DispatchEvent("club_message_notify", ret);
        });

        pc.on("sys_message_updated", data => {
            DispatchEvent("sys_message_updated", data);
        });

        pc.on("recommend_room_updated", data => {
            Debug.Log("recommend_room_updated");
            DispatchEvent("recommend_room_updated", data);
        });
    }
Example #3
0
    void showDissolveNotice(DissolveInfo dv)
    {
        RoomMgr rm = RoomMgr.GetInstance();

        mDissolve.SetActive(true);

        int now = (int)((DateTime.Now.Ticks - DateTime.Parse("1970-01-01").Ticks) / 10000000);

        mEndTime = dv.time + now;

        UIGrid grid = mSeats[0].GetComponentInParent <UIGrid>();

        int index = 0;

        for (int i = 0; i < rm.players.Count && i < mSeats.Count; i++, index++)
        {
            Transform  s = mSeats[i];
            PlayerInfo p = rm.players[i];

            s.gameObject.SetActive(true);
            s.Find("bghead/icon").GetComponent <IconLoader>().setUserID(p.userid);
            s.Find("name").GetComponent <UILabel>().text = p.name;
        }

        for (int i = index; i < mSeats.Count; i++)
        {
            mSeats[i].gameObject.SetActive(false);
        }

        string[] descs = new string[] { "等待中", "已拒绝", "已同意", "离线", "申请解散" };

        for (int i = 0; i < rm.players.Count && i < mSeats.Count; i++)
        {
            Transform status = mSeats [i].Find("status");

            UILabel   desc  = status.GetComponentInChildren <UILabel>();
            SpriteMgr sm    = status.Find("icon").GetComponent <SpriteMgr>();
            int       state = dv.states[i];
            int       id    = 0;

            if (state > 2)
            {
                id = 4;
            }

            bool online = dv.online[i];
            if (state <= 2)
            {
                if (!online)
                {
                    id = 3;
                }
                else
                {
                    id = state;
                }
            }

            sm.setIndex(id);
            desc.text = descs[id];
        }

        grid.Reposition();

        int si = rm.seatindex;
        int st = dv.states[si];

        bool[] check = new bool[] { false, false, false, false };

        if (dv.reason == "offline")
        {
            check [2] = true;
        }
        else
        {
            if (0 == st)
            {
                check [0] = true;
                check [1] = true;
            }
            else
            {
                check [3] = true;
            }
        }

        mBtnAgree.SetActive(check[0]);
        mBtnReject.SetActive(check[1]);
        mBtnDissolve.SetActive(check[2]);
    }