Esempio n. 1
0
        // Row from code
        public object GetRowFromCode(Xls.TableCodes tableCode, Int16 code)
        {
            ExcelFile table = GetExcelTableFromCode(tableCode);
            object    row;

            return((table.RowFromCode.TryGetValue(code, out row)) ? row : null);
        }
Esempio n. 2
0
        public int GetCodeFromRow(Xls.TableCodes tableCode, object row)
        {
            ExcelFile table = GetExcelTableFromCode(tableCode);
            int       code;

            return((table.CodeFromRow.TryGetValue(row, out code)) ? code : -1);
        }
Esempio n. 3
0
        public Object GetRowFromValue(Xls.TableCodes tableCode, String colName, Object value)
        {
            if (value == null || String.IsNullOrEmpty(colName))
            {
                return(null);
            }

            ExcelFile excelTable = GetExcelTableFromCode(tableCode);

            if (excelTable == null)
            {
                return(null);
            }

            ObjectDelegator tableDelegate = DataFileDelegators[excelTable.StringId];

            ObjectDelegator.FieldDelegate fieldDelegate = tableDelegate.GetFieldDelegate(colName);
            if (fieldDelegate == null)
            {
                return(null);
            }

            foreach (Object row in excelTable.Rows)
            {
                if (value.Equals(fieldDelegate.GetValue(row)))
                {
                    return(row);
                }
            }

            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Retrieves an Excel Table from its Code value. If it's not loaded, then it will be loaded and returned.
        /// </summary>
        /// <param name="code">The code of the Excel Table to retrieve.</param>
        /// <returns>The Excel Table as a DataTable, or null if not found.</returns>
        public ExcelFile GetExcelTableFromCode(Xls.TableCodes code)
        {
            if (DataFiles == null || DataFiles.ContainsKey(ExcelTablesStringId) == false || code == Xls.TableCodes.Null)
            {
                return(null);
            }

            if (_excelCodeToTable == null)
            {
                ExcelFile excelTables = (ExcelFile)DataFiles[ExcelTablesStringId];
                _excelCodeToTable = new Dictionary <Xls.TableCodes, ExcelFile>();

                foreach (ExcelTablesRow excelTablesRow in excelTables.Rows)
                {
                    DataFile dataFile;
                    if (DataFiles.TryGetValue(excelTablesRow.name, out dataFile))
                    {
                        _excelCodeToTable[(Xls.TableCodes)excelTablesRow.code] = (ExcelFile)dataFile;
                    }
                }
            }

            ExcelFile excelTable;

            return(_excelCodeToTable.TryGetValue(code, out excelTable) ? excelTable : null);
        }
Esempio n. 5
0
        // Row from first string
        public object GetRowFromFirstString(Xls.TableCodes tableCode, String firstString)
        {
            ExcelFile table = GetExcelTableFromCode(tableCode);
            Object    row;

            return((table.RowFromFirstString.TryGetValue(firstString, out row)) ? row : null);
        }
Esempio n. 6
0
        // Row index from code
        public int GetRowIndexFromCode(Xls.TableCodes tableCode, Int16 code)
        {
            ExcelFile table = GetExcelTableFromCode(tableCode);
            Object    row;

            return((table.RowFromCode.TryGetValue(code, out row)) ? table.IndexFromRow[row] : -1);
        }
Esempio n. 7
0
        public int GetRowIndexFromRow(Xls.TableCodes tableCode, object row)
        {
            ExcelFile table = GetExcelTableFromCode(tableCode);

            if (row != null)
            {
                int index;
                return((table.IndexFromRow.TryGetValue(row, out index)) ? index : -1);
            }
            return(-1);
        }
Esempio n. 8
0
        // code from first string
        public int GetCodeFromFirstString(Xls.TableCodes tableCode, String firstString)
        {
            ExcelFile table = GetExcelTableFromCode(tableCode);
            object    row;

            if (table.RowFromFirstString.TryGetValue(firstString, out row))
            {
                int code;
                return((table.CodeFromRow.TryGetValue(row, out code)) ? code : -1);
            }
            return(-1);
        }
Esempio n. 9
0
        // Row index from first string
        public int GetRowIndexFromFirstString(Xls.TableCodes tableCode, String firstString)
        {
            ExcelFile table = GetExcelTableFromCode(tableCode);
            object    row   = GetRowFromFirstString(tableCode, firstString);

            if (row != null)
            {
                int index = 0;
                return((table.IndexFromRow.TryGetValue(row, out index)) ? index : -1);
            }
            return(-1);
        }
Esempio n. 10
0
        public String GetExcelStringFromRowIndex(Xls.TableCodes code, int rowIndex, int colIndex = 0)
        {
            if (DataFiles == null || DataFiles.ContainsKey(ExcelTablesStringId) == false || rowIndex < 0)
            {
                return(null);
            }

            ExcelFile excelTable = GetExcelTableFromCode(code);

            String stringVal = _GetExcelStringFromExcelFile(excelTable, rowIndex, colIndex);

            return(stringVal);
        }
Esempio n. 11
0
        public ExcelFile GetExcelTableFromIndex(int tableIndex)
        {
            if (tableIndex < 0)
            {
                throw new ArgumentOutOfRangeException("tableIndex", "The table index must be be at least 0.");
            }

            Xls.TableCodes tableCode = _GetTableCodeFromTableIndex(tableIndex);
            ExcelFile      excelFile = GetExcelTableFromCode(tableCode);

            //if (tableCode == Xls.TableCodes.LEVEL_AREAS || tableCode == Xls.TableCodes.QUEST_COUNT_TUGBOAT ||
            //    tableCode == Xls.TableCodes.QUESTS_TASKS_FOR_TUGBOAT || tableCode == Xls.TableCodes.QUEST_TITLES_FOR_TUGBOAT ||
            //    tableCode == Xls.TableCodes.CRAFTING_SLOTS) return excelFile;

            //if (excelFile == null && tableCode != Xls.TableCodes.Null && tableIndex < _excelIndexToCodeList.Count)
            //{
            //    throw new Exceptions.UnknownExcelCodeException((int)tableCode,
            //        "The excel table code was not found!\nThis means the DataMap has a StringId as a FileName instead of using the FileName attribute parameter.");
            //}

            return(excelFile);
        }
Esempio n. 12
0
        // not needed anymore (name is obtained automatically)
        //private void GenerateUnitNameStrings(UnitObject[] units, Hashtable hash)
        //{
        //    if (hash == null) hash = new Hashtable();

        //    try
        //    {
        //        UnitObjectStats.Stat stat;
        //        foreach (UnitObject unit in units)
        //        {
        //            for (int counter = 0; counter < unit.Stats.Stats.Count; counter++)
        //            {
        //                stat = unit.Stats.Stats[counter];

        //                String name;
        //                if (hash.Contains(stat.Code))
        //                {
        //                    name = (string)hash[stat.Code];
        //                }
        //                else
        //                {
        //                    DataRow[] statRows = statsTable.Select("code = " + stat.Code);
        //                    name = (string)statRows[0]["stat"];

        //                    if (name != null)
        //                    {
        //                        hash.Add(stat.Code, name);
        //                    }
        //                }

        //                unit.Stats[counter].Name = name;
        //            }

        //            GenerateUnitNameStrings(unit.Items.ToArray(), hash);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message, "GenerateUnitNameStrings");
        //    }
        //}

        public string MapIdToString(UnitObjectStats.Stat stat, Xls.TableCodes tableId, int lookupId)
        {
            string value = string.Empty;

            if (stat.Values.Count != 0)
            {
                String    select = String.Format("code = '{0}'", lookupId);
                DataTable table  = null;// todo: rewrite  _dataSet.GetExcelTableFromCode((uint)tableId);
                DataRow[] row;

                if (table != null)
                {
                    row = table.Select(select);

                    if (row != null && row.Length != 0)
                    {
                        value = (string)row[0][1];
                    }
                }
            }

            return(value);
        }
Esempio n. 13
0
 public String GetExcelRowStringFromTableIndex(int tableIndex, int rowIndex)
 {
     Xls.TableCodes tableCode = _GetTableCodeFromTableIndex(tableIndex);
     return(GetExcelStringFromRowIndex(tableCode, rowIndex));
 }
Esempio n. 14
0
        // Row from index
        public object GetRowFromIndex(Xls.TableCodes tableCode, Int32 index)
        {
            ExcelFile table = GetExcelTableFromCode(tableCode);

            return(index < table.Rows.Count() ? (table.Rows[index]) : null);
        }
Esempio n. 15
0
 // UnitData row from index
 public UnitDataRow GetUnitDataRowFromIndex(Xls.TableCodes tableCode, Int32 index)
 {
     return((UnitDataRow)GetRowFromIndex(tableCode, index));
 }
Esempio n. 16
0
 // UnitData row from code
 public UnitDataRow GetUnitDataRowFromCode(Xls.TableCodes tableCode, Int16 code)
 {
     return((UnitDataRow)GetRowFromCode(tableCode, code));
 }
Esempio n. 17
0
        public void ProcessTables()
        {
            // excel tables
            ExcelFile excelTables = (ExcelFile)DataFiles[ExcelTablesStringId];

            foreach (ExcelTablesRow excelTableRow in excelTables.Rows)
            {
                Xls.TableCodes tableCode = (Xls.TableCodes)excelTableRow.code;

                ExcelFile excelTable = GetExcelTableFromCode(tableCode);
                if (excelTable == null)
                {
                    continue;
                }

                excelTable.TableCode = tableCode;
            }

            // stats table
            ExcelFile statsTable = (ExcelFile)DataFiles[StatsTableStringId];

            foreach (StatsRow stat in statsTable.Rows)
            {
                int bitCount = _GetTableRowBitMax(stat.valTable, false);
                if (bitCount != -1)
                {
                    stat.valbits = bitCount;
                }

                bitCount = _GetTableRowBitMax(stat.param1Table, true);
                if (bitCount != -1)
                {
                    stat.param1Bits = bitCount;
                }
                if (stat.param1Bits > 0)
                {
                    stat.ParamCount++;
                }

                bitCount = _GetTableRowBitMax(stat.param2Table, true);
                if (bitCount != -1)
                {
                    stat.param2Bits = bitCount;
                }
                if (stat.param2Bits > 0)
                {
                    stat.ParamCount++;
                }

                bitCount = _GetTableRowBitMax(stat.param3Table, true);
                if (bitCount != -1)
                {
                    stat.param3Bits = bitCount;
                }
                if (stat.param3Bits > 0)
                {
                    stat.ParamCount++;
                }

                bitCount = _GetTableRowBitMax(stat.param4Table, true);
                if (bitCount != -1)
                {
                    stat.param4Bits = bitCount;
                }
                if (stat.param4Bits > 0)
                {
                    stat.ParamCount++;
                }

                if (stat.valTable != -1)
                {
                    stat.ValueExcelTable = GetExcelTableFromIndex(stat.valTable);
                }
                if (stat.param1Table != -1)
                {
                    stat.Param1ExcelTable = GetExcelTableFromIndex(stat.param1Table);
                }
                if (stat.param2Table != -1)
                {
                    stat.Param2ExcelTable = GetExcelTableFromIndex(stat.param2Table);
                }
                if (stat.param3Table != -1)
                {
                    stat.Param3ExcelTable = GetExcelTableFromIndex(stat.param3Table);
                }
                if (stat.param4Table != -1)
                {
                    stat.Param4ExcelTable = GetExcelTableFromIndex(stat.param4Table);
                }
            }

            // level drlg choice table
            ExcelFile levelDrlgChoiceTable = (ExcelFile)DataFiles["LEVEL_DRLG_CHOICE"];

            foreach (LevelDrlgChoiceRow levelDrlgChoice in levelDrlgChoiceTable.Rows)
            {
                if (levelDrlgChoice.nameOffset == -1)
                {
                    continue;
                }

                levelDrlgChoice.name = levelDrlgChoiceTable.ReadStringTable(levelDrlgChoice.nameOffset);
                Debug.Assert(!String.IsNullOrEmpty(levelDrlgChoice.name));
            }
        }