public static string Creature(Dictionary<Guid, Unit> units)
        {
            if (units.Count == 0)
                return string.Empty;

            const string tableName = "creature";

            uint count = 0;
            var rows = new List<QueryBuilder.SQLInsertRow>();
            foreach (var unit in units)
            {
                var row = new QueryBuilder.SQLInsertRow();

                var creature = unit.Value;

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

                var spawnTimeSecs = creature.GetDefaultSpawnTime();
                var movementType = 0; // TODO: Find a way to check if our unit got random movement
                var spawnDist = (movementType == 1) ? 5 : 0;

                row.AddValue("guid", "@GUID+" + count, noQuotes: true);
                row.AddValue("id", unit.Key.GetEntry());
                row.AddValue("map", creature.Map);
                row.AddValue("spawnMask", 1);
                row.AddValue("phaseMask", creature.PhaseMask);
                row.AddValue("position_x", creature.Movement.Position.X);
                row.AddValue("position_y", creature.Movement.Position.Y);
                row.AddValue("position_z", creature.Movement.Position.Z);
                row.AddValue("orientation", creature.Movement.Orientation);
                row.AddValue("spawntimesecs", spawnTimeSecs);
                row.AddValue("spawndist", spawnDist);
                row.AddValue("MovementType", movementType);
                row.Comment = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, creature.Area, false) + ")";

                if (creature.IsTemporarySpawn())
                {
                    row.CommentOut = true;
                    row.Comment += " - !!! might be temporary spawn !!!";
                }
                else
                    ++count;

                rows.Add(row);
            }

            var result = new StringBuilder();
            // delete query for GUIDs
            var delete = new QueryBuilder.SQLDelete(Tuple.Create("@GUID+0", "@GUID+" + count), "guid", tableName);
            result.Append(delete.Build());

            var sql = new QueryBuilder.SQLInsert(tableName, rows, withDelete: false);
            result.Append(sql.Build());
            return result.ToString();
        }
