Пример #1
0
        private void DeleteProfile(GumpButton button)
        {
            if (Selected == null || Selected.Deleted)
            {
                Selected = Voting.EnsureProfile(User as PlayerMobile);
            }

            if (Selected == null)
            {
                Refresh(true);
                return;
            }

            if (UseConfirmDialog)
            {
                Send(
                    new ConfirmDialogGump(User, Refresh())
                {
                    Title = "Delete Profile?",
                    Html  =
                        "All data associated with this profile will be deleted.\n" +
                        "This action can not be reversed!\nDo you want to continue?",
                    AcceptHandler = ConfirmDeleteProfile
                });
            }
            else
            {
                Selected.Delete();
                Close();
            }
        }
Пример #2
0
        protected override void CompileMenuOptions(MenuGumpOptions list)
        {
            if (Selected == null || Selected.Deleted)
            {
                Selected = Voting.EnsureProfile(User as PlayerMobile, true);
            }

            if (Selected == null)
            {
                base.CompileMenuOptions(list);
                return;
            }

            if (User.AccessLevel >= Voting.Access)
            {
                list.AppendEntry(new ListGumpEntry("Clear History", OnClearHistory, HighlightHue));
                list.AppendEntry(new ListGumpEntry("Delete Profile", OnDeleteProfile, HighlightHue));
            }

            list.AppendEntry(new ListGumpEntry("View History", OnViewHistory, HighlightHue));

            list.AppendEntry(new ListGumpEntry("Help", ShowHelp));

            base.CompileMenuOptions(list);
        }
Пример #3
0
        private void ClearHistory(GumpButton button)
        {
            if (Selected == null || Selected.Deleted)
            {
                Selected = Voting.EnsureProfile(User as PlayerMobile);
            }

            if (Selected == null)
            {
                Refresh(true);
                return;
            }

            if (UseConfirmDialog)
            {
                Send(
                    new ConfirmDialogGump(User, Refresh())
                {
                    Title = "Clear Profile History?",
                    Html  =
                        "All data associated with the profile history will be lost.\n" +
                        "This action can not be reversed!\nDo you want to continue?",
                    AcceptHandler = ConfirmClearHistory
                });
            }
            else
            {
                Selected.ClearHistory();
                Refresh(true);
            }
        }
Пример #4
0
        public virtual bool Vote(PlayerMobile voter, bool message = true)
        {
            if (voter == null || voter.Deleted || !CanVote(voter, message))
            {
                return(false);
            }

            var p = Voting.EnsureProfile(voter);

            if (p == null || p.Deleted)
            {
                if (message)
                {
                    voter.SendMessage("Your vote profile can't be accessed right now.");
                }

                return(false);
            }

            if (message)
            {
                voter.SendMessage("Thanks for voting, {0}! Every vote counts!", voter.RawName);
            }

            var tokens = Tokens;

            if (Voting.CMOptions.GiveBonusTokens && BonusTokens > 0 && Utility.RandomMinMax(0, 100) <= BonusTokensChance)
            {
                tokens += BonusTokens;

                if (message)
                {
                    voter.SendMessage("You've just earned {0} bonus tokens!", BonusTokens);
                }
            }

            var e = new VoteRequestEventArgs(voter, this, tokens, message);

            VitaNexCore.TryCatch(e.Invoke, Voting.CMOptions.ToConsole);

            if (tokens != e.Tokens)
            {
                tokens = Math.Max(0, e.Tokens);
            }

            message = e.Message;

            if (!e.HandledTokens)
            {
                p.TransferTokens(this, tokens, message);
            }
            else
            {
                p.RegisterTokens(this, tokens);
            }

            Timer.DelayCall(Voting.CMOptions.BrowserDelay, () => voter.LaunchBrowser(Link));
            return(true);
        }
Пример #5
0
        private void OnViewHistory(GumpButton button)
        {
            if (Selected == null || Selected.Deleted)
            {
                Selected = Voting.EnsureProfile(User);
            }

            Send(new VoteProfileHistoryGump(User, Selected, Hide(true), UseConfirmDialog, DateTime.UtcNow));
        }
Пример #6
0
        protected override void Compile()
        {
            base.Compile();

            if (Selected == null || Selected.Deleted)
            {
                Selected = Voting.EnsureProfile(User, true);
            }

            Html  = String.Format("<basefont color=#{0:X6}>", HtmlColor.ToArgb());
            Html += Selected.ToHtmlString(User);
        }
