mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
add hud string method and code docs for modifiers
This commit is contained in:
1 parent
264defe8bf
commit
1f357b5e08
6 files changed
+129
-18
No files matched your search
@@ -45,4 +45,4 @@ public class MeetingButton : CustomActionButton
|
|||||||
PlayerControl.LocalPlayer.RpcRemoveModifier<CaptainModifier>();
|
PlayerControl.LocalPlayer.RpcRemoveModifier<CaptainModifier>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ namespace MiraAPI.Example.Modifiers;
|
|||||||
public class CaptainModifier : GameModifier
|
public class CaptainModifier : GameModifier
|
||||||
{
|
{
|
||||||
public override string ModifierName => "Captain";
|
public override string ModifierName => "Captain";
|
||||||
|
|
||||||
public override int GetAmountPerGame()
|
public override int GetAmountPerGame()
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
@@ -16,4 +17,4 @@ public class CaptainModifier : GameModifier
|
|||||||
{
|
{
|
||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ public class FreezeModifier : TimedModifier
|
|||||||
|
|
||||||
public override void OnActivate()
|
public override void OnActivate()
|
||||||
{
|
{
|
||||||
if (Player.AmOwner)
|
if (Player?.AmOwner == true)
|
||||||
{
|
{
|
||||||
Player.moveable = false;
|
Player.moveable = false;
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ public class FreezeModifier : TimedModifier
|
|||||||
|
|
||||||
public override void OnTimerComplete()
|
public override void OnTimerComplete()
|
||||||
{
|
{
|
||||||
if (Player.AmOwner)
|
if (Player?.AmOwner == true)
|
||||||
{
|
{
|
||||||
Player.moveable = true;
|
Player.moveable = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,74 @@
|
|||||||
namespace MiraAPI.Modifiers;
|
namespace MiraAPI.Modifiers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for all modifiers.
|
||||||
|
/// </summary>
|
||||||
public abstract class BaseModifier
|
public abstract class BaseModifier
|
||||||
{
|
{
|
||||||
public abstract string ModifierName { get; }
|
/// <summary>
|
||||||
public virtual bool HideOnUi => false;
|
/// Gets the player that the modifier is attached to.
|
||||||
public PlayerControl Player { get; internal set; }
|
/// </summary>
|
||||||
|
public PlayerControl? Player { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the modifier id.
|
||||||
|
/// </summary>
|
||||||
public uint ModifierId { get; internal set; }
|
public uint ModifierId { get; internal set; }
|
||||||
public virtual void OnActivate() { }
|
|
||||||
public virtual void OnDeactivate() { }
|
/// <summary>
|
||||||
public virtual void Update() { }
|
/// Gets the modifier name.
|
||||||
public virtual void FixedUpdate() { }
|
/// </summary>
|
||||||
public virtual void OnDeath() { }
|
public abstract string ModifierName { get; }
|
||||||
public virtual bool CanVent() => Player.Data.Role.CanVent;
|
|
||||||
}
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the modifier is hidden on the UI.
|
||||||
|
/// </summary>
|
||||||
|
public virtual bool HideOnUi => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the HUD information for this modifier. Defaults to the modifier name. Does nothing if <see cref="HideOnUi"/> is true.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The information string for the HUD.</returns>
|
||||||
|
public virtual string GetHudString() => ModifierName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the modifier is activated.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void OnActivate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the modifier is deactivated.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void OnDeactivate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the modifier is updated. Attached to the ModifierComponent's Update method.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the modifier is updated. Attached to the ModifierComponent's FixedUpdate method.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void FixedUpdate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the player dies.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void OnDeath()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the player can vent.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if the player can vent, false otherwise.</returns>
|
||||||
|
public virtual bool CanVent() => Player?.Data.Role.CanVent == true;
|
||||||
|
}
|
||||||
@@ -1,7 +1,26 @@
|
|||||||
namespace MiraAPI.Modifiers.Types;
|
namespace MiraAPI.Modifiers.Types;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The base class for a game modifier. Game modifiers are applied at the start of the game on top of the player's role.
|
||||||
|
/// </summary>
|
||||||
public abstract class GameModifier : BaseModifier
|
public abstract class GameModifier : BaseModifier
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the chance of the modifier being assigned to a player.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An int value between 0 and 100 representing percent.</returns>
|
||||||
public abstract int GetAssignmentChance();
|
public abstract int GetAssignmentChance();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the amount of players that can have this modifier in a game.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An int value greater than or equal to zero.</returns>
|
||||||
public abstract int GetAmountPerGame();
|
public abstract int GetAmountPerGame();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the modifier is valid on a role.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="role">The role to be checked.</param>
|
||||||
|
/// <returns>True if the modifier is valid on the role, otherwise false.</returns>
|
||||||
public virtual bool IsModifierValidOn(RoleBehaviour role) => true;
|
public virtual bool IsModifierValidOn(RoleBehaviour role) => true;
|
||||||
}
|
}
|
||||||
@@ -3,20 +3,48 @@ using Reactor.Utilities;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Modifiers.Types;
|
namespace MiraAPI.Modifiers.Types;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The base class for all timed modifiers. Timed modifiers have a duration and can be started and stopped.
|
||||||
|
/// </summary>
|
||||||
public abstract class TimedModifier : BaseModifier
|
public abstract class TimedModifier : BaseModifier
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the duration of the modifier.
|
||||||
|
/// </summary>
|
||||||
public abstract float Duration { get; }
|
public abstract float Duration { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the timer should start automatically when added.
|
||||||
|
/// </summary>
|
||||||
public virtual bool AutoStart => false;
|
public virtual bool AutoStart => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether the modifier should be removed when the timer completes.
|
||||||
|
/// </summary>
|
||||||
public virtual bool RemoveOnComplete => true;
|
public virtual bool RemoveOnComplete => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the timer completes.
|
||||||
|
/// </summary>
|
||||||
public abstract void OnTimerComplete();
|
public abstract void OnTimerComplete();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether the timer is active.
|
||||||
|
/// </summary>
|
||||||
public bool TimerActive { get; protected set; }
|
public bool TimerActive { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the time remaining on the timer.
|
||||||
|
/// </summary>
|
||||||
public float TimeRemaining { get; protected set; }
|
public float TimeRemaining { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The FixedUpdate method for timed modifiers. Automatically handles the timer logic.
|
||||||
|
/// </summary>
|
||||||
public override void FixedUpdate()
|
public override void FixedUpdate()
|
||||||
{
|
{
|
||||||
if (!Player.AmOwner)
|
if (Player?.AmOwner == false)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -33,11 +61,14 @@ public abstract class TimedModifier : BaseModifier
|
|||||||
|
|
||||||
if (RemoveOnComplete)
|
if (RemoveOnComplete)
|
||||||
{
|
{
|
||||||
Player.RpcRemoveModifier(ModifierId);
|
Player?.RpcRemoveModifier(ModifierId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts the timer.
|
||||||
|
/// </summary>
|
||||||
public void StartTimer()
|
public void StartTimer()
|
||||||
{
|
{
|
||||||
if (TimerActive)
|
if (TimerActive)
|
||||||
@@ -49,4 +80,4 @@ public abstract class TimedModifier : BaseModifier
|
|||||||
TimerActive = true;
|
TimerActive = true;
|
||||||
TimeRemaining = Duration;
|
TimeRemaining = Duration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user