Skip to content

Commit

Permalink
Small bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dabao40 committed Nov 23, 2024
1 parent 5461be3 commit cefc82d
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 212 deletions.
72 changes: 36 additions & 36 deletions TheOtherRoles/Buttons.cs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions TheOtherRoles/Objects/CustomButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public void setActive(bool isActive) {

public void Update()
{
var localPlayer = CachedPlayer.LocalPlayer.PlayerControl;
var moveable = localPlayer.moveable;
var localPlayer = CachedPlayer.LocalPlayer;
var moveable = localPlayer.PlayerControl.moveable;

if (localPlayer.Data == null || MeetingHud.Instance || ExileController.Instance || !HasButton()) {
setActive(false);
Expand All @@ -193,7 +193,7 @@ public void Update()
if (DeputyTimer >= 0) { // This had to be reordered, so that the handcuffs do not stop the underlying timers from running
if (HasEffect && isEffectActive)
DeputyTimer -= Time.deltaTime;
else if (!localPlayer.inVent && moveable)
else if (!localPlayer.PlayerControl.inVent && moveable)
DeputyTimer -= Time.deltaTime;
}

Expand Down Expand Up @@ -237,7 +237,7 @@ public void Update()
if (Timer <= 3f && Timer > 0f && shakeOnEnd)
actionButton.graphic.transform.localPosition = actionButton.transform.localPosition + (Vector3)UnityEngine.Random.insideUnitCircle * 0.05f;
}
else if (!localPlayer.inVent && moveable)
else if (!localPlayer.PlayerControl.inVent && moveable)
Timer -= Time.deltaTime;
}

Expand Down
7 changes: 7 additions & 0 deletions TheOtherRoles/Patches/ExileControllerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ static void WrapUpPostfix(NetworkedPlayerInfo exiled)
// AntiTeleport set position
AntiTeleport.setPosition();

// Remove DeadBodys
DeadBody[] array = UnityEngine.Object.FindObjectsOfType<DeadBody>();
for (int i = 0; i < array.Length; i++)
{
UnityEngine.Object.Destroy(array[i].gameObject);
}

MapBehaviourPatch.resetRealTasks();

if (CustomOptionHolder.randomGameStartPosition.getBool() && (AntiTeleport.antiTeleport.FindAll(x => x.PlayerId == CachedPlayer.LocalPlayer.PlayerControl.PlayerId).Count == 0))
Expand Down
2 changes: 2 additions & 0 deletions TheOtherRoles/Patches/MeetingPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,8 @@ public static void Prefix(PlayerControl __instance, [HarmonyArgument(0)]Networke
// Resett Bait list
//Bait.active = new Dictionary<DeadPlayer, float>();
// Save AntiTeleport position, if the player is able to move (i.e. not on a ladder or a gap thingy)
Bait.reported = true;

if (CachedPlayer.LocalPlayer.PlayerPhysics.enabled && (CachedPlayer.LocalPlayer.PlayerControl.moveable || CachedPlayer.LocalPlayer.PlayerControl.inVent
|| HudManagerStartPatch.hackerVitalsButton.isEffectActive || HudManagerStartPatch.hackerAdminTableButton.isEffectActive || HudManagerStartPatch.securityGuardCamButton.isEffectActive
|| Portal.isTeleporting && Portal.teleportedPlayers.Last().playerId == CachedPlayer.LocalPlayer.PlayerId))
Expand Down
123 changes: 28 additions & 95 deletions TheOtherRoles/Patches/PlayerControlPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ static void baitUpdate()
if (Bait.bait == null || Bait.bait != CachedPlayer.LocalPlayer.PlayerControl) return;

// Bait report
if (Bait.bait.Data.IsDead && !Bait.reported && Bait.killed)
if (Bait.bait.Data.IsDead && !Bait.reported)
{
Bait.reportDelay -= Time.fixedDeltaTime;
DeadPlayer deadPlayer = deadPlayers?.Where(x => x.player?.PlayerId == Bait.bait.PlayerId)?.FirstOrDefault();
Expand Down Expand Up @@ -1226,6 +1226,15 @@ static void bountyHunterUpdate() {
}
}

static void schrodingersCatUpdate()
{
if (SchrodingersCat.schrodingersCat == null || CachedPlayer.LocalPlayer.PlayerControl != SchrodingersCat.schrodingersCat) return;
if (SchrodingersCat.schrodingersCat.Data.IsDead || SchrodingersCat.hasTeam() || MeetingHud.Instance || ExileController.Instance) {
if (SchrodingersCat.shownMenu) SchrodingersCat.showMenu();
return;
}
}

static void jekyllAndHydeSetTarget()
{
if (JekyllAndHyde.jekyllAndHyde == null || CachedPlayer.LocalPlayer.PlayerControl != JekyllAndHyde.jekyllAndHyde || JekyllAndHyde.jekyllAndHyde.Data.IsDead || JekyllAndHyde.isJekyll()) return;
Expand Down Expand Up @@ -1615,9 +1624,7 @@ public static void cupidUpdate()
{
HudManagerStartPatch.cupidTimeRemainingText.text = TimeSpan.FromSeconds(Cupid.timeLeft).ToString(@"mm\:ss");
}
HudManagerStartPatch.cupidTimeRemainingText.enabled = !(MapBehaviour.Instance && MapBehaviour.Instance.IsOpen) &&
!MeetingHud.Instance &&
!ExileController.Instance;
HudManagerStartPatch.cupidTimeRemainingText.enabled = Helpers.ShowButtons;
}
else HudManagerStartPatch.cupidTimeRemainingText.enabled = false;
}
Expand Down Expand Up @@ -1646,9 +1653,7 @@ public static void akujoUpdate()
{
HudManagerStartPatch.akujoTimeRemainingText.text = TimeSpan.FromSeconds(Akujo.timeLeft).ToString(@"mm\:ss");
}
HudManagerStartPatch.akujoTimeRemainingText.enabled = !(MapBehaviour.Instance && MapBehaviour.Instance.IsOpen) &&
!MeetingHud.Instance &&
!ExileController.Instance;
HudManagerStartPatch.akujoTimeRemainingText.enabled = Helpers.ShowButtons;
}
else HudManagerStartPatch.akujoTimeRemainingText.enabled = false;
}
Expand Down Expand Up @@ -2125,6 +2130,8 @@ public static void Postfix(PlayerControl __instance) {
// Cupid
cupidSetTarget();
cupidUpdate();
// Schrodinger's Cat
schrodingersCatUpdate();
// Blackmailer
blackmailerSetTarget();
// Prophet
Expand Down Expand Up @@ -2400,7 +2407,7 @@ public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)]PlayerC
// Show flash on bait kill to the killer if enabled
if (Bait.bait != null && target == Bait.bait)
{
Bait.killed = true;
Bait.reported = false;
if (Bait.showKillFlash && __instance != Bait.bait && __instance == CachedPlayer.LocalPlayer.PlayerControl) {
Helpers.showFlash(new Color(204f / 255f, 102f / 255f, 0f / 255f));
}
Expand Down Expand Up @@ -3020,23 +3027,12 @@ public static void Postfix(PlayerControl __instance)
if (NekoKabocha.nekoKabocha != null && __instance == NekoKabocha.nekoKabocha && NekoKabocha.meetingKiller != null)
{
PlayerControl killer = NekoKabocha.meetingKiller;
bool revengeFlag = (NekoKabocha.revengeCrew && (!Helpers.isNeutral(killer) && !killer.Data.Role.IsImpostor)) ||
bool revengeFlag = (NekoKabocha.revengeCrew && !Helpers.isNeutral(killer) && !killer.Data.Role.IsImpostor) ||
(NekoKabocha.revengeNeutral && Helpers.isNeutral(killer)) ||
(NekoKabocha.revengeImpostor && killer.Data.Role.IsImpostor);

if (MeetingHud.Instance && revengeFlag)
{
foreach (PlayerVoteArea pva in MeetingHud.Instance.playerStates)
{
if (pva.VotedFor != killer.PlayerId) continue;
pva.UnsetVote();
var voteAreaPlayer = Helpers.playerById(pva.TargetPlayerId);
if (!voteAreaPlayer.AmOwner) continue;
MeetingHud.Instance.ClearVote();
}

if (AmongUsClient.Instance.AmHost)
MeetingHud.Instance.CheckForEndVoting();
if (MeetingHud.Instance && revengeFlag) {
RPCProcedure.updateMeeting(killer.PlayerId);
}
}

Expand All @@ -3063,30 +3059,10 @@ public static void Postfix(PlayerControl __instance)
}

if (MeetingHud.Instance && otherLover != null)
{
foreach (PlayerVoteArea pva in MeetingHud.Instance.playerStates)
{
if (pva.VotedFor != otherLover.PlayerId) continue;
pva.UnsetVote();
var voteAreaPlayer = Helpers.playerById(pva.TargetPlayerId);
if (!voteAreaPlayer.AmOwner) continue;
MeetingHud.Instance.ClearVote();
}

if (Cupid.cupid != null && !Cupid.cupid.Data.IsDead)
{
foreach (PlayerVoteArea pva in MeetingHud.Instance.playerStates)
{
if (pva.VotedFor != Cupid.cupid.PlayerId) continue;
pva.UnsetVote();
var voteAreaPlayer = Helpers.playerById(pva.TargetPlayerId);
if (!voteAreaPlayer.AmOwner) continue;
MeetingHud.Instance.ClearVote();
}
}

if (AmongUsClient.Instance.AmHost)
MeetingHud.Instance.CheckForEndVoting();
{
RPCProcedure.updateMeeting(otherLover.PlayerId);
if (Cupid.cupid != null && !Cupid.cupid.Data.IsDead)
RPCProcedure.updateMeeting(Cupid.cupid.PlayerId);
}

if (Cupid.cupid != null && !Cupid.cupid.Data.IsDead)
Expand All @@ -3103,23 +3079,8 @@ public static void Postfix(PlayerControl __instance)
if (MimicK.ifOneDiesBothDie && !otherMimic.Data.IsDead)
{
otherMimic.Exiled();
GameHistory.overrideDeathReasonAndKiller(otherMimic, DeadPlayer.CustomDeathReason.Suicide);
}

// Going to reset the votes here
if (MeetingHud.Instance && MimicK.ifOneDiesBothDie && otherMimic != null)
{
foreach (PlayerVoteArea pva in MeetingHud.Instance.playerStates)
{
if (pva.VotedFor != otherMimic.PlayerId) continue;
pva.UnsetVote();
var voteAreaPlayer = Helpers.playerById(pva.TargetPlayerId);
if (!voteAreaPlayer.AmOwner) continue;
MeetingHud.Instance.ClearVote();
}

if (AmongUsClient.Instance.AmHost)
MeetingHud.Instance.CheckForEndVoting();
GameHistory.overrideDeathReasonAndKiller(otherMimic, DeadPlayer.CustomDeathReason.Suicide);
RPCProcedure.updateMeeting(otherMimic.PlayerId);
}
}

Expand All @@ -3130,22 +3091,8 @@ public static void Postfix(PlayerControl __instance)
if (otherBomber != null && BomberA.ifOneDiesBothDie && !otherBomber.Data.IsDead)
{
otherBomber.Exiled();
GameHistory.overrideDeathReasonAndKiller(otherBomber, DeadPlayer.CustomDeathReason.Suicide);
}

if (MeetingHud.Instance && BomberA.ifOneDiesBothDie && otherBomber != null)
{
foreach (PlayerVoteArea pva in MeetingHud.Instance.playerStates)
{
if (pva.VotedFor != otherBomber.PlayerId) continue;
pva.UnsetVote();
var voteAreaPlayer = Helpers.playerById(pva.TargetPlayerId);
if (!voteAreaPlayer.AmOwner) continue;
MeetingHud.Instance.ClearVote();
}

if (AmongUsClient.Instance.AmHost)
MeetingHud.Instance.CheckForEndVoting();
GameHistory.overrideDeathReasonAndKiller(otherBomber, DeadPlayer.CustomDeathReason.Suicide);
RPCProcedure.updateMeeting(otherBomber.PlayerId);
}
}

