コード例 #1
0
        public static void DbCommaRange <T>(DbDebugItem <T> debug, AttributeList list, int indexStart, int length, bool addAutomatically = true)
        {
            var table = debug.AbsractDb.Table;

            foreach (string[] elements in TextFileHelper.GetElementsByCommas(File.ReadAllBytes(debug.FilePath)))
            {
                try {
                    T itemId = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);

                    if (!addAutomatically && !table.ContainsKey(itemId))
                    {
                        Z.F();
                        continue;
                    }

                    int max = length;

                    for (int index = 1; index < elements.Length && max > 0; index++)
                    {
                        DbAttribute property = list.Attributes[index + indexStart - 1];
                        table.SetRaw(itemId, property, elements[index]);
                        max--;
                    }
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
            }
        }
コード例 #2
0
        public static void DbCommaNoCast <T>(DbDebugItem <T> debug, AttributeList list, int indexStart, int length)
        {
            var table = debug.AbsractDb.Table;

            foreach (string[] elements in TextFileHelper.GetElementsByCommas(File.ReadAllBytes(debug.FilePath)))
            {
                try {
                    T   itemId = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);
                    int max    = length;

                    for (int index = 1; index < elements.Length && max > 0; index++)
                    {
                        DbAttribute property = list.Attributes[index + indexStart - 1];

                        int previousVal = 0;

                        if (table.ContainsKey(itemId))
                        {
                            previousVal = table.GetTuple(itemId).GetValue <int>(ServerSkillAttributes.Flag);
                        }

                        table.SetRaw(itemId, property, Int32.Parse(elements[index]) | previousVal);
                        max--;
                    }
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
            }
        }
コード例 #3
0
        public static void DbLoaderCommaRange <T>(DbDebugItem <T> debug, AttributeList list, int indexStart, int length, bool addAutomatically = true)
        {
            var table = debug.AbsractDb.Table;

            foreach (string[] elements in TextFileHelper.GetElementsByCommas(FtpHelper.ReadAllBytes(debug.FilePath)))
            {
                try {
                    T itemId = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);

                    if (!addAutomatically && !table.ContainsKey(itemId))
                    {
                        TkDictionary <T, string[]> phantomTable;

                        if (!debug.AbsractDb.Attached.ContainsKey("Phantom." + debug.DbSource.Filename))
                        {
                            phantomTable = new TkDictionary <T, string[]>();
                            debug.AbsractDb.Attached["Phantom." + debug.DbSource.Filename] = phantomTable;
                        }
                        else
                        {
                            phantomTable = (TkDictionary <T, string[]>)debug.AbsractDb.Attached["Phantom." + debug.DbSource.Filename];
                        }

                        phantomTable[itemId] = elements;
                        continue;
                    }

                    int max = length;

                    for (int index = 1; index < elements.Length && max > 0; index++)
                    {
                        DbAttribute property = list.Attributes[index + indexStart - 1];
                        table.SetRaw(itemId, property, elements[index]);
                        max--;
                    }
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
            }
        }
