Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions source/Patches/CrewmateRoles/InvestigatorMod/AddPrints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,21 @@ public static void Postfix(HudManager __instance)
if (_time >= Interval)
{
_time -= Interval;
foreach (var player in PlayerControl.AllPlayerControls)
{
if (player == null || player.Data.IsDead ||
player.PlayerId == PlayerControl.LocalPlayer.PlayerId) continue;
if (!(investigator.InvestigatedPlayer == null || investigator.InvestigatedPlayer.Data.IsDead ||
investigator.InvestigatedPlayer.PlayerId == PlayerControl.LocalPlayer.PlayerId))
{
var canPlace = !investigator.AllPrints.Any(print =>
Vector3.Distance(print.Position, Position(player)) < 0.5f &&
Vector3.Distance(print.Position, Position(investigator.InvestigatedPlayer)) < 0.5f &&
print.Color.a > 0.5 &&
print.Player.PlayerId == player.PlayerId);
print.Player.PlayerId == investigator.InvestigatedPlayer.PlayerId);

if (Vent && ShipStatus.Instance != null)
if (ShipStatus.Instance.AllVents.Any(vent =>
Vector2.Distance(vent.gameObject.transform.position, Position(player)) < 1f))
Vector2.Distance(vent.gameObject.transform.position, Position(investigator.InvestigatedPlayer)) < 1f))
canPlace = false;

if (canPlace) new Footprint(player, investigator);
}
if (canPlace) new Footprint(investigator.InvestigatedPlayer, investigator);
}