Exemple #2
0
        public static string Creature(Dictionary <WowGuid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

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

            const string tableName      = "creature";
            const string addonTableName = "creature_addon";

            uint count     = 0;
            var  rows      = new List <QueryBuilder.SQLInsertRow>();
            var  addonRows = new List <QueryBuilder.SQLInsertRow>();

            foreach (var unit in units)
            {
                var row          = new QueryBuilder.SQLInsertRow();
                var badTransport = false;

                var creature = unit.Value;

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

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

                UpdateField uf;
                if (!creature.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(ObjectField.OBJECT_FIELD_ENTRY), out uf))
                {
                    continue;   // broken entry, nothing to spawn
                }
                var entry = uf.UInt32Value;

                var movementType = 0;
                var spawnDist    = 0;

                if (creature.Movement.HasWpsOrRandMov)
                {
                    movementType = 1;
                    spawnDist    = 5;
                }


                row.AddValue("guid", "@CGUID+" + count, noQuotes: true);
                row.AddValue("id", entry);
                if (!creature.IsOnTransport())
                {
                    row.AddValue("map", creature.Map);
                }
                else
                {
                    int mapId;
                    badTransport = !GetTransportMap(creature, out mapId);
                    row.AddValue("map", mapId);
                }

                row.AddValue("spawnMask", creature.GetDefaultSpawnMask());
                row.AddValue("phaseMask", creature.PhaseMask);

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_3_4_15595) && creature.Phases != null)
                {
                    row.AddValue("phaseId", string.Join(" - ", creature.Phases));
                }

                if (!creature.IsOnTransport())
                {
                    row.AddValue("position_x", creature.Movement.Position.X);
                    row.AddValue("position_y", creature.Movement.Position.Y);
                    row.AddValue("position_z", creature.Movement.Position.Z);
                    row.AddValue("orientation", creature.Movement.Orientation);
                }
                else
                {
                    row.AddValue("position_x", creature.Movement.TransportOffset.X);
                    row.AddValue("position_y", creature.Movement.TransportOffset.Y);
                    row.AddValue("position_z", creature.Movement.TransportOffset.Z);
                    row.AddValue("orientation", creature.Movement.TransportOffset.O);
                }

                row.AddValue("spawntimesecs", creature.GetDefaultSpawnTime());
                row.AddValue("spawndist", spawnDist);
                row.AddValue("MovementType", movementType);

                row.Comment  = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, creature.Area, false) + ")";


                var auras        = string.Empty;
                var commentAuras = string.Empty;
                if (creature.Auras != null && creature.Auras.Count() != 0)
                {
                    foreach (var aura in creature.Auras)
                    {
                        if (aura == null)
                        {
                            continue;
                        }

                        // usually "template auras" do not have caster
                        if (ClientVersion.AddedInVersion(ClientType.MistsOfPandaria) ? !aura.AuraFlags.HasAnyFlag(AuraFlagMoP.NoCaster) : !aura.AuraFlags.HasAnyFlag(AuraFlag.NotCaster))
                        {
                            continue;
                        }

                        auras        += aura.SpellId + " ";
                        commentAuras += aura.SpellId.ToString() + " - " + StoreGetters.GetName(StoreNameType.Spell, (int)aura.SpellId, false) + ", ";
                    }

                    auras        = auras.TrimEnd(' ');
                    commentAuras = commentAuras.TrimEnd(',', ' ');

                    row.Comment += " (Auras: " + commentAuras + ")";
                }

                var addonRow = new QueryBuilder.SQLInsertRow();
                if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
                {
                    addonRow.AddValue("guid", "@CGUID+" + count, noQuotes: true);
                    addonRow.AddValue("mount", creature.Mount);
                    addonRow.AddValue("bytes1", creature.Bytes1, true);
                    addonRow.AddValue("bytes2", creature.Bytes2, true);
                    addonRow.AddValue("auras", auras);
                    addonRow.Comment += StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                    if (!String.IsNullOrWhiteSpace(auras))
                    {
                        addonRow.Comment += " - " + commentAuras;
                    }
                    addonRows.Add(addonRow);
                }

                if (creature.IsTemporarySpawn())
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! might be temporary spawn !!!";
                }
                else if (creature.IsOnTransport() && badTransport)
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! on transport - transport template not found !!!";
                }
                else
                {
                    ++count;
                }

                if (creature.Movement.HasWpsOrRandMov)
                {
                    row.Comment += " (possible waypoints or random movement)";
                }

                rows.Add(row);
            }

            var result = new StringBuilder();

            if (count > 0)
            {
                // delete query for GUIDs
                var delete = new QueryBuilder.SQLDelete(Tuple.Create("@CGUID+0", "@CGUID+" + --count), "guid", tableName);
                result.Append(delete.Build());
                var sql = new QueryBuilder.SQLInsert(tableName, rows, withDelete: false);
                result.Append(sql.Build());

                if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
                {
                    var addonDelete = new QueryBuilder.SQLDelete(Tuple.Create("@CGUID+0", "@CGUID+" + count), "guid", addonTableName);
                    result.Append(addonDelete.Build());
                    var addonSql = new QueryBuilder.SQLInsert(addonTableName, addonRows, withDelete: false);
                    result.Append(addonSql.Build());
                }
            }

            return(result.ToString());
        }
