示例#1
0
        // Non-WDB data but nevertheless data that should be saved to gameobject_template
        public static string GameobjectTemplateNonWDB(Dictionary<Guid, GameObject> gameobjects)
        {
            if (gameobjects.Count == 0)
                return String.Empty;

            var templates = new StoreDictionary<uint, GameObjectTemplateNonWDB>();
            foreach (var goT in gameobjects)
            {
                if (templates.ContainsKey(goT.Key.GetEntry()))
                    continue;

                var go = goT.Value;
                var template = new GameObjectTemplateNonWDB
                {
                    Size = go.Size.GetValueOrDefault(1.0f),
                    Faction = go.Faction.GetValueOrDefault(0),
                    Flags = go.Flags.GetValueOrDefault(GameObjectFlag.None)
                };

                if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 ||
                    template.Faction == 4 || template.Faction == 5 || template.Faction == 6 ||
                    template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 ||
                    template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions
                    template.Faction = 0;

                template.Flags &= ~GameObjectFlag.Triggered;
                template.Flags &= ~GameObjectFlag.Damaged;
                template.Flags &= ~GameObjectFlag.Destroyed;

                templates.Add(goT.Key.GetEntry(), template, null);
            }

            var templatesDb = SQLDatabase.GetDict<uint, GameObjectTemplateNonWDB>(templates.Keys());
            return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.GameObject);
        }
示例#2
0
        public static string CreatureEquip(Dictionary <Guid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_equip_template))
            {
                return(string.Empty);
            }

            var equips = new StoreDictionary <ushort, CreatureEquipment>();

            foreach (var unit in units)
            {
                var equip = new CreatureEquipment();
                var npc   = unit.Value;
                var entry = (ushort)unit.Key.GetEntry();

                if (npc.Equipment == null || npc.Equipment.Length != 3)
                {
                    continue;
                }

                if (npc.Equipment[0] == 0 && npc.Equipment[1] == 0 && npc.Equipment[2] == 0)
                {
                    continue;
                }

                if (equips.ContainsKey(entry))
                {
                    var existingEquip = equips[entry].Item1;

                    if (existingEquip.ItemEntry1 != npc.Equipment[0] ||
                        existingEquip.ItemEntry2 != npc.Equipment[1] ||
                        existingEquip.ItemEntry3 != npc.Equipment[2])
                    {
                        equips.Remove(entry); // no conflicts
                    }
                    continue;
                }

                equip.ItemEntry1 = npc.Equipment[0];
                equip.ItemEntry2 = npc.Equipment[1];
                equip.ItemEntry3 = npc.Equipment[2];

                equips.Add(entry, equip);
            }

            var entries  = equips.Keys();
            var equipsDb = SQLDatabase.GetDict <ushort, CreatureEquipment>(entries);

            return(SQLUtil.CompareDicts(equips, equipsDb, StoreNameType.Unit));
        }
        public static string ModelData(Dictionary <Guid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_model_info))
            {
                return(string.Empty);
            }

            // Build a dictionary with model data; model is the key
            var models = new StoreDictionary <uint, ModelData>();

            foreach (var npc in units.Select(unit => unit.Value))
            {
                uint modelId;
                if (npc.Model.HasValue)
                {
                    modelId = npc.Model.Value;
                }
                else
                {
                    continue;
                }

                // Do not add duplicate models
                if (models.ContainsKey(modelId))
                {
                    continue;
                }

                float scale = npc.Size.GetValueOrDefault(1.0f);
                var   model = new ModelData
                {
                    BoundingRadius = npc.BoundingRadius.GetValueOrDefault(0.306f) / scale,
                    CombatReach    = npc.CombatReach.GetValueOrDefault(1.5f) / scale,
                    Gender         = npc.Gender.GetValueOrDefault(Gender.Male)
                };

                models.Add(modelId, model, null);
            }

            var entries  = models.Keys();
            var modelsDb = SQLDatabase.GetDict <uint, ModelData>(entries, "modelid");

            return(SQLUtil.CompareDicts(models, modelsDb, StoreNameType.None, "modelid"));
        }
示例#4
0
        // Non-WDB data but nevertheless data that should be saved to gameobject_template
        public static string GameobjectTemplateNonWDB(Dictionary <Guid, GameObject> gameobjects)
        {
            if (gameobjects.Count == 0)
            {
                return(string.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject_template))
            {
                return(string.Empty);
            }

            var templates = new StoreDictionary <uint, GameObjectTemplateNonWDB>();

            foreach (var goT in gameobjects)
            {
                if (templates.ContainsKey(goT.Key.GetEntry()))
                {
                    continue;
                }

                var go       = goT.Value;
                var template = new GameObjectTemplateNonWDB
                {
                    Size    = go.Size.GetValueOrDefault(1.0f),
                    Faction = go.Faction.GetValueOrDefault(0),
                    Flags   = go.Flags.GetValueOrDefault(GameObjectFlag.None)
                };

                if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 ||
                    template.Faction == 4 || template.Faction == 5 || template.Faction == 6 ||
                    template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 ||
                    template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions
                {
                    template.Faction = 0;
                }

                template.Flags &= ~GameObjectFlag.Triggered;
                template.Flags &= ~GameObjectFlag.Damaged;
                template.Flags &= ~GameObjectFlag.Destroyed;

                templates.Add(goT.Key.GetEntry(), template, null);
            }

            var templatesDb = SQLDatabase.GetDict <uint, GameObjectTemplateNonWDB>(templates.Keys());

            return(SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.GameObject));
        }
示例#5
0
        public static string CreatureEquip(Dictionary<Guid, Unit> units)
        {
            if (units.Count == 0)
                return string.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_equip_template))
                return string.Empty;

            var equips = new StoreDictionary<ushort, CreatureEquipment>();
            foreach (var unit in units)
            {
                var equip = new CreatureEquipment();
                var npc = unit.Value;
                var entry = (ushort)unit.Key.GetEntry();

                if (npc.Equipment == null || npc.Equipment.Length != 3)
                    continue;

                if (npc.Equipment[0] == 0 && npc.Equipment[1] == 0 && npc.Equipment[2] == 0)
                    continue;

                if (equips.ContainsKey(entry))
                {
                    var existingEquip = equips[entry].Item1;

                    if (existingEquip.ItemEntry1 != npc.Equipment[0] ||
                          existingEquip.ItemEntry2 != npc.Equipment[1] ||
                          existingEquip.ItemEntry3 != npc.Equipment[2])
                        equips.Remove(entry); // no conflicts

                    continue;
                }

                equip.ItemEntry1 = npc.Equipment[0];
                equip.ItemEntry2 = npc.Equipment[1];
                equip.ItemEntry3 = npc.Equipment[2];

                equips.Add(entry, equip);
            }

            var entries = equips.Keys();
            var equipsDb = SQLDatabase.GetDict<ushort, CreatureEquipment>(entries);
            return SQLUtil.CompareDicts(equips, equipsDb, StoreNameType.Unit);
        }
