using System; using System.Collections.Generic; using asap.core; using cfg; using GameCore; using TMPro; using UnityEngine; using UnityEngine.UI; public class EventPartnerMultiplierController : MonoBehaviour { [SerializeField] private TMP_Text _textMultiplier, _textMultiplierMax; [SerializeField] private Button _btnMultiplier; [SerializeField] private GameObject _goNormal, _goMax; [SerializeField] private Animator btnAnimation; private int _idx, _redirectId, largeIdx; private Tables _tables; private List _multiplierList; private PlayerItemData _playerItemData; private IEventAggregator _eventAggregator; public int Multiplier => _multiplierList[_idx]; private void Awake() { _btnMultiplier.onClick.AddListener(CycleMultiplierToNext); } // Start is called before the first frame update public void Init(int redirectId, IEventAggregator eventAggregator) { // Debug.Log("Btn init:"); // Debug.Log(eventAggregator.GetHashCode()); _tables = GContext.container.Resolve(); _redirectId = redirectId; _playerItemData = GContext.container.Resolve(); _multiplierList = _tables.TbEventPartnerMain[_redirectId].SpinMag; SwitchToNextMax(); _eventAggregator = eventAggregator; } [SerializeField] private float btnReactTime = 0.05f; public async void CycleMultiplierToNext() { _idx++; int currentMaxMultiplier = GetCurrentMaxMultiplier(); btnAnimation.Play("Pressed"); ToggleMultiplierButtonFunction(false); if (_idx >= _multiplierList.Count || Multiplier > currentMaxMultiplier) { _idx = 0; ToggleButtons(largeIdx != 0); } else if (Multiplier == currentMaxMultiplier) { ToggleButtons(false); } else { ToggleButtons(true); } _eventAggregator.Publish(new EventPartnerMultiplierChange()); await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(btnReactTime)); btnAnimation.Play("Normal"); ToggleMultiplierButtonFunction(true); } public void ToggleMultiplierButtonFunction(bool doEnable) { _btnMultiplier.enabled = doEnable; } public void SwitchToNextMax() { GetCurrentMaxMultiplier(); _idx = largeIdx; _textMultiplier.text = $"x{_multiplierList[_idx]}"; _textMultiplierMax.text = $"x{_multiplierList[_idx]}"; ToggleMultiplierButtonFunction(true); _goNormal.SetActive(false); _goMax.SetActive(true); } private int GetCurrentMaxMultiplier() { int ans = _multiplierList[0]; largeIdx = 0; for (int i = 0; i < _multiplierList.Count; i++ ) if (_multiplierList[i] * _tables.TbEventPartnerMain[_redirectId].SpinRequire <= GContext.container.Resolve().TicketCount) { ans = _multiplierList[i]; largeIdx = i; } // Debug.Log($"Multiplier: {ans}"); return ans; } private void ToggleButtons(bool doShowNormal) { if (doShowNormal) { _goNormal.SetActive(true); _goMax.SetActive(false); _textMultiplier.text = $"x{Multiplier}"; } else { _goNormal.SetActive(false); _goMax.SetActive(true); _textMultiplierMax.text = $"x{Multiplier}"; } } } public struct EventPartnerMultiplierChange { }