예제 #1
0
    /// <summary>
    /// 清空房间数据
    /// </summary>
    public void ClearRoom()
    {
        CurrentRoom     = null;
        PlayerSeat      = null;
        CurrentOperator = null;
        Currhint        = null;
        //CurrentState = MahjongGameState.None;
        //Rule = null;

        //RecentlyPlayPoker = null;
    }
예제 #2
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;//(时间戳)
        //}
    }