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

Commit

Permalink
Merge pull request #232 from NotSugden/fix-underdog
Browse files Browse the repository at this point in the history
fix(Underdog): change kill cooldown at the end of a meeting
  • Loading branch information
cybershard authored Jun 30, 2021
2 parents ebba1fa + 4d232f0 commit 249a5ef
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 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;
}
}
}
}
16 changes: 8 additions & 8 deletions source/Patches/ImpostorRoles/UnderdogMod/PostMeeting.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using HarmonyLib;
using HarmonyLib;
using TownOfUs.Roles;
using UnityEngine;

namespace TownOfUs.ImpostorRoles.UnderdogMod
{
[HarmonyPatch(typeof(Object), nameof(Object.Destroy), typeof(Object))]
[HarmonyPatch(typeof(ExileController), nameof(ExileController.WrapUp))]
public static class HUDClose
{
public static void Postfix(Object obj)
public static void Postfix()
{
if (ExileController.Instance == null || obj != ExileController.Instance.gameObject) return;
if (PlayerControl.LocalPlayer.Is(RoleEnum.Underdog))
PlayerControl.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 249a5ef

Please sign in to comment.