コード例 #4
0
ファイル: DbIOItemGroups.cs プロジェクト: userid0/RagnarokSDE
        private static void _loadItemsGroupdDb(AbstractDb <int> db, ServerDbs serverDb, string file)
        {
            int numberOfErrors = 3;

            TextFileHelper.LatestFile = file;

            if (String.IsNullOrEmpty(file))
            {
                DbIOErrorHandler.Handle(StackTraceException.GetStrackTraceException(), "File not found " + ServerDbs.ItemGroups + ".", ErrorLevel.NotSpecified);
                return;
            }

            var itemDb1 = db.ProjectDatabase.GetDb <int>(ServerDbs.Items);
            var itemDb2 = db.ProjectDatabase.GetDb <int>(ServerDbs.Items2);

            if (!itemDb1.IsLoaded)
            {
                itemDb1.LoadDb();
            }

            if (!itemDb2.IsLoaded)
            {
                itemDb2.LoadDb();
            }

            var itemDb = new MetaTable <int>(ServerItemAttributes.AttributeList);

            itemDb.AddTable(itemDb1.Table);
            itemDb.AddTable(itemDb2.Table);
            itemDb.MergeOnce();

            Dictionary <string, ReadableTuple <int> > bufferredTuples = new Dictionary <string, ReadableTuple <int> >();

            foreach (var tuple in itemDb.FastItems)
            {
                bufferredTuples[tuple.GetStringValue(ServerItemAttributes.AegisName.Index)] = tuple;
            }

            var table = db.Table;

            if (db.Attached[serverDb] == null)
            {
                db.Attached[serverDb] = new Utilities.Extension.Tuple <ServerDbs, HashSet <int> >(serverDb, new HashSet <int>());
            }

            HashSet <int> loadedIds = ((Utilities.Extension.Tuple <ServerDbs, HashSet <int> >)db.Attached[serverDb]).Item2;

            foreach (string[] elements in TextFileHelper.GetElementsByCommas(IOHelper.ReadAllBytes(file)))
            {
                try {
                    int itemId;
                    int iItemId;

                    if (Int32.TryParse(elements[0], out iItemId))
                    {
                        itemId = iItemId;
                    }
                    else
                    {
                        var constantDb = db.ProjectDatabase.GetDb <string>(ServerDbs.Constants);

                        if (!constantDb.IsLoaded)
                        {
                            constantDb.LoadDb();
                        }

                        var tuple = constantDb.Table.TryGetTuple(elements[0]);

                        if (tuple == null)
                        {
                            if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0]))
                            {
                                return;
                            }
                            continue;
                        }

                        itemId = tuple.GetValue <int>(1);
                    }

                    string orate = elements[2];

                    int nameId;
                    int rate;

                    if (Int32.TryParse(elements[1], out nameId))
                    {
                    }
                    else
                    {
                        var tuple = bufferredTuples[elements[1]];

                        if (tuple == null)
                        {
                            if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0]))
                            {
                                return;
                            }
                            continue;
                        }

                        nameId = tuple.Key;
                    }

                    Int32.TryParse(orate, out rate);

                    var id = (object)itemId;
                    loadedIds.Add((int)id);

                    if (!table.ContainsKey(itemId))
                    {
                        ReadableTuple <int> tuple = new ReadableTuple <int>(itemId, db.AttributeList);
                        tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >());
                        table.Add(itemId, tuple);
                    }

                    Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(itemId, ServerItemGroupAttributes.Table);

                    ReadableTuple <int> newTuple   = new ReadableTuple <int>(nameId, ServerItemGroupSubAttributes.AttributeList);
                    List <DbAttribute>  attributes = new List <DbAttribute>(ServerItemGroupSubAttributes.AttributeList.Attributes);

                    for (int i = 2; i < elements.Length; i++)
                    {
                        newTuple.SetRawValue(attributes[i - 1], elements[i]);
                    }

                    newTuple.SetRawValue(ServerItemGroupSubAttributes.ParentGroup, itemId);

                    dico[nameId] = newTuple;
                }
                catch {
                    if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0]))
                    {
                        return;
                    }
                }
            }
        }
コード例 #5
0
        public static void Loader(DbDebugItem <int> debug, AbstractDb <int> db, int groupId)
        {
            bool hasGuessedAttributes     = false;
            List <DbAttribute> attributes = new List <DbAttribute>(ServerMobGroupSubAttributes.AttributeList.Attributes.Where(p => p.Visibility == VisibleState.Visible));
            var table = db.Table;

            if (!table.ContainsKey(groupId))
            {
                ReadableTuple <int> tuple = new ReadableTuple <int>(groupId, db.AttributeList);
                tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >());
                table.Add(groupId, tuple);
            }

            var dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(groupId, ServerMobGroupAttributes.Table);

            foreach (string[] elements in TextFileHelper.GetElementsByCommas(IOHelper.ReadAllBytes(debug.FilePath)))
            {
                try {
                    if (!hasGuessedAttributes)
                    {
                        db.Attached["Scanned"] = null;
                        DbIOMethods.GuessAttributes(elements, attributes, -1, db);
                        hasGuessedAttributes = true;
                    }

                    if (attributes.Count == 4)
                    {
                        // rAthena
                        int id = Int32.Parse(elements[1]);

                        ReadableTuple <int> tuple = new ReadableTuple <int>(id, ServerMobGroupSubAttributes.AttributeList);
                        tuple.SetRawValue(ServerMobGroupSubAttributes.Rate, elements[3]);
                        tuple.SetRawValue(ServerMobGroupSubAttributes.DummyName, elements[2]);
                        tuple.SetRawValue(ServerMobGroupSubAttributes.ParentGroup, groupId);
                        dico[id] = tuple;
                    }
                    else
                    {
                        // Hercules
                        int id = Int32.Parse(elements[0]);

                        ReadableTuple <int> tuple = new ReadableTuple <int>(id, ServerMobGroupSubAttributes.AttributeList);
                        tuple.SetRawValue(ServerMobGroupSubAttributes.Rate, elements[2]);
                        tuple.SetRawValue(ServerMobGroupSubAttributes.DummyName, elements[1]);
                        tuple.SetRawValue(ServerMobGroupSubAttributes.ParentGroup, groupId);
                        dico[id] = tuple;
                    }
                }
                catch {
                    if (elements.Length <= 0)
                    {
                        if (!debug.ReportIdException("#"))
                        {
                            return;
                        }
                    }
                    else if (!debug.ReportIdException(elements[0]))
                    {
                        return;
                    }
                }
            }
        }
