/*
 * 由SharpDevelop创建。
 * 用户： Administrator
 * 日期: 2018-11-13
 * 时间: 17:01
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using Server.Data;
using MrWu.Debug;
using System.Collections.Generic;
using Server.DB.Redis;
using System.Collections;
using Server.Data.Module;
using System.Threading;
using Game.Player;
using GameData;

namespace Server.Module {
    /// <summary>
    /// 游戏数据   掌管玩家数据
    /// </summary>
    public class GameDataTab {
        /// <summary>
        /// 游戏信息表
        /// </summary>
        public readonly GameInfoTab infoTab;

        /// <summary>
        /// 游戏信息
        /// </summary>
        private readonly GameInfo gameinfo;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="util"></param>
        /// <param name="info"></param>
        public GameDataTab(ModuleUtile util, GameInfo info) {
            //onlinePlayerIds = new OnLinePlayers();

            gameinfo = info;
            infoTab = new GameInfoTab(util, info);
        }

        /// <summary>
        /// 获取游戏信息
        /// </summary>
        /// <returns></returns>
        public GameInfo GetGameInfo() {
            return gameinfo.Clone();
        }

        /// <summary>
        /// 关闭
        /// </summary>
        public void Close() {
            //所有的玩家
            IEnumerator itor = PlayerCollection.Instance.GetEnumerator();
            while(itor.MoveNext()) {
                int userid = (int)itor.Current;

                PlayerDataAsyc pl =   PlayerCollection.Instance.FindPlayerByUserId(userid);

                if(pl == null) {
                    Debug.Error("不应该存在的错误:取到空玩家!");
                    continue;
                }

                if(pl.friendRoomNum <= 0) {    //没有朋友房,移除玩家
                    if(PlayerCollection.Instance.RemovePlayer(pl) == 1) {
                        PlayerFun.UnLockPlayer(userid, GlobalManager.instance.myUtil);
                        Debug.Info("解锁玩家:" + userid);
                    }
                } else {
                    pl.outline = 1; //离线处理
                }
                Thread.Sleep(1);
            }
        }
    }
}