Exemple #3
0
        public static string GameObject(Dictionary <WowGuid, GameObject> gameObjects)
        {
            if (gameObjects.Count == 0)
            {
                return(string.Empty);
            }

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

            const string tableName = "gameobject";

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

            foreach (var gameobject in gameObjects)
            {
                var row = new QueryBuilder.SQLInsertRow();

                var go = gameobject.Value;

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

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

                uint        animprogress = 0;
                uint        state        = 0;
                UpdateField uf;
                if (!go.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(ObjectField.OBJECT_FIELD_ENTRY), out uf))
                {
                    continue;   // broken entry, nothing to spawn
                }
                var entry        = uf.UInt32Value;
                var badTransport = false;

                if (go.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(GameObjectField.GAMEOBJECT_BYTES_1), out uf))
                {
                    var bytes = uf.UInt32Value;
                    state        = (bytes & 0x000000FF);
                    animprogress = Convert.ToUInt32((bytes & 0xFF000000) >> 24);
                }

                row.AddValue("guid", "@OGUID+" + count, noQuotes: true);
                row.AddValue("id", entry);
                if (!go.IsOnTransport())
                {
                    row.AddValue("map", go.Map);
                }
                else
                {
                    int mapId;
                    badTransport = !GetTransportMap(go, out mapId);
                    row.AddValue("map", mapId);
                }

                row.AddValue("spawnMask", go.GetDefaultSpawnMask());
                row.AddValue("phaseMask", go.PhaseMask);

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_3_4_15595) && go.Phases != null)
                {
                    row.AddValue("phaseId", string.Join(" - ", go.Phases));
                }

                if (!go.IsOnTransport())
                {
                    row.AddValue("position_x", go.Movement.Position.X);
                    row.AddValue("position_y", go.Movement.Position.Y);
                    row.AddValue("position_z", go.Movement.Position.Z);
                    row.AddValue("orientation", go.Movement.Orientation);
                }
                else
                {
                    row.AddValue("position_x", go.Movement.TransportOffset.X);
                    row.AddValue("position_y", go.Movement.TransportOffset.Y);
                    row.AddValue("position_z", go.Movement.TransportOffset.Z);
                    row.AddValue("orientation", go.Movement.TransportOffset.O);
                }

                var rotation = go.GetRotation();
                if (rotation != null && rotation.Length == 4)
                {
                    row.AddValue("rotation0", rotation[0]);
                    row.AddValue("rotation1", rotation[1]);
                    row.AddValue("rotation2", rotation[2]);
                    row.AddValue("rotation3", rotation[3]);
                }
                else
                {
                    row.AddValue("rotation0", 0);
                    row.AddValue("rotation1", 0);
                    row.AddValue("rotation2", 0);
                    row.AddValue("rotation3", 0);
                }

                row.AddValue("spawntimesecs", go.GetDefaultSpawnTime());
                row.AddValue("animprogress", animprogress);
                row.AddValue("state", state);
                row.Comment  = StoreGetters.GetName(StoreNameType.GameObject, (int)gameobject.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, go.Area, false) + ")";

                if (go.IsTemporarySpawn())
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! might be temporary spawn !!!";
                }
                else if (go.IsTransport())
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! transport !!!";
                }
                else if (go.IsOnTransport() && badTransport)
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! on transport - transport template not found !!!";
                }
                else
                {
                    ++count;
                }

                rows.Add(row);
            }

            var result = new StringBuilder();

            if (count > 0)
            {
                // delete query for GUIDs
                var delete = new QueryBuilder.SQLDelete(Tuple.Create("@OGUID+0", "@OGUID+" + --count), "guid", tableName);
                result.Append(delete.Build());
            }

            var sql = new QueryBuilder.SQLInsert(tableName, rows, withDelete: false);

            result.Append(sql.Build());
            return(result.ToString());
        }
Exemple #4
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);
        }
