Ejemplo n.º 1
0
        public static string BroadcastTextLocale()
        {
            if (Storage.BroadcastTextLocales.IsEmpty())
                return String.Empty;

            if (!Settings.HotfixSQLOutputFlag.HasAnyFlagBit(HotfixSQLOutput.broadcast_text_locale))
                return String.Empty;

            const string tableName = "broadcast_text_locale";

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

            foreach (var broadcastTextLocale in Settings.SQLOrderByKey ? Storage.BroadcastTextLocales.OrderBy(blub => blub.Key).ToList() : Storage.BroadcastTextLocales.ToList())
            {
                if (SQLDatabase.BroadcastTextLocaleStores != null && SQLDatabase.BroadcastTextLocaleStores.ContainsKey(Tuple.Create(broadcastTextLocale.Key.Item1, broadcastTextLocale.Key.Item2)))
                {
                    var row = new QueryBuilder.SQLUpdateRow();
                    var broadcastTextLocaleDB = SQLDatabase.BroadcastTextLocaleStores[Tuple.Create(broadcastTextLocale.Key.Item1, broadcastTextLocale.Key.Item2)];

                    if (!Utilities.EqualValues(broadcastTextLocaleDB.MaleText_lang, broadcastTextLocale.Value.Item1.MaleText_lang))
                        row.AddValue("MaleText_lang", broadcastTextLocale.Value.Item1.MaleText_lang);

                    if (!Utilities.EqualValues(broadcastTextLocaleDB.FemaleText_lang, broadcastTextLocale.Value.Item1.FemaleText_lang))
                        row.AddValue("FemaleText_lang", broadcastTextLocale.Value.Item1.FemaleText_lang);

                    if (!Utilities.EqualValues(broadcastTextLocaleDB.VerifiedBuild, broadcastTextLocale.Value.Item1.VerifiedBuild))
                        row.AddValue("VerifiedBuild", broadcastTextLocale.Value.Item1.VerifiedBuild);

                    row.AddWhere("ID", broadcastTextLocale.Key.Item1);
                    row.AddWhere("locale", broadcastTextLocale.Key.Item2);

                    row.Table = tableName;

                    rowsUpd.Add(row);
                }
                else // insert new
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("ID", broadcastTextLocale.Key.Item1);
                    row.AddValue("locale", broadcastTextLocale.Key.Item2);

                    row.AddValue("MaleText_lang", broadcastTextLocale.Value.Item1.MaleText_lang);
                    row.AddValue("FemaleText_lang", broadcastTextLocale.Value.Item1.FemaleText_lang);

                    row.AddValue("VerifiedBuild", broadcastTextLocale.Value.Item1.VerifiedBuild);

                    rowsIns.Add(row);
                }
            }

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

            return "SET NAMES 'utf8';" + Environment.NewLine + result + Environment.NewLine + "SET NAMES 'latin1';";
        }
Ejemplo n.º 2
0
        public static string NpcName()
        {
            var result = "";

            if (Storage.UnitTemplates.IsEmpty())
                return String.Empty;

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

            const string tableName = "creature_template";

            if (SQLConnector.Enabled)
            {
                var rowsUpd = new List<QueryBuilder.SQLUpdateRow>();

                foreach (var npcName in Storage.UnitTemplates)
                {
                    var query = string.Format("SELECT name FROM {0}.creature_template WHERE entry={1};",
                        Settings.TDBDatabase, npcName.Key);

                    using (var reader = SQLConnector.ExecuteQuery(query))
                    {
                        if (reader.HasRows) // possible update
                        {
                            while (reader.Read())
                            {
                                var row = new QueryBuilder.SQLUpdateRow();

                                if (!Utilities.EqualValues(reader.GetValue(0), npcName.Value.Item1.Name))
                                    row.AddValue("name", npcName.Value.Item1.Name);

                                if (Utilities.EqualValues(reader.GetValue(0), npcName.Value.Item1.Name) && npcName.Value.Item1.femaleName != null)
                                    row.AddValue("femaleName", npcName.Value.Item1.femaleName);

                                row.AddWhere("entry", npcName.Key);

                                row.Table = tableName;

                                if (row.ValueCount != 0)
                                    rowsUpd.Add(row);
                            }
                        }
                    }
                }

                result += new QueryBuilder.SQLUpdate(rowsUpd).Build();
            }

            return result;
        }
Ejemplo n.º 3
0
        public static string NpcName()
        {
            var result = "";

            if (Storage.UnitTemplates.IsEmpty())
                return String.Empty;

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

            const string tableName = "creature_template";

            if (SQLConnector.Enabled)
            {
                var rowsUpd = new List<QueryBuilder.SQLUpdateRow>();

                foreach (var npcName in Storage.UnitTemplates)
                {
                    var query = string.Format("SELECT name FROM {0}.creature_template WHERE entry={1};",
                        Settings.TDBDatabase, npcName.Key);

                    using (var reader = SQLConnector.ExecuteQuery(query))
                    {
                        if (reader.HasRows) // possible update
                        {
                            while (reader.Read())
                            {
                                var row = new QueryBuilder.SQLUpdateRow();

                                if (!Utilities.EqualValues(reader.GetValue(0), npcName.Value.Item1.Name))
                                    row.AddValue("name", npcName.Value.Item1.Name);

                                if (Utilities.EqualValues(reader.GetValue(0), npcName.Value.Item1.Name) && npcName.Value.Item1.femaleName != null)
                                    row.AddValue("femaleName", npcName.Value.Item1.femaleName);

                                row.AddWhere("entry", npcName.Key);

                                row.Table = tableName;

                                if (row.ValueCount != 0)
                                    rowsUpd.Add(row);
                            }
                        }
                    }
                }

                result += new QueryBuilder.SQLUpdate(rowsUpd).Build();
            }

            return result;
        }
Ejemplo n.º 4
0
        public static string LocalesQuest()
        {
            if (Storage.LocalesQuests.IsEmpty())
                return String.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.locales_quest))
                return String.Empty;

            const string tableName = "quest_template_locale";

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

            foreach (var localesQuest in Settings.SQLOrderByKey ? Storage.LocalesQuests.OrderBy(blub => blub.Key).ToList() : Storage.LocalesQuests.ToList())
            {
                if (SQLDatabase.LocalesQuestStores != null && SQLDatabase.LocalesQuestStores.ContainsKey(Tuple.Create(localesQuest.Key.Item1, localesQuest.Key.Item2)))
                {
                    var row = new QueryBuilder.SQLUpdateRow();
                    var localesQuestDB = SQLDatabase.LocalesQuestStores[Tuple.Create(localesQuest.Key.Item1, localesQuest.Key.Item2)];

                    if (!Utilities.EqualValues(localesQuestDB.LogTitle, localesQuest.Value.Item1.LogTitle))
                        row.AddValue("LogTitle", localesQuest.Value.Item1.LogTitle);

                    if (!Utilities.EqualValues(localesQuestDB.LogDescription, localesQuest.Value.Item1.LogDescription))
                        row.AddValue("LogDescription", localesQuest.Value.Item1.LogDescription);

                    if (!Utilities.EqualValues(localesQuestDB.QuestDescription, localesQuest.Value.Item1.QuestDescription))
                        row.AddValue("QuestDescription", localesQuest.Value.Item1.QuestDescription);

                    if (!Utilities.EqualValues(localesQuestDB.AreaDescription, localesQuest.Value.Item1.AreaDescription))
                        row.AddValue("AreaDescription", localesQuest.Value.Item1.AreaDescription);

                    if (!Utilities.EqualValues(localesQuestDB.QuestCompletionLog, localesQuest.Value.Item1.QuestCompletionLog))
                        row.AddValue("QuestCompletionLog", localesQuest.Value.Item1.QuestCompletionLog);

                    if (!Utilities.EqualValues(localesQuestDB.PortraitGiverText, localesQuest.Value.Item1.PortraitGiverText))
                        row.AddValue("PortraitGiverText", localesQuest.Value.Item1.PortraitGiverText);

                    if (!Utilities.EqualValues(localesQuestDB.PortraitGiverName, localesQuest.Value.Item1.PortraitGiverName))
                        row.AddValue("PortraitGiverName", localesQuest.Value.Item1.PortraitGiverName);

                    if (!Utilities.EqualValues(localesQuestDB.PortraitTurnInText, localesQuest.Value.Item1.PortraitTurnInText))
                        row.AddValue("PortraitTurnInText", localesQuest.Value.Item1.PortraitTurnInText);

                    if (!Utilities.EqualValues(localesQuestDB.PortraitTurnInName, localesQuest.Value.Item1.PortraitTurnInName))
                        row.AddValue("PortraitTurnInName", localesQuest.Value.Item1.PortraitTurnInName);

                    if (!Utilities.EqualValues(localesQuestDB.VerifiedBuild, localesQuest.Value.Item1.VerifiedBuild))
                        row.AddValue("VerifiedBuild", localesQuest.Value.Item1.VerifiedBuild);

                    row.AddWhere("ID", localesQuest.Key.Item1);
                    row.AddWhere("locale", localesQuest.Key.Item2);

                    row.Table = tableName;

                    rowsUpd.Add(row);
                }
                else // insert new
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("ID", localesQuest.Key.Item1);
                    row.AddValue("locale", localesQuest.Key.Item2);

                    row.AddValue("LogTitle", localesQuest.Value.Item1.LogTitle);
                    row.AddValue("LogDescription", localesQuest.Value.Item1.LogDescription);
                    row.AddValue("QuestDescription", localesQuest.Value.Item1.QuestDescription);
                    row.AddValue("AreaDescription", localesQuest.Value.Item1.AreaDescription);
                    row.AddValue("PortraitGiverText", localesQuest.Value.Item1.AreaDescription);
                    row.AddValue("PortraitGiverName", localesQuest.Value.Item1.PortraitGiverName);
                    row.AddValue("PortraitTurnInText", localesQuest.Value.Item1.PortraitTurnInText);
                    row.AddValue("PortraitTurnInName", localesQuest.Value.Item1.PortraitTurnInName);
                    row.AddValue("QuestCompletionLog", localesQuest.Value.Item1.QuestCompletionLog);

                    row.AddValue("VerifiedBuild", localesQuest.Value.Item1.VerifiedBuild);

                    rowsIns.Add(row);
                }
            }

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

            return "SET NAMES 'utf8';" + Environment.NewLine + result + Environment.NewLine + "SET NAMES 'latin1';";
        }
