Example #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();
        }
Example #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);
        }
Example #3
0
        public static void StartGame(CommandArgs args)
        {
            TSPlayer tSPlayer = args.Player;

            HubEvent hubEvent = HubEvent.GetEventPlayerIn(tSPlayer.Name);

            if (hubEvent == null)
            {
                tSPlayer.SendErrorMessage("You are not in an event!");
                return;
            }

            tSPlayer.SendSuccessMessage("You successfully started a vote to start the event!");

            VotingSystem votingSystem = new VotingSystem("Should the game start?",
                                                         60000,
                                                         hubEvent,
                                                         new OptionInfo("Yes", hubEvent.StartEventCountdown),
                                                         new OptionInfo("No"));

            votingSystem.Start();
        }
Example #4
0
        public static void OnGameUpdate(EventArgs _)
        {
            // Teleport spectating players to their targets.
            foreach (TSPlayer tSPlayer in Util.spectatingPlayersToTargets.Keys)
            {
                TSPlayer target   = Util.spectatingPlayersToTargets[tSPlayer];
                Vector2  position = target.TPlayer.position;
                tSPlayer.TeleportNoDust(position);
            }

            // Check if an event has already started.
            HubEvent startedEvent = HubEvent.GetOngoingEvent();

            if (startedEvent != null)
            {
                startedEvent.GameUpdate();
                return;
            }

            // Check if there is already an ongoing vote.
            if (VotingSystem.ongoingVotes.Count > 0)
            {
                return;
            }

            // Start the event countdown vote if there are enough players.
            foreach (HubEvent hubEvent in HubConfig.config.HubEvents)
            {
                if (hubEvent.tSPlayers.Count >= hubEvent.minPlayersForStart)
                {
                    VotingSystem votingSystem = new VotingSystem("Should the game start?",
                                                                 60000,
                                                                 hubEvent,
                                                                 new OptionInfo("Yes", hubEvent.StartEventCountdown),
                                                                 new OptionInfo("No", hubEvent.DeclineStart));
                    votingSystem.Start();
                }
            }
        }
Example #5
0
        public static void CreateVote(CommandArgs args)
        {
            TSPlayer tSPlayer = args.Player;

            if (args.Parameters.Count < 4)
            {
                tSPlayer.SendErrorMessage("Invalid syntax! Proper syntax: /createvote <Question> <Vote Length in MS> <Option 1> <Option 2> <Optional/More Options...>");
                return;
            }

            string question = args.Parameters[0];

            if (!int.TryParse(args.Parameters[1], out int voteLengthMS))
            {
                tSPlayer.SendErrorMessage("The vote length must be a number!");
                return;
            }

            IEnumerable <string> options = args.Parameters.Skip(2);

            List <OptionInfo> optionInfos = new List <OptionInfo>();

            foreach (string option in options)
            {
                optionInfos.Add(new OptionInfo(option));
            }

            VotingSystem votingSystem = new VotingSystem(question,
                                                         voteLengthMS,
                                                         null,
                                                         optionInfos.ToArray());

            tSPlayer.SendSuccessMessage("The vote was successfully created!");

            votingSystem.Start();
        }