Exemple #5
0
        public static string Creature(Dictionary <Guid, Unit> units)
        {
            if (units.Count == 0)
            {
                return(string.Empty);
            }

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

            const string tableName = "creature";

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

            foreach (var unit in units)
            {
                var row = new QueryBuilder.SQLInsertRow();

                var creature = unit.Value;

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

                UpdateField uf;
                if (!creature.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(ObjectField.OBJECT_FIELD_ENTRY), out uf))
                {
                    continue;   // broken entry, nothing to spawn
                }
                var entry = uf.UInt32Value;

                var spawnTimeSecs = creature.GetDefaultSpawnTime();
                var movementType  = 0; // TODO: Find a way to check if our unit got random movement
                var spawnDist     = (movementType == 1) ? 5 : 0;

                row.AddValue("guid", "@CGUID+" + count, noQuotes: true);
                row.AddValue("id", entry);
                row.AddValue("map", !creature.IsOnTransport() ? creature.Map : 0);  // TODO: query transport template for map
                row.AddValue("spawnMask", 1);
                row.AddValue("phaseMask", creature.PhaseMask);
                if (!creature.IsOnTransport())
                {
                    row.AddValue("position_x", creature.Movement.Position.X);
                    row.AddValue("position_y", creature.Movement.Position.Y);
                    row.AddValue("position_z", creature.Movement.Position.Z);
                    row.AddValue("orientation", creature.Movement.Orientation);
                }
                else
                {
                    row.AddValue("position_x", creature.Movement.TransportOffset.X);
                    row.AddValue("position_y", creature.Movement.TransportOffset.Y);
                    row.AddValue("position_z", creature.Movement.TransportOffset.Z);
                    row.AddValue("orientation", creature.Movement.TransportOffset.O);
                }

                row.AddValue("spawntimesecs", spawnTimeSecs);
                row.AddValue("spawndist", spawnDist);
                row.AddValue("MovementType", movementType);
                row.Comment  = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, creature.Area, false) + ")";

                if (creature.IsTemporarySpawn())
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! might be temporary spawn !!!";
                }
                else if (creature.IsOnTransport())
                {
                    row.CommentOut = true;
                    row.Comment   += " - !!! on transport (NYI) !!!";
                }
                else
                {
                    ++count;
                }

                if (creature.Movement.HasWpsOrRandMov)
                {
                    row.Comment += " (possible waypoints or random movement)";
                }

                rows.Add(row);
            }

            var result = new StringBuilder();
            // delete query for GUIDs
            var delete = new QueryBuilder.SQLDelete(Tuple.Create("@CGUID+0", "@CGUID+" + --count), "guid", tableName);

            result.Append(delete.Build());

            var sql = new QueryBuilder.SQLInsert(tableName, rows, withDelete: false);

            result.Append(sql.Build());
            return(result.ToString());
        }
Exemple #6
0
        public static string Creature(Dictionary<Guid, Unit> units)
        {
            if (units.Count == 0)
                return string.Empty;

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

            const string tableName = "creature";

            uint count = 0;
            var rows = new List<QueryBuilder.SQLInsertRow>();
            foreach (var unit in units)
            {
                var row = new QueryBuilder.SQLInsertRow();

                var creature = unit.Value;

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

                UpdateField uf;
                if (!creature.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(ObjectField.OBJECT_FIELD_ENTRY), out uf))
                    continue;   // broken entry, nothing to spawn

                var entry = uf.UInt32Value;

                var spawnTimeSecs = creature.GetDefaultSpawnTime();
                var movementType = 0; // TODO: Find a way to check if our unit got random movement
                var spawnDist = (movementType == 1) ? 5 : 0;

                row.AddValue("guid", "@CGUID+" + count, noQuotes: true);
                row.AddValue("id", entry);
                row.AddValue("map", !creature.IsOnTransport() ? creature.Map : 0);  // TODO: query transport template for map
                row.AddValue("spawnMask", 1);
                row.AddValue("phaseMask", creature.PhaseMask);
                if (!creature.IsOnTransport())
                {
                    row.AddValue("position_x", creature.Movement.Position.X);
                    row.AddValue("position_y", creature.Movement.Position.Y);
                    row.AddValue("position_z", creature.Movement.Position.Z);
                    row.AddValue("orientation", creature.Movement.Orientation);
                }
                else
                {
                    row.AddValue("position_x", creature.Movement.TransportOffset.X);
                    row.AddValue("position_y", creature.Movement.TransportOffset.Y);
                    row.AddValue("position_z", creature.Movement.TransportOffset.Z);
                    row.AddValue("orientation", creature.Movement.TransportOffset.O);
                }

                row.AddValue("spawntimesecs", spawnTimeSecs);
                row.AddValue("spawndist", spawnDist);
                row.AddValue("MovementType", movementType);
                row.Comment = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, creature.Area, false) + ")";

                if (creature.IsTemporarySpawn())
                {
                    row.CommentOut = true;
                    row.Comment += " - !!! might be temporary spawn !!!";
                }
                else if (creature.IsOnTransport())
                {
                    row.CommentOut = true;
                    row.Comment += " - !!! on transport (NYI) !!!";
                }
                else
                    ++count;

                if (creature.Movement.HasWpsOrRandMov)
                    row.Comment += " (possible waypoints or random movement)";

                rows.Add(row);
            }

            var result = new StringBuilder();
            // delete query for GUIDs
            var delete = new QueryBuilder.SQLDelete(Tuple.Create("@CGUID+0", "@CGUID+" + --count), "guid", tableName);
            result.Append(delete.Build());

            var sql = new QueryBuilder.SQLInsert(tableName, rows, withDelete: false);
            result.Append(sql.Build());
            return result.ToString();
        }
