Skip to content

Commit 674e4a0

Browse files
committed
Fix CanUse in ReviveButton
1 parent ac7360c commit 674e4a0

2 files changed

Lines changed: 25 additions & 28 deletions

File tree

NewMod/Buttons/Necromancer/ReviveButton.cs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using UnityEngine;
77
using NewMod.Utilities;
88
using MiraAPI.Keybinds;
9+
using AmongUs.GameOptions;
10+
using Reactor.Utilities;
911

1012
namespace NewMod.Buttons.Necromancer
1113
{
@@ -54,13 +56,25 @@ public class ReviveButton : CustomActionButton
5456
/// </summary>
5557
protected override void OnClick()
5658
{
57-
SoundManager.Instance.PlaySound(NewModAsset.ReviveSound?.LoadAsset(), false, 2f);
58-
5959
var closestBody = Utils.GetClosestBody();
60-
if (closestBody != null)
60+
var killedPlayer = GameData.Instance.GetPlayerById(closestBody.ParentId)?.Object;
61+
62+
var killer = Utils.GetKiller(killedPlayer);
63+
if (killer != null && killer.PlayerId == PlayerControl.LocalPlayer.PlayerId)
6164
{
62-
Utils.HandleRevive(PlayerControl.LocalPlayer, closestBody.ParentId, AmongUs.GameOptions.RoleTypes.Impostor, closestBody.TruePosition.x, closestBody.TruePosition.y);
65+
Coroutines.Start(CoroutinesHelper.CoNotify("Heads up: you tried to revive someone you killed, one use has been consumed"));
66+
return;
6367
}
68+
69+
SoundManager.Instance.PlaySound(NewModAsset.ReviveSound?.LoadAsset(), false, 2f);
70+
71+
Utils.HandleRevive(
72+
PlayerControl.LocalPlayer,
73+
closestBody.ParentId,
74+
RoleTypes.Impostor,
75+
closestBody.transform.position.x,
76+
closestBody.transform.position.y
77+
);
6478
}
6579
/// <summary>
6680
/// Determines whether this button is enabled for the role, returning true if the role is <see cref="NecromancerRole"/>.
@@ -78,32 +92,15 @@ public override bool Enabled(RoleBehaviour role)
7892
/// <returns>True if all requirements to use this button are met; otherwise false.</returns>
7993
public override bool CanUse()
8094
{
81-
bool isTimerDone = Timer <= 0;
82-
bool hasUsesLeft = UsesLeft > 0;
95+
if (Timer > 0) return false;
96+
if (UsesLeft <= 0) return false;
97+
8398
var closestBody = Utils.GetClosestBody();
84-
bool isNearDeadBody = closestBody != null;
85-
bool isFakeBody = isNearDeadBody && PranksterUtilities.IsPranksterBody(closestBody);
99+
if (closestBody == null) return false;
86100

87-
if (closestBody == null)
88-
{
89-
return false;
90-
}
101+
if (PranksterUtilities.IsPranksterBody(closestBody)) return false;
91102

92-
bool wasNotKilledByNecromancer = true;
93-
var deadBody = closestBody.GetComponent<DeadBody>();
94-
if (deadBody != null)
95-
{
96-
var killedPlayer = GameData.Instance.GetPlayerById(deadBody.ParentId)?.Object;
97-
if (killedPlayer != null)
98-
{
99-
var killer = Utils.GetKiller(killedPlayer);
100-
if (killer != null && killer.Data.Role is NecromancerRole)
101-
{
102-
wasNotKilledByNecromancer = false;
103-
}
104-
}
105-
}
106-
return isTimerDone && hasUsesLeft && isNearDeadBody && wasNotKilledByNecromancer && !isFakeBody;
103+
return true;
107104
}
108105
}
109106
}

NewMod/Utilities/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static PlayerControl PlayerById(byte id)
102102
/// <param name="victim">The player who was killed.</param>
103103
public static void RecordOnKill(PlayerControl killer, PlayerControl victim)
104104
{
105-
if (PlayerKiller.ContainsKey(killer))
105+
if (PlayerKiller.ContainsKey(victim))
106106
{
107107
PlayerKiller[victim] = killer;
108108
}

0 commit comments

Comments
 (0)