for (var i = 0; i < investigator.AllPrints.Count; i++)
{
Expand Down
23 changes: 2 additions & 21 deletions source/Patches/CrewmateRoles/InvestigatorMod/Footprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using UnityEngine;
using TownOfUs.Extensions;
using TownOfUs.Patches;

namespace TownOfUs.CrewmateRoles.InvestigatorMod
{
public class Footprint
Expand All @@ -12,82 +11,64 @@ public class Footprint
private SpriteRenderer _spriteRenderer;
private readonly float _time;
private readonly Vector2 _velocity;

public Color Color;
public Vector3 Position;
public Investigator Role;

public Footprint(PlayerControl player, Investigator role)
{
Role = role;
Position = player.transform.position;
_velocity = player.gameObject.GetComponent<Rigidbody2D>().velocity;

Player = player;
_time = (int) Time.time;
Color = Color.black;

Start();
role.AllPrints.Add(this);
}

public static float Duration => CustomGameOptions.FootprintDuration;

public static bool Grey =>
CustomGameOptions.AnonymousFootPrint || CamouflageUnCamouflage.IsCamoed;

public static void DestroyAll(Investigator role)
{
while (role.AllPrints.Count != 0) role.AllPrints[0].Destroy();
}


private void Start()
{
_gameObject = new GameObject("Footprint");
_gameObject.AddSubmergedComponent(SubmergedCompatibility.Classes.ElevatorMover);
_gameObject.transform.position = Position;
_gameObject.transform.Rotate(Vector3.forward * Vector2.SignedAngle(Vector2.up, _velocity));
_gameObject.transform.SetParent(Player.transform.parent);

_spriteRenderer = _gameObject.AddComponent<SpriteRenderer>();
_spriteRenderer.sprite = TownOfUs.Footprint;
_spriteRenderer.color = Color;
_gameObject.transform.localScale *= new Vector2(1.2f, 1f) * (CustomGameOptions.FootprintSize / 10);

_gameObject.SetActive(true);
}

private void Destroy()
{
Object.Destroy(_gameObject);
Role.AllPrints.Remove(this);
}

public bool Update()
{
var currentTime = Time.time;
var alpha = Mathf.Max(1f - (currentTime - _time) / Duration, 0f);

if (alpha < 0 || alpha > 1)
alpha = 0;
if (RainbowUtils.IsRainbow(Player.GetDefaultOutfit().ColorId) & !Grey)

if (RainbowUtils.IsRainbow(Player.GetDefaultOutfit().ColorId))
Color = RainbowUtils.Rainbow;
else if (Grey)
Color = new Color(0.2f, 0.2f, 0.2f, 1f);
else
Color = Palette.PlayerColors[Player.GetDefaultOutfit().ColorId];

Color = new Color(Color.r, Color.g, Color.b, alpha);
_spriteRenderer.color = Color;

if (_time + (int) Duration < currentTime)
{
Destroy();
return true;
}

return false;
}
}
Expand Down
79 changes: 79 additions & 0 deletions source/Patches/CrewmateRoles/InvestigatorMod/HudInvestigate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using AmongUs.GameOptions;
using HarmonyLib;
using Il2CppSystem.Reflection;
using TownOfUs.Roles;
using UnityEngine;
using TownOfUs.Extensions;
using Reactor.Utilities;

namespace TownOfUs.CrewmateRoles.InvestigatorMod
{
[HarmonyPatch(typeof(HudManager))]
public class HudInvestigate
{

[HarmonyPatch(nameof(HudManager.Update))]
public static void Postfix(HudManager __instance)
{
UpdateInvestigateButton(__instance);
}

public static void UpdateInvestigateButton(HudManager __instance)
{
if (PlayerControl.AllPlayerControls.Count <= 1) return;
if (PlayerControl.LocalPlayer == null) return;
if (PlayerControl.LocalPlayer.Data == null) return;
if (!PlayerControl.LocalPlayer.Is(RoleEnum.Investigator)) return;

var role = Role.GetRole<Investigator>(PlayerControl.LocalPlayer);

if (role.ShouldNotify)
{
role.ShouldRemove = true;
Coroutines.Start(Utils.FlashCoroutine(Color.cyan));
}

if (role.InvestigatedPlayer != null)
{
role.InvestigatedPlayer.myRend().material.SetColor("_VisorColor", Color.cyan);
role.InvestigatedPlayer.nameText().color = Color.cyan;
if (role.InvestigatedPlayer.Data.IsDead || role.InvestigatedPlayer.Data.Disconnected)
{
role.PreviouslyInvestigated.Add(role.InvestigatedPlayer.PlayerId);
role.InvestigatedPlayer = null;
Utils.Rpc(CustomRPC.StopInvestigation, role.Player.PlayerId);
role.StartRemoving = false;
role.ShouldNotify = false;
role.ShouldRemove = false;
MeetingStart.RoleList.Clear();
MeetingStart.OnCrewRoles.Clear();
MeetingStart.OnNeutRoles.Clear();
MeetingStart.OnImpRoles.Clear();
MeetingStart.SetRole = false;
Coroutines.Start(Utils.FlashCoroutine(Color.red));
}
}

var InvestigateButton = __instance.KillButton;

InvestigateButton.gameObject.SetActive((__instance.UseButton.isActiveAndEnabled || __instance.PetButton.isActiveAndEnabled)
&& !MeetingHud.Instance && !PlayerControl.LocalPlayer.Data.IsDead
&& AmongUsClient.Instance.GameState == InnerNet.InnerNetClient.GameStates.Started);

InvestigateButton.SetCoolDown(role.InvestigateTimer(), CustomGameOptions.InvestCd);
Utils.SetTarget(ref role.ClosestPlayer, InvestigateButton, float.NaN);

var renderer = InvestigateButton.graphic;
if (role.ClosestPlayer != null)
{
renderer.color = Palette.EnabledColor;
renderer.material.SetFloat("_Desat", 0f);
}
else
{
renderer.color = Palette.DisabledClear;
renderer.material.SetFloat("_Desat", 1f);
}
}
}
}
30 changes: 30 additions & 0 deletions source/Patches/CrewmateRoles/InvestigatorMod/MeetingHudUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using HarmonyLib;
using TownOfUs.Roles;
using UnityEngine;

namespace TownOfUs.CrewmateRoles.InvestigatorMod
{
[HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Update))]
public static class MeetingHudUpdate
{
public static void Postfix(MeetingHud __instance)
{
var localPlayer = PlayerControl.LocalPlayer;
var _role = Role.GetRole(localPlayer);
if (_role?.RoleType != RoleEnum.Investigator) return;
if (localPlayer.Data.IsDead) return;
var role = (Investigator)_role;
foreach (var state in __instance.playerStates)
{
var targetId = state.TargetPlayerId;
var playerData = Utils.PlayerById(targetId)?.Data;
if (playerData == null || playerData.Disconnected)
{
role.InvestigatedPlayer = null;
continue;
}
if (role.InvestigatedPlayer.PlayerId == targetId) state.NameText.color = Color.cyan;
}
}
}
}
Loading