예제 #1
0
        public virtual bool Vote(PlayerMobile voter, bool message = true)
        {
            if (voter == null || voter.Deleted || !CanVote(voter, message))
            {
                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);
            }

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

            int 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);
        }
예제 #2
0
파일: Voting.cs 프로젝트: zerodowned/Core
        public static VoteProfile EnsureProfile(PlayerMobile m, bool replace = false)
        {
            if (!Profiles.ContainsKey(m))
            {
                Profiles.Add(m, new VoteProfile(m));
            }
            else if (replace || Profiles[m] == null || Profiles[m].Deleted)
            {
                Profiles[m] = new VoteProfile(m);
            }

            return(Profiles[m]);
        }
예제 #3
0
파일: Voting.cs 프로젝트: Ravenwolfe/Core
		public static VoteProfile EnsureProfile(PlayerMobile m, bool replace = false)
		{
			if (!Profiles.ContainsKey(m))
			{
				Profiles.Add(m, new VoteProfile(m));
			}
			else if (replace || Profiles[m] == null || Profiles[m].Deleted)
			{
				Profiles[m] = new VoteProfile(m);
			}

			return Profiles[m];
		}
예제 #4
0
파일: Voting.cs 프로젝트: LordEnigma/UO
        private static int InternalProfileSortToday(VoteProfile a, VoteProfile b)
        {
            if (a == b)
            {
                return(0);
            }

            if (a == null)
            {
                return(1);
            }

            if (b == null)
            {
                return(-1);
            }

            if (a.Deleted && b.Deleted)
            {
                return(0);
            }

            if (a.Deleted)
            {
                return(1);
            }

            if (b.Deleted)
            {
                return(-1);
            }

            DateTime when = DateTime.UtcNow;

            int aTotal = a.GetTokenTotal(when);
            int bTotal = b.GetTokenTotal(when);

            if (aTotal > bTotal)
            {
                return(-1);
            }

            if (aTotal < bTotal)
            {
                return(1);
            }

            return(0);
        }
예제 #5
0
		private static int InternalProfileSort(VoteProfile a, VoteProfile b)
		{
			if (a == b)
			{
				return 0;
			}

			if (a == null)
			{
				return 1;
			}

			if (b == null)
			{
				return -1;
			}

			if (a.Deleted && b.Deleted)
			{
				return 0;
			}

			if (a.Deleted)
			{
				return 1;
			}

			if (b.Deleted)
			{
				return -1;
			}

			int aTotal = a.GetTokenTotal();
			int bTotal = b.GetTokenTotal();

			if (aTotal > bTotal)
			{
				return -1;
			}

			if (aTotal < bTotal)
			{
				return 1;
			}

			return 0;
		}
예제 #6
0
파일: Voting.cs 프로젝트: LordEnigma/UO
        private static int InternalProfileSort(VoteProfile a, VoteProfile b)
        {
            if (a == b)
            {
                return(0);
            }

            if (a == null)
            {
                return(1);
            }

            if (b == null)
            {
                return(-1);
            }

            if (a.Deleted && b.Deleted)
            {
                return(0);
            }

            if (a.Deleted)
            {
                return(1);
            }

            if (b.Deleted)
            {
                return(-1);
            }

            int aTotal = a.GetTokenTotal();
            int bTotal = b.GetTokenTotal();

            if (aTotal > bTotal)
            {
                return(-1);
            }

            if (aTotal < bTotal)
            {
                return(1);
            }

            return(0);
        }
예제 #7
0
        private static bool DeserializeProfiles(GenericReader reader)
        {
            int version = reader.GetVersion();

            switch (version)
            {
            case 0:
            {
                reader.ReadBlockDictionary(
                    r =>
                    {
                        var k = r.ReadMobile <PlayerMobile>();
                        var v = new VoteProfile(r);
                        return(new KeyValuePair <PlayerMobile, VoteProfile>(k, v));
                    },
                    Profiles);
            }
            break;
            }

            return(true);
        }
예제 #8
0
파일: Voting.cs 프로젝트: zerodowned/Core
 public static void Remove(this VoteProfile profile)
 {
     Profiles.Remove(profile.Owner);
 }
예제 #9
0
		private static int InternalProfileSortToday(VoteProfile a, VoteProfile b)
		{
			if (a == b)
			{
				return 0;
			}

			if (a == null)
			{
				return 1;
			}

			if (b == null)
			{
				return -1;
			}

			if (a.Deleted && b.Deleted)
			{
				return 0;
			}

			if (a.Deleted)
			{
				return 1;
			}

			if (b.Deleted)
			{
				return -1;
			}

			DateTime when = DateTime.UtcNow;

			int aTotal = a.GetTokenTotal(when);
			int bTotal = b.GetTokenTotal(when);

			if (aTotal > bTotal)
			{
				return -1;
			}

			if (aTotal < bTotal)
			{
				return 1;
			}

			return 0;
		}
예제 #10
0
		private static bool DeserializeProfiles(GenericReader reader)
		{
			int version = reader.GetVersion();

			switch (version)
			{
				case 0:
					{
						reader.ReadBlockDictionary(
							r =>
							{
								var k = r.ReadMobile<PlayerMobile>();
								var v = new VoteProfile(r);
								return new KeyValuePair<PlayerMobile, VoteProfile>(k, v);
							},
							Profiles);
					}
					break;
			}

			return true;
		}
예제 #11
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);
        }