public async Task <IQuery> GenerateSql(QuestChainSolutionItem item) { var store = new QuestStore(questTemplateSource); foreach (var q in item.Entries) { store.LoadQuest(q); } var query = queryGenerator.Generate(store); return(sqlGenerator.GenerateQuery(query.ToList(), item.ExistingData)); }
public IEnumerable <ChainRawData> Generate(QuestStore questStore) { Dictionary <uint, ChainRawData> datas = new(); foreach (var q in questStore) { datas[q.Entry] = new(q.Entry); } foreach (var q in questStore) { if (q.Requirements.Count == 1) { var group = q.Requirements[0]; if (group.Quests.Count == 1) { var requirement = group.Quests[0]; if (group.RequirementType == QuestRequirementType.MustBeActive) { datas[q.Entry].PrevQuestId = -(int)requirement; } else if (group.RequirementType == QuestRequirementType.Breadcrumb) { datas[requirement].BreadcrumbQuestId = (int)q.Entry; } else { datas[q.Entry].PrevQuestId = (int)requirement; } } else if (group.Quests.Count > 0) { int exclusiveGroup = (int)(group.Quests.Min()); if (group.RequirementType == QuestRequirementType.MustBeActive) { throw new Exception("Cannot handle exclusive group with multiple quests"); } else if (group.RequirementType == QuestRequirementType.AllCompleted) { exclusiveGroup = -exclusiveGroup; } else if (group.RequirementType == QuestRequirementType.OnlyOneCompleted) { exclusiveGroup = exclusiveGroup; } else if (group.RequirementType == QuestRequirementType.Breadcrumb) { exclusiveGroup = exclusiveGroup; } foreach (var requirement in group.Quests) { datas[requirement].ExclusiveGroup = exclusiveGroup; if (group.RequirementType == QuestRequirementType.Breadcrumb) { datas[requirement].BreadcrumbQuestId = (int)q.Entry; } else { datas[requirement].NextQuestId = (int)q.Entry; } } } } else if (q.Requirements.Count > 0) { foreach (var group in q.Requirements) { if (group.Quests.Count == 1) { var requirement = group.Quests[0]; if (group.RequirementType == QuestRequirementType.MustBeActive) { throw new Exception("Cannot handle single quest with multiple quests as active requirement"); } else if (group.RequirementType == QuestRequirementType.Breadcrumb) { throw new Exception("Cannot handle single quest with multiple quests as breadcrumb requirement"); } else { datas[requirement].NextQuestId = (int)q.Entry; } } else if (group.Quests.Count > 0) { int exclusiveGroup = (int)(group.Quests.Min()); if (group.RequirementType == QuestRequirementType.MustBeActive) { throw new Exception("Cannot handle exclusive group with multiple quests"); } else if (group.RequirementType == QuestRequirementType.AllCompleted) { exclusiveGroup = -exclusiveGroup; } else if (group.RequirementType == QuestRequirementType.OnlyOneCompleted || group.RequirementType == QuestRequirementType.Breadcrumb) { exclusiveGroup = exclusiveGroup; } foreach (var requirement in group.Quests) { datas[requirement].ExclusiveGroup = exclusiveGroup; if (group.RequirementType == QuestRequirementType.Breadcrumb) { datas[requirement].BreadcrumbQuestId = (int)q.Entry; } else { datas[requirement].NextQuestId = (int)q.Entry; } } } } } } return(datas.Values); }