Exemple #1
0
    public Transform GetHandGroupUI(Transform parentT, List <byte> cards)
    {
        Transform tran = GetGroupUI();

        if (null == tran)
        {
            return(null);
        }
        //cards.Sort(delegate(Student a, Student b) { return a.Age.CompareTo(b.Age); });
        cards.Sort();
        tran.parent = parentT;
        tran.gameObject.SetActive(true);
        UIGroupCardsView      rview      = tran.gameObject.GetComponent <UIGroupCardsView> () ?? tran.gameObject.AddComponent <UIGroupCardsView>();
        HorizontalLayoutGroup layerGroup = tran.gameObject.GetComponent <HorizontalLayoutGroup> ();

        //layerGroup.spacing = -3;
        for (int i = 0; i < cards.Count; i++)
        {
            UICardView cview = rview._cardViews [i];
            TileDef    def   = TileDef.Create(cards[i]);
            cview._imgMj.sprite = UIOperation.Instance.GetMJSprite(def);
            cview.gameObject.SetActive(true);
            cview._imgbsBG.gameObject.SetActive(false);
            cview._textX.gameObject.SetActive(false);
            cview._textNum.gameObject.SetActive(false);
        }
        return(tran);
    }
Exemple #2
0
    public Transform GetHuGroupUI(Transform parentT, List <GameMessage.HuCards> huCards)
    {
        Transform tran = GetGroupUI();

        if (null == tran)
        {
            return(null);
        }
        tran.parent = parentT;
        tran.gameObject.SetActive(true);
        HorizontalLayoutGroup layerGroup = tran.gameObject.GetComponent <HorizontalLayoutGroup> ();
        //layerGroup.spacing = -1;

        UIGroupCardsView rview = tran.gameObject.GetComponent <UIGroupCardsView> () ?? tran.gameObject.AddComponent <UIGroupCardsView>();

        for (int i = 0; i < huCards.Count; i++)
        {
            UICardView cview = rview._cardViews [i];
            TileDef    def   = TileDef.Create(huCards[i].cCard);
            cview._imgMj.sprite = UIOperation.Instance.GetMJSprite(def);
            cview.gameObject.SetActive(true);
            cview._imgbsBG.gameObject.SetActive(true);
            cview._textX.gameObject.SetActive(true);
            cview._textNum.gameObject.SetActive(true);
            cview._textNum.text = huCards[i].cNum.ToString();
        }
        return(tran);
    }
Exemple #3
0
    public Transform GetPengGroupUI(Transform parentT, byte card, byte specialType)
    {
        Transform tran = GetGroupUI();

        if (null == tran)
        {
            return(null);
        }
        tran.parent = parentT;
        tran.gameObject.SetActive(true);
        HorizontalLayoutGroup layerGroup = tran.gameObject.GetComponent <HorizontalLayoutGroup> ();
        //layerGroup.spacing = -4;
        int cardNum = 0;

        switch (specialType)
        {
        case (byte)GameMessage.SPECIAL_TYPE.PONG:
            cardNum = 3;
            break;

        case (byte)GameMessage.SPECIAL_TYPE.KONG:
            cardNum = 4;
            break;

        case (byte)GameMessage.SPECIAL_TYPE.DARK_KONG:
            cardNum = 4;
            break;

        case (byte)GameMessage.SPECIAL_TYPE.SPECIAL_TYPE_PENGGANG:
            cardNum = 4;
            break;
        }
        UIGroupCardsView rview = tran.gameObject.GetComponent <UIGroupCardsView> () ?? tran.gameObject.AddComponent <UIGroupCardsView>();

        for (int i = 0; i < cardNum; i++)
        {
            if (i == 3)
            {
                break;
            }
            UICardView cview = rview._cardViews [i];
            TileDef    def   = TileDef.Create(card);
            cview._imgMj.sprite = UIOperation.Instance.GetMJSprite(def);
            cview.gameObject.SetActive(true);
            cview._imgbsBG.gameObject.SetActive(false);
            cview._textX.gameObject.SetActive(false);
            cview._textNum.gameObject.SetActive(false);
            if (cardNum == 4 && i == 1)
            {
                Transform gangTran = cview.transform.Find("img_gang");
                if (gangTran)
                {
                    gangTran.gameObject.SetActive(true);
                    gangTran.Find("img_mj").GetComponent <Image> ().sprite = cview._imgMj.sprite;
                }
            }
        }
        return(tran);
    }
    public void OnClickHuanpai(UIController ctrl)
    {
        MahjongTile.TotalClickCount = 1;
        UIGameSetingController seting = (UIGameSetingController)ctrl;

        seting.CloseHuanpaiTips();

        List <byte> cards = new List <byte> ();


        MahjongUserPlayer userPlayer = GameClient.Instance.MG.Self as MahjongUserPlayer;
        bool checkSelect             = true;

        if (userPlayer != null)
        {
            List <MahjongTile> mahjongTiles = userPlayer.Clicked;
            if (mahjongTiles.Count > 0)
            {
                TileDef.Kind kind = mahjongTiles [0].Def.GetKind();
                foreach (var temp in mahjongTiles)
                {
                    if (kind != temp.Def.GetKind())
                    {
                        checkSelect = false;
                    }
                    cards.Add(temp.Def.Value);
                }
            }
        }

        if (cards.Count == 0 || !checkSelect)
        {
            foreach (var temp in _HuanPaiOldDef)
            {
                cards.Add(temp.Value);
            }
        }
        else
        {
            for (int i = 0; i < GameMessage.MAXHUANPAINUM; i++)
            {
                if (i < cards.Count)
                {
                    _HuanPaiOldDef [i] = TileDef.Create(cards[i]);
                }
            }
        }

        GameClient.Instance.MG.Self.Proxy.Huanpai(cards);
    }