示例#6
0
        /// <summary>
        /// <para>Compare two dictionaries (of the same types) and creates SQL inserts
        ///  or updates accordingly.</para>
        /// <remarks>Second dictionary can be null (only inserts queries will be produced)</remarks>
        /// <remarks>Use DBTableName and DBFieldName attributes to specify table and field names, in TK</remarks>
        /// </summary>
        /// <typeparam name="T">Type of the first primary key</typeparam>
        /// /// <typeparam name="TG">Type of the second primary key</typeparam>
        /// <typeparam name="TK">Type of the WDB struct (field names and types must match DB field name and types)</typeparam>
        /// <typeparam name="TH"></typeparam>
        /// <param name="dict1">Dictionary retrieved from  parser</param>
        /// <param name="dict2">Dictionary retrieved from  DB</param>
        /// <param name="storeType1">(T) Are we dealing with Spells, Quests, Units, ...?</param>
        /// <param name="storeType2">(TG) Are we dealing with Spells, Quests, Units, ...?</param>
        /// <param name="storeType3">(TH) Are we dealing with Spells, Quests, Units, ...?</param>
        /// <param name="primaryKeyName1">The name of the first primary key</param>
        /// <param name="primaryKeyName2">The name of the second primary key</param>
        /// <param name="primaryKeyName3">The name of the third primary key</param>
        /// <returns>A string containing full SQL queries</returns>
        public static string CompareDicts <T, TG, TH, TK>(StoreDictionary <Tuple <T, TG, TH>, TK> dict1, StoreDictionary <Tuple <T, TG, TH>, TK> dict2, StoreNameType storeType1, StoreNameType storeType2, StoreNameType storeType3, string primaryKeyName1, string primaryKeyName2, string primaryKeyName3)
        {
            var tableAttrs = (DBTableNameAttribute[])typeof(TK).GetCustomAttributes(typeof(DBTableNameAttribute), false);

            if (tableAttrs.Length <= 0)
            {
                return(string.Empty);
            }
            var tableName = tableAttrs[0].Name;

            var fields = Utilities.GetFieldsAndAttribute <TK, DBFieldNameAttribute>();

            if (fields == null)
            {
                return(string.Empty);
            }

            fields.RemoveAll(field => field.Item2.Name == null);

            var rowsIns = new List <QueryBuilder.SQLInsertRow>();
            var rowsUpd = new List <QueryBuilder.SQLUpdateRow>();

            foreach (var elem1 in Settings.SQLOrderByKey ? dict1.OrderBy(blub => blub.Key).ToList() : dict1.ToList())
            {
                if (dict2 != null && dict2.ContainsKey(elem1.Key)) // update
                {
                    var row = new QueryBuilder.SQLUpdateRow();

                    foreach (var field in fields)
                    {
                        var elem2 = dict2[elem1.Key];

                        var val1 = field.Item1.GetValue(elem1.Value.Item1);
                        var val2 = field.Item1.GetValue(elem2.Item1);

                        var arr1 = val1 as Array;
                        if (arr1 != null)
                        {
                            var arr2 = (Array)val2;

                            var isString = arr1.GetType().GetElementType() == typeof(string);

                            for (var i = 0; i < field.Item2.Count; i++)
                            {
                                var value1 = i >= arr1.Length ? (isString ? (object)string.Empty : 0) : arr1.GetValue(i);
                                var value2 = i >= arr2.Length ? (isString ? (object)string.Empty : 0) : arr2.GetValue(i);

                                if (!Utilities.EqualValues(value1, value2))
                                {
                                    row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), value1);
                                }
                            }

                            continue;
                        }

                        if (!Utilities.EqualValues(val1, val2))
                        {
                            row.AddValue(field.Item2.Name, val1);
                        }
                    }

                    var key1 = Convert.ToUInt32(elem1.Key.Item1);
                    var key2 = Convert.ToUInt32(elem1.Key.Item2);
                    var key3 = Convert.ToUInt32(elem1.Key.Item3);

                    row.AddWhere(primaryKeyName1, key1);
                    row.AddWhere(primaryKeyName2, key2);
                    row.AddWhere(primaryKeyName3, key3);

                    var key1Name = storeType1 != StoreNameType.None ?
                                   StoreGetters.GetName(storeType1, (int)key1, false) :
                                   elem1.Key.Item1.ToString();
                    var key2Name = storeType2 != StoreNameType.None ?
                                   StoreGetters.GetName(storeType2, (int)key2, false) :
                                   elem1.Key.Item2.ToString();
                    var key3Name = storeType3 != StoreNameType.None ?
                                   StoreGetters.GetName(storeType3, (int)key3, false) :
                                   elem1.Key.Item2.ToString();

                    row.Comment = key1Name + " - " + key2Name + " - " + key3Name;
                    row.Table   = tableName;

                    if (row.ValueCount == 0)
                    {
                        continue;
                    }

                    var lastField = fields[fields.Count - 1];
                    if (lastField.Item2.Name == "VerifiedBuild")
                    {
                        var buildvSniff = (int)lastField.Item1.GetValue(elem1.Value.Item1);
                        var buildvDB    = (int)lastField.Item1.GetValue(dict2[elem1.Key].Item1);

                        if (buildvDB > buildvSniff) // skip update if DB already has a VerifiedBuild higher than this one
                        {
                            continue;
                        }
                    }

                    rowsUpd.Add(row);
                }
                else // insert new
                {
                    var row = new QueryBuilder.SQLInsertRow();
                    row.AddValue(primaryKeyName1, elem1.Key.Item1);
                    row.AddValue(primaryKeyName2, elem1.Key.Item2);
                    row.AddValue(primaryKeyName3, elem1.Key.Item3);

                    var key1 = Convert.ToUInt32(elem1.Key.Item1);
                    var key2 = Convert.ToUInt32(elem1.Key.Item2);
                    var key3 = Convert.ToUInt32(elem1.Key.Item3);

                    var key1Name = storeType1 != StoreNameType.None ?
                                   StoreGetters.GetName(storeType1, (int)key1, false) :
                                   elem1.Key.Item1.ToString();
                    var key2Name = storeType2 != StoreNameType.None ?
                                   StoreGetters.GetName(storeType2, (int)key2, false) :
                                   elem1.Key.Item2.ToString();
                    var key3Name = storeType3 != StoreNameType.None ?
                                   StoreGetters.GetName(storeType3, (int)key3, false) :
                                   elem1.Key.Item2.ToString();

                    row.Comment = key1Name + " - " + key2Name + " - " + key3Name;

                    foreach (var field in fields)
                    {
                        if (field.Item1.FieldType.BaseType == typeof(Array))
                        {
                            var arr = (Array)field.Item1.GetValue(elem1.Value.Item1);
                            if (arr == null)
                            {
                                continue;
                            }

                            for (var i = 0; i < arr.Length; i++)
                            {
                                row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), arr.GetValue(i));
                            }

                            continue;
                        }

                        var val = field.Item1.GetValue(elem1.Value.Item1);
                        if (val == null && field.Item1.FieldType == typeof(string))
                        {
                            val = string.Empty;
                        }

                        row.AddValue(field.Item2.Name, val);
                    }
                    rowsIns.Add(row);
                }
            }

            var result = new QueryBuilder.SQLInsert(tableName, rowsIns, deleteDuplicates: false, primaryKeyNumber: 3).Build() +
                         new QueryBuilder.SQLUpdate(rowsUpd).Build();

            return(result);
        }