Exemple #7
0
        public static string GameObject(Dictionary<Guid, GameObject> gameObjects)
        {
            if (gameObjects.Count == 0)
                return string.Empty;

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

            const string tableName = "gameobject";

            uint count = 0;
            var rows = new List<QueryBuilder.SQLInsertRow>();
            foreach (var gameobject in gameObjects)
            {
                var row = new QueryBuilder.SQLInsertRow();

                var go = gameobject.Value;

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

                uint animprogress = 0;
                uint state = 0;
                UpdateField uf;
                if (!go.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(ObjectField.OBJECT_FIELD_ENTRY), out uf))
                    continue;   // broken entry, nothing to spawn

                var entry = uf.UInt32Value;

                if (go.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(GameObjectField.GAMEOBJECT_BYTES_1), out uf))
                {
                    var bytes = uf.UInt32Value;
                    state = (bytes & 0x000000FF);
                    animprogress = Convert.ToUInt32((bytes & 0xFF000000) >> 24);
                }

                row.AddValue("guid", "@OGUID+" + count, noQuotes: true);
                row.AddValue("id", entry);
                row.AddValue("map", !go.IsOnTransport() ? go.Map : 0);  // TODO: query transport template for map
                row.AddValue("spawnMask", 1);
                row.AddValue("phaseMask", go.PhaseMask);
                if (!go.IsOnTransport())
                {
                    row.AddValue("position_x", go.Movement.Position.X);
                    row.AddValue("position_y", go.Movement.Position.Y);
                    row.AddValue("position_z", go.Movement.Position.Z);
                    row.AddValue("orientation", go.Movement.Orientation);
                }
                else
                {
                    row.AddValue("position_x", go.Movement.TransportOffset.X);
                    row.AddValue("position_y", go.Movement.TransportOffset.Y);
                    row.AddValue("position_z", go.Movement.TransportOffset.Z);
                    row.AddValue("orientation", go.Movement.TransportOffset.O);
                }

                var rotation = go.GetRotation();
                if (rotation != null && rotation.Length == 4)
                {
                    row.AddValue("rotation0", rotation[0]);
                    row.AddValue("rotation1", rotation[1]);
                    row.AddValue("rotation2", rotation[2]);
                    row.AddValue("rotation3", rotation[3]);
                }
                else
                {
                    row.AddValue("rotation0", 0);
                    row.AddValue("rotation1", 0);
                    row.AddValue("rotation2", 0);
                    row.AddValue("rotation3", 0);
                }

                row.AddValue("spawntimesecs", go.GetDefaultSpawnTime());
                row.AddValue("animprogress", animprogress);
                row.AddValue("state", state);
                row.Comment = StoreGetters.GetName(StoreNameType.GameObject, (int)gameobject.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, go.Area, false) + ")";

                if (go.IsTemporarySpawn())
                {
                    row.CommentOut = true;
                    row.Comment += " - !!! might be temporary spawn !!!";
                }
                else if (go.IsTransport())
                {
                    row.CommentOut = true;
                    row.Comment += " - !!! transport !!!";
                }
                else if (go.IsOnTransport())
                {
                    row.CommentOut = true;
                    row.Comment += " - !!! on transport (NYI) !!!";
                }
                else
                    ++count;

                rows.Add(row);
            }

            var result = new StringBuilder();

            // delete query for GUIDs
            var delete = new QueryBuilder.SQLDelete(Tuple.Create("@OGUID+0", "@OGUID+" + --count), "guid", tableName);
            result.Append(delete.Build());

            var sql = new QueryBuilder.SQLInsert(tableName, rows, withDelete: false);
            result.Append(sql.Build());
            return result.ToString();
        }