Ejemplo n.º 5
0
        public static string QuestObjective()
        {
            var result = "";

            if (Storage.QuestObjectives.IsEmpty())
            {
                return(String.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.quest_template))
            {
                return(String.Empty);
            }

            var entries     = Storage.QuestObjectives.Keys();
            var templatesDb = SQLDatabase.GetDict <uint, QuestInfoObjective>(entries, "Id");

            result += SQLUtil.CompareDicts(Storage.QuestObjectives, templatesDb, StoreNameType.QuestObjective, "Id");

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

            foreach (var questObjectives in Storage.QuestObjectives)
            {
                foreach (var visualEffectIds in questObjectives.Value.Item1.VisualEffectIds)
                {
                    if (SQLConnector.Enabled)
                    {
                        var query = string.Format("SELECT `VisualEffect`, `VerifiedBuild` FROM {0}.quest_visual_effect WHERE `Id`={1} AND `Index`={2};",
                                                  Settings.TDBDatabase, questObjectives.Key, visualEffectIds.Index);

                        using (var reader = SQLConnector.ExecuteQuery(query))
                        {
                            if (reader.HasRows) // possible update
                            {
                                while (reader.Read())
                                {
                                    var row = new QueryBuilder.SQLUpdateRow();

                                    if (!Utilities.EqualValues(reader.GetValue(0), visualEffectIds.VisualEffect))
                                    {
                                        row.AddValue("VisualEffect", visualEffectIds.VisualEffect);
                                    }

                                    if (!Utilities.EqualValues(reader.GetValue(1), questObjectives.Value.Item1.VerifiedBuild))
                                    {
                                        row.AddValue("VerifiedBuild", questObjectives.Value.Item1.VerifiedBuild);
                                    }

                                    row.AddWhere("Id", questObjectives.Key);
                                    row.AddWhere("Index", visualEffectIds.Index);

                                    row.Table = "quest_visual_effect";

                                    if (row.ValueCount != 0)
                                    {
                                        rowsUpd.Add(row);
                                    }
                                }
                            }
                            else // insert
                            {
                                var row = new QueryBuilder.SQLInsertRow();

                                row.AddValue("Id", questObjectives.Key);
                                row.AddValue("Index", visualEffectIds.Index);
                                row.AddValue("VisualEffect", visualEffectIds.VisualEffect);
                                row.AddValue("VerifiedBuild", questObjectives.Value.Item1.VerifiedBuild);

                                rowsIns.Add(row);
                            }
                        }
                    }
                    else // insert
                    {
                        var row = new QueryBuilder.SQLInsertRow();

                        row.AddValue("Id", questObjectives.Key);
                        row.AddValue("Index", visualEffectIds.Index);
                        row.AddValue("VisualEffect", visualEffectIds.VisualEffect);
                        row.AddValue("VerifiedBuild", questObjectives.Value.Item1.VerifiedBuild);

                        rowsIns.Add(row);
                    }
                }
            }

            result += new QueryBuilder.SQLInsert("quest_visual_effect", rowsIns, 2).Build() + new QueryBuilder.SQLUpdate(rowsUpd).Build();

            return(result);
        }
Ejemplo n.º 6
0
        public static string PointsOfInterest()
        {
            if (Storage.GossipPOIs.IsEmpty())
            {
                return(string.Empty);
            }

            var result = string.Empty;

            if (!Storage.GossipSelects.IsEmpty() && Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gossip_menu_option))
            {
                var gossipPOIsTable = new Dictionary <Tuple <uint, uint>, uint>();

                foreach (var poi in Storage.GossipPOIs)
                {
                    foreach (var gossipSelect in Storage.GossipSelects)
                    {
                        var tuple = Tuple.Create(gossipSelect.Key.Item1, gossipSelect.Key.Item2);

                        if (gossipPOIsTable.ContainsKey(tuple))
                        {
                            continue;
                        }

                        var timeSpan = poi.Value.Item2 - gossipSelect.Value.Item2;
                        if (timeSpan != null && timeSpan.Value.Duration() <= TimeSpan.FromSeconds(1))
                        {
                            gossipPOIsTable.Add(tuple, poi.Key);
                        }
                    }
                }

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

                foreach (var u in gossipPOIsTable)
                {
                    var row = new QueryBuilder.SQLUpdateRow();

                    row.AddValue("action_poi_id", u.Value);

                    row.AddWhere("menu_id", u.Key.Item1);
                    row.AddWhere("id", u.Key.Item2);

                    row.Table = "gossip_menu_option";

                    rowsUpd.Add(row);
                }

                result += new QueryBuilder.SQLUpdate(rowsUpd).Build();
            }

            if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.points_of_interest))
            {
                const string tableName = "points_of_interest";
                var          rowsIns   = new List <QueryBuilder.SQLInsertRow>();

                uint count = 0;

                foreach (var poi in Storage.GossipPOIs)
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("entry", "@ID+" + count, noQuotes: true);
                    row.AddValue("x", poi.Value.Item1.XPos);
                    row.AddValue("y", poi.Value.Item1.YPos);
                    row.AddValue("icon", poi.Value.Item1.Icon);
                    row.AddValue("flags", poi.Value.Item1.Flags);
                    row.AddValue("data", poi.Value.Item1.Data);
                    row.AddValue("icon_name", poi.Value.Item1.IconName);

                    rowsIns.Add(row);
                    count++;
                }

                result += new QueryBuilder.SQLDelete(Tuple.Create("@ID+0", "@ID+" + (count - 1)), "entry", tableName).Build();
                result += new QueryBuilder.SQLInsert(tableName, rowsIns, withDelete: false).Build();
            }

            return(result);
        }
Ejemplo n.º 7
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;

            const string tableName = "creature_template";

            var rows = new List<QueryBuilder.SQLUpdateRow>();
            ICollection<uint> key = new Collection<uint>();

            foreach (var unit in units)
            {
                // don't save duplicates
                if (key.Contains(unit.Key.GetEntry()))
                    continue;

                var row = new QueryBuilder.SQLUpdateRow();
                var npc = unit.Value;
                npc.LoadValuesFromUpdateFields();

                var name = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);

                // Only movement flags in 335 are being read correctly - fix them and remove this if
                if (ClientVersion.Build == ClientVersionBuild.V3_3_5a_12340)
                {
                    if (npc.Movement.Flags.HasAnyFlag(MovementFlag.CanFly) && npc.Movement.Flags.HasAnyFlag(MovementFlag.WalkMode))
                        row.AddValue("InhabitType", InhabitType.Ground | InhabitType.Air, true);
                    else if (npc.Movement.Flags.HasAnyFlag(MovementFlag.DisableGravity))
                        row.AddValue("InhabitType", InhabitType.Air, true);
                }

                row.AddValue("HoverHeight", npc.HoverHeight, 1);
                row.AddValue("WalkSpeed", npc.Movement.WalkSpeed, 1);
                row.AddValue("RunSpeed", npc.Movement.RunSpeed, 1.142857);
                row.AddValue("VehicleId", npc.Movement.VehicleId, 0u);
                row.AddValue("Size", npc.Size, 1u);
                row.AddValue("Level", npc.Level, 1u); // min/max
                row.AddValue("Faction", npc.Faction, 35u); // faction_A, faction_H
                row.AddValue("UnitFlags", npc.UnitFlags, UnitFlags.None, true);
                row.AddValue("BaseAttackTime", npc.MeleeTime, 2000u);
                row.AddValue("RangeAttackTime", npc.RangedTime, 0u); // 2000?
                row.AddValue("Model", npc.Model, 0u); // model1, model2, ...
                row.AddValue("DynamicFlags", npc.DynamicFlags, UnitDynamicFlags.None, true);
                row.AddValue("NpcFlags", npc.NpcFlags, NPCFlags.None, true);

                if (npc.Resistances != null)
                    for (var i = 1; i < npc.Resistances.Length; ++i) // No armor
                        row.AddValue("Resistances" + i, npc.Resistances[i], 0u);

                // row.AddValue("ManaMod", npc.ManaMod, 1); this is not mod, it needs to be calculated
                // row.AddValue("HealthMod", npc.HealthMod, 1);
                row.AddValue("Class", npc.Class, Class.Warrior);
                //row.AddValue("Race", npc.Race, Race.None);

                row.AddWhere("entry", unit.Key.GetEntry());
                row.Table = tableName;
                row.Comment = name;

                rows.Add(row);
                key.Add(unit.Key.GetEntry());
            }

            return new QueryBuilder.SQLUpdate(rows).Build();
        }
Ejemplo n.º 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);*/
        }
Ejemplo n.º 9
0
        public static string ModelData(Dictionary <Guid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

            const string tableName = "creature_model_info";

            // Build a dictionary with model data; model is the key
            var models = new SortedDictionary <uint, Tuple <float, float, Gender> >();

            foreach (var unit in units)
            {
                var npc = unit.Value;

                if (npc.Model == null)
                {
                    continue;
                }
                var model = (uint)npc.Model;

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

                var boundingRadius = 0.0f;
                if (npc.BoundingRadius != null)
                {
                    boundingRadius = (float)npc.BoundingRadius;
                }

                var combatReach = 0.0f;
                if (npc.CombatReach != null)
                {
                    combatReach = (float)npc.CombatReach;
                }

                var gender = Gender.None;
                if (npc.Gender != null)
                {
                    gender = (Gender)npc.Gender;
                }

                models.Add(model, Tuple.Create(boundingRadius, combatReach, gender));
            }

            Dictionary <uint, dynamic> modelsDb = null;

            if (SQLConnector.Enabled)
            {
                modelsDb = SQLDatabase.GetDict <uint>(string.Format(
                                                          "SELECT `modelid`, `bounding_radius`, `combat_reach`," +
                                                          "`gender` FROM `{0}`.{1} WHERE `modelid` IN ({2});", Settings.TDBDatabase, tableName, String.Join(",", models.Keys)));
            }

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

            foreach (var model in models)
            {
                if (modelsDb != null && modelsDb.Count != 0)
                {
                    if (modelsDb.ContainsKey(model.Key)) // possible update
                    {
                        var row = new QueryBuilder.SQLUpdateRow();

                        if (!Utilities.EqualValues(modelsDb[model.Key].Item1, model.Value.Item1))
                        {
                            row.AddValue("bounding_radius", model.Value.Item1);
                        }

                        if (!Utilities.EqualValues(modelsDb[model.Key].Item2, model.Value.Item2))
                        {
                            row.AddValue("combat_reach", model.Value.Item2);
                        }

                        if (!Utilities.EqualValues(modelsDb[model.Key].Item3, model.Value.Item3))
                        {
                            row.AddValue("gender", model.Value.Item3);
                        }

                        row.AddWhere("modelid", model.Key);
                        row.Table = tableName;

                        if (row.ValueCount != 0)
                        {
                            rowsUpd.Add(row);
                        }
                    }
                    else // insert new
                    {
                        var row = new QueryBuilder.SQLInsertRow();
                        row.AddValue("modelid", model.Key);
                        row.AddValue("bounding_radius", model.Value.Item1);
                        row.AddValue("combat_reach", model.Value.Item2);
                        row.AddValue("gender", model.Value.Item3);
                        rowsIns.Add(row);
                    }
                }
                else // no db values, simply do inserts
                {
                    var row = new QueryBuilder.SQLInsertRow();
                    row.AddValue("modelid", model.Key);
                    row.AddValue("bounding_radius", model.Value.Item1);
                    row.AddValue("combat_reach", model.Value.Item2);
                    row.AddValue("gender", model.Value.Item3);
                    rowsIns.Add(row);
                }
            }

            return(new QueryBuilder.SQLInsert(tableName, rowsIns).Build() +
                   new QueryBuilder.SQLUpdate(rowsUpd).Build());
        }
