コード例 #1
0
        public AccessoryTable(AbstractDb <int> db, byte[] dataAccId, byte[] dataAccName)
        {
            // Load current tables as fallback values
            ItemIdToSprite = LuaHelper.GetRedirectionTable();
            _itemDb        = db.GetMeta <int>(ServerDbs.Items);
            _cItemDb       = db.Get <int>(ServerDbs.CItems);

            LuaAccIdParser   = new LuaParser(dataAccId, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(dataAccId), EncodingService.DisplayEncoding);
            LuaAccNameParser = new LuaParser(dataAccName, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(dataAccName), EncodingService.DisplayEncoding);

            LuaAccId   = LuaHelper.GetLuaTable(LuaAccIdParser, "ACCESSORY_IDs");
            LuaAccName = LuaHelper.GetLuaTable(LuaAccNameParser, "AccNameTable");

            _viewIdToSpriteFallback = GetViewIdTableFallback(LuaAccId, LuaAccName);
            _headgears = _itemDb.FastItems.Where(p => ItemParser.IsArmorType(p) && (p.GetIntNoThrow(ServerItemAttributes.Location) & 7937) != 0).OrderBy(p => p.GetIntNoThrow(ServerItemAttributes.ClassNumber)).ToList();

            LuaAccId.Clear();
            LuaAccName.Clear();
        }