Exemple #5
0
    public void SetPocketCount(int index, int num)
    {
        MahjongPlayer player = _playPlayers [index];

        if (player != _self)
        {
            if (player.Proxy.PocketList.Count > num)
            {
                int count = player.Proxy.PocketList.Count - num;
                player.Proxy.RemovePocketList(count);
            }
            else if (player.Proxy.PocketList.Count < num)
            {
                for (int i = 0; i < (num - player.Proxy.PocketList.Count); ++i)
                {
                    player.Proxy.PocketList.Add(TileDef.Create());
                }
            }
        }
    }
Exemple #6
0
    //dealer and opposite dealer are 14 tons, others are 13tons
    public List <TileDef> RebuildStack(int a, int b, int count, int drawFront, int drawBehind)
    {
        int stackIndex = 0;
        int pointMin   = Math.Min(a, b);
        int pointSum   = a + b;
        int skipCount  = pointMin * 2;        // pointMin tons to keep

        // 4, 8, 12, banker's left
        if (pointSum % 4 == 0)
        {
            stackIndex = 3;
        }
        // 2, 6, 10, banker's right
        else if (pointSum % 2 == 0)
        {
            stackIndex = 1;
        }
        // 1, 3, 5, 7, 9, 11, banker's front
        else
        {
            stackIndex = 2;
        }

        _wall.Clear();
        for (int i = 0; i < count; ++i)
        {
            _wall.Add(TileDef.Create((byte)0x11));
        }

        /*
         * for (int i = 0; i < _playPlayers.Length; ++i) {
         *      _players [i] = _playPlayers [i];
         * }
         *
         * //hard code
         * if (_playPlayers.Length == 3) {
         *      if (_players [0] == _self) {
         *              _players [3] = _players [2];
         *              _players [2] = _front;
         *      } else if (_players [1] == _self) {
         *              _players [3] = _front;
         *      } else if (_players [2] == _self) {
         *              _players [0] = _right;
         *              _players [1] = _front;
         *              _players [2] = _left;
         *              _players [3] = _self;
         *      }
         * }
         *
         * int stackCount = _players [stackIndex].GetStack ().Count;
         * _wall.Clear ();
         * _wall.AddRange (_players [stackIndex].GetStack (skipCount, stackCount - skipCount));
         * _wall.AddRange (_players [(stackIndex + 3) % 4].GetStack ());
         * _wall.AddRange (_players [(stackIndex + 2) % 4].GetStack ());
         * _wall.AddRange (_players [(stackIndex + 1) % 4].GetStack ());
         * _wall.AddRange (_players [stackIndex].GetStack (0, skipCount));
         *
         * UIControllerGame.Instance.SetPaiRestInfo (_wall.Count);
         * UIControllerGame.Instance.RefreshPaiRestInfo ();
         */
        return(_wall);
    }
