Beispiel #1
0
        protected virtual void AddAttrVal(T type, float val)
        {
            var index = Enum <T> .Int(type);

            if (attrDataList != null)
            {
                TDBaseAttrData tempAttrData = null;
                if (index >= attrDataList.Count)
                {
                    CLog.Error("SetAttrVal:" + type.ToString() + ":没有配置属性表");
                    return;
                }
                tempAttrData = attrDataList[index];
                if (tempAttrData == null)
                {
                    _curDataPool[index] += val;
                }
                else
                {
                    _curDataPool[index] = Mathf.Clamp(_curDataPool[index] + val, tempAttrData.Min, tempAttrData.Max);
                }
            }
            else
            {
                _curDataPool[index] += val;
            }
        }
Beispiel #2
0
        public TDBaseAttrData GetAttrData(int index)
        {
            TDBaseAttrData tempAttrData = null;

            if (index >= attrDataList.Count)
            {
                CLog.Error("InitAttr:" + index + ":没有配置属性表");
                return(null);
            }
            tempAttrData = attrDataList[index];
            return(tempAttrData);
        }
Beispiel #3
0
        public TDBaseAttrData GetAttrData(T type)
        {
            int index = Enum <T> .Int(type);

            TDBaseAttrData tempAttrData = GetAttrData(index);

            if (tempAttrData == null)
            {
                CLog.Error("InitAttr:" + type.ToString() + ":没有配置属性表");
                return(null);
            }
            return(tempAttrData);
        }
Beispiel #4
0
        // 获得额外的加成
        protected float GetExtraAddtion(AttrConvert <T> data, float?customVal = null)
        {
            if (data == null)
            {
                return(0);
            }
            int fromIndex = Enum <T> .Int(data.From);

            TDBaseAttrData attrData = attrDataList[fromIndex];
            var            fromVal  = _getCurAttrVal(fromIndex);

            if (customVal.HasValue)
            {
                fromVal = customVal.Value;
            }
            if (fromVal <= data.IgnoreMin || fromVal >= data.IgnoreMax)
            {
                return(0);
            }
            fromVal += data.Offset;

            var toVal = 0.0f;

            if (data.IsUseSlot && fromVal >= 0 && fromVal < data.Slot.Count)
            {
                toVal = data.Slot[Mathf.RoundToInt(fromVal)];
            }
            else
            {
                var step = data.Step;
                if (step == 0)
                {
                    CLog.Error("Step不能为0");
                    return(0.0f);
                }

                if (!data.IsReverse)
                {
                    toVal = (fromVal / step) * data.Faction;
                }
                else
                {
                    toVal = ((attrData.Max - fromVal) / step) * data.Faction;
                }
            }
            return(Mathf.Clamp(toVal, data.Min, data.Max));
        }
Beispiel #5
0
        public virtual void SetVal(T type, float val, float?minVal = null, float?maxVal = null)
        {
            var index = Enum <T> .Int(type);

            if (attrDataList != null)
            {
                //截取最大最小限制
                if (minVal != null)
                {
                    if (val < minVal.Value)
                    {
                        val = minVal.Value;
                    }
                }
                if (maxVal != null)
                {
                    if (val > maxVal)
                    {
                        val = maxVal.Value;
                    }
                }

                TDBaseAttrData tempAttrData = GetAttrData(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;
            }

            if (!lastChangedType.Contains(type))
            {
                lastChangedType.Add(type);
            }
            SetDirty();
        }
Beispiel #6
0
        /// <summary>
        /// 手动改变属性值
        /// </summary>
        /// <param name="type">属性类型</param>
        /// <param name="val">改变的值</param>
        /// <param name="minVal">最小值</param>
        /// <param name="maxVal">最大值</param>
        /// <param name="onlyDynamicVal">只能改变Dynamic属性,如果改变了Fixed属性则会提示错误</param>
        public virtual void ChangeVal(T type, float val, float?minVal = null, float?maxVal = null, bool onlyDynamicVal = true)
        {
            if (val == 0)
            {
                return;
            }
            int index = Enum <T> .Int(type);

            TDBaseAttrData tempAttrData = GetAttrData(index);

            if (tempAttrData == null)
            {
                return;
            }
            else if (onlyDynamicVal)
            {
                if (tempAttrData.Type == AttrType.Fixed)
                {
                    CLog.Error("错误!! {0}是Fixed类型,无法使用ChangeVal", typeof(T).Name);
                    return;
                }
            }
            SetVal(type, _getBaseAttrVal(index) + val, minVal, maxVal);
        }
Beispiel #7
0
        public override string GetDesc()
        {
            TDBaseAttrData attrData = BaseAttrMgr <Type> .GetAttrDataList()[Enum <Type> .Int(AttrType)];

            return(GetStr("AC_IsAttrToAct", (AttrType as Enum).GetName(), CompareType.GetName(), BaseAttrMgr <Type> .GetAttrNumberStr(AttrType, val)));
        }