|
| 1 | +using MiraAPI.GameOptions; |
| 2 | +using MiraAPI.Hud; |
| 3 | +using MiraAPI.Utilities.Assets; |
| 4 | +using UnityEngine; |
| 5 | +using NewMod.Roles.NeutralRoles; |
| 6 | +using NewMod.Options.Roles.InjectorOptions; |
| 7 | +using MiraAPI.Utilities; |
| 8 | +using System; |
| 9 | +using static NewMod.Utilities.Utils; |
| 10 | + |
| 11 | +namespace NewMod.Buttons.Injector |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Represents the serum injection button for the Injector role. |
| 15 | + /// Allows injecting a random serum into nearby players. |
| 16 | + /// </summary> |
| 17 | + public class InjectButton : CustomActionButton<PlayerControl> |
| 18 | + { |
| 19 | + /// <summary> |
| 20 | + /// The name displayed on the button (if any). |
| 21 | + /// </summary> |
| 22 | + public override string Name => "Inject"; |
| 23 | + |
| 24 | + /// <summary> |
| 25 | + /// Cooldown time between uses, configured via <see cref="InjectorOptions"/>. |
| 26 | + /// </summary> |
| 27 | + public override float Cooldown => OptionGroupSingleton<InjectorOptions>.Instance.SerumCooldown; |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Maximum allowed injections, configured via <see cref="InjectorOptions"/>. |
| 31 | + /// </summary> |
| 32 | + public override int MaxUses => OptionGroupSingleton<InjectorOptions>.Instance.MaxSerumUses; |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Effect duration — unused here since injection is instant. |
| 36 | + /// </summary> |
| 37 | + public override float EffectDuration => 0f; |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Screen location of the button on the HUD. |
| 41 | + /// </summary> |
| 42 | + public override ButtonLocation Location => ButtonLocation.BottomLeft; |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Sprite/icon displayed on the button. |
| 46 | + /// </summary> |
| 47 | + public override LoadableAsset<Sprite> Sprite => MiraAssets.Empty; |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Returns the closest valid player target within range, |
| 51 | + /// used by the Injector to determine who can be injected. |
| 52 | + /// </summary> |
| 53 | + /// <returns>The nearest PlayerControl instance, or null if none is in range.</returns> |
| 54 | + public override PlayerControl GetTarget() |
| 55 | + { |
| 56 | + return PlayerControl.LocalPlayer.GetClosestPlayer(true, Distance, false); |
| 57 | + } |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Sets an outline around the target player to visually indicate interaction, |
| 61 | + /// such as highlighting a valid injection target for the Injector role. |
| 62 | + /// </summary> |
| 63 | + /// <param name="active">True to show the outline; false to hide it.</param> |
| 64 | + public override void SetOutline(bool active) |
| 65 | + { |
| 66 | + Target?.cosmetics.SetOutline(active, new Il2CppSystem.Nullable<Color>(Palette.AcceptedGreen)); |
| 67 | + } |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Determines whether this button is available for the current role. |
| 71 | + /// </summary> |
| 72 | + /// <param name="role">The current player's role.</param> |
| 73 | + /// <returns>True only for the Injector role.</returns> |
| 74 | + public override bool Enabled(RoleBehaviour role) |
| 75 | + { |
| 76 | + return role is InjectorRole; |
| 77 | + } |
| 78 | + |
| 79 | + /// <summary> |
| 80 | + /// Called when the button is clicked. Applies a serum to the closest valid target. |
| 81 | + /// </summary> |
| 82 | + protected override void OnClick() |
| 83 | + { |
| 84 | + var serumValues = Enum.GetValues(typeof(SerumType)); |
| 85 | + SerumType randomSerum = (SerumType)serumValues.GetValue(UnityEngine.Random.Range(0, serumValues.Length)); |
| 86 | + |
| 87 | + RpcApplySerum(PlayerControl.LocalPlayer, Target, randomSerum); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments