Пример #1
0
    //收到GetRoomList协议
    public void onReqRoomList(ROOM_LIST roomList)
    {
        //清理
        ClearRoomUnit();
        room_list = roomList;

        for (int i = 0; i < roomList.values.Count; i++)
        {
            ROOM_INFO room = roomList.values[i];
            GenerateRoomUnit(i, room.player_count, room.room_state);
        }
    }
Пример #2
0
 //新建按钮返回
 public void onCreateRoomResult(byte result, ROOM_INFO roomInfo)
 {
     //处理
     if (result == 0)
     {
         PanelMgr.instance.OpenPanel <TipPanel>("", "创建成功!");
         //PanelMgr.instance.OpenPanel<RoomPanel>("");
         //Close();
     }
     else
     {
         PanelMgr.instance.OpenPanel <TipPanel>("", "创建房间失败!");
     }
     KBEngine.Event.fireIn("reqRoomList", new object[] { });
 }
Пример #3
0
    //加入按钮返回

    public void onEnterRoomResult(byte result, ROOM_INFO roomInfo)
    {
        //处理
        if (result == 0)
        {
            PanelMgr.instance.OpenPanel <TipPanel>("", "成功进入房间!");
            PanelMgr.instance.OpenPanel <RoomPanel>("");
            Close();
        }
        else
        {
            GameData.Instance.CurrentRoom = null;
            PanelMgr.instance.OpenPanel <TipPanel>("", "进入房间失败");
        }
    }