示例#7
0
        public static string NpcTemplateNonWDB(Dictionary <WowGuid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template))
            {
                return(string.Empty);
            }

            var levels = GetLevels(units);

            var templates = new StoreDictionary <uint, UnitTemplateNonWDB>();

            foreach (var unit in units)
            {
                if (templates.ContainsKey(unit.Key.GetEntry()))
                {
                    continue;
                }

                var npc      = unit.Value;
                var template = new UnitTemplateNonWDB
                {
                    GossipMenuId     = npc.GossipId,
                    MinLevel         = levels[unit.Key.GetEntry()].Item1,
                    MaxLevel         = levels[unit.Key.GetEntry()].Item2,
                    Faction          = npc.Faction.GetValueOrDefault(35),
                    NpcFlag          = (uint)npc.NpcFlags.GetValueOrDefault(NPCFlags.None),
                    SpeedRun         = npc.Movement.RunSpeed,
                    SpeedWalk        = npc.Movement.WalkSpeed,
                    BaseAttackTime   = npc.MeleeTime.GetValueOrDefault(2000),
                    RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000),
                    UnitClass        = (uint)npc.Class.GetValueOrDefault(Class.Warrior),
                    UnitFlag         = (uint)npc.UnitFlags.GetValueOrDefault(UnitFlags.None),
                    UnitFlag2        = (uint)npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None),
                    DynamicFlag      = (uint)npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None),
                    VehicleId        = npc.Movement.VehicleId,
                    HoverHeight      = npc.HoverHeight.GetValueOrDefault(1.0f)
                };

                if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 ||
                    template.Faction == 4 || template.Faction == 5 || template.Faction == 6 ||
                    template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 ||
                    template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204)     // player factions
                {
                    template.Faction = 35;
                }

                template.UnitFlag    &= ~(uint)UnitFlags.IsInCombat;
                template.UnitFlag    &= ~(uint)UnitFlags.PetIsAttackingTarget;
                template.UnitFlag    &= ~(uint)UnitFlags.PlayerControlled;
                template.UnitFlag    &= ~(uint)UnitFlags.Silenced;
                template.UnitFlag    &= ~(uint)UnitFlags.PossessedByPlayer;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.Lootable;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.Tapped;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByPlayer;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByAllThreatList;

                // has trainer flag but doesn't have prof nor class trainer flag
                if ((template.NpcFlag & (uint)NPCFlags.Trainer) != 0 &&
                    ((template.NpcFlag & (uint)NPCFlags.ProfessionTrainer) == 0 ||
                     (template.NpcFlag & (uint)NPCFlags.ClassTrainer) == 0))
                {
                    var name       = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                    var firstIndex = name.LastIndexOf('<');
                    var lastIndex  = name.LastIndexOf('>');
                    if (firstIndex != -1 && lastIndex != -1)
                    {
                        var subname = name.Substring(firstIndex + 1, lastIndex - firstIndex - 1);

                        if (_professionTrainers.Contains(subname))
                        {
                            template.NpcFlag |= (uint)NPCFlags.ProfessionTrainer;
                        }
                        else if (_classTrainers.Contains(subname))
                        {
                            template.NpcFlag |= (uint)NPCFlags.ClassTrainer;
                        }
                    }
                }

                templates.Add(unit.Key.GetEntry(), template);
            }

            var templatesDb = SQLDatabase.GetDict <uint, UnitTemplateNonWDB>(templates.Keys());

            return(SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit));
        }
示例#8
0
        public static string NpcTemplateNonWDB(Dictionary<WowGuid, Unit> units)
        {
            /* if (ClientVersion.AddedInVersion(ClientType.WarlordsOfDraenor))
                return string.Empty;*/

            if (units.Count == 0)
                return string.Empty;

            /*if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template))
                return string.Empty;*/

            var levels = GetLevels(units);

            var result = string.Empty;
            const string tableName = "creature_template";
            var rowsIns = new List<QueryBuilder.SQLUpdateRow>();
            uint count = 0;

            var templates = new StoreDictionary<uint, UnitTemplateNonWDB>();
            foreach (var unit in units)
            {
                if (templates.ContainsKey(unit.Key.GetEntry()))
                    continue;

                var row = new QueryBuilder.SQLUpdateRow();

                var npc = unit.Value;
                var template = new UnitTemplateNonWDB
                {
                    //GossipMenuId = npc.GossipId,
                    MinLevel = (int) levels[unit.Key.GetEntry()].Item1,
                    MaxLevel = (int) levels[unit.Key.GetEntry()].Item2,
                    Faction = npc.Faction.GetValueOrDefault(35),
                    NpcFlag = (uint) npc.NpcFlags.GetValueOrDefault(NPCFlags.None),
                    SpeedRun = npc.Movement.RunSpeed,
                    SpeedWalk = npc.Movement.WalkSpeed
                    /*BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000),
                    RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000),
                    UnitClass = (uint) npc.Class.GetValueOrDefault(Class.Warrior),
                    UnitFlag = (uint) npc.UnitFlags.GetValueOrDefault(UnitFlags.None),
                    UnitFlag2 = (uint) npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None),
                    DynamicFlag = (uint) npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None),
                    VehicleId = npc.Movement.VehicleId,
                    HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f)*/
                };

                if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 ||
                        template.Faction == 4 || template.Faction == 5 || template.Faction == 6 ||
                        template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 ||
                        template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions
                    template.Faction = 35;

               /* template.UnitFlag &= ~(uint)UnitFlags.IsInCombat;
                template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget;
                template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled;
                template.UnitFlag &= ~(uint)UnitFlags.Silenced;
                template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer;

                if (!ClientVersion.AddedInVersion(ClientType.WarlordsOfDraenor))
                {
                    template.DynamicFlag &= ~(uint)UnitDynamicFlags.Lootable;
                    template.DynamicFlag &= ~(uint)UnitDynamicFlags.Tapped;
                    template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByPlayer;
                    template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByAllThreatList;
                }
                else
                {
                    template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.Lootable;
                    template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.Tapped;
                    template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.TappedByPlayer;
                    template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.TappedByAllThreatList;
                }*/

                // has trainer flag but doesn't have prof nor class trainer flag
                if ((template.NpcFlag & (uint) NPCFlags.Trainer) != 0 &&
                    ((template.NpcFlag & (uint) NPCFlags.ProfessionTrainer) == 0 ||
                     (template.NpcFlag & (uint) NPCFlags.ClassTrainer) == 0))
                {
                    UnitTemplate unitData;
                    var subname = GetSubName((int)unit.Key.GetEntry(), false); // Fall back
                    if (Storage.UnitTemplates.TryGetValue(unit.Key.GetEntry(), out unitData))
                    {
                        if (unitData.SubName.Length > 0)
                            template.NpcFlag |= ProcessNpcFlags(unitData.SubName);
                        else // If the SubName doesn't exist or is cached, fall back to DB method
                            template.NpcFlag |= ProcessNpcFlags(subname);
                    }
                    else // In case we have NonWDB data which doesn't have an entry in UnitTemplates
                        template.NpcFlag |= ProcessNpcFlags(subname);
                }
                row.AddValue("minlevel", template.MinLevel);
                row.AddValue("maxlevel", template.MaxLevel);
                row.AddValue("faction", template.Faction);
                row.AddValue("npcflag", template.NpcFlag);
                row.AddValue("speed_walk", template.SpeedWalk);
                row.AddValue("speed_run", template.SpeedRun);

                row.AddWhere("entry", unit.Key.GetEntry());

                row.Table = tableName;
                rowsIns.Add(row);
                count++;

                templates.Add(unit.Key.GetEntry(), template);
            }

            //result += new QueryBuilder.SQLDelete(Tuple.Create("@ID+0", "@ID+" + (count - 1)), "entry", tableName).Build();
            result += new QueryBuilder.SQLUpdate(rowsIns).Build();
            return result;

            /*var templatesDb = SQLDatabase.GetDict<uint, UnitTemplateNonWDB>(templates.Keys());
            return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit);*/
        }
