using System;
using System.Collections.Generic;
using GameData;
using zyxAdapter;
using Game.Shadow;
using Game.Queue;
using MrWu.Debug;

namespace Server {
    /// <summary>
    /// 游戏单元抽象工厂
    /// </summary>
    public class GameUtilFactory {

        /// <summary>
        /// 创建游戏管理单元
        /// </summary>
        /// <returns></returns>
        public virtual GameManager CreateManager(Server.Config.GameConfig config) {
            return new GameManager(config, this);
        }

        /// <summary>
        /// 创建房间
        /// </summary>
        /// <returns></returns>
        public virtual RoomManager CreateRoom(int id, Server.Config.CastlesConfig config, bool isFriend) {
            if (isFriend)
                return new RoomManager_Friend(id, config);
            return new RoomManager_gold(id, config);
        }

        /// <summary>
        /// 创建厅
        /// </summary>
        /// <returns></returns>
        public virtual TingManager CreateTing(Server.Config.TingConfig config, bool isFriend) {
            if (isFriend)
                return new TingManager_Friend(config);
            return new TingManager_Gold(config);
        }

        /// <summary>
        /// 创建桌子
        /// </summary>
        /// <returns></returns>
        public virtual Desk CreateDesk(TingManager ting,Server.Config.TingConfig config, int id, DeskInfo info = null) {
            Desk desk;
            if (info == null)
                desk = new Desk_gold(ting, config, id, info);
            else
                desk = new Desk_friend(ting, config, id, info);
            GameManager.dllUtil.CreateDesk(ting.id, id);
            GameBase gm = GameBase.instance as GameBase;
            GameDo gamelogic = GetGameDo(desk);
            desk.SetGameLogic(gamelogic);
            desk.state = DeskState.Idle;
            return desk;
        }

        /// <summary>
        /// 创建算法
        /// </summary>
        /// <param name="desk"></param>
        /// <returns></returns>
        public virtual GameDo GetGameDo(Desk desk) {
            return new GameDo(desk);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public virtual IHostUtil CreateHostUtil() {
            return new EmptyHostUtil();
        }

        /// <summary>
        /// 获取影子池
        /// </summary>
        /// <returns></returns>
        public virtual ShadowPool GetShadowPool() {
            return new ShadowPool();
        }

        /// <summary>
        /// 创建排队控制器
        /// </summary>
        /// <param name="ControllName">排队器名称</param>
        /// <param name="ting">哪个厅的</param>
        /// <returns></returns>
        public virtual IQueueControll GetQueueControll(string ControllName, TingManager ting) {
            switch (ControllName) {
                case "General":
                    return new GeneralQueue(ting);
                case "Friend":
                    return new FriendQueue(ting);
                case "Open":
                    return new OpenQueue(ting);
                case "Empty":
                    return new EmptyQueue();

                default:

                    return null;
            }
        }

    }
}
