Skip to content

Commit

Permalink
run custom scripts before detecting prerequisites, so that prerequisi…
Browse files Browse the repository at this point in the history
…tes could be detected correctly
  • Loading branch information
AndrewSav committed Jan 11, 2025
1 parent 6e14801 commit 49ac9b8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
62 changes: 45 additions & 17 deletions Analyzer.LootGroups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LootItemContext, bool>? 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))
Expand All @@ -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<LootItemContext, bool>? 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<LootGroup>(location.LootGroups))
{
lootGroup.Items.Remove(lootItem);
bool emptyBeforePrerequisitesCheck = lootGroup.Items.Count == 0;
foreach (LootItem item in new List<LootItem>(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)
Expand All @@ -271,7 +298,7 @@ void ProcessPrerequisitesAndScripts(Zone? zone, Location? location, LootGroup lo
bool emptyBeforePrerequisitesCheck = lootGroup.Items.Count == 0;
foreach (LootItem item in new List<LootItem>(lootGroup.Items))
{
ProcessPrerequisitesAndScripts(zone, location, lootGroup, item);
ProcessPrerequisites(zone, location, lootGroup, item);
}

if (lootGroup.Items.Count == 0 && !emptyBeforePrerequisitesCheck)
Expand All @@ -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()
Expand All @@ -293,7 +320,8 @@ void ProcessPrerequisitesAndScripts(Zone? zone, Location? location, LootGroup lo
world.AdditionalItems.Add(progression);
foreach (LootItem item in new List<LootItem>(progression.Items))
{
ProcessPrerequisitesAndScripts(null, null, progression, item);
ProcessScripts(null, null, progression, item);
ProcessPrerequisites(null, null, progression, item);
}
operation.Complete();

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions CustomScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Func<LootItemContext, bool>> PrerequisitesScripts = new()
{
{ "Amulet_EchoOfTheForest", EchoOfTheForest },
Expand Down

0 comments on commit 49ac9b8

Please sign in to comment.