示例#9
0
        /// <summary>
        /// <para>Compare two dictionaries (of the same types) and creates SQL inserts
        ///  or updates accordingly.</para>
        /// <remarks>Second dictionary can be null (only inserts queries will be produced)</remarks>
        /// <remarks>Use DBTableName and DBFieldName attributes to specify table and field names, in TK</remarks>
        /// </summary>
        /// <typeparam name="T">Type of the primary key (uint)</typeparam>
        /// <typeparam name="TK">Type of the WDB struct (field types must match DB field)</typeparam>
        /// <param name="dict1">Dictionary retrieved from  parser</param>
        /// <param name="dict2">Dictionary retrieved from  DB</param>
        /// <param name="storeType">Are we dealing with Spells, Quests, Units, ...?</param>
        /// <param name="primaryKeyName">The name of the primary key, usually "entry"</param>
        /// <returns>A string containing full SQL queries</returns>
        public static string CompareDicts <T, TK>(StoreDictionary <T, TK> dict1, StoreDictionary <T, TK> dict2, StoreNameType storeType, string primaryKeyName = "entry")
        {
            var tableAttrs = (DBTableNameAttribute[])typeof(TK).GetCustomAttributes(typeof(DBTableNameAttribute), false);

            if (tableAttrs.Length <= 0)
            {
                return(string.Empty);
            }
            var tableName = tableAttrs[0].Name;

            var fields = Utilities.GetFieldsAndAttribute <TK, DBFieldNameAttribute>();

            if (fields == null)
            {
                return(string.Empty);
            }

            var rowsIns = new List <QueryBuilder.SQLInsertRow>();
            var rowsUpd = new List <QueryBuilder.SQLUpdateRow>();

            foreach (var elem1 in dict1)
            {
                if (dict2 != null && dict2.ContainsKey(elem1.Key)) // update
                {
                    var row = new QueryBuilder.SQLUpdateRow();

                    foreach (var field in fields)
                    {
                        var elem2 = dict2[elem1.Key];

                        var val1 = field.Item1.GetValue(elem1.Value.Item1);
                        var val2 = field.Item1.GetValue(elem2.Item1);

                        var arr1 = val1 as Array;
                        if (arr1 != null)
                        {
                            var arr2 = (Array)val2;

                            var isString = arr1.GetType().GetElementType() == typeof(string);

                            for (var i = 0; i < field.Item2.Count; i++)
                            {
                                var value1 = i >= arr1.Length ? (isString ? (object)string.Empty : 0) : arr1.GetValue(i);
                                var value2 = i >= arr2.Length ? (isString ? (object)string.Empty : 0) : arr2.GetValue(i);

                                if (!Utilities.EqualValues(value1, value2))
                                {
                                    row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), value1);
                                }
                            }

                            continue;
                        }

                        if ((val2 is Array) && val1 == null)
                        {
                            continue;
                        }

                        if (!Utilities.EqualValues(val1, val2))
                        {
                            row.AddValue(field.Item2.Name, val1);
                        }
                    }

                    var key = Convert.ToUInt32(elem1.Key);

                    row.AddWhere(primaryKeyName, key);
                    row.Comment = StoreGetters.GetName(storeType, (int)key, false);
                    row.Table   = tableName;

                    if (row.ValueCount == 0)
                    {
                        continue;
                    }

                    var lastField = fields[fields.Count - 1];
                    if (lastField.Item2.Name == "WDBVerified")
                    {
                        var wdbvSniff = (int)lastField.Item1.GetValue(elem1.Value.Item1);
                        var wdbvDB    = (int)lastField.Item1.GetValue(dict2[elem1.Key].Item1);

                        if (wdbvDB > wdbvSniff) // skip update if DB already has a WDBVerified higher than this one
                        {
                            continue;
                        }
                    }

                    rowsUpd.Add(row);
                }
                else // insert new
                {
                    var row = new QueryBuilder.SQLInsertRow();
                    row.AddValue(primaryKeyName, elem1.Key);
                    row.Comment = StoreGetters.GetName(storeType, Convert.ToInt32(elem1.Key), false);

                    foreach (var field in fields)
                    {
                        if (field.Item1.FieldType.BaseType == typeof(Array))
                        {
                            var arr = (Array)field.Item1.GetValue(elem1.Value.Item1);
                            if (arr == null)
                            {
                                continue;
                            }

                            for (var i = 0; i < arr.Length; i++)
                            {
                                row.AddValue(field.Item2.Name + (field.Item2.StartAtZero ? i : i + 1), arr.GetValue(i));
                            }

                            continue;
                        }

                        row.AddValue(field.Item2.Name, field.Item1.GetValue(elem1.Value.Item1));
                    }
                    rowsIns.Add(row);
                }
            }

            var result = new QueryBuilder.SQLInsert(tableName, rowsIns, deleteDuplicates: false).Build() +
                         new QueryBuilder.SQLUpdate(rowsUpd).Build();

            return(result);
        }
示例#10
0
        public static string CreatureEquip(Dictionary<WowGuid, Unit> units)
        {
            if (units.Count == 0)
                return string.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_equip_template))
                return string.Empty;

            var rows = new List<QueryBuilder.SQLInsertRow>();

            var equips = new StoreDictionary<uint, CreatureEquipment>();
            foreach (var unit in units)
            {
                var equip = new CreatureEquipment();
                var npc = unit.Value;
                var CreatureID = unit.Key.GetEntry();
                var row = new QueryBuilder.SQLInsertRow();

                if (Settings.AreaFilters.Length > 0)
                    if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters)))
                        continue;

                if (Settings.MapFilters.Length > 0)
                    if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters)))
                        continue;

                if (npc.Equipment == null || npc.Equipment.Length != 3)
                    continue;

                if (npc.Equipment[0] == 0 && npc.Equipment[1] == 0 && npc.Equipment[2] == 0)
                    continue;

                if (equips.ContainsKey(CreatureID))
                {
                    var existingEquip = equips[CreatureID].Item1;

                    if (existingEquip.ItemEntry1 != npc.Equipment[0] ||
                          existingEquip.ItemEntry2 != npc.Equipment[1] ||
                          existingEquip.ItemEntry3 != npc.Equipment[2])
                        equips.Remove(CreatureID); // no conflicts

                    continue;
                }

                /*equip.ID = 1;
                equip.ItemEntry1 = npc.Equipment[0];
                equip.ItemEntry2 = npc.Equipment[1];
                equip.ItemEntry3 = npc.Equipment[2];*/

                row.AddValue("CreatureID", CreatureID);
                row.AddValue("ID", 1);
                row.AddValue("ItemID1", npc.Equipment[0]);
                row.AddValue("ItemID2", npc.Equipment[1]);
                row.AddValue("ItemID3", npc.Equipment[2]);

                equips.Add(CreatureID, equip);
                rows.Add(row);
            }

            var entries = equips.Keys();
            //var equipsDb = SQLDatabase.GetDict<uint, CreatureEquipment>(entries);
            //return SQLUtil.CompareDicts(equips, equipsDb, StoreNameType.Unit);
            return new QueryBuilder.SQLInsert("creature_equip_template", rows, withDelete: true).Build();
        }
