示例#1
0
 public MysqlDatabaseProvider()
 {
     try
     {
         string Database = MySqlDatabaseModule.DbAccess.DB;
         string User     = MySqlDatabaseModule.DbAccess.User;
         string Password = MySqlDatabaseModule.DbAccess.Password;
         string Host     = MySqlDatabaseModule.DbAccess.Host;
         var    config   = MySqlConfiguration.Create(Database, Host, User, Password);
         model = DataAccessModel.BuildDataAccessModel <TrinityDatabase>(config);
         try
         {
             model.Create(DatabaseCreationOptions.IfDatabaseNotExist);
         }
         catch (Exception e)
         {
             // already exists, its ok
         }
         var temp = GetCreatureTemplates();
     }
     catch (Exception e)
     {
         Console.WriteLine("Cannot connect to MySql database. Check your settings.");
         model = null;
     }
 }
示例#2
0
        public IQuestTemplate?GetQuestTemplate(uint entry)
        {
            using var model = new TrinityDatabase();
            MySqlQuestTemplateAddon?addon = model.QuestTemplateAddon.FirstOrDefault(addon => addon.Entry == entry);

            return(model.QuestTemplate.FirstOrDefault(q => q.Entry == entry)?.SetAddon(addon));
        }
示例#3
0
        public TrinityMysqlDatabaseProvider()
        {
            string Database = TrinityMySqlDatabaseModule.DbAccess.DB;
            string User     = TrinityMySqlDatabaseModule.DbAccess.User;
            string Password = TrinityMySqlDatabaseModule.DbAccess.Password;
            string Host     = TrinityMySqlDatabaseModule.DbAccess.Host;

            try
            {
                var config = MySqlConfiguration.Create(Database, Host, User, Password);
                model = DataAccessModel.BuildDataAccessModel <TrinityDatabase>(config);
                try
                {
                    model.Create(DatabaseCreationOptions.IfDatabaseNotExist);
                }
                catch (Exception)
                {
                    // already exists, its ok
                }
                var temp = GetCreatureTemplates();
            }
            catch (Exception e)
            {
                if (!string.IsNullOrEmpty(Host))
                {
                    MessageBox.Show($"Cannot connect to MySql database: {e.Message} Check your settings.");
                }
                model = null;
            }
        }
示例#4
0
 private IQueryable <MySqlQuestTemplate> GetQuestsQuery(TrinityDatabase model)
 {
     return(from t in model.QuestTemplate
            join addon in model.QuestTemplateAddon on t.Entry equals addon.Entry into adn
            from subaddon in adn.DefaultIfEmpty()
            orderby t.Entry
            select t.SetAddon(subaddon));
 }
        public async Task InstallScriptFor(int entryOrGuid, SmartScriptType type, IEnumerable <ISmartScriptLine> script)
        {
            using var writeLock = await MySqlSingleWriteLock.WriteLock();

            await using var model = new TrinityDatabase();

            await model.BeginTransactionAsync(IsolationLevel.ReadCommitted);

            await model.SmartScript.Where(x => x.EntryOrGuid == entryOrGuid && x.ScriptSourceType == (int)type).DeleteAsync();

            switch (type)
            {
            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)));

            await model.CommitTransactionAsync();
        }
示例#6
0
        public IEnumerable <ICreatureClassLevelStat> GetCreatureClassLevelStats()
        {
            if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(ICreatureClassLevelStat)))
            {
                return(Enumerable.Empty <ICreatureClassLevelStat>());
            }

            using var model = new TrinityDatabase();
            return((from t in model.CreatureClassLevelStats select t).ToList <ICreatureClassLevelStat>());
        }
示例#7
0
        public async Task <List <IConversationTemplate> > GetConversationTemplatesAsync()
        {
            if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(IConversationTemplate)))
            {
                return(new List <IConversationTemplate>());
            }

            await using var model = new TrinityDatabase();
            return(await(from t in model.ConversationTemplate orderby t.Id select t).ToListAsync <IConversationTemplate>());
        }
示例#8
0
        public async Task <List <INpcText> > GetNpcTextsAsync()
        {
            if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(INpcText)))
            {
                return(new List <INpcText>());
            }

            await using var model = new TrinityDatabase();
            return(await(from t in model.NpcTexts orderby t.Id select t).ToListAsync <INpcText>());
        }
示例#9
0
        public IEnumerable <IConversationTemplate> GetConversationTemplates()
        {
            if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(IConversationTemplate)))
            {
                return(new List <IConversationTemplate>());
            }

            using var model = new TrinityDatabase();
            return((from t in model.ConversationTemplate orderby t.Id select t).ToList <IConversationTemplate>());
        }
示例#10
0
        public async Task <List <ICreatureClassLevelStat> > GetCreatureClassLevelStatsAsync()
        {
            if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(ICreatureClassLevelStat)))
            {
                return(new List <ICreatureClassLevelStat>());
            }

            await using var model = new TrinityDatabase();
            return(await(from t in model.CreatureClassLevelStats select t).ToListAsync <ICreatureClassLevelStat>());
        }
示例#11
0
        public async Task <List <IQuestTemplate> > GetQuestTemplatesAsync()
        {
            using var model = new TrinityDatabase();

            return(await(from t in model.QuestTemplate
                         join addon in model.QuestTemplateAddon on t.Entry equals addon.Entry into adn
                         from subaddon in adn.DefaultIfEmpty()
                         orderby t.Entry
                         select t.SetAddon(subaddon)).ToListAsync <IQuestTemplate>());
        }