Пример #4
0
    ///// <summary>
    ///// 当前游戏状态
    ///// </summary>
    //public MahjongGameState CurrentState;

    ///// <summary>
    ///// 游戏规则
    ///// </summary>
    //public MahjongRule Rule;



    #endregion

    #region InitRoom 初始化房间数据
    public void InitRoom(ROOM_INFO protoRoom)
    {
        //ROOM_INFO protoRoom = proto.roomInfo;
        CurrentRoom = new RoomEntity()
        {
            //BaseScore = proto.baseScore,
            roomId      = protoRoom.roomId,
            ownerId     = protoRoom.ownerId,
            currentLoop = protoRoom.loop,
            //matchId = protoRoom.matchId,//比赛场ID
            Status           = (RoomEntity.RoomStatus)protoRoom.roomStatus,
            maxLoop          = protoRoom.maxLoop,
            DisbandStartTime = protoRoom.dismissTime,
            DisbandTime      = protoRoom.dismissMaxTime,
            DisbandTimeMax   = (int)(protoRoom.dismissMaxTime - protoRoom.dismissTime),
        };
        CurrentRoom.HistoryPoker = new List <Poker>();

        CurrentRoom.SeatList = new List <SeatEntity>();

        //收到数据存到模型基类
        CurrentRoom.Config.Clear();
        for (int i = 0; i < protoRoom.settingIdCount(); ++i)
        {
            cfg_settingEntity settingEntity = cfg_settingDBModel.Instance.Get(protoRoom.getSettingId(i));

            if (settingEntity != null)
            {
                CurrentRoom.Config.Add(settingEntity);
            }
        }

        //获得当前游戏模式
        for (int i = 0; i < CurrentRoom.Config.Count; i++)
        {
            if (CurrentRoom.Config[i].tags.Equals("mode"))
            {
                //CurrentRoom.roomModel = (Room.RoomModel)CurrentRoom.Config[i].value;
            }
        }
        for (int i = 0; i < CurrentRoom.Config.Count; i++)
        {
            if (CurrentRoom.Config[i].tags.Equals("roomMode"))
            {
                //CurrentRoom.superModel = (Room.SuperModel)CurrentRoom.Config[i].value;
                //Debug.Log("服务器发送的房间 普通高级场模式为为:" + CurrentRoom.Config[i].value);
            }
        }



        Debug.Log("房间ID为:" + protoRoom.roomId);
        Debug.Log("服务器发送的房间座位长度为:" + protoRoom.getSeatInfoList().Count);

        CurrentRoom.SeatCount = protoRoom.getSeatInfoList().Count;

        CurrentRoom.SeatList = new List <SeatEntity>();

        for (int i = 0; i < CurrentRoom.SeatCount; ++i)
        {
            SEAT_INFO  protoSeat = protoRoom.getSeatInfo(i);
            SeatEntity seat      = new SeatEntity();


            //是否同意解散
            if (protoSeat.hasSeatStatus())
            {
                seat.DisbandState = (DisbandState)protoSeat.dismiss_status;
            }

            //庄
            //seat.IsBanker = protoSeat.isBanker;
            //玩家ID
            seat.PlayerId = protoSeat.playerId;
            //房主
            seat.isLandlord = seat.PlayerId == protoRoom.ownerId;
            //pos
            seat.Pos = protoSeat.pos;
            //昵称
            seat.Nickname = protoSeat.nickname;
            //头像
            seat.Avatar = protoSeat.avatar;
            //性别
            seat.Gender = protoSeat.gender;
            //是否准备
            seat.IsReady = protoSeat.isReady;

            //已有金币
            seat.Gold = protoSeat.gold;

            //座位状态
            seat.Status = (SeatEntity.SeatStatus)protoSeat.seatStatus;
            ////本局收益
            //seat.Earnings = protoSeat.nn_earnings;
            ////是否是胜利者
            //seat.Winner = protoSeat.isWiner;

            ////纬度
            //if (protoSeat.hasLatitude()) seat.Latitude = protoSeat.latitude;

            ////经度
            //if (protoSeat.hasLongitude()) seat.Longitude = protoSeat.longitude;


            //手牌类型


            seat.pokerList = new List <Poker>();
            //具体手牌
            if (protoSeat.hasPokerInfo())
            {
                List <POKER_INFO> prPokerList = protoSeat.getPokerInfoList();
                Debug.Log("prPokerList:" + prPokerList.Count);
                for (int j = 0; j < prPokerList.Count; ++j)
                {
                    seat.pokerList.Add(new Poker(prPokerList[j].index, prPokerList[j].size, prPokerList[j].color));
                }
                seat.HandPockerNum = prPokerList.Count;
            }

            CurrentRoom.SeatList.Add(seat);
            if (seat.Status == SeatEntity.SeatStatus.Operate)
            {
                CurrentRoom.OperateSeat = seat;
            }
        }

        CalculateSeatIndex();

        //上家出牌
        List <Poker>      recentlyPlayPoker = new List <Poker>();
        List <POKER_INFO> leftPoker         = new List <POKER_INFO>();

        if (protoRoom.hasLeftPoker())
        {
            leftPoker = protoRoom.leftPoker.getPokerInfoList();
        }
        for (int i = 0; i < leftPoker.Count; ++i)
        {
            recentlyPlayPoker.Add(new Poker(leftPoker[i].index, leftPoker[i].size, leftPoker[i].color));
        }
        int leftPokerPos = protoRoom.hasLeftPoker() ? protoRoom.leftPoker.pos : 0;

        CurrentRoom.CurrAlreadyPlayPos = leftPokerPos;
        CurrentRoom.RecentlyPlayPoker  = new CombinationPokersEntity(leftPokerPos, recentlyPlayPoker, PokersType.None, 0);
        PaoDeKuaiHelper.CheckPokerType(CurrentRoom.RecentlyPlayPoker);
        Currhint = new HintPokersEntity(CurrentRoom.RecentlyPlayPoker);

        SeatEntity leftseat = GetSeatBySeatPos(leftPokerPos);

        if (leftseat != null)
        {
            if (recentlyPlayPoker.Count > 0)
            {
                leftseat.pokerList.AddRange(recentlyPlayPoker);
            }
        }

        SetSeatPass(CurrentRoom.RecentlyPlayPoker.Pos, CurrentRoom.OperateSeat);

        //if (proto.nn_room.hasUnixtime())
        //{
        //    CurrentRoom.serverTime = proto.nn_room.unixtime;//(时间戳)
        //}
    }
