|
| 1 | +using MiraAPI.GameOptions; |
| 2 | +using MiraAPI.Hud; |
| 3 | +using MiraAPI.Utilities.Assets; |
| 4 | +using NewMod.Options.Roles.EdgeveilOptions; |
| 5 | +using EV = NewMod.Roles.ImpostorRoles.Edgeveil; |
| 6 | +using Rewired; |
| 7 | +using UnityEngine; |
| 8 | +using NewMod.Components.ScreenEffects; |
| 9 | +using NewMod.Utilities; |
| 10 | +using Reactor.Utilities; |
| 11 | +using MiraAPI.Keybinds; |
| 12 | + |
| 13 | +namespace NewMod.Buttons.Edgeveil |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// Defines a custom action button for Edgeviel's Arc ability. |
| 17 | + /// </summary> |
| 18 | + public class ArcButton : CustomActionButton |
| 19 | + { |
| 20 | + /// <summary> |
| 21 | + /// The name displayed on the button. |
| 22 | + /// </summary> |
| 23 | + public override string Name => "Arc"; |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Gets the cooldown time for this button, based on <see cref="EdgeveilOptions"/>. |
| 27 | + /// </summary> |
| 28 | + public override float Cooldown => OptionGroupSingleton<EdgeveilOptions>.Instance.SlashCooldown; |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Gets the maximum number of uses for this button (0 = infinite). |
| 32 | + /// </summary> |
| 33 | + public override int MaxUses => (int)OptionGroupSingleton<EdgeveilOptions>.Instance.SlashMaxUses; |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Determines how long the effect lasts. For Arc, none. |
| 37 | + /// </summary> |
| 38 | + public override float EffectDuration => 0f; |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// Default keybind for Edgeveil's Arc ability. |
| 42 | + /// </summary> |
| 43 | + public override MiraKeybind Keybind => MiraGlobalKeybinds.PrimaryAbility; |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Defines where on the screen this button should appear. |
| 47 | + /// </summary> |
| 48 | + public override ButtonLocation Location => ButtonLocation.BottomLeft; |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// The visual icon for this button, set to the Edgeveil Arc sprite asset. |
| 52 | + /// </summary> |
| 53 | + public override LoadableAsset<Sprite> Sprite => NewModAsset.SlashIcon; |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Invoked when the Arc button is clicked. |
| 57 | + /// </summary> |
| 58 | + protected override void OnClick() |
| 59 | + { |
| 60 | + var player = PlayerControl.LocalPlayer; |
| 61 | + |
| 62 | + bool flipLeft = player.cosmetics.currentBodySprite.BodySprite.flipX; |
| 63 | + Vector2 dir = flipLeft ? Vector2.left : Vector2.right; |
| 64 | + |
| 65 | + float spawnOffset = 0.55f; |
| 66 | + var spawnPos = player.GetTruePosition() + dir * spawnOffset; |
| 67 | + |
| 68 | + var tray = SlashTray.CreateTray(); |
| 69 | + tray.transform.SetParent(ShipStatus.Instance.transform, worldPositionStays: true); |
| 70 | + tray.transform.SetPositionAndRotation( |
| 71 | + new Vector3(spawnPos.x, spawnPos.y, player.transform.position.z), |
| 72 | + Quaternion.FromToRotation(Vector3.right, new Vector3(dir.x, dir.y, 0f)) |
| 73 | + ); |
| 74 | + |
| 75 | + tray.Owner = player; |
| 76 | + tray.SetMotion(dir, OptionGroupSingleton<EdgeveilOptions>.Instance.SlashSpeed); |
| 77 | + |
| 78 | + float effectDuration = OptionGroupSingleton<EdgeveilOptions>.Instance.EffectDuration; |
| 79 | + |
| 80 | + HudManager.Instance.PlayerCam.ShakeScreen(effectDuration, 2f); |
| 81 | + } |
| 82 | + /// <summary> |
| 83 | + /// Determines whether this button is enabled for the role, returning true if the role is <see cref="EdgevielRole"/>. |
| 84 | + /// </summary> |
| 85 | + /// <param name="role">The current player's role.</param> |
| 86 | + /// <returns>True if the role is Edgeveil; otherwise false.</returns> |
| 87 | + public override bool Enabled(RoleBehaviour role) |
| 88 | + { |
| 89 | + return role is EV; |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments