Skip to content

Commit

Permalink
[Database] Quest template fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Mar 25, 2022
1 parent b6427a3 commit 3cb863d
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,17 @@ public virtual async Task<List<IQuestTemplate>> GetQuestTemplatesAsync()
return await GetQuestsQuery(model).ToListAsync<IQuestTemplate>();
}

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<ISmartScriptLine> script)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,34 @@ public override async Task<IList<IGameObject>> GetGameObjectsByMapAsync(uint map
await using var model = Database();
return await model.GameObject.Where(c => c.Map == map).ToListAsync<IGameObject>();
}

protected virtual IQueryable<MySqlCataQuestTemplate> 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<IQuestTemplate> GetQuestTemplates()
{
using var model = Database();

return GetQuestsQuery(model).ToList<IQuestTemplate>();
}

public override async Task<List<IQuestTemplate>> GetQuestTemplatesAsync()
{
await using var model = Database();
return await GetQuestsQuery(model).ToListAsync<IQuestTemplate>();
}

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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public class TrinityCataDatabase : BaseTrinityDatabase
public ITable<TrinityString> Strings => GetTable<TrinityString>();
public ITable<TrinityMySqlSpellDbc> SpellDbc => GetTable<TrinityMySqlSpellDbc>();
public ITable<MySqlGameObjectCata> GameObject => GetTable<MySqlGameObjectCata>();
public ITable<MySqlCataQuestTemplate> CataQuestTemplate => GetTable<MySqlCataQuestTemplate>();
public ITable<MySqlCataQuestTemplateAddon> CataQuestTemplateAddon => GetTable<MySqlCataQuestTemplateAddon>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LinqToDB.Mapping;
using WDE.Common.Database;

namespace WDE.TrinityMySqlDatabase.Models
{
Expand All @@ -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
{
Expand Down

0 comments on commit 3cb863d

Please sign in to comment.