Exemple #1
0
        private LynchVoteResult UnsafeVoteToLynch(string voterName, string targetName, uint votesToLynch)
        {
            LynchVoteResult  voteResult      = LynchVoteResult.VotedLynch;
            HashSet <string> currPlayerVotes = this.UnsafeGetPlayerVotes(voterName);
            int  currVoteCount = this.UnsafeGetNumVotesAgainst(targetName);
            bool wasContained  = currPlayerVotes.Contains(targetName);

            if (!wasContained)
            {
                currPlayerVotes.Add(targetName);
                currVoteCount += 1;
            }
            bool enoughVotes = currVoteCount >= votesToLynch;

            if (enoughVotes && LynchState.Vulnerable == this.UnsafeGetLynchState(targetName))
            {
                this.UnsafeSetLynchState(targetName, LynchState.Lynchable);
                voteResult = LynchVoteResult.StartedLynch;
            }
            this.playerLynchVotes[voterName] = currPlayerVotes;
            this.votesCounter[targetName]    = currVoteCount;
            return(voteResult);
        }
Exemple #2
0
        // Function for command: /lynch vote targetName
        public void VoteLynch(CommandArgs args)
        {
            if (!this.config.pluginEnabled)
            {
                return;
            }

            if (!args.Player.IsLoggedIn)
            {
                args.Player.SendErrorMessage("You need to be logged in to do that!");
                return;
            }

            if (!TShockExtensions.TShockExtensions.ArgCountCheck(args, 1, "/lynch vote targetName"))
            {
                return;
            }

            TSPlayer victimCandidate;

            try {
                victimCandidate = TShockExtensions.TShockExtensions.GetPlayerByName(args.Parameters[0]);
            }
            catch (ArgumentException ae) {
                args.Player.SendErrorMessage(ae.Message);
                return;
            }

            if ((int)PlayerDifficulty.Hardcore == victimCandidate.Difficulty && !this.config.allowHardcoreLynching)
            {
                args.Player.SendErrorMessage("You cannot vote to lynch a hardcore player!");
                return;
            }
            if ((int)PlayerDifficulty.Mediumcore == victimCandidate.Difficulty && !this.config.allowMediumcoreLynching)
            {
                args.Player.SendErrorMessage("You cannot vote to lynch a mediumcore player!");
                return;
            }
            if ((int)PlayerDifficulty.Softcore == victimCandidate.Difficulty && !this.config.allowSoftcoreLynching)
            {
                args.Player.SendErrorMessage("You cannot vote to lynch a softcore player!");
                return;
            }

            string          voterName              = args.Player.Name;
            string          targetName             = victimCandidate.Name;
            int             currPlayerCount        = TShock.Utils.GetActivePlayerCount();
            int             ratioScaledPlayerCount = (int)Math.Ceiling(this.config.lynchingPlayersRatio * currPlayerCount);
            uint            votesNeeded            = Math.Max(this.config.minPlayersForLynch, (uint)ratioScaledPlayerCount);
            LynchVoteResult voteResult             = this.lynchState.ToggleLynchVote(voterName, targetName, votesNeeded);

            if (LynchVoteResult.VotedProtect == voteResult)
            {
                args.Player.SendSuccessMessage("Your vote for {0} to be lynched was removed.", targetName);
            }
            else
            {
                args.Player.SendSuccessMessage("You voted for {0} to be lynched.", targetName);
                if (LynchVoteResult.StartedLynch == voteResult)
                {
                    Thread lynchManagementThread = new Thread(() => this.LynchManagementThreadAction(targetName));
                    lynchManagementThread.Start();
                    TShockExtensions.TShockExtensions.EnablePvP(victimCandidate);
                    TShockExtensions.TShockExtensions.ForceNoTeam(victimCandidate);
                }
            }
        }
Exemple #3
0
        // ------------------------------
        // Plugin commands
        // ------------------------------

        // Function for command: /lynch force targetName
        public void ForceLynch(CommandArgs args)
        {
            if (!this.config.pluginEnabled)
            {
                return;
            }

            if (!args.Player.IsLoggedIn)
            {
                args.Player.SendErrorMessage("You need to be logged in to do that!");
                return;
            }

            if (!TShockExtensions.TShockExtensions.ArgCountCheck(args, 1, "/lynch force targetName"))
            {
                return;
            }

            TSPlayer victimCandidate;

            try {
                victimCandidate = TShockExtensions.TShockExtensions.GetPlayerByName(args.Parameters[0]);
            }
            catch (ArgumentException ae) {
                args.Player.SendErrorMessage(ae.Message);
                return;
            }

            string          targetName       = victimCandidate.Name;
            LynchVoteResult forceLynchResult = this.config.ToggleLynchForce(targetName);

            // We just modified the config, so save it to the disk
            Config.SaveConfigData(this.config);
            if (LynchVoteResult.StartedLynch == forceLynchResult)
            {
                TSPlayer.All.SendMessage(
                    String.Format("{0}", this.config.lynchPlayerMessage.Replace("{PLAYER_NAME}", targetName)),
                    this.config.lynchPlayerMessageRed, this.config.lynchPlayerMessageGreen, this.config.lynchPlayerMessageBlue
                    );
                if ((int)PlayerDifficulty.Mediumcore == victimCandidate.Difficulty)
                {
                    //Info Message is yellow
                    args.Player.SendInfoMessage(String.Format("Warning! {0} is a mediumcore player"), victimCandidate.Name);
                }
                if ((int)PlayerDifficulty.Hardcore == victimCandidate.Difficulty)
                {
                    args.Player.SendInfoMessage(String.Format("Warning! {0} is a hardcore player"), victimCandidate.Name);
                }
                TShockExtensions.TShockExtensions.EnablePvP(victimCandidate);
                TShockExtensions.TShockExtensions.ForceNoTeam(victimCandidate);
            }
            else if (LynchVoteResult.VotedProtect == forceLynchResult)
            {
                TSPlayer.All.SendMessage(
                    String.Format("{0}", this.config.unlynchPlayerMessage.Replace("{PLAYER_NAME}", targetName)),
                    this.config.unlynchPlayerMessageRed, this.config.unlynchPlayerMessageGreen, this.config.unlynchPlayerMessageBlue
                    );
                if (!this.lynchState.IsVotedLynchTarget(targetName))
                {
                    TShockExtensions.TShockExtensions.DisablePvP(victimCandidate);
                }
            }
        }