using UnityEngine;

namespace XGame.Database
{
    public static class TableUtils
    {
        /// <summary>
        /// 属性缩放倍数
        /// </summary>
        public static readonly int Multiple = 10000;
        /// <summary>
        /// 数据库万分比字段转真实值
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static float ToRealFloat(this int val)
        {
            return val * 0.0001f;
        }
        /// <summary>
        /// 数据库万分比字段转真实值
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static int ToReal(this int val)
        {
            return Mathf.CeilToInt(val * 0.0001f);
        }

        /// <summary>
        /// 数据库万分比字段转真实值
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static double ToRealDouble(this long val)
        {
            return val * 0.0001f;
        }
        /// <summary>
        /// 数据库万分比字段转真实值
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static long ToReal(this long val)
        { //四舍五入
            return (val + 5000) / Multiple;
        }

        /// <summary>
        /// 检测技能或Buff的目标类型
        /// </summary>
        /// <param name="val"></param>
        /// <param name="targetType"></param>
        /// <returns></returns>
        public static bool IsContain(uint skillTargetType, ESkillTargetType targetType)
        {
            return (skillTargetType & (uint)targetType) != 0;
        }
        /// <summary>
        /// 是否基础属性
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool IsBasic(this EAttributeType type)
        {
            return type is EAttributeType.Hp or EAttributeType.Atk or EAttributeType.Def or EAttributeType.AtkSpeed;
        }
        /// <summary>
        /// 是否装备特殊属性
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool IsItemSpecial(this EAttributeType type)
        {
            return type is EAttributeType.Crit or EAttributeType.DoubleHit or EAttributeType.Counter or EAttributeType.Verti or
                EAttributeType.Eva or EAttributeType.CritRes or EAttributeType.VertigoRes or EAttributeType.EvaRes or
                EAttributeType.DoubleHitRes or EAttributeType.CounterRes;
        }
    }
}
