Beispiel #1
0
        /// <summary>
        /// Sets the time of the last vote request sent for the given Mobile and VoteSite objects.
        /// </summary>
        /// <param name="m">Mobile object.</param>
        /// <param name="voteSite">VoteSite object.</param>
        public static void SetLastVoteTime(Mobile m, VoteSite voteSite)
        {
            if (m == null || m.Deleted)
            {
                return;
            }

            if (voteSite == null || !voteSite.Valid)
            {
                return;
            }

            Account a = (Account)m.Account;

            if (a == null)
            {
                return;
            }

            DateTime now = DateTime.Now;

            string tag = now.ToString();

            a.SetTag("VS_LAST_VOTE_" + voteSite.Name.ToUpper(), tag);
        }
        /// <summary>
        /// Gets the time that the given Mobile last voted for the given VoteSite object.
        /// </summary>
        /// <param name="m">Mobile object.</param>
        /// <param name="voteSite">VoteSite object.</param>
        /// <returns>The time that the given Mobile last voted for the given VoteSite object.</returns>
        public static DateTime GetLastVoteTime(Mobile m, VoteSite voteSite)
        {
            bool     canVote;
            TimeSpan timeLeft;

            return(GetLastVoteTime(m, voteSite, out canVote, out timeLeft));
        }
        /// <summary>
        /// Gets the time that the given Mobile last voted for the given VoteSite object.
        /// </summary>
        /// <param name="m">Mobile object.</param>
        /// <param name="voteSite">VoteSite object.</param>
        /// <param name="canVote">A value indecating whether the Mobile object is allowed to vote.</param>
        /// <param name="timeLeft">A value indecating the amount of time left before the Mobile is allowed to vote again.</param>
        /// <returns>The time that the given Mobile last voted for the given VoteSite object, with extra output information.</returns>
        public static DateTime GetLastVoteTime(Mobile m, VoteSite voteSite, out bool canVote, out TimeSpan timeLeft)
        {
            canVote  = true;
            timeLeft = TimeSpan.Zero;

            if (m == null || m.Deleted || voteSite == null)
            {
                canVote = false;
                return(DateTime.Now);
            }

            DateTime now          = DateTime.Now;
            DateTime lastVoteTime = now.Subtract(voteSite.CoolDown);
            Account  a            = (Account)m.Account;

            if (a == null)
            {
                return(DateTime.Now);
            }

            string tag = a.GetTag("VS_LAST_VOTE_" + voteSite.Name.ToUpper());

            if (String.IsNullOrEmpty(tag))
            {
                SetLastVoteTime(m, voteSite);
                tag = now.Subtract(voteSite.CoolDown).ToString();
            }

            if (String.IsNullOrEmpty(tag))
            {
                tag = now.ToString();
            }

            bool parsed = DateTime.TryParse(tag, out lastVoteTime);

            if (parsed)
            {
                if (lastVoteTime.Add(voteSite.CoolDown) < now)
                {
                    timeLeft = TimeSpan.Zero;
                    canVote  = true;
                }
                else
                {
                    timeLeft = lastVoteTime.Add(voteSite.CoolDown) - now;
                    canVote  = false;
                }
            }
            else
            {
                lastVoteTime = now.Subtract(voteSite.CoolDown);
                timeLeft     = TimeSpan.Zero;
                canVote      = true;
            }

            return(lastVoteTime);
        }
        /// <summary>
        /// Invokes a new vote request for the given Mobile and VoteSite objects.
        /// </summary>
        /// <param name="from">Request sender.</param>
        /// <param name="site">VoteSite object.</param>
        public static void CastVote(Mobile from, VoteSite site)
        {
            if (from == null || from.Deleted || site == null)
            {
                return;
            }

            VoteEvents.InvokeVoteRequest(new VoteRequestEventArgs(from, site));
        }
        /// <summary>
        /// Gets the amount of time left before the given Mobile object can vote for the given VoteSite object.
        /// </summary>
        /// <param name="m">Mobile object.</param>
        /// <param name="site">VoteSite object.</param>
        /// <returns>The amount of time left before the given Mobile object can vote for the given VoteSite object.</returns>
        public static TimeSpan GetTimeLeft(Mobile m, VoteSite site)
        {
            bool     canVote;
            TimeSpan timeLeft;

            GetLastVoteTime(m, site, out canVote, out timeLeft);

            return(timeLeft);
        }
Beispiel #6
0
		/// <summary>
		/// Gets the time that the given Mobile last voted for the given VoteSite object.
		/// </summary>
		/// <param name="m">Mobile object.</param>
		/// <param name="voteSite">VoteSite object.</param>
		/// <param name="canVote">A value indecating whether the Mobile object is allowed to vote.</param>
		/// <param name="timeLeft">A value indecating the amount of time left before the Mobile is allowed to vote again.</param>
		/// <returns>The time that the given Mobile last voted for the given VoteSite object, with extra output information.</returns>
		public static DateTime GetLastVoteTime(Mobile m, VoteSite voteSite, out bool canVote, out TimeSpan timeLeft)
		{
			DateTime now = DateTime.Now;
			DateTime lastVoteTime = now.Subtract(voteSite.CoolDown);

			canVote = true;
			timeLeft = TimeSpan.Zero;

			if (m == null || m.Deleted)
				return DateTime.Now;

			Account a = (Account)m.Account;

			if (a == null)
				return DateTime.Now;

			string tag = a.GetTag("VS_LAST_VOTE_" + voteSite.Name.ToUpper());

			if (String.IsNullOrEmpty(tag))
			{
				SetLastVoteTime(m, voteSite);
				tag = now.Subtract(voteSite.CoolDown).ToString();
			}

			if (String.IsNullOrEmpty(tag))
				tag = now.ToString();

			bool parsed = DateTime.TryParse(tag, out lastVoteTime);

			if (parsed)
			{
				if (lastVoteTime.Add(voteSite.CoolDown) < now)
				{
					timeLeft = TimeSpan.Zero;
					canVote = true;
				}
				else
				{
					timeLeft = lastVoteTime.Add(voteSite.CoolDown) - now;
					canVote = false;
				}
			}
			else
			{
				lastVoteTime = now.Subtract(voteSite.CoolDown);
				timeLeft = TimeSpan.Zero;
				canVote = true;
			}

			return lastVoteTime;
		}
