Files
EndlessHostRoles/Roles/Standard/Impostor/Support/Ventriloquist.cs
T
Newchan 4d6f697dbc More Custom Button Images (#5) + Additional Meeting UI for some roles (#636)
* More custom buttons (Meeting SS and Client buttons)

* more additions...

* since its not needed, reverted it

* hmm what?

* bruh, literally blocked meeting shapeshift button having custom buttons
2026-06-28 18:28:00 +02:00

90 lines
3.3 KiB
C#

using System;
using UnityEngine;
namespace EHR.Roles;
public class Ventriloquist : RoleBase
{
public static bool On;
private static OptionItem UseLimit;
private static OptionItem VentriloquistAbilityUseGainWithEachKill;
public byte Target;
public override bool IsEnable => On;
public override void SetupCustomOption()
{
Options.SetupRoleOptions(649650, TabGroup.ImpostorRoles, CustomRoles.Ventriloquist);
UseLimit = new FloatOptionItem(649652, "AbilityUseLimit", new(0, 20, 0.05f), 0, TabGroup.ImpostorRoles)
.SetParent(Options.CustomRoleSpawnChances[CustomRoles.Ventriloquist])
.SetValueFormat(OptionFormat.Times);
VentriloquistAbilityUseGainWithEachKill = new FloatOptionItem(649653, "AbilityUseGainWithEachKill", new(0f, 5f, 0.1f), 2f, TabGroup.ImpostorRoles)
.SetParent(Options.CustomRoleSpawnChances[CustomRoles.Ventriloquist])
.SetValueFormat(OptionFormat.Times);
}
public override void Init()
{
On = false;
}
public override void Add(byte playerId)
{
On = true;
Target = byte.MaxValue;
playerId.SetAbilityUseLimit(UseLimit.GetFloat());
}
public override void OnMeetingShapeshift(PlayerControl shapeshifter, PlayerControl target)
{
var command = $"/target {target.PlayerId}";
ChatCommands.TargetCommand(shapeshifter, command, command.Split(' '));
}
private static void VentriloquistOnClick(byte playerId /*, MeetingHud __instance*/)
{
Logger.Msg($"Click: ID {playerId}", "Ventriloquist UI");
PlayerControl pc = Utils.GetPlayerById(playerId);
if (pc == null || !pc.IsAlive() || !GameStates.IsVoting || Starspawn.IsDayBreak) return;
var command = $"/target {playerId}";
if (AmongUsClient.Instance.AmHost)
ChatCommands.TargetCommand(PlayerControl.LocalPlayer, command, command.Split(' '));
else
ChatCommands.RequestCommandProcessingFromHost(command, "Target");
}
public static void CreateVentriloquistButton(MeetingHud __instance)
{
foreach (PlayerVoteArea pva in __instance.playerStates)
{
PlayerControl pc = Utils.GetPlayerById(pva.TargetPlayerId);
if (!pc || !pc.IsAlive()) continue;
GameObject template = pva.Buttons.transform.Find("CancelButton").gameObject;
GameObject targetBox = Object.Instantiate(template, pva.transform);
targetBox.name = "ShootButton";
targetBox.transform.localPosition = new(-0.35f, 0.03f, -1.31f);
var renderer = targetBox.GetComponent<SpriteRenderer>();
renderer.sprite = Utils.LoadSprite("EHR.Resources.Images.Skills.Hack.png", 160f);
var button = targetBox.GetComponent<PassiveButton>();
button.OnClick.RemoveAllListeners();
button.OnClick.AddListener((Action)(() => VentriloquistOnClick(pva.TargetPlayerId)));
}
}
//[HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Start))]
public static class StartMeetingPatch
{
public static void Postfix(MeetingHud __instance)
{
if (PlayerControl.LocalPlayer.Is(CustomRoles.Ventriloquist) && PlayerControl.LocalPlayer.IsAlive())
CreateVentriloquistButton(__instance);
}
}
}