using System.Collections.Generic;
using System.Text;
using GameData;
using Server.Data;
using MrWu.Debug;
using GameDAL.FriendRoom;
using Server.Pack;
using Server.MQ;
using Server.Data.Module;
using ObjectModel.Club;
using Server.AliyunSDK.SLSLog;

namespace Server
{
    /// <summary>
    /// 朋友房桌子
    /// </summary>
    public class Desk_friend : Desk
    {
        public override bool ReConnectCancelDeposit
        {
            get { return false; }
        }

        /// <summary>
        /// 
        /// </summary>
        public override bool isFriend => true;

        /// <summary>
        /// 添加玩家列表
        /// </summary>
        /// <param name="pl">玩家</param>
        /// <param name="roomid">房间号</param>
        /// <returns></returns>
        protected override int AddPlayerArray(PlayerDataAsyc pl, int roomid)
        {
            int seat = -1;
            int len = Count;

            if (deskinfo.rule.RuleEx != null && deskinfo.rule.RuleEx.JoinRandomSeat)
            {
                GetEmptySeat();
                if (emptySeats.Count > 0)
                {
                    int idx = random.Next(0, emptySeats.Count);
                    seat = emptySeats[idx];
                }
            }
            else
            {
                //按顺序上桌
                for (int i = 0; i < len; i++)
                {
                    if (!HasSeat(i))
                    {
                        seat = i;
                        break;
                    }
                    // if (pls[i] == null)
                    // {
                    //     PlayerChange(pl);
                    //     pls[i] = pl;
                    //     seat = i;
                    //     break;
                    // }
                }
            }

            if (seat >= 0)
            {
                PlayerChange(pl);
                pls[seat] = pl;
                pl.DepositChange = PlayerDepositChange;
            }

            if (seat < 0)
            {
                Debug.Error($"随机桌位?{deskinfo.rule.RuleEx != null && deskinfo.rule.RuleEx.JoinRandomSeat}");
            }

            return seat;
        }

        private bool HasSeat(int seat)
        {
            for (int i = 0; i < deskinfo.seat.Length; i++)
            {
                if (deskinfo.seat[i] == seat)
                {
                    return true;
                }
            }

            return false;
        }

        private readonly List<int> emptySeats = new List<int>();

        private void GetEmptySeat()
        {
            emptySeats.Clear();
            for (int i = 0; i < Count; i++)
            {
                if (!HasSeat(i))
                {
                    emptySeats.Add(i);
                }
            }
        }

