Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

124 righe
3.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using CIG;
  5. using CIG.Translation;
  6. using CIGEnums;
  7. using SUISS.Core;
  8. using SUISS.Core.Utilities;
  9. using SUISSEngine;
  10. using UnityEngine;
  11. [RequireComponent(typeof(GridTile), typeof(Serializing), typeof(Clickable))]
  12. public class FloatingChest : MonoBehaviour
  13. {
  14. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  15. public event Action RewardCollectedEvent;
  16. private void FireRewardCollectedEvent()
  17. {
  18. if (this.RewardCollectedEvent != null)
  19. {
  20. this.RewardCollectedEvent();
  21. }
  22. }
  23. private void Start()
  24. {
  25. this._currencyAnimationSource.Init(this._animationSourceObject);
  26. this._clickable.OnClickEvent += this.Collect;
  27. }
  28. private void OnDestroy()
  29. {
  30. if (this._clickable != null)
  31. {
  32. this._clickable.OnClickEvent -= this.Collect;
  33. }
  34. }
  35. public void Collect(GameObject target)
  36. {
  37. if (SingletonMonobehaviour<CIGGameState>.IsAvailable)
  38. {
  39. int num = UnityEngine.Random.Range(1, 101);
  40. decimal num2;
  41. string currency;
  42. PlingType plingType;
  43. if (num <= 80)
  44. {
  45. num2 = this.CashCalucator();
  46. currency = "Cash";
  47. plingType = PlingType.Cash_Green;
  48. }
  49. else if (num - 80 <= 19)
  50. {
  51. num2 = 1m;
  52. currency = "Gold";
  53. plingType = PlingType.Gold;
  54. }
  55. else
  56. {
  57. num2 = 5m;
  58. currency = "Gold";
  59. plingType = PlingType.Gold;
  60. }
  61. SingletonMonobehaviour<CIGGameState>.Instance.EarnCurrencies(new Currencies(currency, num2), this._animationSourceObject);
  62. Pling pling = this._plingManager.Show(plingType, Vector3.zero, Clip.Ping);
  63. if (plingType == PlingType.Cash_Green)
  64. {
  65. pling.ShowWithParticles(Localization.Integer(num2), ParticleType.CashFountain);
  66. }
  67. else
  68. {
  69. pling.Show(Localization.Integer(num2));
  70. }
  71. if (this._clickable != null)
  72. {
  73. this._clickable.OnClickEvent -= this.Collect;
  74. }
  75. IsometricIsland.GetParent(this).builder.DestroyTile(this._tile);
  76. this.FireRewardCollectedEvent();
  77. }
  78. }
  79. private long CashCalucator()
  80. {
  81. List<CIGCommercialBuilding> list = new List<CIGCommercialBuilding>(SingletonMonobehaviour<GameObjectManager>.Instance.Commercial);
  82. int level = SingletonMonobehaviour<CIGGameState>.Instance.Level;
  83. int i;
  84. for (i = level; i > 0; i--)
  85. {
  86. List<CIGCommercialBuilding> list2 = list.FindAll((CIGCommercialBuilding x) => Array.Exists<int>(x.unlockLevels, (int y) => y == i) && x.baseProfitCurrencies.Contains("Cash"));
  87. if (list2.Count > 0)
  88. {
  89. CIGCommercialBuilding cigcommercialBuilding = list2.PickRandom<CIGCommercialBuilding>();
  90. return (long)cigcommercialBuilding.baseProfitCurrencies.GetValue("Cash");
  91. }
  92. }
  93. return 0L;
  94. }
  95. private const int CashPercentage = 80;
  96. private const int GoldHighChancePercentage = 19;
  97. private const int GoldHighChanceReward = 1;
  98. private const int GoldLowChanceReward = 5;
  99. [SerializeField]
  100. private Clickable _clickable;
  101. [SerializeField]
  102. private GridTile _tile;
  103. [SerializeField]
  104. private PlingManager _plingManager;
  105. [SerializeField]
  106. private CurrencyAnimationSource _currencyAnimationSource;
  107. private object _animationSourceObject = new object();
  108. }