示例#11
0
        public static string ModelData(Dictionary<WowGuid, Unit> units)
        {
            if (units.Count == 0)
                return string.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_model_info))
                return string.Empty;

            // Build a dictionary with model data; model is the key
            var models = new StoreDictionary<uint, ModelData>();
            foreach (var npc in units.Select(unit => unit.Value))
            {
                if (Settings.AreaFilters.Length > 0)
                    if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters)))
                        continue;

                if (Settings.MapFilters.Length > 0)
                    if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters)))
                        continue;

                uint modelId;
                if (npc.Model.HasValue)
                    modelId = npc.Model.Value;
                else
                    continue;

                // Do not add duplicate models
                if (models.ContainsKey(modelId))
                    continue;

                float scale = npc.Size.GetValueOrDefault(1.0f);
                var model = new ModelData
                {
                    BoundingRadius = npc.BoundingRadius.GetValueOrDefault(0.306f) / scale,
                    CombatReach = npc.CombatReach.GetValueOrDefault(1.5f) / scale,
                    Gender = npc.Gender.GetValueOrDefault(Gender.Male)
                };

                models.Add(modelId, model);
            }

            var entries = models.Keys();
            var modelsDb = SQLDatabase.GetDict<uint, ModelData>(entries, "DisplayID");
            return SQLUtil.CompareDicts(models, modelsDb, StoreNameType.None, "DisplayID");
        }
示例#12
0
        // Non-WDB data but nevertheless data that should be saved to creature_template
        public static string NpcTemplateNonWDB(Dictionary <Guid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template))
            {
                return(string.Empty);
            }

            var levels = GetLevels(units);

            var templates = new StoreDictionary <uint, UnitTemplateNonWDB>();

            foreach (var unit in units)
            {
                if (templates.ContainsKey(unit.Key.GetEntry()))
                {
                    continue;
                }

                var npc      = unit.Value;
                var template = new UnitTemplateNonWDB
                {
                    GossipMenuId     = npc.GossipId,
                    MinLevel         = levels[unit.Key.GetEntry()].Item1,
                    MaxLevel         = levels[unit.Key.GetEntry()].Item2,
                    Faction          = npc.Faction.GetValueOrDefault(35),
                    Faction2         = npc.Faction.GetValueOrDefault(35),
                    NpcFlag          = (uint)npc.NpcFlags.GetValueOrDefault(NPCFlags.None),
                    SpeedRun         = npc.Movement.RunSpeed,
                    SpeedWalk        = npc.Movement.WalkSpeed,
                    BaseAttackTime   = npc.MeleeTime.GetValueOrDefault(2000),
                    RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000),
                    UnitClass        = (uint)npc.Class.GetValueOrDefault(Class.Warrior),
                    UnitFlag         = (uint)npc.UnitFlags.GetValueOrDefault(UnitFlags.None),
                    UnitFlag2        = (uint)npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None),
                    DynamicFlag      = (uint)npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None),
                    VehicleId        = npc.Movement.VehicleId,
                    HoverHeight      = npc.HoverHeight.GetValueOrDefault(1.0f)
                };

                if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 ||
                    template.Faction == 4 || template.Faction == 5 || template.Faction == 6 ||
                    template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 ||
                    template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204)     // player factions
                {
                    template.Faction = 35;
                }

                template.UnitFlag &= ~(uint)UnitFlags.IsInCombat;
                template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget;
                template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled;
                template.UnitFlag &= ~(uint)UnitFlags.Silenced;
                template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer;

                templates.Add(unit.Key.GetEntry(), template, null);
            }

            var templatesDb = SQLDatabase.GetDict <uint, UnitTemplateNonWDB>(templates.Keys());

            return(SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit));
        }
示例#13
0
        public static string NpcTemplateNonWDB(Dictionary<WowGuid, Unit> units)
        {
            if (ClientVersion.AddedInVersion(ClientType.WarlordsOfDraenor))
                return string.Empty;

            if (units.Count == 0)
                return string.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template))
                return string.Empty;

            var levels = GetLevels(units);

            var templates = new StoreDictionary<uint, UnitTemplateNonWDB>();
            foreach (var unit in units)
            {
                if (templates.ContainsKey(unit.Key.GetEntry()))
                    continue;

                var npc = unit.Value;
                var template = new UnitTemplateNonWDB
                {
                    GossipMenuId = npc.GossipId,
                    MinLevel = (int) levels[unit.Key.GetEntry()].Item1,
                    MaxLevel = (int) levels[unit.Key.GetEntry()].Item2,
                    Faction = npc.Faction.GetValueOrDefault(35),
                    NpcFlag = (uint) npc.NpcFlags.GetValueOrDefault(NPCFlags.None),
                    SpeedRun = npc.Movement.RunSpeed,
                    SpeedWalk = npc.Movement.WalkSpeed,
                    BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000),
                    RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000),
                    UnitClass = (uint) npc.Class.GetValueOrDefault(Class.Warrior),
                    UnitFlag = (uint) npc.UnitFlags.GetValueOrDefault(UnitFlags.None),
                    UnitFlag2 = (uint) npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None),
                    DynamicFlag = (uint) npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None),
                    VehicleId = npc.Movement.VehicleId,
                    HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f)
                };

                if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 ||
                        template.Faction == 4 || template.Faction == 5 || template.Faction == 6 ||
                        template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 ||
                        template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions
                    template.Faction = 35;

                template.UnitFlag &= ~(uint)UnitFlags.IsInCombat;
                template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget;
                template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled;
                template.UnitFlag &= ~(uint)UnitFlags.Silenced;
                template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.Lootable;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.Tapped;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByPlayer;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByAllThreatList;

                // has trainer flag but doesn't have prof nor class trainer flag
                if ((template.NpcFlag & (uint) NPCFlags.Trainer) != 0 &&
                    ((template.NpcFlag & (uint) NPCFlags.ProfessionTrainer) == 0 ||
                     (template.NpcFlag & (uint) NPCFlags.ClassTrainer) == 0))
                {
                    UnitTemplate unitData;
                    var subname = GetSubName((int)unit.Key.GetEntry(), false); // Fall back
                    if (Storage.UnitTemplates.TryGetValue(unit.Key.GetEntry(), out unitData))
                    {
                        if (unitData.SubName.Length > 0)
                            template.NpcFlag |= ProcessNpcFlags(unitData.SubName);
                        else // If the SubName doesn't exist or is cached, fall back to DB method
                            template.NpcFlag |= ProcessNpcFlags(subname);
                    }
                    else // In case we have NonWDB data which doesn't have an entry in UnitTemplates
                        template.NpcFlag |= ProcessNpcFlags(subname);
                }

                templates.Add(unit.Key.GetEntry(), template);
            }

            var templatesDb = SQLDatabase.GetDict<uint, UnitTemplateNonWDB>(templates.Keys());
            return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit);
        }
示例#14
0
        // Non-WDB data but nevertheless data that should be saved to creature_template
        public static string NpcTemplateNonWDB(Dictionary<Guid, Unit> units)
        {
            if (units.Count == 0)
                return string.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template))
                return string.Empty;

            var levels = GetLevels(units);

            var templates = new StoreDictionary<uint, UnitTemplateNonWDB>();
            foreach (var unit in units)
            {
                if (templates.ContainsKey(unit.Key.GetEntry()))
                    continue;

                var npc = unit.Value;
                var template = new UnitTemplateNonWDB
                {
                    GossipMenuId = npc.GossipId,
                    MinLevel = levels[unit.Key.GetEntry()].Item1,
                    MaxLevel = levels[unit.Key.GetEntry()].Item2,
                    Faction = npc.Faction.GetValueOrDefault(35),
                    Faction2 = npc.Faction.GetValueOrDefault(35),
                    NpcFlag = (uint) npc.NpcFlags.GetValueOrDefault(NPCFlags.None),
                    SpeedRun = npc.Movement.RunSpeed,
                    SpeedWalk = npc.Movement.WalkSpeed,
                    BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000),
                    RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000),
                    UnitClass = (uint) npc.Class.GetValueOrDefault(Class.Warrior),
                    UnitFlag = (uint) npc.UnitFlags.GetValueOrDefault(UnitFlags.None),
                    UnitFlag2 = (uint) npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None),
                    DynamicFlag = (uint) npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None),
                    VehicleId = npc.Movement.VehicleId,
                    HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f)
                };

                if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 ||
                        template.Faction == 4 || template.Faction == 5 || template.Faction == 6 ||
                        template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 ||
                        template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions
                    template.Faction = 35;

                template.UnitFlag &= ~(uint)UnitFlags.IsInCombat;
                template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget;
                template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled;
                template.UnitFlag &= ~(uint)UnitFlags.Silenced;
                template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer;

                templates.Add(unit.Key.GetEntry(), template, null);
            }

            var templatesDb = SQLDatabase.GetDict<uint, UnitTemplateNonWDB>(templates.Keys());
            return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit);
        }