Пример #5
0
    ///// <summary>
    ///// 当前游戏状态
    ///// </summary>
    //public MahjongGameState CurrentState;


    ///// <summary>
    ///// 游戏规则
    ///// </summary>
    //public MahjongRule Rule;


    #endregion


    #region 初始化房间信息  构建房间
    /// <summary>
    /// 初始化房间信息  构建房间
    /// </summary>
    /// <param name="proto"></param>
    public void InitRoom(ROOM_INFO proto)
    {
        CurrentRoom = new RoomEntity()
        {
            currentLoop = proto.loop,

            roomId = proto.roomId,

            Status  = proto.room_status,
            maxLoop = proto.maxLoop,

            //matchId = protoRoom.matchId,//比赛场
        };


        CurrentRoom.Config.Clear();
        //for (int i = 0; i < proto.settingIdCount(); ++i)
        //{
        //    cfg_settingEntity settingEntity = cfg_settingDBModel.Instance.Get(proto.getSettingId(i));
        //    if (settingEntity != null)
        //    {
        //        CurrentRoom.Config.Add(settingEntity);
        //    }
        //}
        CurrentRoom.SeatList = new List <SeatEntity>();
        for (int i = 0; i < proto.seatinfoCount(); ++i)
        {
            SEAT_INFO op_seat = proto.getSeatinfo(i);

            SeatEntity seat = new SeatEntity();
            seat.Pos = op_seat.pos;

            seat.PlayerId = op_seat.playerId;
            seat.Gender   = op_seat.gender;
            seat.Gold     = op_seat.gold;
            seat.Nickname = op_seat.nickname;
            seat.Avatar   = op_seat.avatar;
            //seat.IP = op_seat.ipaddr;
            seat.Status = op_seat.seat_status;
            Debug.Log(seat.Status);

            for (int j = 0; j < op_seat.pockerInfoCount(); ++j)
            {
                POCKER_INFO protoPoker = op_seat.getPockerInfo(j);
                seat.PokerList.Add(new Poker(protoPoker.index, protoPoker.color, protoPoker.size));
            }

            seat.SetSeat(op_seat);
            CurrentRoom.SeatList.Add(seat);

            //            for (int j = 0; j < op_seat.desktopCount(); ++j)
            //            {

            //                OP_POKER protoPoker = op_seat.getDesktop(j);
            //                seat.DeskTopPoker.Add(new Poker(protoPoker.index, protoPoker.color, protoPoker.size, protoPoker.pos));
            //            }
            //            for (int j = 0; j < op_seat.usePokerGroupCount(); ++j)
            //            {
            //                OP_POKER_GROUP protoPoker = op_seat.getUsePokerGroup(j);
            //                List<Poker> lst = new List<Poker>();
            //                for (int k = 0; k < protoPoker.pokerCount(); ++k)
            //                {
            //                    OP_POKER op_poker = protoPoker.getPoker(k);
            //                    Poker poker = new Poker(op_poker.index, op_poker.color, op_poker.size, op_poker.pos);
            //                    lst.Add(poker);
            //                }
            //                if (protoPoker.typeId != ENUM_POKER_TYPE.POKER_TYPE_GANG)
            //                {
            //                    MahJongHelper.SimpleSort(lst);
            //                }
            //#if IS_DAZHONG || IS_WUANJUN
            //                if ((OperatorType)protoPoker.typeId == OperatorType.Chi)//吃的牌放中间
            //                {
            //                    for (int k = 0; k < lst.Count; ++k)
            //                    {
            //                        if (lst[k].pos != seat.Pos)
            //                        {
            //                            Poker poker = lst[k];
            //                            lst.Remove(poker);
            //                            lst.Insert(1, poker);
            //                        }
            //                    }
            //                }

            //                if ((OperatorType)protoPoker.typeId == OperatorType.Peng || (OperatorType)protoPoker.typeId == OperatorType.Gang)
            //                {
            //                    for (int k = 0; k < lst.Count; ++k)
            //                    {
            //                        if (lst[k].pos != op_seat.pos)
            //                        {
            //                            Poker poker = lst[k];
            //                            lst.Remove(poker);
            //                            if (Mathf.Abs(poker.pos - op_seat.pos) == 2)
            //                            {
            //                                lst.Insert(1, poker);
            //                                break;
            //                            }
            //                            if (poker.pos - op_seat.pos == 1 || poker.pos - op_seat.pos == -3)
            //                            {
            //                                lst.Insert(2, poker);
            //                                break;
            //                            }
            //                            if (poker.pos - op_seat.pos == -1 || poker.pos - op_seat.pos == 3)
            //                            {
            //                                lst.Insert(0, poker);
            //                                break;
            //                            }
            //                        }
            //                    }
            //                }
            //#endif
            //                PokerCombinationEntity combination = new PokerCombinationEntity((OperatorType)protoPoker.typeId, (int)protoPoker.subTypeId, lst);

            //                seat.UsedPokerList.Add(combination);
        }
        //            for (int j = 0; j < op_seat.universalCount(); ++j)
        //            {
        //                OP_POKER op_poker = op_seat.getUniversal(j);
        //                seat.UniversalList.Add(new Poker(op_poker.index, op_poker.color, op_poker.size, op_poker.pos));
        //            }
        //            seat.PokerAmount = op_seat.pokerAmount;
        //            seat.IsBanker = op_seat.isBanker;
        //            seat.IsTrustee = op_seat.isTrustee;
        //            seat.IsWaiver = op_seat.isWaiver;
        //            for (int j = 0; j < op_seat.keepPokerGroupCount(); ++j)
        //            {
        //                OP_POKER_GROUP op_poker_group = op_seat.getKeepPokerGroup(j);
        //                List<Poker> lstPoker = new List<Poker>();
        //                for (int k = 0; k < op_poker_group.pokerCount(); ++k)
        //                {
        //                    OP_POKER op_poker = op_poker_group.getPoker(k);
        //                    lstPoker.Add(new Poker(op_poker.index, op_poker.color, op_poker.size, op_poker.pos));
        //                }
        //                seat.HoldPoker.Add(lstPoker);
        //            }
        //            for (int j = 0; j < op_seat.dingPokerGroupCount(); ++j)
        //            {
        //                OP_POKER_GROUP op_poker_group = op_seat.getDingPokerGroup(j);
        //                List<Poker> lstPoker = new List<Poker>();
        //                for (int k = 0; k < op_poker_group.pokerCount(); ++k)
        //                {
        //                    OP_POKER op_poker = op_poker_group.getPoker(k);
        //                    lstPoker.Add(new Poker(op_poker.index, op_poker.color, op_poker.size, op_poker.pos));
        //                }
        //                seat.DingJiangPoker.AddRange(lstPoker);
        //            }
        //            seat.Direction = op_seat.wind;
        //            if (proto.seatCount() == 2 && seat.Direction == 2)
        //            {
        //                seat.Direction = 3;
        //            }
        //            CurrentRoom.SeatList.Add(seat);
        //        }

        //        if (CurrentRoom.SeatList.Count == 2)
        //        {
        //            for (int i = 0; i < CurrentRoom.SeatList.Count; ++i)
        //            {
        //                for (int j = 0; j < CurrentRoom.SeatList[i].UsedPokerList.Count; ++j)
        //                {
        //                    for (int k = 0; k < CurrentRoom.SeatList[i].UsedPokerList[j].PokerCount; ++k)
        //                    {
        //                        if (CurrentRoom.SeatList[i].UsedPokerList[j].PokerList[k].pos == 2)
        //                        {
        //                            CurrentRoom.SeatList[i].UsedPokerList[j].PokerList[k].pos = 3;
        //                        }
        //                    }
        //                }
        //            }
        //        }

        //        CurrentRoom.FirstDice = new DiceEntity()
        //        {
        //            diceA = proto.diceFirstA,
        //            diceB = proto.diceFirstB,
        //            seatPos = proto.diceFirst,
        //        };
        //        CurrentRoom.SecondDice = new DiceEntity()
        //        {
        //            diceA = proto.diceSecondA,
        //            diceB = proto.diceSecondB,
        //            seatPos = proto.diceSecond,
        //        };

        //        int askLeng = proto.askPokerGroupCount();
        //        if (askLeng > 0)
        //        {
        //            AskPokerGroup = new List<OP_POKER_GROUP>();
        //            for (int i = 0; i < askLeng; ++i)
        //            {
        //                AskPokerGroup.Add(proto.getAskPokerGroup(i));
        //            }
        //        }
        //        else
        //        {
        //            AskPokerGroup = null;
        //        }
        //        cfg_settingDBModel.Instance.SetSetting(new List<int>(proto.getSettingIdList()));

        //        CalculateSeatIndex();

        //        InitConfig();

        //        if (currentOperatorPos == 0)
        //        {
        //            currentOperatorPos = CurrentRoom.BankerPos;
        //        }

        //        for (int i = 0; i < CurrentRoom.SeatList.Count; ++i)
        //        {
        //            SeatEntity seat = CurrentRoom.SeatList[i];
        //            for (int j = 0; j < CurrentRoom.SeatList.Count; ++j)
        //            {
        //                for (int k = 0; k < CurrentRoom.SeatList[j].UsedPokerList.Count; ++k)
        //                {
        //                    for (int l = 0; l < CurrentRoom.SeatList[j].UsedPokerList[k].PokerList.Count; ++l)
        //                    {
        //                        if (CurrentRoom.SeatList[j].UsedPokerList[k].PokerList[l].pos == seat.Pos && MahJongHelper.HasPoker(CurrentRoom.SeatList[j].UsedPokerList[k].PokerList[l], seat.UniversalList))
        //                        {
        //                            seat.isPlayedUniversal = true;
        //                            break;
        //                        }
        //                    }
        //                    if (seat.isPlayedUniversal) break;
        //                }
        //                if (seat.isPlayedUniversal) break;
        //                for (int k = 0; k < CurrentRoom.SeatList[j].DeskTopPoker.Count; ++k)
        //                {
        //                    if (CurrentRoom.SeatList[j].DeskTopPoker[k].pos == seat.Pos && MahJongHelper.HasPoker(CurrentRoom.SeatList[j].DeskTopPoker[k], seat.UniversalList))
        //                    {
        //                        seat.isPlayedUniversal = true;
        //                        break;
        //                    }
        //                }
        //                if (seat.isPlayedUniversal) break;
        //                for (int k = 0; k < CurrentRoom.SeatList[j].PokerList.Count; ++k)
        //                {
        //                    if (CurrentRoom.SeatList[j].PokerList[k].pos == seat.Pos && MahJongHelper.HasPoker(CurrentRoom.SeatList[j].PokerList[k], seat.UniversalList))
        //                    {
        //                        seat.isPlayedUniversal = true;
        //                        break;
        //                    }
        //                }
        //                if (seat.isPlayedUniversal) break;
        //            }
        //        }

        //        for (int i = 0; i < CurrentRoom.Config.Count; ++i)
        //        {
        //            if (CurrentRoom.Config[i].tags.Equals("handTotal"))
        //            {
        //                CurrentRoom.PokerTotalPerPlayer = CurrentRoom.Config[i].value;
        //                break;
        //            }
        //        }

        //        SetCurrentOperator(currentOperatorPos, true);
    }