|
- using System;
- using CIG;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using SUISSEngine;
- using UnityEngine;
-
- [RequireComponent(typeof(GridTile), typeof(Serializing), typeof(Clickable))]
- public class DropChest : MonoBehaviour
- {
- private void Awake()
- {
- this._currencyAnimationSource.Init(this._animationSourceObject);
- }
-
- private void OnDestroy()
- {
- if (this._clickable != null)
- {
- this._clickable.OnClickEvent -= this.Collect;
- }
- }
-
- public void Collect(GameObject target)
- {
- if (this.CanCollect() && SingletonMonobehaviour<CIGGameState>.IsAvailable)
- {
- decimal num = UnityEngine.Random.Range(this._minGoldReward, this._maxGoldReward);
- SingletonMonobehaviour<CIGGameState>.Instance.EarnCurrencies(new Currencies("Gold", num), this._animationSourceObject);
- Pling pling = this._plingManager.Show(PlingType.Gold, Vector3.zero, Clip.Ping);
- pling.Show(Localization.Integer(num));
- if (this._clickable != null)
- {
- this._clickable.OnClickEvent -= this.Collect;
- }
- IsometricIsland.GetParent(this).builder.DestroyTile(this._tile);
- }
- }
-
- private bool CanCollect()
- {
- if (!this._tile.grid.IsWithinBounds(this._tile.index))
- {
- return true;
- }
- GridElement gridElement = this._tile.grid[this._tile.index.u, this._tile.index.v];
- return gridElement.Type == -1 || gridElement.Unlocked;
- }
-
- private void OnDeserialized()
- {
- this._clickable.OnClickEvent += this.Collect;
- }
-
- private const string GoldRewardKey = "chestGoldReward";
-
- [SerializeField]
- private Clickable _clickable;
-
- [SerializeField]
- private GridTile _tile;
-
- [SerializeField]
- private int _minGoldReward;
-
- [SerializeField]
- private int _maxGoldReward;
-
- [SerializeField]
- private PlingManager _plingManager;
-
- [SerializeField]
- private CurrencyAnimationSource _currencyAnimationSource;
-
- private object _animationSourceObject = new object();
- }
|