Ejemplo n.º 10
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);
            }

            const string tableName = "creature_template";

            var rows = new List <QueryBuilder.SQLUpdateRow>();
            ICollection <uint> key = new Collection <uint>();

            foreach (var unit in units)
            {
                // don't save duplicates
                if (key.Contains(unit.Key.GetEntry()))
                {
                    continue;
                }

                var row = new QueryBuilder.SQLUpdateRow();
                var npc = unit.Value;

                var name = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);

                // Only movement flags in 335 are being read correctly - fix them and remove this if
                if (ClientVersion.Build == ClientVersionBuild.V3_3_5a_12340)
                {
                    if (npc.Movement.Flags.HasAnyFlag(MovementFlag.CanFly) && npc.Movement.Flags.HasAnyFlag(MovementFlag.WalkMode))
                    {
                        row.AddValue("InhabitType", InhabitType.Ground | InhabitType.Air, true);
                    }
                    else if (npc.Movement.Flags.HasAnyFlag(MovementFlag.DisableGravity))
                    {
                        row.AddValue("InhabitType", InhabitType.Air, true);
                    }
                }

                row.AddValue("HoverHeight", npc.HoverHeight, 1);
                row.AddValue("WalkSpeed", npc.Movement.WalkSpeed, 1);
                row.AddValue("RunSpeed", npc.Movement.RunSpeed, 1.142857);
                row.AddValue("VehicleId", npc.Movement.VehicleId, 0u);
                row.AddValue("Size", npc.Size, 1u);
                row.AddValue("Level", npc.Level, 1u);      // min/max
                row.AddValue("Faction", npc.Faction, 35u); // faction_A, faction_H
                row.AddValue("UnitFlags", npc.UnitFlags, UnitFlags.None, true);
                row.AddValue("BaseAttackTime", npc.MeleeTime, 2000u);
                row.AddValue("RangeAttackTime", npc.RangedTime, 0u); // 2000?
                row.AddValue("Model", npc.Model, 0u);                // model1, model2, ...
                row.AddValue("DynamicFlags", npc.DynamicFlags, UnitDynamicFlags.None, true);
                row.AddValue("NpcFlags", npc.NpcFlags, NPCFlags.None, true);

                if (npc.Resistances != null)
                {
                    for (var i = 1; i < npc.Resistances.Length; ++i) // No armor
                    {
                        row.AddValue("Resistances" + i, npc.Resistances[i], 0u);
                    }
                }

                // row.AddValue("ManaMod", npc.ManaMod, 1); this is not mod, it needs to be calculated
                // row.AddValue("HealthMod", npc.HealthMod, 1);
                row.AddValue("Class", npc.Class, Class.Warrior);
                //row.AddValue("Race", npc.Race, Race.None);

                row.AddWhere("entry", unit.Key.GetEntry());
                row.Table   = tableName;
                row.Comment = name;

                rows.Add(row);
                key.Add(unit.Key.GetEntry());
            }

            return(new QueryBuilder.SQLUpdate(rows).Build());
        }
Ejemplo n.º 11
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;

            const string tableName = "creature_template";

            var levels = GetLevels(units);

            var templates = new Dictionary<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),
                    SpeedWalk = npc.Movement.RunSpeed,
                    SpeedRun = 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),
                    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);
            }

            var db = SQLDatabase.GetDict<uint, UnitTemplateNonWDB>(templates.Keys.ToList());
            if (db == null)
                return "";

            var rows = new List<QueryBuilder.SQLUpdateRow>();
            foreach (var unit in templates)
            {
                var row = new QueryBuilder.SQLUpdateRow();
                var npcLocal = unit.Value;
                UnitTemplateNonWDB npcRemote;
                if (!db.TryGetValue(unit.Key, out npcRemote))
                    continue;

                if (!Utilities.EqualValues(npcLocal.GossipMenuId, npcRemote.GossipMenuId))
                    row.AddValue("gossip_menu_id", npcLocal.GossipMenuId);

                if (!Utilities.EqualValues(npcLocal.MinLevel, npcRemote.MinLevel))
                    row.AddValue("minlevel", npcLocal.MinLevel);

                if (!Utilities.EqualValues(npcLocal.MaxLevel, npcRemote.MaxLevel))
                    row.AddValue("maxlevel", npcLocal.MaxLevel);

                if (!Utilities.EqualValues(npcLocal.Faction, npcRemote.Faction))
                {
                    row.AddValue("faction_A", npcLocal.Faction);
                    row.AddValue("faction_H", npcLocal.Faction);
                }

                if (!Utilities.EqualValues(npcLocal.NpcFlag, npcRemote.NpcFlag))
                    row.AddValue("npcflag", npcLocal.NpcFlag);

                if (!Utilities.EqualValues(npcLocal.SpeedWalk, npcRemote.SpeedWalk))
                    row.AddValue("speed_walk", npcLocal.SpeedWalk);

                if (!Utilities.EqualValues(npcLocal.SpeedRun, npcRemote.SpeedRun))
                    row.AddValue("speed_run", npcLocal.SpeedRun);

                if (!Utilities.EqualValues(npcLocal.BaseAttackTime, npcRemote.BaseAttackTime))
                    row.AddValue("baseattacktime", npcLocal.BaseAttackTime);

                if (!Utilities.EqualValues(npcLocal.RangedAttackTime, npcRemote.RangedAttackTime))
                    row.AddValue("rangeattacktime", npcLocal.RangedAttackTime);

                if (!Utilities.EqualValues(npcLocal.UnitClass, npcRemote.UnitClass))
                    row.AddValue("unit_class", npcLocal.UnitClass);

                if (!Utilities.EqualValues(npcLocal.UnitFlag, npcRemote.UnitFlag))
                    row.AddValue("unit_flags", npcLocal.UnitFlag);

                if (!Utilities.EqualValues(npcLocal.DynamicFlag, npcRemote.DynamicFlag))
                    row.AddValue("dynamicflags", npcLocal.DynamicFlag);

                if (!Utilities.EqualValues(npcLocal.VehicleId, npcRemote.VehicleId))
                    row.AddValue("VehicleId", npcLocal.VehicleId);

                if (!Utilities.EqualValues(npcLocal.HoverHeight, npcRemote.UnitClass))
                    row.AddValue("HoverHeight", npcLocal.HoverHeight);

                if (row.ValueCount != 0)
                {
                    row.AddWhere("entry", unit.Key);
                    row.Table = tableName;
                    row.Comment = StoreGetters.GetName(StoreNameType.Unit, (int) unit.Key, false);
                    rows.Add(row);
                }
            }

            return new QueryBuilder.SQLUpdate(rows).Build();
        }
Ejemplo n.º 12
0
        public static string LocalesQuest()
        {
            if (Storage.LocalesQuests.IsEmpty())
            {
                return(String.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.locales_quest))
            {
                return(String.Empty);
            }

            const string tableName = "quest_template_locale";

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

            foreach (var localesQuest in Settings.SQLOrderByKey ? Storage.LocalesQuests.OrderBy(blub => blub.Key).ToList() : Storage.LocalesQuests.ToList())
            {
                if (SQLDatabase.LocalesQuestStores != null && SQLDatabase.LocalesQuestStores.ContainsKey(Tuple.Create(localesQuest.Key.Item1, localesQuest.Key.Item2)))
                {
                    var row            = new QueryBuilder.SQLUpdateRow();
                    var localesQuestDB = SQLDatabase.LocalesQuestStores[Tuple.Create(localesQuest.Key.Item1, localesQuest.Key.Item2)];

                    if (!Utilities.EqualValues(localesQuestDB.LogTitle, localesQuest.Value.Item1.LogTitle))
                    {
                        row.AddValue("LogTitle", localesQuest.Value.Item1.LogTitle);
                    }

                    if (!Utilities.EqualValues(localesQuestDB.LogDescription, localesQuest.Value.Item1.LogDescription))
                    {
                        row.AddValue("LogDescription", localesQuest.Value.Item1.LogDescription);
                    }

                    if (!Utilities.EqualValues(localesQuestDB.QuestDescription, localesQuest.Value.Item1.QuestDescription))
                    {
                        row.AddValue("QuestDescription", localesQuest.Value.Item1.QuestDescription);
                    }

                    if (!Utilities.EqualValues(localesQuestDB.AreaDescription, localesQuest.Value.Item1.AreaDescription))
                    {
                        row.AddValue("AreaDescription", localesQuest.Value.Item1.AreaDescription);
                    }

                    if (!Utilities.EqualValues(localesQuestDB.QuestCompletionLog, localesQuest.Value.Item1.QuestCompletionLog))
                    {
                        row.AddValue("QuestCompletionLog", localesQuest.Value.Item1.QuestCompletionLog);
                    }

                    if (!Utilities.EqualValues(localesQuestDB.PortraitGiverText, localesQuest.Value.Item1.PortraitGiverText))
                    {
                        row.AddValue("PortraitGiverText", localesQuest.Value.Item1.PortraitGiverText);
                    }

                    if (!Utilities.EqualValues(localesQuestDB.PortraitGiverName, localesQuest.Value.Item1.PortraitGiverName))
                    {
                        row.AddValue("PortraitGiverName", localesQuest.Value.Item1.PortraitGiverName);
                    }

                    if (!Utilities.EqualValues(localesQuestDB.PortraitTurnInText, localesQuest.Value.Item1.PortraitTurnInText))
                    {
                        row.AddValue("PortraitTurnInText", localesQuest.Value.Item1.PortraitTurnInText);
                    }

                    if (!Utilities.EqualValues(localesQuestDB.PortraitTurnInName, localesQuest.Value.Item1.PortraitTurnInName))
                    {
                        row.AddValue("PortraitTurnInName", localesQuest.Value.Item1.PortraitTurnInName);
                    }

                    if (!Utilities.EqualValues(localesQuestDB.VerifiedBuild, localesQuest.Value.Item1.VerifiedBuild))
                    {
                        row.AddValue("VerifiedBuild", localesQuest.Value.Item1.VerifiedBuild);
                    }

                    row.AddWhere("ID", localesQuest.Key.Item1);
                    row.AddWhere("locale", localesQuest.Key.Item2);

                    row.Table = tableName;

                    rowsUpd.Add(row);
                }
                else // insert new
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("ID", localesQuest.Key.Item1);
                    row.AddValue("locale", localesQuest.Key.Item2);

                    row.AddValue("LogTitle", localesQuest.Value.Item1.LogTitle);
                    row.AddValue("LogDescription", localesQuest.Value.Item1.LogDescription);
                    row.AddValue("QuestDescription", localesQuest.Value.Item1.QuestDescription);
                    row.AddValue("AreaDescription", localesQuest.Value.Item1.AreaDescription);
                    row.AddValue("PortraitGiverText", localesQuest.Value.Item1.AreaDescription);
                    row.AddValue("PortraitGiverName", localesQuest.Value.Item1.PortraitGiverName);
                    row.AddValue("PortraitTurnInText", localesQuest.Value.Item1.PortraitTurnInText);
                    row.AddValue("PortraitTurnInName", localesQuest.Value.Item1.PortraitTurnInName);
                    row.AddValue("QuestCompletionLog", localesQuest.Value.Item1.QuestCompletionLog);

                    row.AddValue("VerifiedBuild", localesQuest.Value.Item1.VerifiedBuild);

                    rowsIns.Add(row);
                }
            }

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

            return("SET NAMES 'utf8';" + Environment.NewLine + result + Environment.NewLine + "SET NAMES 'latin1';");
        }
