|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using MiraAPI.GameOptions; |
| 5 | +using NewMod.Components.ScreenEffects; |
| 6 | +using NewMod.Options.Roles.ShadeOptions; |
| 7 | +using NewMod.Roles.NeutralRoles; |
| 8 | +using NewMod.Utilities; |
| 9 | +using Reactor.Networking.Attributes; |
| 10 | +using Reactor.Utilities; |
| 11 | +using Reactor.Utilities.Attributes; |
| 12 | +using UnityEngine; |
| 13 | + |
| 14 | +namespace NewMod.Components |
| 15 | +{ |
| 16 | + [RegisterInIl2Cpp] |
| 17 | + public class ShadowZone(IntPtr ptr) : MonoBehaviour(ptr) |
| 18 | + { |
| 19 | + public byte shadeId; |
| 20 | + public float radius; |
| 21 | + public float duration; |
| 22 | + private float timer; |
| 23 | + private bool active; |
| 24 | + public static readonly List<ShadowZone> zones = new(); |
| 25 | + |
| 26 | + public void Awake() |
| 27 | + { |
| 28 | + if (!zones.Contains(this)) |
| 29 | + zones.Add(this); |
| 30 | + } |
| 31 | + |
| 32 | + public void OnDestroy() |
| 33 | + { |
| 34 | + zones.Remove(this); |
| 35 | + } |
| 36 | + |
| 37 | + private bool Contains(Vector2 pos) |
| 38 | + { |
| 39 | + return Vector2.Distance(pos, (Vector2)transform.position) <= radius; |
| 40 | + } |
| 41 | + |
| 42 | + public void Update() |
| 43 | + { |
| 44 | + timer += Time.deltaTime; |
| 45 | + if (timer >= duration) |
| 46 | + { |
| 47 | + Coroutines.Start(CoroutinesHelper.RemoveCameraEffect(Camera.main, 0f)); |
| 48 | + active = false; |
| 49 | + Destroy(gameObject); |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + var lp = PlayerControl.LocalPlayer; |
| 54 | + var hud = HudManager.Instance; |
| 55 | + var killButton = hud.KillButton; |
| 56 | + |
| 57 | + bool inside = Contains(lp.GetTruePosition()); |
| 58 | + var mode = OptionGroupSingleton<ShadeOptions>.Instance.Behavior; |
| 59 | + var cam = Camera.main; |
| 60 | + |
| 61 | + if (inside && !active) |
| 62 | + { |
| 63 | + cam.gameObject.AddComponent<ShadowFluxEffect>(); |
| 64 | + if (lp.PlayerId == shadeId && lp.Data.Role is Shade) |
| 65 | + { |
| 66 | + if (mode is ShadeOptions.ShadowMode.Invisible or ShadeOptions.ShadowMode.Both) |
| 67 | + { |
| 68 | + lp.cosmetics.SetPhantomRoleAlpha(0); |
| 69 | + lp.cosmetics.nameText.gameObject.SetActive(false); |
| 70 | + } |
| 71 | + |
| 72 | + killButton.gameObject.SetActive(true); |
| 73 | + killButton.currentTarget = null; |
| 74 | + } |
| 75 | + active = true; |
| 76 | + } |
| 77 | + |
| 78 | + if (inside && active && lp.PlayerId == shadeId && lp.Data.Role is Shade) |
| 79 | + { |
| 80 | + if (mode is ShadeOptions.ShadowMode.KillEnabled or ShadeOptions.ShadowMode.Both) |
| 81 | + { |
| 82 | + var list = new Il2CppSystem.Collections.Generic.List<PlayerControl>(); |
| 83 | + lp.Data.Role.GetPlayersInAbilityRangeSorted(list); |
| 84 | + var players = list.ToArray().Where(p => p.PlayerId != lp.PlayerId && !p.Data.IsDead).ToList(); |
| 85 | + var closest = players.Count > 0 ? players[0] : null; |
| 86 | + |
| 87 | + if (killButton.currentTarget && killButton.currentTarget != closest) |
| 88 | + killButton.currentTarget.ToggleHighlight(false, RoleTeamTypes.Impostor); |
| 89 | + |
| 90 | + killButton.currentTarget = closest; |
| 91 | + if (closest != null) |
| 92 | + closest.ToggleHighlight(true, RoleTeamTypes.Impostor); |
| 93 | + } |
| 94 | + } |
| 95 | + else if (!inside && active) |
| 96 | + { |
| 97 | + Coroutines.Start(CoroutinesHelper.RemoveCameraEffect(cam, 0f)); |
| 98 | + if (lp.PlayerId == shadeId) |
| 99 | + { |
| 100 | + lp.cosmetics.SetPhantomRoleAlpha(1); |
| 101 | + lp.cosmetics.nameText.gameObject.SetActive(true); |
| 102 | + |
| 103 | + if (killButton.currentTarget) |
| 104 | + { |
| 105 | + killButton.currentTarget.ToggleHighlight(false, RoleTeamTypes.Impostor); |
| 106 | + killButton.currentTarget = null; |
| 107 | + } |
| 108 | + killButton.gameObject.SetActive(false); |
| 109 | + } |
| 110 | + active = false; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + public static ShadowZone Create(byte id, Vector2 pos, float r, float dur) |
| 115 | + { |
| 116 | + var go = new GameObject("ShadowZone"); |
| 117 | + var z = go.AddComponent<ShadowZone>(); |
| 118 | + z.shadeId = id; |
| 119 | + z.radius = r; |
| 120 | + z.duration = dur; |
| 121 | + go.transform.position = pos; |
| 122 | + return z; |
| 123 | + } |
| 124 | + |
| 125 | + [MethodRpc((uint)CustomRPC.DeployZone)] |
| 126 | + public static void RpcDeployZone(PlayerControl source, Vector2 pos, float radius, float duration) |
| 127 | + { |
| 128 | + Create(source.PlayerId, pos, radius, duration); |
| 129 | + } |
| 130 | + |
| 131 | + public static bool IsInsideAny(Vector2 pos) |
| 132 | + { |
| 133 | + return zones.Any(z => z && z.Contains(pos)); |
| 134 | + } |
| 135 | + } |
| 136 | +} |
0 commit comments