Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

107 рядки
3.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using CIG3.ExtensionMethods;
  4. using SUISS.Core;
  5. using SUISS.Storage;
  6. using SUISSEngine;
  7. using UnityEngine;
  8. public class CIGInterestingRatingListener : MonoBehaviour
  9. {
  10. private void Start()
  11. {
  12. SingletonMonobehaviour<CIGIslandsManager>.Instance.IslandChangedEvent += this.OnIslandChanged;
  13. this._storage = Storage.Get(StorageLifecycle.Game).GetDictionary("CIGIslandsManager");
  14. if (!this._storage.ContainsKey("IslandsOpened"))
  15. {
  16. this._islandsOpened = new Dictionary<int, bool>();
  17. foreach (Island island in IslandExtensions.GetIslands())
  18. {
  19. this._islandsOpened.Add(island.GetIndex(), false);
  20. }
  21. this._storage["IslandsOpened"] = this.SerializeIslandsOpened(this._islandsOpened);
  22. }
  23. else
  24. {
  25. this._islandsOpened = this.DeserializeIslandsOpened((string)this._storage["IslandsOpened"]);
  26. }
  27. }
  28. private void OnDestroy()
  29. {
  30. if (SingletonMonobehaviour<CIGIslandsManager>.IsAvailable)
  31. {
  32. SingletonMonobehaviour<CIGIslandsManager>.Instance.IslandChangedEvent -= this.OnIslandChanged;
  33. }
  34. }
  35. private void OnIslandChanged(Island island, bool isVisiting)
  36. {
  37. if (!isVisiting)
  38. {
  39. int index = island.GetIndex();
  40. if (!this._islandsOpened.ContainsKey(index) || !this._islandsOpened[index])
  41. {
  42. this._islandsOpened[index] = true;
  43. this._storage["IslandsOpened"] = this.SerializeIslandsOpened(this._islandsOpened);
  44. Messenger messenger = ServiceLocator.Find<Messenger>();
  45. if (messenger != null)
  46. {
  47. messenger.Invoke<InterestingRatingTriggerEvent<CIGInterestingRatingTriggerEventType>>(new InterestingRatingTriggerEvent<CIGInterestingRatingTriggerEventType>(CIGInterestingRatingTriggerEventType.OpenNewIsland));
  48. }
  49. }
  50. }
  51. }
  52. private string SerializeIslandsOpened(Dictionary<int, bool> islandsOpened)
  53. {
  54. string text = string.Empty;
  55. foreach (KeyValuePair<int, bool> keyValuePair in islandsOpened)
  56. {
  57. string text2 = text;
  58. text = string.Concat(new object[]
  59. {
  60. text2,
  61. keyValuePair.Key,
  62. ".",
  63. (!keyValuePair.Value) ? bool.FalseString : bool.TrueString,
  64. "|"
  65. });
  66. }
  67. if (text.Length > 0)
  68. {
  69. return text.Substring(0, text.Length - 1);
  70. }
  71. UnityEngine.Debug.LogError("The serialized string of the islandsOpened dictionary was empty. This would mean there are no islands which is obviously false.");
  72. return text;
  73. }
  74. private Dictionary<int, bool> DeserializeIslandsOpened(string islandsOpenedString)
  75. {
  76. Dictionary<int, bool> dictionary = new Dictionary<int, bool>();
  77. string[] array = islandsOpenedString.Split(new char[]
  78. {
  79. '|'
  80. });
  81. foreach (string text in array)
  82. {
  83. string[] array3 = text.Split(new char[]
  84. {
  85. '.'
  86. });
  87. dictionary.Add(int.Parse(array3[0]), bool.Parse(array3[1]));
  88. }
  89. return dictionary;
  90. }
  91. private const string IslandsOpenedKey = "IslandsOpened";
  92. private const string StorageKey = "CIGIslandsManager";
  93. private const StorageLifecycle StorageCycle = StorageLifecycle.Game;
  94. private Dictionary<string, object> _storage;
  95. private Dictionary<int, bool> _islandsOpened;
  96. }