Exemple #7
0
    public void OnRestoreGameState(GameMessage.GameStateDef info)
    {
        _self.Proxy.PocketList.Clear();
        // total 14
#if USE_MP2
        for (int i = 0; i < info.cHandCards.Count; ++i)
#else
        for (int i = 0; i < info.cHandCards.Length; ++i)
#endif

        {
            if (TileDef.IsValid(info.cHandCards[i]))
            {
                TileDef def = TileDef.Create(info.cHandCards[i]);
                _self.Proxy.PocketList.Add(def);
            }
        }
#if USE_MP2
        //玩家已经出的牌
        //List<List<TileDef>> lists = new List<List<TileDef>>();
        List <TileDef>[] lists = new List <TileDef> [4];
        for (int i = 0; i < GameMessage.TABLE_PLAYER_NUM; ++i)
        {
            lists[i] = new List <TileDef>();
            for (int j = 0; j < info.cSendCards[i].cCards.Count; ++j)
            {
                byte card = info.cSendCards[i].cCards[j];
                lists[i].Add(TileDef.Create(card));
            }
        }
        GameClient.Instance.MG.ArrangePlayer(_self.Proxy.Index, 4);
        GameClient.Instance.MG.ReBuildStack(3, 5, 108, 0, 0);
        for (int i = 0; i < info.cHandCardsNum.Count; ++i)
        {
            GameClient.Instance.MG.SetPocketCount(i, info.cHandCardsNum[i]);
        }
        for (int i = 0; i < GameMessage.TABLE_PLAYER_NUM; ++i)
        {
            GameClient.Instance.MG.SetPlayList(i, lists[i]);
        }
#else
        //玩家已经出的牌
        List <TileDef> list = new List <TileDef>();
        for (int i = 0; i < GameMessage.TABLE_PLAYER_NUM; ++i)
        {
            for (int j = 0; j < 21; ++j)
            {
                //byte card = info.cSendCards[i * 21 + j];
                byte card = info.cSendCards[i * 21 + j];
                list.Add(TileDef.Create(card));
            }
        }
        GameClient.Instance.MG.ArrangePlayer(_self.Proxy.Index, 4);
        GameClient.Instance.MG.ReBuildStack(3, 5, 108, 0, 0);

        //reset pocket data
        for (int i = 0; i < info.cHandCardsNum.Length; ++i)
        {
            GameClient.Instance.MG.SetPocketCount(i, info.cHandCardsNum[i]);
        }

        for (int i = 0; i < GameMessage.TABLE_PLAYER_NUM; ++i)
        {
            var newList = list.GetRange(i * 21, 21);
            GameClient.Instance.MG.SetPlayList(i, newList);
        }
#endif

        //combo
        for (int i = 0; i < GameMessage.TABLE_PLAYER_NUM; ++i)
        {
            var comboCards = info.combo[i];
            //for (int j = 0; j < comboCards.list.Count; ++j) {
            //SpecialCardReqDef special = comboCards [j];
            //combo
            //}
        }

        UpdatePlayList();
        UpdatePocketList();
        UpdateComboList();
        if (GameClient.Instance.SpecialCard > 0 && GameClient.Instance.SpecialType > 0)
        {
            UpdateCombo();
        }
    }