コード例 #2
0
        public static bool GetIdToSpriteTable(AbstractDb <int> db, ViewIdTypes type, out Dictionary <int, string> outputIdsToSprites, out string error)
        {
            outputIdsToSprites = new Dictionary <int, string>();
            error = null;

            if (db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccId) == null || db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccName) == null)
            {
                error = "The accessory ID table or accessory name table has not been set, the paths are based on those.";
                return(false);
            }

            int    temp_i;
            string temp_s;
            var    accIdPath = ProjectConfiguration.SyncAccId;
            Dictionary <string, int> ids;

            switch (type)
            {
            case ViewIdTypes.Weapon:
                if (_weaponBuffer.IsBuffered())
                {
                    outputIdsToSprites = _weaponBuffer.Ids;
                    error = _weaponBuffer.Error;
                    return(_weaponBuffer.Result);
                }

                var weaponPath = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "weapontable" + Path.GetExtension(accIdPath));
                var weaponData = db.ProjectDatabase.MetaGrf.GetData(weaponPath);

                if (weaponData == null)
                {
                    error = "Couldn't find " + weaponPath;
                    _weaponBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                var weaponTable     = new LuaParser(weaponData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(weaponData), EncodingService.DisplayEncoding);
                var weaponIds       = GetLuaTable(weaponTable, "Weapon_IDs");
                var weaponNameTable = GetLuaTable(weaponTable, "WeaponNameTable");

                ids = SetIds(weaponIds, "Weapon_IDs");

                foreach (var pair in weaponNameTable)
                {
                    temp_s = pair.Key.Trim('[', ']');

                    if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                    {
                        outputIdsToSprites[temp_i] = pair.Value.Trim('\"');
                    }
                }

                _weaponBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);

            case ViewIdTypes.Npc:
                if (_npcBuffer.IsBuffered())
                {
                    outputIdsToSprites = _npcBuffer.Ids;
                    error = _npcBuffer.Error;
                    return(_npcBuffer.Result);
                }

                var npcPathSprites = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "jobname" + Path.GetExtension(accIdPath));
                var npcPathIds     = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "npcIdentity" + Path.GetExtension(accIdPath));
                var npcDataSprites = db.ProjectDatabase.MetaGrf.GetData(npcPathSprites);
                var npcDataIds     = db.ProjectDatabase.MetaGrf.GetData(npcPathIds);

                if (npcDataSprites == null)
                {
                    error = "Couldn't find " + npcPathSprites;
                    _npcBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                if (npcDataIds == null)
                {
                    error = "Couldn't find " + npcPathIds;
                    _npcBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                //var itemDb = db.GetMeta<int>(ServerDbs.Items);
                var jobname = new LuaParser(npcDataSprites, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(npcDataSprites), EncodingService.DisplayEncoding);
                var jobtbl  = new LuaParser(npcDataIds, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(npcDataIds), EncodingService.DisplayEncoding);

                var jobtblT  = GetLuaTable(jobtbl, "jobtbl");
                var jobnameT = GetLuaTable(jobname, "JobNameTable");

                ids = SetIds(jobtblT, "jobtbl");

                foreach (var pair in jobnameT)
                {
                    temp_s = pair.Key.Trim('[', ']');

                    if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                    {
                        outputIdsToSprites[temp_i] = pair.Value.Trim('\"');
                    }
                }

                _npcBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);

            case ViewIdTypes.Headgear:
                if (_headgearBuffer.IsBuffered())
                {
                    outputIdsToSprites = _headgearBuffer.Ids;
                    error = _headgearBuffer.Error;
                    return(_headgearBuffer.Result);
                }

                var redirectionTable = GetRedirectionTable();
                var dataAccId        = db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccId);
                var dataAccName      = db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccName);
                var itemDb           = db.GetMeta <int>(ServerDbs.Items);
                var accId            = new LuaParser(dataAccId, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(dataAccId), EncodingService.DisplayEncoding);
                var accName          = new LuaParser(dataAccName, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(dataAccName), EncodingService.DisplayEncoding);
                var accIdT           = GetLuaTable(accId, "ACCESSORY_IDs");
                var accNameT         = GetLuaTable(accName, "AccNameTable");
                outputIdsToSprites = _getViewIdTable(accIdT, accNameT);

                accIdT.Clear();
                accNameT.Clear();

                var resourceToIds = new Dictionary <string, int>();

                if (ProjectConfiguration.HandleViewIds)
                {
                    try {
                        List <ReadableTuple <int> > headgears = itemDb.FastItems.Where(p => ItemParser.IsArmorType(p) && (p.GetIntNoThrow(ServerItemAttributes.Location) & 7937) != 0).OrderBy(p => p.GetIntNoThrow(ServerItemAttributes.ClassNumber)).ToList();
                        _loadFallbackValues(outputIdsToSprites, headgears, accIdT, accNameT, resourceToIds, redirectionTable);
                    }
                    catch (Exception err) {
                        error = err.ToString();
                        _headgearBuffer.Buffer(outputIdsToSprites, false, error);
                        return(false);
                    }
                }

                _headgearBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);

            case ViewIdTypes.Shield:
                if (_shieldBuffer.IsBuffered())
                {
                    outputIdsToSprites = _shieldBuffer.Ids;
                    error = _shieldBuffer.Error;
                    return(_shieldBuffer.Result);
                }

                var shieldPath = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "ShieldTable" + Path.GetExtension(accIdPath));
                var shieldData = db.ProjectDatabase.MetaGrf.GetData(shieldPath);

                if (shieldData == null)
                {
                    outputIdsToSprites[1] = "_°¡µå";
                    outputIdsToSprites[2] = "_¹öŬ·¯";
                    outputIdsToSprites[3] = "_½¯µå";
                    outputIdsToSprites[4] = "_¹Ì·¯½¯µå";
                    outputIdsToSprites[5] = "";
                    outputIdsToSprites[6] = "";
                }
                else
                {
                    _debugStatus = "OK";

                    var shieldTable = new LuaParser(shieldData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(shieldData), EncodingService.DisplayEncoding);

                    _debugStatus = "LoadTables";

                    var shieldIds       = GetLuaTable(shieldTable, "Shield_IDs");
                    var shieldNameTable = GetLuaTable(shieldTable, "ShieldNameTable");
                    var shieldMapTable  = GetLuaTable(shieldTable, "ShieldMapTable");

                    ids = SetIds(shieldIds, "Shield_IDs");
                    Dictionary <int, string> idsToSprite = new Dictionary <int, string>();

                    foreach (var pair in shieldNameTable)
                    {
                        temp_s = pair.Key.Trim('[', ']');

                        if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                        {
                            temp_s = pair.Value.Trim('\"');
                            idsToSprite[temp_i]        = temp_s;
                            outputIdsToSprites[temp_i] = temp_s;
                        }
                    }

                    foreach (var pair in shieldMapTable)
                    {
                        var key = pair.Key.Trim('[', ']', '\t');
                        int id1;

                        if (ids.TryGetValue(key, out id1))
                        {
                            int id2;
                            temp_s = pair.Value.Trim('\"', '\t');

                            if (ids.TryGetValue(temp_s, out id2) || Int32.TryParse(temp_s, out id2))
                            {
                                if (idsToSprite.TryGetValue(id2, out temp_s))
                                {
                                    outputIdsToSprites[id1] = temp_s;
                                }
                            }
                        }
                    }

                    error = PreviewHelper.ViewIdIncrease;
                }

                _shieldBuffer.Buffer(outputIdsToSprites, true, error);
                return(true);

            case ViewIdTypes.Garment:
                if (_garmentBuffer.IsBuffered())
                {
                    outputIdsToSprites = _garmentBuffer.Ids;
                    error = _garmentBuffer.Error;
                    return(_garmentBuffer.Result);
                }

                var robeSpriteName = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "spriterobename" + Path.GetExtension(accIdPath));
                var robeSpriteId   = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "spriterobeid" + Path.GetExtension(accIdPath));
                var robeNameData   = db.ProjectDatabase.MetaGrf.GetData(robeSpriteName);
                var robeIdData     = db.ProjectDatabase.MetaGrf.GetData(robeSpriteId);

                if (robeNameData == null)
                {
                    error = "Couldn't find " + robeSpriteName;
                    _garmentBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                if (robeIdData == null)
                {
                    error = "Couldn't find " + robeSpriteId;
                    _garmentBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                var robeNameTable = new LuaParser(robeNameData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(robeNameData), EncodingService.DisplayEncoding);
                var robeIdTable   = new LuaParser(robeIdData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(robeIdData), EncodingService.DisplayEncoding);
                var robeNames     = GetLuaTable(robeNameTable, "RobeNameTable");
                var robeIds       = GetLuaTable(robeIdTable, "SPRITE_ROBE_IDs");

                ids = SetIds(robeIds, "SPRITE_ROBE_IDs");

                foreach (var pair in robeNames)
                {
                    temp_s = pair.Key.Trim('[', ']');

                    if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                    {
                        outputIdsToSprites[temp_i] = pair.Value.Trim('\"');
                    }
                }

                _garmentBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);
            }

            return(false);
        }
