This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9024eed
commit 27b3bc4
Showing
156 changed files
with
2,375 additions
and
948 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using TownOfUs.Roles; | ||
using UnityEngine; | ||
using Object = UnityEngine.Object; | ||
|
||
|
||
namespace TownOfUs.AltruistMod | ||
{ | ||
public class Coroutine | ||
{ | ||
public static ArrowBehaviour Arrow; | ||
public static PlayerControl Target; | ||
public static Sprite Sprite => TownOfUs.Arrow; | ||
|
||
public static IEnumerator AltruistRevive(DeadBody target, Altruist role) | ||
{ | ||
var parentId = target.ParentId; | ||
var position = target.TruePosition; | ||
|
||
var revived = new List<PlayerControl>(); | ||
|
||
|
||
Utils.MurderPlayer(role.Player, role.Player); | ||
|
||
if (CustomGameOptions.AltruistTargetBody) | ||
{ | ||
if(target != null) Object.Destroy(target.gameObject); | ||
} | ||
|
||
var startTime = DateTime.UtcNow; | ||
while (true) | ||
{ | ||
var now = DateTime.UtcNow; | ||
var seconds = (now - startTime).TotalSeconds; | ||
if (seconds < CustomGameOptions.ReviveDuration) | ||
{ | ||
yield return null; | ||
} | ||
else break; | ||
|
||
if (MeetingHud.Instance) yield break; | ||
|
||
} | ||
|
||
var altruistBody = Object.FindObjectsOfType<DeadBody>().FirstOrDefault(b => b.ParentId == role.Player.PlayerId); | ||
if (altruistBody != null) | ||
{ | ||
Object.Destroy(altruistBody.gameObject); | ||
} | ||
|
||
var player = Utils.PlayerById(parentId); | ||
|
||
|
||
player.Revive(); | ||
MedicMod.Murder.KilledPlayers.Remove( | ||
MedicMod.Murder.KilledPlayers.FirstOrDefault(x => x.PlayerId == player.PlayerId)); | ||
revived.Add(player); | ||
player.NetTransform.SnapTo(position); | ||
|
||
if (target != null) | ||
{ | ||
|
||
Object.Destroy(target.gameObject); | ||
} | ||
|
||
if (player.isLover()) | ||
{ | ||
var lover = Roles.Role.GetRole<Lover>(player).OtherLover.Player; | ||
|
||
lover.Revive(); | ||
MedicMod.Murder.KilledPlayers.Remove( | ||
MedicMod.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) | ||
{ | ||
lover.NetTransform.SnapTo(loverBody.TruePosition); | ||
Object.Destroy(loverBody.gameObject); | ||
} | ||
|
||
} | ||
|
||
if (revived.Any(x => x.AmOwner)) | ||
{ | ||
try | ||
{ | ||
Minigame.Instance.Close(); | ||
Minigame.Instance.Close(); | ||
} | ||
catch | ||
{ | ||
} | ||
} | ||
|
||
|
||
if (PlayerControl.LocalPlayer.Data.IsImpostor) | ||
{ | ||
var gameObj = new GameObject(); | ||
Arrow = gameObj.AddComponent<ArrowBehaviour>(); | ||
gameObj.transform.parent = PlayerControl.LocalPlayer.gameObject.transform; | ||
var renderer = gameObj.AddComponent<SpriteRenderer>(); | ||
renderer.sprite = Sprite; | ||
Arrow.image = renderer; | ||
gameObj.layer = 5; | ||
Target = player; | ||
yield return Utils.FlashCoroutine(role.Color, 1f, 0.5f); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using HarmonyLib; | ||
using UnityEngine; | ||
|
||
namespace TownOfUs.AltruistMod | ||
{ | ||
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))] | ||
public class HudManagerUpdate | ||
{ | ||
public static void Postfix(HudManager __instance) | ||
{ | ||
if (PlayerControl.AllPlayerControls.Count <= 1) return; | ||
if (PlayerControl.LocalPlayer == null) return; | ||
if (PlayerControl.LocalPlayer.Data == null) return; | ||
if (!PlayerControl.LocalPlayer.Is(RoleEnum.Altruist)) return; | ||
|
||
var role = Roles.Role.GetRole<Roles.Altruist>(PlayerControl.LocalPlayer); | ||
|
||
var data = PlayerControl.LocalPlayer.Data; | ||
var isDead = data.IsDead; | ||
var truePosition = PlayerControl.LocalPlayer.GetTruePosition(); | ||
var maxDistance = GameOptionsData.KillDistances[PlayerControl.GameOptions.KillDistance]; | ||
var flag = (PlayerControl.GameOptions.GhostsDoTasks || !data.IsDead) && | ||
(!AmongUsClient.Instance || !AmongUsClient.Instance.IsGameOver) && PlayerControl.LocalPlayer.CanMove; | ||
var allocs = Physics2D.OverlapCircleAll(truePosition, maxDistance, | ||
LayerMask.GetMask(new [] {"Players", "Ghost"})); | ||
var killButton = __instance.KillButton; | ||
DeadBody closestBody = null; | ||
var closestDistance = float.MaxValue; | ||
|
||
foreach (var collider2D in allocs) | ||
{ | ||
if (!flag || isDead || collider2D.tag != "DeadBody") continue; | ||
var component = collider2D.GetComponent<DeadBody>(); | ||
|
||
|
||
if (!(Vector2.Distance(truePosition, component.TruePosition) <= | ||
maxDistance)) continue; | ||
|
||
var distance = Vector2.Distance(truePosition, component.TruePosition); | ||
if (!(distance < closestDistance)) continue; | ||
closestBody = component; | ||
closestDistance = distance; | ||
|
||
} | ||
|
||
if (isDead) | ||
{ | ||
killButton.gameObject.SetActive(false); | ||
killButton.isActive = false; | ||
} | ||
else | ||
{ | ||
killButton.gameObject.SetActive(!MeetingHud.Instance); | ||
killButton.isActive = !MeetingHud.Instance; | ||
} | ||
|
||
KillButtonTarget.SetTarget(killButton, closestBody, role); | ||
__instance.KillButton.SetCoolDown(0f, 1f); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using HarmonyLib; | ||
using UnityEngine; | ||
|
||
namespace TownOfUs.AltruistMod | ||
{ | ||
[HarmonyPatch(typeof(KillButtonManager), nameof(KillButtonManager.SetTarget))] | ||
public class KillButtonTarget | ||
{ | ||
|
||
public static byte DontRevive = byte.MaxValue; | ||
public static bool Prefix(KillButtonManager __instance) | ||
{ | ||
return !PlayerControl.LocalPlayer.Is(RoleEnum.Altruist); | ||
} | ||
|
||
public static void SetTarget(KillButtonManager __instance, DeadBody target, Roles.Altruist role) | ||
{ | ||
if (role.CurrentTarget && role.CurrentTarget != target) | ||
{ | ||
role.CurrentTarget.GetComponent<SpriteRenderer>().material.SetFloat("_Outline", 0f); | ||
} | ||
|
||
|
||
if (target != null && target.ParentId == DontRevive) target = null; | ||
role.CurrentTarget = target; | ||
if (role.CurrentTarget && __instance.enabled) | ||
{ | ||
var component = role.CurrentTarget.GetComponent<SpriteRenderer>(); | ||
component.material.SetFloat("_Outline", 1f); | ||
component.material.SetColor("_OutlineColor", Color.red); | ||
__instance.renderer.color = Palette.EnabledColor; | ||
__instance.renderer.material.SetFloat("_Desat", 0f); | ||
return; | ||
} | ||
|
||
__instance.renderer.color = Palette.DisabledClear; | ||
__instance.renderer.material.SetFloat("_Desat", 1f); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using HarmonyLib; | ||
using Hazel; | ||
using Reactor; | ||
using TownOfUs.Roles; | ||
using UnityEngine; | ||
|
||
namespace TownOfUs.AltruistMod | ||
{ | ||
[HarmonyPatch(typeof(KillButtonManager), nameof(KillButtonManager.PerformKill))] | ||
public class PerformKillButton | ||
{ | ||
public static bool Prefix(KillButtonManager __instance) | ||
{ | ||
if (__instance != DestroyableSingleton<HudManager>.Instance.KillButton) return true; | ||
var flag = PlayerControl.LocalPlayer.Is(RoleEnum.Altruist); | ||
if (!flag) return true; | ||
if (!PlayerControl.LocalPlayer.CanMove) return false; | ||
if (PlayerControl.LocalPlayer.Data.IsDead) return false; | ||
var role = Roles.Role.GetRole<Altruist>(PlayerControl.LocalPlayer); | ||
|
||
var flag2 = __instance.isCoolingDown; | ||
if (flag2) return false; | ||
if (!__instance.enabled) return false; | ||
var maxDistance = GameOptionsData.KillDistances[PlayerControl.GameOptions.KillDistance]; | ||
if (Vector2.Distance(role.CurrentTarget.TruePosition, | ||
PlayerControl.LocalPlayer.GetTruePosition()) > maxDistance) return false; | ||
var playerId = role.CurrentTarget.ParentId; | ||
|
||
var writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, | ||
(byte) CustomRPC.AltruistRevive, SendOption.Reliable, -1); | ||
writer.Write(PlayerControl.LocalPlayer.PlayerId); | ||
writer.Write(playerId); | ||
AmongUsClient.Instance.FinishRpcImmediately(writer); | ||
|
||
Coroutines.Start(Coroutine.AltruistRevive(role.CurrentTarget, role)); | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using HarmonyLib; | ||
using Reactor.Extensions; | ||
|
||
namespace TownOfUs.AltruistMod | ||
{ | ||
[HarmonyPatch(typeof(PlayerControl), nameof(PlayerControl.FixedUpdate))] | ||
public class UpdateArrows | ||
{ | ||
public static void Postfix(PlayerControl __instance) | ||
{ | ||
if (Coroutine.Arrow != null) | ||
{ | ||
if (LobbyBehaviour.Instance || MeetingHud.Instance || PlayerControl.LocalPlayer.Data.IsDead || | ||
Coroutine.Target.Data.IsDead) | ||
{ | ||
Coroutine.Arrow.gameObject.Destroy(); | ||
Coroutine.Target = null; | ||
return; | ||
} | ||
|
||
Coroutine.Arrow.target = Coroutine.Target.transform.position; | ||
|
||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.