Пример #1
0
        public static void DbItemsFunction <TKey>(DbDebugItem <TKey> debug, AttributeList list, string[] elements, Table <TKey, ReadableTuple <TKey> > table)
        {
#if SDE_DEBUG
            CLHelper.CR(-3);
#endif
            ItemParser itemHelper = new ItemParser(elements[0]);
#if SDE_DEBUG
            CLHelper.CS(-3);
#endif
            TKey itemId = (TKey)(object)Int32.Parse(itemHelper.Id);

            // This is not allowed because it doesn't follow the Table rules consistency
            // The table is the one generating the events, calling table.Add() will not update
            // the list views properly.
            //ReadableTuple<TKey> tuple = new ReadableTuple<TKey>(itemId, ServerItemAttributes.AttributeList);
            //table.Add(itemId, tuple);

            table.SetRaw(itemId, ServerItemAttributes.AegisName, itemHelper.AegisName);
            table.SetRaw(itemId, ServerItemAttributes.Name, itemHelper.Name);
            table.SetRaw(itemId, ServerItemAttributes.Type, itemHelper.Type);
            table.SetRaw(itemId, ServerItemAttributes.Buy, itemHelper.Buy);
            table.SetRaw(itemId, ServerItemAttributes.Sell, itemHelper.Sell);
            table.SetRaw(itemId, ServerItemAttributes.Weight, itemHelper.Weight);
            table.SetRaw(itemId, ServerItemAttributes.Attack, itemHelper.Atk);
            table.SetRaw(itemId, ServerItemAttributes.Defense, itemHelper.Def);
            table.SetRaw(itemId, ServerItemAttributes.Range, itemHelper.Range);
            table.SetRaw(itemId, ServerItemAttributes.NumberOfSlots, itemHelper.Slots);
            table.SetRaw(itemId, ServerItemAttributes.ApplicableJob, itemHelper.Job);
            table.SetRaw(itemId, ServerItemAttributes.Upper, itemHelper.Upper);
            table.SetRaw(itemId, ServerItemAttributes.Gender, itemHelper.Gender);
            table.SetRaw(itemId, ServerItemAttributes.Location, itemHelper.Loc);
            table.SetRaw(itemId, ServerItemAttributes.WeaponLevel, itemHelper.WeaponLv);
            table.SetRaw(itemId, ServerItemAttributes.EquipLevel, itemHelper.EquipLv);
            table.SetRaw(itemId, ServerItemAttributes.Refineable, itemHelper.Refineable);
            table.SetRaw(itemId, ServerItemAttributes.ClassNumber, itemHelper.View);
            table.SetRaw(itemId, ServerItemAttributes.Script, itemHelper.Script);
            table.SetRaw(itemId, ServerItemAttributes.OnEquipScript, itemHelper.OnEquipScript);
            table.SetRaw(itemId, ServerItemAttributes.OnUnequipScript, itemHelper.OnUnequipScript);

            table.SetRaw(itemId, ServerItemAttributes.Matk, itemHelper.Matk);
            table.SetRaw(itemId, ServerItemAttributes.BindOnEquip, itemHelper.BindOnEquip);
            table.SetRaw(itemId, ServerItemAttributes.BuyingStore, itemHelper.BuyingStore);
            table.SetRaw(itemId, ServerItemAttributes.Delay, itemHelper.Delay);
            table.SetRaw(itemId, ServerItemAttributes.Stack, itemHelper.Stack);
            table.SetRaw(itemId, ServerItemAttributes.Sprite, itemHelper.Sprite);
            table.SetRaw(itemId, ServerItemAttributes.Trade, itemHelper.Trade);
            table.SetRaw(itemId, ServerItemAttributes.NoUse, itemHelper.Nouse);
        }
