using System.Collections.Generic;
using CombatLibrary.CombatLibrary.CombatCore.CustomizeTimeLogic.FxLogic;
using Common.Combat.FxAILogic;
using GameLogic.Combat.Buff;
using GameLogic.Combat.CombatTool;
using GameLogic.Combat.Hero;
using UnityEngine;
using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
namespace GameLogic.Combat.Skill
{
    /// 
    /// 引雷
    /// 请求仰天施法,引导天雷,天雷在战场上随机落下,{0}%概率击中目标,每层感电额外+{1}%概率
    /// ,最多被击中{2}次,每次击中消耗一层感电额外照成{3}伤害。引雷可以击中弹道.持续{4}秒
    /// 
    public class S9053 : SkillBasic
    {
        private float _currTime;
        private int _hitCount;
        private bool _isUpdate;
        private float _jianGe;
        private float _allTime;
        protected override void ProUseSkill()
        {
            _hitCount = 0;
            ballisticsCount = (int)effectValue[0];
            ActivationTimeLineData("9053");
            _isUpdate = true;
            _allTime = 0;
        }
        protected override void ProDefaultTimeLineTrigger(string groupName, CombatHeroHitPoint targetEntity,
            ITimelineFxLogic timelineFxLogic,
            TriggerData triggerData, ISkillFeatures skillFeatures)
        {
        }
        private void SetJianGe()
        {
            _jianGe = CombatCalculateTool.Instance.GetOdd(20, 100) / 100f;
        }
        protected override void ProCombatUpdate(float time)
        {
            if (!_isUpdate)
            {
                return;
            }
            _currTime += time;
            _allTime += time;
            if (_allTime > effectValue[5])
            {
                _isUpdate = false;
                return;
            }
            if (_currTime >= _jianGe)
            {
                _currTime = 0;
                SetJianGe();
                Vector3 targetPos = Vector3.zero;
                //发射一道闪电
                int odds = CombatCalculateTool.Instance.GetOdd(0, 100);
                CombatHeroEntity combatHeroEntity = CombatHeroEntity.CombatAIBasic.currFocusTarget;
                if (combatHeroEntity == null || combatHeroEntity.BuffControl == null)
                {
                    return;
                }
                b_1018 b1018 = combatHeroEntity.BuffControl.GetBuffBasicForType();
                float addOdds = b1018 != null ? b1018.buffCount * effectValue[1] : 0;
                if (_hitCount();
                    if (b1018 != null) //消耗一层感电,额外照成伤害
                    {
                        b1018.ReduceCount(1);
                        harmBl += effectValue[4];
                    }
                    long v = CombatCalculateTool.Instance.GetVlaueRatioForLong(
                        CombatHeroEntity.CurrCombatHeroInfo.attack.Value,
                        harmBl);
                    HarmReturnInfo harmReturnInfo = CombatCalculateTool.Instance.Harm(CombatHeroEntity,
                        combatHeroEntity, v,
                        AttType.Skill, triggerData,
                        wuXingType, null,
                        HarmType.Default);
                }
                else
                {
                    List allFxAi =
                        CombatController.currActiveCombat.GameTimeLineParticleFactory.GetFxAILogicBasic(
                            !CombatHeroEntity
                                .IsEnemy);
                    if (allFxAi.Count > 0)
                    {
                        int index = Random.Range(0, allFxAi.Count);
                        FxAILogicBasic fxAILogicBasic = allFxAi[index];
                        targetPos = fxAILogicBasic.gameObject.transform.position;
                        FxParabolaBulletLogic fxParabolaBulletLogic = fxAILogicBasic as FxParabolaBulletLogic;
                        if (fxParabolaBulletLogic != null)
                        {
                            fxParabolaBulletLogic.PengZhuang(GetSkillFeaturesData(), CombatHeroEntity);
                        }
                    }
                    else
                    {
                        int x = Random.Range(-10, 10);
                        int z = Random.Range(4, 10);
                        targetPos = CombatHeroEntity.GameObject.transform.TransformPoint(new Vector3(x, 0, z));
                    }
                }
                ActivationTimeLineData("9053_fashe", customizePos: new Vector3[] { targetPos });
            }
        }
    }
}