Exemple #8
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;
        }
Exemple #9
0
        public static string Creature(Dictionary<WowGuid, Unit> units)
        {
            if (units.Count == 0)
                return string.Empty;

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

            const string tableName = "creature";
            const string addonTableName = "creature_addon";

            uint count = 0;
            var rows = new List<QueryBuilder.SQLInsertRow>();
            var addonRows = new List<QueryBuilder.SQLInsertRow>();
            foreach (var unit in units)
            {
                var row = new QueryBuilder.SQLInsertRow();
                var badTransport = false;

                var creature = unit.Value;

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

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

                UpdateField uf;
                if (!creature.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(ObjectField.OBJECT_FIELD_ENTRY), out uf))
                    continue;   // broken entry, nothing to spawn

                var entry = uf.UInt32Value;

                var movementType = 0;
                var spawnDist = 0;

                if (creature.Movement.HasWpsOrRandMov)
                {
                    movementType = 1;
                    spawnDist = 5;
                }

                row.AddValue("guid", "@CGUID+" + count, noQuotes: true);
                row.AddValue("id", entry);
                if (!creature.IsOnTransport())
                {
                    row.AddValue("map", creature.Map);
                }
                else
                {
                    int mapId;
                    badTransport = !GetTransportMap(creature, out mapId);
                    row.AddValue("map", mapId);
                }

                row.AddValue("spawnMask", creature.GetDefaultSpawnMask());
                row.AddValue("phaseMask", creature.PhaseMask);

                if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_3_4_15595) && creature.Phases != null)
                    row.AddValue("phaseId", string.Join(" - ", creature.Phases));

                if (!creature.IsOnTransport())
                {
                    row.AddValue("position_x", creature.Movement.Position.X);
                    row.AddValue("position_y", creature.Movement.Position.Y);
                    row.AddValue("position_z", creature.Movement.Position.Z);
                    row.AddValue("orientation", creature.Movement.Orientation);
                }
                else
                {
                    row.AddValue("position_x", creature.Movement.TransportOffset.X);
                    row.AddValue("position_y", creature.Movement.TransportOffset.Y);
                    row.AddValue("position_z", creature.Movement.TransportOffset.Z);
                    row.AddValue("orientation", creature.Movement.TransportOffset.O);
                }

                row.AddValue("spawntimesecs", creature.GetDefaultSpawnTime());
                row.AddValue("spawndist", spawnDist);
                row.AddValue("MovementType", movementType);

                row.Comment = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, creature.Area, false) + ")";

                var auras = string.Empty;
                var commentAuras = string.Empty;
                if (creature.Auras != null && creature.Auras.Count() != 0)
                {
                    foreach (var aura in creature.Auras)
                    {
                        if (aura == null)
                            continue;

                        // usually "template auras" do not have caster
                        if (ClientVersion.AddedInVersion(ClientType.MistsOfPandaria) ? !aura.AuraFlags.HasAnyFlag(AuraFlagMoP.NoCaster) : !aura.AuraFlags.HasAnyFlag(AuraFlag.NotCaster))
                            continue;

                        auras += aura.SpellId + " ";
                        commentAuras += aura.SpellId + " - " + StoreGetters.GetName(StoreNameType.Spell, (int)aura.SpellId, false) + ", ";
                    }

                    auras = auras.TrimEnd(' ');
                    commentAuras = commentAuras.TrimEnd(',', ' ');

                    row.Comment += " (Auras: " + commentAuras + ")";
                }

                var addonRow = new QueryBuilder.SQLInsertRow();
                if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
                {
                    addonRow.AddValue("guid", "@CGUID+" + count, noQuotes: true);
                    addonRow.AddValue("mount", creature.Mount);
                    addonRow.AddValue("bytes1", creature.Bytes1, true);
                    addonRow.AddValue("bytes2", creature.Bytes2, true);
                    addonRow.AddValue("auras", auras);
                    addonRow.Comment += StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false);
                    if (!String.IsNullOrWhiteSpace(auras))
                        addonRow.Comment += " - " + commentAuras;
                    addonRows.Add(addonRow);
                }

                if (creature.IsTemporarySpawn())
                {
                    row.CommentOut = true;
                    row.Comment += " - !!! might be temporary spawn !!!";
                }
                else if (creature.IsOnTransport() && badTransport)
                {
                    row.CommentOut = true;
                    row.Comment += " - !!! on transport - transport template not found !!!";
                }
                else
                    ++count;

                if (creature.Movement.HasWpsOrRandMov)
                    row.Comment += " (possible waypoints or random movement)";

                rows.Add(row);
            }

            var result = new StringBuilder();

            if (count > 0)
            {
                // delete query for GUIDs
                var delete = new QueryBuilder.SQLDelete(Tuple.Create("@CGUID+0", "@CGUID+" + --count), "guid", tableName);
                result.Append(delete.Build());
                var sql = new QueryBuilder.SQLInsert(tableName, rows, withDelete: false);
                result.Append(sql.Build());

                if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
                {
                    var addonDelete = new QueryBuilder.SQLDelete(Tuple.Create("@CGUID+0", "@CGUID+" + count), "guid", addonTableName);
                    result.Append(addonDelete.Build());
                    var addonSql = new QueryBuilder.SQLInsert(addonTableName, addonRows, withDelete: false);
                    result.Append(addonSql.Build());
                }
            }

            return result.ToString();
        }
