|
- 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<CIGIslandsManager>.Instance.IslandChangedEvent += this.OnIslandChanged;
- this._storage = Storage.Get(StorageLifecycle.Game).GetDictionary("CIGIslandsManager");
- if (!this._storage.ContainsKey("IslandsOpened"))
- {
- this._islandsOpened = new Dictionary<int, bool>();
- 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<CIGIslandsManager>.IsAvailable)
- {
- SingletonMonobehaviour<CIGIslandsManager>.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<Messenger>();
- if (messenger != null)
- {
- messenger.Invoke<InterestingRatingTriggerEvent<CIGInterestingRatingTriggerEventType>>(new InterestingRatingTriggerEvent<CIGInterestingRatingTriggerEventType>(CIGInterestingRatingTriggerEventType.OpenNewIsland));
- }
- }
- }
- }
-
- private string SerializeIslandsOpened(Dictionary<int, bool> islandsOpened)
- {
- string text = string.Empty;
- foreach (KeyValuePair<int, bool> 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<int, bool> DeserializeIslandsOpened(string islandsOpenedString)
- {
- Dictionary<int, bool> dictionary = new Dictionary<int, bool>();
- 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<string, object> _storage;
-
- private Dictionary<int, bool> _islandsOpened;
- }
|