Expand All @@ -3157,22 +3104,8 @@ public static void Postfix(PlayerControl __instance)
{
if (NekoKabocha.nekoKabocha != null && akujoPartner == NekoKabocha.nekoKabocha) NekoKabocha.otherKiller = akujoPartner;
akujoPartner.Exiled();
GameHistory.overrideDeathReasonAndKiller(akujoPartner, DeadPlayer.CustomDeathReason.LoverSuicide);
}

if (MeetingHud.Instance && akujoPartner != null)
{
foreach (PlayerVoteArea pva in MeetingHud.Instance.playerStates)
{
if (pva.VotedFor != akujoPartner.PlayerId) continue;
pva.UnsetVote();
var voteAreaPlayer = Helpers.playerById(pva.TargetPlayerId);
if (!voteAreaPlayer.AmOwner) continue;
MeetingHud.Instance.ClearVote();
}

if (AmongUsClient.Instance.AmHost)
MeetingHud.Instance.CheckForEndVoting();
GameHistory.overrideDeathReasonAndKiller(akujoPartner, DeadPlayer.CustomDeathReason.LoverSuicide);
RPCProcedure.updateMeeting(akujoPartner.PlayerId);
}
}

Expand Down
42 changes: 22 additions & 20 deletions TheOtherRoles/Patches/RoleAssignmentPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,31 @@ private static void assignModifiers() {
RoleId.Sunglasses,
RoleId.Vip,
RoleId.Invert,
RoleId.Chameleon,
RoleId.Madmate
RoleId.Chameleon
//RoleId.Shifter
});