Пример #7
0
        protected virtual void OnDeleteProfile(GumpButton button)
        {
            if (Selected == null || Selected.Deleted)
            {
                Selected = Voting.EnsureProfile(User);
            }

            if (UseConfirmDialog)
            {
                Send(
                    new ConfirmDialogGump(User, Refresh())
                {
                    Title = "Delete Profile?",
                    Html  =
                        "All data associated with this profile will be deleted.\nThis action can not be reversed!\nDo you want to continue?",
                    AcceptHandler = ConfirmDeleteProfile
                });
            }
            else
            {
                Selected.Delete();
                Close();
            }
        }
Пример #8
0
        public virtual bool CanVote(PlayerMobile voter, bool message = true)
        {
            if (voter == null || voter.Deleted)
            {
                return(false);
            }

            if (!Valid || !Enabled || Deleted)
            {
                if (message)
                {
                    voter.SendMessage(0x22, "This vote site is currently disabled.");
                }

                return(false);
            }

            var p = Voting.EnsureProfile(voter);

            if (p == null || p.Deleted)
            {
                if (message)
                {
                    voter.SendMessage(0x22, "Your vote profile can't be accessed right now.");
                }

                return(false);
            }

            var now = DateTime.UtcNow;

            if (Interval <= TimeSpan.Zero)
            {
                return(true);
            }

            TimeSpan time;

            var entry = p.GetHistory(now - Interval).FirstOrDefault(e => e.VoteSite == this);

            if (entry != null)
            {
                time = Interval - (now - entry.VoteTime);

                if (time > TimeSpan.Zero)
                {
                    if (message)
                    {
                        voter.SendMessage(0x22, "You can't vote at this site yet. Try again in {0}", time.ToSimpleString("h:m:s"));
                    }

                    return(false);
                }
            }

            if (!Voting.CMOptions.RestrictByIP)
            {
                return(true);
            }

            p = Voting.Profiles.Values.FirstOrDefault(o => o != p && o.Owner.Account.IsSharedWith(p.Owner.Account));

            if (p == null)
            {
                return(true);
            }

            entry = p.GetHistory(now - Interval).FirstOrDefault(e => e.VoteSite == this);

            if (entry == null)
            {
                return(true);
            }

            time = Interval - (now - entry.VoteTime);

            if (time <= TimeSpan.Zero)
            {
                return(true);
            }

            if (message)
            {
                voter.SendMessage(
                    "You have already cast a vote from this IP recently. Try again in {0}",
                    time.ToSimpleString("h:m:s"));
            }

            return(false);
        }
Пример #9
0
 private void OnMyProfile(GumpButton button)
 {
     Send(new VoteProfileGump(User, Voting.EnsureProfile(User as PlayerMobile), Hide(true), UseConfirmDialog));
 }
Пример #10
0
        public virtual bool CanVote(PlayerMobile voter, bool message = true)
        {
            if (voter == null || voter.Deleted)
            {
                return(false);
            }

            if (!Valid || !Enabled || Deleted)
            {
                if (message)
                {
                    voter.SendMessage("This vote site is currently disabled.");
                }

                return(false);
            }

            VoteProfile p = Voting.EnsureProfile(voter);

            if (p == null || p.Deleted)
            {
                if (message)
                {
                    voter.SendMessage("Your vote profile can't be accessed right now.");
                }

                return(false);
            }

            DateTime now   = DateTime.UtcNow;
            var      entry = p.GetHistory(now - Interval).LastOrDefault(e => e.VoteSite == this);

            if (entry != null && now <= (entry.VoteTime + Interval))
            {
                if (message)
                {
                    voter.SendMessage(
                        "You can't vote at this site yet. Try again in {0}", (now - (entry.VoteTime + Interval)).ToSimpleString("h:m:s"));
                }

                return(false);
            }

            if (Voting.CMOptions.RestrictByIP)
            {
                var p2 = Voting.Profiles.Values.FirstOrDefault(o => o != p && o.LoginIPs.Any(oip => p.LoginIPs.Contains(oip)));

                if (p2 != null)
                {
                    var entry2 = p2.GetHistory(now - Interval).LastOrDefault(e => e.VoteSite == this);

                    if (entry2 != null && now <= (entry2.VoteTime + Interval))
                    {
                        if (message)
                        {
                            voter.SendMessage(
                                "You have already cast a vote from this IP recently. Try again in {0}",
                                (now - (entry2.VoteTime + Interval)).ToSimpleString("h:m:s"));
                        }

                        return(false);
                    }
                }
            }

            return(true);
        }