Skip to content

Commit

Permalink
add check for 10 corrupted shards for corrupted weapon prerequisites
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSav committed Jul 20, 2024
1 parent 9ded26c commit 085dda3
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 38 deletions.
78 changes: 51 additions & 27 deletions Analyzer.LootGroups.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using lib.remnant2.analyzer.Model;
using System.Runtime.InteropServices;
using lib.remnant2.analyzer.Model;
using System.Text.RegularExpressions;
using Serilog;
using SerilogTimings.Extensions;
Expand Down Expand Up @@ -213,7 +214,8 @@ private static void FillLootGroups(RolledWorld world)

void ProcessPrerequisitesAndScripts(Zone? zone, Location? location, LootGroup lootGroup, LootItem lootItem)
{
if (lootItem.Properties.TryGetValue("Prerequisite", out string? prerequisite))
if (lootItem.Properties.TryGetValue("Prerequisite", out string? prerequisite) ||
CustomScripts.PrerequisitesScripts.ContainsKey(lootItem.Id))
{
bool res = CheckPrerequisites(world, lootItem, prerequisite);

Expand Down Expand Up @@ -319,7 +321,7 @@ internal static IEnumerable<LootItem> GetItemsWithMaterials(IEnumerable<Inventor
}
}

internal static bool CheckPrerequisites(RolledWorld world, LootItem item, string prerequisite, bool checkHave = true, bool checkCanGet = true)
internal static bool CheckPrerequisites(RolledWorld world, LootItem item, string? prerequisite, bool checkHave = true, bool checkCanGet = true)
{
if (!checkHave && !checkCanGet) return true;

Expand All @@ -332,12 +334,53 @@ internal static bool CheckPrerequisites(RolledWorld world, LootItem item, string
.ForContext(Log.Category, Log.Prerequisites)
.ForContext("SourceContext", "Analyzer:LootGroups");

bool CheckAdditionalPrerequisite(string cur)
{
if (CustomScripts.PrerequisitesScripts.TryGetValue(cur, out Func<LootItemContext, bool>? script))
{
prerequisiteLogger.Information($" Running custom prerequisite script for '{cur}'");
var li = world.AllZones
.SelectMany(x => x.Locations.Select(y => new { Zone = x, Location = y }))
.SelectMany(x => x.Location.LootGroups.Select(y => new { x.Zone, x.Location, LootGroup = y }))
.SelectMany(x =>
x.LootGroup.Items.Select(y => new { x.Zone, x.Location, x.LootGroup, LootItem = y }))
.Single(x => x.LootItem.Id == cur);

// If we already determined that a prerequisite is missing, do not check again
if (li.LootItem.IsPrerequisiteMissing)
{
prerequisiteLogger.Information($" Skip custom prerequisite script for '{cur}' since it is marked with IsPrerequisiteMissing already");
return false;
}

List<string> prerequisiteExpressionTokens = RegexPrerequisite().Matches(prerequisite)
.Select(x => x.Value.Trim()).ToList();
LootItemContext lic = new()
{
LootItem = li.LootItem,
Location = li.Location,
LootGroup = li.LootGroup,
World = world,
Zone = li.Zone
};
bool ok = script(lic);
prerequisiteLogger.Information($" Custom prerequisite script for '{cur}' returned '{ok}'. (true - ok, false - missing prerequisite detected)");
if (!ok)
{
li.LootItem.IsPrerequisiteMissing = true;
}
return ok;
}
return true;
}

if (!CheckAdditionalPrerequisite(item.Id)) return false;

if (prerequisite == null) return true;

prerequisiteLogger.Information($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, Processing prerequisites for {item.Name}. '{prerequisite}'");

List<string> prerequisiteExpressionTokens = RegexPrerequisite().Matches(prerequisite)
.Select(x => x.Value.Trim()).ToList();

bool Check(string cur)
{
LootItem currentItem = ItemDb.GetItemById(cur);
Expand Down Expand Up @@ -390,29 +433,10 @@ bool Check(string cur)

if (world.CanGetItem(cur) && checkCanGet)
{
if (CustomScripts.PrerequisitesScripts.TryGetValue(cur, out Action<LootItemContext>? script))
if (!CheckAdditionalPrerequisite(cur))
{
prerequisiteLogger.Information($" Running custom prerequisite script for '{cur}'");
var li = world.AllZones
.SelectMany(x => x.Locations.Select(y => new { Zone = x, Location = y }))
.SelectMany(x => x.Location.LootGroups.Select(y => new { x.Zone, x.Location, LootGroup = y }))
.SelectMany(x => x.LootGroup.Items.Select(y => new { x.Zone, x.Location, x.LootGroup, LootItem = y }))
.Single(x => x.LootItem.Id == cur);

LootItemContext lic = new()
{
LootItem = li.LootItem,
Location = li.Location,
LootGroup = li.LootGroup,
World = world,
Zone = li.Zone
};
script(lic);
if (li.LootItem.IsPrerequisiteMissing)
{
prerequisiteLogger.Information($" Cannot get '{cur}' due to custom prerequisite script");
return false;
}
prerequisiteLogger.Information($" Cannot get '{cur}' due to additional prerequisites");
return false;
}
prerequisiteLogger.Information($" Can get '{cur}'");
return true;
Expand Down
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Changelog

## v0.0.23 (Unreleased)
- Fix compatibility with changes in the saves library
- Add Relic Charges
## v0.0.23 (20 July 2024)
- Fixed compatibility with changes in the saves library
- Added Relic Charges
- Fixed notes for Game Master's Pride
- Added check for 10 corrupted shards for corrupted weapon prerequisites

## v0.0.22 (2 July 2024)
- Update dependencies
- Updated dependencies

## v0.0.21 (2 July 2024)
- Fix regression with connections showing x2 for non-Yaesha zones
- Fixed regression with connections showing x2 for non-Yaesha zones
- Formatting and typo fixes

## v0.0.20 (13 June 2024)
Expand Down
16 changes: 12 additions & 4 deletions CustomScripts.Items.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ private static bool Anguish(LootItemContext lic)
}

// Additional Prerequisites detection ----------------------------------------------------------------------------------------------------------
// Return true if additional check passes, returns false if additional prerequisites are missing

private static void EchoOfTheForest(LootItemContext lic)
private static bool EchoOfTheForest(LootItemContext lic)
{
string counterItemProfileId = "/Game/World_DLC2/Quests/Quest_Story_DLC2/Items/Quest_Hidden_Item_Trinity_Counter.Quest_Hidden_Item_Trinity_Counter_C";

Expand All @@ -252,11 +253,18 @@ private static void EchoOfTheForest(LootItemContext lic)
string mementoItemName = "/Game/World_DLC2/Quests/Quest_Story_DLC2/Items/Quest_Item_Story_DwellsItem/Quest_Item_Story_DwellsItem.Quest_Item_Story_DwellsItem_C";
bool hasMemento = lic.World.QuestInventory.Any(x => x.ProfileId == mementoItemName);

lic.LootItem.IsPrerequisiteMissing = counter < 2 || counter < 3 && !(hasMemento || mementoAvailable);
return !(counter < 2 || counter < 3 && !(hasMemento || mementoAvailable));
}


private static bool CorruptedWeapon(LootItemContext lic)
{
string corruptedShardProfileId = "/Game/World_Base/Items/Materials/LumeniteCrystal/Material_CorruptedShard.Material_CorruptedShard_C";
InventoryItem? corruptedShardItem = lic.World.ParentCharacter.Profile.Inventory.SingleOrDefault(x => x.ProfileId == corruptedShardProfileId);
return corruptedShardItem?.Quantity >= 10;
}

// Additional IsLooted detection ----------------------------------------------------------------------------------------------------------

private static void Deceit(LootItemContext lic)
{
// If Faelin / Faerlin is killed, you cannot get the weapon from the other either
Expand Down
12 changes: 11 additions & 1 deletion CustomScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@ public static bool CanGetChallenge(RolledWorld world, string id)
{ "Amulet_NecklaceOfFlowingLife", lic => { NecklaceOfFlowingLife(lic); return true; } }
};

public static Dictionary<string, Action<LootItemContext>> PrerequisitesScripts = new()
public static Dictionary<string, Func<LootItemContext, bool>> PrerequisitesScripts = new()
{
{ "Amulet_EchoOfTheForest", EchoOfTheForest },
{ "Weapon_CorruptedAphelion", CorruptedWeapon },
{ "Weapon_CorruptedDeceit", CorruptedWeapon },
{ "Weapon_CorruptedMerciless", CorruptedWeapon },
{ "Weapon_CorruptedMeridian", CorruptedWeapon },
{ "Weapon_CorruptedRunePistol", CorruptedWeapon },
{ "Weapon_CorruptedSavior", CorruptedWeapon },
{ "Weapon_CorruptedCubeGun", CorruptedWeapon },
{ "Weapon_CorruptedNebula", CorruptedWeapon },
{ "Weapon_CorruptedSorrow", CorruptedWeapon },
{ "Weapon_CorruptedTwistedArbalest", CorruptedWeapon }
};

public static Dictionary<string, Func<RolledWorld, string, bool>> CanGetChallengeFunctions = new()
Expand Down
2 changes: 1 addition & 1 deletion lib.remnant2.analyzer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="lib.remnant2.saves" Version="0.0.15" />
<PackageReference Include="lib.remnant2.saves" Version="0.0.16" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="SerilogTimings" Version="3.1.0" />
Expand Down

0 comments on commit 085dda3

Please sign in to comment.