
using System;
using System.Diagnostics;
using System.Text;
using GameMessage;
using Newtonsoft.Json;

namespace GameData
{
    /// <summary>
    /// 桌子规则
    /// </summary>
    public class DeskRule
    {
        /// <summary>
        /// 密码
        /// </summary>
        public string pwd;

        /// <summary>
        /// 最大玩家数量
        /// </summary>
        public int maxCnt;

        /// <summary>
        /// 最小玩家数量
        /// </summary>
        public int minCnt;

        /// <summary>
        /// 战斗场次
        /// </summary>
        public int warCnt;

        /// <summary>
        /// 游戏的服务器id
        /// </summary>
        public int game_serid;

        /// <summary>
        /// 是否拦截ip
        /// </summary>
        public int interceptIp;

        /// <summary>
        /// 地理位置拦截
        /// </summary>
        public int interceptpos;

        /// <summary>
        /// 是否拦截不是微信的账号
        /// </summary>
        public int interceptWeChat;

        /// <summary>
        /// 检查设备唯一码是否相同
        /// </summary>
        public int interecptimei;

        /// <summary>
        /// 防外挂
        /// </summary>
        public int fanG;

        /// <summary>
        /// 是否开启语音
        /// </summary>
        public int yuying;

        /// <summary>
        /// 防作弊变化是否提醒
        /// </summary>
        public int warn;

        /// <summary>
        /// 客户端拓展，只保存,服务器不处理
        /// </summary>
        public string[] ex;

        /// <summary>
        /// 是否需要换座位
        /// </summary>
        public bool isNeedSwapSeat;

        /// <summary>
        /// 赔率
        /// </summary>
        public float peilv;

        /// <summary>
        /// 房间规则
        /// </summary>
        public string roomrule;

        /// <summary>
        /// 多少数封顶，总结算的封顶（子乘倍率的,就是最后封顶输多少钱） 等于0的值就是有封顶，要不就没有封顶
        /// </summary>
        public int Capping;

        /// <summary>
        /// 玩法备注
        /// </summary>
        public string Remarks;

        /// <summary>
        /// 规则拓展
        /// </summary>
        public DeskRuleEx RuleEx;

        [JsonIgnore]
        public string RuleExStr
        {
            get
            {
                if (RuleEx == null)
                {
                    return string.Empty;
                }
                return JsonPack.GetJson(RuleEx);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public DeskRule()
        {
            //SetCappingAndPeiLv(ex);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="maxCnt"></param>
        public DeskRule(int maxCnt)
        {
            this.maxCnt = maxCnt;
            //SetCappingAndPeiLv(ex);
        }

        /// <summary>
        /// 获取创建房间所需要的房卡
        /// 一般在客户端显示的时候需要传递参数。
        /// 服务器在创建房间的时候是不用填写参数，直接使用类里面的内存技术即可
        /// </summary>
        /// <param name="_warCnt">局数</param>
        /// <param name="_maxCnt">人数</param>
        /// <param name="clacCreateRoomCardNum">计算房卡的委托，自己计算</param>
        /// <returns>返回所需要的房卡数量</returns>
        /// <exception cref="Exception"></exception>
        [Obsolete("方法作废，客户端自己计算使用了多少房卡，服务器取规则里面的房卡数量", true)]
        public int GetCreateRoomCardNum(int _warCnt = 0, int _maxCnt = 0,Func<int,int,int> clacCreateRoomCardNum=null)
        {

            if (clacCreateRoomCardNum != null) {
                return clacCreateRoomCardNum(_warCnt,_maxCnt);
            }
            var num = _warCnt > 0 ? _warCnt : warCnt;
            var renshu = _maxCnt > 0 ? _maxCnt : maxCnt;
            int result = 0;
            switch (game_serid)//游戏的服务器id
            {
                case 42: //跑得快朋友房
                case 41: //上饶打炸
                    result = num / 4;
                    break;
                case 26: //窝龙
                    result = num / 4;
                    if (renshu > 4)
                    {
                        result = result * 2;
                    }
                    break;
                case 45:

                    break;
                default:
#if !Server

                    throw new Exception("游戏未实现创建房间需要多少张房卡" + game_serid);
#endif

                    break;
            }
            return result;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("密码" + pwd);
            sb.AppendLine("最大开战人数:" + maxCnt);
            sb.AppendLine("最小开战人数:" + minCnt);
            sb.AppendLine("总局数:" + warCnt);
            sb.AppendLine("游戏id:" + game_serid);
            sb.AppendLine("是否拦截ip:" + interceptIp);
            sb.AppendLine("是否拦截电脑账号:" + interceptWeChat);
            sb.AppendLine("是否拦截定位:" + interceptpos);
            sb.AppendLine("是否拦截设备唯一标识:" + interecptimei);
            sb.AppendLine("规则:" + roomrule);
            return sb.ToString();
        }
    }

    
}

