using CombatLibrary.CombatLibrary.CombatCore.CustomizeTimeLogic.FxLogic;
using Common.Utility.CombatEvent;
using Core.Utility;
using Fort23.Core;
using GameLogic.Combat.CombatTool;
using GameLogic.Combat.Hero;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
using UnityEngine;
using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
namespace GameLogic.Combat.Skill
{
    /// 
    /// 木灵分身
    /// 生命低于{0}%时触发,木灵的根须快速在自身周围生出2个木灵之子,木灵之子之有普通攻击,木灵之子拥有boss的{1}最大生命值的生命
    ///(等级跟随boss的等级走)
    /// 
    public class S9062 : SkillBasic
    {
        private bool _isTrigger;
        private Vector3[] pos;
        // private Vector3 pos2;
        protected override void ProUseSkill()
        {
            ActivationTimeLineData("9062");
            Vector3 pos1 = CombatHeroEntity.GameObject.transform.TransformPoint(new Vector3(3, 0, 3));
            Vector3 pos2 = CombatHeroEntity.GameObject.transform.TransformPoint(new Vector3(-3, 0, 3));
            if (pos == null)
            {
                pos = new Vector3[2];
            }
            pos[0] = pos1;
            pos[1] = pos2;
            ActivationTimeLineData("9062_fashe", customizePos: new Vector3[] { pos1 });
            ActivationTimeLineData("9062_fashe", customizePos: new Vector3[] { pos2 });
        }
        protected override void ProActiveSkill()
        {
            CombatEventManager.Instance.AddEventListener(CombatEventType.HeroInjured, HeroInjured);
        }
        protected override void ProDispose()
        {
            CombatEventManager.Instance.RemoveEventListener(CombatEventType.HeroInjured, HeroInjured);
        }
        private void HeroInjured(IEventData data)
        {
            if (_isTrigger)
            {
                return;
            }
            HeroInjuredEventData heroInjuredEventData = data as HeroInjuredEventData;
            if (heroInjuredEventData.HarmReturnInfo.target.combatHeroEntity == CombatHeroEntity)
            {
                if (CombatHeroEntity.HpBl < effectValue[0])
                {
                    _isTrigger = true;
                    CombatHeroEntity.CombatHeroSkillControl.This().AddCommandSkill(this);
                    // ZhaoHuan();
                }
            }
        }
        private void ZhaoHuan()
        {
            for (int i = 0; i < 2; i++)
            {
                CombatHeroEntity heroEntity = new CombatHeroEntity();
                heroEntity.IsEnemy = true;
                CombatHeroInfo combatHeroInfo = new CombatHeroInfo();
                combatHeroInfo.InitMonster(1005, CombatHeroEntity.CurrCombatHeroInfo.level.Value);
                combatHeroInfo.hp =(EncryptionLong)
                    CombatCalculateTool.Instance.GetVlaueRatioForLong(CombatHeroEntity.MaxCombatHeroInfo.hp.Value,
                        effectValue[1]);
                CombatController.currActiveCombat.CombatHeroController.SummonHero(combatHeroInfo, CombatHeroEntity,
                    pos[i], -1, null);
            }
            S9061 s9061 = CombatHeroEntity.CombatHeroSkillControl.GetSkillBasic();
            if (s9061 != null)
            {
                CombatHeroEntity.CombatHeroSkillControl.This().AddCommandSkill(s9061);
            }
        }
        
        protected override void ProDefaultTimeLineTrigger(string groupName, CombatHeroHitPoint targetEntity,
            ITimelineFxLogic timelineFxLogic,
            TriggerData triggerData, ISkillFeatures skillFeatures)
        {
            ZhaoHuan();
            // float harmBl = 0;
            // b_1018 b1018 = targetEntity.combatHeroEntity.BuffControl.GetBuffBasicForType();
            // if (b1018 != null) //消耗一层感电,额外照成伤害
            // {
            //     harmBl += b1018.buffCount * effectValue[1];
            // }
            //
            // long v = CombatCalculateTool.Instance.GetVlaueRatioForLong(CombatHeroEntity.CurrCombatHeroInfo.attack.Value,
            //     harmBl);
            //
            // HarmReturnInfo harmReturnInfo = CombatCalculateTool.Instance.Harm(CombatHeroEntity, targetEntity, v,
            //     AttType.Skill, triggerData,
            //     wuXingType, skillFeatures,
            //     HarmType.Default);
        }
    }
}