using System; using CIG.Extensions; using CIG3.ExtensionMethods; using Inno.DLC; using SUISS.Core; using SUISS.Scheduling; using SUISS.Storage; using SUISSEngine; using UnityEngine; public class CIGDLCDownloader : MonoBehaviour { public static double AllowedToAskTimestamp { get { return Storage.Get(StorageLifecycle.Player).Root.GetValue("AskDLCTimestamp", 0.0); } set { Storage.Get(StorageLifecycle.Player).Root["AskDLCTimestamp"] = value; } } public bool IsDone { get { return this._done; } } public void ShowPopup() { this.CancelInvoke(new Action(this.TryShow)); if (this._group != null) { DLCGroup group = this._group; this._popupRequest = SingletonMonobehaviour.Instance.RequestFirstPopup(delegate(State state) { if (this != null) { PopupRequest? popupRequest = this._popupRequest; if (popupRequest != null) { this._popupRequest = null; } } DownloadChoicePopupState downloadChoicePopupState = state as DownloadChoicePopupState; if (downloadChoicePopupState != null) { downloadChoicePopupState.Setup(group); } else { UnityEngine.Debug.LogError("Wrong type for popup state"); } }); } else { UnityEngine.Debug.LogError("Group is null"); } } public void Check() { if (this.cityIsland != null) { string text = this.cityIsland.island.ToString(); DLCManager dlcmanager = ServiceLocator.Find(); if (dlcmanager != null && dlcmanager.IsEnabled) { this._group = dlcmanager.GetGroup(text); if (this._group != null) { long remainingDownloadSize = this._group.RemainingDownloadSize; this._done = (remainingDownloadSize == 0L); } else { UnityEngine.Debug.LogError(string.Format("Group {0} not found.", text)); } } else { UnityEngine.Debug.LogWarning("No DLC manager found"); } } else { UnityEngine.Debug.LogError("No CityIsland linked"); } if (this._done) { if (this._requestedSettingsExclamation) { SingletonMonobehaviour.Instance.fsm.GetState().PopSettingsExclamationRequest(this); this._requestedSettingsExclamation = false; } this._group = null; } else if (!this._requestedSettingsExclamation) { SingletonMonobehaviour.Instance.fsm.GetState().PushSettingsExclamationRequest(this); this._requestedSettingsExclamation = true; } } private void Start() { this.Check(); if (!this._done) { if (Timing.UtcNow > CIGDLCDownloader.AllowedToAskTimestamp) { this.InvokeRepeating(new Action(this.TryShow), 2f, 1f, false); } else { UnityEngine.Debug.Log(string.Format("Will ask in {0} days", (CIGDLCDownloader.AllowedToAskTimestamp - Timing.UtcNow) / 86400.0)); } } } private void OnDestroy() { if (SingletonMonobehaviour.IsAvailable) { PopupRequest? popupRequest = this._popupRequest; if (popupRequest != null) { PopupManager instance = SingletonMonobehaviour.Instance; PopupRequest? popupRequest2 = this._popupRequest; instance.RemovePopupRequest(popupRequest2.Value); } if (this._requestedSettingsExclamation) { SingletonMonobehaviour.Instance.fsm.GetState().PopSettingsExclamationRequest(this); this._requestedSettingsExclamation = false; } } } private void TryShow() { if (SingletonMonobehaviour.Instance.IsVisible) { return; } if (this._group == null) { this.Check(); if (this._done) { this.CancelInvoke(new Action(this.TryShow)); } return; } this.ShowPopup(); } [SerializeField] [SelfReference] private CityIsland cityIsland; private bool _requestedSettingsExclamation; private const string TimestampKey = "AskDLCTimestamp"; private bool _done; private DLCGroup _group; private PopupRequest? _popupRequest; }