123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- using System.Collections;
- using System.Collections.Generic;
- using Animancer;
- using Common.Utility.CombatEvent;
- using Core.Utility;
- using Fort23.Common;
- using Fort23.Core;
- using Fort23.UTool;
- using GameLogic.Combat.Buff;
- using GameLogic.Combat.CombatTool;
- using GameLogic.Combat.Hero;
- using GameLogic.Combat.Hero.HeroGPU;
- using GameLogic.Player;
- using UnityEngine;
- using UnityEngine.AI;
- using UnityEngine.Rendering;
- using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
- public class CombatHeroEntity : ShowBaiscEntity, ITimeLineAnimtion, ITimeLineGetAttSpeed,
- IHero
- {
- /// <summary>
- /// 死亡时的节点ID
- /// </summary>
- public int heroDieNodeId;
- public bool isPlayer;
- public string guidName
- {
- get { return CurrCombatHeroInfo.modelName; }
- }
- public bool isFollowState;
- private float _lasetShowHarmTime;
- private float _injuriedShowTime;
- private bool _isAddinjuriedShow;
- private float _addInjuiedValue = (1.0f / 0.2f) * 0.3f;
- private bool _isDis;
- public float DisTime;
- public MagicWeaponControl MagicWeaponControl;
- public float HpBl
- {
- get { return CurrCombatHeroInfo.hp.Value * 100f / MaxCombatHeroInfo.hp.Value; }
- }
- public Vector3 dotPos
- {
- get { return combatHeroGameObject.position; }
- }
- public T GetThis<T>() where T : IHero
- {
- return (T)(object)this;
- }
- public GameObject GameObject
- {
- get { return combatHeroGameObject.transform.gameObject; }
- }
- public Vector3 faceDir
- {
- get { return combatHeroGameObject.transform.forward; }
- }
- public virtual async CTask<CombatHeroEntity> Init(CombatAIBasic combatAIBasic, CombatHeroInfo combatHeroInfo,
- Vector3 pos,
- System.Action<CombatHeroEntity> callBack = null,bool isPlayer=false)
- {
- //后面记到检查战斗里面不要出现异步加载,也不要出现同步IO加载
- this.isPlayer = isPlayer;
- string modelName = combatHeroInfo.modelName;
- if (combatHeroInfo.isGpu)
- {
- modelName += "_gpu";
- }
- CurrCombatHeroInfo = combatHeroInfo.Copy();
- MaxCombatHeroInfo = combatHeroInfo.Copy();
- // GameTimeLineParticleFactory
- CombatHeroGameObjectPool poolInterface =
- await GObjectPool.Instance.FetchAsync<CombatHeroGameObjectPool>(modelName + ".prefab", null);
- #if !COMBAT_SERVER
- if (poolInterface == null || poolInterface.own == null)
- {
- return null;
- }
- poolInterface.own.transform.position = pos;
- // if (!IsEnemy)
- // {
- // GameObjectPool fx_hero_quan =
- // await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_hero_quan.prefab", null);
- // fx_hero_quan.own.transform.SetParent(poolInterface.own.transform);
- // fx_hero_quan.own.transform.localPosition = Vector3.zero;
- // }
- poolInterface.own.SetActive(false);
- MagicWeaponControl = new MagicWeaponControl();
- combatHeroTimeLineControl = new CombatHeroTimeLineControl();
- combatHeroTimeLineControl.Init(this);
- AssetHandle assetHandle =
- await AssetBundleLoadManager.Instance.LoadAssetAsyncTask<TextAsset>(combatHeroInfo.modelName + "_TD.txt");
- if (assetHandle != null)
- {
- TextAsset textAsset = assetHandle.AssetObject<TextAsset>();
- TimeLienData timeLienData = JsonManager.FromJson<TimeLienData>(textAsset.text);
- timeLienData.DeserializeData();
- assetHandle.Release();
- combatHeroTimeLineControl.AddTimeLienData(timeLienData);
- }
- combatHeroGameObject = new CombatHeroGameObject();
- combatHeroGameObject.Init(this, poolInterface);
- BuffControl = new BuffControl();
- BuffControl.Init(this);
- NavMeshAgent navMeshAgent = poolInterface.own.GetComponent<NavMeshAgent>();
- if (combatAIBasic == null)
- {
- combatAIBasic = new CombatAIBasic();
- }
- HeroEntityMono heroEntityMono = poolInterface.own.GetComponent<HeroEntityMono>();
- if (heroEntityMono == null)
- {
- heroEntityMono = poolInterface.own.AddComponent<HeroEntityMono>();
- }
- heroEntityMono.combatHeroEntity = this;
- CombatAIBasic = combatAIBasic;
- CombatAIBasic.Init(this);
- CombatHeroSkillControl = new CombatHeroSkillControl();
- await CombatHeroSkillControl.Init(this);
- CurrCombatHeroInfo.Shield = (EncryptionLong)300;
- await InitShieldsFx();
- AnimancerComponent animancerComponent = poolInterface.own.GetComponent<AnimancerComponent>();
- combatHeroAnimtion = new CombatHeroAnimtion();
- // if (animancerComponent != null)
- {
- }
- // else
- // {
- // combatHeroAnimtion = new CombatHeroGPUAnimtion();
- // }
- poolInterface.own.SetActive(true);
- combatHeroAnimtion.Init(this);
- CombatAIBasic.ChangeState(CombatHeroStateType.XiuMian);
- if (IsEnemy )
- {
- CreateHeroHpEventData createHeroHpEventData = CreateHeroHpEventData.Create();
- createHeroHpEventData.combatHeroEntity = this;
- EventManager.Instance.Dispatch(CustomEventType.CreateHeroHp, createHeroHpEventData);
- }
- await MagicWeaponControl.InitMagicWeapon(this,isPlayer);
- callBack?.Invoke(this);
- #endif
- return this;
- }
- public virtual void Update(float t)
- {
- CombatAIBasic.Update(t);
- CombatHeroSkillControl.Update(t);
- combatHeroTimeLineControl.Update(t);
- combatHeroAnimtion.Update(t);
- combatHeroGameObject.Update(t);
- BuffControl.Update(t);
- MagicWeaponControl?.Update(t);
- if (combatHeroGameObject.HeroGPUMono != null)
- {
- if (_injuriedShowTime > 0)
- {
- _injuriedShowTime -= t;
- if (_isAddinjuriedShow)
- {
- combatHeroGameObject.HeroGPUMono.injuriedStrength += t * (_addInjuiedValue);
- if (combatHeroGameObject.HeroGPUMono.injuriedStrength >= 0.3f)
- {
- _isAddinjuriedShow = false;
- }
- }
- else
- {
- combatHeroGameObject.HeroGPUMono.injuriedStrength -= t * (_addInjuiedValue);
- if (combatHeroGameObject.HeroGPUMono.injuriedStrength < 0)
- {
- combatHeroGameObject.HeroGPUMono.injuriedStrength = 0;
- }
- }
- }
- else
- {
- combatHeroGameObject.HeroGPUMono.injuriedStrength = 0;
- }
- }
- }
- public T This<T>()
- {
- return (T)(object)this;
- }
- public override T GetILifetCycleHitPoint<T>(string hitPoinName, bool isStandType, bool isIgnoreHind)
- {
- return combatHeroGameObject.GetILifetCycleHitPoint<T>(hitPoinName, isStandType, isIgnoreHind);
- }
- public override T GetMainHotPoin<T>(bool isIgnoreHind = false)
- {
- return combatHeroGameObject.GetMainHotPoin<T>(isIgnoreHind);
- }
- public void PlayAnim(string animName, bool isLoop, int layerId, bool repeat, float speed)
- {
- combatHeroAnimtion.Play(animName, speed);
- }
- public SpecialDotInfo GetSpecialDotInfo(string specialDotName)
- {
- return combatHeroGameObject.GetMainHotPoin<CombatHeroHitPoint>(true).GetSpecialDotInfo(specialDotName);
- }
- public virtual float GetAttSpeed()
- {
- CombatHeroSkillControl combatHeroSkillControl = CombatHeroSkillControl as CombatHeroSkillControl;
- if (combatHeroSkillControl != null)
- {
- if (combatHeroSkillControl.useSkillCount > 1)
- {
- return 4;
- }
- return CurrCombatHeroInfo.attSpeed.Value;
- }
- return 1;
- }
- public void HeroResurrection()
- {
- isDie = false;
- CombatAIBasic.ChangeState(CombatHeroStateType.idle, isQiangZhi: true);
- HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create();
- heroHpUpdateEventData.combatHeroEntity = this;
- CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData);
- HeroResurrectionEventData heroResurrectionEventData = HeroResurrectionEventData.Create();
- heroResurrectionEventData.combatHeroEntity = this;
- CombatEventManager.Instance.Dispatch(CombatEventType.HeroResurrection, heroResurrectionEventData);
- }
- public void HeroDie(HarmReturnInfo harmReturnInfo)
- {
- heroDieNodeId = CombatController.currActiveCombat.CombatTypeBasic.allWinNodeCount;
- isDie = true;
- HeroDieEventData heroDieEventData = HeroDieEventData.Create();
- heroDieEventData.combatHeroEntity = this;
- heroDieEventData.HarmReturnInfo = harmReturnInfo;
- CombatEventManager.Instance.Dispatch(CombatEventType.HeroDie, heroDieEventData);
- combatHeroGameObject.HeroDie();
- CombatAIBasic.ChangeState(CombatHeroStateType.dile);
- CombatEventManager.Instance.Dispatch(CombatEventType.HeroDieFinish, heroDieEventData);
- }
- public void HeroHurt(HarmReturnInfo harmReturnInfo)
- {
- if (isDie)
- {
- return;
- }
- ShieldsBarrier shieldsBarrier= harmReturnInfo.triggerData.IBarrier as ShieldsBarrier;
- if (shieldsBarrier!=null)
- {
- shieldsBarrier.Harm(harmReturnInfo);
-
- }
- else
- {
- CurrCombatHeroInfo.hp -= harmReturnInfo.att;
- }
- UpdateHarmText(harmReturnInfo);
- if (combatHeroGameObject.HeroGPUMono != null)
- {
- _injuriedShowTime = 0.4f;
- combatHeroGameObject.HeroGPUMono.injuriedStrength = 0;
- _isAddinjuriedShow = true;
- }
- HeroInjuredEventData heroInjured = HeroInjuredEventData.Create();
- heroInjured.HarmReturnInfo = harmReturnInfo;
- CombatEventManager.Instance.Dispatch(CombatEventType.HeroInjured, heroInjured);
-
- HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create();
- heroHpUpdateEventData.combatHeroEntity = this;
- CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData);
- if (CurrCombatHeroInfo.hp <= 0)
- {
- HeroDie(harmReturnInfo);
- }
- }
- private void UpdateHarmText(HarmReturnInfo harmReturnInfo)
- {
- float currTime = Time.time;
- if (currTime - _lasetShowHarmTime < 0.1f)
- {
- return;
- }
- _lasetShowHarmTime = currTime;
- HarmUpdateEventData harmUpdateEventData = HarmUpdateEventData.Create();
- harmUpdateEventData.HarmReturnInfo = harmReturnInfo;
- CombatEventManager.Instance.Dispatch(CombatEventType.HarmUpdate, harmUpdateEventData);
- }
- public void Recover(HarmReturnInfo harmReturnInfo)
- {
- CurrCombatHeroInfo.hp += harmReturnInfo.att;
- HarmUpdateEventData harmUpdateEventData = HarmUpdateEventData.Create();
- harmUpdateEventData.HarmReturnInfo = harmReturnInfo;
- CombatEventManager.Instance.Dispatch(CombatEventType.RecoverUpdate, harmUpdateEventData);
- HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create();
- heroHpUpdateEventData.combatHeroEntity = this;
- CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData);
- }
- public void CloseLoopFx()
- {
- for (int i = 0; i < heroLoopParticle.Count; i++)
- {
- GObjectPool.Instance.Recycle(heroLoopParticle[i]);
- }
- heroLoopParticle.Clear();
- }
- public void Dispose()
- {
- if (_isDis)
- {
- return;
- }
- _isDis = true;
- combatHeroGameObject.Dispose();
- isDie = true;
- CombatHeroSkillControl.Dispose();
- CombatAIBasic.Dispose();
- combatHeroTimeLineControl.Dispose();
- combatHeroAnimtion.Dispose();
- CloseLoopFx();
- ShieldsBarrier?.Dispose();
- ShieldsBarrier = null;
- }
- private void ProDormancyObj()
- {
- CombatHeroSkillControl.ProDormancyObj();
- }
- public override void ActiveObj()
- {
- isDie = false;
- _isDis = false;
- }
- public override void DormancyObj()
- {
- Dispose();
- ProDormancyObj();
- _isDis = false;
- CombatAIBasic = null;
- combatHeroGameObject = null;
- CurrCombatHeroInfo = null;
- MaxCombatHeroInfo = null;
- combatHeroTimeLineControl = null;
- combatHeroAnimtion = null;
- CombatHeroSkillControl = null;
- isFollowState = false;
- heroLoopParticle.Clear();
- isDie = true;
- }
- }
|