public string Execute(bool isEnabled = true, [CurrentCharacterIfNull] ICharacter character = null)
        {
            if (isEnabled)
            {
                CharacterInvincibilitySystem.ServerAdd(character);
            }
            else
            {
                CharacterInvincibilitySystem.ServerRemove(character);
            }

            return($"{character} invincibility mode is {(isEnabled ? "on" : "off")}");
        }
示例#2
0
        public string Execute()
        {
            var player = this.ExecutionContextCurrentCharacter;

            if (player == null)
            {
                return("This command cannot be executed directly from the server console");
            }

            var stats = player.GetPublicState <PlayerCharacterPublicState>()
                        .CurrentStatsExtended;

            if (stats.HealthCurrent <= 0)
            {
                return("You're already dead.");
            }

            // ensure character is not invincible
            CharacterInvincibilitySystem.ServerRemove(player);

            if (!ServerOperatorSystem.SharedIsOperator(player))
            {
                // check cooldown
                var time = Server.Game.FrameTime;
                if (this.characterLastKillTime.TryGetValue(player, out var lastKillTime) &&
                    time < lastKillTime + CooldownSeconds)
                {
                    return(string.Format(
                               "You've already killed yourself recently... please wait for cooldown: {0} remaining.",
                               ClientTimeFormatHelper.FormatTimeDuration(lastKillTime + CooldownSeconds - time)));
                }

                this.characterLastKillTime[player] = time;
            }

            stats.ServerSetHealthCurrent(0);
            return("You've killed yourself.");
        }