Beispiel #1
0
        /// <summary>
        /// 得到额外加成的字符窜
        /// customVal:可以使用这个值替代原来的属性值
        /// </summary>
        /// <param name="from"></param>
        /// <returns></returns>
        public string GetAllConvertStr(T from, string Indent = "\n", float?customVal = null)
        {
            Dictionary <T, float> tempVal = new Dictionary <T, float>();
            string hint = "";

            if (_attrConvertData != null)
            {
                foreach (var item in _attrConvertData)
                {
                    if (item != null && BoxAvoidance <T> .ToInt(item.From) == BoxAvoidance <T> .ToInt(from))
                    {
                        if (!tempVal.ContainsKey(item.To))
                        {
                            tempVal.Add(item.To, 0.0f);
                        }
                        tempVal[item.To] += GetExtraAddtion(item, customVal);
                    }
                }
            }
            foreach (var item in tempVal)
            {
                hint += Indent + GetAttrStr(item.Key, item.Value);
            }
            return(hint);
        }
Beispiel #2
0
        /// <summary>
        /// 获得转换后的属性字符窜,比如百分比,KGM
        /// </summary>
        /// <returns></returns>
        public static string GetAttrNumber(T Type, float Val)
        {
            List <TDAttrData> tempAttrData = GetAttrDataList();

            if (tempAttrData != null)
            {
                var tempData = tempAttrData[BoxAvoidance <T> .ToInt(Type)];
                if (tempData.NumberType == NumberType.KMG)
                {
                    return(BaseUIUtils.KMG(Val));
                }
                else if (tempData.NumberType == NumberType.Percent)
                {
                    return(BaseUIUtils.Percent(Val));
                }
                else if (tempData.NumberType == NumberType.Normal)
                {
                    return(BaseUIUtils.OptionalTwoDigit(Val));
                }
                else if (tempData.NumberType == NumberType.Integer)
                {
                    return(BaseUIUtils.Round(Val));
                }
                else if (tempData.NumberType == NumberType.Bool)
                {
                    return(BaseUIUtils.Bool(Val));
                }
            }
            return(Val.ToString());
        }
Beispiel #3
0
        public virtual void ChangeVal(T type, float val, float?minVal = null, float?maxVal = null)
        {
            if (val == 0)
            {
                return;
            }
            int index = BoxAvoidance <T> .ToInt(type);

            float baseVal = _baseDataPool[index];

            baseVal += val;
            if (minVal != null)
            {
                if (baseVal < minVal.Value)
                {
                    baseVal = minVal.Value;
                }
            }
            if (maxVal != null)
            {
                if (baseVal > maxVal)
                {
                    baseVal = maxVal.Value;
                }
            }
            InitAttr(type, baseVal);
        }
Beispiel #4
0
        /// <summary>
        /// 获得额外的加成
        /// </summary>
        protected float GetExtraAddtion(AttrConvertData <T> data, float?customVal = null)
        {
            if (data == null)
            {
                return(0);
            }
            int fromIndex = BoxAvoidance <T> .ToInt(data.From);

            TDAttrData tempData = attrDataList[fromIndex];
            var        fromVal  = _curDataPool[fromIndex];

            if (customVal.HasValue)
            {
                fromVal = customVal.Value;
            }
            var toVal = 0.0f;
            var Step  = data.Step;

            if (Step == 0)
            {
                CLog.Error("Step不能为0");
                return(0.0f);
            }

            if (!data.IsReverse)
            {
                toVal = (fromVal / Step) * data.Faction;
            }
            else
            {
                toVal = ((tempData.Max - fromVal) / Step) * data.Faction;
            }
            return(Mathf.Clamp(toVal, data.Min, data.Max));
        }
Beispiel #5
0
        public virtual void InitAttr(T type, float val)
        {
            var index = BoxAvoidance <T> .ToInt(type);

            if (attrDataList != null)
            {
                TDAttrData tempAttrData = null;
                if (index >= attrDataList.Count)
                {
                    CLog.Error("InitAttr:" + type.ToString() + ":没有配置属性表");
                    return;
                }
                tempAttrData = attrDataList[index];
                if (tempAttrData == null)
                {
                    _curDataPool[index]  = val;
                    _baseDataPool[index] = val;
                }
                else
                {
                    _curDataPool[index]  = Mathf.Clamp(val, tempAttrData.Min, tempAttrData.Max);
                    _baseDataPool[index] = Mathf.Clamp(val, tempAttrData.Min, tempAttrData.Max);
                }
            }
            else
            {
                _curDataPool[index]  = val;
                _baseDataPool[index] = val;
            }
            SetDirty();
        }
