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

Commit

Permalink
Merge pull request #30 from LaicosVK/JesterClient
Browse files Browse the repository at this point in the history
Lawyer can have Jester as Client
  • Loading branch information
LaicosVK authored Feb 23, 2022
2 parents c68d25d + 321537b commit 0bbfd66
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
2 changes: 2 additions & 0 deletions TheOtherRoles/CustomOptionHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class CustomOptionHolder {
public static CustomOption jesterSpawnRate;
public static CustomOption jesterCanCallEmergency;
public static CustomOption jesterHasImpostorVision;
public static CustomOption jesterCanBeLawyerClient;

public static CustomOption arsonistSpawnRate;
public static CustomOption arsonistCooldown;
Expand Down Expand Up @@ -349,6 +350,7 @@ public static void Load() {
jesterSpawnRate = CustomOption.Create(60, cs(Jester.color, "Jester"), rates, null, true);
jesterCanCallEmergency = CustomOption.Create(61, "Jester Can Call Emergency Meeting", true, jesterSpawnRate);
jesterHasImpostorVision = CustomOption.Create(62, "Jester Has Impostor Vision", false, jesterSpawnRate);
jesterCanBeLawyerClient = CustomOption.Create(8999, "Jester Can Be Client Of Lawyer", false, jesterSpawnRate);

arsonistSpawnRate = CustomOption.Create(290, cs(Arsonist.color, "Arsonist"), rates, null, true);
arsonistCooldown = CustomOption.Create(291, "Arsonist Cooldown", 12.5f, 2.5f, 60f, 2.5f, arsonistSpawnRate);
Expand Down
33 changes: 18 additions & 15 deletions TheOtherRoles/Patches/EndGamePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,25 @@ public static void Postfix(AmongUsClient __instance, [HarmonyArgument(0)]ref End
}

// Possible Additional winner: Lawyer
if (!lawyerSoloWin && Lawyer.lawyer != null && Lawyer.target != null && !Lawyer.target.Data.IsDead) {
WinningPlayerData winningClient = null;
foreach (WinningPlayerData winner in TempData.winners) {
if (winner.PlayerName == Lawyer.target.Data.PlayerName)
winningClient = winner;
}
if (winningClient != null) { // The Lawyer wins if the client is winning (and alive, but if he wasn't the Lawyer shouldn't exist anymore)
if (!TempData.winners.ToArray().Any(x => x.PlayerName == Lawyer.lawyer.Data.PlayerName))
TempData.winners.Add(new WinningPlayerData(Lawyer.lawyer.Data));
if (!Lawyer.lawyer.Data.IsDead) { // The Lawyer steals the clients win
TempData.winners.Remove(winningClient);
AdditionalTempData.additionalWinConditions.Add(WinCondition.AdditionalLawyerStolenWin);
} else { // The Lawyer wins together with the client
AdditionalTempData.additionalWinConditions.Add(WinCondition.AdditionalLawyerBonusWin);
if (!lawyerSoloWin && Lawyer.lawyer != null && Lawyer.target != null) {
if (!Lawyer.target.Data.IsDead || (Jester.jester != null && Lawyer.target == Jester.jester)) {
WinningPlayerData winningClient = null;
foreach (WinningPlayerData winner in TempData.winners) {
if (winner.PlayerName == Lawyer.target.Data.PlayerName)
winningClient = winner;
}
}
if (winningClient != null) { // The Lawyer wins if the client is winning (and alive, but if he wasn't the Lawyer shouldn't exist anymore)
if (!TempData.winners.ToArray().Any(x => x.PlayerName == Lawyer.lawyer.Data.PlayerName))
TempData.winners.Add(new WinningPlayerData(Lawyer.lawyer.Data));
if (!Lawyer.lawyer.Data.IsDead) { // The Lawyer steals the clients win
TempData.winners.Remove(winningClient);
AdditionalTempData.additionalWinConditions.Add(WinCondition.AdditionalLawyerStolenWin);
}
else { // The Lawyer wins together with the client
AdditionalTempData.additionalWinConditions.Add(WinCondition.AdditionalLawyerBonusWin);
}
}
}
}

// Possible Additional winner: Pursuer
Expand Down
5 changes: 3 additions & 2 deletions TheOtherRoles/Patches/RoleAssignmentPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ private static void assignRoleTargets(RoleAssignmentData data) {
if (Lawyer.lawyer != null) {
var possibleTargets = new List<PlayerControl>();
foreach (PlayerControl p in PlayerControl.AllPlayerControls) {
if (!p.Data.IsDead && !p.Data.Disconnected && p != Lovers.lover1 && p != Lovers.lover2 && (p.Data.Role.IsImpostor || p == Jackal.jackal))
possibleTargets.Add(p);
// Only allow Jester as client if setting is true
if (!p.Data.IsDead && !p.Data.Disconnected && p != Lovers.lover1 && p != Lovers.lover2 && (p.Data.Role.IsImpostor || p == Jackal.jackal || (p == Jester.jester && Jester.canBeLawyerClient)))
possibleTargets.Add(p);
}
if (possibleTargets.Count == 0) {
MessageWriter w = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.LawyerPromotesToPursuer, Hazel.SendOption.Reliable, -1);
Expand Down
10 changes: 7 additions & 3 deletions TheOtherRoles/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,17 @@ public static void lawyerSetTarget(byte playerId) {
public static void lawyerPromotesToPursuer() {
PlayerControl player = Lawyer.lawyer;
PlayerControl client = Lawyer.target;

// Don't promote to pursuer if target is jester and jester was exiled
if (client != null && client == Jester.jester && ExileController.Instance.exiled != null && ExileController.Instance.exiled.PlayerId == Jester.jester.PlayerId) return;

Lawyer.clearAndReload();
Pursuer.pursuer = player;

if (player.PlayerId == PlayerControl.LocalPlayer.PlayerId && client != null) {
Transform playerInfoTransform = client.nameText.transform.parent.FindChild("Info");
TMPro.TextMeshPro playerInfo = playerInfoTransform != null ? playerInfoTransform.GetComponent<TMPro.TextMeshPro>() : null;
if (playerInfo != null) playerInfo.text = "";
Transform playerInfoTransform = client.nameText.transform.parent.FindChild("Info");
TMPro.TextMeshPro playerInfo = playerInfoTransform != null ? playerInfoTransform.GetComponent<TMPro.TextMeshPro>() : null;
if (playerInfo != null) playerInfo.text = "";
}
}

Expand Down
2 changes: 2 additions & 0 deletions TheOtherRoles/TheOtherRoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ public static class Jester {
public static bool triggerJesterWin = false;
public static bool canCallEmergency = true;
public static bool hasImpostorVision = false;
public static bool canBeLawyerClient = false;

public static void clearAndReload() {
jester = null;
triggerJesterWin = false;
canCallEmergency = CustomOptionHolder.jesterCanCallEmergency.getBool();
hasImpostorVision = CustomOptionHolder.jesterHasImpostorVision.getBool();
canBeLawyerClient = CustomOptionHolder.jesterCanBeLawyerClient.getBool();
}
}

Expand Down

0 comments on commit 0bbfd66

Please sign in to comment.