/*
 * 由SharpDevelop创建。
 * 用户： Administrator
 * 日期: 2019-03-08
 * 时间: 15:09
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using Server.Data;
using GameData;
using MrWu.Debug;

namespace Server
{
    /// <summary>
    /// 金币场房间管理器
    /// </summary>
    public class RoomManager_gold : RoomManager
    {

        public override bool isFriend => false;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="config"></param>
        public RoomManager_gold(int id, Server.Config.CastlesConfig config) : base(id, config) { }

        
        /// <summary>
        /// 加入房间
        /// </summary>
        /// <param name="pl"></param>
        /// <param name="tingid"></param>
        /// <param name="deskid"></param>
        /// <returns></returns>
        public override bool InRoom(PlayerDataAsyc pl, int tingid, int deskid = -1) {
            if (isFriend) {
                Debug.Warning($"朋友房不能手动进入!userid:{pl.userid}");
                return false;
            }

            if (pl.state != (int)PlayerState.INGame) {       //玩家状态不对
                Debug.Error("进入房间失败,玩家状态不对:" + pl.state + "," + pl.userid + "," + pl.id + "-" +pl.PlatEnum);
                return false;
            }

            if (!isExists(tingid)) { //没有这个厅
                Debug.Warning($"房间没有这个厅:{tingid}");
                return false;
            }

            int result = CheckInRoom(pl);

            if (result != 0) {
                if (result < 0) {
                    Debug.Error("您的游戏币小于" + config.MinMoney + ",进入房间失败!" + pl.userid + "," + pl.money);
                    return false;
                }
            }

            string errinfo = null;
            int errorcode = 0;
            bool r = FindTing(tingid).InTing(pl, id,ref errinfo,ref errorcode,deskid);
            return r;
        }

    }
}
