Skip to content

Commit

Permalink
Merge pull request #104 from Vivelin/fix/clear-dungeon
Browse files Browse the repository at this point in the history
Fixed multiple dungeon-clearing issues
  • Loading branch information
Vivelin authored Mar 31, 2022
2 parents fdc931b + d09e67f commit 0dfafbb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/Randomizer.SMZ3.Tracking/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,15 @@ public void ClearArea(IHasLocations area, bool trackItems, bool includeUnavailab
{
Say(x => x.ClearedMultipleItems, itemsCleared, area.GetName());
}

if (treasureTracked > 0)
{
var dungeon = GetDungeonFromArea(area);
if (dungeon != null)
{
TrackDungeonTreasure(dungeon, amount: treasureTracked);
}
}
}
OnItemTracked(new ItemTrackedEventArgs(null, confidence));
}
Expand Down Expand Up @@ -1550,9 +1559,12 @@ public void ClearDungeon(DungeonInfo dungeon, float? confidence = null)
if (remaining > 0)
{
dungeon.TreasureRemaining = 0;
dungeon.Cleared = true;
}

// Clear the dungeon only if there's no bosses to defeat
if (!dungeon.HasReward)
dungeon.Cleared = true;

var progress = GetProgression();
var locations = dungeon.GetLocations(World).Where(x => !x.Cleared).ToList();
var inaccessibleLocations = locations.Where(x => !x.IsAvailable(progress)).ToList();
Expand Down Expand Up @@ -1592,7 +1604,7 @@ public void ClearDungeon(DungeonInfo dungeon, float? confidence = null)
AddUndo(() =>
{
dungeon.TreasureRemaining = remaining;
if (remaining > 0)
if (remaining > 0 && !dungeon.HasReward)
dungeon.Cleared = false;
locations.ForEach(x => x.Cleared = false);
});
Expand Down Expand Up @@ -2164,6 +2176,16 @@ private static bool IsTreasure(Item? item)
return WorldInfo.Dungeons.SingleOrDefault(x => x.Is(location.Region));
}

private DungeonInfo? GetDungeonFromArea(IHasLocations area)
{
return area switch
{
Room room => WorldInfo.Dungeons.SingleOrDefault(x => x.Is(room.Region)),
Region region => WorldInfo.Dungeons.SingleOrDefault(x => x.Is(region)),
_ => null
};
}

private Action? TryTrackDungeonTreasure(ItemData item, float? confidence)
{
if (confidence < Options.MinimumSassConfidence)
Expand Down
6 changes: 5 additions & 1 deletion src/Randomizer.SMZ3.Tracking/locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,11 @@
"Lumberjack Ledge"
],
"X": 633,
"Y": 117
"Y": 117,
"WhenMarkingJunk": [ "That's a relief, I'm sure.", "Not an Aga seed then?" ],
"WhenMarkingProgression": [ "Sucks to be you." ],
"WhenTrackingJunk": [ "Why did you bother?" ],
"WhenTrackingProgression": [ "Well, at least you got something." ]
},
{
"Id": 274,
Expand Down

0 comments on commit 0dfafbb

Please sign in to comment.