diff --git a/Dalamud/Game/DutyState/DutyState.cs b/Dalamud/Game/DutyState/DutyState.cs index 11eeff9f3..49fc874e3 100644 --- a/Dalamud/Game/DutyState/DutyState.cs +++ b/Dalamud/Game/DutyState/DutyState.cs @@ -5,6 +5,7 @@ using Dalamud.Game.ClientState.Conditions; using Dalamud.Hooking; using Dalamud.IoC; using Dalamud.IoC.Internal; +using Dalamud.Plugin.Services; using Dalamud.Utility; namespace Dalamud.Game.DutyState; @@ -15,7 +16,10 @@ namespace Dalamud.Game.DutyState; [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.EarlyLoadedService] -public unsafe class DutyState : IDisposable, IServiceType +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +public unsafe class DutyState : IDisposable, IServiceType, IDutyState { private readonly DutyStateAddressResolver address; private readonly Hook contentDirectorNetworkMessageHook; @@ -44,42 +48,24 @@ public unsafe class DutyState : IDisposable, IServiceType [UnmanagedFunctionPointer(CallingConvention.ThisCall)] private delegate byte SetupContentDirectNetworkMessageDelegate(IntPtr a1, IntPtr a2, ushort* a3); - /// - /// Event that gets fired when the duty starts. Triggers when the "Duty Start" - /// message displays, and on the remove of the ring at duty's spawn. - /// + /// public event EventHandler DutyStarted; - /// - /// Event that gets fired when everyone in the party dies and the screen fades to black. - /// + /// public event EventHandler DutyWiped; - - /// - /// Event that gets fired when the "Duty Recommence" message displays, - /// and on the remove the the ring at duty's spawn. - /// + + /// public event EventHandler DutyRecommenced; - - /// - /// Event that gets fired when the duty is completed successfully. - /// + + /// public event EventHandler DutyCompleted; - - /// - /// Gets a value indicating whether the current duty has been started. - /// + + /// public bool IsDutyStarted { get; private set; } - /// - /// Gets or sets a value indicating whether the current duty has been completed or not. - /// Prevents DutyStarted from triggering if combat is entered after receiving a duty complete network event. - /// private bool CompletedThisTerritory { get; set; } - /// - /// Dispose of managed and unmanaged resources. - /// + /// void IDisposable.Dispose() { this.contentDirectorNetworkMessageHook.Dispose(); @@ -171,9 +157,6 @@ public unsafe class DutyState : IDisposable, IServiceType else if (!this.IsBoundByDuty() && this.IsDutyStarted) { this.IsDutyStarted = false; - - // Could potentially add a call to DutyCompleted here since this - // should only be reached if we are actually no longer in a duty, and missed the network event. } } diff --git a/Dalamud/Plugin/Services/IDutyState.cs b/Dalamud/Plugin/Services/IDutyState.cs new file mode 100644 index 000000000..a2331364c --- /dev/null +++ b/Dalamud/Plugin/Services/IDutyState.cs @@ -0,0 +1,36 @@ +using System; + +namespace Dalamud.Plugin.Services; + +/// +/// This class represents the state of the currently occupied duty. +/// +public interface IDutyState +{ + /// + /// Event that gets fired when the duty starts. + /// Triggers when the "Duty Start" message displays, and on the removal of the ring at duty's spawn. + /// Does not trigger when loading into a duty that was in progress, or from loading in after a disconnect. + /// + public event EventHandler DutyStarted; + + /// + /// Event that gets fired when everyone in the party dies and the screen fades to black. + /// + public event EventHandler DutyWiped; + + /// + /// Event that gets fired when the "Duty Recommence" message displays, and on the removal of the ring at duty's spawn. + /// + public event EventHandler DutyRecommenced; + + /// + /// Event that gets fired when the duty is completed successfully. + /// + public event EventHandler DutyCompleted; + + /// + /// Gets a value indicating whether the current duty has been started. + /// + public bool IsDutyStarted { get; } +}