You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

95 line
2.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using SUISS.Storage;
  4. using SUISSEngine;
  5. public class XPBoostReward : IOngoingReward, IStorable
  6. {
  7. public XPBoostReward()
  8. {
  9. }
  10. public XPBoostReward(double boostPercentage, DateTime startTime, TimeSpan duration)
  11. {
  12. this.BoostPercentage = boostPercentage;
  13. this.StartTime = startTime;
  14. this.Duration = duration;
  15. this.IsActive = true;
  16. }
  17. public static decimal CurrentMultiplier
  18. {
  19. get
  20. {
  21. XPBoostReward xpboostReward = Singleton<OngoingRewardManager>.Instance.FindActiveReward<XPBoostReward>(null);
  22. if (xpboostReward != null)
  23. {
  24. return 1m + (decimal)xpboostReward.BoostPercentage * 0.01m;
  25. }
  26. return 1m;
  27. }
  28. }
  29. public double BoostPercentage { get; private set; }
  30. public DateTime StartTime { get; private set; }
  31. public TimeSpan Duration { get; private set; }
  32. public bool IsActive
  33. {
  34. get
  35. {
  36. return this._isActive && DateTime.UtcNow - this.StartTime <= this.Duration;
  37. }
  38. private set
  39. {
  40. this._isActive = value;
  41. }
  42. }
  43. public void FromStorage(IDictionary<string, object> dict)
  44. {
  45. this.BoostPercentage = (double)dict["BoostPercentage"];
  46. this.StartTime = new DateTime((long)dict["StartTime"], DateTimeKind.Utc);
  47. this.Duration = new TimeSpan((long)dict["Duration"]);
  48. }
  49. public void Run()
  50. {
  51. }
  52. public IDictionary<string, object> ToStorage()
  53. {
  54. IDictionary<string, object> dictionary = new Dictionary<string, object>();
  55. dictionary["BoostPercentage"] = this.BoostPercentage;
  56. dictionary["StartTime"] = this.StartTime.Ticks;
  57. dictionary["Duration"] = this.Duration.Ticks;
  58. return dictionary;
  59. }
  60. public override string ToString()
  61. {
  62. return string.Format("[Percentage] {0}\n[StartTime] {1}\n[Duration] {2}/{3}", new object[]
  63. {
  64. this.BoostPercentage,
  65. this.StartTime,
  66. DateTime.UtcNow - this.StartTime,
  67. this.Duration
  68. });
  69. }
  70. public bool Add(IOngoingReward reward)
  71. {
  72. return false;
  73. }
  74. public const string BoostPercentageKey = "BoostPercentage";
  75. public const string StartTimeKey = "StartTime";
  76. public const string DurationKey = "Duration";
  77. private bool _isActive;
  78. }