Beispiel #6
0
        protected virtual void AddAttrVal(T type, float val)
        {
            var index = BoxAvoidance <T> .ToInt(type);

            if (attrDataList != null)
            {
                TDAttrData tempAttrData = null;
                if (index >= attrDataList.Count)
                {
                    CLog.Error("SetAttrVal:" + type.ToString() + ":没有配置属性表");
                    return;
                }
                tempAttrData = attrDataList[index];
                if (tempAttrData == null)
                {
                    _curDataPool[index] += val;
                }
                else
                {
                    _curDataPool[index] += val;
                    _curDataPool[index]  = Mathf.Clamp(_curDataPool[index], tempAttrData.Min, tempAttrData.Max);
                }
            }
            else
            {
                _curDataPool[index] += val;
            }
        }
Beispiel #7
0
        /// <summary>
        /// 根据传入的属性类型,以及值判断是否为正面效果
        /// </summary>
        /// <returns></returns>
        public static bool IsPositive(T Type, float Val)
        {
            bool ret = true;
            List <TDAttrData> tempAttrData = GetAttrDataList();

            if (tempAttrData != null)
            {
                var tempData = tempAttrData[BoxAvoidance <T> .ToInt(Type)];
                if (tempData.IsForwardBuff)
                {
                    if (Val < 0)
                    {
                        ret = false;
                    }
                    else if (Val > 0)
                    {
                        ret = true;
                    }
                }
                else
                {
                    if (Val < 0)
                    {
                        ret = true;
                    }
                    else if (Val > 0)
                    {
                        ret = false;
                    }
                }
            }
            return(ret);
        }
Beispiel #8
0
 public virtual Sprite GetIcon(T type)
 {
     if (attrDataList == null)
     {
         return(null);
     }
     return(SelfBaseGlobal.GRMgr.GetIcon(attrDataList[BoxAvoidance <T> .ToInt(type)].Icon));
 }
Beispiel #9
0
        public List <AttrAdditon <T> > Add(List <AttrAdditon <T> > array)
        {
            if (array == null)
            {
                return(null);
            }
            for (var i = 0; i < array.Count; ++i)
            {
                if (array[i] != null)
                {
                    var index = BoxAvoidance <T> .ToInt(array[i].Type);

                    var tempAttrData = attrDataList[index];

                    //固定值,持续变化
                    if (tempAttrData.Type == AttrType.Fixed)
                    {
                        if (array[i].AddType == AttrOpType.Direct ||
                            array[i].AddType == AttrOpType.DirectAdd)
                        {
                            _data.Add(array[i]);
                        }
                        else
                        {
                            _percentData.Add(array[i]);
                        }
                    }
                    //动态值一次性变化
                    else if (tempAttrData.Type == AttrType.Dynamic)
                    {
                        if (array[i].AddType == AttrOpType.Direct)
                        {
                            InitAttr(array[i].Type, array[i].RealVal);
                        }
                        else if (array[i].AddType == AttrOpType.DirectAdd)
                        {
                            ChangeVal(array[i].Type, array[i].RealVal);
                        }
                        else if (array[i].AddType == AttrOpType.Percent)
                        {
                            InitAttr(array[i].Type, array[i].RealVal * _curDataPool[index]);
                        }
                        else if (array[i].AddType == AttrOpType.PercentAdd)
                        {
                            ChangeVal(array[i].Type, array[i].RealVal * _curDataPool[index]);
                        }
                    }
                }
            }
            SetDirty();
            return(array);
        }