示例#15
0
        public static string ModelData(Dictionary<Guid, Unit> units)
        {
            if (units.Count == 0)
                return string.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_model_info))
                return string.Empty;

            // Build a dictionary with model data; model is the key
            var models = new StoreDictionary<uint, ModelData>();
            foreach (var npc in units.Select(unit => unit.Value))
            {
                uint modelId;
                if (npc.Model.HasValue)
                    modelId = npc.Model.Value;
                else
                    continue;

                // Do not add duplicate models
                if (models.ContainsKey(modelId))
                    continue;

                var model = new ModelData
                {
                    BoundingRadius = npc.BoundingRadius.GetValueOrDefault(0.306f),
                    CombatReach = npc.CombatReach.GetValueOrDefault(1.5f),
                    Gender = npc.Gender.GetValueOrDefault(Gender.Male)
                };

                models.Add(modelId, model, null);
            }

            var entries = models.Keys();
            var modelsDb = SQLDatabase.GetDict<uint, ModelData>(entries, "modelid");
            return SQLUtil.CompareDicts(models, modelsDb, StoreNameType.None, "modelid");
        }
示例#16
0
        public static string NpcTemplateNonWDB(Dictionary<WowGuid, Unit> units)
        {
            if (units.Count == 0)
                return string.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template))
                return string.Empty;

            var levels = GetLevels(units);

            var templates = new StoreDictionary<uint, UnitTemplateNonWDB>();
            foreach (var unit in units)
            {
                if (templates.ContainsKey(unit.Key.GetEntry()))
                    continue;

                var npc = unit.Value;
                var template = new UnitTemplateNonWDB
                {
                    GossipMenuId = npc.GossipId,
                    MinLevel = levels[unit.Key.GetEntry()].Item1,
                    MaxLevel = levels[unit.Key.GetEntry()].Item2,
                    Faction = npc.Faction.GetValueOrDefault(35),
                    NpcFlag = (uint) npc.NpcFlags.GetValueOrDefault(NPCFlags.None),
                    SpeedRun = npc.Movement.RunSpeed,
                    SpeedWalk = npc.Movement.WalkSpeed,
                    BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000),
                    RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000),
                    UnitClass = (uint) npc.Class.GetValueOrDefault(Class.Warrior),
                    UnitFlag = (uint) npc.UnitFlags.GetValueOrDefault(UnitFlags.None),
                    UnitFlag2 = (uint) npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None),
                    DynamicFlag = (uint) npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None),
                    VehicleId = npc.Movement.VehicleId,
                    HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f)
                };

                if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 ||
                        template.Faction == 4 || template.Faction == 5 || template.Faction == 6 ||
                        template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 ||
                        template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions
                    template.Faction = 35;

                template.UnitFlag &= ~(uint)UnitFlags.IsInCombat;
                template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget;
                template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled;
                template.UnitFlag &= ~(uint)UnitFlags.Silenced;
                template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.Lootable;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.Tapped;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByPlayer;
                template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByAllThreatList;

                // has trainer flag but doesn't have prof nor class trainer flag
                if ((template.NpcFlag & (uint) NPCFlags.Trainer) != 0 &&
                    ((template.NpcFlag & (uint) NPCFlags.ProfessionTrainer) == 0 ||
                     (template.NpcFlag & (uint) NPCFlags.ClassTrainer) == 0))
                {
                    var name = StoreGetters.GetName(StoreNameType.Unit, (int) unit.Key.GetEntry(), false);
                    var firstIndex = name.LastIndexOf('<');
                    var lastIndex = name.LastIndexOf('>');
                    if (firstIndex != -1 && lastIndex != -1)
                    {
                        var subname = name.Substring(firstIndex + 1, lastIndex - firstIndex - 1);

                        if (_professionTrainers.Contains(subname))
                            template.NpcFlag |= (uint) NPCFlags.ProfessionTrainer;
                        else if (_classTrainers.Contains(subname))
                            template.NpcFlag |= (uint) NPCFlags.ClassTrainer;
                    }
                }

                templates.Add(unit.Key.GetEntry(), template);
            }

            var templatesDb = SQLDatabase.GetDict<uint, UnitTemplateNonWDB>(templates.Keys());
            return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit);
        }
示例#17
0
        public bool ParsePage(string page, Item item, string colour)
        {
            if (page == null)
            {
                return(false);
            }

            List <string> chunks = page.Split(new string[] { "<B>Currently Available</B>" }, StringSplitOptions.None).ToList();
            List <string> rawpgitems;

            if (chunks.Count > 1)
            {
                rawpgitems = chunks[1].Split(new string[] { "</TD></TR>" }, StringSplitOptions.None).ToList();
            }
            else
            {
                AddStatus("Error downloading price guide (got page, but there was nothing on it)" + Environment.NewLine);
                return(false);
            }
            rawpgitems.Add("#usedstart#");
            if (chunks.Count() > 2)
            {
                rawpgitems.AddRange(chunks[2].Split(new string[] { "</TD></TR>" }, StringSplitOptions.None).ToList());
            }

            int usedmarker = 0;

            foreach (string raw in rawpgitems)
            {
                if (raw == "#usedstart#")
                {
                    usedmarker = 1;
                    continue;
                }

                if ((item.condition == "N") && (usedmarker == 1))
                {
                    break;
                }

                if (raw.Contains("nbsp;(S)</"))
                {
                    AddStatus("skip ");
                    continue;
                }

                // what is this madness?
                var pattern = ".*<TR ALIGN=" + "\"" + @"RIGHT" + "\"" + @"><TD NOWRAP>.*?<A HREF=" + "\"" +
                              @"/store.asp\?sID=(\d*?)&.*?<IMG SRC=" + "\"" + @"/images/box16(.).png" + "\"" + @".*?TITLE=" + "\"" + @"Store: (.*?)" +
                              "\"" + @" ALIGN=" + "\"" + @"ABSMIDDLE" + "\"" + @">.*?</TD><TD>(\d*)</TD><TD.*?&nbsp;\D*([\d,]*)\.(\d+)$";
                Match linematch = Regex.Match(raw, pattern);

                if (linematch.Success)
                {
                    string id = linematch.Groups[1].ToString();

                    if (blacklistdic.ContainsKey(id))
                    {
                        continue;
                    }

                    string  ship      = linematch.Groups[2].ToString();
                    string  storename = linematch.Groups[3].ToString();
                    int     qty       = System.Convert.ToInt32(linematch.Groups[4].ToString());
                    string  price1    = linematch.Groups[5].ToString().Replace(",", "");
                    decimal price     = ConvertToDecimal(price1 + "." + linematch.Groups[6].ToString());

                    if (ship == "Y")
                    {
                        if (((StoreDictionary.ContainsKey(storename)) || (settings.countries.Contains("All"))) && (true)) // blacklist
                        {
                            item.availqty += qty;
                            if (!storeid.ContainsKey(storename))
                            {
                                storeid.Add(storename, id);
                            }
                            if (!StoreDictionary.ContainsKey(storename))
                            {
                                StoreDictionary.Add(storename, new Dictionary <string, StoreItem>());
                            }
                            if (!StoreDictionary[storename].ContainsKey(item.extid))
                            {
                                item.availstores++;
                                StoreDictionary[storename].Add(item.extid, new StoreItem());
                            }
                            if (StoreDictionary[storename][item.extid].qty == 0)
                            {
                                StoreDictionary[storename][item.extid].qty    = qty;
                                StoreDictionary[storename][item.extid].price  = price;
                                StoreDictionary[storename][item.extid].colour = colour;
                            }
                            else if (StoreDictionary[storename][item.extid].qty > 0)
                            {
                                StoreDictionary[storename][item.extid].qty = StoreDictionary[storename][item.extid].qty + qty;
                                item.availqty = item.availqty + qty;
                                if (StoreDictionary[storename][item.extid].price > price)
                                {
                                    StoreDictionary[storename][item.extid].price  = price;
                                    StoreDictionary[storename][item.extid].colour = colour;
                                }
                            }
                            storesWithItemsList.Add(storename); // Added by CAC, 2015-06-24
                        }
                    }
                }
                else
                {
                    if (Regex.Match(raw, "<TR ALIGN=" + "\"" + @"RIGHT" + "\"" + @"><TD NOWRAP>").Success)
                    {
                        AddStatus("No Match: " + raw + Environment.NewLine + Environment.NewLine);
                    }
                }
            }
            return(true);
        }
