diff --git a/QuestChainTest/MainWindow.xaml.cs b/QuestChainTest/MainWindow.xaml.cs index 1f169073c..b3c0e1ac4 100644 --- a/QuestChainTest/MainWindow.xaml.cs +++ b/QuestChainTest/MainWindow.xaml.cs @@ -1,6 +1,9 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using System.Windows; +using WDE.Common.CoreVersion; +using WDE.Common.Database; using WDE.Common.Tasks; using WDE.QuestChainEditor.Editor.ViewModels; using WDE.QuestChainEditor.Exporter; @@ -28,7 +31,7 @@ public MainWindow() new TrinityMySqlDatabaseModule().OnInitialized(null); - TrinityMySqlDatabaseProvider db = new(new ConnectionSettingsProvider(), new DatabaseLogger(), new MockTaskRunner()); + TrinityMySqlDatabaseProvider db = new(new ConnectionSettingsProvider(), new DatabaseLogger(), new MockCoreVersion()); ExampleQuestsProvider exampleQuestProvider = new(); @@ -46,6 +49,17 @@ public MainWindow() q.RequiredQuests.CollectionChanged += (sender, e) => { Update(); }; } + public class MockCoreVersion : ICurrentCoreVersion, ICoreVersion, IDatabaseFeatures,ISmartScriptFeatures + { + public ICoreVersion Current => this; + public string Tag => "mock"; + public string FriendlyName => "mock"; + public IDatabaseFeatures DatabaseFeatures => this; + public ISmartScriptFeatures SmartScriptFeatures => this; + public ISet UnsupportedTables => new HashSet(); + public ISet SupportedTypes => null; + } + private void Update() { Text.Text = new QuestChainExporter().GenerateSQL(quests); diff --git a/WDE.AzerothCore/AzerothCoreVersion.cs b/WDE.AzerothCore/AzerothCoreVersion.cs index 4b76323ea..9979d384f 100644 --- a/WDE.AzerothCore/AzerothCoreVersion.cs +++ b/WDE.AzerothCore/AzerothCoreVersion.cs @@ -1,13 +1,27 @@ -using WDE.Common.CoreVersion; +using System; +using System.Collections.Generic; +using WDE.Common.CoreVersion; +using WDE.Common.Database; using WDE.Module.Attributes; namespace WDE.AzerothCore { [AutoRegister] [SingleInstance] - public class AzerothCoreVersion : ICoreVersion + public class AzerothCoreVersion : ICoreVersion, IDatabaseFeatures, ISmartScriptFeatures { public string Tag => "Azeroth"; public string FriendlyName => "AzerothCore Wrath of the Lich King"; + public ISmartScriptFeatures SmartScriptFeatures => this; + public IDatabaseFeatures DatabaseFeatures => this; + + public ISet UnsupportedTables { get; } = new HashSet{typeof(IAreaTriggerTemplate)}; + public ISet SupportedTypes { get; } = new HashSet + { + SmartScriptType.Creature, + SmartScriptType.GameObject, + SmartScriptType.AreaTrigger, + SmartScriptType.TimedActionList, + }; } } \ No newline at end of file diff --git a/WDE.Blueprints/Providers/BlueprintItemProvider.cs b/WDE.Blueprints/Providers/BlueprintItemProvider.cs index 612bccb94..603e70087 100644 --- a/WDE.Blueprints/Providers/BlueprintItemProvider.cs +++ b/WDE.Blueprints/Providers/BlueprintItemProvider.cs @@ -2,6 +2,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using WDE.Common; +using WDE.Common.CoreVersion; using WDE.Module.Attributes; namespace WDE.Blueprints.Providers @@ -9,6 +10,8 @@ namespace WDE.Blueprints.Providers //[AutoRegister] public class BlueprintItemProvider : ISolutionItemProvider { + public bool IsCompatibleWithCore(ICoreVersion core) => false; + public ISolutionItem CreateSolutionItem() { return new BlueprintSolutionItem(); diff --git a/WDE.SmartScriptEditor/Exporter/SmartScriptExporter.cs b/WDE.SmartScriptEditor/Exporter/SmartScriptExporter.cs index caf046f47..3b27d7195 100644 --- a/WDE.SmartScriptEditor/Exporter/SmartScriptExporter.cs +++ b/WDE.SmartScriptEditor/Exporter/SmartScriptExporter.cs @@ -149,6 +149,12 @@ private void BuildUpdate() sql.AppendLine("DELETE FROM areatrigger_scripts WHERE entry = @ENTRY;"); sql.AppendLine("INSERT INTO areatrigger_scripts(entry, ScriptName) VALUES(@ENTRY, \"SmartTrigger\");"); break; + case SmartScriptType.AreaTriggerEntityServerSide: + sql.AppendLine("UPDATE areatrigger_template SET ScriptName = \"SmartAreaTriggerAI\" WHERE Id = @ENTRY AND IsServerSide = 1;"); + break; + case SmartScriptType.AreaTriggerEntity: + sql.AppendLine("UPDATE areatrigger_template SET ScriptName = \"SmartAreaTriggerAI\" WHERE Id = @ENTRY AND IsServerSide = 0;"); + break; } } diff --git a/WDE.SmartScriptEditor/Providers/SmartScriptNameProvider.cs b/WDE.SmartScriptEditor/Providers/SmartScriptNameProvider.cs index a8d0e6e7e..e3368cf2f 100644 --- a/WDE.SmartScriptEditor/Providers/SmartScriptNameProvider.cs +++ b/WDE.SmartScriptEditor/Providers/SmartScriptNameProvider.cs @@ -32,7 +32,7 @@ public string GetName(SmartScriptSolutionItem item) IGameObjectTemplate g = database.GetGameObjectTemplate((uint) entry); return g == null || g.Name == null ? "GameObject " + entry : g.Name; case SmartScriptType.AreaTrigger: - return "Areatrigger " + entry; + return "Clientside area trigger " + entry; case SmartScriptType.Quest: IQuestTemplate q = database.GetQuestTemplate((uint) entry); return q == null || q.Name == null ? "Quest " + entry : q.Name; @@ -43,8 +43,10 @@ public string GetName(SmartScriptSolutionItem item) return (item.SmartType == SmartScriptType.Aura ? "Aura " : "Spell ") + entry; case SmartScriptType.TimedActionList: return "Timed list " + entry; - case SmartScriptType.Cinematic: - return "Cinematic " + entry; + case SmartScriptType.AreaTriggerEntity: + return "Area trigger entity " + entry; + case SmartScriptType.AreaTriggerEntityServerSide: + return "Serverside area trigger entity " + entry; } } diff --git a/WDE.SmartScriptEditor/SmartData/events.json b/WDE.SmartScriptEditor/SmartData/events.json index 5a7d1d15b..0aa4c5473 100644 --- a/WDE.SmartScriptEditor/SmartData/events.json +++ b/WDE.SmartScriptEditor/SmartData/events.json @@ -1838,7 +1838,9 @@ { "id": 46, "valid_types": [ - "AreaTrigger" + "AreaTrigger", + "AreaTriggerEntity", + "AreaTriggerEntityServerSide" ], "name": "SMART_EVENT_AREATRIGGER_ONTRIGGER", "parameters": [ diff --git a/WDE.SmartScriptEditor/SmartScriptSolutionItemProvider.cs b/WDE.SmartScriptEditor/SmartScriptSolutionItemProvider.cs index 05f0f0b87..4ac2b37b0 100644 --- a/WDE.SmartScriptEditor/SmartScriptSolutionItemProvider.cs +++ b/WDE.SmartScriptEditor/SmartScriptSolutionItemProvider.cs @@ -1,8 +1,13 @@ using System; +using System.Linq; using System.Windows.Media; using System.Windows.Media.Imaging; using WDE.Common; +using WDE.Common.CoreVersion; using WDE.Common.Database; +using WDE.Common.DBC; +using WDE.Common.Parameters; +using WDE.Common.Providers; using WDE.Module.Attributes; namespace WDE.SmartScriptEditor @@ -36,6 +41,9 @@ public string GetDescription() { return desc; } + + public bool IsCompatibleWithCore(ICoreVersion core) => + core.SmartScriptFeatures.SupportedTypes.Contains(type); public abstract ISolutionItem CreateSolutionItem(); } @@ -172,4 +180,101 @@ public override ISolutionItem CreateSolutionItem() return new SmartScriptSolutionItem((int) entry.Value, SmartScriptType.TimedActionList); } } + + [AutoRegister] + public class SmartScriptClientAreaTriggerEntityListProvider : SmartScriptSolutionItemProvider + { + private readonly Lazy itemFromListProvider; + private readonly Lazy dbcStore; + + public SmartScriptClientAreaTriggerEntityListProvider( + Lazy itemFromListProvider, + Lazy dbcStore + ) : base("Client Area Trigger", + "The script from AreaTrigger from client database (DBC)", + "SmartScriptGeneric", + SmartScriptType.AreaTrigger) + { + this.itemFromListProvider = itemFromListProvider; + this.dbcStore = dbcStore; + } + + public override ISolutionItem CreateSolutionItem() + { + var areaTriggers = + dbcStore.Value.AreaTriggerStore.ToDictionary(at => at.Key, at => new SelectOption($"Client areatrigger {at.Key}")); + int? entry = itemFromListProvider.Value.GetItemFromList(areaTriggers, false); + if (!entry.HasValue) + return null; + return new SmartScriptSolutionItem(entry.Value, SmartScriptType.AreaTrigger); + } + } + + public abstract class SmartScriptAreaTriggerEntityListProviderBase : SmartScriptSolutionItemProvider + { + private readonly Lazy itemFromListProvider; + private readonly Lazy database; + private readonly SmartScriptType type; + private readonly bool serverSide; + + public SmartScriptAreaTriggerEntityListProviderBase( + Lazy itemFromListProvider, + Lazy database, + string name, + string desc, + string icon, + SmartScriptType type, + bool serverSide + ) : base(name, desc, icon, type) + { + this.itemFromListProvider = itemFromListProvider; + this.database = database; + this.type = type; + this.serverSide = serverSide; + } + + public override ISolutionItem CreateSolutionItem() + { + var areaTriggers = database.Value.GetAreaTriggerTemplates() + .Where(trigger => trigger.IsServerSide == serverSide) + .ToDictionary(at => (int)at.Id, at => new SelectOption($"Area trigger {at.Id}")); + + int? entry = itemFromListProvider.Value.GetItemFromList(areaTriggers, false); + if (!entry.HasValue) + return null; + return new SmartScriptSolutionItem(entry.Value, type); + } + } + + [AutoRegister] + public class SmartScriptAreaTriggerEntityListProvider : SmartScriptAreaTriggerEntityListProviderBase + { + public SmartScriptAreaTriggerEntityListProvider( + Lazy itemFromListProvider, + Lazy database + ) : base( + itemFromListProvider, + database, + "Area Trigger Entity", + "The script from AreaTrigger defined in areatrigger_template", + "SmartScriptGeneric", + SmartScriptType.AreaTriggerEntity, + false) {} + } + + [AutoRegister] + public class SmartScriptServerSideAreaTriggerEntityListProvider : SmartScriptAreaTriggerEntityListProviderBase + { + public SmartScriptServerSideAreaTriggerEntityListProvider( + Lazy itemFromListProvider, + Lazy database + ) : base( + itemFromListProvider, + database, + "Area Trigger Server-side Entity", + "The script from server side AreaTrigger defined in areatrigger_template", + "SmartScriptGeneric", + SmartScriptType.AreaTriggerEntityServerSide, + true) {} + } } \ No newline at end of file diff --git a/WDE.Solutions/SolutionFolderItemProvider.cs b/WDE.Solutions/SolutionFolderItemProvider.cs index 109e0f8d5..5cd5071c6 100644 --- a/WDE.Solutions/SolutionFolderItemProvider.cs +++ b/WDE.Solutions/SolutionFolderItemProvider.cs @@ -3,6 +3,7 @@ using System.Windows.Media.Imaging; using Microsoft.VisualBasic; using WDE.Common; +using WDE.Common.CoreVersion; using WDE.Module.Attributes; namespace WDE.Solutions @@ -10,6 +11,8 @@ namespace WDE.Solutions [AutoRegister] public class SolutionFolderItemProvider : ISolutionItemProvider { + public bool IsCompatibleWithCore(ICoreVersion core) => true; + public string GetName() { return "Folder"; diff --git a/WDE.Trinity/TrinityCataclysmVersion.cs b/WDE.Trinity/TrinityCataclysmVersion.cs index b801b0dea..6deb536d1 100644 --- a/WDE.Trinity/TrinityCataclysmVersion.cs +++ b/WDE.Trinity/TrinityCataclysmVersion.cs @@ -1,13 +1,28 @@ -using WDE.Common.CoreVersion; +using System; +using System.Collections.Generic; +using WDE.Common.CoreVersion; +using WDE.Common.Database; using WDE.Module.Attributes; namespace WDE.Trinity { [AutoRegister] [SingleInstance] - public class TrinityCataclysmVersion : ICoreVersion + public class TrinityCataclysmVersion : ICoreVersion, IDatabaseFeatures, ISmartScriptFeatures { public string Tag => "TrinityCata"; public string FriendlyName => "The Cataclysm Preservation Project"; + + public IDatabaseFeatures DatabaseFeatures => this; + public ISmartScriptFeatures SmartScriptFeatures => this; + + public ISet UnsupportedTables { get; } = new HashSet{typeof(IAreaTriggerTemplate)}; + public ISet SupportedTypes { get; } = new HashSet + { + SmartScriptType.Creature, + SmartScriptType.GameObject, + SmartScriptType.AreaTrigger, + SmartScriptType.TimedActionList, + }; } } \ No newline at end of file diff --git a/WDE.Trinity/TrinityMasterVersion.cs b/WDE.Trinity/TrinityMasterVersion.cs index 02241bf0e..6c8539827 100644 --- a/WDE.Trinity/TrinityMasterVersion.cs +++ b/WDE.Trinity/TrinityMasterVersion.cs @@ -1,14 +1,30 @@ -using WDE.Common.CoreVersion; -using WDE.Common.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using WDE.Common.CoreVersion; +using WDE.Common.Database; using WDE.Module.Attributes; namespace WDE.Trinity { [AutoRegister] [SingleInstance] - public class TrinityMasterVersion : ICoreVersion + public class TrinityMasterVersion : ICoreVersion, IDatabaseFeatures, ISmartScriptFeatures { public string Tag => "TrinityMaster"; public string FriendlyName => "TrinityCore Shadowlands"; + public ISmartScriptFeatures SmartScriptFeatures => this; + public IDatabaseFeatures DatabaseFeatures => this; + + public ISet UnsupportedTables { get; } = new HashSet(); + public ISet SupportedTypes { get; } = new HashSet + { + SmartScriptType.Creature, + SmartScriptType.GameObject, + SmartScriptType.AreaTrigger, + SmartScriptType.TimedActionList, + SmartScriptType.AreaTriggerEntity, + SmartScriptType.AreaTriggerEntityServerSide + }; } } \ No newline at end of file diff --git a/WDE.Trinity/TrinityWrathVersion.cs b/WDE.Trinity/TrinityWrathVersion.cs index 5ffcb172a..204879db8 100644 --- a/WDE.Trinity/TrinityWrathVersion.cs +++ b/WDE.Trinity/TrinityWrathVersion.cs @@ -1,13 +1,27 @@ -using WDE.Common.CoreVersion; +using System; +using System.Collections.Generic; +using WDE.Common.CoreVersion; +using WDE.Common.Database; using WDE.Module.Attributes; namespace WDE.Trinity { [AutoRegister] [SingleInstance] - public class TrinityWrathVersion : ICoreVersion + public class TrinityWrathVersion : ICoreVersion, IDatabaseFeatures, ISmartScriptFeatures { public string Tag => "TrinityWrath"; public string FriendlyName => "TrinityCore Wrath of the Lich King"; + public ISmartScriptFeatures SmartScriptFeatures => this; + public IDatabaseFeatures DatabaseFeatures => this; + + public ISet UnsupportedTables { get; } = new HashSet{typeof(IAreaTriggerTemplate)}; + public ISet SupportedTypes { get; } = new HashSet + { + SmartScriptType.Creature, + SmartScriptType.GameObject, + SmartScriptType.AreaTrigger, + SmartScriptType.TimedActionList, + }; } } \ No newline at end of file diff --git a/WoWDatabaseEditor.Common/WDE.Common/CoreVersion/ICoreVersion.cs b/WoWDatabaseEditor.Common/WDE.Common/CoreVersion/ICoreVersion.cs index e76b6d62f..2f4327a8e 100644 --- a/WoWDatabaseEditor.Common/WDE.Common/CoreVersion/ICoreVersion.cs +++ b/WoWDatabaseEditor.Common/WDE.Common/CoreVersion/ICoreVersion.cs @@ -1,4 +1,7 @@ -using WDE.Module.Attributes; +using System; +using System.Collections.Generic; +using WDE.Common.Database; +using WDE.Module.Attributes; namespace WDE.Common.CoreVersion { @@ -7,5 +10,17 @@ public interface ICoreVersion { string Tag { get; } string FriendlyName { get; } + IDatabaseFeatures DatabaseFeatures { get; } + ISmartScriptFeatures SmartScriptFeatures { get; } + } + + public interface IDatabaseFeatures + { + ISet UnsupportedTables { get; } + } + + public interface ISmartScriptFeatures + { + ISet SupportedTypes { get; } } } \ No newline at end of file diff --git a/WoWDatabaseEditor.Common/WDE.Common/DBC/IDbcStore.cs b/WoWDatabaseEditor.Common/WDE.Common/DBC/IDbcStore.cs index b85d90cfb..8da93ee7a 100644 --- a/WoWDatabaseEditor.Common/WDE.Common/DBC/IDbcStore.cs +++ b/WoWDatabaseEditor.Common/WDE.Common/DBC/IDbcStore.cs @@ -6,6 +6,7 @@ namespace WDE.Common.DBC [UniqueProvider] public interface IDbcStore { + Dictionary AreaTriggerStore { get; } Dictionary SkillStore { get; } Dictionary LanguageStore { get; } Dictionary PhaseStore { get; } diff --git a/WoWDatabaseEditor.Common/WDE.Common/Database/Enums.cs b/WoWDatabaseEditor.Common/WDE.Common/Database/Enums.cs index fd753b3a3..b5d063888 100644 --- a/WoWDatabaseEditor.Common/WDE.Common/Database/Enums.cs +++ b/WoWDatabaseEditor.Common/WDE.Common/Database/Enums.cs @@ -12,7 +12,10 @@ public enum SmartScriptType Transport = 7, Instance = 8, TimedActionList = 9, - Aura = 10, - Cinematic = 11 + Scene = 10, + AreaTriggerEntity = 11, + AreaTriggerEntityServerSide = 12, + Aura = 13, // do not exists on TC + Cinematic = 14 // do not exists on TC } } \ No newline at end of file diff --git a/WoWDatabaseEditor.Common/WDE.Common/Database/IAreaTriggerTemplate.cs b/WoWDatabaseEditor.Common/WDE.Common/Database/IAreaTriggerTemplate.cs new file mode 100644 index 000000000..5e66f16ac --- /dev/null +++ b/WoWDatabaseEditor.Common/WDE.Common/Database/IAreaTriggerTemplate.cs @@ -0,0 +1,9 @@ +namespace WDE.Common.Database +{ + public interface IAreaTriggerTemplate + { + public uint Id { get; } + bool IsServerSide { get; } + string ScriptName { get; } + } +} \ No newline at end of file diff --git a/WoWDatabaseEditor.Common/WDE.Common/Database/IDatabaseProvider.cs b/WoWDatabaseEditor.Common/WDE.Common/Database/IDatabaseProvider.cs index c9db6c50a..8f46619fe 100644 --- a/WoWDatabaseEditor.Common/WDE.Common/Database/IDatabaseProvider.cs +++ b/WoWDatabaseEditor.Common/WDE.Common/Database/IDatabaseProvider.cs @@ -14,6 +14,8 @@ public interface IDatabaseProvider IGameObjectTemplate GetGameObjectTemplate(uint entry); IEnumerable GetGameObjectTemplates(); + IEnumerable GetAreaTriggerTemplates(); + IQuestTemplate GetQuestTemplate(uint entry); IEnumerable GetQuestTemplates(); diff --git a/WoWDatabaseEditor.Common/WDE.Common/Database/IGameObjectTemplate.cs b/WoWDatabaseEditor.Common/WDE.Common/Database/IGameObjectTemplate.cs index e50b86d1a..228972770 100644 --- a/WoWDatabaseEditor.Common/WDE.Common/Database/IGameObjectTemplate.cs +++ b/WoWDatabaseEditor.Common/WDE.Common/Database/IGameObjectTemplate.cs @@ -4,5 +4,7 @@ public interface IGameObjectTemplate { uint Entry { get; set; } string Name { get; set; } + string AIName { get; set; } + string ScriptName { get; set; } } } \ No newline at end of file diff --git a/WoWDatabaseEditor.Common/WDE.Common/Solution/ISolutionItemProvider.cs b/WoWDatabaseEditor.Common/WDE.Common/Solution/ISolutionItemProvider.cs index f5560d89a..aa64a1771 100644 --- a/WoWDatabaseEditor.Common/WDE.Common/Solution/ISolutionItemProvider.cs +++ b/WoWDatabaseEditor.Common/WDE.Common/Solution/ISolutionItemProvider.cs @@ -1,4 +1,5 @@ using System.Windows.Media; +using WDE.Common.CoreVersion; using WDE.Module.Attributes; namespace WDE.Common @@ -9,6 +10,8 @@ public interface ISolutionItemProvider string GetName(); ImageSource GetImage(); string GetDescription(); + + bool IsCompatibleWithCore(ICoreVersion core); ISolutionItem CreateSolutionItem(); } diff --git a/WoWDatabaseEditor.Common/WDE.DbcStore/DbcStore.cs b/WoWDatabaseEditor.Common/WDE.DbcStore/DbcStore.cs index 63376bbb7..93ebddce9 100644 --- a/WoWDatabaseEditor.Common/WDE.DbcStore/DbcStore.cs +++ b/WoWDatabaseEditor.Common/WDE.DbcStore/DbcStore.cs @@ -36,6 +36,7 @@ public DbcStore(IParameterFactory parameterFactory, ITaskRunner taskRunner) Load(); } + public Dictionary AreaTriggerStore { get; internal set; } = new(); public Dictionary FactionStore { get; internal set; } = new(); public Dictionary SpellStore { get; internal set; } = new(); public Dictionary SkillStore { get; internal set;} = new(); @@ -90,6 +91,7 @@ private class DbcLoadTask : IThreadedTask private readonly IParameterFactory parameterFactory; private readonly DbcStore store; + private Dictionary AreaTriggerStore { get; } = new(); private Dictionary FactionStore { get; } = new(); private Dictionary SpellStore { get; } = new(); public Dictionary SkillStore { get; } = new(); @@ -132,6 +134,7 @@ private void Load(string filename, int id, int nameIndex, Dictionary? questTemplateCache; private Dictionary questTemplateByEntry = new(); + private List? areaTriggerTemplates; private List? gameEventsCache; private TrinityMySqlDatabaseProvider trinityDatabase; @@ -82,13 +83,10 @@ public IEnumerable GetQuestTemplates() return trinityDatabase.GetQuestTemplates(); } - public IEnumerable GetGameEvents() - { - if (gameEventsCache != null) - return gameEventsCache; + public IEnumerable GetGameEvents() => gameEventsCache ?? trinityDatabase.GetGameEvents(); - return trinityDatabase.GetGameEvents(); - } + public IEnumerable GetAreaTriggerTemplates() => + areaTriggerTemplates ?? trinityDatabase.GetAreaTriggerTemplates(); public IEnumerable GetScriptFor(int entryOrGuid, SmartScriptType type) { @@ -125,16 +123,21 @@ public DatabaseCacheTask(CachedDatabaseProvider cache) public async Task Run(ITaskProgress progress) { - progress.Report(0, 4, "Loading creatures"); + int steps = 5; + + progress.Report(0, steps, "Loading creatures"); cache.creatureTemplateCache = await cache.trinityDatabase.GetCreatureTemplatesAsync(); - progress.Report(1, 4, "Loading gameobjects"); + progress.Report(1, steps, "Loading gameobjects"); cache.gameObjectTemplateCache = await cache.trinityDatabase.GetGameObjectTemplatesAsync(); - progress.Report(2, 4, "Loading game events"); + progress.Report(2, steps, "Loading game events"); cache.gameEventsCache = await cache.trinityDatabase.GetGameEventsAsync(); - progress.Report(3, 4, "Loading quests"); + progress.Report(3, steps, "Loading areatrigger templates"); + cache.areaTriggerTemplates = await cache.trinityDatabase.GetAreaTriggerTemplatesAsync(); + + progress.Report(4, steps, "Loading quests"); cache.questTemplateCache = await cache.trinityDatabase.GetQuestTemplatesAsync(); diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/NullDatabaseProvider.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/NullDatabaseProvider.cs index 565c48f8c..c7b8a2cfa 100644 --- a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/NullDatabaseProvider.cs +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/NullDatabaseProvider.cs @@ -18,7 +18,9 @@ public class NullDatabaseProvider : IDatabaseProvider public IQuestTemplate? GetQuestTemplate(uint entry) => null; public IEnumerable GetQuestTemplates() => Enumerable.Empty(); - + + public IEnumerable GetAreaTriggerTemplates() => Enumerable.Empty(); + public IEnumerable GetGameEvents() => Enumerable.Empty(); public IEnumerable GetScriptFor(int entryOrGuid, SmartScriptType type) => Enumerable.Empty(); diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/TrinityMySqlDatabaseProvider.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/TrinityMySqlDatabaseProvider.cs index 99e66b30e..f9e9d921e 100644 --- a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/TrinityMySqlDatabaseProvider.cs +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/TrinityMySqlDatabaseProvider.cs @@ -6,6 +6,7 @@ using LinqToDB; using LinqToDB.Configuration; using LinqToDB.Data; +using WDE.Common.CoreVersion; using WDE.Common.Database; using WDE.Common.Tasks; using WDE.TrinityMySqlDatabase.Data; @@ -17,10 +18,13 @@ namespace WDE.TrinityMySqlDatabase.Database { public class TrinityMySqlDatabaseProvider : IDatabaseProvider { + private readonly ICurrentCoreVersion currentCoreVersion; + public TrinityMySqlDatabaseProvider(IConnectionSettingsProvider settings, DatabaseLogger databaseLogger, - ITaskRunner taskRunner) + ICurrentCoreVersion currentCoreVersion) { + this.currentCoreVersion = currentCoreVersion; string? host = settings.GetSettings().Host; DataConnection.TurnTraceSwitchOn(); DataConnection.WriteTraceLine = databaseLogger.Log; @@ -65,6 +69,23 @@ public async Task> GetGameEventsAsync() return await (from t in model.GameEvents orderby t.Entry select t).ToListAsync(); } + + public IEnumerable GetAreaTriggerTemplates() + { + var task = GetAreaTriggerTemplatesAsync(); + task.Wait(); + return task.Result; + } + + public async Task> GetAreaTriggerTemplatesAsync() + { + if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(IAreaTriggerTemplate))) + return new List(); + + using var model = new TrinityDatabase(); + return await (from t in model.AreaTriggerTemplate orderby t.Id select t).ToListAsync(); + } + public IEnumerable GetGameObjectTemplates() { var task = GetGameObjectTemplatesAsync(); @@ -116,12 +137,35 @@ public async Task InstallScriptFor(int entryOrGuid, SmartScriptType type, IEnume await model.BeginTransactionAsync(IsolationLevel.ReadCommitted); await model.SmartScript.Where(x => x.EntryOrGuid == entryOrGuid && x.ScriptSourceType == (int) type).DeleteAsync(); - if (type == SmartScriptType.Creature) + + switch (type) { - await model.CreatureTemplate.Where(p => p.Entry == (uint) entryOrGuid) - .Set(p => p.AIName, "SmartAI") - .Set(p => p.ScriptName, "") - .UpdateAsync(); + case SmartScriptType.Creature: + await model.CreatureTemplate.Where(p => p.Entry == (uint) entryOrGuid) + .Set(p => p.AIName, "SmartAI") + .Set(p => p.ScriptName, "") + .UpdateAsync(); + break; + case SmartScriptType.GameObject: + await model.GameObjectTemplate.Where(p => p.Entry == (uint)entryOrGuid) + .Set(p => p.AIName, "SmartAI") + .Set(p => p.ScriptName, "") + .UpdateAsync(); + break; + case SmartScriptType.AreaTrigger: + await model.AreaTriggerScript.Where(p => p.Id == entryOrGuid).DeleteAsync(); + await model.AreaTriggerScript.InsertAsync(() => new MySqlAreaTriggerScript(){Id = entryOrGuid, ScriptName = "SmartTrigger"}); + break; + case SmartScriptType.AreaTriggerEntity: + await model.AreaTriggerTemplate.Where(p => p.Id == (uint) entryOrGuid && p.IsServerSide == false) + .Set(p => p.ScriptName, "SmartAreaTriggerAI") + .UpdateAsync(); + break; + case SmartScriptType.AreaTriggerEntityServerSide: + await model.AreaTriggerTemplate.Where(p => p.Id == (uint) entryOrGuid && p.IsServerSide == true) + .Set(p => p.ScriptName, "SmartAreaTriggerAI") + .UpdateAsync(); + break; } await model.SmartScript.BulkCopyAsync(script.Select(l => new MySqlSmartScriptLine(l))); diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/DatabaseProvider.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/DatabaseProvider.cs index 843d58ddd..97fb191ad 100644 --- a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/DatabaseProvider.cs +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/DatabaseProvider.cs @@ -47,6 +47,7 @@ public DatabaseProvider(CachedDatabaseProvider cachedDatabase, public IGameObjectTemplate GetGameObjectTemplate(uint entry) => impl.GetGameObjectTemplate(entry); public IEnumerable GetGameObjectTemplates() => impl.GetGameObjectTemplates(); public IQuestTemplate GetQuestTemplate(uint entry) => impl.GetQuestTemplate(entry); + public IEnumerable GetAreaTriggerTemplates() => impl.GetAreaTriggerTemplates(); public IEnumerable GetQuestTemplates() => impl.GetQuestTemplates(); public IEnumerable GetGameEvents() => impl.GetGameEvents(); public IEnumerable GetScriptFor(int entryOrGuid, SmartScriptType type) => diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlAreaTriggerScript.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlAreaTriggerScript.cs new file mode 100644 index 000000000..45a60e0ef --- /dev/null +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlAreaTriggerScript.cs @@ -0,0 +1,15 @@ +using LinqToDB.Mapping; + +namespace WDE.TrinityMySqlDatabase.Models +{ + [Table(Name = "areatrigger_scripts")] + public class MySqlAreaTriggerScript + { + [PrimaryKey] + [Column(Name = "entry")] + public int Id { get; set; } + + [Column(Name = "ScriptName")] + public string? ScriptName { get; set; } + } +} \ No newline at end of file diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlAreaTriggerTemplate.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlAreaTriggerTemplate.cs new file mode 100644 index 000000000..b0ef9f2d1 --- /dev/null +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlAreaTriggerTemplate.cs @@ -0,0 +1,20 @@ +using LinqToDB.Mapping; +using WDE.Common.Database; + +namespace WDE.TrinityMySqlDatabase.Models +{ + [Table(Name = "areatrigger_template")] + public class MySqlAreaTriggerTemplate : IAreaTriggerTemplate + { + [PrimaryKey] + [Column(Name = "Id")] + public uint Id { get; set; } + + [PrimaryKey] + [Column(Name = "IsServerSide")] + public bool IsServerSide { get; set; } + + [Column(Name = "ScriptName")] + public string? ScriptName { get; set; } + } +} \ No newline at end of file diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlGameObjectTemplate.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlGameObjectTemplate.cs index 49bcd6b0a..9315e8664 100644 --- a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlGameObjectTemplate.cs +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlGameObjectTemplate.cs @@ -12,5 +12,11 @@ public class MySqlGameObjectTemplate : IGameObjectTemplate [Column(Name = "name")] public string Name { get; set; } = ""; + + [Column(Name = "AIName")] + public string? AIName { get; set; } + + [Column(Name = "ScriptName")] + public string? ScriptName { get; set; } } } \ No newline at end of file diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/TrinityDatabase.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/TrinityDatabase.cs index 46a17a23b..b66e7b5b3 100644 --- a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/TrinityDatabase.cs +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/TrinityDatabase.cs @@ -9,11 +9,13 @@ public TrinityDatabase() : base("Trinity") { } + public ITable AreaTriggerScript => GetTable(); public ITable CreatureTemplate => GetTable(); public ITable SmartScript => GetTable(); public ITable GameObjectTemplate => GetTable(); public ITable QuestTemplate => GetTable(); public ITable QuestTemplateAddon => GetTable(); + public ITable AreaTriggerTemplate => GetTable(); public ITable GameEvents => GetTable(); public ITable Conditions => GetTable(); } diff --git a/WoWDatabaseEditor/Services/NewItemService/NewItemDialogViewModel.cs b/WoWDatabaseEditor/Services/NewItemService/NewItemDialogViewModel.cs index dcea87c77..a8e5e206b 100644 --- a/WoWDatabaseEditor/Services/NewItemService/NewItemDialogViewModel.cs +++ b/WoWDatabaseEditor/Services/NewItemService/NewItemDialogViewModel.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using System.Windows.Input; using Prism.Commands; using Prism.Mvvm; using WDE.Common; +using WDE.Common.CoreVersion; using WDE.Module.Attributes; namespace WoWDatabaseEditor.Services.NewItemService @@ -14,11 +16,12 @@ public class NewItemDialogViewModel : BindableBase, INewItemDialogViewModel { private NewItemPrototypeInfo? selectedPrototype; - public NewItemDialogViewModel(IEnumerable items) + public NewItemDialogViewModel(IEnumerable items, + ICurrentCoreVersion coreVersion) { ItemPrototypes = new ObservableCollection(); - foreach (var item in items) + foreach (var item in items.Where(i => i.IsCompatibleWithCore(coreVersion.Current))) ItemPrototypes.Add(new NewItemPrototypeInfo(item)); Accept = new DelegateCommand(() =>