Skip to content

Commit

Permalink
rework logging and implemeted debug logging for prerequisites
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSav committed May 10, 2024
1 parent 503dc3c commit a9fc1da
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 247 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore lib.remnant2.analyzer.csproj
- name: Set Version Variable
if: ${{ github.ref_type == 'tag' }}
env:
TAG: ${{ github.ref_name }}
run: echo "VERSION=${TAG#v}" >> $GITHUB_ENV
- name: Build
run: dotnet build lib.remnant2.analyzer.csproj -c Release --no-restore /p:Version=$VERSION
#- name: Pack
# run: dotnet pack
- name: Create Release
uses: softprops/action-gh-release@v2
- name: Push
if: github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v')
run: dotnet nuget push bin/Release/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
63 changes: 35 additions & 28 deletions Analyzer.LootGroups.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using lib.remnant2.analyzer.Model;
using System.Runtime.ConstrainedExecution;
using System.Text.RegularExpressions;
using Serilog;

namespace lib.remnant2.analyzer;

Expand All @@ -9,9 +9,21 @@ public partial class Analyzer
[GeneratedRegex(@"([^|,]+)|(\|)|(,)")]
private static partial Regex RegexPrerequisite();

private static List<string> FillLootGroups(RolledWorld world, Profile profile, List<string> accountAwards)
private static void FillLootGroups(RolledWorld world, Profile profile, List<string> accountAwards)
{
List<string> debugMessages = [];
int characterSlot = world.Character.Index;
int characterIndex = world.Character.Dataset.Characters.FindIndex(x => x == world.Character);
string mode = world.Zones.Exists(x => x.Name == "Labyrinth") ? "campaign" : "adventure";

ILogger logger = Log.Logger
.ForContext(Log.Category, Log.UnknownItems)
.ForContext("RemnantNotificationType", "Warning")
.ForContext("SourceContext", "Analyzer:LootGroups");

ILogger prerequisiteLogger = Log.Logger
.ForContext(Log.Category, Log.Prerequisites)
.ForContext("SourceContext", "Analyzer:LootGroups");

// Add items to locations
foreach (Zone zz in world.AllZones)
{
Expand Down Expand Up @@ -63,7 +75,7 @@ private static List<string> FillLootGroups(RolledWorld world, Profile profile, L

if (ev == null)
{
debugMessages.Add($"Event: Drop reference '{dropReference.Name}' found in the save but is absent from the database");
logger.Warning($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, Event: Drop reference '{dropReference.Name}' found in the save but is absent from the database");
lg = new LootGroup
{
Items = [],
Expand Down Expand Up @@ -106,7 +118,7 @@ private static List<string> FillLootGroups(RolledWorld world, Profile profile, L
UnknownData unknown = UnknownData.None;
foreach (DropReference s in l.WorldDrops.Where(x => x.Name != "Bloodmoon" && !ItemDb.HasItem(x.Name)))
{
debugMessages.Add($"World Drop: Drop reference {s.Name} is absent from the database (world drop {l.Name})");
logger.Warning($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, World Drop: Drop reference {s.Name} is absent from the database (world drop {l.Name})");
Dictionary<string, string> unknownItem = new()
{
{ "Name", s.Name },
Expand Down Expand Up @@ -153,7 +165,7 @@ private static List<string> FillLootGroups(RolledWorld world, Profile profile, L
LootItem? li = ItemDb.GetItemByProfileId(m.ProfileId);
if (li == null)
{
debugMessages.Add($"Looted marker not found in database: {m.ProfileId}");
logger.Warning($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, Looted marker not found in database: {m.ProfileId}");
continue;
}

Expand All @@ -169,7 +181,6 @@ private static List<string> FillLootGroups(RolledWorld world, Profile profile, L
}

// Mark items that cannot be obtained because no prerequisite
// TODO: need to have debug logging here to troubleshoot why item is shown/not shown
foreach (Zone zz in world.AllZones)
{
foreach (Location l in zz.Locations)
Expand All @@ -180,11 +191,10 @@ private static List<string> FillLootGroups(RolledWorld world, Profile profile, L
{
if (i.Item.TryGetValue("Prerequisite", out string? prerequisite))
{
List<string> prerequisiteDebugMessages = [];
List<string> prerequisiteExpressionTokens = RegexPrerequisite().Matches(prerequisite)
.Select(x => x.Value.Trim()).ToList();

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

bool Check(string cur)
{
Expand All @@ -194,54 +204,54 @@ bool Check(string cur)
{
if (accountAwards.Contains(cur))
{
prerequisiteDebugMessages.Add($"Have '{cur}'");
prerequisiteLogger.Information($" Have '{cur}'");
return true;
}
if (world.CanGetAccountAward(cur))
{
prerequisiteDebugMessages.Add($"Can get '{cur}'");
prerequisiteLogger.Information($" Can get '{cur}'");
return true;
}
prerequisiteDebugMessages.Add($"Do not have and cannot get '{cur}'");
prerequisiteLogger.Information($" Do not have and cannot get '{cur}'");
return false;
}

if (item.Type == "challenge")
{
//if (world.Character.Profile.IsObjectiveAchieved(cur))
//{
// prerequisiteDebugMessages.Add($"Have '{item.Name}'");
// return true;
//}
if (world.Character.Profile.IsObjectiveAchieved(cur))
{
prerequisiteLogger.Information($" Have '{item.Name}'");
return true;
}
if (world.CanGetChallenge(cur))
{
prerequisiteDebugMessages.Add($"Can get '{item.Name}'");
prerequisiteLogger.Information($" Can get '{item.Name}'");
return true;
}
prerequisiteDebugMessages.Add($"Do not have and cannot get '{item.Name}'");
prerequisiteLogger.Information($" Do not have and cannot get '{item.Name}'");
return false;
}

string itemProfileId = item.Item["ProfileId"];
if (profile.Inventory.Select(y => y.ToLowerInvariant()).Contains(itemProfileId.ToLowerInvariant()))
{
prerequisiteDebugMessages.Add($"Have '{cur}'");
prerequisiteLogger.Information($" Have '{cur}'");
return true;
}

if (world.QuestInventory.Select(y => y.ToLowerInvariant()).Contains(itemProfileId.ToLowerInvariant()))
{
prerequisiteDebugMessages.Add($"Have '{cur}'");
prerequisiteLogger.Information($" Have '{cur}'");
return true;
}

if (world.CanGetItem(cur))
{
prerequisiteDebugMessages.Add($"Can get '{cur}'");
prerequisiteLogger.Information($" Can get '{cur}'");
return true;
}

prerequisiteDebugMessages.Add($"Do not have and cannot get '{cur}'");
prerequisiteLogger.Information($" Do not have and cannot get '{cur}'");
return false;
}

Expand All @@ -267,19 +277,16 @@ bool Check(string cur)
if (!res)
{
i.IsPrerequisiteMissing = true;
prerequisiteDebugMessages.Add($"Prerequisite check NEGATIVE for '{prerequisite}'");
prerequisiteLogger.Information($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, Prerequisite check NEGATIVE for '{prerequisite}'");
}
else
{
prerequisiteDebugMessages.Add($"Prerequisite check POSITIVE for '{prerequisite}'");
prerequisiteLogger.Information($"Character {characterIndex} (save_{characterSlot}), mode: {mode}, Prerequisite check POSITIVE for '{prerequisite}'");
}
//debugMessages.AddRange(prerequisiteDebugMessages);
}
}
}
}
}

return debugMessages;
}
}
Loading

0 comments on commit a9fc1da

Please sign in to comment.