Example #1
0
        /// <summary>
        /// 读取Excel表格并向内存中写入技能数据
        /// </summary>
        /// RowCount,ColumnCount : 读取的行数和列数 维护时请删除Excel内的空白行 以提高性能
        /// <returns></returns>
        ObjectResult <WeaponSkill> LoadFromLocalSkill()
        {
            var ObjResult = new ObjectResult <WeaponSkill>();
            List <WeaponSkill> skillList = new List <WeaponSkill>();

            try
            {
                var asm          = System.Reflection.Assembly.GetExecutingAssembly();
                var resourceName = asm.GetName().Name + ".Resources.Excel.WeaponSkill.xls";

                Aspose.Cells.Workbook wk;
                using (Stream stream = asm.GetManifestResourceStream(resourceName))
                {
                    wk = new Aspose.Cells.Workbook(stream);
                }
                var sheet = wk.Worksheets["WeaponSkill"];

                //读取的行数和列数 维护时请根据Excel内的行数列数设置  以提高性能
                int RowCount    = sheet.Cells.Rows.Count;
                int ColumnCount = 50;

                DataTable dt = sheet.Cells.ExportDataTable(0, 0, RowCount, ColumnCount);
                for (var i = 2; i < dt.Rows.Count; i++)
                {
                    WeaponSkill skill = new WeaponSkill
                    {
                        Skill_ID  = Convert.ToInt32(dt.Rows[i][0]),
                        Main_Name = (WeaponSkill.SkillTypeEnum)Enum.Parse(typeof(WeaponSkill.SkillTypeEnum),
                                                                          dt.Rows[i][1].ToString()),
                        Extra_Name           = dt.Rows[i][2].ToString() == string.Empty ? "" : dt.Rows[i][2].ToString(),
                        Main_Description     = dt.Rows[i][3].ToString() == string.Empty ? "" : dt.Rows[i][3].ToString(),
                        Extra_Description    = dt.Rows[i][4].ToString() == string.Empty ? "" : dt.Rows[i][4].ToString(),
                        Main_Tag             = dt.Rows[i][5].ToString() == string.Empty ? "" : dt.Rows[i][5].ToString(),
                        Extra_Tag            = dt.Rows[i][6].ToString() == string.Empty ? "" : dt.Rows[i][6].ToString(),
                        IsCalculation        = dt.Rows[i][7].ToString() == "1",
                        IsSpecialCalculation = dt.Rows[i][8].ToString() == "1",
                        IsSpecial            = dt.Rows[i][9].ToString() == "1",
                        TheReason            = dt.Rows[i][10].ToString() == string.Empty ? "" : dt.Rows[i][10].ToString(),
                        Extra_Comment        = dt.Rows[i][13].ToString() == string.Empty ? "" : dt.Rows[i][13].ToString(),
                        DurationType         = dt.Rows[i][14].ToString() == string.Empty
                            ? WeaponSkill.DurationEnum.NoHave
                            : (WeaponSkill.DurationEnum)Enum.Parse(typeof(WeaponSkill.DurationEnum),
                                                                   dt.Rows[i][14].ToString()),
                        DurationValue = dt.Rows[i][15].ToString() == string.Empty
                            ? (short)-1
                            : Convert.ToInt16(dt.Rows[i][15].ToString()),
                        SummonType = dt.Rows[i][16].ToString() == string.Empty
                            ? WeaponSkill.SummonEnum.Normal
                            : (WeaponSkill.SummonEnum)Enum.Parse(typeof(WeaponSkill.SummonEnum),
                                                                 dt.Rows[i][16].ToString())
                    };
                    //设置持续时间类型
                    //设置技能生效条件
                    skill.SetConditionType(dt.Rows[i][17].ToString());
                    skill.MaxValue  = dt.Rows[i][18].ToString() == string.Empty ? 0 : Convert.ToDouble(dt.Rows[i][18].ToString());
                    skill.BaseLimit = dt.Rows[i][19].ToString() == string.Empty ? -1.0 : Convert.ToDouble(dt.Rows[i][19].ToString());


                    //设置技能目标
                    if (dt.Rows[i][11].ToString() != string.Empty)
                    {
                        skill.SetSkillTarget(dt.Rows[i][11].ToString());
                    }
                    //设置计算方式
                    if (dt.Rows[i][12].ToString() != string.Empty)
                    {
                        skill.SetFormulaModeEnum(dt.Rows[i][12].ToString());
                    }

                    //设置技能数值
                    var StrList = new List <string>();
                    for (var index = 19; index < 40; index++)
                    {
                        StrList.Add(dt.Rows[i][index].ToString() == string.Empty ? "" : dt.Rows[i][index].ToString());
                    }
                    skill.SetSkillValue(StrList);

                    skillList.Add(skill);
                }
                skillList.Insert(0, new WeaponSkill()
                {
                    Main_Name        = WeaponSkill.SkillTypeEnum.allSkill,
                    Main_Description = "全部技能",
                    Skill_ID         = -1,
                    TheReason        = "该技能仅作为一个筛选技能的词缀存在,无计算,无其他作用",
                    IsCalculation    = false
                });
                skillList.Add(new WeaponSkill()
                {
                    Main_Name        = WeaponSkill.SkillTypeEnum.errorSkill,
                    Main_Description = "错误技能",
                    Skill_ID         = -999,
                    TheReason        = "技能字典集中无此技能,请维护技能字典集",
                    IsCalculation    = false
                });
                ObjResult.ObjList = skillList;
                ObjResult         = new WeaponSkill().GetWeaponSkillList(ObjResult);
            }
            catch (Exception ex)
            {
                return(ObjResult.SetError("从Excel读取技能数据失败:" + ex.Message));
            }
            return(ObjResult);
        }