Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

175 строки
4.0 KiB

  1. using System;
  2. using System.Diagnostics;
  3. using CIG;
  4. using SUISS.Core;
  5. using UnityEngine;
  6. namespace SUISSEngine
  7. {
  8. public abstract class GameState<T> : DailyAbstractState<T> where T : GameState<T>
  9. {
  10. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  11. public event GameState<T>.SecondsPlayedChangedEventHandler SecondsPlayedChangedEvent;
  12. private void FireSecondsPlayedChangedEvent()
  13. {
  14. if (this.SecondsPlayedChangedEvent != null)
  15. {
  16. this.SecondsPlayedChangedEvent();
  17. }
  18. }
  19. protected override void Start()
  20. {
  21. base.Start();
  22. this.MinutesPlayedInThisSession = 0;
  23. this.SecondsPlayedInThisSession = 0;
  24. this.CleanGameDateTime = this.CleanGameDateTime;
  25. }
  26. private void Update()
  27. {
  28. this._secondsTimer += Time.unscaledDeltaTime;
  29. this._minuteTimerInSeconds += Time.unscaledDeltaTime;
  30. if (this._secondsTimer > 11f)
  31. {
  32. this.SecondPlayed11();
  33. this._secondsTimer %= 11f;
  34. }
  35. if (this._minuteTimerInSeconds > 60f)
  36. {
  37. this.MinutePlayed();
  38. this._minuteTimerInSeconds %= 60f;
  39. }
  40. }
  41. public TimeSpan TimePassedSinceCleanGameDateTime
  42. {
  43. get
  44. {
  45. return DateTime.UtcNow - this.CleanGameDateTime;
  46. }
  47. }
  48. public int HoursSinceCleanGame
  49. {
  50. get
  51. {
  52. return Mathf.Max(0, Mathf.FloorToInt((float)this.TimePassedSinceCleanGameDateTime.TotalHours));
  53. }
  54. }
  55. public int MinutesPlayedInThisSession { get; protected set; }
  56. public int SecondsPlayedInThisSession { get; protected set; }
  57. public long TotalMinutesPlayed
  58. {
  59. get
  60. {
  61. return this.GetValue<long>("TotalMinutesPlayed", 0L);
  62. }
  63. protected set
  64. {
  65. this.SetValue("TotalMinutesPlayed", value);
  66. }
  67. }
  68. public long TotalFiveMinuteSessions
  69. {
  70. get
  71. {
  72. return this.GetValue<long>("TotalFiveMinuteSessions", 0L);
  73. }
  74. protected set
  75. {
  76. this.SetValue("TotalFiveMinuteSessions", value);
  77. }
  78. }
  79. public DateTime CleanGameDateTime
  80. {
  81. get
  82. {
  83. if (this._cleanGameDateTime == null)
  84. {
  85. this._cleanGameDateTime = new DateTime?(DateTime.FromBinary(this.GetValue<long>("CleanGameDateTime", DateTime.UtcNow.ToBinary())));
  86. }
  87. return this._cleanGameDateTime.Value;
  88. }
  89. protected set
  90. {
  91. this._cleanGameDateTime = new DateTime?(value);
  92. this.SetValue("CleanGameDateTime", value.ToBinary());
  93. }
  94. }
  95. public long TotalSessionLengthEventsFired
  96. {
  97. get
  98. {
  99. return this.GetValue<long>("TotalSessionLengthEventsFired", 0L);
  100. }
  101. set
  102. {
  103. this.SetValue("TotalSessionLengthEventsFired", value);
  104. }
  105. }
  106. protected override void OnNewGameState()
  107. {
  108. this.TotalMinutesPlayed = 0L;
  109. this.TotalFiveMinuteSessions = 0L;
  110. this.TotalSessionLengthEventsFired = 0L;
  111. this.CleanGameDateTime = this.CleanGameDateTime;
  112. }
  113. private void MinutePlayed()
  114. {
  115. long totalMinutesPlayed = this.TotalMinutesPlayed;
  116. long oldMinutesPlayed = (long)this.MinutesPlayedInThisSession;
  117. this.TotalMinutesPlayed += 1L;
  118. this.MinutesPlayedInThisSession++;
  119. if (this.MinutesPlayedInThisSession == 5)
  120. {
  121. long totalFiveMinuteSessions = this.TotalFiveMinuteSessions;
  122. this.TotalFiveMinuteSessions += 1L;
  123. }
  124. int numberOfTimesPlayed = SingletonMonobehaviour<CIGGameStats>.Instance.NumberOfTimesPlayed;
  125. if (numberOfTimesPlayed != 1)
  126. {
  127. if (numberOfTimesPlayed == 2)
  128. {
  129. }
  130. }
  131. else
  132. {
  133. }
  134. }
  135. private void SecondPlayed11()
  136. {
  137. this.SecondsPlayedInThisSession += 11;
  138. this.FireSecondsPlayedChangedEvent();
  139. }
  140. public const int MAGIC_ELEVEN_SECONDS = 11;
  141. public const string TotalMinutesPlayedKey = "TotalMinutesPlayed";
  142. public const string TotalFiveMinuteSessionsKey = "TotalFiveMinuteSessions";
  143. public const string CleanGameDateTimeKey = "CleanGameDateTime";
  144. public const string TotalSessionLengthEventsFiredKey = "TotalSessionLengthEventsFired";
  145. private float _secondsTimer;
  146. private float _minuteTimerInSeconds;
  147. private DateTime? _cleanGameDateTime;
  148. public delegate void SecondsPlayedChangedEventHandler();
  149. }
  150. }