From 49ac9b809a4a282cee4ba3d97c08a0fc3066efb3 Mon Sep 17 00:00:00 2001 From: Andrew Savinykh <658865+AndrewSav@users.noreply.github.com> Date: Sun, 12 Jan 2025 12:27:24 +1300 Subject: [PATCH] run custom scripts before detecting prerequisites, so that prerequisites could be detected correctly --- Analyzer.LootGroups.cs | 62 ++++++++++++++++++++++++++++++------------ CHANGELOG.md | 4 +++ CustomScripts.cs | 2 ++ 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/Analyzer.LootGroups.cs b/Analyzer.LootGroups.cs index 6c13049..50818d5 100644 --- a/Analyzer.LootGroups.cs +++ b/Analyzer.LootGroups.cs @@ -224,7 +224,26 @@ private static void FillLootGroups(RolledWorld world) operation.Complete(); - void ProcessPrerequisitesAndScripts(Zone? zone, Location? location, LootGroup lootGroup, LootItem lootItem) + void ProcessScripts(Zone? zone, Location? location, LootGroup lootGroup, LootItem lootItem) + { + if (CustomScripts.Scripts.TryGetValue(lootItem.Id, out Func? func)) + { + LootItemContext lic = new() + { + LootItem = lootItem, + Location = location, + LootGroup = lootGroup, + World = world, + Zone = zone + }; + if (!func(lic)) + { + lootGroup.Items.Remove(lootItem); + } + } + } + + void ProcessPrerequisites(Zone? zone, Location? location, LootGroup lootGroup, LootItem lootItem) { if (lootItem.Properties.TryGetValue("Prerequisite", out string? prerequisite) || CustomScripts.PrerequisitesScripts.ContainsKey(lootItem.Id)) @@ -241,27 +260,35 @@ void ProcessPrerequisitesAndScripts(Zone? zone, Location? location, LootGroup lo prerequisiteLogger.Information($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, Prerequisite check POSITIVE for '{prerequisite}'"); } } + } - if (CustomScripts.Scripts.TryGetValue(lootItem.Id, out Func? func)) + + + // Process item custom scripts + operation = performanceLogger.BeginOperation($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, process scripts"); + foreach (Zone zone in world.AllZones) + { + foreach (Location location in zone.Locations) { - LootItemContext lic = new() - { - LootItem = lootItem, - Location = location, - LootGroup = lootGroup, - World = world, - Zone = zone - }; - if (!func(lic)) + foreach (LootGroup lootGroup in new List(location.LootGroups)) { - lootGroup.Items.Remove(lootItem); + bool emptyBeforePrerequisitesCheck = lootGroup.Items.Count == 0; + foreach (LootItem item in new List(lootGroup.Items)) + { + ProcessScripts(zone, location, lootGroup, item); + } + + if (lootGroup.Items.Count == 0 && !emptyBeforePrerequisitesCheck) + { + location.LootGroups.Remove(lootGroup); + } } } } + operation.Complete(); // Mark items that cannot be obtained because no prerequisite - // Process item custom scripts - operation = performanceLogger.BeginOperation($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, process prerequisites and scripts"); + operation = performanceLogger.BeginOperation($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, process prerequisites"); foreach (Zone zone in world.AllZones) { foreach (Location location in zone.Locations) @@ -271,7 +298,7 @@ void ProcessPrerequisitesAndScripts(Zone? zone, Location? location, LootGroup lo bool emptyBeforePrerequisitesCheck = lootGroup.Items.Count == 0; foreach (LootItem item in new List(lootGroup.Items)) { - ProcessPrerequisitesAndScripts(zone, location, lootGroup, item); + ProcessPrerequisites(zone, location, lootGroup, item); } if (lootGroup.Items.Count == 0 && !emptyBeforePrerequisitesCheck) @@ -282,7 +309,7 @@ void ProcessPrerequisitesAndScripts(Zone? zone, Location? location, LootGroup lo } } operation.Complete(); - + // Progression items are the items that are not tied to any particular location operation = performanceLogger.BeginOperation($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, progression items"); LootGroup progression = new() @@ -293,7 +320,8 @@ void ProcessPrerequisitesAndScripts(Zone? zone, Location? location, LootGroup lo world.AdditionalItems.Add(progression); foreach (LootItem item in new List(progression.Items)) { - ProcessPrerequisitesAndScripts(null, null, progression, item); + ProcessScripts(null, null, progression, item); + ProcessPrerequisites(null, null, progression, item); } operation.Complete(); diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b22b7f..914bfae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog +## v0.0.34 (12 Jan 2025) +- Fixed a bunch of game pass issues +- Fixed a subtle issue with evaluation oreder which caused Nimue Ribbon to be detected incorrectly in case both dark and light potential hosts for the ribbon event injectable spawn + ## v0.0.33 (12 Jan 2025) - Add support for Microsoft Game pass saves diff --git a/CustomScripts.cs b/CustomScripts.cs index dce4b8c..2f4ca98 100644 --- a/CustomScripts.cs +++ b/CustomScripts.cs @@ -42,6 +42,8 @@ public static bool CanGetChallenge(RolledWorld world, string id) { "Amulet_NecklaceOfFlowingLife", lic => { NecklaceOfFlowingLife(lic); return true; } } }; + // These are for the purpose of IsPrerequisiteMissing flag + // Unlike scripts above, these will cause the flag to be set, instead of removing the item from the detected list public static Dictionary> PrerequisitesScripts = new() { { "Amulet_EchoOfTheForest", EchoOfTheForest },