Пример #1
0
        public static void CancelVoting(GamePlayer aGM)
        {
            if (m_Timer != null)
            {
                m_Timer.Dispose();
            }
            m_Timer   = null;
            m_Current = null;
            string msg = aGM.Name + " cancels the voting!";

            foreach (GameClient client in WorldMgr.GetAllPlayingClients())
            {
                client.Player.TempProperties.removeProperty(PLY_TEMP_PROP_KEY);
                client.Out.SendMessage(msg, eChatType.CT_ScreenCenter, eChatLoc.CL_SystemWindow);
                client.Out.SendMessage(msg, eChatType.CT_Staff, eChatLoc.CL_SystemWindow);
                client.Out.SendPlaySound(eSoundType.Craft, 0x02);
            }
            //NewsMgr.CreateNews(msg, (byte)eRealm.None, eNewsType.RvRGlobal, false);
        }
Пример #2
0
        public static void BeginVoting(GamePlayer aGM, DBVoting aVoting)
        {
            m_Current = aVoting;
            m_Dura    = STD_VOTING_DURATION;
            string msg1 = "Voting in progress... type /vote";
            string msg2 = aGM.Name + " starts a new voting for " + m_Dura + "sec ... Use /vote";

            foreach (GameClient client in WorldMgr.GetAllPlayingClients())
            {
                client.Player.TempProperties.removeProperty(PLY_TEMP_PROP_KEY);
                client.Out.SendMessage(msg1, eChatType.CT_ScreenCenter, eChatLoc.CL_SystemWindow);
                client.Out.SendMessage(msg2, eChatType.CT_Staff, eChatLoc.CL_SystemWindow);
                client.Out.SendPlaySound(eSoundType.Craft, 0x04);
            }
            //NewsMgr.CreateNews(aGM.Name+" starts a new voting!", (byte)eRealm.None, eNewsType.RvRGlobal, false);
            if (m_Timer != null)
            {
                m_Timer.Dispose();
            }
            m_Timer = new Timer(new TimerCallback(OnTimer), m_Timer, 1000, 1000);
        }
Пример #3
0
        public static void ShowVoting(GamePlayer player, DBVoting voting)
        {
            if (voting == null || player == null)
            {
                return;
            }
            StringBuilder sb = new StringBuilder();

            if (player.Client.Account.PrivLevel >= (uint)ePrivLevel.GM)
            {
                sb.Append("VoteID: ").Append(voting.VoteID).Append("\n");
            }
            if (voting.Description != string.Empty)
            {
                sb.Append("\n").Append(voting.Description).Append("\n");
            }
            sb.Append("\nOptions:\n");
            int i = 0;

            foreach (string option in voting.Options)
            {
                sb.Append("- ").Append(++i).Append(": ").Append(option).Append("\n");
            }
            if (voting == CurrentVotingInProgress)
            {
                int vote = player.TempProperties.getProperty(PLY_TEMP_PROP_KEY, -1);
                if (vote >= 0 && vote < voting.Options.Length)
                {
                    sb.Append("\nYou vote for: ").Append(voting.Options[vote]).Append("\n");
                }
                else
                {
                    sb.Append("\nYou did not vote yet!\nUse /vote 1 | 2 | ... x to vote for an option.\n");
                }
                sb.Append("\nVoting ends in " + m_Dura + " seconds...");
            }
            player.Out.SendCustomTextWindow("Voting", sb.ToString().Split('\n'));
        }
Пример #4
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;
        }
Пример #5
0
        protected static void EndVoting()
        {
            if (m_Timer != null)
            {
                m_Timer.Dispose();
            }
            m_Timer = null;
            DBVoting voting = m_Current;

            m_Current = null;

            string msg = "Voting ended!";

            ArrayList clients = WorldMgr.GetAllPlayingClients();

            lock (clients)
            {
                // counting the votes for each option
                uint      count = 0;
                ArrayList votes = new ArrayList();
                for (int i = 0; i < voting.Options.Length; i++)
                {
                    votes.Add(new KVP(voting.Options[i], 0));
                }

                foreach (GameClient client in clients)
                {
                    client.Out.SendMessage(msg, eChatType.CT_ScreenCenter, eChatLoc.CL_SystemWindow);
                    client.Out.SendMessage(msg, eChatType.CT_Staff, eChatLoc.CL_SystemWindow);
                    client.Out.SendPlaySound(eSoundType.Craft, 0x04);

                    int vote = client.Player.TempProperties.getProperty(PLY_TEMP_PROP_KEY, -1);
                    client.Player.TempProperties.removeProperty(PLY_TEMP_PROP_KEY);
                    if (vote >= 0 && vote < voting.Options.Length)
                    {
                        ((KVP)votes[vote]).Value++;
                        ++count;
                    }
                }

                // generating result
                StringBuilder msg1 = new StringBuilder(); // for PrivLevel < GM
                StringBuilder msg2 = new StringBuilder(); // for PrivLevel >= GM
                string        tmp  = string.Format(
                    "Altogether {0} of {1} players voted ({2}%).\n",
                    count, clients.Count, PDivide(count, clients.Count));
                msg1.Append(tmp);
                msg2.Append("VoteID: ").Append(voting.VoteID).Append("\n").Append(tmp);
                if (voting.Description != string.Empty)
                {
                    msg2.Append("\n").Append(voting.Description).Append("\n");
                }

                votes.Sort(new SortByKVP());
                votes.Reverse();
                foreach (KVP kvp in votes)
                {
                    tmp = string.Format(
                        "- {0}: {1} ({2}%)\n",
                        kvp.Key, kvp.Value, PDivide(kvp.Value, clients.Count));
                    msg1.Append(tmp);
                    msg2.Append(tmp);
                }
                tmp = string.Format(
                    "{0} players did not vote ({1}%).\n",
                    (clients.Count - count), PDivide(clients.Count - count, clients.Count));
                msg1.Append(tmp);
                msg2.Append(tmp);
                string   str1   = msg1.ToString();
                string   str2   = msg2.ToString();
                string[] array1 = str1.Split('\n');
                string[] array2 = str2.Split('\n');


                foreach (GameClient client in clients)
                {
                    if (client.Account.PrivLevel <= (uint)ePrivLevel.GM)
                    {
                        client.Out.SendCustomTextWindow("Voting", array1);
                        client.Out.SendMessage(str1, eChatType.CT_Staff, eChatLoc.CL_SystemWindow);
                    }
                    else
                    {
                        client.Out.SendCustomTextWindow("Voting", array2);
                        client.Out.SendMessage(str2, eChatType.CT_Staff, eChatLoc.CL_SystemWindow);
                    }
                }
                m_Result = str2;
            }
        }