public static string Creature(Dictionary <WowGuid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature)) { return(string.Empty); } uint count = 0; CreatureAddon addonDefault = null; if (Settings.DBEnabled && Settings.SkipRowsWithFallbackValues) { addonDefault = SQLUtil.GetDefaultObject <CreatureAddon>(); } var dbFields = SQLUtil.GetDBFields <CreatureAddon>(false); var rows = new RowList <Creature>(); var addonRows = new RowList <CreatureAddon>(); foreach (var unit in units) { Row <Creature> row = new Row <Creature>(); bool badTransport = false; Unit 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; } } uint entry = (uint)creature.ObjectData.EntryID; if (entry == 0) { continue; // broken entry, nothing to spawn } uint movementType = 0; int wanderDistance = 0; row.Data.AreaID = 0; row.Data.ZoneID = 0; if (creature.Movement.HasWpsOrRandMov) { movementType = 1; wanderDistance = 10; } row.Data.GUID = "@CGUID+" + count; row.Data.ID = entry; if (!creature.IsOnTransport()) { row.Data.Map = creature.Map; } else { int mapId; badTransport = !GetTransportMap(creature, out mapId); if (mapId != -1) { row.Data.Map = (uint)mapId; } } if (creature.Area != -1) { row.Data.AreaID = (uint)creature.Area; } if (creature.Zone != -1) { row.Data.ZoneID = (uint)creature.Zone; } row.Data.SpawnMask = (uint)creature.GetDefaultSpawnMask(); if (ClientVersion.AddedInVersion(ClientVersionBuild.V7_0_3_22248)) { string data = string.Join(",", creature.GetDefaultSpawnDifficulties()); if (string.IsNullOrEmpty(data)) { data = "0"; } row.Data.spawnDifficulties = data; } row.Data.PhaseMask = creature.PhaseMask; if (ClientVersion.AddedInVersion(ClientVersionBuild.V4_3_4_15595) && creature.Phases != null) { string data = string.Join(" - ", creature.Phases); if (string.IsNullOrEmpty(data) || Settings.ForcePhaseZero) { data = "0"; } row.Data.PhaseID = data; } if (!creature.IsOnTransport()) { row.Data.PositionX = creature.Movement.Position.X; row.Data.PositionY = creature.Movement.Position.Y; row.Data.PositionZ = creature.Movement.Position.Z; row.Data.Orientation = creature.Movement.Orientation; } else { row.Data.PositionX = creature.Movement.TransportOffset.X; row.Data.PositionY = creature.Movement.TransportOffset.Y; row.Data.PositionZ = creature.Movement.TransportOffset.Z; row.Data.Orientation = creature.Movement.TransportOffset.O; } row.Data.SpawnTimeSecs = creature.GetDefaultSpawnTime(creature.DifficultyID); row.Data.WanderDistance = wanderDistance; row.Data.MovementType = movementType; // set some defaults row.Data.PhaseGroup = 0; row.Data.ModelID = 0; row.Data.CurrentWaypoint = 0; row.Data.CurHealth = (uint)creature.UnitData.MaxHealth; row.Data.CurMana = (uint)creature.UnitData.MaxPower[0]; row.Data.NpcFlag = 0; row.Data.UnitFlag = 0; row.Data.DynamicFlag = 0; row.Comment = StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false); row.Comment += " (Area: " + StoreGetters.GetName(StoreNameType.Area, creature.Area, false) + " - "; row.Comment += "Difficulty: " + StoreGetters.GetName(StoreNameType.Difficulty, (int)creature.DifficultyID, false) + ")"; string auras = string.Empty; string commentAuras = string.Empty; if (creature.Auras != null && creature.Auras.Count != 0) { foreach (Aura 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 Row <CreatureAddon>(); if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon)) { addonRow.Data.PathID = 0; addonRow.Data.Mount = (uint)creature.UnitData.MountDisplayID; addonRow.Data.Bytes1 = creature.Bytes1; addonRow.Data.Bytes2 = creature.Bytes2; addonRow.Data.Emote = 0; addonRow.Data.Auras = auras; addonRow.Data.AIAnimKit = creature.AIAnimKit.GetValueOrDefault(0); addonRow.Data.MovementAnimKit = creature.MovementAnimKit.GetValueOrDefault(0); addonRow.Data.MeleeAnimKit = creature.MeleeAnimKit.GetValueOrDefault(0); addonRow.Data.VisibilityDistanceType = creature.VisibilityDistanceType; if (addonDefault == null || !SQLUtil.AreDBFieldsEqual(addonDefault, addonRow.Data, dbFields)) { addonRow.Data.GUID = $"@CGUID+{count}"; addonRow.Comment += StoreGetters.GetName(StoreNameType.Unit, (int)unit.Key.GetEntry(), false); if (!string.IsNullOrWhiteSpace(auras)) { addonRow.Comment += $" - {commentAuras}"; } addonRows.Add(addonRow); } } if (creature.IsTemporarySpawn() && !Settings.SaveTempSpawns) { row.CommentOut = true; row.Comment += " - !!! might be temporary spawn !!!"; if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon)) { addonRow.CommentOut = true; addonRow.Comment += " - !!! might be temporary spawn !!!"; } } else if (creature.IsOnTransport() && badTransport) { row.CommentOut = true; row.Comment += " - !!! on transport - transport template not found !!!"; if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon)) { addonRow.CommentOut = true; addonRow.Comment += " - !!! on transport - transport template not found !!!"; } } ++count; if (creature.Movement.HasWpsOrRandMov) { row.Comment += " (possible waypoints or random movement)"; } rows.Add(row); } if (count == 0) { return(string.Empty); } StringBuilder result = new StringBuilder(); // delete query for GUIDs var delete = new SQLDelete <Creature>(Tuple.Create("@CGUID+0", "@CGUID+" + --count)); result.Append(delete.Build()); var sql = new SQLInsert <Creature>(rows, false); result.Append(sql.Build()); if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon)) { var addonDelete = new SQLDelete <CreatureAddon>(Tuple.Create("@CGUID+0", "@CGUID+" + count)); result.Append(addonDelete.Build()); var addonSql = new SQLInsert <CreatureAddon>(addonRows, false); result.Append(addonSql.Build()); } return(result.ToString()); }
public static string CreatureTemplateAddon(Dictionary <WowGuid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template_addon)) { return(string.Empty); } CreatureTemplateAddon templateAddonDefault = null; if (Settings.DBEnabled && Settings.SkipRowsWithFallbackValues) { templateAddonDefault = SQLUtil.GetDefaultObject <CreatureTemplateAddon>(); } var dbFields = SQLUtil.GetDBFields <CreatureTemplateAddon>(false); var addons = new DataBag <CreatureTemplateAddon>(); foreach (var unit in units) { var npc = unit.Value; if (Settings.AreaFilters.Length > 0) { if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) { continue; } } if (Settings.MapFilters.Length > 0) { if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) { continue; } } var auras = string.Empty; var commentAuras = string.Empty; if (npc.Auras != null && npc.Auras.Count != 0) { foreach (var aura in npc.Auras.Where(aura => aura != null && (ClientVersion.AddedInVersion(ClientType.MistsOfPandaria) ? aura.AuraFlags.HasAnyFlag(AuraFlagMoP.NoCaster) : aura.AuraFlags.HasAnyFlag(AuraFlag.NotCaster)))) { auras += aura.SpellId + " "; commentAuras += StoreGetters.GetName(StoreNameType.Spell, (int)aura.SpellId, false) + ", "; } auras = auras.TrimEnd(' '); commentAuras = commentAuras.TrimEnd(',', ' '); } var addon = new CreatureTemplateAddon { Entry = unit.Key.GetEntry(), PathID = 0, MountID = (uint)npc.UnitData.MountDisplayID, Bytes1 = npc.Bytes1, Bytes2 = npc.Bytes2, Emote = 0, AIAnimKit = npc.AIAnimKit.GetValueOrDefault(0), MovementAnimKit = npc.MovementAnimKit.GetValueOrDefault(0), MeleeAnimKit = npc.MeleeAnimKit.GetValueOrDefault(0), VisibilityDistanceType = npc.VisibilityDistanceType, Auras = auras, CommentAuras = commentAuras }; if (templateAddonDefault != null && SQLUtil.AreDBFieldsEqual(addon, templateAddonDefault, dbFields)) { continue; } if (addons.ContainsKey(addon)) { continue; } addons.Add(addon); } var addonsDb = SQLDatabase.Get(addons); return(SQLUtil.Compare(addons, addonsDb, addon => { var comment = StoreGetters.GetName(StoreNameType.Unit, (int)addon.Entry.GetValueOrDefault()); if (!string.IsNullOrEmpty(addon.CommentAuras)) { comment += " - " + addon.CommentAuras; } return comment; })); }