Beispiel #1
0
        public void OnCommand(GameClient client, string[] args)
        {
            GamePlayer player = client.Player;

            if (!VotingMgr.IsVotingInProgress)
            {
                DisplaySyntax(client);
                player.Out.SendMessage("There is no voting in progress.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }
            if (args.Length > 1)
            {
                try
                {
                    int vote = int.Parse(args[1]) - 1;
                    player.Out.SendMessage("You vote for '" + VotingMgr.CurrentVotingInProgress.Options[vote] + "'.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    player.TempProperties.setProperty(VotingMgr.PLY_TEMP_PROP_KEY, vote);
                }
                catch (Exception)
                {
                    DisplaySyntax(client);
                    player.Out.SendMessage("Choose a valid option!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
            }
            VotingMgr.ShowVoting(player, VotingMgr.CurrentVotingInProgress);
            return;
        }
Beispiel #2
0
        public void OnCommand(GameClient client, string[] args)
        {
            if (args.Length == 1)
            {
                DisplaySyntax(client);
                return;
            }
            GamePlayer player  = client.Player;
            string     command = args[1].ToLower();
            string     param   = (args.Length > 2) ? String.Join(" ", args, 2, args.Length - 2) : string.Empty;

            if (VotingMgr.IsVotingInProgress && command != "cancel")
            {
                player.Out.SendMessage("A voting is in progress. You cannot use any commands except /gmvote cancel!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                return;
            }

            switch (command)
            {
                #region /gmvote create
            case "create":
            {
                player.TempProperties.setProperty(VotingMgr.GM_TEMP_PROP_KEY, new DBVoting());
                player.Out.SendMessage("You created an empty voting. Please customize it.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
            }
            break;

                #endregion
                #region /gmvote add
            case "add":
            {
                DBVoting voting = (DBVoting)player.TempProperties.getProperty <object>(VotingMgr.GM_TEMP_PROP_KEY, null);
                if (voting == null)
                {
                    player.Out.SendMessage("You didnt created an empty voting. Please use /gmvote create before!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                voting.AddOption(param);
                player.Out.SendMessage("You added the choice: '" + param + "'.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
            }
            break;

                #endregion
                #region /gmvote desc
            case "desc":
            {
                DBVoting voting = (DBVoting)player.TempProperties.getProperty <object>(VotingMgr.GM_TEMP_PROP_KEY, null);
                if (voting == null)
                {
                    player.Out.SendMessage("You didnt created an empty voting. Please use /gmvote create before!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                voting.AddDescription(param);
                player.Out.SendMessage("You added to the description: '" + param + "'.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
            }
            break;
                #endregion

                #region /gmvote start
            case "start":
            {
                DBVoting voting;
                if (param != string.Empty)
                {
                    voting = (DBVoting)GameServer.Database.FindObjectByKey(typeof(DBVoting), GameServer.Database.Escape(param));
                }
                else
                {
                    voting = (DBVoting)player.TempProperties.getProperty <object>(VotingMgr.GM_TEMP_PROP_KEY, null);
                }

                if (voting == null)
                {
                    player.Out.SendMessage("You didnt specify any voting. Please create one first or give me a name!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                VotingMgr.BeginVoting(player, voting);
                player.Out.SendMessage("You started the voting: '" + param + "'.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
            }
            break;

                #endregion
                #region /gmvote cancel
            case "cancel":
            {
                if (!VotingMgr.IsVotingInProgress)
                {
                    player.Out.SendMessage("There is no voting in progress. What you want to cancel?!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                VotingMgr.CancelVoting(player);
                player.Out.SendMessage("You canceled the voting!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
            }
            break;

                #endregion
                #region /gmvote last
            case "last":
            {
                string[] text;
                if (VotingMgr.LastVotingResult == string.Empty)
                {
                    text = "Couldnt find last voting result.\nPossible none voting since last server start?".Split('\n');
                }
                else
                {
                    text = VotingMgr.LastVotingResult.Split('\n');
                }
                player.Out.SendCustomTextWindow("voting result", text);
            }
            break;

                #endregion
                #region /gmvote list
            case "list":
            {
                DBVoting[] votings;
                if (param != string.Empty)
                {
                    votings = (DBVoting[])GameServer.Database.SelectObjects(typeof(DBVoting), "VoteID LIKE '%" + GameServer.Database.Escape(param) + "%'");
                }
                else
                {
                    votings = (DBVoting[])GameServer.Database.SelectAllObjects(typeof(DBVoting));
                }

                if (votings == null || votings.Length == 0)
                {
                    player.Out.SendMessage("No saved votings found.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                else
                {
                    player.Out.SendMessage("Found " + votings.Length + " votings.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                }
                foreach (DBVoting voting in votings)
                {
                    player.Out.SendMessage("Voting: '" + voting.VoteID + "'.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                }
            }
            break;

                #endregion
                #region /gmvote info
            case "info":
            {
                DBVoting voting;
                if (param != string.Empty)
                {
                    voting = (DBVoting)GameServer.Database.FindObjectByKey(typeof(DBVoting), GameServer.Database.Escape(param));
                }
                else
                {
                    voting = (DBVoting)player.TempProperties.getProperty <object>(VotingMgr.GM_TEMP_PROP_KEY, null);
                }

                if (voting == null)
                {
                    player.Out.SendMessage("You didnt specify any voting. Please create one first or give me a name!", eChatType.CT_System, eChatLoc.CL_SystemWindow);
                    return;
                }
                VotingMgr.ShowVoting(player, voting);
                player.Out.SendMessage("You looks into the details of the voting: '" + param + "'.", eChatType.CT_System, eChatLoc.CL_SystemWindow);
            }
            break;
                #endregion

            default: DisplaySyntax(client); break;
            }
            return;
        }