Exemplo n.º 1
0
        public static IEnumerator CleanCoroutine(DeadBody body, Roles.Janitor role)
        {
            KillButtonTarget.SetTarget(DestroyableSingleton <HudManager> .Instance.KillButton, null, role);
            role.Player.SetKillTimer(PlayerControl.GameOptions.KillCooldown);
            var renderer  = body.GetComponent <SpriteRenderer>();
            var backColor = renderer.material.GetColor(BackColor);
            var bodyColor = renderer.material.GetColor(BodyColor);
            var newColor  = new Color(1f, 1f, 1f, 0f);

            for (var i = 0; i < 60; i++)
            {
                if (body == null)
                {
                    yield break;
                }
                renderer.color = Color.Lerp(backColor, newColor, i / 60f);
                renderer.color = Color.Lerp(bodyColor, newColor, i / 60f);
                yield return(null);
            }
            UnityEngine.Object.Destroy(body.gameObject);
        }
Exemplo n.º 2
0
        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.Janitor))
            {
                return;
            }

            var role = Roles.Role.GetRole <Roles.Janitor>(PlayerControl.LocalPlayer);

            if (role.CleanButton == null)
            {
                role.CleanButton = Object.Instantiate(__instance.KillButton, HudManager.Instance.transform);
                role.CleanButton.renderer.enabled = true;
            }
            role.CleanButton.gameObject.SetActive(!PlayerControl.LocalPlayer.Data.IsDead && !MeetingHud.Instance);
            var position = __instance.KillButton.transform.localPosition;

            role.CleanButton.transform.localPosition = new Vector3(position.x,
                                                                   __instance.ReportButton.transform.localPosition.y, position.z);

            role.CleanButton.renderer.sprite = TownOfUs.JanitorClean;


            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      = role.CleanButton;
            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;
            }


            KillButtonTarget.SetTarget(killButton, closestBody, role);
            role.CleanButton.SetCoolDown(PlayerControl.LocalPlayer.killTimer, PlayerControl.GameOptions.KillCooldown);
        }
Exemplo n.º 3
0
        public static void Postfix(PlayerControl __instance)
        {
            if (PlayerControl.AllPlayerControls.Count <= 1)
            {
                return;
            }
            if (PlayerControl.LocalPlayer == null)
            {
                return;
            }
            if (PlayerControl.LocalPlayer.Data == null)
            {
                return;
            }
            if (!__instance.AmOwner)
            {
                return;
            }
            if (!PlayerControl.LocalPlayer.Is(RoleEnum.Janitor))
            {
                return;
            }
            if (CustomGameOptions.JanitorKill && Utils.IsLastImp(PlayerControl.LocalPlayer))
            {
                return;
            }
            var data         = __instance.Data;
            var isDead       = data.IsDead;
            var truePosition = __instance.GetTruePosition();
            var maxDistance  = GameOptionsData.KillDistances[PlayerControl.GameOptions.KillDistance];
            var flag         = (PlayerControl.GameOptions.GhostsDoTasks || !data.IsDead) &&
                               (!AmongUsClient.Instance || !AmongUsClient.Instance.IsGameOver) && __instance.CanMove;
            var allocs = Physics2D.OverlapCircleAll(truePosition, maxDistance,
                                                    Constants.PlayersOnlyMask);
            var      killButton      = DestroyableSingleton <HudManager> .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) || PhysicsHelpers.AnythingBetween(truePosition,
                                                                     component.TruePosition, Constants.ShipAndObjectsMask, false))
                {
                    continue;
                }

                var distance = Vector2.Distance(truePosition, component.TruePosition);
                if (!(distance < closestDistance))
                {
                    continue;
                }
                closestBody     = component;
                closestDistance = distance;
            }

            var role = Roles.Role.GetRole <Roles.Janitor>(PlayerControl.LocalPlayer);

            KillButtonTarget.SetTarget(killButton, closestBody, role);

            if (isDead)
            {
                killButton.gameObject.SetActive(false);
                killButton.isActive = false;
            }
            else
            {
                killButton.gameObject.SetActive(true);
                killButton.isActive = true;
                killButton.SetCoolDown(role.JanitorTimer(), CustomGameOptions.JanitorCleanCd);
            }
        }