Ejemplo n.º 1
0
        /// <summary>
        ///     添加一个组牌
        /// </summary>
        /// <param name="data"></param>
        /// <param name="isOther"></param>
        public virtual MahjongGroupItem AddGroup(MahjongGroupData data, List <MahjongItem> items, bool isOther)
        {
            var group = _groupPile.AddGroup(data, items, isOther);

            _groupPile.ResetPosition();
            return(group);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建一个牌组(重连时使用这个,这个时候是需要处理Group中的数据即可)
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static MahjongGroupData CteateGroupFromSfsObject(ISFSObject data)
        {
            int gtype;
            int value;

            int[] cards;
            GameTools.TryGetValueWitheKey(data, out gtype, RequestKey.KeyType);
            GameTools.TryGetValueWitheKey(data, out value, RequestKey.KeyCard);
            GameTools.TryGetValueWitheKey(data, out cards, RequestKey.KeyCards);
            GroupType        type      = (GroupType)gtype;
            MahjongGroupData groupData = new MahjongGroupData(type);

            switch (type)
            {
            case GroupType.Chi:
                groupData.AddValue(cards[0]);
                groupData.AddValue(value);
                groupData.AddValue(cards[1]);
                break;

            default:
                for (int i = 0, max = groupData.values.Length; i < max; i++)
                {
                    groupData.AddValue(value);
                }
                break;
            }
            return(groupData);
        }
Ejemplo n.º 3
0
        public void OnGetJueGang(RequestData requeset)
        {
            CpghBehavior.SetBehavior(Enum_CPGType.MingGang);

            Facade.Instance <MusicManager>()
            .Play(GameTools.GetOperationVoice(UserInfo.Sex, ConstantData.Voice_Gang, Random.Range(0, 2)));
            var groupData = new MahjongGroupData(GroupType.JueGang);

            foreach (var card in requeset.Cards)
            {
                if (card > 0)
                {
                    groupData.AddValue(card);
                }
            }
            var needItems = new List <MahjongItem>();

            needItems.AddRange(GetCardsFromHand(groupData.values.ToList(), IsOther));
            foreach (var item in needItems)
            {
                DestroyUserContorl(item);
            }
            MahjongEnv.AddGroup(groupData, needItems, IsOther);
            GroupItems.Add(groupData);
            SortHandCard();
        }
Ejemplo n.º 4
0
        public override MahjongGroupItem AddGroup(MahjongGroupData groupData, List <MahjongItem> items, bool isOther)
        {
            if (groupData.type.Equals(GroupType.FengGang))
            {
                groupData.SortDataByLuanFengData();
            }
            MahjongGroupItem group = base.AddGroup(groupData, items, isOther);

            return(group);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取组牌数据
        /// </summary>
        /// <param name="groups"></param>
        /// <returns></returns>
        public static List <MahjongGroupData> GetGroupData(ISFSArray groups)
        {
            List <MahjongGroupData> datas = new List <MahjongGroupData>();

            for (int i = 0, lenth = groups.Size(); i < lenth; i++)
            {
                ISFSObject       g         = groups.GetSFSObject(i);
                MahjongGroupData groupData = CreateGroupFromSfsObject(g);
                datas.Add(groupData);
            }
            return(datas);
        }
Ejemplo n.º 6
0
        public virtual MahjongGroupItem AddGroup(MahjongGroupData groupData, List <MahjongItem> items, bool isOther)
        {
            MahjongGroupItem item = MahjongGroupItem.CreateGroup();

            item.ParentPile = this;
            items           = item.SetGroup(groupData, items, GroupItemWidth, GroupItemHeight, FourOffsetY, isOther, Layout.directon);
            _pileList.Add(item);
            AddItem(item.transform);
            ParseItemToThis(item.transform);
            item.SetLuanFengShow(groupData, items);
            return(item);
        }
Ejemplo n.º 7
0
        public virtual MahjongGroupItem AddGroup(MahjongGroupData groupData, List <MahjongItem> items, bool isOther,
                                                 bool changeNumber = true)
        {
            var Item = MahjongGroupItem.CreateGroup();

            Item.ParentPile = this;
            Item.SetGroup(groupData, items, GroupItemWidth, GroupItemHeight, FourOffsetY, isOther, Layout.directon);
            _pileList.Add(Item);
            AddItem(Item.transform);
            ParseItemToThis(Item.transform);
            return(Item);
        }
Ejemplo n.º 8
0
        public virtual void OnGetXFGang(RequestData requeset)
        {
            EnumCpgType fengGangBehavior = EnumCpgType.MingGang;
            string      fengGangInfo     = GameTools.GetOperationVoice(UserInfo.Sex, ConstantData.VoiceGang, Random.Range(0, 2));

            GetToken();
            MahjongGroupData groupData = new MahjongGroupData(GroupType.FengGang);

            if (requeset.Cards.Length == 3)
            {
                if (ShowFengGangByNum)
                {
                    fengGangBehavior = EnumCpgType.ThreeFengGang;
                    fengGangInfo     = GameTools.GetOperationVoice(UserInfo.Sex, ConstantData.VoiceThreeFengGang, 0);
                }
                groupData.values = new int[3];
            }
            else
            {
                if (ShowFengGangByNum)
                {
                    fengGangBehavior = EnumCpgType.FourFengGang;
                    fengGangInfo     = GameTools.GetOperationVoice(UserInfo.Sex, ConstantData.VoiceFourFengGang, 0);
                }
            }
            Facade.Instance <MusicManager>().Play(fengGangInfo);
            CpghBehavior.SetBehavior(fengGangBehavior);
            foreach (int card in requeset.Cards)
            {
                if (card > 0)
                {
                    groupData.AddValue(card);
                }
            }

            List <MahjongItem> needItems = new List <MahjongItem>();

            needItems.AddRange(GetCardsFromHand(groupData.values.ToList(), IsOther));
            foreach (var item in needItems)
            {
                GameTools.DestroyUserContorl(item);
            }
            MahjongEnv.AddGroup(groupData, needItems, IsOther);
            GroupItems.Add(groupData);
            SortHandCard();
            RecheckLastGetIn();
        }
Ejemplo n.º 9
0
        public void DealGroupData(List <List <int> > groupData)
        {
            if (GroupPile)
            {
                var count = groupData[0].Count;
                switch (count)
                {
                case 3:
                    GroupPile.Layout.maxPerLine       = 5;
                    GroupPile.Layout.Width            = 190;
                    GroupPile.transform.localPosition = new Vector3(70, 0, 0);
                    break;

                case 4:
                    GroupPile.Layout.maxPerLine       = 4;
                    GroupPile.Layout.Width            = 250;
                    GroupPile.transform.localPosition = new Vector3(15, 0, 0);
                    break;
                }
                GroupPile.ResetPile();
                foreach (var group in groupData)
                {
                    MahjongGroupData data = new MahjongGroupData(GroupType.Other);
                    data.values = group.ToArray();
                    var mahJongList = new List <MahjongItem>();
                    for (int i = 0; i < group.Count; i++)
                    {
                        mahJongList.Add(GameTools.CreateMahjong(group[i], false).GetComponent <MahjongItem>());
                    }
                    var         groupItem = GroupPile.AddGroup(data, mahJongList, false);
                    BoxCollider box       = groupItem.gameObject.AddComponent <BoxCollider>();
                    box.size   = new Vector3(GroupPile.Layout.Width, GroupPile.Layout.Height);
                    box.center = new Vector3(GroupPile.Layout.Width / 3, 0);
                    UIEventListener.Get(groupItem.gameObject).onClick = OnGroupItemClick;
                }
                var bound = GroupPile.Layout.GetLayoutBounds();
                CardsBg.width  = (int)(bound.x + BgBaseBounds.x);
                CardsBg.height = (int)(bound.y + BgBaseBounds.y);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 设置乱风显示
        /// </summary>
        /// <param name="data"></param>
        /// <param name="items"></param>
        public void SetLuanFengShow(MahjongGroupData data, List <MahjongItem> items)
        {
            if (data.type.Equals(GroupType.FengGang))//乱风显示处理
            {
                var count = data.values.Length;
                if (count == 4 && data.TopLandScape)
                {
                    var item             = items[3];
                    var nowDirection     = item.SelfData.Direction;
                    var nowShowDirection = item.SelfData.ShowDirection;
                    if (nowDirection == EnumMahJongDirection.Horizontal)
                    {
                        nowDirection = EnumMahJongDirection.Vertical;
                    }
                    else
                    {
                        nowDirection = EnumMahJongDirection.Horizontal;
                    }

                    switch (nowShowDirection)
                    {
                    case EnumShowDirection.Self:
                    case EnumShowDirection.Oppset:
                        nowShowDirection = EnumShowDirection.Left;
                        break;

                    case EnumShowDirection.Right:
                    case EnumShowDirection.Left:
                        nowShowDirection = EnumShowDirection.Self;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    item.SelfData.Direction     = nowDirection;
                    item.SelfData.ShowDirection = nowShowDirection;
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     吃碰杠回包
        /// </summary>
        /// <param name="request"></param>
        /// <param name="data"></param>
        public void AllowRequest(RequestData request, ISFSObject data)
        {
            GetToken();
            int  tType;
            int  dealCard;
            var  randomNum = 0;
            var  voiceName = "";
            bool isOk;

            dealCard = request.Card;
            GameTools.TryGetValueWitheKey(data, out tType, RequestKey.KeyTypeType);
            GameTools.TryGetValueWitheKey(data, out isOk, RequestKey.KeyOk);
            if (isOk)
            {
                YxDebug.Log("这个回包中的ok标识是true,不执行操作,因为false时已经执行过了");
                return;
            }
            var needItems = new List <MahjongItem>();
            var groupData = new MahjongGroupData((GroupType)tType);
            var dealCards = new List <int>();

            for (int i = 0, lenth = request.Cards.Length; i < lenth; i++)
            {
                YxDebug.Log((EnumMahjongValue)request.Cards[i]);
            }
            var fromHand = true;

            switch ((Enum_CPGType)tType)
            {
            case Enum_CPGType.None:
                return;

            case Enum_CPGType.Chi:
                groupData.AddValue(request.Cards[0]);
                groupData.AddValue(dealCard);
                groupData.AddValue(request.Cards[1]);
                for (int i = 0, lenth = request.Cards.Length; i < lenth; i++)
                {
                    dealCards.Add(request.Cards[i]);
                }
                voiceName = ConstantData.Voice_Chi;
                randomNum = Random.Range(0, 3);
                break;

            case Enum_CPGType.Peng:
                if (dealCard.Equals(App.GetGameManager <Lyzz2DGameManager>().FanNum) && Data.IsGangSelect)
                {
                    voiceName = ConstantData.Voice_Gang;
                    randomNum = Random.Range(0, 2);
                    tType     = (int)Enum_CPGType.ZhuaGang;
                }
                else
                {
                    voiceName = ConstantData.Voice_Peng;
                    randomNum = Random.Range(0, 3);
                }
                dealCards = CreateListWithValue(2, dealCard);
                break;

            case Enum_CPGType.ZhuaGang:
                voiceName = ConstantData.Voice_Gang;
                randomNum = Random.Range(0, 2);
                fromHand  = false;
                dealCards = CreateListWithValue(1, dealCard);
                break;

            case Enum_CPGType.PengGang:
            case Enum_CPGType.MingGang:
                dealCards = CreateListWithValue(3, dealCard);
                voiceName = ConstantData.Voice_Gang;
                randomNum = Random.Range(0, 2);
                break;

            case Enum_CPGType.AnGang:
                dealCards = CreateListWithValue(4, dealCard);
                voiceName = ConstantData.Voice_Gang;
                randomNum = Random.Range(0, 2);
                break;

            case Enum_CPGType.LaiZiGang:
                break;
            }
            if (!tType.Equals((int)Enum_CPGType.Chi))
            {
                for (int i = 0, lenth = request.Cards.Length; i < lenth; i++)
                {
                    groupData.AddValue(dealCard);
                }
            }
            var lastItem = Manager.GetLastOutCardItem(dealCard);

            if (lastItem != null)
            {
                YxDebug.Log(string.Format("最后打出的一张牌是:{0}", (EnumMahjongValue)lastItem.Value));
                needItems.Add(lastItem);
                if (!tType.Equals((int)Enum_CPGType.Chi))
                {
                    groupData.AddValue(dealCard);
                }
            }
            if (fromHand)
            {
                needItems.AddRange(GetCardsFromHand(dealCards, IsOther));
                foreach (var item in needItems)
                {
                    DestroyUserContorl(item);
                }
                MahjongEnv.AddGroup(groupData, needItems, IsOther);
                GroupItems.Add(groupData);
            }
            else //抓杠特殊处理
            {
                var item = GetHandCard(dealCard);
                if (item != null)
                {
                    DestroyUserContorl(item);
                    MahjongEnv.ChangeGroup(dealCard, item);
                    if (IsOther)
                    {
                        HandCardList.Remove(0);
                    }
                    else
                    {
                        HandCardList.Remove(dealCard);
                    }
                }
                else
                {
                    YxDebug.LogError("抓杠时,找不到那张手牌" + (EnumMahjongValue)dealCard);
                }
            }
            CpghBehavior.SetBehavior((Enum_CPGType)tType);
            Facade.Instance <MusicManager>().Play(GameTools.GetOperationVoice(UserInfo.Sex, voiceName, randomNum));
            SortHandCard();
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     设置组牌中的UI显示
        /// </summary>
        /// <param name="data"></param>
        /// <param name="IsOther"></param>
        /// <returns></returns>
        public virtual Transform SetGroup(MahjongGroupData data, List <MahjongItem> items, float groupWidth,
                                          float groupHeight, float fourOffsetY, bool IsOther, DefLayout.Directon direction, bool changeNum = true)
        {
            _data = data;
            var values = data.values;
            var pos    = Vector3.zero;

            if (items == null)
            {
                items = new List <MahjongItem>();
                foreach (var value in values)
                {
                    items.Add(GameTools.CreateMahjong(value, changeNum).GetComponent <MahjongItem>());
                }
            }
            var isHorizontal = direction.Equals(DefLayout.Directon.Horizontal);

            for (int i = 0, lenth = values.Length; i < lenth; i++)
            {
                var item = items[i];
                if (item == null)
                {
                    YxDebug.LogError("找不到一张牌了?");
                }
                var newTran = item.transform;
                switch (data.type)
                {
                case GroupType.Chi:
                case GroupType.Peng:
                case GroupType.MingGang:
                case GroupType.ZhuaGang:
                case GroupType.PengGang:
                    SetNewItem(item, values[i], EnumMahJongAction.Lie);
                    break;

                case GroupType.AnGang:
                case GroupType.FengGang:
                    if (IsOther)
                    {
                        SetNewItem(item, values[i], EnumMahJongAction.Push);
                    }
                    else
                    {
                        if (i != 3)
                        {
                            SetNewItem(item, values[i], EnumMahJongAction.Push);
                        }
                        else
                        {
                            SetNewItem(item, values[i], EnumMahJongAction.Lie);
                        }
                    }
                    break;

                case GroupType.JueGang:
                    if (IsOther)
                    {
                        SetNewItem(item, values[i], EnumMahJongAction.Push);
                    }
                    else
                    {
                        if (i != 1)
                        {
                            SetNewItem(item, values[i], EnumMahJongAction.Push);
                        }
                        else
                        {
                            SetNewItem(item, values[i], EnumMahJongAction.Lie);
                        }
                    }
                    break;

                default:
                    newTran = null;
                    YxDebug.LogError("There is not exist such GroupType " + data.type);
                    break;
                }
                if (i == 3)
                {
                    if (isHorizontal)
                    {
                        pos.x = 1 * groupWidth;
                        pos.y = pos.y + fourOffsetY;
                    }
                    else
                    {
                        pos.y = 1 * groupHeight + fourOffsetY;
                    }
                }
                else
                {
                    if (isHorizontal)
                    {
                        pos.x = i * groupWidth;
                    }
                    else
                    {
                        pos.y = i * groupHeight;
                    }
                }
                newTran.localPosition = pos;
            }
            return(transform);
        }