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); }
private void OnViewHistory(GumpButton button) { if (Selected == null || Selected.Deleted) { Selected = Voting.EnsureProfile(User); } Send(new VoteProfileHistoryGump(User, Selected, Hide(true), UseConfirmDialog, DateTime.UtcNow)); }
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); }
public void Deserialize(GenericReader reader) { int version = reader.GetVersion(); switch (version) { case 0: { VoteTime = reader.ReadDateTime(); VoteSite = Voting.FindSite(reader.ReadInt()); } break; } }
public override void GetProperties(ObjectPropertyList list) { base.GetProperties(list); var site = Voting.FindSite(SiteUID); if (site != null && !site.Deleted && site.Valid) { list.Add("Use: Cast a vote for {0} at '{1}'".WrapUOHtmlColor(UsageColor), ServerList.ServerName, site.Name); } else { list.Add("[No Vote Site Available]".WrapUOHtmlColor(Color.OrangeRed)); } }
protected override void CompileMenuOptions(MenuGumpOptions list) { if (Selected == null || Selected.Deleted) { Selected = Voting.EnsureProfile(User, true); } 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); }
public override void OnDoubleClick(Mobile from) { var voter = from as PlayerMobile; if (voter == null || voter.Deleted) { return; } var site = Voting.FindSite(SiteUID); if (site != null) { site.Vote(voter); } else if (voter.AccessLevel >= Voting.Access) { SuperGump.Send(new VoteAdminGump(voter)); } }
public override void GetProperties(ObjectPropertyList list) { base.GetProperties(list); IVoteSite site = Voting.FindSite(SiteUID); if (site != null && !site.Deleted) { int color = Color.FromKnownColor(UsageColor).ToArgb(); list.Add( "<basefont color=#{0:X6}>Use: Cast a vote for {1} at {2}<basefont color=#ffffff>", color, ServerList.ServerName, site.Name); } else { list.Add("<basefont color=#{0:X6}>[No Vote Site Available]<basefont color=#ffffff>", Color.Red.ToArgb()); } }
private void DeleteProfile(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(); } }
private void ClearHistory(GumpButton button) { if (Selected == null || Selected.Deleted) { Selected = Voting.EnsureProfile(User); } if (UseConfirmDialog) { Send( new ConfirmDialogGump(User, Refresh()) { Title = "Clear Profile History?", Html = "All data associated with the profile history will be lost.\nThis action can not be reversed!\nDo you want to continue?", AcceptHandler = ConfirmClearHistory }); } else { Selected.ClearHistory(); Refresh(true); } }
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); }
private void OnMyProfile(GumpButton button) { Send(new VoteProfileGump(User, Voting.EnsureProfile(User as PlayerMobile), Hide(true), UseConfirmDialog)); }
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); }
protected override void CompileList(List <VoteProfile> list) { list.Clear(); list.AddRange(Voting.GetSortedProfiles(SortByToday)); base.CompileList(list); }