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

Commit

Permalink
fix(Underdog): set kill timer correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
NotSugden committed Jun 29, 2021
1 parent 71212ac commit 4d232f0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
20 changes: 20 additions & 0 deletions source/Patches/ImpostorRoles/UnderdogMod/PatchKillTimer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using HarmonyLib;
using TownOfUs.Roles;
using UnityEngine;

namespace TownOfUs.ImpostorRoles.UnderdogMod
{
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.SetKillTimer))]
public static class PatchKillTimer
{
public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] float time)
{
var role = Role.GetRole(__instance);
if (role?.RoleType != RoleEnum.Underdog) return true;
var maxTimer = ((Underdog)role).MaxTimer();
__instance.killTimer = Mathf.Clamp(time, 0, maxTimer);
HudManager.Instance.KillButton.SetCoolDown(__instance.killTimer, maxTimer);
return false;
}
}
}
14 changes: 8 additions & 6 deletions source/Patches/ImpostorRoles/UnderdogMod/PerformKill.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using System.Linq;
using HarmonyLib;
using TownOfUs.Roles;

namespace TownOfUs.ImpostorRoles.UnderdogMod
{
Expand All @@ -8,14 +9,15 @@ public class PerformKill
{
public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] PlayerControl target)
{
if (__instance.Is(RoleEnum.Underdog))
__instance.SetKillTimer(PlayerControl.GameOptions.KillCooldown * (LastImp() ? 0.5f : 1.5f));
var role = Role.GetRole(__instance);
if (role?.RoleType == RoleEnum.Underdog)
((Underdog)role).SetKillTimer();
}

internal static bool LastImp()
{
return PlayerControl.AllPlayerControls.ToArray().Count(x => x.Data.IsImpostor && !x.Data.IsDead) ==
1;
return PlayerControl.AllPlayerControls.ToArray()
.Count(x => x.Data.IsImpostor && !x.Data.IsDead) == 1;
}
}
}
}
9 changes: 4 additions & 5 deletions source/Patches/ImpostorRoles/UnderdogMod/PostMeeting.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using TownOfUs.Roles;
using UnityEngine;

namespace TownOfUs.ImpostorRoles.UnderdogMod
Expand All @@ -8,11 +9,9 @@ public static class HUDClose
{
public static void Postfix()
{
var localPlayer = PlayerControl.LocalPlayer;
if (localPlayer.Is(RoleEnum.Underdog))
localPlayer.SetKillTimer(PlayerControl.GameOptions.KillCooldown * (
PerformKill.LastImp() ? 0.5f : 1.5f
));
var role = Role.GetRole(PlayerControl.LocalPlayer);
if (role?.RoleType == RoleEnum.Underdog)
((Underdog)role).SetKillTimer();
}
}
}
13 changes: 12 additions & 1 deletion source/Patches/Roles/Underdog.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using TownOfUs.ImpostorRoles.UnderdogMod;

namespace TownOfUs.Roles
{
public class Underdog : Role
Expand All @@ -11,5 +13,14 @@ public Underdog(PlayerControl player) : base(player)
RoleType = RoleEnum.Underdog;
Faction = Faction.Impostors;
}

public float MaxTimer() => PlayerControl.GameOptions.KillCooldown * (
PerformKill.LastImp() ? 0.5f : 1.5f
);

public void SetKillTimer()
{
Player.SetKillTimer(MaxTimer());
}
}
}
}

0 comments on commit 4d232f0

Please sign in to comment.