        /// <summary>
        /// 把玩家根据房间信息添加到桌子中
        /// </summary>
        public virtual void LoadPlayerInDesk(PlayerDataAsyc pl)
        {
            int len = deskinfo.pls.Length;
            for (int i = 0; i < len; i++)
            {
                if (pl.userid == deskinfo.pls[i].userid)
                {
                    if (pls[i] != null)
                        Debug.Error("服务器逻辑错误:asfabskhg这个位置有人!");
                    pls[i] = pl;
                    PlayerChange(pl);
                    return;
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ting"></param>
        /// <param name="tingConfig"></param>
        /// <param name="id"></param>
        /// <param name="info"></param>
        public Desk_friend(TingManager ting,Server.Config.TingConfig tingConfig, int id, DeskInfo info = null) : base(ting,
            tingConfig, id, info)
        {
        }

        private StringBuilder sb = new StringBuilder();

        /// <summary>
        /// 加入到内存 并发包
        /// </summary>
        /// <param name="pl"></param>
        /// <param name="roomid"></param>
        /// <returns></returns>
        public override bool AddPlayer(PlayerDataAsyc pl, int roomid)
        {
            int roomnum = int.Parse(deskinfo.roomNum);

            if (PlayerCnt >= deskinfo.rule.maxCnt)
            {
                Debug.Warning("玩家数量超过最大值!");
                return false;
            }

            pl.seat = AddPlayerArray(pl, roomid);
            if (pl.seat < 0)
            {
                // foreach (var seat in deskinfo.seat)
                // {
                //     sb.AppendLine("seat:")
                // }
                Debug.Error("程序错误,上桌失败!");
                return false;
            }

            int index = deskinfo.AddPlayer(pl);

            if (!Room.SavePlayerToRedis(deskinfo, index))
            {
                Debug.Fatal($"保存玩家数据失败! {pl.userid}");
                return false;
            }

            //保存deskinfo信息到数据库，以及玩家信息


            pl.state = (int)PlayerState.Desk;
            pl.tingid = tingConfig.TingId;
            pl.deskid = id;
            pl.roomid = roomid;

            if (!pl.isRobot && GameManager.instance.isExistsRoom(roomid))
            {
                var room = GameManager.instance.FindRoom(roomid);
                room.SetRoomPlayerCnt(pl);
            }
            else
            {
                Debug.Warning("addPlayer玩家的房间数据错误:" + pl.roomid + "," + pl.userid + "," + pl.nickname);
            }

            //看是否是竞技比赛房间
            if (deskinfo.creatStyle == 5)
            {
                Debug.Info("玩家人数:" + PlayerCnt);

                if (deskinfo.rule.RuleEx?.ReadyTimeout > 0)
                    pl.readCtDown = deskinfo.rule.RuleEx.ReadyTimeout;
                else
                    pl.readCtDown = ServerConfigManager.Instance.ClubReadyTimeOut;
            }


            pl.friendRoomNum = roomnum;
            pl.friendWeiYiMa = deskinfo.weiyima;
            //设置自动托管时间
            pl.AutoDepositTime = 0;
            pl.SetDeposit(false);

            if (roomnum <= 0)
            {
                Debug.Error($"玩家进入的房间号是有问题的值:{roomnum}");
            }

            //在此处需要把桌子人数添加到玩法的桌子在上
            if (deskinfo.creatStyle == 5)
            {
                //Debug.Info("桌子更新!!!!");
                WayManager.instance.ClubWayPlayerChange(deskinfo.creatUserid, deskinfo.wayid, deskinfo.weiyima, true);
                WayManager.instance.WayDeskChangeSend(deskinfo.creatUserid, deskinfo.wayid, deskinfo.weiyima, 2);
            }

            //FriendRoomManager.instance.AddScore(deskinfo);

            //竞技比赛不执行重连
            if (pl.socketUtil != null && pl.socketUtil.id == ServerConfigManager.Instance.NodeId)
                //创建或加入成功, 玩家到
                GameManager.instance.Reconnect(pl, pl.socketUtil);
            SendAddPlayer(pl);
            //设备信息重新计算
            ChangePosition();
            //SendAllPlayerInfo(pl);
            return true;
        }


        /// <summary>
        /// 玩家的坐标发生变化
        /// </summary>
        public override void ChangePosition()
        {
            foreach (var item in this)
            {
                if (item != null) //先把作弊等级置为0
                    item.device.zuobichengdu = 0;
            }

            for (int i = 0; i < this.Count; i++)
            {
                if (this[i] == null) continue;
                for (int j = i + 1; j < this.Count; j++)
                {
                    if (this[j] == null) continue;
                    var cheatinglevel = ting.CheckCheatingLevel(this[i], this[j]);
                    this[i].device.zuobichengdu = cheatinglevel.Item1;
                    this[i].device.zuobichengdu = cheatinglevel.Item2;
                }
            }

            //发送设备变化信息
            this.SendDeviceInfo();
        }


        /// <summary>
        /// 从玩家列表中移除玩家
        /// </summary>
        /// <param name="pl"></param>
        /// <returns></returns>
        public override bool RemovePlayer(PlayerDataAsyc pl)
        {
            if ((state & DeskState.Queue) == 0)
            {
                Debug.Info("移出玩家时,玩家状态不是0");

                return false;
            }

            PlayerDataAsyc tmppl;
            int len = Count;
            for (int i = 0; i < len; i++)
            {
                tmppl = pls[i];
                if (tmppl == null)
                    continue;
                if (pl.userid == tmppl.userid)
                {
                    DeskInfo.PlayerData pldata = null;
                    int index = deskinfo.RemovePlayer(pl.userid, ref pldata);
                    if (index < 0)
                    {
                        Debug.Log("移除玩家失败!！" + pl.userid + "," + index);
                        return false;
                    }

                    pl.seat = -1;
                    pl.DepositChange = null;
                    pls[i] = null;
                    PlayerChange(pl, true);

                    if (Room.ClearPlayerToRedis(deskinfo, index, pl.userid))
                    {
                        Quit(i);
                        SendRemovePlayer(i);
                        return true;
                    }
                    else
                    {
                        //清楚数据失败,回滚数据
                        deskinfo.pls[index] = pldata;
                        deskinfo.seat[index] = index;

                        Debug.Error("清除玩家数据失败,回滚数据!");
                        return false;
                    }
                }
            }

            return false;
        }

        /// <summary>
        /// 检查玩家是否可进入房间
        /// </summary>
        /// <param name="pl"></param>
        /// <returns></returns>
        protected bool _CheckPlayer(PlayerDataAsyc pl)
        {
            return true;
        }

        /// <summary>
        /// 朋友场秒级定时器
        /// </summary>
        public override void SecondTime()
        {
            if (waitRecover)
            {
                return;
            }

            if ((state & DeskState.Idle) > 0)
            {
                return;
            }

            PlayerDataAsyc tmppl;

            int goNext = -1;
            if ((state & DeskState.Queue) > 0)
            {
                int len = Count;
                //自动准备的处理
                for (int i = len - 1; i >= 0; i--)
                {
                    tmppl = pls[i];

                    if (tmppl == null)
                        continue;

#if DEBUG
                    //if (deskinfo.noWar && tmppl.IsTest && tmppl.state == (int)PlayerState.Desk)
                    if (tmppl.IsTest && tmppl.state == (int)PlayerState.Desk)
                    {
                        Debug.Info($"玩家测试自动准备:{tmppl.seat}");
                        Ready(tmppl, true);
                    }
#endif

                    //开战过的自动准备
                    if (tmppl.state == (int)PlayerState.Desk && !deskinfo.noWar)
                    {
                        //自动准备处理
                        // if (tmppl.isDePosit)
                        // {
                        //     Debug.Log("托管自动准备!");
                        //     Ready(tmppl, true);
                        // }
                        // else
                        // {
                        if (tmppl.readCtDown >= 0)
                        {
                            Debug.Log($"玩家准备处理:{tmppl.readCtDown},{tmppl.seat}");
                            tmppl.readCtDown--;
                            if (tmppl.readCtDown < 0)
                            {
                                Debug.Log($"玩家自动准备:{tmppl.seat}");
                                gameLogic.OverTimePenalty(tmppl.seat);
                                Ready(tmppl, true);
                            }
                        }
                        // }
                    }

                    //未开战的超时未准备，踢出
                    if (tmppl.state != (int)PlayerState.Ready && deskinfo.noWar)
                    {
                        //俱乐部房间，超时未准备
                        if (deskinfo.creatStyle == 5 && 
                            !string.IsNullOrEmpty(deskinfo.wayid) && 
                            deskinfo.rule.RuleEx.ReadyTimeout != -1)
                        {
                            if (tmppl.readCtDown >= 0)
                                tmppl.readCtDown--;
                            if (tmppl.readCtDown < 0)
                            {
                                goNext = i;
                            }

                            if (goNext >= 0)
                            {
                                Debug.Info("竞技比赛玩家超时未准备 踢出玩家!" + goNext + "," + tmppl.userid);
                            }
                        }
                    }
                }

                //大于等于最小开战人数
                if (PlayerCnt >= deskinfo.rule.minCnt)
                {
                    //大于1个人才能开战
                    //检查是否开战
                    bool war = true;

                    //开战检测 以及超时踢出
                    for (int i = len - 1; i >= 0; i--)
                    {
                        tmppl = pls[i];

                        if (tmppl == null)
                            continue;

                        // 小于开战人数的情况下,立即开战未开启的,不能开战 俱乐部不能使用立即开战，会导致俱乐部玩家位置数据错乱
                        if (PlayerCnt < deskinfo.rule.maxCnt && (deskinfo.OnceFight[i] != 1 || deskinfo.creatStyle > 0))
                        {
                            war = false;
                            break;
                        }
                        else if (tmppl.state != (int)PlayerState.Ready)
                        {
                            //没准备不能开
                            war = false;
                            break;
                        }
                    }

                    if (goNext >= 0)
                    {
                        war = false;
                    }

                    if (war)
                    {
                        //开战
                        int oldCnt = deskinfo.rule.maxCnt;
                        //修改玩家人数
                        if (deskinfo.CompressionPlayer())
                        {
                            //deskinfo 中的玩家进行压缩
                            //桌子上的玩家进行压缩
                            var oldpl = pls;
                            int newcnt = deskinfo.rule.maxCnt;
                            pls = new PlayerDataAsyc[newcnt];
                            for (int i = 0; i < newcnt; i++)
                            {
                                for (int j = 0; j < oldpl.Length; j++)
                                {
                                    if (oldpl[j] != null)
                                    {
                                        pls[i] = oldpl[j];
                                        pls[i].seat = i;
                                        oldpl[j] = null;
                                        break;
                                    }
                                }
                            }

                            for (int i = 0; i < newcnt; i++)
                            {
                                if (pls[i] != null)
                                    SendAllPlayerInfo(pls[i]);
                            }

                            Room.RenewRoom(deskinfo); //重新修改座位
                        }

                        SendDeskInfoAll(GameSeverAgreement.DeskInfoChange);
                        Debug.Info("桌子开战! -- 可能需要调整玩家座位!");
                        //FriendRoomManager.instance.AddScore(deskinfo, oldCnt); 2020-06-18 删除, 改成具体信息了,不需要加分处理

                        /*
                         * 0731 桌子第一次开战逻辑在这里，补推送的地方
                         *
                         *
                         * */


                        StartWar();
                        return;
                    }
                }
            }

            //已经开战, 到了时间自动托管
            if ((state & DeskState.War) > 0)
            {
                //需要处理自动托管
                if (deskinfo.rule.RuleEx?.AutoDeposit > 0)
                {
                    for (int i = 0; i < Count; i++)
                    {
                        tmppl = pls[i];
                        if (tmppl == null || !tmppl.WaitOperation)
                        {
                            continue;
                        }

                        if (!tmppl.isDePosit)
                        {
                            tmppl.AutoDepositTime++;
                            Debug.Info($"检查自动托管 seat:{i},AutoDepositTime:{tmppl.AutoDepositTime}");
                            if (tmppl.AutoDepositTime > deskinfo.rule.RuleEx?.AutoDeposit)
                            {
                                tmppl.SetDeposit(true);
                                foreach (var item in pls)
                                {
                                    if (item == null) continue;
                                    if (item.isRobot) continue;
                                    SendAllPlayerInfo(item);
                                }
                                //todo 发送玩家托管状态  上面的发送所有玩家信息可以屏蔽  20250211
                                //SendPlayerDePositChange(tmppl.seat);
                            }
                        }
                    }
                }
            }

            //朋友场

            if (deskinfo.isDising)
            {
                //检查是否解散中
                Debug.Info("朋友房解散倒计时{0},roomnum:{1}", deskinfo.DisCount, deskinfo.roomNum);

                deskinfo.DisCount--; //解散倒计时
                if (deskinfo.DisCount < 0)
                {
                    //解散时间已过，自动解散
                    Debug.Warning("解散时间过了，解散房间！");
                    FriendRoomManager.instance.DisBank(this, 2);
                }
            }
            else if (goNext >= 0)
            {
                //要把某个人挪走
                var tmp = pls[goNext];
                Debug.Info("把人挪走!");
                GeneralSendPack.SendErrorInfo_Socket(tmp.userid, 2, 79, tmp.socketUtil);
                GameManager.instance.DoComBack(tmp);
            }
        }

        /// <summary>
        /// 随机换座位处理
        /// </summary>
        protected virtual void SwapSeat()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        public override void StartWar()
        {
            if (!GlobalManager.instance.IsCanWar)
            {
                SendNoWarPack();
                return;
            }

            Debug.Info("开战!" + deskinfo.rule.warCnt);
            base.StartWar();

            PlayerDataAsyc tmppl;
            int len = Count;


            tempUserId.Clear();
            for (int i = 0; i < len; i++)
            {
                tmppl = pls[i];
                if (tmppl == null)
                    continue;
                tmppl.state = (int)PlayerState.War;
                tempUserId.Add(tmppl.userid);
                //tmppl.isDePosit = false;    //托管不重置
                Debug.Log("玩家状态设置为War");
            }

            deskinfo.nowCnt = deskinfo.overCnt + 1; //当前开战场次+1

            // //第一局开战锁住玩家
            if (deskinfo.nowCnt == 1)
            {
                totalWarTime = 0; // 重置统计时间
                if (deskinfo.creatStyle == 5)
                    Room.LockClubFightPlayer(tempUserId, ServerConfigManager.Instance.GameId);
            }

            Room.SetNowCnt(deskinfo);
            //如果需要换座位,执行换座位处理

            Debug.Log(deskinfo.nowCnt);
            //生成局明细-并保存局明细
            deskinfo.burs.Add(deskinfo.CreateBureau(deskinfo.nowCnt));
            Room.SaveBureau(deskinfo, deskinfo.burs.Count - 1);

            //发送对局详情
            SendBurInfo(deskinfo.burs.Count - 1, 1);

            fightdata = new FightData();

            //有数据进行了更新
            Debug.Info("桌子更新!");
            if (deskinfo.creatStyle == 5)
            {
                WayManager.instance.WayDeskChangeSend(deskinfo.creatUserid, deskinfo.wayid, deskinfo.weiyima, 2);
            }

            SendStartWar();
            gameLogic.StartWar();
        }

        /// <summary>
        /// 
        /// </summary>
        public override void WarOver()
        {
            /*
             * 1.修改房间状态
             * 2.修改厅中的列表
             * 3.处理玩家信息
             * 4.检查房间重新排队
             *
             * */

            base.WarOver();

            if (!ting.RemoveWaring(this))
            {
                Debug.Error("游戏结束，未从开战中的桌子移除!");
            }

            ting.AddQueueing(this);


            Debug.Info("-----------战斗结束!");

            PlayerDataAsyc tmppl;

            //朋友房
            deskinfo.nowCnt = 0;
            deskinfo.overCnt++;

            //第一局打完就扣卡
            if (deskinfo.overCnt == 1)
            {
                PlayerDataAsyc fangzhu = null;

                if (deskinfo.creatStyle != 5)
                {
                    for (int i = 0; i < Count; i++)
                    {
                        tmppl = pls[i];
                        if (tmppl == null)
                            continue;

                        if (tmppl.userid == deskinfo.creatUserid)
                        {
                            fangzhu = tmppl;
                        }
                    }
                }

                FriendRoomManager.instance.DeductCard(fangzhu, deskinfo);
            }

            Room.SetNowCnt(deskinfo);
            Room.SetOverCnt(deskinfo);

            int len = Count;
            for (int i = 0; i < len; i++)
            {
                tmppl = pls[i];
                if (tmppl == null)
                    continue;

                if (tmppl.state == (int)PlayerState.War)
                {
                    tmppl.state = (int)PlayerState.Desk;
                    int autoReadTime = 0;
                    if (deskinfo != null && deskinfo.rule.RuleEx != null)
                    {
                        autoReadTime = deskinfo.rule.RuleEx.AutoReadTime;
                    }
                    //使用默认值
                    if (autoReadTime <= 0)
                    {
                        autoReadTime = ServerConfigManager.Instance.FriendAutoReady;
                    }
                    tmppl.readCtDown = autoReadTime;
                }
                else
                {
                    Debug.Error("不可能存在的情况asdasjbdkjasb!" + tmppl.state);
                }
            }

            Debug.Info("桌子更新");
            //更新数据
            if (deskinfo.creatStyle == 5)
            {
                WayManager.instance.WayDeskChangeSend(deskinfo.creatUserid, deskinfo.wayid, deskinfo.weiyima, 2);
            }

            SendFriendRoomOver(0);
            SendWarOver();

            Room.SaveFightRecord(deskinfo, fightdata, 0);
            Debug.Info("朋友房战斗结束-保存战斗数据:" + deskinfo.overCnt + "," + deskinfo.ToString());
            if (deskinfo.creatStyle == 5 && !deskinfo.isAllOver)
            {
                //发送小局结算数据
                SendBureaToClub();
            }
            
            // 统计总时长
            AddWarTime();
            if (deskinfo.isAllOver)
            {
                //全部结束
                Debug.Info("------------------------------全部结束解散!");
                FriendRoomManager.instance.DisBank(this, 1);
            }

            //检查托管后自动解散 20240819 增加
            if (deskinfo.rule.RuleEx != null && !deskinfo.noWar && deskinfo.rule.RuleEx.AutoDeposit > 0 &&
                deskinfo.rule.RuleEx.DepositAutoDissolve)
            {
                bool isDeposit = false;
                //检查是否有人托管
                for (int i = 0; i < PlayerCnt; i++)
                {
                    if (pls[i].isDePosit)
                    {
                        isDeposit = true;
                        break;
                    }
                }

                if (isDeposit)
                {
                    Debug.Info("------------------------------托管自动解散!");
                    FriendRoomManager.instance.DisBank(this, 9);
                }
            }
            
        }

        /// <summary>
        /// 发送每小局结算数据给俱乐部
        /// </summary>
        private void SendBureaToClub()
        {
            int len = deskinfo.pls.Length;
            ClubBureauScore data = new ClubBureauScore() { };
            data.ClubId = deskinfo.creatUserid;
            data.weiyima = deskinfo.weiyima;
            data.wayId = deskinfo.wayid;
            data.game_serid = ServerConfigManager.Instance.GameId;
            data.ModuleId = ServerConfigManager.Instance.NodeId;
            data.Players = new BureauScorePlayer[len];
            decimal beishu = (decimal)deskinfo.rule.peilv;
            //if (deskinfo.rule.ex == null || deskinfo.rule.ex.Length < 2 || !decimal.TryParse(deskinfo.rule.ex[1], out beishu))
            //{
            //    beishu = 1.0m;
            //}
            int cnt = 0;
            for (int i = 0; i < len; i++)
            {
                if (deskinfo.pls[i] != null)
                {
                    data.Players[i] = new BureauScorePlayer();
                    data.Players[i].UserId = deskinfo.pls[i].userid;
                    data.Players[i].NickName = deskinfo.pls[i].nickName;
                    data.Players[i].ClubId = deskinfo.pls[i].ClubId;
                    cnt++;
                }
            }

            foreach (var bur in deskinfo.burs)
            {
                for (int i = 0; i < len; i++)
                {
                    if (data.Players[i] == null)
                        continue;
                    data.Players[i].Score += bur.playScore[i] * beishu;
                }
            }


            if (cnt != len)
            {
                BureauScorePlayer[] lst = new BureauScorePlayer[cnt];
                cnt = 0;
                for (int i = 0; i < len; i++)
                {
                    if (data.Players[i] != null)
                    {
                        lst[cnt++] = data.Players[i];
                    }
                }

                data.Players = lst;
            }

            Debug.Info("发送小局结算数据!");

            PackHead head = PackHead.Create(ServerPackAgreement.SendBureaToClub);
            GlobalMQ.instance.DeliveryEveryOne((int)ModuleType.ClubModule, GlobalMQ.CreateMessage(head, data), true);
            head.Dispose();
        }

        /// <summary>
        /// 朋友房加减钱
        /// </summary>
        /// <param name="seat">座位</param>
        /// <param name="lx">类型 8是最终  9是增量</param>
        /// <param name="num">金额</param>
        protected virtual void _IncMoney(int seat, int lx, int num)
        {
            var bur = deskinfo.burs[deskinfo.burs.Count - 1];
            int len = bur.seat.Length;
            for (int i = 0; i < len; i++)
            {
                if (bur.seat[i] == seat)
                {
                    if (lx == 9)
                        bur.playScore[i] += num;
                    else
                        bur.playScore[i] = num;
                }
            }

            Room.SaveBureau(deskinfo, deskinfo.burs.Count - 1);
            SendBurInfo(deskinfo.burs.Count - 1, 1);
            if (lx == 8 && deskinfo.creatStyle == 5)
            {
                LuckPlayerManager.Instance.AddOnceFight(deskinfo.wayid, pls[seat].userid, num);
                FriendRoomStatistics.Instance.AddOnceFight(deskinfo.wayid, seat, pls[seat].userid, num);
            }
        }

        /// <summary>
        /// 加载桌子
        /// </summary>
        /// <returns></returns>
        public override bool LoadDesk()
        {
            if (!isFriend)
                return false;

            bool isOld = false;
            byte[] data = Room.LoadFightData(deskinfo.weiyima, out isOld);
            FightData tmpdata = null;
            Room.LoadFightRecord(deskinfo.weiyima, deskinfo.burs.Count, out tmpdata);
            fightdata = tmpdata;

            //不是空
            if (data != null)
            {
                LoadMem(data, isOld);
            }

            return true;
        }

        // public override void OutLine(int seat)
        // {
        //     try
        //     {
        //         if (deskinfo != null && deskinfo.noWar && pls[seat].state == (int)PlayerState.Ready)
        //         {
        //             pls[seat].state = (int)PlayerState.Desk;
        //         }
        //         SendPlayerStateChange(seat);
        //     }
        //     catch (Exception e)
        //     {
        //         Debug.Error($"玩家离线出错:{e.Message}");
        //     }
        //
        //     base.OutLine(seat);
        // }

        /// <summary>
        /// 加减钱
        /// </summary>
        /// <param name="seat"></param>
        /// <param name="lx"></param>
        /// <param name="num"></param>
        public override void IncMoney(int seat, int lx, int num)
        {
            _IncMoney(seat, lx, num);
        }

        /// <summary>
        /// 重连信号
        /// </summary>
        /// <param name="seat"></param>
        public override void Reconnect(int seat)
        {
            //朋友房重连   //发送信号
            Debug.Info("发送重连信号!");
            SendReconnectonSign(pls[seat]);

            base.Reconnect(seat);
        }

        /// <summary>
        /// 加载桌子数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="isOld">是否是旧数据</param>
        public override void LoadMem(byte[] data, bool isOld)
        {
            NextBehavior.LoadMem(data, isOld);
        }

        public override void LoadMemSuccess()
        {
            NextBehavior.LoadMemSuccess();
        }

        /// <summary>
        /// 发送详情信息 如果count 是小于0 则表示发送全部
        /// </summary>
        protected virtual void SendBurInfo(int index, int count = -1)
        {
            BurInfo bi = new BurInfo();
            if (count < -1)
            {
                index = 0;
                count = deskinfo.burs.Count;
            }
            else
            {
                bi.style = 1;
            }

            bi.burs.AddRange(deskinfo.burs.GetRange(index, count));
            PackHead head = PackHead.Create(GameSeverAgreement.friendroombrus);
            SendAllPack(head, bi);
            head.Dispose();
        }

        /// <summary>
        /// 发送重连信号
        /// </summary>
        /// <param name="pl"></param>
        public virtual void SendReconnectonSign(PlayerDataAsyc pl)
        {
            Debug.Info("发送重连信号:" + (pl == null) + "," + isFriend);

            if (pl == null) return;
            if (isFriend)
            {
                //朋友房重连信号
                PackHead head = PackHead.Create();
                head.otherInt = new int[] { pl.userid };

                for (int i = 0; i < PlayerCnt; i++)
                {
                    if (pls[i] == null || pls[i].userid == pl.userid) continue;
                    head.packlx = GameSeverAgreement.accesstoFriendRoom;
                    GameNet.SendPack(pls[i], head, deskinfo);

                    Debug.Info("发送重连信号:" + pls[i].nickname + "," + pls[i].userid + "," + pl.outline);
                }

                head.Dispose();
            }
        }
    }
}