Esempio n. 1
0
            /// <summary>
            /// Export Item Debugging Files to the supplied directory.
            /// </summary>
            /// <param name="directory">The directory to file the debug files to.</param>
            public static void ExportDebug(string directory)
            {
                // Write some debug files.
                // Get all of the Item IDs and sort the list.
                var allItemIDs = AllIDs.ToList();

                allItemIDs.Sort();

                // Iterate through all of the items to determine which ones are missing filters or names.
                var allItems         = new List <object>();
                var itemsMissingData = new List <object>();

                Objects.Filters filter       = Objects.Filters.Invalid;
                var             filterGroups = new Dictionary <Objects.Filters, List <Dictionary <string, object> > >();

                foreach (var itemID in allItemIDs)
                {
                    // Get the item.
                    var item = GetNull(itemID);
                    if (item == null)
                    {
                        continue;
                    }
                    allItems.Add(item);

                    // If an item already has a filter ID assigned and the ID is valid, ignore it.
                    if (item.TryGetValue("f", out object rawObjectData))
                    {
                        filter = (Objects.Filters)rawObjectData;
                    }
                    else
                    {
                        filter = Objects.Filters.Invalid;
                    }

                    // Add the item to the filter group
                    if (!filterGroups.TryGetValue(filter, out List <Dictionary <string, object> > listing))
                    {
                        filterGroups[filter] = new List <Dictionary <string, object> > {
                            item
                        };
                    }
                    else
                    {
                        listing.Add(item);
                    }

                    // If an item doesn't have a name or only has 4 fields, then it's probably missing a database entry.
                    if (!item.ContainsKey("name") || item.Count < 4)
                    {
                        itemsMissingData.Add(item);
                    }
                }

                // Export all of the Items to the Item DB folder.
                File.WriteAllText(Path.Combine(directory, "AllItems.lua"), Framework.ExportRaw(allItems).ToString());
                File.WriteAllText(Path.Combine(directory, "ItemsMissingData.lua"), Framework.ExportRaw(itemsMissingData).ToString());

                // Export all items into their respective filter locations
                var filtersFolder    = Path.Combine(directory, "Filters/");
                var filtersDirectory = Directory.CreateDirectory(filtersFolder);

                foreach (var group in filterGroups)
                {
                    var builder = Framework.ExportRaw(group.Value);
                    builder.AppendLine().AppendLine();
                    foreach (var item in group.Value)
                    {
                        if (item.TryGetValue("itemID", out object id))
                        {
                            builder.Append("i(").Append(id).Append(");");
                            if (item.TryGetValue("name", out object name))
                            {
                                builder.Append("\t\t--[[").Append(name).Append("]]");
                            }
                            builder.AppendLine();
                        }
                    }
                    File.WriteAllText(Path.Combine(filtersDirectory.FullName, $"{group.Key}.json"), builder.ToString());
                }
            }