示例#12
0
        public IEnumerable <INpcText> GetNpcTexts()
        {
            if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(INpcText)))
            {
                return(new List <INpcText>());
            }

            using var model = new TrinityDatabase();
            return((from t in model.NpcTexts orderby t.Id select t).ToList <INpcText>());
        }
示例#13
0
        public async Task InstallConditions(IEnumerable <IConditionLine> conditionLines,
                                            IDatabaseProvider.ConditionKeyMask keyMask,
                                            IDatabaseProvider.ConditionKey?manualKey = null)
        {
            using var writeLock = await DatabaseLock.WriteLock();

            await using var model = new TrinityDatabase();

            var conditions = conditionLines?.ToList() ?? new List <IConditionLine>();
            List <(int SourceType, int?SourceGroup, int?SourceEntry, int?SourceId)> keys = conditions.Select(c =>
                                                                                                             (c.SourceType, keyMask.HasFlag(IDatabaseProvider.ConditionKeyMask.SourceGroup) ? (int?)c.SourceGroup : null,
                                                                                                              keyMask.HasFlag(IDatabaseProvider.ConditionKeyMask.SourceEntry) ? (int?)c.SourceEntry : null,
                                                                                                              keyMask.HasFlag(IDatabaseProvider.ConditionKeyMask.SourceId) ? (int?)c.SourceId : null))
                                                                                           .Union(manualKey.HasValue
                    ? new[]
示例#14
0
        public IEnumerable <IGossipMenu> GetGossipMenus()
        {
            using var model = new TrinityDatabase();

            List <MySqlGossipMenuLine> gossips;

            if (currentCoreVersion.Current.DatabaseFeatures.UnsupportedTables.Contains(typeof(INpcText)))
            {
                gossips = model.GossipMenus.ToList();
            }
            else
            {
                gossips = (from gossip in model.GossipMenus
                           join p in model.NpcTexts on gossip.TextId equals p.Id into lj
                           from lp in lj.DefaultIfEmpty()
                           select gossip.SetText(lp)).ToList();
            }

            return(gossips.GroupBy(g => g.MenuId)
                   .Select(t => new MySqlGossipMenu(t.Key, t.Where(t => t.Text != null).Select(t => t.Text !).ToList()))
                   .ToList <IGossipMenu>());
        }
示例#15
0
 public async Task <List <IGameEvent> > GetGameEventsAsync()
 {
     await using var model = new TrinityDatabase();
     return(await(from t in model.GameEvents orderby t.Entry select t).ToListAsync <IGameEvent>());
 }
示例#16
0
 public IEnumerable <IGameEvent> GetGameEvents()
 {
     using var model = new TrinityDatabase();
     return((from t in model.GameEvents orderby t.Entry select t).ToList <IGameEvent>());
 }
示例#17
0
 public IEnumerable <ISmartScriptLine> GetScriptFor(int entryOrGuid, SmartScriptType type)
 {
     using var model = new TrinityDatabase();
     return(model.SmartScript.Where(line => line.EntryOrGuid == entryOrGuid && line.ScriptSourceType == (int)type).ToList());
 }
示例#18
0
 public async Task <List <ICreatureTemplate> > GetCreatureTemplatesAsync()
 {
     await using var model = new TrinityDatabase();
     return(await model.CreatureTemplate.OrderBy(t => t.Entry).ToListAsync <ICreatureTemplate>());
 }
示例#19
0
 public IEnumerable <ICreatureTemplate> GetCreatureTemplates()
 {
     using var model = new TrinityDatabase();
     return(model.CreatureTemplate.OrderBy(t => t.Entry).ToList <ICreatureTemplate>());
 }
示例#20
0
 public async Task <List <IGameObjectTemplate> > GetGameObjectTemplatesAsync()
 {
     using var model = new TrinityDatabase();
     return(await(from t in model.GameObjectTemplate orderby t.Entry select t).ToListAsync <IGameObjectTemplate>());
 }
示例#21
0
 public async Task <List <IQuestTemplate> > GetQuestTemplatesAsync()
 {
     await using var model = new TrinityDatabase();
     return(await GetQuestsQuery(model).ToListAsync <IQuestTemplate>());
 }
示例#22
0
        public IEnumerable <IQuestTemplate> GetQuestTemplates()
        {
            using var model = new TrinityDatabase();

            return(GetQuestsQuery(model).ToList <IQuestTemplate>());
        }
示例#23
0
 public IEnumerable <IGameObjectTemplate> GetGameObjectTemplates()
 {
     using var model = new TrinityDatabase();
     return((from t in model.GameObjectTemplate orderby t.Entry select t).ToList <IGameObjectTemplate>());
 }
示例#24
0
 public IGameObjectTemplate?GetGameObjectTemplate(uint entry)
 {
     using var model = new TrinityDatabase();
     return(model.GameObjectTemplate.FirstOrDefault(g => g.Entry == entry));
 }
示例#25
0
 public ICreatureTemplate?GetCreatureTemplate(uint entry)
 {
     using var model = new TrinityDatabase();
     return(model.CreatureTemplate.FirstOrDefault(ct => ct.Entry == entry));
 }