using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using asap.core;
using cfg;
using DG.Tweening;
using game;
using GameCore;
using TMPro;
using UI.Wheel;
using UniRx;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.UI;
using UnityEngine.ResourceManagement.AsyncOperations;
using Random = UnityEngine.Random;
namespace EventBossFight
{
public partial class EventBossFightMainPanel : BasePanel
{
#region UI_ELEMENTS
private PlayableDirector _enterDirector;
//top
private RewardItemNew[] _bossReward;
private TMP_Text _textBossHp;
private Image _imgBossHpBar;
private GameObject _hpBossObj;
private RewardItemNew _bossRewardFinal;
private TMP_Text _textBossHpFinal;
private Image _imgBossHpBarFinal;
private GameObject _hpBossObjFinal;
private RewardItemNew _finalReward;
private TMP_Text _textTime;
private SandDigLevel[] _levels;
private Button _btnQuestionmark;
private GameObject _goBtnFightInfo;
private Button _btnFightInfo;
private TMP_Text _textBossAttackTime;
private TMP_Text _textBossAttackRange;
private GameObject _objTipsBoss;
//center
/// Boss 预制体父节点(仅挂载 Transform,不要求根上 )。
protected Transform _bossMount;
private PlayableDirector _playerDirector;
private EventBossFightTimelinePlayerCell _playerCell;
//bottom
private Button _btnAdd;
private Button _btnSpin;
private Button _btnClose;
private Button _btnMagnification;
private TMP_Text _textMagnification;
private GameObject _objMagnification;
private TMP_Text _textPlayerHp;
private TMP_Text _textPlayerChangeHp;
private RectTransform _iconHpTarget;
private Button _iconHpBtn;
private GameObject _tipsHp;
private Button _tipsHpBtnClose;
private Image _imgPlayerHpBar;
private Image[] _shields;
private Button[] _shieldBtns;
private GameObject _tipsShield;
private Button _tipsShieldBtnClose;
private TMP_Text _textSpin;
private TMP_Text _textTokenAmount;
private Image _imgTokenIcon;
private EventBossFightWheelRewardComponent _wheel;
private RewardFlyBatchController RewardFlyBatchCtrl;
/// 付费复活:与转盘区域互斥,预制体上需有名为 btn_revive 的节点。
private GameObject _goPaidReviveRoot;
private GameObject _goSpinButtonRoot;
private GameObject _goMagnificationRoot;
private Button _btnPaidRevive;
private TMP_Text _textPaidRevivePrice;
//UI effect
private Animation _shieldAddAni;
private Animation _hpAddAni;
private GameObject _tokenShieldGameObject;
private GameObject _tokenHpGameObject;
//private Animation _tokenAddAni;
#endregion UI_ELEMENTS
#region FX
private GameObject fx_eventbossfight_warning;
private GameObject fx_eventbossfight_wheel_shieldswitch;
private GameObject fx_eventbossfight_wheel_healswitch;
private GameObject fx_eventbossfight_wheel_heal_01;
private GameObject fx_eventbossfight_wheel_heal_02;
#endregion
#region SerializeField
[Header("UI Effect")]
[SerializeField] [Min(0)]private float delayShowFailPanelTime=0.5f;
[SerializeField] [Min(0)] private float sliderChangeTime = 0.3f;
[SerializeField] [Min(0)] private float hpTextChangeTime = 1f;
[SerializeField] [Min(0)] private float panelOutAniTime = 0.3f;
[SerializeField] [Min(1)] private float infoOutTime = 2f;
[SerializeField] [Min(1)]
[Tooltip("boss攻击倒计时小于等于这个时间 就显示这个特效")]
private int bossAttackWarningSeconds = 30;
[Header("scene crack effect")]
[SerializeField]private Vector2 minPositonOffset = Vector2.zero;
[SerializeField]private Vector2 maxPositonOffset = Vector2.zero;
#region player
[Header("play attack")]
[SerializeField] [Tooltip("开始从转盘结束开始算,时间结束开始播放boss受击动画")]
private float bossAttackedDelay1 = 0.5f;
[SerializeField][Tooltip("开始从转盘结束开始算,时间结束开始播放boss受击动画")]
private float bossAttackedDelay2 = 0.5f;
[SerializeField] [Tooltip("开始从转盘结束开始算,时间结束开始播放boss受击动画特效")]
private float bossAttackedFxDelay1 = 0.5f;
[SerializeField][Tooltip("开始从转盘结束开始算,时间结束开始播放boss受击动画特效")]
private float bossAttackedFxDelay2 = 0.5f;
[SerializeField] [Tooltip("开始从转盘结束开始算,时间结束开始播放boss血条动画")]
private float bossAttackedHpAniDelay1 = 0.5f;
[SerializeField][Tooltip("开始从转盘结束开始算,时间结束开始播放boss血条动画")]
private float bossAttackedHpAniDelay2 = 0.5f;
[SerializeField] protected float playAttackTier2Interval=0.5f;
[SerializeField][Min(1)] protected int playAttackTier2Count =1;
[SerializeField] [Tooltip("血条清空之后,延迟一个时间播boss死亡动画")]
private float bossDeathDelay = 0.5f;
[SerializeField][Tooltip("玩家攻击的震动数据,必须有3个")]
List playerShakeData;
[Header("shield")]
[SerializeField] private float shieldAddTime = 0.5f;
[SerializeField] [Tooltip("连续播盾牌飞入动画的间隔时间")]
private float shieldAddIntervalTime = 0.5f;
[SerializeField] [Tooltip("盾牌飞入动画delay一段时间之后 刷新显示")]
private float shieldDelayTime1 = 0.5f;
[SerializeField] [Tooltip("盾牌飞入到破碎位置delay一段时间之后 播碎裂动画")]
private float shieldDelayTime2= 0.5f;
[SerializeField] private GameObject shieldGameObject;
[SerializeField] private float shieldReduceTime;
[Header("hp")]
[SerializeField] private float hpAddTime = 0.5f;
[Header("token")]
[SerializeField] private float tokenAddTime = 0.5f;
[SerializeField] private GameObject hurt_fx_position;
#endregion
#endregion
private bool _isRotating;
private bool _isOpening=true;
private bool _isBossDeath;
private bool _isPlayerDeath;
private readonly int _showRewardCount = 4;
private EventBossFightStage _stageConfigWithUI ;
private EventBossFightRectFollowerGraphic _eventRectFollowerGraphic;
protected IEventBossFightBossCell _bossCell;
private List _wheelRewards;
private EventBossFightManager _manager;
private EventBossFightManager Manager => _manager ??= GContext.container.Resolve();
protected EventBossFightData Data => Manager?.Data;
private GameObject[] _sceneCrackFxs=new GameObject[5];
private AsyncOperationHandle _bossInstantiateHandle;
protected virtual void Awake()
{
//fx
fx_eventbossfight_warning=gameObject.FindChildGameObject("fx_eventbossfight_warning");
fx_eventbossfight_wheel_shieldswitch=gameObject.FindChildGameObject("fx_eventbossfight_wheel_shieldswitch");
fx_eventbossfight_wheel_healswitch=gameObject.FindChildGameObject("fx_eventbossfight_wheel_healswitch");
fx_eventbossfight_wheel_heal_01=gameObject.FindChildGameObject("fx_eventbossfight_wheel_heal_01");
fx_eventbossfight_wheel_heal_02=gameObject.FindChildGameObject("fx_eventbossfight_wheel_heal_02");
for (int i = 0; i < 4; i++)
{
var obj = gameObject.FindChildGameObject($"fx_eventbossfight_submarine_attacked0{i+1}");
if (!obj) continue;
obj.SetActive(false);
_sceneCrackFxs[i]=obj;
}
_enterDirector=gameObject.FindChildGameObject("root").GetComponent();
//top
_finalReward = gameObject.FindChildGameObject("p_final_reward").GetComponentInChildren();
_textTime = gameObject.FindChildGameObject("p_text_event_time").GetComponent();
_bossReward = gameObject.FindChildGameObject("p_boss_reward").GetComponentsInChildren();
_textBossHp = gameObject.FindChildGameObject("p_text_bossHp").GetComponent();
_imgBossHpBar=gameObject.FindChildGameObject("p_img_boss_hp_bar").GetComponent();
_bossRewardFinal=gameObject.FindChildGameObject("p_boss_reward_final").GetComponent();
_textBossHpFinal = gameObject.FindChildGameObject("p_text_bossHp_final").GetComponent();
_imgBossHpBarFinal=gameObject.FindChildGameObject("p_img_boss_hp_bar_final").GetComponent();
_hpBossObj = gameObject.FindChildGameObject("hp_boss");
_hpBossObjFinal = gameObject.FindChildGameObject("hp_boss_final");
_levels = gameObject.FindChildGameObject("level").GetComponentsInChildren();
_btnQuestionmark = gameObject.FindChildGameObject("p_btn_questionmark").GetComponentInChildren