diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/BaseTrinityMySqlDatabaseProvider.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/BaseTrinityMySqlDatabaseProvider.cs index 61213423a..5caa399e1 100644 --- a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/BaseTrinityMySqlDatabaseProvider.cs +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/BaseTrinityMySqlDatabaseProvider.cs @@ -264,17 +264,17 @@ public virtual async Task> GetQuestTemplatesAsync() return await GetQuestsQuery(model).ToListAsync(); } - public IGameObjectTemplate? GetGameObjectTemplate(uint entry) + public virtual IQuestTemplate? GetQuestTemplate(uint entry) { using var model = Database(); - return model.GameObjectTemplate.FirstOrDefault(g => g.Entry == entry); + MySqlQuestTemplateAddon? addon = model.QuestTemplateAddon.FirstOrDefault(addon => addon.Entry == entry); + return model.QuestTemplate.FirstOrDefault(q => q.Entry == entry)?.SetAddon(addon); } - public IQuestTemplate? GetQuestTemplate(uint entry) + public IGameObjectTemplate? GetGameObjectTemplate(uint entry) { using var model = Database(); - MySqlQuestTemplateAddon? addon = model.QuestTemplateAddon.FirstOrDefault(addon => addon.Entry == entry); - return model.QuestTemplate.FirstOrDefault(q => q.Entry == entry)?.SetAddon(addon); + return model.GameObjectTemplate.FirstOrDefault(g => g.Entry == entry); } public async Task InstallScriptFor(int entryOrGuid, SmartScriptType type, IList script) diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/TrinityCataMySqlDatabaseProvider.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/TrinityCataMySqlDatabaseProvider.cs index 32f8c8435..92ab6b14d 100644 --- a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/TrinityCataMySqlDatabaseProvider.cs +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Database/TrinityCataMySqlDatabaseProvider.cs @@ -173,4 +173,34 @@ public override async Task> GetGameObjectsByMapAsync(uint map await using var model = Database(); return await model.GameObject.Where(c => c.Map == map).ToListAsync(); } + + protected virtual IQueryable GetQuestsQuery(TrinityCataDatabase model) + { + return (from t in model.CataQuestTemplate + join addon in model.CataQuestTemplateAddon on t.Entry equals addon.Entry into adn + from subaddon in adn.DefaultIfEmpty() + orderby t.Entry + select t.SetAddon(subaddon)); + } + + public override IEnumerable GetQuestTemplates() + { + using var model = Database(); + + return GetQuestsQuery(model).ToList(); + } + + public override async Task> GetQuestTemplatesAsync() + { + await using var model = Database(); + return await GetQuestsQuery(model).ToListAsync(); + } + + public override IQuestTemplate? GetQuestTemplate(uint entry) + { + using var model = Database(); + MySqlCataQuestTemplateAddon? addon = model.CataQuestTemplateAddon.FirstOrDefault(addon => addon.Entry == entry); + return model.CataQuestTemplate.FirstOrDefault(q => q.Entry == entry)?.SetAddon(addon); + } + } \ No newline at end of file diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/Databases/TrinityCataDatabase.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/Databases/TrinityCataDatabase.cs index 80b1a7886..4c946978d 100644 --- a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/Databases/TrinityCataDatabase.cs +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/Databases/TrinityCataDatabase.cs @@ -12,4 +12,6 @@ public class TrinityCataDatabase : BaseTrinityDatabase public ITable Strings => GetTable(); public ITable SpellDbc => GetTable(); public ITable GameObject => GetTable(); + public ITable CataQuestTemplate => GetTable(); + public ITable CataQuestTemplateAddon => GetTable(); } \ No newline at end of file diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlQuestTemplate.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlQuestTemplate.cs index 2e7520d4c..7ada2249b 100644 --- a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlQuestTemplate.cs +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlQuestTemplate.cs @@ -39,6 +39,40 @@ public MySqlQuestTemplate SetAddon(MySqlQuestTemplateAddon? addon) } } + [Table(Name = "quest_template")] + public class MySqlCataQuestTemplate : IQuestTemplate + { + private MySqlCataQuestTemplateAddon? addon; + + [PrimaryKey] + [Column(Name = "ID")] + public uint Entry { get; set; } + + [Column(Name = "LogTitle")] + public string Name { get; set; } = ""; + + public CharacterClasses AllowableClasses => addon == null ? CharacterClasses.None : (CharacterClasses)addon.AllowableClasses; + + public CharacterRaces AllowableRaces => addon?.AllowableRaces ?? CharacterRaces.All; + + public int PrevQuestId => addon == null ? 0 : addon.PrevQuestId; + + public int NextQuestId => addon == null ? 0 : addon.NextQuestId; + + public int ExclusiveGroup => addon == null ? 0 : addon.ExclusiveGroup; + + public int BreadcrumbForQuestId => addon?.BreadcrumbForQuest ?? 0; + + [Column(Name = "RewardNextQuest")] + public uint NextQuestInChain { get; set; } + + public MySqlCataQuestTemplate SetAddon(MySqlCataQuestTemplateAddon? addon) + { + this.addon = addon; + return this; + } + } + [Table(Name = "quest_template")] public class MySqlMasterQuestTemplate : IQuestTemplate { diff --git a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlQuestTemplateAddon.cs b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlQuestTemplateAddon.cs index 427b80f94..5f885c4e7 100644 --- a/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlQuestTemplateAddon.cs +++ b/WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlQuestTemplateAddon.cs @@ -1,4 +1,5 @@ using LinqToDB.Mapping; +using WDE.Common.Database; namespace WDE.TrinityMySqlDatabase.Models { @@ -25,6 +26,13 @@ public class MySqlQuestTemplateAddon public uint AllowableClasses { get; set; } } + [Table(Name = "quest_template_addon")] + public class MySqlCataQuestTemplateAddon : MySqlQuestTemplateAddon + { + [Column(Name="AllowableRaces")] + public CharacterRaces AllowableRaces { get; set; } + } + [Table(Name = "quest_template_addon")] public class MySqlQuestTemplateAddonWithScriptName : MySqlQuestTemplateAddon {