Exemple #10
0
        public static string GameObject(Dictionary<Guid, GameObject> gameObjects)
        {
            if (gameObjects.Count == 0)
                return string.Empty;

            const string tableName = "gameobject";

            uint count = 0;
            var rows = new List<QueryBuilder.SQLInsertRow>();
            foreach (var gameobject in gameObjects)
            {
                var row = new QueryBuilder.SQLInsertRow();

                var go = gameobject.Value;

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

                uint animprogress = 0;
                uint state = 0;
                UpdateField uf;
                if (go.UpdateFields.TryGetValue(UpdateFields.GetUpdateField(GameObjectField.GAMEOBJECT_BYTES_1), out uf))
                {
                    var bytes = uf.UInt32Value;
                    state = (bytes & 0x000000FF);
                    animprogress = Convert.ToUInt32((bytes & 0xFF000000) >> 24);
                }

                var spawnTimeSecs = go.GetDefaultSpawnTime();

                row.AddValue("guid", "@GUID+" + count, noQuotes: true);
                row.AddValue("id", gameobject.Key.GetEntry());
                row.AddValue("map", go.Map);
                row.AddValue("spawnMask", 1);
                row.AddValue("phaseMask", go.PhaseMask);
                row.AddValue("position_x", go.Movement.Position.X);
                row.AddValue("position_y", go.Movement.Position.Y);
                row.AddValue("position_z", go.Movement.Position.Z);
                row.AddValue("orientation", go.Movement.Orientation);
                row.AddValue("rotation0", go.Movement.Rotation.X);
                row.AddValue("rotation1", go.Movement.Rotation.Y);
                row.AddValue("rotation2", go.Movement.Rotation.Z);
                row.AddValue("rotation3", go.Movement.Rotation.W);
                row.AddValue("spawntimesecs", spawnTimeSecs);
                row.AddValue("animprogress", animprogress);
                row.AddValue("state", state);
                row.Comment = StoreGetters.GetName(StoreNameType.GameObject, (int)gameobject.Key.GetEntry(), false);
                row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, go.Area, false) + ")";

                if (go.IsTemporarySpawn())
                {
                    row.CommentOut = true;
                    row.Comment += " - !!! might be temporary spawn !!!";
                }
                else
                    ++count;

                rows.Add(row);
            }

            var result = new StringBuilder();

            // delete query for GUIDs
            var delete = new QueryBuilder.SQLDelete(Tuple.Create("@GUID+0", "@GUID+" + count), "guid", tableName);
            result.Append(delete.Build());

            var sql = new QueryBuilder.SQLInsert(tableName, rows, withDelete: false);
            result.Append(sql.Build());
            return result.ToString();
        }