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

fix: show destroyed bodies as dead #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions source/Patches/CrewmateRoles/AltruistMod/Coroutine.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using InnerNet;
using Reactor.Extensions;
using TownOfUs.CrewmateRoles.MedicMod;
using TownOfUs.Extensions;
using TownOfUs.Roles;
using UnityEngine;
using InnerNet;
using Object = UnityEngine.Object;

namespace TownOfUs.CrewmateRoles.AltruistMod
Expand All @@ -25,17 +24,15 @@ public static IEnumerator AltruistRevive(DeadBody target, Altruist role)

var revived = new List<PlayerControl>();


if (AmongUsClient.Instance.AmHost) Utils.RpcMurderPlayer(role.Player, role.Player);

if (CustomGameOptions.AltruistTargetBody)
if (target != null)
{
foreach (DeadBody deadBody in GameObject.FindObjectsOfType<DeadBody>())
{
if (deadBody.ParentId == target.ParentId) deadBody.gameObject.Destroy();
}
}
if (CustomGameOptions.AltruistTargetBody && target != null)
{
target.gameObject?.Destroy();
MeetingIntroPatch.DeadPlayers.Add(
GameData.Instance.GetPlayerById(parentId)
);
}

var startTime = DateTime.UtcNow;
while (true)
Expand All @@ -49,47 +46,54 @@ public static IEnumerator AltruistRevive(DeadBody target, Altruist role)
if (MeetingHud.Instance) yield break;
}

foreach (DeadBody deadBody in GameObject.FindObjectsOfType<DeadBody>())
var altruist = role.Player;
var altruistBody = Object.FindObjectsOfType<DeadBody>()
.FirstOrDefault(b => b.ParentId == altruist.PlayerId);
if (altruistBody != null)
{
if (deadBody.ParentId == role.Player.PlayerId) deadBody.gameObject.Destroy();
altruistBody.gameObject?.Destroy();
MeetingIntroPatch.DeadPlayers.Add(altruist.Data);
}

var player = Utils.PlayerById(parentId);

// if (player == null || AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started)
// yield break;
if (player == null || AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started)
yield break;

player.Revive();
Murder.KilledPlayers.Remove(
Murder.KilledPlayers.FirstOrDefault(x => x.PlayerId == player.PlayerId));
revived.Add(player);
player.NetTransform.SnapTo(position);

if (target != null) Object.Destroy(target.gameObject);
if (target != null) target.gameObject?.Destroy();

if (player.isLover() && CustomGameOptions.BothLoversDie)
{
var lover = Role.GetRole<Lover>(player).OtherLover.Player;

lover.Revive();
Murder.KilledPlayers.Remove(
Murder.KilledPlayers.FirstOrDefault(x => x.PlayerId == lover.PlayerId));
revived.Add(lover);

foreach (DeadBody deadBody in GameObject.FindObjectsOfType<DeadBody>())
if (lover?.Data != null && !lover.Data.Disconnected)
{
if (deadBody.ParentId == lover.PlayerId)
lover.Revive();
Murder.KilledPlayers.Remove(
Murder.KilledPlayers.FirstOrDefault(x => x.PlayerId == lover.PlayerId));
revived.Add(lover);

var loverBody = Object.FindObjectsOfType<DeadBody>().FirstOrDefault(b => b.ParentId == lover.PlayerId);

if (loverBody != null)
{
deadBody.gameObject.Destroy();
lover.NetTransform.SnapTo(loverBody.TruePosition);
loverBody.gameObject?.Destroy();
}
}
}

if (revived.Any(x => x.AmOwner))
try
{
Minigame.Instance.Close();
Minigame.Instance.Close();
Minigame.Instance?.Close();
Minigame.Instance?.Close();
}
catch
{
Expand All @@ -110,4 +114,4 @@ public static IEnumerator AltruistRevive(DeadBody target, Altruist role)
}
}
}
}
}
4 changes: 2 additions & 2 deletions source/Patches/CrewmateRoles/SwapperMod/SwapVotes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Linq;
using HarmonyLib;
using Reactor;
Expand Down Expand Up @@ -91,4 +91,4 @@ public static void Postfix(MeetingHud __instance)
}
}
}
}
}
7 changes: 5 additions & 2 deletions source/Patches/ImpostorRoles/JanitorMod/Coroutine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using TownOfUs.Roles;
using UnityEngine;

Expand Down Expand Up @@ -26,6 +26,9 @@ public static IEnumerator CleanCoroutine(DeadBody body, Janitor role)
}

Object.Destroy(body.gameObject);
MeetingIntroPatch.DeadPlayers.Add(
GameData.Instance.GetPlayerById(body.ParentId)
);
}
}
}
}
13 changes: 0 additions & 13 deletions source/Patches/MeetingHud_Start.cs

This file was deleted.

36 changes: 36 additions & 0 deletions source/Patches/MeetingIntroPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using HarmonyLib;
using System.Collections.Generic;
using System.Linq;
using UnhollowerBaseLib;

using PlayerData = GameData.PlayerInfo;

namespace TownOfUs
{
public static class MeetingIntroPatch
{
public static List<PlayerData> DeadPlayers =
new List<PlayerData>();

[HarmonyPatch(typeof(MeetingHud), nameof(MeetingHud.Start))]
public static class MeetingHud_Start
{
public static void Postfix() =>
Utils.ShowDeadBodies = PlayerControl.LocalPlayer.Data.IsDead;
}

[HarmonyPatch(typeof(MeetingIntroAnimation), nameof(MeetingIntroAnimation.Init))]
public static class IntroPatch
{
public static void Prefix(
[HarmonyArgument(1)] ref Il2CppReferenceArray<PlayerData> deadPlayers
)
{
var players = deadPlayers.ToHashSet();
players.UnionWith(DeadPlayers);
deadPlayers = players.ToArray();
DeadPlayers.Clear();
}
}
}
}