diff --git a/MiraAPI.Example/Buttons/MeetingButton.cs b/MiraAPI.Example/Buttons/MeetingButton.cs index a5e1e10..4b4f087 100644 --- a/MiraAPI.Example/Buttons/MeetingButton.cs +++ b/MiraAPI.Example/Buttons/MeetingButton.cs @@ -45,4 +45,4 @@ protected override void OnClick() PlayerControl.LocalPlayer.RpcRemoveModifier(); } } -} \ No newline at end of file +} diff --git a/MiraAPI.Example/Modifiers/CaptainModifier.cs b/MiraAPI.Example/Modifiers/CaptainModifier.cs index 80d9224..09c733c 100644 --- a/MiraAPI.Example/Modifiers/CaptainModifier.cs +++ b/MiraAPI.Example/Modifiers/CaptainModifier.cs @@ -7,6 +7,7 @@ namespace MiraAPI.Example.Modifiers; public class CaptainModifier : GameModifier { public override string ModifierName => "Captain"; + public override int GetAmountPerGame() { return 1; @@ -16,4 +17,4 @@ public override int GetAssignmentChance() { return 100; } -} \ No newline at end of file +} diff --git a/MiraAPI.Example/Modifiers/Freezer/FreezeModifier.cs b/MiraAPI.Example/Modifiers/Freezer/FreezeModifier.cs index d112406..fc6746f 100644 --- a/MiraAPI.Example/Modifiers/Freezer/FreezeModifier.cs +++ b/MiraAPI.Example/Modifiers/Freezer/FreezeModifier.cs @@ -14,7 +14,7 @@ public class FreezeModifier : TimedModifier public override void OnActivate() { - if (Player.AmOwner) + if (Player?.AmOwner == true) { Player.moveable = false; } @@ -22,7 +22,7 @@ public override void OnActivate() public override void OnTimerComplete() { - if (Player.AmOwner) + if (Player?.AmOwner == true) { Player.moveable = true; } diff --git a/MiraAPI/Modifiers/BaseModifier.cs b/MiraAPI/Modifiers/BaseModifier.cs index 2e2f107..af9b491 100644 --- a/MiraAPI/Modifiers/BaseModifier.cs +++ b/MiraAPI/Modifiers/BaseModifier.cs @@ -1,14 +1,74 @@ namespace MiraAPI.Modifiers; + +/// +/// Base class for all modifiers. +/// public abstract class BaseModifier { + /// + /// Gets the player that the modifier is attached to. + /// + public PlayerControl? Player { get; internal set; } + + /// + /// Gets the modifier id. + /// + public uint ModifierId { get; internal set; } + + /// + /// Gets the modifier name. + /// public abstract string ModifierName { get; } + + /// + /// Gets a value indicating whether the modifier is hidden on the UI. + /// public virtual bool HideOnUi => false; - public PlayerControl Player { get; internal set; } - public uint ModifierId { get; internal set; } - public virtual void OnActivate() { } - public virtual void OnDeactivate() { } - public virtual void Update() { } - public virtual void FixedUpdate() { } - public virtual void OnDeath() { } - public virtual bool CanVent() => Player.Data.Role.CanVent; -} \ No newline at end of file + + /// + /// Gets the HUD information for this modifier. Defaults to the modifier name. Does nothing if is true. + /// + /// The information string for the HUD. + public virtual string GetHudString() => ModifierName; + + /// + /// Called when the modifier is activated. + /// + public virtual void OnActivate() + { + } + + /// + /// Called when the modifier is deactivated. + /// + public virtual void OnDeactivate() + { + } + + /// + /// Called when the modifier is updated. Attached to the ModifierComponent's Update method. + /// + public virtual void Update() + { + } + + /// + /// Called when the modifier is updated. Attached to the ModifierComponent's FixedUpdate method. + /// + public virtual void FixedUpdate() + { + } + + /// + /// Called when the player dies. + /// + public virtual void OnDeath() + { + } + + /// + /// Determines whether the player can vent. + /// + /// True if the player can vent, false otherwise. + public virtual bool CanVent() => Player?.Data.Role.CanVent == true; +} diff --git a/MiraAPI/Modifiers/Types/GameModifier.cs b/MiraAPI/Modifiers/Types/GameModifier.cs index cda0844..9ec6f28 100644 --- a/MiraAPI/Modifiers/Types/GameModifier.cs +++ b/MiraAPI/Modifiers/Types/GameModifier.cs @@ -1,7 +1,26 @@ namespace MiraAPI.Modifiers.Types; + +/// +/// The base class for a game modifier. Game modifiers are applied at the start of the game on top of the player's role. +/// public abstract class GameModifier : BaseModifier { + /// + /// Gets the chance of the modifier being assigned to a player. + /// + /// An int value between 0 and 100 representing percent. public abstract int GetAssignmentChance(); + + /// + /// Gets the amount of players that can have this modifier in a game. + /// + /// An int value greater than or equal to zero. public abstract int GetAmountPerGame(); + + /// + /// Determines whether the modifier is valid on a role. + /// + /// The role to be checked. + /// True if the modifier is valid on the role, otherwise false. public virtual bool IsModifierValidOn(RoleBehaviour role) => true; -} \ No newline at end of file +} diff --git a/MiraAPI/Modifiers/Types/TimedModifier.cs b/MiraAPI/Modifiers/Types/TimedModifier.cs index 44e73f7..248af76 100644 --- a/MiraAPI/Modifiers/Types/TimedModifier.cs +++ b/MiraAPI/Modifiers/Types/TimedModifier.cs @@ -3,20 +3,48 @@ using UnityEngine; namespace MiraAPI.Modifiers.Types; + +/// +/// The base class for all timed modifiers. Timed modifiers have a duration and can be started and stopped. +/// public abstract class TimedModifier : BaseModifier { + /// + /// Gets the duration of the modifier. + /// public abstract float Duration { get; } + + /// + /// Gets a value indicating whether the timer should start automatically when added. + /// public virtual bool AutoStart => false; + + /// + /// Gets a value indicating whether the modifier should be removed when the timer completes. + /// public virtual bool RemoveOnComplete => true; + + /// + /// Called when the timer completes. + /// public abstract void OnTimerComplete(); + /// + /// Gets or sets a value indicating whether the timer is active. + /// public bool TimerActive { get; protected set; } + /// + /// Gets or sets the time remaining on the timer. + /// public float TimeRemaining { get; protected set; } + /// + /// The FixedUpdate method for timed modifiers. Automatically handles the timer logic. + /// public override void FixedUpdate() { - if (!Player.AmOwner) + if (Player?.AmOwner == false) { return; } @@ -33,11 +61,14 @@ public override void FixedUpdate() if (RemoveOnComplete) { - Player.RpcRemoveModifier(ModifierId); + Player?.RpcRemoveModifier(ModifierId); } } } + /// + /// Starts the timer. + /// public void StartTimer() { if (TimerActive) @@ -49,4 +80,4 @@ public void StartTimer() TimerActive = true; TimeRemaining = Duration; } -} \ No newline at end of file +}