using System; using System.Collections.Generic; using SUISS.Storage; using SUISSEngine; public class XPBoostReward : IOngoingReward, IStorable { public XPBoostReward() { } public XPBoostReward(double boostPercentage, DateTime startTime, TimeSpan duration) { this.BoostPercentage = boostPercentage; this.StartTime = startTime; this.Duration = duration; this.IsActive = true; } public static decimal CurrentMultiplier { get { XPBoostReward xpboostReward = Singleton.Instance.FindActiveReward(null); if (xpboostReward != null) { return 1m + (decimal)xpboostReward.BoostPercentage * 0.01m; } return 1m; } } public double BoostPercentage { get; private set; } public DateTime StartTime { get; private set; } public TimeSpan Duration { get; private set; } public bool IsActive { get { return this._isActive && DateTime.UtcNow - this.StartTime <= this.Duration; } private set { this._isActive = value; } } public void FromStorage(IDictionary dict) { this.BoostPercentage = (double)dict["BoostPercentage"]; this.StartTime = new DateTime((long)dict["StartTime"], DateTimeKind.Utc); this.Duration = new TimeSpan((long)dict["Duration"]); } public void Run() { } public IDictionary ToStorage() { IDictionary dictionary = new Dictionary(); dictionary["BoostPercentage"] = this.BoostPercentage; dictionary["StartTime"] = this.StartTime.Ticks; dictionary["Duration"] = this.Duration.Ticks; return dictionary; } public override string ToString() { return string.Format("[Percentage] {0}\n[StartTime] {1}\n[Duration] {2}/{3}", new object[] { this.BoostPercentage, this.StartTime, DateTime.UtcNow - this.StartTime, this.Duration }); } public bool Add(IOngoingReward reward) { return false; } public const string BoostPercentageKey = "BoostPercentage"; public const string StartTimeKey = "StartTime"; public const string DurationKey = "Duration"; private bool _isActive; }