Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstractions project #413

Merged
merged 6 commits into from
Oct 25, 2023
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
6 changes: 6 additions & 0 deletions CasRandomizer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Randomizer.PatchBuilder", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Randomizer.CrossPlatform", "src\Randomizer.CrossPlatform\Randomizer.CrossPlatform.csproj", "{B18DD122-3612-4948-B512-464D410A271B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Randomizer.Abstractions", "src\Randomizer.Abstractions\Randomizer.Abstractions.csproj", "{C5CED4F3-F57F-4651-88FB-5774326654E7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -107,6 +109,10 @@ Global
{B18DD122-3612-4948-B512-464D410A271B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B18DD122-3612-4948-B512-464D410A271B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B18DD122-3612-4948-B512-464D410A271B}.Release|Any CPU.Build.0 = Release|Any CPU
{C5CED4F3-F57F-4651-88FB-5774326654E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5CED4F3-F57F-4651-88FB-5774326654E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5CED4F3-F57F-4651-88FB-5774326654E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5CED4F3-F57F-4651-88FB-5774326654E7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
132 changes: 132 additions & 0 deletions src/Randomizer.Abstractions/AutoTrackerBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using Randomizer.Data.Options;
using Randomizer.Data.Tracking;
using Randomizer.Shared.Enums;

namespace Randomizer.Abstractions;

public abstract class AutoTrackerBase
{
/// <summary>
/// The tracker associated with this auto tracker
/// </summary>
protected TrackerBase TrackerBase { get; set; } = null!;

/// <summary>
/// The type of connector that the auto tracker is currently using
/// </summary>
public EmulatorConnectorType ConnectorType { get; protected set; }

/// <summary>
/// The game that the player is currently in
/// </summary>
public Game CurrentGame { get; protected set; }

/// <summary>
/// The latest state that the player in LTTP (location, health, etc.)
/// </summary>
public AutoTrackerZeldaState? ZeldaState { get; protected set; }

/// <summary>
/// The latest state that the player in Super Metroid (location, health, etc.)
/// </summary>
public AutoTrackerMetroidState? MetroidState { get; protected set; }

/// <summary>
/// Disables the current connector and creates the requested type
/// </summary>
public abstract void SetConnector(EmulatorConnectorType type, string? qusb2SnesIp);

/// <summary>
/// Occurs when the tracker's auto tracker is enabled
/// </summary>
public event EventHandler? AutoTrackerEnabled;

/// <summary>
/// Occurs when the tracker's auto tracker is disabled
/// </summary>
public event EventHandler? AutoTrackerDisabled;

/// <summary>
/// Occurs when the tracker's auto tracker is connected
/// </summary>
public event EventHandler? AutoTrackerConnected;

/// <summary>
/// Occurs when the tracker's auto tracker is disconnected
/// </summary>
public event EventHandler? AutoTrackerDisconnected;

/// <summary>
/// The action to run when the player asks Tracker to look at the game
/// </summary>
public AutoTrackerViewedAction? LatestViewAction { get; set; }

/// <summary>
/// If a connector is currently enabled
/// </summary>
public abstract bool IsEnabled { get; }

/// <summary>
/// If a connector is currently connected to the emulator
/// </summary>
public abstract bool IsConnected { get; }

/// <summary>
/// If a connector is currently connected to the emulator and a valid game state is detected
/// </summary>
public abstract bool HasValidState { get; }

/// <summary>
/// If the auto tracker is currently sending messages
/// </summary>
protected bool IsSendingMessages { get; set; }

/// <summary>
/// If the player currently has a fairy
/// </summary>
public bool PlayerHasFairy { get; protected set; }

/// <summary>
/// If the user is activately in an SMZ3 rom
/// </summary>
public abstract bool IsInSMZ3 { get; }

/// <summary>
/// Writes a particular action to the emulator memory
/// </summary>
/// <param name="action">The action to write to memory</param>
public abstract void WriteToMemory(EmulatorAction action);

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

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

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

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

}
110 changes: 110 additions & 0 deletions src/Randomizer.Abstractions/IGameService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using Randomizer.Data.Tracking;
using Randomizer.Data.WorldData;
using Randomizer.Shared;

namespace Randomizer.Abstractions;

public interface IGameService
{
/// <summary>
/// Updates memory values so both SM and Z3 will cancel any pending MSU resumes and play
/// all tracks from the start until new resume points have been stored.
/// </summary>
/// <returns>True, even if it didn't do anything</returns>
public void TryCancelMsuResume();

/// <summary>
/// Gives an item to the player
/// </summary>
/// <param name="item">The item to give</param>
/// <param name="fromPlayerId">The id of the player giving the item to the player (null for tracker)</param>
/// <returns>False if it is currently unable to give an item to the player</returns>
public bool TryGiveItem(Item item, int? fromPlayerId);

/// <summary>
/// Gives a series of items to the player
/// </summary>
/// <param name="items">The list of items to give to the player</param>
/// <param name="fromPlayerId">The id of the player giving the item to the player</param>
/// <returns>False if it is currently unable to give an item to the player</returns>
public bool TryGiveItems(List<Item> items, int fromPlayerId);

/// <summary>
/// Gives a series of item types from particular players
/// </summary>
/// <param name="items">The list of item types and the players that are giving the item to the player</param>
/// <returns>False if it is currently unable to give the items to the player</returns>
public bool TryGiveItemTypes(List<(ItemType type, int fromPlayerId)> items);

/// <summary>
/// Restores the player to max health
/// </summary>
/// <returns>False if it is currently unable to give an item to the player</returns>
public bool TryHealPlayer();

/// <summary>
/// Fully fills the player's magic
/// </summary>
/// <returns>False if it is currently unable to give magic to the player</returns>
public bool TryFillMagic();

/// <summary>
/// Fully fills the player's bombs to capacity
/// </summary>
/// <returns>False if it is currently unable to give bombs to the player</returns>
public bool TryFillZeldaBombs();

/// <summary>
/// Fully fills the player's arrows
/// </summary>
/// <returns>False if it is currently unable to give arrows to the player</returns>
public bool TryFillArrows();

/// <summary>
/// Fully fills the player's rupees (sets to 2000)
/// </summary>
/// <returns>False if it is currently unable to give rupees to the player</returns>
public bool TryFillRupees();

/// <summary>
/// Fully fills the player's missiles
/// </summary>
/// <returns>False if it is currently unable to give missiles to the player</returns>
public bool TryFillMissiles();

/// <summary>
/// Fully fills the player's super missiles
/// </summary>
/// <returns>False if it is currently unable to give super missiles to the player</returns>
public bool TryFillSuperMissiles();

/// <summary>
/// Fully fills the player's power bombs
/// </summary>
/// <returns>False if it is currently unable to give power bombs to the player</returns>
public bool TryFillPowerBombs();

/// <summary>
/// Kills the player by removing their health and dealing damage to them
/// </summary>
/// <returns>True if successful</returns>
public bool TryKillPlayer();

/// <summary>
/// Sets the player to have the requirements for a crystal flash
/// </summary>
/// <returns>True if successful</returns>
public bool TrySetupCrystalFlash();

/// <summary>
/// Gives the player any items that tracker thinks they should have but are not in memory as having been gifted
/// </summary>
/// <param name="action"></param>
public void SyncItems(EmulatorAction action);

/// <summary>
/// If the player was recently killed by the game service
/// </summary>
public bool PlayerRecentlyKilled { get; }

}
44 changes: 44 additions & 0 deletions src/Randomizer.Abstractions/IHistoryService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Randomizer.Data.WorldData;
using Randomizer.Shared.Enums;
using Randomizer.Shared.Models;

namespace Randomizer.Abstractions;

/// <summary>
/// Service for managing the history of events through a playthrough
/// </summary>
public interface IHistoryService
{
/// <summary>
/// Adds an event to the history log
/// </summary>
/// <param name="type">The type of event</param>
/// <param name="isImportant">If this is an important event or not</param>
/// <param name="objectName">The name of the event being logged</param>
/// <param name="location">The optional location of where this event happened</param>
/// <returns>The created event</returns>
public TrackerHistoryEvent AddEvent(HistoryEventType type, bool isImportant, string objectName, Location? location = null);

/// <summary>
/// Adds an event to the history log
/// </summary>
/// <param name="histEvent">The event to add</param>
public void AddEvent(TrackerHistoryEvent histEvent);

/// <summary>
/// Removes the event that was added last to the log
/// </summary>
public void RemoveLastEvent();

/// <summary>
/// Removes a specific event from the log
/// </summary>
/// <param name="histEvent">The event to log</param>
public void Remove(TrackerHistoryEvent histEvent);

/// <summary>
/// Retrieves the current history log
/// </summary>
/// <returns>The collection of events</returns>
public IReadOnlyCollection<TrackerHistoryEvent> GetHistory();
}
Loading
Loading