コード例 #3
0
ファイル: DbIOItemGroups.cs プロジェクト: userid0/RagnarokSDE
        public static void Writer(DbDebugItem <int> debug, AbstractDb <int> db)
        {
            try {
                if (debug.FileType == FileType.Txt)
                {
                    // Do not care about the loaded IDs, just write them where they belong
                    _idToGroupName.Clear();
                    var itemDb = db.GetMeta <int>(ServerDbs.Items);
                    AbstractDb <string> constantDb = db.GetDb <string>(ServerDbs.Constants);
                    var affectedGroups             = new HashSet <int>();
                    var nonNullGroups = new HashSet <int> {
                        1, 2, 3, 4, 6, 44, 28, 29, 30, 31, 34, 43
                    };

                    if (debug.DbSource == ServerDbs.ItemGroupsBlueBox)
                    {
                        affectedGroups = new HashSet <int> {
                            1
                        };
                    }
                    else if (debug.DbSource == ServerDbs.ItemGroupsVioletBox)
                    {
                        affectedGroups = new HashSet <int> {
                            2
                        };
                    }
                    else if (debug.DbSource == ServerDbs.ItemGroupsCardalbum)
                    {
                        affectedGroups = new HashSet <int> {
                            3, 44
                        };
                    }
                    else if (debug.DbSource == ServerDbs.ItemGroupsFindingore)
                    {
                        affectedGroups = new HashSet <int> {
                            6
                        };
                    }
                    else if (debug.DbSource == ServerDbs.ItemGroupsGiftBox)
                    {
                        affectedGroups = new HashSet <int> {
                            4, 28, 29, 30, 31, 34, 43
                        };
                    }
                    else if (debug.DbSource == ServerDbs.ItemGroupsMisc)
                    {
                        affectedGroups = null;
                    }
                    else if (debug.DbSource == ServerDbs.ItemGroupsPackages)
                    {
                        affectedGroups = null;
                    }

                    if (affectedGroups != null)
                    {
                        while (true)
                        {
                            bool isModified = false;

                            // Check if the group was modified or not
                            foreach (var tuple in db.Table.FastItems.Where(p => affectedGroups.Contains(p.Key)))
                            {
                                if (!tuple.Normal)
                                {
                                    isModified = true;
                                    break;
                                }
                            }

                            if (isModified)
                            {
                                break;
                            }

                            // Check if the file has more groups than what it's supposed to
                            HashSet <int> loadedIds = ((Utilities.Extension.Tuple <ServerDbs, HashSet <int> >)db.Attached[debug.DbSource]).Item2;

                            foreach (var id in loadedIds)
                            {
                                if (!affectedGroups.Contains(id))
                                {
                                    isModified = true;
                                    break;
                                }
                            }

                            if (isModified)
                            {
                                break;
                            }

                            foreach (var id in affectedGroups)
                            {
                                if (!loadedIds.Contains(id))
                                {
                                    isModified = true;
                                    break;
                                }
                            }

                            if (isModified)
                            {
                                break;
                            }

                            return;
                        }
                    }
                    else
                    {
                        while (true)
                        {
                            bool isModified = false;

                            // Check if the group was modified or not
                            foreach (var tuple in db.Table.FastItems.Where(p => !nonNullGroups.Contains(p.Key)))
                            {
                                bool isPackage = _isPackage((Dictionary <int, ReadableTuple <int> >)tuple.GetRawValue(1));

                                if (debug.DbSource == ServerDbs.ItemGroupsMisc && isPackage)
                                {
                                    continue;
                                }

                                if (debug.DbSource == ServerDbs.ItemGroupsPackages && !isPackage)
                                {
                                    continue;
                                }

                                if (!tuple.Normal)
                                {
                                    isModified = true;
                                    break;
                                }
                            }

                            if (isModified)
                            {
                                break;
                            }

                            return;
                        }
                    }

                    using (StreamWriter writer = new StreamWriter(debug.FilePath)) {
                        foreach (ReadableTuple <int> tup in db.Table.FastItems.OrderBy(p => p.Key))
                        {
                            Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)tup.GetRawValue(1);
                            int  key       = tup.GetKey <int>();
                            bool isPackage = _isPackage(dico);

                            if ((affectedGroups != null && affectedGroups.Contains(key)) ||
                                (affectedGroups == null && debug.DbSource == ServerDbs.ItemGroupsGiftBox && isPackage == false) ||
                                (affectedGroups == null && debug.DbSource == ServerDbs.ItemGroupsPackages && isPackage == true))
                            {
                                foreach (var pair in dico.OrderBy(p => p.Key))
                                {
                                    var           dbTuple = itemDb.TryGetTuple(pair.Key);
                                    List <string> items   = ServerItemGroupSubAttributes.AttributeList.Attributes.Select(p => pair.Value.GetValue <string>(p)).ToList();
                                    RemoveDefaultValues(items);
                                    writer.WriteLine(_getWriterGroupName(key, constantDb) + "," + string.Join(",", items.ToArray()) + (dbTuple == null ? "" : "\t// " + dbTuple.GetValue(ServerItemAttributes.Name)));
                                }

                                writer.WriteLine();
                            }
                        }
                    }
                }
                else if (debug.FileType == FileType.Conf)
                {
                    StringBuilder builder = new StringBuilder();
                    var           dbItems = db.GetMeta <int>(ServerDbs.Items);

                    List <string> aegisNames = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.AegisName.Index)).ToList();
                    List <string> names      = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.Name.Index)).ToList();

                    foreach (int id in db.Table.FastItems.Select(p => p.Key).OrderBy(p => p))
                    {
                        //bool isPackage = _isPackage((Dictionary<int, ReadableTuple<int>>)db.Table[id].GetRawValue(1));
                        //
                        //if (debug.DbSource == ServerDbs.ItemGroupsMisc && isPackage)
                        //	continue;
                        //
                        //if (debug.DbSource == ServerDbs.ItemGroupsPackages && !isPackage)
                        //	continue;

                        builder.AppendLine(ItemGroupParser.ToHerculesDbEntry(db, id, aegisNames, names));
                        builder.AppendLine();
                    }

                    IOHelper.WriteAllText(debug.FilePath, builder.ToString());
                }
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }
コード例 #4
0
ファイル: DbIOItemGroups.cs プロジェクト: userid0/RagnarokSDE
        public static void Loader(DbDebugItem <int> debug, AbstractDb <int> db)
        {
            //foreach (DbAttribute attribute in ServerItemGroupSubAttributes.AttributeList.Attributes) {
            //	db.Attached[attribute.DisplayName] = false;
            //}

            if (debug.FileType == FileType.Txt)
            {
                _loadItemsGroupdDb(db, debug.DbSource, debug.FilePath);
            }
            else if (debug.FileType == FileType.Conf)
            {
                Table <int, ReadableTuple <int> > itemsDb = db.GetMeta <int>(ServerDbs.Items);
                var items = itemsDb.FastItems;
                int index = ServerItemAttributes.AegisName.Index;

                // The reverse table is used for an optimization
                // All the items are stored in a dictionary by their name instead of their ID
                _reverseTable = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);

                foreach (var item in items)
                {
                    _reverseTable[item.GetStringValue(index)] = item.Key;
                }

                var ele   = new LibconfigParser(debug.FilePath);
                var table = debug.AbsractDb.Table;

                foreach (ParserKeyValue group in ele.Output.OfType <ParserKeyValue>())
                {
                    string groupAegisName = group.Key;
                    int    groupId        = _aegisNameToId(groupAegisName);

                    if (groupId == -1)
                    {
                        debug.ReportIdException("Item ID '" + groupAegisName + "' couldn't be found.", groupAegisName, ErrorLevel.Critical);
                        continue;
                    }

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

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

                    foreach (var itemEntry in group.Value)
                    {
                        string itemName;
                        int    quantity;

                        if (itemEntry is ParserList)
                        {
                            ParserList list = (ParserList)itemEntry;
                            itemName = list.Objects[0].ObjectValue;
                            quantity = Int32.Parse(list.Objects[1].ObjectValue);
                        }
                        else if (itemEntry is ParserString)
                        {
                            itemName = itemEntry.ObjectValue;
                            quantity = 1;
                        }
                        else
                        {
                            debug.ReportIdException("Unknown item entry in group '" + groupAegisName + "'.", groupAegisName, ErrorLevel.Critical);
                            continue;
                        }

                        int itemId = _aegisNameToId(itemName);

                        if (itemId == -1)
                        {
                            debug.ReportIdException("Failed to parse the item '" + itemName + "'.", itemName, ErrorLevel.Critical);
                            continue;
                        }

                        ReadableTuple <int> tuple = new ReadableTuple <int>(itemId, ServerItemGroupSubAttributes.AttributeList);
                        tuple.SetRawValue(ServerItemGroupSubAttributes.Rate, quantity);
                        tuple.SetRawValue(ServerItemGroupSubAttributes.ParentGroup, groupId);
                        dico[itemId] = tuple;
                    }
                }
            }
        }