Ejemplo n.º 13
0
        public static string LocalesQuestObjectives()
        {
            if (Storage.LocalesQuestObjectives.IsEmpty())
            {
                return(String.Empty);
            }

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.locales_quest_objectives))
            {
                return(String.Empty);
            }

            const string tableName = "quest_objectives_locale";

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

            foreach (var localesQuestObjective in Settings.SQLOrderByKey ? Storage.LocalesQuestObjectives.OrderBy(blub => blub.Key).ToList() : Storage.LocalesQuestObjectives.ToList())
            {
                if (SQLDatabase.LocalesQuestObjectiveStores != null && SQLDatabase.LocalesQuestObjectiveStores.ContainsKey(Tuple.Create(localesQuestObjective.Key.Item1, localesQuestObjective.Key.Item2)))
                {
                    var row = new QueryBuilder.SQLUpdateRow();
                    var localesQuestObjectiveDB = SQLDatabase.LocalesQuestObjectiveStores[Tuple.Create(localesQuestObjective.Key.Item1, localesQuestObjective.Key.Item2)];

                    if (!Utilities.EqualValues(localesQuestObjectiveDB.QuestId, localesQuestObjective.Value.Item1.QuestId))
                    {
                        row.AddValue("QuestId", localesQuestObjective.Value.Item1.QuestId);
                    }

                    if (!Utilities.EqualValues(localesQuestObjectiveDB.StorageIndex, localesQuestObjective.Value.Item1.StorageIndex))
                    {
                        row.AddValue("StorageIndex", localesQuestObjective.Value.Item1.StorageIndex);
                    }

                    if (!Utilities.EqualValues(localesQuestObjectiveDB.Description, localesQuestObjective.Value.Item1.Description))
                    {
                        row.AddValue("Description", localesQuestObjective.Value.Item1.Description);
                    }

                    if (!Utilities.EqualValues(localesQuestObjectiveDB.VerifiedBuild, localesQuestObjective.Value.Item1.VerifiedBuild))
                    {
                        row.AddValue("VerifiedBuild", localesQuestObjective.Value.Item1.VerifiedBuild);
                    }

                    row.AddWhere("ID", localesQuestObjective.Key.Item1);
                    row.AddWhere("locale", localesQuestObjective.Key.Item2);

                    row.Table = tableName;

                    rowsUpd.Add(row);
                }
                else // insert new
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("ID", localesQuestObjective.Key.Item1);
                    row.AddValue("locale", localesQuestObjective.Key.Item2);

                    row.AddValue("QuestId", localesQuestObjective.Value.Item1.QuestId);
                    row.AddValue("StorageIndex", localesQuestObjective.Value.Item1.StorageIndex);
                    row.AddValue("Description", localesQuestObjective.Value.Item1.Description);

                    row.AddValue("VerifiedBuild", localesQuestObjective.Value.Item1.VerifiedBuild);

                    rowsIns.Add(row);
                }
            }

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

            return("SET NAMES 'utf8';" + Environment.NewLine + result + Environment.NewLine + "SET NAMES 'latin1';");
        }
Ejemplo n.º 14
0
        public static string BroadcastTextLocale()
        {
            if (Storage.BroadcastTextLocales.IsEmpty())
            {
                return(String.Empty);
            }

            if (!Settings.HotfixSQLOutputFlag.HasAnyFlagBit(HotfixSQLOutput.broadcast_text_locale))
            {
                return(String.Empty);
            }

            const string tableName = "broadcast_text_locale";

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

            foreach (var broadcastTextLocale in Settings.SQLOrderByKey ? Storage.BroadcastTextLocales.OrderBy(blub => blub.Key).ToList() : Storage.BroadcastTextLocales.ToList())
            {
                if (SQLDatabase.BroadcastTextLocaleStores != null && SQLDatabase.BroadcastTextLocaleStores.ContainsKey(Tuple.Create(broadcastTextLocale.Key.Item1, broadcastTextLocale.Key.Item2)))
                {
                    var row = new QueryBuilder.SQLUpdateRow();
                    var broadcastTextLocaleDB = SQLDatabase.BroadcastTextLocaleStores[Tuple.Create(broadcastTextLocale.Key.Item1, broadcastTextLocale.Key.Item2)];

                    if (!Utilities.EqualValues(broadcastTextLocaleDB.MaleText_lang, broadcastTextLocale.Value.Item1.MaleText_lang))
                    {
                        row.AddValue("MaleText_lang", broadcastTextLocale.Value.Item1.MaleText_lang);
                    }

                    if (!Utilities.EqualValues(broadcastTextLocaleDB.FemaleText_lang, broadcastTextLocale.Value.Item1.FemaleText_lang))
                    {
                        row.AddValue("FemaleText_lang", broadcastTextLocale.Value.Item1.FemaleText_lang);
                    }

                    if (!Utilities.EqualValues(broadcastTextLocaleDB.VerifiedBuild, broadcastTextLocale.Value.Item1.VerifiedBuild))
                    {
                        row.AddValue("VerifiedBuild", broadcastTextLocale.Value.Item1.VerifiedBuild);
                    }

                    row.AddWhere("ID", broadcastTextLocale.Key.Item1);
                    row.AddWhere("locale", broadcastTextLocale.Key.Item2);

                    row.Table = tableName;

                    rowsUpd.Add(row);
                }
                else // insert new
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("ID", broadcastTextLocale.Key.Item1);
                    row.AddValue("locale", broadcastTextLocale.Key.Item2);

                    row.AddValue("MaleText_lang", broadcastTextLocale.Value.Item1.MaleText_lang);
                    row.AddValue("FemaleText_lang", broadcastTextLocale.Value.Item1.FemaleText_lang);

                    row.AddValue("VerifiedBuild", broadcastTextLocale.Value.Item1.VerifiedBuild);

                    rowsIns.Add(row);
                }
            }

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

            return("SET NAMES 'utf8';" + Environment.NewLine + result + Environment.NewLine + "SET NAMES 'latin1';");
        }
Ejemplo n.º 15
0
        public static string Gossip()
        {
            if (Storage.Gossips.IsEmpty)
                return String.Empty;

            // `creature_template`
            var gossipIds = new Dictionary<uint, UnitGossip>();
            foreach (var gossip in Storage.Gossips)
            {
                if (gossip.Value.ObjectType != ObjectType.Unit) continue;
                // no support for entries with multiple gossips (i.e changed by script)
                if (gossipIds.ContainsKey(gossip.Value.ObjectEntry)) continue;

                UnitGossip a;
                a.GossipId = gossip.Key.Item1;
                gossipIds.Add(gossip.Value.ObjectEntry, a);
            }

            var entries = gossipIds.Keys.ToList();
            var gossipIdsDb = SQLDatabase.GetDict<uint, UnitGossip>(entries);
            var result = SQLUtil.CompareDicts(gossipIds, gossipIdsDb, StoreNameType.Unit);

            // `gossip`
            if (SQLConnector.Enabled)
            {
                var query = new StringBuilder("SELECT `entry`,`text_id` FROM `world`.`gossip_menu` WHERE ");
                foreach (Tuple<uint, uint> gossip in Storage.Gossips.Keys)
                {
                    query.Append("(`entry`=").Append(gossip.Item1).Append(" AND ");
                    query.Append("`text_id`=").Append(gossip.Item2).Append(") OR ");
                }
                query.Remove(query.Length - 4, 4).Append(";");

                var rows = new List<QueryBuilder.SQLInsertRow>();
                using (var reader = SQLConnector.ExecuteQuery(query.ToString()))
                {
                    if (reader != null)
                        while (reader.Read())
                        {
                            var values = new object[2];
                            var count = reader.GetValues(values);
                            if (count != 2)
                                break; // error in query

                            var entry = Convert.ToUInt32(values[0]);
                            var textId = Convert.ToUInt32(values[1]);

                            // our table is small, 2 fields and both are PKs; no need for updates
                            if (!Storage.Gossips.ContainsKey(Tuple.Create(entry, textId)))
                            {
                                var row = new QueryBuilder.SQLInsertRow();
                                row.AddValue("entry", entry);
                                row.AddValue("text_id", textId);
                                row.Comment = StoreGetters.GetName(StoreNameType.Unit, // BUG: GOs can send gossips too
                                                                   (int) entry, false);
                                rows.Add(row);
                            }
                        }
                }
                result += new QueryBuilder.SQLInsert("gossip_menu", rows, 2).Build();
            }
            else
            {
                var rows = new List<QueryBuilder.SQLInsertRow>();
                foreach (var gossip in Storage.Gossips)
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("entry", gossip.Key.Item1);
                    row.AddValue("text_id", gossip.Key.Item2);
                    row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.ObjectType),
                                                       (int) gossip.Value.ObjectEntry, false);

                    rows.Add(row);
                }

                result += new QueryBuilder.SQLInsert("gossip_menu", rows, 2).Build();
            }

            // `gossip_menu_option`
            if (SQLConnector.Enabled)
            {
                var rowsIns = new List<QueryBuilder.SQLInsertRow>();
                var rowsUpd = new List<QueryBuilder.SQLUpdateRow>();

                foreach (var gossip in Storage.Gossips)
                {
                    if (gossip.Value.GossipOptions == null) continue;
                    foreach (var gossipOption in gossip.Value.GossipOptions)
                    {
                        var query =       //         0     1       2         3         4        5         6
                            string.Format("SELECT menu_id,id,option_icon,box_coded,box_money,box_text,option_text " +
                                          "FROM world.gossip_menu_option WHERE menu_id={0} AND id={1};", gossip.Key.Item1,
                                          gossipOption.Index);
                        using (var reader = SQLConnector.ExecuteQuery(query))
                        {
                            if (reader.HasRows) // possible update
                            {
                                while (reader.Read())
                                {
                                    var row = new QueryBuilder.SQLUpdateRow();

                                    if (!Utilities.EqualValues(reader.GetValue(2), gossipOption.OptionIcon))
                                        row.AddValue("option_icon", gossipOption.OptionIcon);

                                    if (!Utilities.EqualValues(reader.GetValue(3), gossipOption.Box))
                                        row.AddValue("box_coded", gossipOption.Box);

                                    if (!Utilities.EqualValues(reader.GetValue(4), gossipOption.RequiredMoney))
                                        row.AddValue("box_money", gossipOption.RequiredMoney);

                                    if (!Utilities.EqualValues(reader.GetValue(5), gossipOption.BoxText))
                                        row.AddValue("box_text", gossipOption.BoxText);

                                    if (!Utilities.EqualValues(reader.GetValue(6), gossipOption.OptionText))
                                        row.AddValue("option_text", gossipOption.OptionText);

                                    row.AddWhere("menu_id", gossip.Key.Item1);
                                    row.AddWhere("id", gossipOption.Index);

                                    row.Comment =
                                        StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.ObjectType),
                                                             (int) gossip.Value.ObjectEntry, false);

                                    row.Table = "gossip_menu_option";

                                    if (row.ValueCount != 0)
                                        rowsUpd.Add(row);
                                }
                            }
                            else // insert
                            {
                                var row = new QueryBuilder.SQLInsertRow();

                                row.AddValue("menu_id", gossip.Key.Item1);
                                row.AddValue("id", gossipOption.Index);
                                row.AddValue("option_icon", gossipOption.OptionIcon);
                                row.AddValue("option_text", gossipOption.OptionText);
                                row.AddValue("box_coded", gossipOption.Box);
                                row.AddValue("box_money", gossipOption.RequiredMoney);
                                row.AddValue("box_text", gossipOption.BoxText);

                                row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.ObjectType),
                                                           (int)gossip.Value.ObjectEntry, false);

                                rowsIns.Add(row);
                            }
                        }
                    }
                }
                result += new QueryBuilder.SQLInsert("gossip_menu_option", rowsIns, 2).Build() +
                          new QueryBuilder.SQLUpdate(rowsUpd).Build();
            }
            else
            {
                var rows = new List<QueryBuilder.SQLInsertRow>();
                foreach (var gossip in Storage.Gossips)
                {
                    if (gossip.Value.GossipOptions != null)
                        foreach (var gossipOption in gossip.Value.GossipOptions)
                        {
                            var row = new QueryBuilder.SQLInsertRow();

                            row.AddValue("menu_id", gossip.Key.Item1);
                            row.AddValue("id", gossipOption.Index);
                            row.AddValue("option_icon", gossipOption.OptionIcon);
                            row.AddValue("option_text", gossipOption.OptionText);
                            row.AddValue("box_coded", gossipOption.Box);
                            row.AddValue("box_money", gossipOption.RequiredMoney);
                            row.AddValue("box_text", gossipOption.BoxText);

                            row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.ObjectType),
                                                       (int) gossip.Value.ObjectEntry, false);

                            rows.Add(row);
                        }
                }

                result += new QueryBuilder.SQLInsert("gossip_menu_option", rows, 2).Build();
            }

            return result;
        }