示例#18
0
        public static string GameobjectTemplateNonWDB(Dictionary<WowGuid, GameObject> gameobjects)
        {
            if (gameobjects.Count == 0)
                return string.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject_template))
                return string.Empty;

            var templates = new StoreDictionary<uint, GameObjectTemplateNonWDB>();
            foreach (var goT in gameobjects)
            {
                if (templates.ContainsKey(goT.Key.GetEntry()))
                    continue;

                var go = goT.Value;

                if (Settings.AreaFilters.Length > 0)
                    if (!(go.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters)))
                        continue;

                if (Settings.MapFilters.Length > 0)
                    if (!(go.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters)))
                        continue;

                var template = new GameObjectTemplateNonWDB
                {
                    Size = go.Size.GetValueOrDefault(1.0f),
                    Faction = go.Faction.GetValueOrDefault(0),
                    Flags = go.Flags.GetValueOrDefault(GameObjectFlag.None)
                };

                if (template.Faction == 1 || template.Faction == 2 || template.Faction == 3 ||
                    template.Faction == 4 || template.Faction == 5 || template.Faction == 6 ||
                    template.Faction == 115 || template.Faction == 116 || template.Faction == 1610 ||
                    template.Faction == 1629 || template.Faction == 2203 || template.Faction == 2204) // player factions
                    template.Faction = 0;

                template.Flags &= ~GameObjectFlag.Triggered;
                template.Flags &= ~GameObjectFlag.Damaged;
                template.Flags &= ~GameObjectFlag.Destroyed;

                templates.Add(goT.Key.GetEntry(), template);
            }

            var templatesDb = SQLDatabase.GetDict<uint, GameObjectTemplateNonWDB>(templates.Keys());
            return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.GameObject);
        }
示例#19
0
        public static string CreatureDifficultyMisc(Dictionary<WowGuid, Unit> units)
        {
            if (!ClientVersion.AddedInVersion(ClientType.WarlordsOfDraenor))
                return string.Empty;

            if (units.Count == 0)
                return string.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template))
                return string.Empty;

            var templates = new StoreDictionary<uint, CreatureDifficultyMisc>();
            foreach (var unit in units)
            {
                if (SQLDatabase.CreatureDifficultyStores != null)
                {
                    foreach (var creatureDiff in SQLDatabase.CreatureDifficultyStores)
                    {
                        if (!Utilities.EqualValues(unit.Key.GetEntry(), creatureDiff.Value.CreatureID))
                            continue;

                        if (templates.ContainsKey(creatureDiff.Key))
                            continue;

                        var npc = unit.Value;
                        var template = new CreatureDifficultyMisc
                        {
                            CreatureId = unit.Key.GetEntry(),
                            GossipMenuId = npc.GossipId,
                            NpcFlag = (uint)npc.NpcFlags.GetValueOrDefault(NPCFlags.None),
                            SpeedRun = npc.Movement.RunSpeed,
                            SpeedWalk = npc.Movement.WalkSpeed,
                            BaseAttackTime = npc.MeleeTime.GetValueOrDefault(2000),
                            RangedAttackTime = npc.RangedTime.GetValueOrDefault(2000),
                            UnitClass = (uint)npc.Class.GetValueOrDefault(Class.Warrior),
                            UnitFlag = (uint)npc.UnitFlags.GetValueOrDefault(UnitFlags.None),
                            UnitFlag2 = (uint)npc.UnitFlags2.GetValueOrDefault(UnitFlags2.None),
                            DynamicFlag = (uint)npc.DynamicFlags.GetValueOrDefault(UnitDynamicFlags.None),
                            VehicleId = npc.Movement.VehicleId,
                            HoverHeight = npc.HoverHeight.GetValueOrDefault(1.0f)
                        };

                        template.UnitFlag &= ~(uint)UnitFlags.IsInCombat;
                        template.UnitFlag &= ~(uint)UnitFlags.PetIsAttackingTarget;
                        template.UnitFlag &= ~(uint)UnitFlags.PlayerControlled;
                        template.UnitFlag &= ~(uint)UnitFlags.Silenced;
                        template.UnitFlag &= ~(uint)UnitFlags.PossessedByPlayer;

                        if (!ClientVersion.AddedInVersion(ClientType.WarlordsOfDraenor))
                        {
                            template.DynamicFlag &= ~(uint)UnitDynamicFlags.Lootable;
                            template.DynamicFlag &= ~(uint)UnitDynamicFlags.Tapped;
                            template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByPlayer;
                            template.DynamicFlag &= ~(uint)UnitDynamicFlags.TappedByAllThreatList;
                        }
                        else
                        {
                            template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.Lootable;
                            template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.Tapped;
                            template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.TappedByPlayer;
                            template.DynamicFlag &= ~(uint)UnitDynamicFlagsWOD.TappedByAllThreatList;
                        }

                        // has trainer flag but doesn't have prof nor class trainer flag
                        if ((template.NpcFlag & (uint)NPCFlags.Trainer) != 0 &&
                            ((template.NpcFlag & (uint)NPCFlags.ProfessionTrainer) == 0 ||
                             (template.NpcFlag & (uint)NPCFlags.ClassTrainer) == 0))
                        {
                            var name = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                            var firstIndex = name.LastIndexOf('<');
                            var lastIndex = name.LastIndexOf('>');
                            if (firstIndex != -1 && lastIndex != -1)
                            {
                                var subname = name.Substring(firstIndex + 1, lastIndex - firstIndex - 1);

                                if (_professionTrainers.Contains(subname))
                                    template.NpcFlag |= (uint)NPCFlags.ProfessionTrainer;
                                else if (_classTrainers.Contains(subname))
                                    template.NpcFlag |= (uint)NPCFlags.ClassTrainer;
                            }
                        }

                        templates.Add(creatureDiff.Key, template);
                    }
                }
            }

            var templatesDb = SQLDatabase.GetDict<uint, CreatureDifficultyMisc>(templates.Keys(), "Id");
            return SQLUtil.CompareDicts(templates, templatesDb, StoreNameType.Unit, "Id");
        }
