From ed81b572f8168a6ae5b4debb9c0961668e206843 Mon Sep 17 00:00:00 2001 From: Chomp Date: Tue, 24 Jan 2023 09:59:24 +0000 Subject: [PATCH] Add ability to insert level prereqs to quest + add prereq of level 50 to `Collector` --- GenerateQuestFile/Program.cs | 78 +++++++++++++------ .../Helpers/QuestRequirements.cs | 18 ++++- 2 files changed, 68 insertions(+), 28 deletions(-) diff --git a/GenerateQuestFile/Program.cs b/GenerateQuestFile/Program.cs index ca7190a..8ac4ec3 100644 --- a/GenerateQuestFile/Program.cs +++ b/GenerateQuestFile/Program.cs @@ -84,7 +84,7 @@ namespace GenerateQuestFile AddQuestName(quest); var originalQuest = existingQuestData.FirstOrDefault(x => x.Key == quest.Key).Value; - + if (originalQuest is null) { LoggingHelpers.LogWarning($"Cant check for original start conditions. Unable to find original quest {quest.Key} {QuestHelper.GetQuestNameById(quest.Key)}, skipping."); @@ -112,37 +112,65 @@ namespace GenerateQuestFile if (questRequirements is null || questRequirements.Count == 0) { LoggingHelpers.LogWarning($"Quest requirement not found for : {quest.Value.QuestName}, skipping."); + continue; } foreach (var requirement in questRequirements) { - // Does quest have requirement - if (!quest.Value.conditions.AvailableForStart.Any(x => x._parent == "Quest" - && x._props.target.ToString() == requirement.Quest.Id)) + if (requirement.PreReqType == PreRequisiteType.Quest) { - LoggingHelpers.LogSuccess($"{quest.Value.QuestName} needs a prereq of quest {requirement.Quest.Name}, adding."); - quest.Value.conditions.AvailableForStart.Add(new AvailableFor + // Does quest have requirement + if (!quest.Value.conditions.AvailableForStart.Any(x => x._parent == "Quest" + && x._props.target.ToString() == requirement.Quest.Id)) { - _parent = "Quest", - _props = new AvailableForProps + LoggingHelpers.LogSuccess($"{quest.Value.QuestName} needs a prereq of quest {requirement.Quest.Name}, adding."); + quest.Value.conditions.AvailableForStart.Add(new AvailableFor { - id = Sha256(new DateTime().ToString()), - index = quest.Value.conditions.AvailableForStart.Count, - parentId = "", - status = GetQuestStatus(requirement.QuestStatus), - target = requirement.Quest.Id, - visibilityConditions = new List(), - availableAfter = 0 + _parent = "Quest", + _props = new AvailableForProps + { + id = Sha256(new DateTime().ToString()), + index = quest.Value.conditions.AvailableForStart.Count, + parentId = "", + status = GetQuestStatus(requirement.QuestStatus), + target = requirement.Quest.Id, + visibilityConditions = new List(), + availableAfter = 0 + } + } + ); + } + else + { + if (questRequirements != null) + { + LoggingHelpers.LogInfo($"{quest.Value.QuestName} already has prereq of quest {requirement.Quest.Name}, skipping."); } } - ); } - else + + if (requirement.PreReqType == PreRequisiteType.Level) { - if (questRequirements != null) + if (!quest.Value.conditions.AvailableForStart.Any(x => x._parent == "Level" + && int.Parse((string)x._props.value) == requirement.Level)) { - LoggingHelpers.LogInfo($"{quest.Value.QuestName} already has prereq of quest {requirement.Quest.Name}, skipping."); + LoggingHelpers.LogSuccess($"{quest.Value.QuestName} needs a prereq of level {requirement.Level}, adding."); + quest.Value.conditions.AvailableForStart.Add(new AvailableFor + { + _parent = "Level", + _props = new AvailableForProps + { + id = Sha256(new DateTime().ToString()), + index = quest.Value.conditions.AvailableForStart.Count, + parentId = "", + dynamicLocale = false, + value = requirement.Level, + compareMethod = ">=", + visibilityConditions = new List() + } + } + ); } } } @@ -166,8 +194,8 @@ namespace GenerateQuestFile } } } - - // JsonWriter.WriteJson(output, "output", Directory.GetCurrentDirectory(), "questRequirements"); + + // JsonWriter.WriteJson(output, "output", Directory.GetCurrentDirectory(), "questRequirements"); } private static void OutputQuestRequirementsToConsole2(Dictionary quests) @@ -230,7 +258,7 @@ namespace GenerateQuestFile // findInRaid foreach (var success in quest.Value.rewards.Success) { - if (string.Equals(success.type, "item", StringComparison.OrdinalIgnoreCase) + if (string.Equals(success.type, "item", StringComparison.OrdinalIgnoreCase) && success.findInRaid == null) { success.findInRaid = true; @@ -286,18 +314,18 @@ namespace GenerateQuestFile { questRequirementToAdd._props.availableAfter = 0; } - + if (questRequirementToAdd._props.visibilityConditions == null || !questRequirementToAdd._props.visibilityConditions.Any()) { questRequirementToAdd._props.visibilityConditions = new List(); } questRequirementToAdd._props.index = questToUpdate.Value.conditions.AvailableForStart.Count; - + } // Already exists, skip - if(questToUpdate.Value.conditions.AvailableForStart + if (questToUpdate.Value.conditions.AvailableForStart .Any(x => x._props.target?.ToString() == questRequirementToAdd._props.target?.ToString() && x._parent == questRequirementToAdd._parent)) { diff --git a/QuestValidator.Common/Helpers/QuestRequirements.cs b/QuestValidator.Common/Helpers/QuestRequirements.cs index ec9691c..4be6582 100644 --- a/QuestValidator.Common/Helpers/QuestRequirements.cs +++ b/QuestValidator.Common/Helpers/QuestRequirements.cs @@ -15,7 +15,16 @@ namespace QuestValidator.Common.Helpers { // TODO: add check if desired prereq is same id as quest, prevent it - (PreRequisites ??= new List()).Add(new PreRequisite { Quest = GetQuestData(quest), QuestStatus = status }); + (PreRequisites ??= new List()).Add(new PreRequisite { PreReqType = PreRequisiteType.Quest, Quest = GetQuestData(quest), QuestStatus = status }); + + return this; + } + + public QuestData AddPrerequisiteLevel(int level) + { + // TODO: add check if level prereq exits already, dont add + + (PreRequisites ??= new List()).Add(new PreRequisite { PreReqType = PreRequisiteType.Level, Level = level }); return this; } @@ -23,8 +32,10 @@ namespace QuestValidator.Common.Helpers public class PreRequisite { + public PreRequisiteType PreReqType { get; set; } public QuestStatus QuestStatus { get; set; } public QuestData Quest { get; set; } + public int Level { get; set; } } private static readonly Dictionary questWithPreceedingQuestDict = new Dictionary @@ -359,7 +370,8 @@ namespace QuestValidator.Common.Helpers .AddPrerequisiteQuest(Quest.ShakingUpTeller, QuestStatus.Success) }, { Quest.Import, GetQuestData(Quest.Import) .AddPrerequisiteQuest(Quest.FarmingP4, QuestStatus.Success) }, - { Quest.Collector, GetQuestData(Quest.Collector) }, + { Quest.Collector, GetQuestData(Quest.Collector) + .AddPrerequisiteLevel(50)}, { Quest.Introduction, GetQuestData(Quest.Introduction) .AddPrerequisiteQuest(Quest.GunsmithP1, QuestStatus.Started)}, { Quest.Acquaintance, GetQuestData(Quest.Acquaintance) @@ -687,7 +699,7 @@ namespace QuestValidator.Common.Helpers // .AddPrerequisiteQuest(Quest., QuestStatus.Success)} }; -private static QuestData GetQuestData(Quest quest) + private static QuestData GetQuestData(Quest quest) { return new QuestData {