|
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using CIG;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using SUISS.Core.Utilities;
- using SUISSEngine;
- using UnityEngine;
-
- [RequireComponent(typeof(GridTile), typeof(Serializing), typeof(Clickable))]
- public class FloatingChest : MonoBehaviour
- {
- //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event Action RewardCollectedEvent;
-
- private void FireRewardCollectedEvent()
- {
- if (this.RewardCollectedEvent != null)
- {
- this.RewardCollectedEvent();
- }
- }
-
- private void Start()
- {
- this._currencyAnimationSource.Init(this._animationSourceObject);
- this._clickable.OnClickEvent += this.Collect;
- }
-
- private void OnDestroy()
- {
- if (this._clickable != null)
- {
- this._clickable.OnClickEvent -= this.Collect;
- }
- }
-
- public void Collect(GameObject target)
- {
- if (SingletonMonobehaviour<CIGGameState>.IsAvailable)
- {
- int num = UnityEngine.Random.Range(1, 101);
- decimal num2;
- string currency;
- PlingType plingType;
- if (num <= 80)
- {
- num2 = this.CashCalucator();
- currency = "Cash";
- plingType = PlingType.Cash_Green;
- }
- else if (num - 80 <= 19)
- {
- num2 = 1m;
- currency = "Gold";
- plingType = PlingType.Gold;
- }
- else
- {
- num2 = 5m;
- currency = "Gold";
- plingType = PlingType.Gold;
- }
- SingletonMonobehaviour<CIGGameState>.Instance.EarnCurrencies(new Currencies(currency, num2), this._animationSourceObject);
- Pling pling = this._plingManager.Show(plingType, Vector3.zero, Clip.Ping);
- if (plingType == PlingType.Cash_Green)
- {
- pling.ShowWithParticles(Localization.Integer(num2), ParticleType.CashFountain);
- }
- else
- {
- pling.Show(Localization.Integer(num2));
- }
- if (this._clickable != null)
- {
- this._clickable.OnClickEvent -= this.Collect;
- }
- IsometricIsland.GetParent(this).builder.DestroyTile(this._tile);
- this.FireRewardCollectedEvent();
- }
- }
-
- private long CashCalucator()
- {
- List<CIGCommercialBuilding> list = new List<CIGCommercialBuilding>(SingletonMonobehaviour<GameObjectManager>.Instance.Commercial);
- int level = SingletonMonobehaviour<CIGGameState>.Instance.Level;
- int i;
- for (i = level; i > 0; i--)
- {
- List<CIGCommercialBuilding> list2 = list.FindAll((CIGCommercialBuilding x) => Array.Exists<int>(x.unlockLevels, (int y) => y == i) && x.baseProfitCurrencies.Contains("Cash"));
- if (list2.Count > 0)
- {
- CIGCommercialBuilding cigcommercialBuilding = list2.PickRandom<CIGCommercialBuilding>();
- return (long)cigcommercialBuilding.baseProfitCurrencies.GetValue("Cash");
- }
- }
- return 0L;
- }
-
- private const int CashPercentage = 80;
-
- private const int GoldHighChancePercentage = 19;
-
- private const int GoldHighChanceReward = 1;
-
- private const int GoldLowChanceReward = 5;
-
- [SerializeField]
- private Clickable _clickable;
-
- [SerializeField]
- private GridTile _tile;
-
- [SerializeField]
- private PlingManager _plingManager;
-
- [SerializeField]
- private CurrencyAnimationSource _currencyAnimationSource;
-
- private object _animationSourceObject = new object();
- }
|