CombatHeroEntity.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Animancer;
  4. using Common.Utility.CombatEvent;
  5. using Core.Utility;
  6. using Fort23.Common;
  7. using Fort23.Core;
  8. using Fort23.UTool;
  9. using GameLogic.Combat.Buff;
  10. using GameLogic.Combat.CombatTool;
  11. using GameLogic.Combat.Hero;
  12. using GameLogic.Combat.Hero.HeroGPU;
  13. using GameLogic.Player;
  14. using UnityEngine;
  15. using UnityEngine.AI;
  16. using UnityEngine.Rendering;
  17. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  18. public class CombatHeroEntity : ShowBaiscEntity, ITimeLineAnimtion, ITimeLineGetAttSpeed,
  19. IHero
  20. {
  21. /// <summary>
  22. /// 死亡时的节点ID
  23. /// </summary>
  24. public int heroDieNodeId;
  25. public bool isPlayer;
  26. public string guidName
  27. {
  28. get { return CurrCombatHeroInfo.modelName; }
  29. }
  30. public bool isFollowState;
  31. private float _lasetShowHarmTime;
  32. private float _injuriedShowTime;
  33. private bool _isAddinjuriedShow;
  34. private float _addInjuiedValue = (1.0f / 0.2f) * 0.3f;
  35. private bool _isDis;
  36. public float DisTime;
  37. public MagicWeaponControl MagicWeaponControl;
  38. public float HpBl
  39. {
  40. get { return CurrCombatHeroInfo.hp.Value * 100f / MaxCombatHeroInfo.hp.Value; }
  41. }
  42. public Vector3 dotPos
  43. {
  44. get { return combatHeroGameObject.position; }
  45. }
  46. public T GetThis<T>() where T : IHero
  47. {
  48. return (T)(object)this;
  49. }
  50. public GameObject GameObject
  51. {
  52. get { return combatHeroGameObject.transform.gameObject; }
  53. }
  54. public Vector3 faceDir
  55. {
  56. get { return combatHeroGameObject.transform.forward; }
  57. }
  58. public virtual async CTask<CombatHeroEntity> Init(CombatAIBasic combatAIBasic, CombatHeroInfo combatHeroInfo,
  59. Vector3 pos,
  60. System.Action<CombatHeroEntity> callBack = null,bool isPlayer=false)
  61. {
  62. //后面记到检查战斗里面不要出现异步加载,也不要出现同步IO加载
  63. this.isPlayer = isPlayer;
  64. string modelName = combatHeroInfo.modelName;
  65. if (combatHeroInfo.isGpu)
  66. {
  67. modelName += "_gpu";
  68. }
  69. CurrCombatHeroInfo = combatHeroInfo.Copy();
  70. MaxCombatHeroInfo = combatHeroInfo.Copy();
  71. // GameTimeLineParticleFactory
  72. CombatHeroGameObjectPool poolInterface =
  73. await GObjectPool.Instance.FetchAsync<CombatHeroGameObjectPool>(modelName + ".prefab", null);
  74. #if !COMBAT_SERVER
  75. if (poolInterface == null || poolInterface.own == null)
  76. {
  77. return null;
  78. }
  79. poolInterface.own.transform.position = pos;
  80. // if (!IsEnemy)
  81. // {
  82. // GameObjectPool fx_hero_quan =
  83. // await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_hero_quan.prefab", null);
  84. // fx_hero_quan.own.transform.SetParent(poolInterface.own.transform);
  85. // fx_hero_quan.own.transform.localPosition = Vector3.zero;
  86. // }
  87. poolInterface.own.SetActive(false);
  88. MagicWeaponControl = new MagicWeaponControl();
  89. combatHeroTimeLineControl = new CombatHeroTimeLineControl();
  90. combatHeroTimeLineControl.Init(this);
  91. AssetHandle assetHandle =
  92. await AssetBundleLoadManager.Instance.LoadAssetAsyncTask<TextAsset>(combatHeroInfo.modelName + "_TD.txt");
  93. if (assetHandle != null)
  94. {
  95. TextAsset textAsset = assetHandle.AssetObject<TextAsset>();
  96. TimeLienData timeLienData = JsonManager.FromJson<TimeLienData>(textAsset.text);
  97. timeLienData.DeserializeData();
  98. assetHandle.Release();
  99. combatHeroTimeLineControl.AddTimeLienData(timeLienData);
  100. }
  101. combatHeroGameObject = new CombatHeroGameObject();
  102. combatHeroGameObject.Init(this, poolInterface);
  103. BuffControl = new BuffControl();
  104. BuffControl.Init(this);
  105. NavMeshAgent navMeshAgent = poolInterface.own.GetComponent<NavMeshAgent>();
  106. if (combatAIBasic == null)
  107. {
  108. combatAIBasic = new CombatAIBasic();
  109. }
  110. HeroEntityMono heroEntityMono = poolInterface.own.GetComponent<HeroEntityMono>();
  111. if (heroEntityMono == null)
  112. {
  113. heroEntityMono = poolInterface.own.AddComponent<HeroEntityMono>();
  114. }
  115. heroEntityMono.combatHeroEntity = this;
  116. CombatAIBasic = combatAIBasic;
  117. CombatAIBasic.Init(this);
  118. CombatHeroSkillControl = new CombatHeroSkillControl();
  119. await CombatHeroSkillControl.Init(this);
  120. CurrCombatHeroInfo.Shield = (EncryptionLong)300;
  121. await InitShieldsFx();
  122. AnimancerComponent animancerComponent = poolInterface.own.GetComponent<AnimancerComponent>();
  123. combatHeroAnimtion = new CombatHeroAnimtion();
  124. // if (animancerComponent != null)
  125. {
  126. }
  127. // else
  128. // {
  129. // combatHeroAnimtion = new CombatHeroGPUAnimtion();
  130. // }
  131. poolInterface.own.SetActive(true);
  132. combatHeroAnimtion.Init(this);
  133. CombatAIBasic.ChangeState(CombatHeroStateType.XiuMian);
  134. if (IsEnemy )
  135. {
  136. CreateHeroHpEventData createHeroHpEventData = CreateHeroHpEventData.Create();
  137. createHeroHpEventData.combatHeroEntity = this;
  138. EventManager.Instance.Dispatch(CustomEventType.CreateHeroHp, createHeroHpEventData);
  139. }
  140. await MagicWeaponControl.InitMagicWeapon(this,isPlayer);
  141. callBack?.Invoke(this);
  142. #endif
  143. return this;
  144. }
  145. public virtual void Update(float t)
  146. {
  147. CombatAIBasic.Update(t);
  148. CombatHeroSkillControl.Update(t);
  149. combatHeroTimeLineControl.Update(t);
  150. combatHeroAnimtion.Update(t);
  151. combatHeroGameObject.Update(t);
  152. BuffControl.Update(t);
  153. MagicWeaponControl?.Update(t);
  154. if (combatHeroGameObject.HeroGPUMono != null)
  155. {
  156. if (_injuriedShowTime > 0)
  157. {
  158. _injuriedShowTime -= t;
  159. if (_isAddinjuriedShow)
  160. {
  161. combatHeroGameObject.HeroGPUMono.injuriedStrength += t * (_addInjuiedValue);
  162. if (combatHeroGameObject.HeroGPUMono.injuriedStrength >= 0.3f)
  163. {
  164. _isAddinjuriedShow = false;
  165. }
  166. }
  167. else
  168. {
  169. combatHeroGameObject.HeroGPUMono.injuriedStrength -= t * (_addInjuiedValue);
  170. if (combatHeroGameObject.HeroGPUMono.injuriedStrength < 0)
  171. {
  172. combatHeroGameObject.HeroGPUMono.injuriedStrength = 0;
  173. }
  174. }
  175. }
  176. else
  177. {
  178. combatHeroGameObject.HeroGPUMono.injuriedStrength = 0;
  179. }
  180. }
  181. }
  182. public T This<T>()
  183. {
  184. return (T)(object)this;
  185. }
  186. public override T GetILifetCycleHitPoint<T>(string hitPoinName, bool isStandType, bool isIgnoreHind)
  187. {
  188. return combatHeroGameObject.GetILifetCycleHitPoint<T>(hitPoinName, isStandType, isIgnoreHind);
  189. }
  190. public override T GetMainHotPoin<T>(bool isIgnoreHind = false)
  191. {
  192. return combatHeroGameObject.GetMainHotPoin<T>(isIgnoreHind);
  193. }
  194. public void PlayAnim(string animName, bool isLoop, int layerId, bool repeat, float speed)
  195. {
  196. combatHeroAnimtion.Play(animName, speed);
  197. }
  198. public SpecialDotInfo GetSpecialDotInfo(string specialDotName)
  199. {
  200. return combatHeroGameObject.GetMainHotPoin<CombatHeroHitPoint>(true).GetSpecialDotInfo(specialDotName);
  201. }
  202. public virtual float GetAttSpeed()
  203. {
  204. CombatHeroSkillControl combatHeroSkillControl = CombatHeroSkillControl as CombatHeroSkillControl;
  205. if (combatHeroSkillControl != null)
  206. {
  207. if (combatHeroSkillControl.useSkillCount > 1)
  208. {
  209. return 4;
  210. }
  211. return CurrCombatHeroInfo.attSpeed.Value;
  212. }
  213. return 1;
  214. }
  215. public void HeroResurrection()
  216. {
  217. isDie = false;
  218. CombatAIBasic.ChangeState(CombatHeroStateType.idle, isQiangZhi: true);
  219. HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create();
  220. heroHpUpdateEventData.combatHeroEntity = this;
  221. CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData);
  222. HeroResurrectionEventData heroResurrectionEventData = HeroResurrectionEventData.Create();
  223. heroResurrectionEventData.combatHeroEntity = this;
  224. CombatEventManager.Instance.Dispatch(CombatEventType.HeroResurrection, heroResurrectionEventData);
  225. }
  226. public void HeroDie(HarmReturnInfo harmReturnInfo)
  227. {
  228. heroDieNodeId = CombatController.currActiveCombat.CombatTypeBasic.allWinNodeCount;
  229. isDie = true;
  230. HeroDieEventData heroDieEventData = HeroDieEventData.Create();
  231. heroDieEventData.combatHeroEntity = this;
  232. heroDieEventData.HarmReturnInfo = harmReturnInfo;
  233. CombatEventManager.Instance.Dispatch(CombatEventType.HeroDie, heroDieEventData);
  234. combatHeroGameObject.HeroDie();
  235. CombatAIBasic.ChangeState(CombatHeroStateType.dile);
  236. CombatEventManager.Instance.Dispatch(CombatEventType.HeroDieFinish, heroDieEventData);
  237. }
  238. public void HeroHurt(HarmReturnInfo harmReturnInfo)
  239. {
  240. if (isDie)
  241. {
  242. return;
  243. }
  244. ShieldsBarrier shieldsBarrier= harmReturnInfo.triggerData.IBarrier as ShieldsBarrier;
  245. if (shieldsBarrier!=null)
  246. {
  247. shieldsBarrier.Harm(harmReturnInfo);
  248. }
  249. else
  250. {
  251. CurrCombatHeroInfo.hp -= harmReturnInfo.att;
  252. }
  253. UpdateHarmText(harmReturnInfo);
  254. if (combatHeroGameObject.HeroGPUMono != null)
  255. {
  256. _injuriedShowTime = 0.4f;
  257. combatHeroGameObject.HeroGPUMono.injuriedStrength = 0;
  258. _isAddinjuriedShow = true;
  259. }
  260. HeroInjuredEventData heroInjured = HeroInjuredEventData.Create();
  261. heroInjured.HarmReturnInfo = harmReturnInfo;
  262. CombatEventManager.Instance.Dispatch(CombatEventType.HeroInjured, heroInjured);
  263. HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create();
  264. heroHpUpdateEventData.combatHeroEntity = this;
  265. CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData);
  266. if (CurrCombatHeroInfo.hp <= 0)
  267. {
  268. HeroDie(harmReturnInfo);
  269. }
  270. }
  271. private void UpdateHarmText(HarmReturnInfo harmReturnInfo)
  272. {
  273. float currTime = Time.time;
  274. if (currTime - _lasetShowHarmTime < 0.1f)
  275. {
  276. return;
  277. }
  278. _lasetShowHarmTime = currTime;
  279. HarmUpdateEventData harmUpdateEventData = HarmUpdateEventData.Create();
  280. harmUpdateEventData.HarmReturnInfo = harmReturnInfo;
  281. CombatEventManager.Instance.Dispatch(CombatEventType.HarmUpdate, harmUpdateEventData);
  282. }
  283. public void Recover(HarmReturnInfo harmReturnInfo)
  284. {
  285. CurrCombatHeroInfo.hp += harmReturnInfo.att;
  286. HarmUpdateEventData harmUpdateEventData = HarmUpdateEventData.Create();
  287. harmUpdateEventData.HarmReturnInfo = harmReturnInfo;
  288. CombatEventManager.Instance.Dispatch(CombatEventType.RecoverUpdate, harmUpdateEventData);
  289. HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create();
  290. heroHpUpdateEventData.combatHeroEntity = this;
  291. CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData);
  292. }
  293. public void CloseLoopFx()
  294. {
  295. for (int i = 0; i < heroLoopParticle.Count; i++)
  296. {
  297. GObjectPool.Instance.Recycle(heroLoopParticle[i]);
  298. }
  299. heroLoopParticle.Clear();
  300. }
  301. public void Dispose()
  302. {
  303. if (_isDis)
  304. {
  305. return;
  306. }
  307. _isDis = true;
  308. combatHeroGameObject.Dispose();
  309. isDie = true;
  310. CombatHeroSkillControl.Dispose();
  311. CombatAIBasic.Dispose();
  312. combatHeroTimeLineControl.Dispose();
  313. combatHeroAnimtion.Dispose();
  314. CloseLoopFx();
  315. ShieldsBarrier?.Dispose();
  316. ShieldsBarrier = null;
  317. }
  318. private void ProDormancyObj()
  319. {
  320. CombatHeroSkillControl.ProDormancyObj();
  321. }
  322. public override void ActiveObj()
  323. {
  324. isDie = false;
  325. _isDis = false;
  326. }
  327. public override void DormancyObj()
  328. {
  329. Dispose();
  330. ProDormancyObj();
  331. _isDis = false;
  332. CombatAIBasic = null;
  333. combatHeroGameObject = null;
  334. CurrCombatHeroInfo = null;
  335. MaxCombatHeroInfo = null;
  336. combatHeroTimeLineControl = null;
  337. combatHeroAnimtion = null;
  338. CombatHeroSkillControl = null;
  339. isFollowState = false;
  340. heroLoopParticle.Clear();
  341. isDie = true;
  342. }
  343. }