Example #1
0
        public void AttemptRevive(SendingConsoleCommandEventArgs ev, SubClass subClass, bool necro = false)
        {
            Log.Debug($"Player {ev.Player.Nickname} {(necro ? "necromancy" : "revive")} attempt", Subclass.Instance.Config.Debug);
            AbilityType ability = necro ? AbilityType.Necromancy : AbilityType.Revive;

            if (Tracking.OnCooldown(ev.Player, ability, subClass))
            {
                Log.Debug($"Player {ev.Player.Nickname} {(necro ? "necromancy" : "revive")} on cooldown", Subclass.Instance.Config.Debug);
                Tracking.DisplayCooldown(ev.Player, necro ? AbilityType.Necromancy : AbilityType.Revive, subClass, necro ? "necromancy" : "revive", Time.time);
                return;
            }

            List <Collider> colliders = Physics.OverlapSphere(ev.Player.Position, 3f).Where(e => e.gameObject.GetComponentInParent <Ragdoll>() != null).ToList();

            colliders.Sort((Collider x, Collider y) =>
            {
                return(Vector3.Distance(x.gameObject.transform.position, ev.Player.Position).CompareTo(Vector3.Distance(y.gameObject.transform.position, ev.Player.Position)));
            });

            if (colliders.Count == 0)
            {
                ev.ReturnMessage = "You must be near a dead body to use this command";
                ev.Player.Broadcast(2, "You must be near a dead body.");
                Log.Debug($"Player {ev.Player.Nickname} {(necro ? "necromancy" : "revive")} overlap did not hit a ragdoll", Subclass.Instance.Config.Debug);
                return;
            }

            Ragdoll doll = colliders[0].gameObject.GetComponentInParent <Ragdoll>();

            if (doll.owner == null)
            {
                Log.Debug($"Player {ev.Player.Nickname} {(necro ? "necromancy" : "revive")} failed", Subclass.Instance.Config.Debug);
                ev.ReturnMessage = "This player is not revivable.";
                ev.Player.Broadcast(2, "This player is not revivable.");
                return;
            }

            EPlayer owner = EPlayer.Get(colliders[0].gameObject.GetComponentInParent <Ragdoll>().owner.PlayerId);

            if (owner != null && !owner.IsAlive)
            {
                if (!necro && Tracking.GetPreviousTeam(owner) != null &&
                    Tracking.GetPreviousTeam(owner) == ev.Player.Team)
                {
                    owner.Role = (RoleType)Tracking.GetPreviousRole(owner);
                }
                else if (necro)
                {
                    owner.Role = RoleType.Scp0492;
                    Tracking.AddZombie(ev.Player, owner);
                    owner.IsFriendlyFireEnabled = true;
                }
                if (owner.Role != RoleType.Spectator)
                {
                    Timing.CallDelayed(0.2f, () =>
                    {
                        owner.Position = colliders[0].gameObject.transform.position + new Vector3(0, 1f, 0);
                    });
                    UnityEngine.Object.DestroyImmediate(doll.gameObject, true);
                    Tracking.AddCooldown(ev.Player, ability);
                    Log.Debug($"Player {ev.Player.Nickname} {(necro ? "necromancy" : "revive")} succeeded", Subclass.Instance.Config.Debug);
                }
                else
                {
                    Log.Debug($"Player {ev.Player.Nickname} {(necro ? "necromancy" : "revive")} failed", Subclass.Instance.Config.Debug);
                    ev.ReturnMessage = "This player is not revivable.";
                    ev.Player.Broadcast(2, "This player is not revivable.");
                }
            }
            else
            {
                Log.Debug($"Player {ev.Player.Nickname} {(necro ? "necromancy" : "revive")} failed", Subclass.Instance.Config.Debug);
                ev.ReturnMessage = "This player is not revivable.";
                ev.Player.Broadcast(2, "This player is not revivable.");
            }
        }