示例#1
0
        public static void Vote(CommandArgs args)
        {
            TSPlayer tSPlayer = args.Player;

            bool multipleOngoingVotes = VotingSystem.ongoingVotes.Count() > 1;

            int voteID = 1;

            if (args.Parameters.Count < (multipleOngoingVotes ? 2 : 1) || !int.TryParse(args.Parameters[0], out int optionID))
            {
                tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /vote <Option ID>" + (multipleOngoingVotes ? " <Vote ID>" : ""));
                return;
            }

            if (multipleOngoingVotes && !int.TryParse(args.Parameters[1], out voteID))
            {
                tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /vote <Option ID> <Vote ID>");
                return;
            }

            VotingSystem votingSystem = VotingSystem.GetVotingSystem(voteID - 1);

            if (votingSystem == null)
            {
                tSPlayer.SendErrorMessage("There is no ongoing vote with that vote ID!");
                return;
            }

            if (votingSystem.voters.Contains(tSPlayer))
            {
                tSPlayer.SendErrorMessage("You have already voted!");
                return;
            }

            if (!votingSystem.AddVote(tSPlayer, optionID - 1))
            {
                tSPlayer.SendErrorMessage("There is no option with that ID!");
                return;
            }

            OptionInfo optionInfo = votingSystem.options[optionID - 1];

            tSPlayer.SendSuccessMessage(string.Format("You successfully voted for \"{0}\" in \"{1}\" \"{0}\" now has {2} vote{3}!", optionInfo.option, votingSystem.question, optionInfo.votes, optionInfo.votes == 1 ? "" : "s"));

            if (!votingSystem.HasEveryoneVoted())
            {
                return;
            }

            TShock.Utils.Broadcast("Everyone participating has voted and so the vote will conclude early.", Color.DarkOrange);

            votingSystem.Stop();
        }
示例#2
0
        public static void ForceVote(CommandArgs args)
        {
            TSPlayer tSPlayer = args.Player;

            bool multipleOngoingVotes = VotingSystem.ongoingVotes.Count() > 1;

            int voteID = 1;

            if (args.Parameters.Count < (multipleOngoingVotes ? 2 : 1) || !int.TryParse(args.Parameters[0], out int optionID))
            {
                tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /forcevote <Option ID>" + (multipleOngoingVotes ? " <Vote ID>" : ""));
                return;
            }

            if (multipleOngoingVotes && !int.TryParse(args.Parameters[1], out voteID))
            {
                tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /forcevote <Option ID> <Vote ID>");
                return;
            }

            VotingSystem votingSystem = VotingSystem.GetVotingSystem(voteID - 1);

            if (votingSystem == null)
            {
                tSPlayer.SendErrorMessage("There is no ongoing vote with that vote ID!");
                return;
            }

            if (!votingSystem.AddVote(tSPlayer, optionID - 1))
            {
                tSPlayer.SendErrorMessage("There is no option with that ID!");
                return;
            }

            OptionInfo optionInfo = votingSystem.options[optionID - 1];

            tSPlayer.SendSuccessMessage(string.Format("You successfully forcevoted for \"{0}\" in \"{1}\"!", optionInfo.option, votingSystem.question));

            TShock.Utils.Broadcast(string.Format("{0} forcevoted and so the vote will conclude early.", tSPlayer.Name), Color.DarkOrange);

            votingSystem.ForceStop(optionInfo);
        }