using System; using System.Diagnostics; using CIG; using SUISS.Core; using UnityEngine; namespace SUISSEngine { public abstract class GameState : DailyAbstractState where T : GameState { //[DebuggerBrowsable(DebuggerBrowsableState.Never)] public event GameState.SecondsPlayedChangedEventHandler SecondsPlayedChangedEvent; private void FireSecondsPlayedChangedEvent() { if (this.SecondsPlayedChangedEvent != null) { this.SecondsPlayedChangedEvent(); } } protected override void Start() { base.Start(); this.MinutesPlayedInThisSession = 0; this.SecondsPlayedInThisSession = 0; this.CleanGameDateTime = this.CleanGameDateTime; } private void Update() { this._secondsTimer += Time.unscaledDeltaTime; this._minuteTimerInSeconds += Time.unscaledDeltaTime; if (this._secondsTimer > 11f) { this.SecondPlayed11(); this._secondsTimer %= 11f; } if (this._minuteTimerInSeconds > 60f) { this.MinutePlayed(); this._minuteTimerInSeconds %= 60f; } } public TimeSpan TimePassedSinceCleanGameDateTime { get { return DateTime.UtcNow - this.CleanGameDateTime; } } public int HoursSinceCleanGame { get { return Mathf.Max(0, Mathf.FloorToInt((float)this.TimePassedSinceCleanGameDateTime.TotalHours)); } } public int MinutesPlayedInThisSession { get; protected set; } public int SecondsPlayedInThisSession { get; protected set; } public long TotalMinutesPlayed { get { return this.GetValue("TotalMinutesPlayed", 0L); } protected set { this.SetValue("TotalMinutesPlayed", value); } } public long TotalFiveMinuteSessions { get { return this.GetValue("TotalFiveMinuteSessions", 0L); } protected set { this.SetValue("TotalFiveMinuteSessions", value); } } public DateTime CleanGameDateTime { get { if (this._cleanGameDateTime == null) { this._cleanGameDateTime = new DateTime?(DateTime.FromBinary(this.GetValue("CleanGameDateTime", DateTime.UtcNow.ToBinary()))); } return this._cleanGameDateTime.Value; } protected set { this._cleanGameDateTime = new DateTime?(value); this.SetValue("CleanGameDateTime", value.ToBinary()); } } public long TotalSessionLengthEventsFired { get { return this.GetValue("TotalSessionLengthEventsFired", 0L); } set { this.SetValue("TotalSessionLengthEventsFired", value); } } protected override void OnNewGameState() { this.TotalMinutesPlayed = 0L; this.TotalFiveMinuteSessions = 0L; this.TotalSessionLengthEventsFired = 0L; this.CleanGameDateTime = this.CleanGameDateTime; } private void MinutePlayed() { long totalMinutesPlayed = this.TotalMinutesPlayed; long oldMinutesPlayed = (long)this.MinutesPlayedInThisSession; this.TotalMinutesPlayed += 1L; this.MinutesPlayedInThisSession++; if (this.MinutesPlayedInThisSession == 5) { long totalFiveMinuteSessions = this.TotalFiveMinuteSessions; this.TotalFiveMinuteSessions += 1L; } int numberOfTimesPlayed = SingletonMonobehaviour.Instance.NumberOfTimesPlayed; if (numberOfTimesPlayed != 1) { if (numberOfTimesPlayed == 2) { } } else { } } private void SecondPlayed11() { this.SecondsPlayedInThisSession += 11; this.FireSecondsPlayedChangedEvent(); } public const int MAGIC_ELEVEN_SECONDS = 11; public const string TotalMinutesPlayedKey = "TotalMinutesPlayed"; public const string TotalFiveMinuteSessionsKey = "TotalFiveMinuteSessions"; public const string CleanGameDateTimeKey = "CleanGameDateTime"; public const string TotalSessionLengthEventsFiredKey = "TotalSessionLengthEventsFired"; private float _secondsTimer; private float _minuteTimerInSeconds; private DateTime? _cleanGameDateTime; public delegate void SecondsPlayedChangedEventHandler(); } }