if (rnd.Next(1, 101) <= CustomOptionHolder.madmateSpawnRate.getSelection() * 10)
{
var crewPlayerMadmate = new List<PlayerControl>(players);
crewPlayerMadmate.RemoveAll(x => x.Data.Role.IsImpostor || Helpers.isNeutral(x) || x == Spy.spy || x == FortuneTeller.fortuneTeller || x == Sprinter.sprinter || x == Veteran.veteran
|| x == Deputy.deputy || x == Portalmaker.portalmaker || x == TaskMaster.taskMaster || x == Sherlock.sherlock || x == Snitch.snitch || x == Teleporter.teleporter || x == Prophet.prophet);

// Always remember to remove the Mad Sheriff if Deputy is assigned
if (Deputy.deputy != null && Sheriff.sheriff != null) crewPlayerMadmate.RemoveAll(x => x == Sheriff.sheriff);

int madmateCount = 0;
byte playerId;
while (madmateCount < CustomOptionHolder.madmateQuantity.getQuantity() && crewPlayerMadmate.Count > 0)
{
playerId = setModifierToRandomPlayer((byte)RoleId.Madmate, crewPlayerMadmate);
crewPlayerMadmate.RemoveAll(x => x.PlayerId == playerId);
madmateCount++;
modifierCount--;
}
}

