Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/TrackerCouncil.Smz3.Abstractions/AutoTrackerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public abstract class AutoTrackerBase : IDisposable
/// </summary>
public event EventHandler? AutoTrackerDisconnected;

/// <summary>
/// Occurs when the tracker detects that the game has changed
/// </summary>
public event EventHandler? GameChanged;

/// <summary>
/// The action to run when the player asks Tracker to look at the game
/// </summary>
Expand Down Expand Up @@ -156,5 +161,13 @@ protected virtual void OnAutoTrackerConnectorChanged()
AutoTrackerConnectorChanged?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Invokes the GameChanged event
/// </summary>
protected virtual void OnGameChanged()
{
GameChanged?.Invoke(this, EventArgs.Empty);
}

public abstract void Dispose();
}
7 changes: 6 additions & 1 deletion src/TrackerCouncil.Smz3.Abstractions/ITrackerModeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ public interface ITrackerModeService
/// <param name="confidence">The speech recognition confidence.</param>
public void Peg(float? confidence = null);

public void SetPegs(int count);
/// <summary>
/// Updates the number of pegs by auto tracker
/// </summary>
/// <param name="count">The current number of pegs</param>
/// <returns>True if the peg count was updated, false otherwise</returns>
public bool SetPegs(int count);

/// <summary>
/// Starts Peg World mode.
Expand Down
2 changes: 2 additions & 0 deletions src/TrackerCouncil.Smz3.Tracking/AutoTracking/AutoTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private void SnesConnectorServiceOnDisconnected(object? sender, EventArgs e)

HasStarted = false;
CurrentGame = Game.Neither;
OnGameChanged();
_hasValidState = false;

if (_numDisconnects > 10)
Expand Down Expand Up @@ -200,6 +201,7 @@ public override void UpdateGame(Game game)
{
PreviousGame = CurrentGame;
CurrentGame = game;
OnGameChanged();
}

