Exemple #1
0
 private bool LoadSpellTableFromBin(string FullPatch)
 {
     m_IDIDAllocator.ClearIDAllocator();
     //技能配置
     if (!DataTableSerializer.LoadBinToTable(ref gSpell_All_DataList, FullPatch, WrapperReflection.gAssembly.GetType("SPELL.SPELL_DATA")))
     {
         return(false);
     }
     if (gSpell_All_DataList.Rows.Count > 0)
     {
         for (int i = 0; i < gSpell_All_DataList.Rows.Count; i++)
         {
             //取出最大的ID
             uint Id = Convert.ToUInt32(gSpell_All_DataList.Rows[i][0]);
             m_IDIDAllocator.PushUsedId(Id);
         }
     }
     m_IDIDAllocator.CalculateUnUsedID();
     return(true);
 }
        /// <summary>
        /// 加载csv到存储模式的table
        /// </summary>
        /// <param name="tablSet">需要填充的table合集</param>
        /// <param name="filePath">文件路径</param>
        /// <param name="rowIndex">索引</param>
        /// <returns></returns>
        private bool LoadSaveFormatTableToCsv(ref Dictionary <string, DataTable> tableSet, string filePath, int rowIndex = 2)
        {
            if (tableSet == null || string.IsNullOrEmpty(filePath))
            {
                return(false);
            }

            if (rowIndex < 0)
            {
                Trace.Error("DataTableSerializer.LoadCSV,RowIndex参数小于0!");
                return(false);
            }
            if (!File.Exists(filePath))
            {
                Trace.Error("文件不存在:" + filePath);
                return(false);
            }
            int i = 0, j = 0;

            try
            {
                using (StreamReader reader = new StreamReader(filePath, Config.FileEncoding, false))
                {
                    reader.Peek();
                    string CurrentLineName = "";
                    //是否第一次读
                    bool      bFirstRead = true;
                    DataTable table      = null;
                    while (reader.Peek() > 0)
                    {
                        j = j + 1;
                        string _line = reader.ReadLine();
                        if (j >= rowIndex + 1)
                        {
                            string[] _split = _line.Split(',');
                            if (bFirstRead)
                            {
                                CurrentLineName = _split[0];
                                bFirstRead      = false;
                                if (!tableSet.ContainsKey(CurrentLineName))
                                {
                                    Trace.Warring("在参数tableSet中找不到类型:" + CurrentLineName + "数据已忽略");
                                    continue;
                                }
                                table = tableSet[CurrentLineName];
                                table.Clear();
                            }

                            //上一次的的名字和这次的名字不一样
                            if (!CurrentLineName.Equals(_split[0]))
                            {
                                if (!tableSet.ContainsKey(CurrentLineName))
                                {
                                    Trace.Warring("在参数tableSet中找不到类型:" + CurrentLineName + "数据已忽略");
                                    continue;
                                }
                                CurrentLineName = _split[0];
                                table           = tableSet[CurrentLineName];
                                table.Clear();
                            }

                            if (table.Columns.Count != _split.Length)
                            {
                                Trace.Warring("文件:" + filePath + ",第" + (j).ToString() + "行格式与所需要的格式不一致,本行只有" +
                                              (_split.Length).ToString() + "列,所需要的格式为:" + table.Columns.Count + "列,已填充默认值,请注意检查!");
                                //table.Rows.Clear();
                                //return false;
                            }
                            DataRow _row = DataTableSerializer.FillDefaultNewRow(ref table);
                            for (i = 0; i < table.Columns.Count; i++)
                            {
                                if (i > _split.Length - 1)
                                {
                                    break;
                                }

                                if (string.IsNullOrEmpty(_split[i]))
                                {
                                    Trace.Error("文件:" + filePath + ",[" + j.ToString() + "行," + i.ToString() + "列]为空!");
                                    table.Rows.Clear();
                                    return(false);
                                }
                                //第二个是技能ID
                                if (i == 1)
                                {
                                    //取出最大的ID
                                    uint Id = Convert.ToUInt32(_split[i]);
                                    m_IDIDAllocator.PushUsedId(Id);
                                }
                                //枚举类型,特殊处理
                                if (DataTableSerializer.IsEnum(table.Columns[i].DataType))
                                {
                                    _row[i] = Enum.Parse(table.Columns[i].DataType, _split[i]);
                                }
                                else
                                {
                                    _row[i] = _split[i];
                                }
                            }
                            table.Rows.Add(_row);
                        }
                    }
                }
            }
            catch (ArgumentException e)
            {
                string erroMsg;
                erroMsg  = "[" + i.ToString() + "列," + j.ToString() + "行]参数错误,";
                erroMsg += e.Message;
                Trace.Error(erroMsg);
                return(false);
            }
            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 加载bin的条件table
        /// </summary>
        /// <param name="tableArray">table数组</param>
        /// <param name="filePath">文件路径</param>
        /// <returns></returns>
        private bool LoadEffectTableFromBinImp(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(false);
            }

            if (!File.Exists(filePath))
            {
                Trace.Error("文件不存在:" + filePath);
                return(false);
            }
            FileStream _readObj = null;

            try
            {
                using (_readObj = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    foreach (KeyValuePair <string, DataTable> kv in mEffectSet)
                    {
                        BIN_FILE_HEADER header = new BIN_FILE_HEADER();
                        //已经读取完了,跳出
                        if (DataTableSerializer.ReadStruct(ref header, _readObj) <= 0)
                        {
                            break;
                        }

                        if (!mEffectSet.ContainsKey(header.szTypeName))
                        {
                            Trace.Error("加载bin格式的效果时遇到无法识别的类型:" + header.szTypeName);
                            continue;
                        }

                        DataTable table      = mEffectSet[header.szTypeName];
                        Type      structType = m_EffectType[header.szTypeName];

                        table.Clear();
                        FieldInfo[] fields = structType.GetFields();
                        // 逐个输入
                        for (int i = 0; i < header.nItemTotal; i++)
                        {
                            Object structTypeInstance = Activator.CreateInstance(structType);
                            DataTableSerializer.ReadStructFromType(ref structTypeInstance, _readObj, structType);
                            DataRow _row = table.NewRow();

                            for (int j = 0; j < fields.Length; j++)
                            {
                                _row[j] = fields[j].GetValue(structTypeInstance);
                                //第一个是技能ID
                                if (j == 0)
                                {
                                    //取出最大的ID
                                    uint        Id    = Convert.ToUInt32(_row[j]);
                                    IDAllocator alloc = GetIDAllocator(Id);
                                    if (alloc != null)
                                    {
                                        alloc.PushUsedId(Id);
                                    }
                                }
                            }
                            table.Rows.Add(_row);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Trace.Error(e.Message);
                return(false);
            }

            return(true);
        }