if (rnd.Next(1, 101) <= CustomOptionHolder.modifierLover.getSelection() * 10) { // Assign lover
bool isEvilLover = rnd.Next(1, 101) <= CustomOptionHolder.modifierLoverImpLoverRate.getSelection() * 10;
byte firstLoverId;
Expand Down Expand Up @@ -722,24 +742,6 @@ private static void assignModifiersToPlayers(List<RoleId> modifiers, List<Player
playerList.RemoveAll(x => x.PlayerId == playerId);
modifiers.RemoveAll(x => x == RoleId.Shifter);
}*/
if (modifiers.Contains(RoleId.Madmate))
{
var crewPlayerMadmate = new List<PlayerControl>(crewPlayer);
crewPlayerMadmate.RemoveAll(x => x == Spy.spy || x == FortuneTeller.fortuneTeller || x == Sprinter.sprinter || x == Veteran.veteran
|| x == Deputy.deputy || x == Portalmaker.portalmaker || x == TaskMaster.taskMaster || x == Sherlock.sherlock || x == Snitch.snitch || x == Teleporter.teleporter || x == Prophet.prophet);

// Always remember to remove the Mad Sheriff if Deputy is assigned
if (Deputy.deputy != null && Sheriff.sheriff != null) crewPlayerMadmate.RemoveAll(x => x == Sheriff.sheriff);

int madmateCount = 0;
while (madmateCount < modifiers.FindAll(x => x == RoleId.Madmate).Count)
{
playerId = setModifierToRandomPlayer((byte)RoleId.Madmate, crewPlayerMadmate);
crewPlayerMadmate.RemoveAll(x => x.PlayerId == playerId);
madmateCount++;
}
modifiers.RemoveAll(x => x == RoleId.Madmate);
}
if (modifiers.Contains(RoleId.Sunglasses)) {
int sunglassesCount = 0;
while (sunglassesCount < modifiers.FindAll(x => x == RoleId.Sunglasses).Count) {
Expand Down
6 changes: 2 additions & 4 deletions TheOtherRoles/Players/CachedPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CachedPlayer
public PlayerControl PlayerControl;
public PlayerPhysics PlayerPhysics;
public CustomNetworkTransform NetTransform;
public NetworkedPlayerInfo Data;
public NetworkedPlayerInfo Data => PlayerControl.Data;
public byte PlayerId;

public static implicit operator bool(CachedPlayer player)
Expand Down Expand Up @@ -105,7 +105,6 @@ public static void AddCachedDataOnDeserialize()
{
foreach (CachedPlayer cachedPlayer in CachedPlayer.AllPlayers)
{
cachedPlayer.Data = cachedPlayer.PlayerControl.Data;
cachedPlayer.PlayerId = cachedPlayer.PlayerControl.PlayerId;
}
}
Expand All @@ -116,7 +115,6 @@ public static void AddCachedDataOnAddPlayer()
{
foreach (CachedPlayer cachedPlayer in CachedPlayer.AllPlayers)
{
cachedPlayer.Data = cachedPlayer.PlayerControl.Data;
cachedPlayer.PlayerId = cachedPlayer.PlayerControl.PlayerId;
}
}
Expand All @@ -127,4 +125,4 @@ public static void SetCachedPlayerId(PlayerControl __instance)
{
CachedPlayer.PlayerPtrs[__instance.Pointer].PlayerId = __instance.PlayerId;
}
}
}
2 changes: 1 addition & 1 deletion TheOtherRoles/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,7 @@ public static void cupidSuicide(byte cupidId, bool isScapegoat)
cupid.MurderPlayer(cupid, MurderResultFlags.Succeeded);
GameHistory.overrideDeathReasonAndKiller(cupid, isScapegoat ? DeadPlayer.CustomDeathReason.Scapegoat : DeadPlayer.CustomDeathReason.Suicide);
if (MeetingHud.Instance) updateMeeting(cupidId);
if (CachedPlayer.LocalPlayer.PlayerControl == cupid) _ = new StaticAchievementToken("cupid.another1");
if (CachedPlayer.LocalPlayer.PlayerControl == cupid && isScapegoat) _ = new StaticAchievementToken("cupid.another1");
}
}

Expand Down
Loading

0 comments on commit cefc82d

Please sign in to comment.