Esempio n. 2
0
        /// <summary>
        /// Process a data container.
        /// </summary>
        /// <param name="data">The data container.</param>
        /// <param name="modID">The modID.</param>
        /// <param name="minLevel">The minimum required level.</param>
        private static void Process(Dictionary <string, object> data, int modID, int minLevel)
        {
            // Check to make sure the data is valid.
            if (data == null)
            {
                return;
            }

            // Assign the modID if not already specified.
            if (data.TryGetValue("modID", out object modIDRef))
            {
                modID = Convert.ToInt32(modIDRef);
                if (modID < 1)
                {
                    data["modID"] = modID = 1;
                }
            }
            else if (data.ContainsKey("ignoreBonus"))
            {
                // Assign the modID, but set it back to 1.
                data["modID"] = modID = 1;
            }
            else if (data.ContainsKey("itemID"))
            {
                // Assign the modID, but only for items.
                data["modID"] = modID;
            }

            if (data.TryGetValue("npcID", out int npcID))
            {
                NPCS_WITH_REFERENCES[npcID] = true;
            }
            if (data.TryGetValue("creatureID", out npcID))
            {
                NPCS_WITH_REFERENCES[npcID] = true;
            }
            if (data.TryGetValue("qg", out npcID))
            {
                NPCS_WITH_REFERENCES[npcID] = true;
            }
            if (data.TryGetValue("qgs", out List <object> qgs))
            {
                foreach (var qg in qgs)
                {
                    NPCS_WITH_REFERENCES[Convert.ToInt32(qg)] = true;
                }
            }
            if (data.TryGetValue("crs", out qgs))
            {
                foreach (var qg in qgs)
                {
                    NPCS_WITH_REFERENCES[Convert.ToInt32(qg)] = true;
                }
            }

            // Cache whether or not this entry had an explicit spellID assignment already.
            bool hasSpellID = data.ContainsKey("spellID");

            // Merge all relevant Item Data into the data container.
            Items.Merge(data);
            Items.MergeInto(data);
            Objects.AssignFactionID(data);

            // Cache the Filter ID.
            Objects.Filters filter = Objects.Filters.Ignored;
            if (data.TryGetValue("f", out int f))
            {
                // Parse it!
                filter = (Objects.Filters)f;
            }

            // Throw away automatic Spell ID assignments for certain filter types.
            if (data.TryGetValue("spellID", out f))
            {
                if (f < 1)
                {
                    data.Remove("spellID");
                }
                else
                {
                    switch (filter)
                    {
                    case Objects.Filters.Recipe:
                        data["recipeID"] = data["spellID"];
                        break;

                    default:
                        if (!hasSpellID)
                        {
                            data.Remove("spellID");
                        }
                        break;
                    }
                }
            }
            if (data.TryGetValue("recipeID", out f))
            {
                if (f < 1)
                {
                    data.Remove("recipeID");
                }
            }
            if (data.TryGetValue("s", out f))
            {
                if (f < 1)
                {
                    data.Remove("s");
                }
            }

            if (data.TryGetValue("q", out f))
            {
                if (f == 7 && data.TryGetValue("itemID", out object itemRef))
                {
                    data["heirloomID"] = itemRef;
                    if (data.TryGetValue("ignoreSource", out itemRef))
                    {
                        Trace.WriteLine("WTF WHY IS THIS HEIRLOOM IGNORING SOURCE IDS?!");
                        Console.ReadLine();
                    }
                    else if (data.TryGetValue("ignoreBonus", out itemRef))
                    {
                        Trace.WriteLine("WTF WHY IS THIS HEIRLOOM IGNORING BONUS IDS?!");
                        Console.ReadLine();
                    }
                }

                // If the level of this object is less than the current minimum level, we can safely remove it.
                if (data.TryGetValue("lvl", out object lvlRef))
                {
                    var level = Convert.ToInt32(lvlRef);
                    if (level <= minLevel)
                    {
                        data.Remove("lvl");
                    }
                    else
                    {
                        minLevel = level;
                    }
                }

                // For Rings, Necklaces, and Trinkets - Ignore BoE filters
                switch (filter)
                {
                /*
                 * case Objects.Filters.Ring:
                 * case Objects.Filters.Trinket:
                 * case Objects.Filters.Neck:
                 * case Objects.Filters.Relic:
                 *  data.Remove("b");
                 *  break;
                 */
                case Objects.Filters.Consumable:
                    data.Remove("heirloomID");
                    break;

                default:
                    break;
                }
            }

            // If this container has groups, then process those groups as well.
            if (data.TryGetValue("g", out List <object> groups))
            {
                Process(groups, modID, minLevel);
            }

            if (data.TryGetValue("requireSkill", out object requiredSkill))
            {
                if (Objects.SKILL_ID_CONVERSION_TABLE.TryGetValue(requiredSkill, out object newRequiredSkill))
                {
                    data["requireSkill"] = newRequiredSkill;
                }
                else
                {
                    switch (Convert.ToInt32(requiredSkill))
                    {
                    // https://www.wowhead.com/skill=
                    case 40:        // Rogue Poisons
                    case 150:       // Tiger Riding
                    case 762:       // Riding
                    case 849:       // Warlock
                    {
                        // Ignore! (and remove!)
                        data.Remove("requireSkill");
                        break;
                    }

                    default:
                    {
                        Trace.Write("Missing Skill ID in Conversion Table: ");
                        Trace.WriteLine(requiredSkill);
                        Trace.WriteLine(ToJSON(data));
                        Console.ReadLine();
                        break;
                    }
                    }
                }
            }

            if (data.TryGetValue("name", out string name))
            {
                // Determine the Most-Significant ID Type (itemID, questID, npcID, etc)
                if (ATT.Export.ObjectData.TryGetMostSignificantObjectType(data, out Export.ObjectData objectData) && data.TryGetValue(objectData.ObjectType, out int id))
                {
                    // Store the name of this object (or whatever it is) in our table.
                    if (!NAMES_BY_TYPE.TryGetValue(objectData.ObjectType, out Dictionary <int, object> names))
                    {
                        names = new Dictionary <int, object>();
                        NAMES_BY_TYPE[objectData.ObjectType] = names;
                    }
                    names[id] = name;
                    data.Remove("name");
                }
            }
        }