Пример #2
0
        public static void DbCommaLoader <T>(DbDebugItem <T> debug, AttributeList list, DbCommaFunctionDelegate <T> function, TextFileHelper.TextFileHelperGetterDelegate getter, bool addAutomatically = true)
        {
            var table = debug.AbsractDb.Table;

#if SDE_DEBUG
            Z.StopAndRemoveWithoutDisplay(-1);
            Z.StopAndRemoveWithoutDisplay(-2);
            CLHelper.CR(-2);
#endif
            foreach (string[] elements in getter(File.ReadAllBytes(debug.FilePath)))
            {
#if SDE_DEBUG
                CLHelper.CS(-2);
                CLHelper.CR(-1);
#endif
                try {
                    if (!addAutomatically)
                    {
                        T id = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);

                        if (!table.ContainsKey(id))
                        {
                            Z.F();
                            continue;
                        }
                    }

                    function(debug, list, elements, table);
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
#if SDE_DEBUG
                CLHelper.CS(-1);
                CLHelper.CR(-2);
#endif
            }
#if SDE_DEBUG
            CLHelper.CS(-2);
            CLHelper.WA = ", method core : " + CLHelper.CD(-1) + "ms, loop getter : " + CLHelper.CD(-2) + "ms";
#endif
        }
Пример #3
0
        public static void DbLoaderAny <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, TextFileHelper.TextFileHelperGetterDelegate getter, bool uniqueKey = true)
        {
            List <DbAttribute> attributes = new List <DbAttribute>(db.AttributeList.Attributes);
            int indexOffset      = uniqueKey ? 1 : 0;
            int attributesOffset = uniqueKey ? 0 : 1;

            if (!uniqueKey)
            {
                TextFileHelper.SaveLastLine = true;
            }

#if SDE_DEBUG
            Z.StopAndRemoveWithoutDisplay(-1);
            Z.StopAndRemoveWithoutDisplay(-2);
            CLHelper.CR(-2);
#endif
            foreach (string[] elements in getter(File.ReadAllBytes(debug.FilePath)))
            {
#if SDE_DEBUG
                CLHelper.CS(-2);
                CLHelper.CR(-1);
#endif
                try {
                    _guessAttributes(elements, attributes, -1, db);

                    TKey id;

                    if (uniqueKey)
                    {
                        id = (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFrom(elements[0]);
                    }
                    else
                    {
                        id = (TKey)(object)TextFileHelper.LastLineRead;
                    }

                    for (int index = indexOffset; index < elements.Length; index++)
                    {
                        DbAttribute property = attributes[index + attributesOffset];
                        db.Table.SetRaw(id, property, elements[index]);
                    }
                }
                catch {
                    if (!debug.ReportIdException(elements[0]))
                    {
                        return;
                    }
                }
#if SDE_DEBUG
                CLHelper.CS(-1);
                CLHelper.CR(-2);
#endif
            }
#if SDE_DEBUG
            CLHelper.CS(-2);
            CLHelper.WA = ", method core : " + CLHelper.CD(-1) + "ms, loop getter : " + CLHelper.CD(-2) + "ms";
#endif
            if (!uniqueKey)
            {
                TextFileHelper.SaveLastLine = false;
            }
        }
        public static void DbItemGroups <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            foreach (DbAttribute attribute in ServerItemGroupSubAttributes.AttributeList.Attributes)
            {
                db.Attached[attribute.DisplayName] = false;
            }

            if (debug.FileType == FileType.Txt)
            {
                if (db.Attached["FromUserRawInput"] != null && (bool)db.Attached["FromUserRawInput"])
                {
                    _loadItemsGroupdDb(db, debug.FilePath);
                    return;
                }

                using (StreamReader reader = new StreamReader(File.OpenRead(debug.FilePath))) {
                    string line;

                    while (!reader.EndOfStream)
                    {
                        line = reader.ReadLine();

                        if (line != null && line.StartsWith("import: "))
                        {
                            string dbPath = AllLoaders.DetectPathAll(line.Replace("import: ", ""));

                            if (dbPath == null)
                            {
                                ErrorHandler.HandleException("Couldn't find the file '" + line.Replace("import: ", "") + "'.");
                            }
                            else
                            {
                                db.Attached[dbPath] = new Tuple <string, HashSet <int> >(line.Replace("import: ", ""), new HashSet <int>());
                                _loadItemsGroupdDb(db, dbPath);
                            }
                        }
                    }
                }
            }
            else if (debug.FileType == FileType.Conf)
            {
                ItemGroupParser itemHelper = new ItemGroupParser();
                Table <int, ReadableTuple <int> > itemsDb = db.GetMeta <int>(ServerDbs.Items);
                int index = ServerItemAttributes.AegisName.Index;
                var table = db.Table;

                var items = itemsDb.FastItems;

                // The reverse table is used for an optimization (~3 seconds to ~50 ms)
                // All the items are stored in a dictionary by their name instead of their ID
                TkDictionary <string, int> reverseTable = new TkDictionary <string, int>();

                foreach (var item in items)
                {
                    reverseTable[item.GetStringValue(index).ToLowerInvariant()] = item.GetKey <int>();
                }

#if SDE_DEBUG
                Z.StopAndRemoveWithoutDisplay(-1);
                Z.StopAndRemoveWithoutDisplay(-2);
                Z.StopAndRemoveWithoutDisplay(-3);
                CLHelper.CR(-2);
#endif
                foreach (string elements in TextFileHelper.GetElementsByParenthesis(File.ReadAllBytes(debug.FilePath)))
                {
#if SDE_DEBUG
                    CLHelper.CS(-2);
                    CLHelper.CR(-1);
                    CLHelper.CR(-3);
#endif
                    if (!itemHelper.Init(debug, elements))
                    {
                        return;
                    }
#if SDE_DEBUG
                    CLHelper.CS(-3);
#endif

                    try {
                        Tuple tupleItem = itemsDb.TryGetTuple(reverseTable[itemHelper.Id.ToLowerInvariant()]);

                        if (tupleItem == null)
                        {
                            if (itemHelper.Id.StartsWith("ID"))
                            {
                                int ival;

                                if (Int32.TryParse(itemHelper.Id.Substring(2), out ival))
                                {
                                    tupleItem = itemsDb.TryGetTuple(ival);
                                }

                                if (tupleItem == null)
                                {
                                    debug.ReportIdException("Item ID '" + ival + "' couldn't be found.", itemHelper.Id, ErrorLevel.Critical);
                                    continue;
                                }
                            }

                            if (tupleItem == null)
                            {
                                debug.ReportIdException("Item ID '" + itemHelper.Id + "' couldn't be found.", itemHelper.Id, ErrorLevel.Critical);
                                continue;
                            }
                        }

                        TKey itemId = tupleItem.GetKey <TKey>();

                        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);
                        }

                        for (int i = 0; i < itemHelper.Quantities.Count; i++)
                        {
                            string onameId = itemHelper.Quantities[i].Item1;
                            string orate   = itemHelper.Quantities[i].Item2;
                            int    id      = 0;
                            int    rate;

                            tupleItem = itemsDb.TryGetTuple(reverseTable[onameId.ToLowerInvariant()]);

                            if (tupleItem == null)
                            {
                                if (onameId.StartsWith("ID"))
                                {
                                    if (!Int32.TryParse(onameId.Substring(2), out id))
                                    {
                                        debug.ReportIdException("Item ID '" + itemHelper.Quantities[i].Item1 + "' couldn't be found in group '" + itemHelper.Id + "'.", itemHelper.Id, ErrorLevel.Critical);
                                        continue;
                                    }
                                }
                                else
                                {
                                    debug.ReportIdException("Item ID '" + itemHelper.Quantities[i].Item1 + "' couldn't be found in group '" + itemHelper.Id + "'.", itemHelper.Id, ErrorLevel.Critical);
                                    continue;
                                }
                            }

                            int nameId = tupleItem == null ? id : tupleItem.GetKey <int>();
                            Int32.TryParse(orate, out rate);

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

                            ReadableTuple <int> tuple = new ReadableTuple <int>(nameId, ServerItemGroupSubAttributes.AttributeList);
                            tuple.SetRawValue(ServerItemGroupSubAttributes.Rate, rate);
                            dico[nameId] = tuple;
                        }
                    }
                    catch {
                        if (!debug.ReportIdException(itemHelper.Id))
                        {
                            return;
                        }
                    }
#if SDE_DEBUG
                    CLHelper.CS(-1);
                    CLHelper.CR(-2);
#endif
                }
#if SDE_DEBUG
                CLHelper.CS(-2);
                CLHelper.CS(-3);
                CLHelper.WA = ", method core : " + CLHelper.CD(-1) + "ms, loop getter : " + CLHelper.CD(-2) + "ms, internal parser : " + CLHelper.CD(-3);
#endif
            }
        }