示例#20
0
        public void GetPGPages(Boolean live)
        {
            int debugged = 0;

            StreamWriter swr;

            if (settings.countries.Contains("All"))
            {
                swr = new StreamWriter(debugpgfilename);
            }
            else
            {
                swr = new StreamWriter(debugpgfilename, true);
            }

            string[] tempbl;
            if (settings.blacklist != "")
            {
                tempbl = settings.blacklist.Split(new char[] { ',', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string blentry in tempbl)
                {
                    if (!blacklistdic.ContainsKey(blentry))
                    {
                        blacklistdic.Add(blentry, true);
                    }
                }
            }
            SetProgressBar(calcitems.Count);
            storesWithItemsList.Clear(); // Added by CAC, 6/24/15

            foreach (Item item in calcitems)
            {
                if (!calcWorker.CancellationPending)
                {
                    string page;
                    if (!db_blitems[item.id].pgpage.ContainsKey(item.colour))
                    {
                        item.availqty    = 0;
                        item.availstores = 0;
                        AddStatus("Getting Price Guide information for " + db_colours[item.colour].name + " " + db_blitems[item.id].name + Environment.NewLine);
                        swr.Write(DateTime.Now + "downloading http://www.bricklink.com/catalogPG.asp?" + item.type + "=" + item.number + "&colorID=" + item.colour + Environment.NewLine);

                        if (live)
                        {
                            page = GetPage("http://www.bricklink.com/catalogPG.asp?" + item.type + "=" + item.number + "&colorID=" + item.colour, settings.login);
                            // Uncomment these three lines to save prices guide information so that it is used instead of live data.
                            // Comment them when done.
                            //if (!Directory.Exists("PGCache")) { Directory.CreateDirectory("PGCache"); }
                            //System.IO.StreamWriter file = new StreamWriter("PGCache\\" + item.type + "_" + item.number + "_" + item.colour + ".txt");
                            //file.Write(page);
                        }
                        else
                        {
                            try {
                                StreamReader pageReader = new StreamReader("PGCache\\" + item.type + "_" + item.number + "_" + item.colour + ".txt");
                                page = pageReader.ReadToEnd();
                            } catch (Exception e) {
                                page = "";
                            }
                        }
                        if (debugged == 0)
                        {
                            swr.Write(page);
                            debugged = 1;
                        }
                        if (page == null || page == "##PageFail##")
                        {
                            AddStatus("Error downloading price guide" + Environment.NewLine);
                            calcfail = true;
                            swr.Close();
                            break;
                        }

                        db_blitems[item.id].pgpage.Add(item.colour, page);
                    }
                    else
                    {
                        AddStatus("Using cached Price Guide information for " + db_colours[item.colour].name + " " + db_blitems[item.id].name + Environment.NewLine);
                        page = db_blitems[item.id].pgpage[item.colour];
                    }

                    List <string> chunks = page.Split(new string[] { "<B>Currently Available</B>" }, StringSplitOptions.None).ToList();
                    List <string> rawpgitems;
                    if (chunks.Count > 1)
                    {
                        rawpgitems = chunks[1].Split(new string[] { "</TD></TR>" }, StringSplitOptions.None).ToList();
                    }
                    else
                    {
                        AddStatus("Error downloading price guide (got page, but there was nothing on it)" + Environment.NewLine);
                        calcfail = true;
                        swr.Close();
                        break;
                    }
                    rawpgitems.Add("#usedstart#");
                    if (chunks.Count() > 2)
                    {
                        rawpgitems.AddRange(chunks[2].Split(new string[] { "</TD></TR>" }, StringSplitOptions.None).ToList());
                    }

                    int usedmarker = 0;

                    foreach (string raw in rawpgitems)
                    {
                        if (raw == "#usedstart#")
                        {
                            usedmarker = 1;
                            continue;
                        }

                        if ((item.condition == "N") && (usedmarker == 1))
                        {
                            break;
                        }

                        if (raw.Contains("nbsp;(S)</"))
                        {
                            AddStatus("skip ");
                            continue;
                        }

                        Match linematch = Regex.Match(raw, ".*<TR ALIGN=" + "\"" + @"RIGHT" + "\"" + @"><TD NOWRAP>.*?<A HREF=" + "\"" +
                                                      @"/store.asp\?sID=(\d*?)&.*?<IMG SRC=" + "\"" + @"/images/box16(.).png" + "\"" + @".*?TITLE=" + "\"" + @"Store: (.*?)" +
                                                      "\"" + @" ALIGN=" + "\"" + @"ABSMIDDLE" + "\"" + @">.*?</TD><TD>(\d*)</TD><TD.*?&nbsp;\D*([\d,]*)\.(\d+)$");
                        if (linematch.Success)
                        {
                            string id = linematch.Groups[1].ToString();

                            if (blacklistdic.ContainsKey(id))
                            {
                                continue;
                            }

                            string  ship      = linematch.Groups[2].ToString();
                            string  storename = linematch.Groups[3].ToString();
                            int     qty       = System.Convert.ToInt32(linematch.Groups[4].ToString());
                            string  price1    = linematch.Groups[5].ToString().Replace(",", "");
                            decimal price     = ConvertToDecimal(price1 + "." + linematch.Groups[6].ToString());

                            if (ship == "Y")
                            {
                                if (((StoreDictionary.ContainsKey(storename)) || (settings.countries.Contains("All"))) && (true)) // blacklist
                                {
                                    item.availqty = item.availqty + qty;
                                    if (!storeid.ContainsKey(storename))
                                    {
                                        storeid.Add(storename, id);
                                    }
                                    if (!StoreDictionary.ContainsKey(storename))
                                    {
                                        StoreDictionary.Add(storename, new Dictionary <string, StoreItem>());
                                    }
                                    if (!StoreDictionary[storename].ContainsKey(item.extid))
                                    {
                                        StoreDictionary[storename].Add(item.extid, new StoreItem());
                                    }
                                    if (StoreDictionary[storename][item.extid].qty == 0)
                                    {
                                        StoreDictionary[storename][item.extid].qty   = qty;
                                        StoreDictionary[storename][item.extid].price = price;
                                        item.availstores++;
                                    }
                                    else if (StoreDictionary[storename][item.extid].qty > 0)
                                    {
                                        StoreDictionary[storename][item.extid].qty = StoreDictionary[storename][item.extid].qty + qty;
                                        item.availqty = item.availqty + qty;
                                        if (StoreDictionary[storename][item.extid].price < price)
                                        {
                                            StoreDictionary[storename][item.extid].price = price;
                                        }
                                    }
                                    storesWithItemsList.Add(storename); // Added by CAC, 6/24/15
                                }
                            }
                        }
                        else
                        {
                            if (Regex.Match(raw, "<TR ALIGN=" + "\"" + @"RIGHT" + "\"" + @"><TD NOWRAP>").Success)
                            {
                                AddStatus("No Match: " + raw + Environment.NewLine + Environment.NewLine);
                            }
                        }
                    }
                    if (item.availqty < item.qty)
                    {
                        AddStatus("Error: " + db_colours[item.colour].name + " " + db_blitems[item.id].name +
                                  ":Either this is not available from any stores you've selected or you need to log in." + Environment.NewLine);
                        calcfail = true;
                        ResetProgressBar();
                        swr.Close();
                        break;
                    }
                    else
                    {
                        AddStatus("Available from " + item.availstores + " stores" + Environment.NewLine);
                        //Progress();
                    }
                }
            }
            swr.Close();
        }