|
6 | 6 | using UnityEngine; |
7 | 7 | using NewMod.Utilities; |
8 | 8 |
|
9 | | -namespace NewMod.Buttons.Necromancer; |
10 | | -public class ReviveButton : CustomActionButton |
| 9 | +namespace NewMod.Buttons.Necromancer |
11 | 10 | { |
12 | | - public override string Name => ""; // It's currently empty since the button has already a name on it |
13 | | - public override float Cooldown => OptionGroupSingleton<NecromancerOption>.Instance.ButtonCooldown; |
14 | | - public override int MaxUses => (int)OptionGroupSingleton<NecromancerOption>.Instance.AbilityUses; |
15 | | - public override float EffectDuration => 0f; |
16 | | - public override ButtonLocation Location => ButtonLocation.BottomLeft; |
17 | | - public override LoadableAsset<Sprite> Sprite => NewModAsset.NecromancerButton; |
18 | | - protected override void OnClick() |
| 11 | + /// <summary> |
| 12 | + /// Defines a custom action button for the role. |
| 13 | + /// </summary> |
| 14 | + public class ReviveButton : CustomActionButton |
19 | 15 | { |
20 | | - NewMod.Instance.Log.LogMessage("Button Clicked!"); |
21 | | - SoundManager.Instance.PlaySound(NewModAsset.ReviveSound?.LoadAsset(), false, 2f); |
22 | | - |
23 | | - var closestBody = Utils.GetClosestBody(); |
24 | | - if (closestBody != null) |
| 16 | + /// <summary> |
| 17 | + /// The name displayed on the button. Intentionally left empty to show an existing name elsewhere. |
| 18 | + /// </summary> |
| 19 | + public override string Name => ""; // It's currently empty since the button has already a name on it |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Gets the cooldown time for this button, based on <see cref="NecromancerOption"/>. |
| 23 | + /// </summary> |
| 24 | + public override float Cooldown => OptionGroupSingleton<NecromancerOption>.Instance.ButtonCooldown; |
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// Gets the maximum number of uses for this button, based on <see cref="NecromancerOption"/>. |
| 28 | + /// </summary> |
| 29 | + public override int MaxUses => (int)OptionGroupSingleton<NecromancerOption>.Instance.AbilityUses; |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Determines how long the effect from clicking the button lasts. In this case, no duration is set. |
| 33 | + /// </summary> |
| 34 | + public override float EffectDuration => 0f; |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Defines where on the screen this button should appear. |
| 38 | + /// </summary> |
| 39 | + public override ButtonLocation Location => ButtonLocation.BottomLeft; |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// The visual icon for this button, set to the necromancer sprite asset. |
| 43 | + /// </summary> |
| 44 | + public override LoadableAsset<Sprite> Sprite => NewModAsset.NecromancerButton; |
| 45 | + |
| 46 | + /// <summary> |
| 47 | + /// Invoked when the revive button is clicked. Plays a sound and revives the nearest dead body. |
| 48 | + /// </summary> |
| 49 | + protected override void OnClick() |
25 | 50 | { |
| 51 | + SoundManager.Instance.PlaySound(NewModAsset.ReviveSound?.LoadAsset(), false, 2f); |
26 | 52 |
|
27 | | - Utils.RpcRevive(closestBody); |
| 53 | + var closestBody = Utils.GetClosestBody(); |
| 54 | + if (closestBody != null) |
| 55 | + { |
| 56 | + Utils.RpcRevive(closestBody); |
| 57 | + } |
28 | 58 | } |
29 | | - } |
30 | | - public override bool Enabled(RoleBehaviour role) |
31 | | - { |
32 | | - return role is NecromancerRole; |
33 | | - } |
34 | | - public override bool CanUse() |
35 | | - { |
36 | | - bool isTimerDone = Timer <= 0; |
37 | | - bool hasUsesLeft = UsesLeft > 0; |
38 | | - var closestBody = Utils.GetClosestBody(); |
39 | | - bool isNearDeadBody = closestBody != null; |
40 | | - bool isFakeBody = isNearDeadBody && PranksterUtilities.IsPranksterBody(closestBody); |
41 | 59 |
|
42 | | - if (closestBody == null) |
| 60 | + /// <summary> |
| 61 | + /// Determines whether this button is enabled for the role, returning true if the role is <see cref="NecromancerRole"/>. |
| 62 | + /// </summary> |
| 63 | + /// <param name="role">The current player's role.</param> |
| 64 | + /// <returns>True if the role is Necromancer; otherwise false.</returns> |
| 65 | + public override bool Enabled(RoleBehaviour role) |
43 | 66 | { |
44 | | - return false; |
| 67 | + return role is NecromancerRole; |
45 | 68 | } |
46 | 69 |
|
47 | | - bool wasNotKilledByNecromancer = true; |
48 | | - var deadBody = closestBody.GetComponent<DeadBody>(); |
49 | | - if (deadBody != null) |
| 70 | + /// <summary> |
| 71 | + /// Checks whether the player can currently use the revive button, ensuring cooldowns, ability uses, and conditions are met. |
| 72 | + /// </summary> |
| 73 | + /// <returns>True if all requirements to use this button are met; otherwise false.</returns> |
| 74 | + public override bool CanUse() |
50 | 75 | { |
51 | | - var killedPlayer = GameData.Instance.GetPlayerById(deadBody.ParentId)?.Object; |
52 | | - if (killedPlayer != null) |
| 76 | + bool isTimerDone = Timer <= 0; |
| 77 | + bool hasUsesLeft = UsesLeft > 0; |
| 78 | + var closestBody = Utils.GetClosestBody(); |
| 79 | + bool isNearDeadBody = closestBody != null; |
| 80 | + bool isFakeBody = isNearDeadBody && PranksterUtilities.IsPranksterBody(closestBody); |
| 81 | + |
| 82 | + if (closestBody == null) |
| 83 | + { |
| 84 | + return false; |
| 85 | + } |
| 86 | + |
| 87 | + bool wasNotKilledByNecromancer = true; |
| 88 | + var deadBody = closestBody.GetComponent<DeadBody>(); |
| 89 | + if (deadBody != null) |
53 | 90 | { |
54 | | - var killer = Utils.GetKiller(killedPlayer); |
55 | | - if (killer != null && killer.Data.Role is NecromancerRole) |
| 91 | + var killedPlayer = GameData.Instance.GetPlayerById(deadBody.ParentId)?.Object; |
| 92 | + if (killedPlayer != null) |
56 | 93 | { |
57 | | - wasNotKilledByNecromancer = false; |
| 94 | + var killer = Utils.GetKiller(killedPlayer); |
| 95 | + if (killer != null && killer.Data.Role is NecromancerRole) |
| 96 | + { |
| 97 | + wasNotKilledByNecromancer = false; |
| 98 | + } |
58 | 99 | } |
59 | 100 | } |
| 101 | + return isTimerDone && hasUsesLeft && isNearDeadBody && wasNotKilledByNecromancer && !isFakeBody; |
60 | 102 | } |
61 | | - return isTimerDone && hasUsesLeft && isNearDeadBody && wasNotKilledByNecromancer && !isFakeBody; |
62 | 103 | } |
63 | 104 | } |
0 commit comments