Ejemplo n.º 16
0
        public static string ModelData(Dictionary<Guid, Unit> units)
        {
            if (units.Count == 0)
                return string.Empty;

            const string tableName = "creature_model_info";

            // Build a dictionary with model data; model is the key
            var models = new SortedDictionary<uint, Tuple<float, float, Gender>>();
            foreach (var unit in units)
            {
                var npc = unit.Value;

                if (npc.Model == null)
                    continue;
                var model = (uint)npc.Model;

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

                var boundingRadius = 0.0f;
                if (npc.BoundingRadius != null)
                    boundingRadius = (float)npc.BoundingRadius;

                var combatReach = 0.0f;
                if (npc.CombatReach != null)
                    combatReach = (float)npc.CombatReach;

                var gender = Gender.None;
                if (npc.Gender != null)
                    gender = (Gender)npc.Gender;

                models.Add(model, Tuple.Create(boundingRadius, combatReach, gender));
            }

            Dictionary<uint, dynamic> modelsDb = null;
            if (SQLConnector.Enabled)
            {
                modelsDb = SQLDatabase.GetDict<uint>(string.Format(
                    "SELECT `modelid`, `bounding_radius`, `combat_reach`," +
                    "`gender` FROM `{0}`.{1} WHERE `modelid` IN ({2});", Settings.TDBDatabase, tableName, String.Join(",", models.Keys)));
            }

            var rowsUpd = new List<QueryBuilder.SQLUpdateRow>();
            var rowsIns = new List<QueryBuilder.SQLInsertRow>();
            foreach (var model in models)
            {
                if (modelsDb != null && modelsDb.Count != 0)
                {
                    if (modelsDb.ContainsKey(model.Key)) // possible update
                    {
                        var row = new QueryBuilder.SQLUpdateRow();

                        if (!Utilities.EqualValues(modelsDb[model.Key].Item1, model.Value.Item1))
                            row.AddValue("bounding_radius", model.Value.Item1);

                        if (!Utilities.EqualValues(modelsDb[model.Key].Item2, model.Value.Item2))
                            row.AddValue("combat_reach", model.Value.Item2);

                        if (!Utilities.EqualValues(modelsDb[model.Key].Item3, model.Value.Item3))
                            row.AddValue("gender", model.Value.Item3);

                        row.AddWhere("entry", model.Key);
                        row.Table = tableName;

                        if (row.ValueCount != 0)
                            rowsUpd.Add(row);
                    }
                    else // insert new
                    {
                        var row = new QueryBuilder.SQLInsertRow();
                        row.AddValue("entry", model.Key);
                        row.AddValue("bounding_radius", model.Value.Item1);
                        row.AddValue("combat_reach", model.Value.Item2);
                        row.AddValue("gender", model.Value.Item3);
                        rowsIns.Add(row);
                    }
                }
                else // no db values, simply do inserts
                {
                    var row = new QueryBuilder.SQLInsertRow();
                    row.AddValue("entry", model.Key);
                    row.AddValue("bounding_radius", model.Value.Item1);
                    row.AddValue("combat_reach", model.Value.Item2);
                    row.AddValue("gender", model.Value.Item3);
                    rowsIns.Add(row);
                }
            }

            return new QueryBuilder.SQLInsert(tableName, rowsIns).Build() +
                   new QueryBuilder.SQLUpdate(rowsUpd).Build();
        }
Ejemplo n.º 17
0
        public static string Gossip()
        {
            // TODO: This should be rewritten

            if (Storage.Gossips.IsEmpty())
                return string.Empty;

            var result = "";

            // `gossip`
            if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gossip_menu))
            {
                if (SQLConnector.Enabled)
                {
                    var query =
                        new StringBuilder(string.Format("SELECT `entry`,`text_id` FROM {0}.`gossip_menu` WHERE ",
                                                        Settings.TDBDatabase));
                    foreach (Tuple<uint, uint> gossip in Storage.Gossips.Keys())
                    {
                        query.Append("(`entry`=").Append(gossip.Item1).Append(" AND ");
                        query.Append("`text_id`=").Append(gossip.Item2).Append(") OR ");
                    }
                    query.Remove(query.Length - 4, 4).Append(";");

                    var rows = new List<QueryBuilder.SQLInsertRow>();
                    using (var reader = SQLConnector.ExecuteQuery(query.ToString()))
                    {
                        if (reader != null)
                            while (reader.Read())
                            {
                                var values = new object[2];
                                var count = reader.GetValues(values);
                                if (count != 2)
                                    break; // error in query

                                var entry = Convert.ToUInt32(values[0]);
                                var textId = Convert.ToUInt32(values[1]);

                                // our table is small, 2 fields and both are PKs; no need for updates
                                if (!Storage.Gossips.ContainsKey(Tuple.Create(entry, textId)))
                                {
                                    var row = new QueryBuilder.SQLInsertRow();
                                    row.AddValue("entry", entry);
                                    row.AddValue("text_id", textId);
                                    row.Comment = StoreGetters.GetName(StoreNameType.Unit,
                                                                       // BUG: GOs can send gossips too
                                                                       (int) entry, false);
                                    rows.Add(row);
                                }
                            }
                    }
                    result += new QueryBuilder.SQLInsert("gossip_menu", rows, 2).Build();
                }
                else
                {
                    var rows = new List<QueryBuilder.SQLInsertRow>();
                    foreach (var gossip in Storage.Gossips)
                    {
                        var row = new QueryBuilder.SQLInsertRow();

                        row.AddValue("entry", gossip.Key.Item1);
                        row.AddValue("text_id", gossip.Key.Item2);
                        row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                           (int) gossip.Value.Item1.ObjectEntry, false);

                        rows.Add(row);
                    }

                    result += new QueryBuilder.SQLInsert("gossip_menu", rows, 2).Build();
                }
            }

            // `gossip_menu_option`
            if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gossip_menu_option))
            {
                if (SQLConnector.Enabled)
                {
                    var rowsIns = new List<QueryBuilder.SQLInsertRow>();
                    var rowsUpd = new List<QueryBuilder.SQLUpdateRow>();

                    foreach (var gossip in Storage.Gossips)
                    {
                        if (gossip.Value.Item1.GossipOptions == null)
                            continue;

                        foreach (var gossipOption in gossip.Value.Item1.GossipOptions)
                        {
                            var query = //         0     1       2         3         4        5         6
                                string.Format(
                                    "SELECT menu_id,id,option_icon,box_coded,box_money,box_text,option_text " +
                                    "FROM {2}.gossip_menu_option WHERE menu_id={0} AND id={1};", gossip.Key.Item1,
                                    gossipOption.Index, Settings.TDBDatabase);

                            using (var reader = SQLConnector.ExecuteQuery(query))
                            {
                                if (reader.HasRows) // possible update
                                {
                                    while (reader.Read())
                                    {
                                        var row = new QueryBuilder.SQLUpdateRow();

                                        if (!Utilities.EqualValues(reader.GetValue(2), gossipOption.OptionIcon))
                                            row.AddValue("option_icon", gossipOption.OptionIcon);

                                        if (!Utilities.EqualValues(reader.GetValue(3), gossipOption.Box))
                                            row.AddValue("box_coded", gossipOption.Box);

                                        if (!Utilities.EqualValues(reader.GetValue(4), gossipOption.RequiredMoney))
                                            row.AddValue("box_money", gossipOption.RequiredMoney);

                                        if (!Utilities.EqualValues(reader.GetValue(5), gossipOption.BoxText))
                                            row.AddValue("box_text", gossipOption.BoxText);

                                        if (!Utilities.EqualValues(reader.GetValue(6), gossipOption.OptionText))
                                            row.AddValue("option_text", gossipOption.OptionText);

                                        row.AddWhere("menu_id", gossip.Key.Item1);
                                        row.AddWhere("id", gossipOption.Index);

                                        row.Comment =
                                            StoreGetters.GetName(
                                                Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                (int) gossip.Value.Item1.ObjectEntry, false);

                                        row.Table = "gossip_menu_option";

                                        if (row.ValueCount != 0)
                                            rowsUpd.Add(row);
                                    }
                                }
                                else // insert
                                {
                                    var row = new QueryBuilder.SQLInsertRow();

                                    row.AddValue("menu_id", gossip.Key.Item1);
                                    row.AddValue("id", gossipOption.Index);
                                    row.AddValue("option_icon", gossipOption.OptionIcon);
                                    row.AddValue("option_text", gossipOption.OptionText);
                                    row.AddValue("box_coded", gossipOption.Box);
                                    row.AddValue("box_money", gossipOption.RequiredMoney);
                                    row.AddValue("box_text", gossipOption.BoxText);

                                    row.Comment =
                                        StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                             (int) gossip.Value.Item1.ObjectEntry, false);

                                    rowsIns.Add(row);
                                }
                            }
                        }
                    }
                    result += new QueryBuilder.SQLInsert("gossip_menu_option", rowsIns, 2).Build() +
                              new QueryBuilder.SQLUpdate(rowsUpd).Build();
                }
                else
                {
                    var rows = new List<QueryBuilder.SQLInsertRow>();
                    foreach (var gossip in Storage.Gossips)
                    {
                        if (gossip.Value.Item1.GossipOptions != null)
                            foreach (var gossipOption in gossip.Value.Item1.GossipOptions)
                            {
                                var row = new QueryBuilder.SQLInsertRow();

                                row.AddValue("menu_id", gossip.Key.Item1);
                                row.AddValue("id", gossipOption.Index);
                                row.AddValue("option_icon", gossipOption.OptionIcon);
                                row.AddValue("option_text", gossipOption.OptionText);
                                row.AddValue("box_coded", gossipOption.Box);
                                row.AddValue("box_money", gossipOption.RequiredMoney);
                                row.AddValue("box_text", gossipOption.BoxText);

                                row.Comment =
                                    StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                         (int) gossip.Value.Item1.ObjectEntry, false);

                                rows.Add(row);
                            }
                    }

                    result += new QueryBuilder.SQLInsert("gossip_menu_option", rows, 2).Build();
                }
            }

            return result;
        }
Ejemplo n.º 18
0
        public static string QuestObjective()
        {
            var result = "";
            if (Storage.QuestObjectives.IsEmpty())
                return String.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.quest_template))
                return String.Empty;

            var entries = Storage.QuestObjectives.Keys();
            var templatesDb = SQLDatabase.GetDict<uint, QuestInfoObjective>(entries, "Id");

            result += SQLUtil.CompareDicts(Storage.QuestObjectives, templatesDb, StoreNameType.QuestObjective, "Id");

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

            foreach (var questObjectives in Storage.QuestObjectives)
            {
                foreach (var visualEffectIds in questObjectives.Value.Item1.VisualEffectIds)
                {
                    if (SQLConnector.Enabled)
                    {
                        var query = string.Format("SELECT `VisualEffect`, `VerifiedBuild` FROM {0}.quest_visual_effect WHERE `Id`={1} AND `Index`={2};",
                            Settings.TDBDatabase, questObjectives.Key, visualEffectIds.Index);

                        using (var reader = SQLConnector.ExecuteQuery(query))
                        {
                            if (reader.HasRows) // possible update
                            {
                                while (reader.Read())
                                {
                                    var row = new QueryBuilder.SQLUpdateRow();

                                    if (!Utilities.EqualValues(reader.GetValue(0), visualEffectIds.VisualEffect))
                                        row.AddValue("VisualEffect", visualEffectIds.VisualEffect);

                                    if (!Utilities.EqualValues(reader.GetValue(1), questObjectives.Value.Item1.VerifiedBuild))
                                        row.AddValue("VerifiedBuild", questObjectives.Value.Item1.VerifiedBuild);

                                    row.AddWhere("Id", questObjectives.Key);
                                    row.AddWhere("Index", visualEffectIds.Index);

                                    row.Table = "quest_visual_effect";

                                    if (row.ValueCount != 0)
                                        rowsUpd.Add(row);
                                }
                            }
                            else // insert
                            {
                                var row = new QueryBuilder.SQLInsertRow();

                                row.AddValue("Id", questObjectives.Key);
                                row.AddValue("Index", visualEffectIds.Index);
                                row.AddValue("VisualEffect", visualEffectIds.VisualEffect);
                                row.AddValue("VerifiedBuild", questObjectives.Value.Item1.VerifiedBuild);

                                rowsIns.Add(row);
                            }
                        }
                    }
                    else // insert
                    {
                        var row = new QueryBuilder.SQLInsertRow();

                        row.AddValue("Id", questObjectives.Key);
                        row.AddValue("Index", visualEffectIds.Index);
                        row.AddValue("VisualEffect", visualEffectIds.VisualEffect);
                        row.AddValue("VerifiedBuild", questObjectives.Value.Item1.VerifiedBuild);

                        rowsIns.Add(row);
                    }
                }
             }

            result += new QueryBuilder.SQLInsert("quest_visual_effect", rowsIns, 2).Build() + new QueryBuilder.SQLUpdate(rowsUpd).Build();

            return result;
        }
Ejemplo n.º 19
0
        public static string PointsOfInterest()
        {
            if (Storage.GossipPOIs.IsEmpty())
                return string.Empty;

            var result = string.Empty;

            if (!Storage.GossipSelects.IsEmpty() && Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gossip_menu_option))
            {
                var gossipPOIsTable = new Dictionary<Tuple<uint, uint>, uint>();

                foreach (var poi in Storage.GossipPOIs)
                {
                    foreach (var gossipSelect in Storage.GossipSelects)
                    {
                        var tuple = Tuple.Create(gossipSelect.Key.Item1, gossipSelect.Key.Item2);

                        if (gossipPOIsTable.ContainsKey(tuple))
                            continue;

                        var timeSpan = poi.Value.Item2 - gossipSelect.Value.Item2;
                        if (timeSpan != null && timeSpan.Value.Duration() <= TimeSpan.FromSeconds(1))
                            gossipPOIsTable.Add(tuple, poi.Key);
                    }
                }

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

                foreach (var u in gossipPOIsTable)
                {
                    var row = new QueryBuilder.SQLUpdateRow();

                    row.AddValue("action_poi_id", u.Value);

                    row.AddWhere("menu_id", u.Key.Item1);
                    row.AddWhere("id", u.Key.Item2);

                    row.Table = "gossip_menu_option";

                    rowsUpd.Add(row);
                }

                result += new QueryBuilder.SQLUpdate(rowsUpd).Build();
            }

            if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.points_of_interest))
            {
                const string tableName = "points_of_interest";
                var rowsIns = new List<QueryBuilder.SQLInsertRow>();

                uint count = 0;

                foreach (var poi in Storage.GossipPOIs)
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("ID", "@ID+" + count, noQuotes: true);
                    row.AddValue("PositionX", poi.Value.Item1.PositionX);
                    row.AddValue("PositionY", poi.Value.Item1.PositionY);
                    row.AddValue("Icon", poi.Value.Item1.Icon);
                    row.AddValue("Flags", poi.Value.Item1.Flags);
                    row.AddValue("Importance", poi.Value.Item1.Importance);
                    row.AddValue("Name", poi.Value.Item1.Name);

                    rowsIns.Add(row);
                    count++;
                }

                result += new QueryBuilder.SQLDelete(Tuple.Create("@ID+0", "@ID+" + (count - 1)), "entry", tableName).Build();
                result += new QueryBuilder.SQLInsert(tableName, rowsIns, withDelete: false).Build();
            }

            return result;
        }
Ejemplo n.º 20
0
        public static string CreatureDifficulty()
        {
            if (Storage.CreatureDifficultys.IsEmpty())
                return String.Empty;

            if (!Settings.HotfixSQLOutputFlag.HasAnyFlagBit(HotfixSQLOutput.creature_difficulty))
                return String.Empty;

            var rowsIns = new List<QueryBuilder.SQLInsertRow>();
            var rowsUpd = new List<QueryBuilder.SQLUpdateRow>();
            foreach (var creature in Storage.CreatureDifficultys)
            {
                if (SQLDatabase.CreatureDifficultyStores != null)
                {
                    if (SQLDatabase.CreatureDifficultyStores.ContainsKey(creature.Key))
                    {
                        foreach (var creatureDiff in SQLDatabase.CreatureDifficultyStores)
                        {
                            var row = new QueryBuilder.SQLUpdateRow();

                            if (!Utilities.EqualValues(creature.Key, creatureDiff.Key))
                                continue;

                            if (!Utilities.EqualValues(creatureDiff.Value.CreatureID, creature.Value.Item1.CreatureID))
                                row.AddValue("CreatureID", creature.Value.Item1.CreatureID);

                            if (!Utilities.EqualValues(creatureDiff.Value.FactionID, creature.Value.Item1.FactionID))
                                row.AddValue("FactionID", creature.Value.Item1.FactionID);

                            if (!Utilities.EqualValues(creatureDiff.Value.Expansion, creature.Value.Item1.Expansion))
                                row.AddValue("Expansion", creature.Value.Item1.Expansion);

                            if (!Utilities.EqualValues(creatureDiff.Value.MinLevel, creature.Value.Item1.MinLevel))
                                row.AddValue("MinLevel", creature.Value.Item1.MinLevel);

                            if (!Utilities.EqualValues(creatureDiff.Value.MaxLevel, creature.Value.Item1.MaxLevel))
                                row.AddValue("MaxLevel", creature.Value.Item1.MaxLevel);

                            for (int i = 0; i < 5; i++)
                                if (!Utilities.EqualValues(creatureDiff.Value.Flags[i], creature.Value.Item1.Flags[i]))
                                    row.AddValue("Flags" + (i + 1), creature.Value.Item1.Flags[i]);

                            if (!Utilities.EqualValues(creatureDiff.Value.VerifiedBuild, creature.Value.Item1.VerifiedBuild))
                                row.AddValue("VerifiedBuild", creature.Value.Item1.VerifiedBuild);

                            row.AddWhere("Id", creature.Key);

                            row.Table = "creature_difficulty";

                            if (row.ValueCount != 0)
                                rowsUpd.Add(row);
                        }
                    }
                    else // insert
                    {
                        var row = new QueryBuilder.SQLInsertRow();

                        row.AddValue("ID", creature.Key);
                        row.AddValue("CreatureID", creature.Value.Item1.CreatureID);

                        row.AddValue("FactionID", creature.Value.Item1.FactionID);
                        row.AddValue("Expansion", creature.Value.Item1.Expansion);

                        row.AddValue("MinLevel", creature.Value.Item1.MinLevel);
                        row.AddValue("MaxLevel", creature.Value.Item1.MaxLevel);

                        for (int i = 0; i < 5; i++)
                            row.AddValue("Flags" + (i + 1), creature.Value.Item1.Flags[i]);

                        row.AddValue("VerifiedBuild", creature.Value.Item1.VerifiedBuild);

                        rowsIns.Add(row);
                    }
                }
                else // insert
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("ID", creature.Key);
                    row.AddValue("CreatureID", creature.Value.Item1.CreatureID);

                    row.AddValue("FactionID", creature.Value.Item1.FactionID);
                    row.AddValue("Expansion", creature.Value.Item1.Expansion);

                    row.AddValue("MinLevel", creature.Value.Item1.MinLevel);
                    row.AddValue("MaxLevel", creature.Value.Item1.MaxLevel);

                    for (int i = 0; i < 5; i++)
                        row.AddValue("Flags" + (i + 1), creature.Value.Item1.Flags[i]);

                    row.AddValue("VerifiedBuild", creature.Value.Item1.VerifiedBuild);

                    rowsIns.Add(row);
                }
            }

            return new QueryBuilder.SQLInsert("creature_difficulty", rowsIns).Build() +
                new QueryBuilder.SQLUpdate(rowsUpd).Build();
        }
Ejemplo n.º 21
0
        public static string Gossip()
        {
            // TODO: This should be rewritten

            if (Storage.Gossips.IsEmpty())
            {
                return(string.Empty);
            }

            var result = "";

            // `gossip`
            if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gossip_menu))
            {
                if (SQLConnector.Enabled)
                {
                    var query =
                        new StringBuilder(string.Format("SELECT `entry`,`text_id` FROM {0}.`gossip_menu` WHERE ",
                                                        Settings.TDBDatabase));
                    foreach (Tuple <uint, uint> gossip in Storage.Gossips.Keys())
                    {
                        query.Append("(`entry`=").Append(gossip.Item1).Append(" AND ");
                        query.Append("`text_id`=").Append(gossip.Item2).Append(") OR ");
                    }
                    query.Remove(query.Length - 4, 4).Append(";");

                    var rows = new List <QueryBuilder.SQLInsertRow>();
                    using (var reader = SQLConnector.ExecuteQuery(query.ToString()))
                    {
                        if (reader != null)
                        {
                            while (reader.Read())
                            {
                                var values = new object[2];
                                var count  = reader.GetValues(values);
                                if (count != 2)
                                {
                                    break; // error in query
                                }
                                var entry  = Convert.ToUInt32(values[0]);
                                var textId = Convert.ToUInt32(values[1]);

                                // our table is small, 2 fields and both are PKs; no need for updates
                                if (!Storage.Gossips.ContainsKey(Tuple.Create(entry, textId)))
                                {
                                    var row = new QueryBuilder.SQLInsertRow();
                                    row.AddValue("entry", entry);
                                    row.AddValue("text_id", textId);
                                    row.Comment = StoreGetters.GetName(StoreNameType.Unit,
                                                                       // BUG: GOs can send gossips too
                                                                       (int)entry, false);
                                    rows.Add(row);
                                }
                            }
                        }
                    }
                    result += new QueryBuilder.SQLInsert("gossip_menu", rows, 2).Build();
                }
                else
                {
                    var rows = new List <QueryBuilder.SQLInsertRow>();
                    foreach (var gossip in Storage.Gossips)
                    {
                        var row = new QueryBuilder.SQLInsertRow();

                        row.AddValue("entry", gossip.Key.Item1);
                        row.AddValue("text_id", gossip.Key.Item2);
                        row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                           (int)gossip.Value.Item1.ObjectEntry, false);

                        rows.Add(row);
                    }

                    result += new QueryBuilder.SQLInsert("gossip_menu", rows, 2).Build();
                }
            }

            // `gossip_menu_option`
            if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gossip_menu_option))
            {
                if (SQLConnector.Enabled)
                {
                    var rowsIns = new List <QueryBuilder.SQLInsertRow>();
                    var rowsUpd = new List <QueryBuilder.SQLUpdateRow>();

                    foreach (var gossip in Storage.Gossips)
                    {
                        if (gossip.Value.Item1.GossipOptions == null)
                        {
                            continue;
                        }
                        foreach (var gossipOption in gossip.Value.Item1.GossipOptions)
                        {
                            var query = //         0     1       2         3         4        5         6
                                        string.Format(
                                "SELECT menu_id,id,option_icon,box_coded,box_money,box_text,option_text " +
                                "FROM {2}.gossip_menu_option WHERE menu_id={0} AND id={1};", gossip.Key.Item1,
                                gossipOption.Index, Settings.TDBDatabase);
                            using (var reader = SQLConnector.ExecuteQuery(query))
                            {
                                if (reader.HasRows) // possible update
                                {
                                    while (reader.Read())
                                    {
                                        var row = new QueryBuilder.SQLUpdateRow();

                                        if (!Utilities.EqualValues(reader.GetValue(2), gossipOption.OptionIcon))
                                        {
                                            row.AddValue("option_icon", gossipOption.OptionIcon);
                                        }

                                        if (!Utilities.EqualValues(reader.GetValue(3), gossipOption.Box))
                                        {
                                            row.AddValue("box_coded", gossipOption.Box);
                                        }

                                        if (!Utilities.EqualValues(reader.GetValue(4), gossipOption.RequiredMoney))
                                        {
                                            row.AddValue("box_money", gossipOption.RequiredMoney);
                                        }

                                        if (!Utilities.EqualValues(reader.GetValue(5), gossipOption.BoxText))
                                        {
                                            row.AddValue("box_text", gossipOption.BoxText);
                                        }

                                        if (!Utilities.EqualValues(reader.GetValue(6), gossipOption.OptionText))
                                        {
                                            row.AddValue("option_text", gossipOption.OptionText);
                                        }

                                        row.AddWhere("menu_id", gossip.Key.Item1);
                                        row.AddWhere("id", gossipOption.Index);

                                        row.Comment =
                                            StoreGetters.GetName(
                                                Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                (int)gossip.Value.Item1.ObjectEntry, false);

                                        row.Table = "gossip_menu_option";

                                        if (row.ValueCount != 0)
                                        {
                                            rowsUpd.Add(row);
                                        }
                                    }
                                }
                                else // insert
                                {
                                    var row = new QueryBuilder.SQLInsertRow();

                                    row.AddValue("menu_id", gossip.Key.Item1);
                                    row.AddValue("id", gossipOption.Index);
                                    row.AddValue("option_icon", gossipOption.OptionIcon);
                                    row.AddValue("option_text", gossipOption.OptionText);
                                    row.AddValue("box_coded", gossipOption.Box);
                                    row.AddValue("box_money", gossipOption.RequiredMoney);
                                    row.AddValue("box_text", gossipOption.BoxText);

                                    row.Comment =
                                        StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                             (int)gossip.Value.Item1.ObjectEntry, false);

                                    rowsIns.Add(row);
                                }
                            }
                        }
                    }
                    result += new QueryBuilder.SQLInsert("gossip_menu_option", rowsIns, 2).Build() +
                              new QueryBuilder.SQLUpdate(rowsUpd).Build();
                }
                else
                {
                    var rows = new List <QueryBuilder.SQLInsertRow>();
                    foreach (var gossip in Storage.Gossips)
                    {
                        if (gossip.Value.Item1.GossipOptions != null)
                        {
                            foreach (var gossipOption in gossip.Value.Item1.GossipOptions)
                            {
                                var row = new QueryBuilder.SQLInsertRow();

                                row.AddValue("menu_id", gossip.Key.Item1);
                                row.AddValue("id", gossipOption.Index);
                                row.AddValue("option_icon", gossipOption.OptionIcon);
                                row.AddValue("option_text", gossipOption.OptionText);
                                row.AddValue("box_coded", gossipOption.Box);
                                row.AddValue("box_money", gossipOption.RequiredMoney);
                                row.AddValue("box_text", gossipOption.BoxText);

                                row.Comment =
                                    StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.Item1.ObjectType),
                                                         (int)gossip.Value.Item1.ObjectEntry, false);

                                rows.Add(row);
                            }
                        }
                    }

                    result += new QueryBuilder.SQLInsert("gossip_menu_option", rows, 2).Build();
                }
            }

            return(result);
        }
Ejemplo n.º 22
0
        public static string LocalesQuestObjectives()
        {
            if (Storage.LocalesQuestObjectives.IsEmpty())
                return String.Empty;

            if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.locales_quest_objectives))
                return String.Empty;

            const string tableName = "quest_objectives_locale";

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

            foreach (var localesQuestObjective in Settings.SQLOrderByKey ? Storage.LocalesQuestObjectives.OrderBy(blub => blub.Key).ToList() : Storage.LocalesQuestObjectives.ToList())
            {
                if (SQLDatabase.LocalesQuestObjectiveStores != null && SQLDatabase.LocalesQuestObjectiveStores.ContainsKey(Tuple.Create(localesQuestObjective.Key.Item1, localesQuestObjective.Key.Item2)))
                {
                    var row = new QueryBuilder.SQLUpdateRow();
                    var localesQuestObjectiveDB = SQLDatabase.LocalesQuestObjectiveStores[Tuple.Create(localesQuestObjective.Key.Item1, localesQuestObjective.Key.Item2)];

                    if (!Utilities.EqualValues(localesQuestObjectiveDB.QuestId, localesQuestObjective.Value.Item1.QuestId))
                        row.AddValue("QuestId", localesQuestObjective.Value.Item1.QuestId);

                    if (!Utilities.EqualValues(localesQuestObjectiveDB.StorageIndex, localesQuestObjective.Value.Item1.StorageIndex))
                        row.AddValue("StorageIndex", localesQuestObjective.Value.Item1.StorageIndex);

                    if (!Utilities.EqualValues(localesQuestObjectiveDB.Description, localesQuestObjective.Value.Item1.Description))
                        row.AddValue("Description", localesQuestObjective.Value.Item1.Description);

                    if (!Utilities.EqualValues(localesQuestObjectiveDB.VerifiedBuild, localesQuestObjective.Value.Item1.VerifiedBuild))
                        row.AddValue("VerifiedBuild", localesQuestObjective.Value.Item1.VerifiedBuild);

                    row.AddWhere("ID", localesQuestObjective.Key.Item1);
                    row.AddWhere("locale", localesQuestObjective.Key.Item2);

                    row.Table = tableName;

                    rowsUpd.Add(row);
                }
                else // insert new
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("ID", localesQuestObjective.Key.Item1);
                    row.AddValue("locale", localesQuestObjective.Key.Item2);

                    row.AddValue("QuestId", localesQuestObjective.Value.Item1.QuestId);
                    row.AddValue("StorageIndex", localesQuestObjective.Value.Item1.StorageIndex);
                    row.AddValue("Description", localesQuestObjective.Value.Item1.Description);

                    row.AddValue("VerifiedBuild", localesQuestObjective.Value.Item1.VerifiedBuild);

                    rowsIns.Add(row);
                }
            }

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

            return "SET NAMES 'utf8';" + Environment.NewLine + result + Environment.NewLine + "SET NAMES 'latin1';";
        }
Ejemplo n.º 23
0
        public static string CreatureDifficulty()
        {
            if (Storage.CreatureDifficultys.IsEmpty())
            {
                return(String.Empty);
            }

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

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

            foreach (var creature in Storage.CreatureDifficultys)
            {
                if (SQLDatabase.CreatureDifficultyStores != null)
                {
                    if (SQLDatabase.CreatureDifficultyStores.ContainsKey(creature.Key))
                    {
                        foreach (var creatureDiff in SQLDatabase.CreatureDifficultyStores)
                        {
                            var row = new QueryBuilder.SQLUpdateRow();

                            if (!Utilities.EqualValues(creature.Key, creatureDiff.Key))
                            {
                                continue;
                            }

                            if (!Utilities.EqualValues(creatureDiff.Value.CreatureID, creature.Value.Item1.CreatureID))
                            {
                                row.AddValue("CreatureID", creature.Value.Item1.CreatureID);
                            }

                            if (!Utilities.EqualValues(creatureDiff.Value.FactionID, creature.Value.Item1.FactionID))
                            {
                                row.AddValue("FactionID", creature.Value.Item1.FactionID);
                            }

                            if (!Utilities.EqualValues(creatureDiff.Value.Expansion, creature.Value.Item1.Expansion))
                            {
                                row.AddValue("Expansion", creature.Value.Item1.Expansion);
                            }

                            if (!Utilities.EqualValues(creatureDiff.Value.MinLevel, creature.Value.Item1.MinLevel))
                            {
                                row.AddValue("MinLevel", creature.Value.Item1.MinLevel);
                            }

                            if (!Utilities.EqualValues(creatureDiff.Value.MaxLevel, creature.Value.Item1.MaxLevel))
                            {
                                row.AddValue("MaxLevel", creature.Value.Item1.MaxLevel);
                            }

                            for (int i = 0; i < 5; i++)
                            {
                                if (!Utilities.EqualValues(creatureDiff.Value.Flags[i], creature.Value.Item1.Flags[i]))
                                {
                                    row.AddValue("Flags" + (i + 1), creature.Value.Item1.Flags[i]);
                                }
                            }

                            if (!Utilities.EqualValues(creatureDiff.Value.VerifiedBuild, creature.Value.Item1.VerifiedBuild))
                            {
                                row.AddValue("VerifiedBuild", creature.Value.Item1.VerifiedBuild);
                            }

                            row.AddWhere("Id", creature.Key);

                            row.Table = "creature_difficulty";

                            if (row.ValueCount != 0)
                            {
                                rowsUpd.Add(row);
                            }
                        }
                    }
                    else // insert
                    {
                        var row = new QueryBuilder.SQLInsertRow();

                        row.AddValue("ID", creature.Key);
                        row.AddValue("CreatureID", creature.Value.Item1.CreatureID);

                        row.AddValue("FactionID", creature.Value.Item1.FactionID);
                        row.AddValue("Expansion", creature.Value.Item1.Expansion);

                        row.AddValue("MinLevel", creature.Value.Item1.MinLevel);
                        row.AddValue("MaxLevel", creature.Value.Item1.MaxLevel);

                        for (int i = 0; i < 5; i++)
                        {
                            row.AddValue("Flags" + (i + 1), creature.Value.Item1.Flags[i]);
                        }

                        row.AddValue("VerifiedBuild", creature.Value.Item1.VerifiedBuild);

                        rowsIns.Add(row);
                    }
                }
                else // insert
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("ID", creature.Key);
                    row.AddValue("CreatureID", creature.Value.Item1.CreatureID);

                    row.AddValue("FactionID", creature.Value.Item1.FactionID);
                    row.AddValue("Expansion", creature.Value.Item1.Expansion);

                    row.AddValue("MinLevel", creature.Value.Item1.MinLevel);
                    row.AddValue("MaxLevel", creature.Value.Item1.MaxLevel);

                    for (int i = 0; i < 5; i++)
                    {
                        row.AddValue("Flags" + (i + 1), creature.Value.Item1.Flags[i]);
                    }

                    row.AddValue("VerifiedBuild", creature.Value.Item1.VerifiedBuild);

                    rowsIns.Add(row);
                }
            }

            return(new QueryBuilder.SQLInsert("creature_difficulty", rowsIns).Build() +
                   new QueryBuilder.SQLUpdate(rowsUpd).Build());
        }
Ejemplo n.º 24
0
        public static string Gossip()
        {
            if (Storage.Gossips.IsEmpty)
            {
                return(String.Empty);
            }

            // `creature_template`
            var gossipIds = new Dictionary <uint, UnitGossip>();

            foreach (var gossip in Storage.Gossips)
            {
                if (gossip.Value.ObjectType != ObjectType.Unit)
                {
                    continue;
                }
                // no support for entries with multiple gossips (i.e changed by script)
                if (gossipIds.ContainsKey(gossip.Value.ObjectEntry))
                {
                    continue;
                }

                UnitGossip a;
                a.GossipId = gossip.Key.Item1;
                gossipIds.Add(gossip.Value.ObjectEntry, a);
            }

            var entries     = gossipIds.Keys.ToList();
            var gossipIdsDb = SQLDatabase.GetDict <uint, UnitGossip>(entries);
            var result      = SQLUtil.CompareDicts(gossipIds, gossipIdsDb, StoreNameType.Unit);

            // `gossip`
            if (SQLConnector.Enabled)
            {
                var query = new StringBuilder("SELECT `entry`,`text_id` FROM `world`.`gossip_menu` WHERE ");
                foreach (Tuple <uint, uint> gossip in Storage.Gossips.Keys)
                {
                    query.Append("(`entry`=").Append(gossip.Item1).Append(" AND ");
                    query.Append("`text_id`=").Append(gossip.Item2).Append(") OR ");
                }
                query.Remove(query.Length - 4, 4).Append(";");

                var rows = new List <QueryBuilder.SQLInsertRow>();
                using (var reader = SQLConnector.ExecuteQuery(query.ToString()))
                {
                    if (reader != null)
                    {
                        while (reader.Read())
                        {
                            var values = new object[2];
                            var count  = reader.GetValues(values);
                            if (count != 2)
                            {
                                break; // error in query
                            }
                            var entry  = Convert.ToUInt32(values[0]);
                            var textId = Convert.ToUInt32(values[1]);

                            // our table is small, 2 fields and both are PKs; no need for updates
                            if (!Storage.Gossips.ContainsKey(Tuple.Create(entry, textId)))
                            {
                                var row = new QueryBuilder.SQLInsertRow();
                                row.AddValue("entry", entry);
                                row.AddValue("text_id", textId);
                                row.Comment = StoreGetters.GetName(StoreNameType.Unit, // BUG: GOs can send gossips too
                                                                   (int)entry, false);
                                rows.Add(row);
                            }
                        }
                    }
                }
                result += new QueryBuilder.SQLInsert("gossip_menu", rows, 2).Build();
            }
            else
            {
                var rows = new List <QueryBuilder.SQLInsertRow>();
                foreach (var gossip in Storage.Gossips)
                {
                    var row = new QueryBuilder.SQLInsertRow();

                    row.AddValue("entry", gossip.Key.Item1);
                    row.AddValue("text_id", gossip.Key.Item2);
                    row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.ObjectType),
                                                       (int)gossip.Value.ObjectEntry, false);

                    rows.Add(row);
                }

                result += new QueryBuilder.SQLInsert("gossip_menu", rows, 2).Build();
            }

            // `gossip_menu_option`
            if (SQLConnector.Enabled)
            {
                var rowsIns = new List <QueryBuilder.SQLInsertRow>();
                var rowsUpd = new List <QueryBuilder.SQLUpdateRow>();

                foreach (var gossip in Storage.Gossips)
                {
                    if (gossip.Value.GossipOptions == null)
                    {
                        continue;
                    }
                    foreach (var gossipOption in gossip.Value.GossipOptions)
                    {
                        var query =       //         0     1       2         3         4        5         6
                                    string.Format("SELECT menu_id,id,option_icon,box_coded,box_money,box_text,option_text " +
                                                  "FROM world.gossip_menu_option WHERE menu_id={0} AND id={1};", gossip.Key.Item1,
                                                  gossipOption.Index);
                        using (var reader = SQLConnector.ExecuteQuery(query))
                        {
                            if (reader.HasRows) // possible update
                            {
                                while (reader.Read())
                                {
                                    var row = new QueryBuilder.SQLUpdateRow();

                                    if (!Utilities.EqualValues(reader.GetValue(2), gossipOption.OptionIcon))
                                    {
                                        row.AddValue("option_icon", gossipOption.OptionIcon);
                                    }

                                    if (!Utilities.EqualValues(reader.GetValue(3), gossipOption.Box))
                                    {
                                        row.AddValue("box_coded", gossipOption.Box);
                                    }

                                    if (!Utilities.EqualValues(reader.GetValue(4), gossipOption.RequiredMoney))
                                    {
                                        row.AddValue("box_money", gossipOption.RequiredMoney);
                                    }

                                    if (!Utilities.EqualValues(reader.GetValue(5), gossipOption.BoxText))
                                    {
                                        row.AddValue("box_text", gossipOption.BoxText);
                                    }

                                    if (!Utilities.EqualValues(reader.GetValue(6), gossipOption.OptionText))
                                    {
                                        row.AddValue("option_text", gossipOption.OptionText);
                                    }

                                    row.AddWhere("menu_id", gossip.Key.Item1);
                                    row.AddWhere("id", gossipOption.Index);

                                    row.Comment =
                                        StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.ObjectType),
                                                             (int)gossip.Value.ObjectEntry, false);

                                    row.Table = "gossip_menu_option";

                                    if (row.ValueCount != 0)
                                    {
                                        rowsUpd.Add(row);
                                    }
                                }
                            }
                            else // insert
                            {
                                var row = new QueryBuilder.SQLInsertRow();

                                row.AddValue("menu_id", gossip.Key.Item1);
                                row.AddValue("id", gossipOption.Index);
                                row.AddValue("option_icon", gossipOption.OptionIcon);
                                row.AddValue("option_text", gossipOption.OptionText);
                                row.AddValue("box_coded", gossipOption.Box);
                                row.AddValue("box_money", gossipOption.RequiredMoney);
                                row.AddValue("box_text", gossipOption.BoxText);

                                row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.ObjectType),
                                                                   (int)gossip.Value.ObjectEntry, false);

                                rowsIns.Add(row);
                            }
                        }
                    }
                }
                result += new QueryBuilder.SQLInsert("gossip_menu_option", rowsIns, 2).Build() +
                          new QueryBuilder.SQLUpdate(rowsUpd).Build();
            }
            else
            {
                var rows = new List <QueryBuilder.SQLInsertRow>();
                foreach (var gossip in Storage.Gossips)
                {
                    if (gossip.Value.GossipOptions != null)
                    {
                        foreach (var gossipOption in gossip.Value.GossipOptions)
                        {
                            var row = new QueryBuilder.SQLInsertRow();

                            row.AddValue("menu_id", gossip.Key.Item1);
                            row.AddValue("id", gossipOption.Index);
                            row.AddValue("option_icon", gossipOption.OptionIcon);
                            row.AddValue("option_text", gossipOption.OptionText);
                            row.AddValue("box_coded", gossipOption.Box);
                            row.AddValue("box_money", gossipOption.RequiredMoney);
                            row.AddValue("box_text", gossipOption.BoxText);

                            row.Comment = StoreGetters.GetName(Utilities.ObjectTypeToStore(gossip.Value.ObjectType),
                                                               (int)gossip.Value.ObjectEntry, false);

                            rows.Add(row);
                        }
                    }
                }

                result += new QueryBuilder.SQLInsert("gossip_menu_option", rows, 2).Build();
            }

            return(result);
        }