Exemple #8
0
    //deprecated later for lua
    IEnumerator shuffleAndInitPocket(/*GameInitPush? gip*/)
    {
        Debug.Log("!!!!!!!!!!!!!!!!!!!!!shuffleAndInitPocket");
        int a = 3;        //gip.Value.Dice (0);
        int b = 5;        //gip.Value.Dice (1);

        _shuffle_initpocket_state = 0;

        //UIControllerGame.Instance.SetPaiRestInfo (_wall.Count);
        //UIControllerGame.Instance.RefreshPaiRestInfo ();

        Transform dice = poolMahjongRes.Spawn("DiceGroup");

        ActionBase act = MoveBy.Create(1f, Vector3.down * MahjongTile.Height * 2);

        ActionManager.Instance.RunAction(_slot.gameObject, act);
        yield return(new WaitForSeconds(1f));

        for (int i = 0; i < _playPlayers.Length; ++i)
        {
            _players [i] = _playPlayers [i];
        }

        //hard code
        if (_playPlayers [_dealerIndex] == _self)
        {
            for (int i = 0; i < _playPlayers.Length; ++i)
            {
                if (_playPlayers [i] != _self)
                {
                    for (int j = 0; j < 13; ++j)
                    {
                        _playPlayers [i].Proxy.PocketList.Add(TileDef.Create());
                    }
                }
            }
        }
        else
        {
            for (int i = 0; i < _playPlayers.Length; ++i)
            {
                if (_playPlayers [i] != _self)
                {
                    if (i == _dealerIndex)
                    {
                        for (int j = 0; j < 14; ++j)
                        {
                            _playPlayers [j].Proxy.PocketList.Add(TileDef.Create());
                        }
                    }
                    else
                    {
                        for (int j = 0; j < 13; ++j)
                        {
                            _playPlayers [j].Proxy.PocketList.Add(TileDef.Create());
                        }
                    }
                }
            }
        }
        if (_playPlayers.Length == 3)
        {
            if (_players [0] == _self)
            {
                _players [3] = _players [2];
                _players [2] = _front;
            }
            else if (_players [1] == _self)
            {
                _players [3] = _front;
            }
            else if (_players [2] == _self)
            {
                _players [0] = _right;
                _players [1] = _front;
                _players [2] = _left;
                _players [3] = _self;
            }
        }

        //dealer and opposite dealer are 14 tons, others are 13tons
        _pile.RebuildStack(a, b, 108, 0, 0);
        int offset = _self.SetupStack(_pile, 0, 14 * 2);

        offset += _right.SetupStack(_pile, offset, 13 * 2);
        offset += _front.SetupStack(_pile, offset, 14 * 2);
        _left.SetupStack(_pile, offset, 13 * 2);

        act = MoveTo.Create(1f, _slotOriginal);
        ActionManager.Instance.RunAction(_slot.gameObject, act);

        yield return(new WaitForSeconds(1f));

        // dice sound
        //AudioManager.Instance.PlaySound (AudioManager.Instance.Tou_Zi);
        DiceController.Instance.ThrowDice(a, b);

        Debug.Log("******" + DiceController.Instance.DiceDone);

        yield return(new WaitUntil(() => DiceController.Instance.DiceDone == true));

        Debug.Log("Dice -> " + a + "," + b);

        for (int i = 0; i < 4; ++i)
        {
            _playPlayers [i].InitDraw(i == _dealerIndex);
        }

        //TableController.Instance.SetCurrentPlayer (GetPlayerDisplayIndex (_playPlayers [0]));

        // despawn dice
        poolMahjongRes.Despawn(dice, poolMahjongRes.transform);

        for (int i = 0; i < 4; ++i)
        {
            yield return(new WaitUntil(() => _playPlayers [i].InitDrawFinished == true));
        }

        _shuffle_initpocket_state = 1;

        //UIControllerGame.Instance.OpenRefreshButton ();

        Debug.Log("@shuffleAndInitPocket");
    }
Exemple #9
0
//    public void setHuPrompt(List<UIOperation.HUPROMPT_INFO> hupaiInfo)
//    {
//        UIOperation.Instance.hupai_infos = hupaiInfo;
//
//    }
//    public void setHuPromptAndOnRefresh(List<UIOperation.HUPROMPT_INFO> hupaiInfo)
//    {
//        setHuPrompt(hupaiInfo);
//        OnRefreshItem();
//    }
    public void OnRefreshItem(TileDef def)
    {
        foreach (var viewItem in _viewHuPrompt._viewHuItems)
        {
            viewItem.gameObject.SetActive(false);
        }
        Debug.Log("*****************************OnRefreshItem:" + def.ToString());


        if (UIOperation.Instance._huTipsCards != null && UIOperation.Instance._huTipsCards.Count > 0)
        {
            List <GameMessage.HuTips> huTips = null;
            foreach (var huTipsCard in UIOperation.Instance._huTipsCards)
            {
                //TileDef tdef = TileDef.Create (huTipsCard.cOutCard);
                if (huTipsCard.cOutCard == def.Value)
                {
                    huTips = huTipsCard.v_Tips;
                    break;
                }
            }
            if (huTips != null && huTips.Count > 0)
            {
                for (int n = 0; n < huTips.Count; n++)
                {
                    var              tips     = huTips[n];
                    TileDef          tempDef  = TileDef.Create(tips.cCard);
                    UIGameHuItemView viewItem = _viewHuPrompt._viewHuItems[n];
                    if (viewItem != null)
                    {
                        viewItem.gameObject.SetActive(true);
                        viewItem._img_MJ.sprite     = UIOperation.Instance.GetMJSprite(tempDef);
                        viewItem._textBeishu.text   = tips.cTimes.ToString();
                        viewItem._textZhangshu.text = tips.cLeftNum.ToString();
                    }
                }

                int   count     = huTips.Count;
                float itemSize  = 130 * count;
                float itemScape = 10 * count - 10;
                float mySize    = 105;
                float maxSize   = itemSize + itemScape + mySize;
                _viewHuPrompt._imgBg.GetComponent <RectTransform>().sizeDelta = new Vector2(maxSize, 100);
                _viewHuPrompt._imgBg.localPosition       = new Vector3(-maxSize / 2, -166, 0);
                _viewHuPrompt._objHuPrompt.localPosition = new Vector3(91 - maxSize / 2, -125, 0);
            }
            else
            {
                _prefab.gameObject.SetActive(false);
            }
        }
        else
        {
            _prefab.gameObject.SetActive(false);
        }


//		int count = 0;
//        foreach (var huPromptInfo in UIOperation.Instance.hupai_infos)
//        {
//            string keyName = huPromptInfo.mjType.ToString() + huPromptInfo.mjView.ToString();
//            UIGameHuItemView viewItem;
//            if (_viewHuPrompt._viewHuItems.TryGetValue(keyName, out viewItem))
//            {
//                count++;
//                viewItem.gameObject.SetActive(true);
//                viewItem._textBeishu.text = huPromptInfo.beishu.ToString();
//                viewItem._textZhangshu.text = huPromptInfo.zhangshu.ToString();
//            }
//        }
//        if (count > 0) {
//            _prefab.gameObject.SetActive(true);
//            float itemSize = 130 * count;
//            float itemScape = 10 * count - 10;
//            float mySize = 105;
//            float maxSize = itemSize + itemScape + mySize;
//            _viewHuPrompt._imgBg.GetComponent<RectTransform>().sizeDelta = new Vector2(maxSize, 100);
//            _viewHuPrompt._imgBg.localPosition = new Vector3( - maxSize / 2, -166, 0);
//            _viewHuPrompt._objHuPrompt.localPosition = new Vector3(91 - maxSize / 2, -125, 0);
//        } else {
//            _prefab.gameObject.SetActive(false);
//        }
    }
