Skip to content

Commit a294cb8

Browse files
Merge pull request #716 from TheTrackerCouncil/ap-fixes
AP updates and location tracking fixes
2 parents 850e1f8 + 56d6ec7 commit a294cb8

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

src/TrackerCouncil.Smz3.Abstractions/ITrackerLocationService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public interface ITrackerLocationService
1818
/// <param name="location">The location to clear.</param>
1919
/// <param name="confidence">The speech recognition confidence.</param>
2020
/// <param name="autoTracked">If this was tracked by the auto tracker</param>
21-
void Clear(Location location, float? confidence = null, bool autoTracked = false, bool stateResponse = true, bool allowLocationComments = false, bool updateTreasureCount = true);
21+
/// <param name="stateResponse">If the location being cleared will be commented on by tracker</param>
22+
/// <param name="allowLocationComments">If location specific comments should be stated</param>
23+
/// <param name="updateTreasureCount">If the dungeon treasure count should be updated, if applicable</param>
24+
/// <param name="stateTreasureResponse">If the dungeon treasure count should be commented on. If not specified, the value of stateResponse will be used.</param>
25+
void Clear(Location location, float? confidence = null, bool autoTracked = false, bool stateResponse = true, bool allowLocationComments = false, bool updateTreasureCount = true, bool? stateTreasureResponse = null);
2226

2327
/// <summary>
2428
/// Unclears an item from the specified location.
Binary file not shown.

src/TrackerCouncil.Smz3.Tracking/AutoTracking/AutoTrackerModules/GiftedItemSync.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using Microsoft.Extensions.Logging;
45
using SnesConnectorLibrary;
@@ -85,21 +86,29 @@ private async void OnMemorySync(SnesData firstDataSet, SnesData? firstPrevData)
8586
{
8687
if (_itemDetailLength == 4)
8788
{
88-
// var fromPlayerId = firstBlockResponse.Data.ReadUInt16(i * 4)!.Value;
8989
var itemId = (ItemType)firstBlockResponse.Data.ReadUInt16(i * 4 + 2)!.Value;
9090
receivedItems.Add(Tracker.World.AllItems.First(x => x.Type == itemId && x.IsLocalPlayerItem));
9191
}
9292
else
9393
{
94-
// var fromPlayerId = firstBlockResponse.Data.ReadUInt8(i * 2)!.Value;
95-
var itemId = (ItemType)firstBlockResponse.Data.ReadUInt8(i * 2 + 1)!.Value;
96-
receivedItems.Add(Tracker.World.AllItems.First(x => x.Type == itemId && x.IsLocalPlayerItem));
94+
var itemId = firstBlockResponse.Data.ReadUInt8(i * 2 + 1)!.Value;
95+
try
96+
{
97+
var itemType = (ItemType)itemId;
98+
receivedItems.Add(Tracker.World.AllItems.First(x => x.Type == itemType && x.IsLocalPlayerItem));
99+
}
100+
catch (Exception)
101+
{
102+
logger.LogWarning("Invalid item type {Id} received", itemId);
103+
}
97104
}
98105
}
99106

100-
logger.LogInformation("Received Items: {Items}", string.Join(",", receivedItems));
101-
102-
Tracker.ItemTracker.TrackItems(receivedItems, true, true);
107+
if (receivedItems.Count > 0)
108+
{
109+
logger.LogInformation("Received Items: {Items}", string.Join(",", receivedItems));
110+
Tracker.ItemTracker.TrackItems(receivedItems, true, true);
111+
}
103112

104113
trackerState.GiftedItemCount = newItemCount.Value;
105114
await Tracker.SaveAsync();

src/TrackerCouncil.Smz3.Tracking/TrackingServices/TrackerItemService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public bool TrackItem(Item item, string? trackedAs = null, float? confidence = n
176176
{
177177
logger.LogInformation("Clearing location for item {ItemType}", item.Type.GetDescription());
178178

179-
Tracker.LocationTracker.Clear(location, confidence, autoTracked, stateResponse: false, allowLocationComments: true, updateTreasureCount: true);
179+
Tracker.LocationTracker.Clear(location, confidence, autoTracked, stateResponse: false, allowLocationComments: true, updateTreasureCount: true, stateTreasureResponse: true);
180180

181181
// If this is a parsed AP/Mainline rom and this is an item for another player, let's comment on it
182182
if (stateResponse && item is { IsLocalPlayerItem: false } && World.Config.RomGenerator != RomGenerator.Cas)
@@ -197,6 +197,8 @@ public bool TrackItem(Item item, string? trackedAs = null, float? confidence = n
197197
item.Metadata.NameWithArticle, item.PlayerName]);
198198
}
199199
}
200+
201+
return true;
200202
}
201203

202204
if (!didTrack)
@@ -233,7 +235,7 @@ public bool TrackItem(Item item, string? trackedAs = null, float? confidence = n
233235
// Clear the location if it's for the local player's world
234236
if (location != null && location.World == World && !location.Cleared)
235237
{
236-
Tracker.LocationTracker.Clear(location, confidence, autoTracked, !silent, true);
238+
Tracker.LocationTracker.Clear(location, confidence, autoTracked, !silent && !isGTPreBigKey, true);
237239
undoActions.Add(autoTracked ? null : PopUndo().Action);
238240
}
239241
}

src/TrackerCouncil.Smz3.Tracking/TrackingServices/TrackerLocationService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class TrackerLocationService(ILogger<TrackerTreasureService> logger, IP
2424
public event EventHandler<LocationClearedEventArgs>? LocationCleared;
2525
public event EventHandler<LocationClearedEventArgs>? LocationMarked;
2626

27-
public void Clear(Location location, float? confidence = null, bool autoTracked = false, bool stateResponse = true, bool allowLocationComments = false, bool updateTreasureCount = true)
27+
public void Clear(Location location, float? confidence = null, bool autoTracked = false, bool stateResponse = true, bool allowLocationComments = false, bool updateTreasureCount = true, bool? stateTreasureCount = null)
2828
{
2929
if (stateResponse && allowLocationComments)
3030
{
@@ -48,7 +48,7 @@ public void Clear(Location location, float? confidence = null, bool autoTracked
4848
}
4949

5050
var undoTrackTreasure = updateTreasureCount
51-
? Tracker.TreasureTracker.TryTrackDungeonTreasure(location, confidence, stateResponse: stateResponse)
51+
? Tracker.TreasureTracker.TryTrackDungeonTreasure(location, confidence, stateResponse: stateTreasureCount ?? stateResponse)
5252
: null;
5353

5454
// Important: clear only after tracking dungeon treasure, as

src/TrackerCouncil.Smz3.Tracking/TrackingServices/TrackerTreasureService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public bool UntrackDungeonTreasure(IHasTreasure region, int amount = 1)
121121
}
122122

123123
var dungeon = location.GetTreasureRegion();
124-
if (dungeon != null && (location.Item.IsTreasure || World.Config.ZeldaKeysanity))
124+
if (dungeon != null && (location.Item.IsTreasure || World.Config.ZeldaKeysanity || !location.Item.IsLocalPlayerItem))
125125
{
126126
if (TrackDungeonTreasure(dungeon, confidence, 1, autoTracked, stateResponse))
127127
{

0 commit comments

Comments
 (0)