コード例 #5
0
        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
            }
        }
コード例 #6
0
        public static void DbItemGroupWriter <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db)
        {
            try {
                if (debug.FileType == FileType.Txt)
                {
                    string     currentDirectory = Path.GetDirectoryName(debug.FilePath);
                    string     parentDirectory  = Path.GetDirectoryName(currentDirectory);
                    var        itemDb           = db.GetMeta <int>(ServerDbs.Items);
                    ServerType source           = AllLoaders.GetServerType();

                    using (StreamWriter writerPrimary = new StreamWriter(debug.FilePath)) {
                        // currentDirectory = something\db\pre-re
                        // parentDirectory = something\db
                        // outmostDirectory = something

                        if (source == ServerType.Hercules)
                        {
                            // This means we read the file from Hercules
                            db.Attached["0"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_bluebox.txt", new HashSet <int> {
                                1
                            });
                            db.Attached["1"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_violetbox.txt", new HashSet <int> {
                                2
                            });
                            db.Attached["2"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_cardalbum.txt", new HashSet <int> {
                                3, 44
                            });
                            db.Attached["3"] = new Tuple <string, HashSet <int> >("db/item_findingore.txt", new HashSet <int> {
                                6
                            });
                            db.Attached["4"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_giftbox.txt", new HashSet <int> {
                                4, 28, 29, 30, 31, 34, 43
                            });
                            db.Attached["5"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_misc.txt", new HashSet <int> {
                                7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
                            });
                        }

                        List <Tuple <string, HashSet <int> > > loadedItems = db.Attached.Values.OfType <Tuple <string, HashSet <int> > >().OrderBy(p => p.Item2.Count).ToList();

                        List <ReadableTuple <TKey> > allTuples;

                        if (source == ServerType.Hercules)
                        {
                            allTuples = db.Table.FastItems.Select(p => db.Table.Copy(p.GetKey <TKey>())).ToList();
                            List <string>                     constantsList = Constants.Keys.ToList();
                            Dictionary <int, int>             matches       = new Dictionary <int, int>();
                            Table <int, ReadableTuple <int> > table         = db.GetMeta <int>(ServerDbs.Items);

                            for (int i = 0; i < allTuples.Count; i++)
                            {
                                var tuple = allTuples[i];

                                int key = tuple.GetKey <int>();

                                if (matches.ContainsKey(key))
                                {
                                    tuple.SetRawValue(0, matches[key]);
                                    continue;
                                }

                                var res2 = table.TryGetTuple(key);

                                if (res2 != null)
                                {
                                    string name          = res2.GetValue(ServerItemAttributes.AegisName).ToString();
                                    string closestString = Methods.ClosestString(name, constantsList);

                                    int groupId = Constants[closestString];
                                    matches[key] = groupId;
                                    tuple.SetRawValue(0, matches[key]);
                                }
                                else
                                {
                                    debug.ReportException("Key not found : " + key);
                                }
                            }
                        }
                        else
                        {
                            allTuples = db.Table.FastItems;
                        }

                        for (int i = 0; i < loadedItems.Count; i++)
                        {
                            var    tuple      = loadedItems[i];
                            string importPath = tuple.Item1.Trim(' ', '\t');
                            string temp       = Path.GetDirectoryName(importPath);
                            string outputPath = "";
                            var    set        = tuple.Item2;

                            int level = 0;

                            while (!string.IsNullOrEmpty(temp))
                            {
                                temp = Path.GetDirectoryName(temp);
                                level++;
                            }

                            string internalPath = "";

                            if (level == 2)
                            {
                                outputPath   = "db/" + debug.SubPath + "/" + Path.GetFileName(importPath);
                                internalPath = debug.SubPath + "/" + Path.GetFileName(importPath);
                            }
                            else if (level == 1)
                            {
                                outputPath   = "db/" + Path.GetFileName(importPath);
                                internalPath = Path.GetFileName(importPath);
                            }

                            string filePath = GrfPath.Combine(parentDirectory, internalPath);

                            GrfPath.CreateDirectoryFromFile(filePath);

                            List <ReadableTuple <TKey> > tuples;

                            if (i == loadedItems.Count - 1)
                            {
                                //outputeverything
                                tuples = allTuples;
                            }
                            else
                            {
                                tuples = allTuples.Where(p => set.Contains(p.GetKey <int>())).ToList();

                                for (int j = 0; j < tuples.Count; j++)
                                {
                                    allTuples.Remove(tuples[j]);
                                }
                            }

                            using (StreamWriter writer = new StreamWriter(filePath)) {
                                foreach (ReadableTuple <TKey> tup in tuples.OrderBy(p => p.GetKey <TKey>()))
                                {
                                    Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)tup.GetRawValue(1);
                                    int key = tup.GetKey <int>();

                                    foreach (var pair in dico.OrderBy(p => p.Key))
                                    {
                                        var           dbTuple = itemDb.TryGetTuple(pair.Key);
                                        List <string> items   = ServerItemGroupSubAttributes.AttributeList.Attributes.Select(p => pair.Value.GetValue <string>(p)).ToList();
                                        RemoveDefaultValues(items);
                                        writer.WriteLine(key + "," + string.Join(",", items.ToArray()) + (dbTuple == null ? "" : "\t// " + dbTuple.GetValue(ServerItemAttributes.Name)));
                                    }

                                    writer.WriteLine();
                                }
                            }

                            writerPrimary.WriteLine("import: " + outputPath);
                        }
                    }
                }
                else if (debug.FileType == FileType.Conf)
                {
                    StringBuilder builder = new StringBuilder();
                    var           dbItems = db.GetMeta <int>(ServerDbs.Items);

                    List <string> aegisNames = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.AegisName.Index)).ToList();
                    List <string> names      = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.Name.Index)).ToList();

                    foreach (int id in db.Table.FastItems.Select(p => p.GetKey <int>()).OrderBy(p => p))
                    {
                        builder.AppendLine(ItemGroupParser.ToHerculesDbEntry(db, id, aegisNames, names));
                        builder.AppendLine();
                    }

                    File.WriteAllText(debug.FilePath, builder.ToString(), Encoding.Default);
                }
            }
            catch (Exception err) {
                debug.ReportException(err);
            }
        }