public override void UpdateValidState(bool hasValidState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using TrackerCouncil.Smz3.Abstractions;
using TrackerCouncil.Smz3.Data.Tracking;
using TrackerCouncil.Smz3.Shared.Enums;
Expand All @@ -9,16 +11,19 @@ namespace TrackerCouncil.Smz3.Tracking.AutoTracking.MetroidStateChecks;
/// Metroid state check for nearing Shaktool
/// Player enters the room with the grapple block from the left
/// </summary>
public class Shaktool : IMetroidStateCheck
public class Shaktool(TrackerBase tracker) : IMetroidStateCheck
{
private readonly HashSet<int> _shaktoolRooms = [70, 154, 197, 208];
private bool _enabledOnGameChangedCheck;

/// <summary>
/// Executes the check for the current state
/// </summary>
/// <param name="tracker">The tracker instance</param>
/// <param name="trackerBase">The tracker instance</param>
/// <param name="currentState">The current state in Super Metroid</param>
/// <param name="prevState">The previous state in Super Metroid</param>
/// <returns>True if the check was identified, false otherwise</returns>
public bool ExecuteCheck(TrackerBase tracker, AutoTrackerMetroidState currentState, AutoTrackerMetroidState prevState)
public bool ExecuteCheck(TrackerBase trackerBase, AutoTrackerMetroidState currentState, AutoTrackerMetroidState prevState)
{
if (currentState is { CurrentRegion: 4, CurrentRoomInRegion: 36 } && prevState.CurrentRoomInRegion == 28 &&
tracker.World.FindLocation(LocationId.InnerMaridiaSpringBall).Cleared != true &&
Expand All @@ -27,17 +32,46 @@ public bool ExecuteCheck(TrackerBase tracker, AutoTrackerMetroidState currentSta
tracker.ShutUp();
tracker.Say(x => x.AutoTracker.NearShaktool, once: true);
tracker.ModeTracker.StartShaktoolMode();
EnableGameChangedCheck();
return true;
}

if (tracker.ModeTracker.ShaktoolMode &&
((currentState is { CurrentRegion: 4, CurrentRoomInRegion: 28 } && prevState.CurrentRoomInRegion == 36) ||
currentState.CurrentRegion != 4))
if (tracker.ModeTracker.ShaktoolMode && (currentState.CurrentRoom == null ||
!_shaktoolRooms.Contains(currentState.CurrentRoom.Value)))
{
tracker.ModeTracker.StopShaktoolMode();
DisableShaktoolMode();
return true;
}

return false;
}

private void EnableGameChangedCheck()
{
if (_enabledOnGameChangedCheck || tracker.AutoTracker == null) return;
_enabledOnGameChangedCheck = true;
tracker.AutoTracker.GameChanged += AutoTrackerOnGameChanged;
}

private void DisableGameChangedCheck()
{
if (!_enabledOnGameChangedCheck || tracker.AutoTracker == null ) return;
_enabledOnGameChangedCheck = false;
tracker.AutoTracker.GameChanged -= AutoTrackerOnGameChanged;
}

private void AutoTrackerOnGameChanged(object? sender, EventArgs e)
{
DisableShaktoolMode();
}

private void DisableShaktoolMode()
{
if (tracker.ModeTracker.ShaktoolMode)
{
tracker.ModeTracker.StopShaktoolMode();
}

DisableGameChangedCheck();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using SnesConnectorLibrary;
using SnesConnectorLibrary.Requests;
using SNI;
Expand All @@ -12,6 +13,8 @@ namespace TrackerCouncil.Smz3.Tracking.AutoTracking.ZeldaStateChecks;
/// </summary>
public class PegWorld(TrackerBase tracker, ISnesConnectorService snesConnector) : IZeldaStateCheck
{
private bool _enabledOnGameChangedCheck;

/// <summary>
/// Executes the check for the current state
/// </summary>
Expand All @@ -27,9 +30,43 @@ public bool ExecuteCheck(TrackerBase trackerBase, AutoTrackerZeldaState currentS
return true;
}

if (tracker.ModeTracker.PegWorldMode && !(currentState.OverworldScreen == 0x62 || currentState is { OverworldScreen: 0, CurrentRoom: 295 }))
{
DisablePegWorldNode();
}

return false;
}

private void EnableGameChangedCheck()
{
if (_enabledOnGameChangedCheck || tracker.AutoTracker == null) return;
_enabledOnGameChangedCheck = true;
tracker.AutoTracker.GameChanged += AutoTrackerOnGameChanged;
}

private void DisableGameChangedCheck()
{
if (!_enabledOnGameChangedCheck || tracker.AutoTracker == null ) return;
_enabledOnGameChangedCheck = false;
tracker.AutoTracker.GameChanged -= AutoTrackerOnGameChanged;
}

private void AutoTrackerOnGameChanged(object? sender, EventArgs e)
{
DisablePegWorldNode();
}

private void DisablePegWorldNode()
{
if (tracker.ModeTracker.PegWorldMode)
{
tracker.ModeTracker.StopPegWorldMode();
}

DisableGameChangedCheck();
}

private async Task CountPegs()
{
var response = await snesConnector.MakeMemoryRequestAsync(new SnesSingleMemoryRequest()
Expand All @@ -46,9 +83,9 @@ private async Task CountPegs()

var count = response.Data.ReadUInt8(0);

if (count != null)
if (count != null && tracker.ModeTracker.SetPegs((int)count))
{
tracker.ModeTracker.SetPegs((int)count);
EnableGameChangedCheck();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ public void Peg(float? confidence = null)
RestartIdleTimers();
}

public void SetPegs(int count)
public bool SetPegs(int count)
{
if (count <= PegsPegged)
return;
return false;

var updated = false;

if (!PegWorldMode)
{
PegWorldMode = true;
ToggledPegWorldModeOn?.Invoke(this, new TrackerEventArgs(null, true));
updated = true;
}

if (count <= PegWorldModeModule.TotalPegs)
Expand All @@ -90,7 +93,10 @@ public void SetPegs(int count)
PegsPegged = count;
Tracker.Say(responses: Responses.PegWorldModePeggedMultiple, tieredKey: delta, wait: true);
PegPegged?.Invoke(this, new TrackerEventArgs(null, true));
updated = true;
}

return updated;
}

public void StartPegWorldMode(float? confidence = null)
Expand Down
Loading