using System; using System.Collections.Generic; using asap.core; using cfg; using game; using GameCore; using Script.RuntimeScript; using Script.RuntimeScript.model.Data; using UniRx; using UnityEngine; public partial class EventSandDigPanelLogic : BasePanel { private int ShowRewardCount = 5; private List _clampRewards = new List(); private DiggingGameManager _manager; private SandDigServerData _serverData; private CompositeDisposable _disposable = new CompositeDisposable(); private Timer _timer; private RewardItemNew _flyRewardEffect; protected override void Start() { base.Start(); AddEvent(); GContext.container.Resolve().InspectTriggerGuide("EventSandDigPanel"); ShowRewardCount = levels.Length; _clampRewards.Add(_reward1); _clampRewards.Add(_reward2); _clampRewards.Add(_reward3); _clampRewards.Add(_reward4); _flyRewardEffect = _flyReward.GetComponent(); _flyReward.gameObject.SetActive(false); _close.onClick.AddListener(OnCloseBtn); _confirm.onClick.AddListener(OnCloseBtn); _questionmark.onClick.AddListener(OnHelpBtn); _btn_add.onClick.AddListener(OnClickBtnPack); _manager = GContext.container.Resolve(); _serverData = _manager.DataModel.GetServerData(); UpdateReward(); UpdateView(); ShowTime(); ShowInfo(); } async void ShowInfo() { bool isShowInfo = _manager.NewInfo(); if (isShowInfo) { await UIManager.Instance.ShowUI(UITypes.EventSandDigInfoPopupPanel); } } public void AddEvent() { GContext.OnEvent().Subscribe(OnPassClamp).AddTo(_disposable); GContext.OnEvent().Subscribe(OnUpdateDigCount).AddTo(_disposable); GContext.OnEvent().Subscribe(OnFlyReward).AddTo(_disposable); GContext.OnEvent().Subscribe(OnCloseAwardPanel).AddTo(_disposable); } private void OnCloseAwardPanel(EndTransition data) { UpdateReward(); } public void ClearEvent() { _disposable.Dispose(); } private void OnHelpBtn() { UIManager.Instance.ShowUI(UITypes.EventSandDigInfoPopupPanel); } private void OnCloseBtn() { DiggingGameManager diggingGameManager = GContext.container.Resolve(); if (!diggingGameManager.IsCanClick) { return; } if (diggingGameManager.GameState != SandDigGameState.Going && diggingGameManager.GameState != SandDigGameState.Normal) { return; } diggingGameManager.GameState = SandDigGameState.Normal; diggingGameManager.BroadLogic?.ClearEvent(); ClearEvent(); UIManager.Instance.DestroyUI(UITypes.EventSandDigPanel); GContext.Publish(new UnloadActToNextAct()); } private void OnPassClamp(EventSandDigNewClamp obj) { GContext.Publish(new ShowData()); UpdateView(); } private void UpdateView() { UpdateDigCount(); DiggingGameManager diggingGameManager = GContext.container.Resolve(); int propId = diggingGameManager.GetActivityPropId(); if (propId > 0) { cfg.Item item = GContext.container.Resolve().GetItemData(propId); GContext.container.Resolve().SetImageSprite(_ticket, item.Icon, PanelName); } } private void OnUpdateDigCount(EventSandDigPropUpdate data) { UpdateDigCount(); } private async void OnFlyReward(EventSandDigAddItem item) { ItemData itemDataNew = new ItemData(); itemDataNew.id = item.Id; itemDataNew.count = item.Count; _flyReward.transform.position = item.Pos; _flyReward.gameObject.SetActive(true); _flyRewardEffect.SetRewardPopupData(itemDataNew, false); await _flyRewardEffect.PlayClose(); await _flyRewardEffect.ParticleAttractor(); _flyReward.gameObject.SetActive(false); } private void UpdateDigCount() { int digCount = _manager.DataModel.GetDigCount(); if (digCount <= 0) { _num.text = $"0"; } else { _num.text = ConvertTools.GetNumberString(_manager.DataModel.GetDigCount()); } } private void UpdateReward() { int clampCount = _manager.DataModel.MaxCount; int curIndex = _serverData.Index % clampCount; DiggingGameManager.LogError("总管卡数量:" + clampCount); int startIndex; int offseIndex = clampCount - ShowRewardCount; if (curIndex <= 1) { startIndex = 0; } else if (curIndex > offseIndex) { startIndex = offseIndex; } else { startIndex = curIndex - 1; } DiggingStageReward clampConfig; for (int i = 0; i < ShowRewardCount - 1; i++) { int index = startIndex + i; if (index >= clampCount) { break; } int state = 0; if (index < curIndex) { state = 2; } else if (index == curIndex) { state = 1; } levels[i].SetState(state); levels[i].SetTextNum($"{index + 1}"); } levels[ShowRewardCount - 1].SetTextNum($"{clampCount}"); int clampId = _serverData.ClampId; clampConfig = GContext.container.Resolve().TbDiggingStageReward.Get(clampId); if (clampConfig != null) { List itemData = GContext.container.Resolve().GetItemDataByDropIdLureInflation(_manager.DataModel.InflationRate, clampConfig.DropID); int itemCount = itemData.Count; for (int i = 0; i < _clampRewards.Count; i++) { if (i < itemCount) { _clampRewards[i].SetData(itemData[i]); } else { _clampRewards[i].gameObject.SetActive(false); } } } else { DiggingGameManager.LogError("沙滩寻宝 管卡奖励配置错误"); } _reward_final.InflationRate = _manager.DataModel.InflationRate; _reward_final.SetDropIcon("", _manager.DataModel.digActivityConfig.Reward); } private void ShowTime() { //显示倒计时 if (_timer == null) { int activityId = _manager.GetActivityId(); if (activityId <= 0) { _time.text = string.Empty; return; } DateTime endTime = GContext.container.Resolve().GetEventEndTime(activityId); TimeSpan now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset(); double seconds = now.TotalSeconds; _timer = this.AttachTimer((float)seconds, OnTimeEnd, (elapsed) => { now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset(); _time.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_end", ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds)); }, useRealTime: true); } } void OnTimeEnd() { DiggingGameManager diggingGameManager = GContext.container.Resolve(); diggingGameManager.GameState = SandDigGameState.Normal; diggingGameManager.BroadLogic?.ClearEvent(); ClearEvent(); UIManager.Instance.DestroyUI(UITypes.EventSandDigPanel); GContext.Publish(new UnloadActToNextAct()); } #region NeoNormalPack public void OnClickBtnPack() { GContext.container.Resolve().OnClickBtnPack(); } #endregion }