You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

140 lines
3.2 KiB

  1. using System;
  2. using CIG;
  3. using CIG.Translation;
  4. using CIGEnums;
  5. using SUISS.Core;
  6. using SUISSEngine;
  7. using Tweening;
  8. using UnityEngine;
  9. public class CIGBuySign : MonoBehaviour
  10. {
  11. protected void Awake()
  12. {
  13. this._currencyAnimationSource.Init(this._currencyAnimationObject);
  14. }
  15. protected virtual void OnGridTileStatusChanged(GridTile.Status oldStatus)
  16. {
  17. if (this == null)
  18. {
  19. return;
  20. }
  21. if (this.chest != null && this.sign != null)
  22. {
  23. this.chest.sortingOrder = this.sign.sortingOrder + 1;
  24. }
  25. }
  26. public void Buy(PlingType type, string currencyType, decimal value)
  27. {
  28. if (!this._haveChest)
  29. {
  30. return;
  31. }
  32. SingletonMonobehaviour<CIGGameState>.Instance.UnprocessedChestGold += value;
  33. if (this.sign != null)
  34. {
  35. this.sign.enabled = false;
  36. }
  37. Action collect = this.CollectAction(type, currencyType, value, this.chestGO, this._chestTweener);
  38. BoxCollider2D collider = null;
  39. if (this.chestGO != null)
  40. {
  41. collider = this.chestGO.GetComponent<BoxCollider2D>();
  42. }
  43. if (collider != null)
  44. {
  45. this.chestGO.transform.parent = base.transform.parent;
  46. collider.enabled = true;
  47. Timer timer = null;
  48. timer = SingletonMonobehaviour<TimerManager>.Instance.CreateClockTimer(DateTimeKind.Utc, TimeSpan.FromSeconds(15.0), delegate()
  49. {
  50. if (collider != null)
  51. {
  52. collider.enabled = false;
  53. }
  54. if (timer != null)
  55. {
  56. timer.Cancel();
  57. }
  58. collect();
  59. });
  60. Clickable.Instance(this.chestGO).OnClickEvent += delegate(GameObject target)
  61. {
  62. if (collider != null)
  63. {
  64. collider.enabled = false;
  65. }
  66. if (timer != null)
  67. {
  68. timer.Cancel();
  69. }
  70. collect();
  71. };
  72. }
  73. else
  74. {
  75. collect();
  76. }
  77. }
  78. public void EnableChest()
  79. {
  80. this.chestGO.SetActive(true);
  81. this._haveChest = true;
  82. }
  83. private Action CollectAction(PlingType type, string currencyType, decimal value, GameObject chestGO, Tweener chestTweener)
  84. {
  85. return delegate()
  86. {
  87. if (value > 0m && SingletonMonobehaviour<CIGGameState>.IsAvailable)
  88. {
  89. SingletonMonobehaviour<CIGGameState>.Instance.UnprocessedChestGold -= value;
  90. SingletonMonobehaviour<CIGGameState>.Instance.EarnCurrencies(new Currencies(currencyType, value), this._currencyAnimationObject);
  91. if (chestGO != null)
  92. {
  93. Pling pling = this._plingManager.Show(type, Vector3.zero, Clip.Ping);
  94. ILocalizedString value2 = Localization.Integer(value);
  95. if (type == PlingType.Cash_Green || type == PlingType.Cash_Red)
  96. {
  97. pling.ShowWithParticles(value2, ParticleType.CashFountain);
  98. }
  99. else
  100. {
  101. pling.Show(value2);
  102. }
  103. }
  104. }
  105. if (chestTweener)
  106. {
  107. chestTweener.Play();
  108. }
  109. else if (chestGO != null)
  110. {
  111. UnityEngine.Object.Destroy(chestGO);
  112. }
  113. };
  114. }
  115. public GameObject chestGO;
  116. public SpriteRenderer sign;
  117. public SpriteRenderer chest;
  118. [SerializeField]
  119. private Tweener _chestTweener;
  120. [SerializeField]
  121. private PlingManager _plingManager;
  122. [SerializeField]
  123. private CurrencyAnimationSource _currencyAnimationSource;
  124. protected bool _haveChest;
  125. private object _currencyAnimationObject = new object();
  126. }