Add CanUseSabotage support in ICustomRole

This commit is contained in:
CallOfCreator committed 2024-09-04 16:27:57 +00:00
1 parent a442f54b82
commit 75dd5e8a35
2 files changed
+40

No files matched your search

+35
View File
@@ -1,5 +1,6 @@
using HarmonyLib;
using MiraAPI.Hud;
using MiraAPI.Roles;
using Reactor.Utilities.Extensions;
using UnityEngine;
using Object = UnityEngine.Object;
@@ -92,10 +93,44 @@ public static class HudManagerPatches
{
return;
}
if (CustomRoleManager.GetCustomRoleBehaviour(role.Role, out var customRole))
{
if (customRole.CanUseSabotage)
{
__instance.SabotageButton.gameObject.SetActive(true);
}
else
{
__instance.SabotageButton.gameObject.SetActive(role.IsImpostor && isActive);
}
}
foreach (var button in CustomButtonManager.CustomButtons)
{
button.SetActive(isActive, role);
}
}
/// <summary>
/// Patches the Sabotage button to check if the player's custom role can use sabotage.
/// </summary>
[HarmonyPatch(typeof(SabotageButton), nameof(SabotageButton.DoClick))]
[HarmonyPrefix]
public static bool StartPrefix(SabotageButton __instance)
{
var player = PlayerControl.LocalPlayer;
if (CustomRoleManager.GetCustomRoleBehaviour(player.Data.Role.Role, out var customRole))
{
if (!customRole.CanUseSabotage) return false;
DestroyableSingleton<HudManager>.Instance.ToggleMapVisible(new MapOptions()
{
Mode = MapOptions.Modes.Sabotage
});
return false;
}
return true;
}
}
+5
View File
@@ -77,6 +77,11 @@ public interface ICustomRole
/// </summary>
bool CanUseVent => Team == ModdedRoleTeams.Impostor;
/// <summary>
/// Gets a value indicating whether the role can use the sabotage button.
/// </summary>
bool CanUseSabotage => Team == ModdedRoleTeams.Impostor;
/// <summary>
/// Gets a value indicating whether the role's tasks count towards task progress.
/// </summary>