Beispiel #10
0
        /// <summary>
        /// 获取带有颜色的加成字符,附带正面效果和负面效果的颜色变化
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="Val"></param>
        /// <returns></returns>
        public static string GetAttrStr(T Type, float Val, bool?isPercent = null, bool isIgnoreName = false, bool isColor = true)
        {
            List <TDAttrData> tempAttrData = GetAttrDataList();
            var    tempData    = tempAttrData[BoxAvoidance <T> .ToInt(Type)];
            string color       = GetAttrColor(Type, Val);
            bool   tempPercent = false;
            bool   tempBool    = false;

            //设置输入的百分比
            if (isPercent.HasValue)
            {
                tempPercent = isPercent.Value;
            }
            //如果是百分比数值则直接使用百分比
            if (tempData.NumberType == NumberType.Percent)
            {
                tempPercent = true;
            }
            if (tempData.NumberType == NumberType.Bool)
            {
                tempBool = true;
            }

            //属性名称
            string name = isIgnoreName ? "" : (Type as Enum).GetName();
            //设置属性值
            string strVal = "No";

            if (tempBool)
            {
                strVal = BaseUIUtils.Bool(Val);
            }
            else if (tempPercent)
            {
                strVal = BaseUIUtils.PercentSign(Val);
            }
            else
            {
                strVal = BaseUIUtils.Sign((float)Math.Round(Val, 2));
            }
            //组合
            string str1 = name + strVal;

            //属性颜色
            if (isColor)
            {
                str1 = color + str1 + "</color>";
            }
            return(str1);
        }
Beispiel #11
0
        /// <summary>
        /// 获得翻译后的描述
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public string GetAttrDesc(T type)
        {
            if (attrDataList == null)
            {
                return("attrData is null:" + type.ToString());
            }
            var index = BoxAvoidance <T> .ToInt(type);

            if (index >= attrDataList.Count)
            {
                return("out of index:" + type.ToString());
            }
            return(attrDataList[index].GetDesc());
        }
Beispiel #12
0
        /// <summary>
        /// 获得属性颜色
        /// </summary>
        /// <returns></returns>
        public static string GetAttrColor(T Type, float Val, bool isReverse = false)
        {
            string            color        = "<color=yellow>";
            List <TDAttrData> tempAttrData = GetAttrDataList();

            if (tempAttrData != null)
            {
                var tempData = tempAttrData[BoxAvoidance <T> .ToInt(Type)];
                if (tempData.IsForwardBuff)
                {
                    if (Val > 0)
                    {
                        color = "<color=green>";
                    }
                    else if (Val < 0)
                    {
                        color = "<color=red>";
                    }
                }
                else
                {
                    if (Val < 0)
                    {
                        color = "<color=green>";
                    }
                    else if (Val > 0)
                    {
                        color = "<color=red>";
                    }
                }

                if (isReverse)
                {
                    if (color.Contains("green"))
                    {
                        color.Replace("green", "red");
                    }
                    else if (color.Contains("red"))
                    {
                        color.Replace("red", "green");
                    }
                }
            }
            return(color);
        }
Beispiel #13
0
 public virtual float GetAttrVal(T type)
 {
     return(_curDataPool[BoxAvoidance <T> .ToInt(type)]);
 }
Beispiel #14
0
 public override void Refresh()
 {
     base.Refresh();
     //重置当前值
     for (int i = 0; i < _baseDataPool.Length; ++i)
     {
         _curDataPool[i] = _baseDataPool[i];
     }
     //计算非百分值
     for (int i = 0; i < _data.Count; ++i)
     {
         AddAttrVal(_data[i].Type, _data[i].RealVal);
     }
     //计算百分值
     for (int i = 0; i < _percentData.Count; ++i)
     {
         AddAttrVal(_percentData[i].Type, _percentData[i].RealVal * _baseDataPool[BoxAvoidance <T> .ToInt(_percentData[i].Type)]);
     }
     //额外加成
     if (_attrConvertData != null)
     {
         foreach (var item in _attrConvertData)
         {
             if (item != null)
             {
                 AddAttrVal(item.To, GetExtraAddtion(item));
             }
         }
     }
     Callback_OnAttrChange?.Invoke();
 }
Beispiel #15
0
 public int GetHashCode(TEnum firstEnum)
 {
     return(BoxAvoidance.ToInt(firstEnum));
 }
Beispiel #16
0
 public bool Equals(TEnum firstEnum, TEnum secondEnum)
 {
     return(BoxAvoidance.ToInt(firstEnum) ==
            BoxAvoidance.ToInt(secondEnum));
 }