Skip to content

Commit

Permalink
Abstractions project
Browse files Browse the repository at this point in the history
  • Loading branch information
MattEqualsCoder committed Oct 24, 2023
1 parent bf480b1 commit 8caebc1
Show file tree
Hide file tree
Showing 109 changed files with 6,499 additions and 5,518 deletions.
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
100 changes: 100 additions & 0 deletions src/Randomizer.Abstractions/IAutoTracker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using Randomizer.Data.Options;
using Randomizer.Data.Tracking;
using Randomizer.Shared.Enums;

namespace Randomizer.Abstractions;

public interface IAutoTracker
{
/// <summary>
/// The tracker associated with this auto tracker
/// </summary>
public ITracker Tracker { get; }

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

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

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

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

/// <summary>
/// Disables the current connector and creates the requested type
/// </summary>
public 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 bool IsEnabled { get; }

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

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

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

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

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

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

}
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

0 comments on commit 8caebc1

Please sign in to comment.