Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
refactor: enable chat only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
NotSugden committed Jul 12, 2021
1 parent 89c211e commit 782a4f4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 42 deletions.
19 changes: 10 additions & 9 deletions source/Patches/CrewmateRoles/InvestigatorMod/AddPrints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static class AddPrints
private static Vector2 Position(PlayerControl player) =>
player.GetTruePosition() + new Vector2(0, 0.366667f);


public static void Postfix(PlayerControl __instance)
{
// only update on local player
Expand All @@ -32,17 +31,19 @@ public static void Postfix(PlayerControl __instance)
_time -= Interval;
foreach (var player in PlayerControl.AllPlayerControls)
{
if (player == null || player.Data.IsDead ||
player.PlayerId == PlayerControl.LocalPlayer.PlayerId) continue;
if (player.Data.IsDead || player.AmOwner) continue;
var canPlace = !investigator.AllPrints.Any(print =>
Vector3.Distance(print.Position, Position(player)) < 0.5f &&
print.Color.a > 0.5 &&
print.Player.PlayerId == player.PlayerId);

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

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

if (canPlace) new Footprint(player, investigator);
}
Expand Down
7 changes: 4 additions & 3 deletions source/Patches/CrewmateRoles/InvestigatorMod/Footprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ public bool Update()
if (alpha < 0 || alpha > 1)
alpha = 0;

if (RainbowUtils.IsRainbow(Player.Data.ColorId) & !Grey)
Color = RainbowUtils.Rainbow;
else if (Grey)

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

Expand Down
9 changes: 3 additions & 6 deletions source/Patches/CrewmateRoles/InvestigatorMod/StartGame.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using HarmonyLib;
using HarmonyLib;

namespace TownOfUs.CrewmateRoles.InvestigatorMod
{
[HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.Start))]
public static class StartGame
{
public static void Postfix(ShipStatus __instance)
{
AddPrints.GameStarted = true;
}
public static void Postfix() => AddPrints.GameStarted = true;
}
}
}
24 changes: 18 additions & 6 deletions source/Patches/CrewmateRoles/LoversMod/Chat.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;

namespace TownOfUs.CrewmateRoles.LoversMod
{
Expand All @@ -17,14 +17,26 @@ public static bool Prefix(ChatController __instance, [HarmonyArgument(0)] Player
}
}

[HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))]
[HarmonyPatch]
public static class EnableChat
{
public static void Postfix(HudManager __instance)
public static void Enable()
{
if (PlayerControl.LocalPlayer.IsLover() & !__instance.Chat.isActiveAndEnabled)
__instance.Chat.SetVisible(true);
if (PlayerControl.LocalPlayer.IsLover())
HudManager.Instance.Chat.SetVisible(true);
}

[HarmonyPostfix]
[HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Close))]
public static void MeetingClose() => Enable();

[HarmonyPostfix]
[HarmonyPatch(typeof(ShipStatus), nameof(ShipStatus.SpawnPlayer))]
public static void SpawnPlayer() => Enable();

[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.Revive))]
public static void OnRevive() => Enable();
}
}
}
}
15 changes: 5 additions & 10 deletions source/Patches/CrewmateRoles/LoversMod/Die.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
namespace TownOfUs.CrewmateRoles.LoversMod
{
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.Die))]
public class Die
public static class Die
{
public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] DeathReason reason)
public static void Postfix(PlayerControl __instance)
{
__instance.Data.IsDead = true;
if (!CustomGameOptions.BothLoversDie || !__instance.IsLover()) return;


var flag3 = __instance.IsLover() && CustomGameOptions.BothLoversDie;
if (!flag3) return true;
var otherLover = Role.GetRole<Lover>(__instance).OtherLover.Player;
if (otherLover.Data.IsDead) return true;

if (AmongUsClient.Instance.AmHost) Utils.RpcMurderPlayer(otherLover, otherLover);
if (otherLover.Data.IsDead) return;

return true;
Utils.MurderPlayer(otherLover, otherLover);
}
}
}
8 changes: 3 additions & 5 deletions source/Patches/CrewmateRoles/LoversMod/Outro.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using HarmonyLib;
using TMPro;
using TownOfUs.Roles;
Expand All @@ -7,7 +7,7 @@
namespace TownOfUs.CrewmateRoles.LoversMod
{
[HarmonyPatch(typeof(EndGameManager), nameof(EndGameManager.Start))]
internal class Outro
public static class Outro
{
public static void Postfix(EndGameManager __instance)
{
Expand All @@ -23,7 +23,6 @@ public static void Postfix(EndGameManager __instance)
pos = __instance.WinText.transform.localPosition;
pos.y = 1.5f;
text.transform.position = pos;
// text.scale = 0.5f;
return;
}

Expand Down Expand Up @@ -57,7 +56,6 @@ public static void Postfix(EndGameManager __instance)
pos = __instance.WinText.transform.localPosition;
pos.y = 1.5f;
text.transform.position = pos;
// text.scale = 1f;
}
}
}
}
6 changes: 3 additions & 3 deletions source/Patches/NeutralRoles/JesterMod/EndGame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using Hazel;
using TownOfUs.Roles;

Expand All @@ -16,11 +16,11 @@ public static bool Prefix(ShipStatus __instance, [HarmonyArgument(0)] GameOverRe
((Jester) role).Loses();

var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId,
(byte) CustomRPC.JesterLose,
(byte)CustomRPC.JesterLose,
SendOption.Reliable, -1);
AmongUsClient.Instance.FinishRpcImmediately(writer);

return true;
}
}
}
}

0 comments on commit 782a4f4

Please sign in to comment.