Beispiel #7
0
        private static void OnVoteRequest(VoteRequestEventArgs e)
        {
            Mobile   from     = e.Sender;
            VoteSite voteSite = e.VoteSite;

            if (from == null || from.Deleted)
            {
                return;
            }

            if (voteSite.Valid)
            {
                if (e.CanVote)
                {
                    if (voteSite.Parent.OnBeforeVote(from))
                    {
                        voteSite.Parent.OnVote(from, VoteStatus.Success);
                        voteSite.Parent.OnAfterVote(from, VoteStatus.Success);
                    }
                    else
                    {
                        voteSite.Parent.OnVote(from, VoteStatus.Custom);
                        voteSite.Parent.OnAfterVote(from, VoteStatus.Custom);
                    }
                }
                else
                {
                    voteSite.Parent.OnVote(from, VoteStatus.TooEarly);
                    voteSite.Parent.OnAfterVote(from, VoteStatus.TooEarly);
                }
            }
            else
            {
                voteSite.Parent.OnVote(from, VoteStatus.Invalid);
                voteSite.Parent.OnAfterVote(from, VoteStatus.Invalid);
            }
        }
Beispiel #8
0
 /// <summary>
 /// Creates a new instance of VoteRequestEventArgs.
 /// </summary>
 /// <param name="sender">The Mobile reference to the request sender.</param>
 /// <param name="voteSite">The VoteSiteProfile used by the request.</param>
 public VoteRequestEventArgs(Mobile sender, VoteSite voteSite)
 {
     _Sender   = sender;
     _VoteSite = voteSite;
 }
Beispiel #9
0
		/// <summary>
		/// Gets the time that the given Mobile last voted for the given VoteSite object.
		/// </summary>
		/// <param name="m">Mobile object.</param>
		/// <param name="voteSite">VoteSite object.</param>
		/// <returns>The time that the given Mobile last voted for the given VoteSite object.</returns>
		public static DateTime GetLastVoteTime(Mobile m, VoteSite voteSite)
		{
			bool canVote;
			TimeSpan timeLeft;
			return GetLastVoteTime(m, voteSite, out canVote, out timeLeft);
		}
Beispiel #10
0
		/// <summary>
		/// Invokes a new vote request for the given Mobile and VoteSite objects.
		/// </summary>
		/// <param name="from">Request sender.</param>
		/// <param name="site">VoteSite object.</param>
		public static void CastVote(Mobile from, VoteSite site)
		{
			VoteEvents.InvokeVoteRequest(new VoteRequestEventArgs(from, site));
		}
Beispiel #11
0
		/// <summary>
		/// Gets the amount of time left before the given Mobile object can vote for the given VoteSite object.
		/// </summary>
		/// <param name="m">Mobile object.</param>
		/// <param name="site">VoteSite object.</param>
		/// <returns>The amount of time left before the given Mobile object can vote for the given VoteSite object.</returns>
		public static TimeSpan GetTimeLeft(Mobile m, VoteSite site)
		{
			bool canVote;
			TimeSpan timeLeft;
			GetLastVoteTime(m, site, out canVote, out timeLeft);

			return timeLeft;
		}
Beispiel #12
0
		/// <summary>
		/// Sets the time of the last vote request sent for the given Mobile and VoteSite objects.
		/// </summary>
		/// <param name="m">Mobile object.</param>
		/// <param name="voteSite">VoteSite object.</param>
		public static void SetLastVoteTime(Mobile m, VoteSite voteSite)
		{
			if (m == null || m.Deleted)
				return;

			if (voteSite == null || !voteSite.Valid)
				return;

			Account a = (Account)m.Account;

			if (a == null)
				return;

			DateTime now = DateTime.Now;

			string tag = now.ToString();

			a.SetTag("VS_LAST_VOTE_" + voteSite.Name.ToUpper(), tag);
		}
Beispiel #13
0
		/// <summary>
		/// Creates a new instance of VoteRequestEventArgs.
		/// </summary>
		/// <param name="sender">The Mobile reference to the request sender.</param>
		/// <param name="voteSite">The VoteSiteProfile used by the request.</param>
		public VoteRequestEventArgs(Mobile sender, VoteSite voteSite)
		{
			_Sender = sender;
			_VoteSite = voteSite;
		}
Beispiel #14
0
 /// <summary>
 /// Invokes a new vote request for the given Mobile and VoteSite objects.
 /// </summary>
 /// <param name="from">Request sender.</param>
 /// <param name="site">VoteSite object.</param>
 public static void CastVote(Mobile from, VoteSite site)
 {
     VoteEvents.InvokeVoteRequest(new VoteRequestEventArgs(from, site));
 }