using System; using System.Collections.Generic; using CIG3.ExtensionMethods; using SUISS.Core; using SUISS.Storage; using SUISSEngine; using UnityEngine; public class CIGInterestingRatingListener : MonoBehaviour { private void Start() { SingletonMonobehaviour.Instance.IslandChangedEvent += this.OnIslandChanged; this._storage = Storage.Get(StorageLifecycle.Game).GetDictionary("CIGIslandsManager"); if (!this._storage.ContainsKey("IslandsOpened")) { this._islandsOpened = new Dictionary(); foreach (Island island in IslandExtensions.GetIslands()) { this._islandsOpened.Add(island.GetIndex(), false); } this._storage["IslandsOpened"] = this.SerializeIslandsOpened(this._islandsOpened); } else { this._islandsOpened = this.DeserializeIslandsOpened((string)this._storage["IslandsOpened"]); } } private void OnDestroy() { if (SingletonMonobehaviour.IsAvailable) { SingletonMonobehaviour.Instance.IslandChangedEvent -= this.OnIslandChanged; } } private void OnIslandChanged(Island island, bool isVisiting) { if (!isVisiting) { int index = island.GetIndex(); if (!this._islandsOpened.ContainsKey(index) || !this._islandsOpened[index]) { this._islandsOpened[index] = true; this._storage["IslandsOpened"] = this.SerializeIslandsOpened(this._islandsOpened); Messenger messenger = ServiceLocator.Find(); if (messenger != null) { messenger.Invoke>(new InterestingRatingTriggerEvent(CIGInterestingRatingTriggerEventType.OpenNewIsland)); } } } } private string SerializeIslandsOpened(Dictionary islandsOpened) { string text = string.Empty; foreach (KeyValuePair keyValuePair in islandsOpened) { string text2 = text; text = string.Concat(new object[] { text2, keyValuePair.Key, ".", (!keyValuePair.Value) ? bool.FalseString : bool.TrueString, "|" }); } if (text.Length > 0) { return text.Substring(0, text.Length - 1); } UnityEngine.Debug.LogError("The serialized string of the islandsOpened dictionary was empty. This would mean there are no islands which is obviously false."); return text; } private Dictionary DeserializeIslandsOpened(string islandsOpenedString) { Dictionary dictionary = new Dictionary(); string[] array = islandsOpenedString.Split(new char[] { '|' }); foreach (string text in array) { string[] array3 = text.Split(new char[] { '.' }); dictionary.Add(int.Parse(array3[0]), bool.Parse(array3[1])); } return dictionary; } private const string IslandsOpenedKey = "IslandsOpened"; private const string StorageKey = "CIGIslandsManager"; private const StorageLifecycle StorageCycle = StorageLifecycle.Game; private Dictionary _storage; private Dictionary _islandsOpened; }