Exemple #10
0
    private IEnumerator initDraw(bool banker)
    {
        _initDrawFinished = false;

        float angle = 0f;

        if (_direction == Vector3.right)
        {
            //self
            angle = 0f;
        }
        else if (_direction == Vector3.forward)
        {
            //right
            angle = -270f;
        }
        else if (_direction == Vector3.left)
        {
            //front
            angle = -180;
        }
        else if (_direction == -Vector3.forward)
        {
            //left
            angle = -90f;
        }

        RotateBy    rb      = null;
        TileDef     def     = null;
        MahjongTile tile    = null;
        Transform   locator = PocketLocator;

        float duration     = 0.1f;
        float waitDuration = 0.3f;

        int index            = 0;
        int drawCountPerTime = 4;

        for (int i = 0; i < 4; ++i)
        {
            if (i == 3)
            {
                drawCountPerTime = 1;
            }

            for (int j = 0; j < drawCountPerTime; ++j)
            {
                //_pile.PopOneTile ();
                def            = _proxy.PocketList [index];
                tile           = MahjongTile.Create(def);
                tile.Direction = MahjongTile.Face.PLANE_NEGTIVE;
                tile.transform.Rotate(Vector3.up, angle, Space.Self);
                tile.transform.parent = locator.transform;

                tile.transform.localPosition = index * _direction * MahjongTile.Width;

                rb = RotateBy.Create(duration, Vector3.right, 90f, Space.Self);
                ActionManager.Instance.RunAction(tile.gameObject, rb);

                //yield return new WaitForSeconds (duration);

                ++index;
            }

            yield return(new WaitForSeconds(waitDuration));
        }

        for (int i = 0; i < locator.childCount; ++i)
        {
            tile = locator.GetChild(i).GetComponent <MahjongTile> ();
            rb   = RotateBy.Create(duration, Vector3.right, -90f, Space.Self);
            ActionManager.Instance.RunAction(tile.gameObject, rb);
        }

        yield return(new WaitForSeconds(waitDuration));

        //_proxy.SortPocketList (TileDef.Comparison);
        _sortPocketList = SortMahjongTile(locator);
        for (int i = 0; i < _sortPocketList.Count; ++i)
        {
            tile = _sortPocketList [i];
            tile.transform.localPosition = i * _direction * MahjongTile.Width;
            rb = RotateBy.Create(duration, Vector3.right, 90f, Space.Self);
            ActionManager.Instance.RunAction(tile.gameObject, rb);
        }

        yield return(new WaitForSeconds(waitDuration));

        if (banker)
        {
            if (_proxy.PocketList.Count == 14)
            {
                def = _proxy.PocketList [13];
                _proxy.RemovePocketList(def, 1);
                Draw(def);
                _drawTile = null;
            }
            else
            {
                def = TileDef.Create();
                Draw(def);
                _drawTile = null;
            }
        }

        _initDrawFinished = true;
    }