コード例 #6
0
        private static void _loadItemsGroupdDb <TKey>(AbstractDb <TKey> db, string file)
        {
            int numberOfErrors = 3;

            TextFileHelper.LatestFile = file;

            if (String.IsNullOrEmpty(file))
            {
                DbLoaderErrorHandler.Handle("File not found " + ServerDbs.ItemGroups + ".", ErrorLevel.NotSpecified);
                return;
            }

            var itemDb1 = db.Database.GetDb <int>(ServerDbs.Items);
            var itemDb2 = db.Database.GetDb <int>(ServerDbs.Items);

            if (!itemDb1.IsLoaded)
            {
                itemDb1.LoadDb();
            }

            if (!itemDb2.IsLoaded)
            {
                itemDb2.LoadDb();
            }

            var itemDb = new MetaTable <int>(ServerItemAttributes.AttributeList);

            itemDb.AddTable(itemDb1.Table);
            itemDb.AddTable(itemDb2.Table);

            var           table     = db.Table;
            HashSet <int> loadedIds = ((Tuple <string, HashSet <int> >)db.Attached[file]).Item2;

            foreach (string[] elements in TextFileHelper.GetElementsByCommas(File.ReadAllBytes(file)))
            {
                try {
                    TKey itemId;
                    int  iItemId;

                    if (Int32.TryParse(elements[0], out iItemId))
                    {
                        itemId = (TKey)(object)iItemId;
                    }
                    else
                    {
                        var constantDb = db.Database.GetDb <string>(ServerDbs.Constants);

                        if (!constantDb.IsLoaded)
                        {
                            constantDb.LoadDb();
                        }

                        var tuple = constantDb.Table.TryGetTuple(elements[0]);

                        if (tuple == null)
                        {
                            if (AllLoaders.GenericErrorHandler(ref numberOfErrors, elements[0]))
                            {
                                return;
                            }
                            continue;
                        }

                        itemId = (TKey)(object)tuple.GetValue <int>(1);
                    }

                    string orate = elements[2];

                    int nameId;
                    int rate;

                    if (Int32.TryParse(elements[1], out nameId))
                    {
                    }
                    else
                    {
                        var tuple = itemDb.FastItems.FirstOrDefault(p => p.GetStringValue(ServerItemAttributes.AegisName.Index) == elements[1]);

                        if (tuple == null)
                        {
                            if (AllLoaders.GenericErrorHandler(ref numberOfErrors, elements[0]))
                            {
                                return;
                            }
                            continue;
                        }

                        nameId = tuple.GetKey <int>();
                    }

                    Int32.TryParse(orate, out rate);

                    var id = (object)itemId;
                    loadedIds.Add((int)id);

                    if (!table.ContainsKey(itemId))
                    {
                        ReadableTuple <TKey> tuple = new ReadableTuple <TKey>(itemId, db.AttributeList);
                        tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >());
                        table.Add(itemId, tuple);
                    }

                    Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(itemId, ServerItemGroupAttributes.Table);

                    ReadableTuple <int> newTuple   = new ReadableTuple <int>(nameId, ServerItemGroupSubAttributes.AttributeList);
                    List <DbAttribute>  attributes = new List <DbAttribute>(ServerItemGroupSubAttributes.AttributeList.Attributes);

                    for (int i = 2; i < elements.Length; i++)
                    {
                        db.Attached[attributes[i - 1].DisplayName] = true;
                        newTuple.SetRawValue(attributes[i - 1], elements[i]);
                    }

                    dico[nameId] = newTuple;
                }
                catch {
                    if (AllLoaders.GenericErrorHandler(ref numberOfErrors, elements[0]))
                    {
                        return;
                    }
                }
            }
        }