Exemplo n.º 1
0
    /// <summary>
    /// 解析buff数据
    /// </summary>
    /// <param name="buffInfo">buff类</param>
    /// <param name="line">数据行</param>
    private static void TransData(BuffInfo buffInfo, string line)
    {
        // 解析数据
        if (buffInfo == null)
        {
            throw new Exception("buffID未指定.buff类为空");
        }

        var pos   = GetSmallBraketPos(line, false);
        var start = pos[0];
        var end   = pos[1];
        // 编号长度
        var length = end - start - 1;

        if (end > 0 && start > 0)
        {
            var symbol = line.Substring(0, start).Trim();
            var strVal = line.Substring(start + 1, length).Trim();
            switch (symbol)
            {
            case "BuffTime":
            {
                buffInfo.BuffTime = buffInfo.GetDataOrReplace <float>("BuffTime", strVal);
            }
            break;

            case "TickTime":
            {
                buffInfo.TickTime = buffInfo.GetDataOrReplace <float>("TickTime", strVal);
            }
            break;

            case "BuffType":
            {
                buffInfo.BuffType = buffInfo.GetDataOrReplace <BuffType>("BuffType", strVal);
            }
            break;

            case "TriggerLevel1":
            {
                // 技能触发事件level1
                buffInfo.TriggerLevel1 = buffInfo.GetDataOrReplace <TriggerLevel1>("TriggerLevel1", strVal);
            }
            break;

            case "TriggerLevel2":
            {
                // 技能触发事件level2
                buffInfo.TriggerLevel2 = buffInfo.GetDataOrReplace <TriggerLevel2>("TriggerLevel2", strVal);
            }
            break;

            case "TriggerProbability":
            {
                //BUFF触发概率
                buffInfo.TriggerProbability = buffInfo.GetDataOrReplace <float>("TriggerProbability", strVal);
            }
            break;

            case "DetachTriggerLevel1":
            {
                // buff Detach触发条件level1
                buffInfo.DetachTriggerLevel1 = buffInfo.GetDataOrReplace <TriggerLevel1>("DetachTriggerLevel1", strVal);
            }
            break;

            case "DetachTriggerLevel2":
            {
                // buff Detach触发条件level2
                buffInfo.DetachTriggerLevel2 = buffInfo.GetDataOrReplace <TriggerLevel2>("DetachTriggerLevel2", strVal);
            }
            break;

            case "BuffLevel":
            {
                // buff优先级
                buffInfo.BuffLevel = buffInfo.GetDataOrReplace <int>("BuffLevel", strVal);
            }
            break;

            case "BuffGroup":
            {
                // buff组
                buffInfo.BuffGroup = buffInfo.GetDataOrReplace <int>("BuffGroup", strVal);
            }
            break;

            case "IsBeneficial":
            {
                buffInfo.IsBeneficial = buffInfo.GetDataOrReplace <bool>("IsBeneficial", strVal);
            }
            break;

            case "ChangeData":
            {
                // 使用反射获得数据
                if (buffInfo.ChangeData == null)
                {
                    buffInfo.ChangeData = new VOBase();
                }
                // 获取值
                var values = line.Substring(start + 1, end - start - 1).Split(',');
                // 属性名称
                var propertyName = values[0].Trim();
                // 属性值
                var propertyValue = values[1].Trim();
                // 属性值类型
                var propertyType = (ChangeDataType)Enum.Parse(typeof(ChangeDataType), values[2].Trim());
                // 反射获取类中的属性
                var property = buffInfo.ChangeData.GetType().GetProperty(propertyName); FieldInfo field = null;
                if (property == null)
                {
                    field = buffInfo.ChangeData.GetType().GetField(propertyName);
                    if (field == null)
                    {
                        throw new Exception("属性不存在, 请检查是否正确, 区分大小写:" + propertyName);
                    }
                }
                // 如果该属性不可以被控制报错
                if ((property == null || !property.GetCustomAttributes(typeof(SkillAddition), false).Any()) &&
                    (field == null || !field.GetCustomAttributes(typeof(SkillAddition), true).Any()))
                {
                    throw new Exception("该属性不可被技能控制:" + propertyName);
                }
                // 设置属性值
                if (property != null)
                {
                    property.SetValue(buffInfo.ChangeData, Convert.ChangeType(propertyValue, property.PropertyType), null);
                }
                if (field != null)
                {
                    field.SetValue(buffInfo.ChangeData, Convert.ChangeType(propertyValue, field.FieldType));
                }
                // 设置该属性的附加类型
                buffInfo.ChangeDataTypeDic.Add(propertyName, propertyType);
            }
            break;

            case "DemageChange":
            {
                // 解析数据
                var values = strVal.Split(',');
                // 类型 (0:伤害增强/1:伤害减免)
                //var type = Convert.ToInt32(values[0].Trim());
                //// 伤害增强/减免值(百分比, 1为100%)
                //var demageVal = Convert.ToSingle(values[1].Trim());
                //// 产生伤害增强/减免概率(百分比, 1为100%)
                //var probability = Convert.ToSingle(values[2].Trim());
                //// 目标/来源类型
                //var targetType = (DemageAdditionOrReductionTargetType)Enum.Parse(typeof(DemageAdditionOrReductionTargetType), values[3].Trim());

                buffInfo.DemageChangeType        = buffInfo.GetDataOrReplace <int>("DemageChangeType", values[0].Trim());
                buffInfo.DemageChange            = buffInfo.GetDataOrReplace <float>("DemageChange", values[1].Trim());
                buffInfo.DemageChangeProbability = buffInfo.GetDataOrReplace <float>("DemageChangeProbability", values[2].Trim());
                buffInfo.DemageChangeTargetType  = buffInfo.GetDataOrReplace <DemageAdditionOrReductionTargetType>("DemageChangeTargetType", values[3].Trim());
            }
            break;

            case "DetachQualified":
            {
                // buff的Detach条件
                var param = strVal.Split(',');
                var key   = param[0];
                var op    = param[1];
                var value = param[2];
                buffInfo.DetachQualifiedKeyList.Add(key);
                buffInfo.DetachQualifiedOptionList.Add(op);
                buffInfo.DetachQualifiedValueList.Add(value);
            }
            break;

            case "IsDeadDisappear":
            {
                // buff存在状态
                buffInfo.IsDeadDisappear = buffInfo.GetDataOrReplace <bool>("IsDeadDisappear", strVal);
            }
            break;

            case "IsNotLethal":
            {
                // buff是否不致死
                buffInfo.IsNotLethal = buffInfo.GetDataOrReplace <bool>("IsNotLethal", strVal);
            }
            break;

            case "IsCouldNotClear":
            {
                // buff是否不可清除
                buffInfo.IsCouldNotClear = buffInfo.GetDataOrReplace <bool>("IsCouldNotClear", strVal);
            }
            break;

            case "Description":
            {
                // buff说明
                buffInfo.Description = buffInfo.GetDataOrReplace <string>("Description", strVal);
            }
            break;

            case "Icon":
            {
                // buff Icon
                buffInfo.Icon = buffInfo.GetDataOrReplace <string>("Icon", strVal);
            }
            break;

            case "HpScopeMax":
            {
                // 触发Action生命上限
                buffInfo.HpScopeMax = buffInfo.GetDataOrReplace <float>("HpScopeMax", strVal);
            }
            break;

            case "HpScopeMin":
            {
                // 触发Action生命下限
                buffInfo.HpScopeMin = buffInfo.GetDataOrReplace <float>("HpScopeMin", strVal);
            }
            break;

            case "DetachHpScopeMax":
            {
                // 触发Detach生命上限
                buffInfo.DetachHpScopeMax = buffInfo.GetDataOrReplace <float>("DetachHpScopeMax", strVal);
            }
            break;

            case "DetachHpScopeMin":
            {
                // 触发Detah生命下限
                buffInfo.DetachHpScopeMin = buffInfo.GetDataOrReplace <float>("DetachHpScopeMin", strVal);
            }
            break;
            }
        }
        else if (start < 0 && end < 0)
        {
            // 解析数据脚本
            var dataArray = line.Split(',');
            var dataList  = dataArray.ToList();
            buffInfo.DataList.Add(dataList);
        }
        else
        {
            ValidSmallBraketIndex(start, end, line);
        }
    }