CombatHeroEntity.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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.CombatTool.CombatReport;
  12. using GameLogic.Combat.Hero;
  13. using GameLogic.Combat.Hero.HeroGPU;
  14. using GameLogic.Player;
  15. using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
  16. using UnityEngine;
  17. using UnityEngine.AI;
  18. using UnityEngine.Rendering;
  19. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  20. public class CombatHeroEntity : ShowBaiscEntity, ITimeLineAnimtion, ITimeLineGetAttSpeed,
  21. IHero
  22. {
  23. /// <summary>
  24. /// 死亡时的节点ID
  25. /// </summary>
  26. public int heroDieNodeId;
  27. public bool isPlayer;
  28. public bool isCreateHeroHp;
  29. public string guidName
  30. {
  31. get { return CurrCombatHeroInfo.modelName; }
  32. }
  33. public bool isFollowState;
  34. private float _injuriedShowTime;
  35. private bool _isAddinjuriedShow;
  36. private float _addInjuiedValue = (1.0f / 0.2f) * 0.3f;
  37. private bool _isDis;
  38. public float DisTime;
  39. public MagicWeaponControl heroMagicWeaponControl;
  40. public float HpBl
  41. {
  42. get { return CurrCombatHeroInfo.hp.Value * 100f / MaxCombatHeroInfo.hp.Value; }
  43. }
  44. public Vector3 dotPos
  45. {
  46. get { return combatHeroGameObject.position; }
  47. }
  48. public T GetThis<T>() where T : IHero
  49. {
  50. return (T)(object)this;
  51. }
  52. public GameObject GameObject
  53. {
  54. get { return combatHeroGameObject.transform.gameObject; }
  55. }
  56. public Vector3 faceDir
  57. {
  58. get { return combatHeroGameObject.transform.forward; }
  59. }
  60. public async CTask<CombatHeroEntity> InitForObject(GameObjectPool poolInterface, CombatAIBasic combatAIBasic,
  61. CombatHeroInfo combatHeroInfo,
  62. Vector3 pos,
  63. System.Action<CombatHeroEntity> callBack = null, bool isPlayer = false)
  64. {
  65. //后面记到检查战斗里面不要出现异步加载,也不要出现同步IO加载
  66. this.isPlayer = isPlayer;
  67. string modelName = combatHeroInfo.modelName;
  68. if (combatHeroInfo.isGpu)
  69. {
  70. modelName += "_gpu";
  71. }
  72. CurrCombatHeroInfo = combatHeroInfo.Copy();
  73. MaxCombatHeroInfo = combatHeroInfo.Copy();
  74. poolInterface.own.transform.position = pos;
  75. if (IsEnemy)
  76. {
  77. poolInterface.own.SetActive(false);
  78. }
  79. // if (!IsEnemy)
  80. // {
  81. // GameObjectPool fx_hero_quan =
  82. // await GObjectPool.Instance.FetchAsync<GameObjectPool>("fx_hero_quan.prefab", null);
  83. // fx_hero_quan.own.transform.SetParent(poolInterface.own.transform);
  84. // fx_hero_quan.own.transform.localPosition = Vector3.zero;
  85. // }
  86. // poolInterface.own.SetActive(false);
  87. heroMagicWeaponControl = new MagicWeaponControl();
  88. combatHeroTimeLineControl = new CombatHeroTimeLineControl();
  89. combatHeroTimeLineControl.Init(this);
  90. AssetHandle assetHandle =
  91. await AssetBundleLoadManager.Instance.LoadAssetAsyncTask<TextAsset>(combatHeroInfo.modelName + "_TD.txt");
  92. if (assetHandle != null)
  93. {
  94. TextAsset textAsset = assetHandle.AssetObject<TextAsset>();
  95. TimeLienData timeLienData = JsonManager.FromJson<TimeLienData>(textAsset.text);
  96. timeLienData.DeserializeData();
  97. assetHandle.Release();
  98. combatHeroTimeLineControl.AddTimeLienData(timeLienData);
  99. }
  100. combatHeroGameObject = new CombatHeroGameObject();
  101. combatHeroGameObject.Init(this, poolInterface);
  102. BuffControl = new BuffControl();
  103. BuffControl.Init(this);
  104. NavMeshAgent navMeshAgent = poolInterface.own.GetComponent<NavMeshAgent>();
  105. if (combatAIBasic == null)
  106. {
  107. combatAIBasic = new CombatAIBasic();
  108. }
  109. HeroEntityMono heroEntityMono = poolInterface.own.GetComponent<HeroEntityMono>();
  110. if (heroEntityMono == null)
  111. {
  112. CombatHeroColliderRoot combatHeroColliderRoot= poolInterface.own.GetComponent<CombatHeroColliderRoot>();
  113. if (combatHeroColliderRoot != null)
  114. {
  115. heroEntityMono = combatHeroColliderRoot.root.GetOrAddComponent<HeroEntityMono>();
  116. }
  117. else
  118. {
  119. heroEntityMono = poolInterface.own.GetOrAddComponent<HeroEntityMono>();
  120. }
  121. }
  122. heroEntityMono.combatHeroEntity = this;
  123. CombatAIBasic = combatAIBasic;
  124. CombatAIBasic.Init(this);
  125. CombatHeroSkillControl = new CombatHeroSkillControl();
  126. await CombatHeroSkillControl.Init(this);
  127. await InitShieldsFx();
  128. AnimancerComponent animancerComponent = poolInterface.own.GetComponent<AnimancerComponent>();
  129. combatHeroAnimtion = new CombatHeroAnimtion();
  130. // if (animancerComponent != null)
  131. {
  132. }
  133. // else
  134. // {
  135. // combatHeroAnimtion = new CombatHeroGPUAnimtion();
  136. // }
  137. combatHeroAnimtion.Init(this);
  138. CombatAIBasic.ChangeState(CombatHeroStateType.XiuMian);
  139. if (isCreateHeroHp)
  140. {
  141. CreateHeroHpEventData createHeroHpEventData = CreateHeroHpEventData.Create();
  142. createHeroHpEventData.combatHeroEntity = this;
  143. EventManager.Instance.Dispatch(CustomEventType.CreateHeroHp, createHeroHpEventData);
  144. }
  145. await heroMagicWeaponControl.InitMagicWeapon(this, isPlayer);
  146. CombatReportManager.Instance.AddCombatReportInfo(this);
  147. poolInterface.own.SetActive(true);
  148. callBack?.Invoke(this);
  149. return this;
  150. }
  151. public virtual async CTask<CombatHeroEntity> Init(CombatAIBasic combatAIBasic, CombatHeroInfo combatHeroInfo,
  152. Vector3 pos,
  153. System.Action<CombatHeroEntity> callBack = null, bool isPlayer = false)
  154. {
  155. //后面记到检查战斗里面不要出现异步加载,也不要出现同步IO加载
  156. this.isPlayer = isPlayer;
  157. string modelName = combatHeroInfo.modelName;
  158. if (combatHeroInfo.isGpu)
  159. {
  160. modelName += "_gpu";
  161. }
  162. CurrCombatHeroInfo = combatHeroInfo.Copy();
  163. MaxCombatHeroInfo = combatHeroInfo.Copy();
  164. // GameTimeLineParticleFactory
  165. CombatHeroGameObjectPool poolInterface =
  166. await GObjectPool.Instance.FetchAsync<CombatHeroGameObjectPool>(modelName + ".prefab", null);
  167. if (poolInterface == null || poolInterface.own == null)
  168. {
  169. return null;
  170. }
  171. return await InitForObject(poolInterface, combatAIBasic, combatHeroInfo, pos, callBack, isPlayer);
  172. }
  173. public virtual void Update(float t)
  174. {
  175. CombatAIBasic.Update(t);
  176. CombatHeroSkillControl.Update(t);
  177. combatHeroTimeLineControl.Update(t);
  178. combatHeroAnimtion.Update(t);
  179. combatHeroGameObject.Update(t);
  180. BuffControl.Update(t);
  181. heroMagicWeaponControl?.Update(t);
  182. if (combatHeroGameObject.HeroGPUMono != null)
  183. {
  184. if (_injuriedShowTime > 0)
  185. {
  186. _injuriedShowTime -= t;
  187. if (_isAddinjuriedShow)
  188. {
  189. combatHeroGameObject.HeroGPUMono.injuriedStrength += t * (_addInjuiedValue);
  190. if (combatHeroGameObject.HeroGPUMono.injuriedStrength >= 0.3f)
  191. {
  192. _isAddinjuriedShow = false;
  193. }
  194. }
  195. else
  196. {
  197. combatHeroGameObject.HeroGPUMono.injuriedStrength -= t * (_addInjuiedValue);
  198. if (combatHeroGameObject.HeroGPUMono.injuriedStrength < 0)
  199. {
  200. combatHeroGameObject.HeroGPUMono.injuriedStrength = 0;
  201. }
  202. }
  203. }
  204. else
  205. {
  206. combatHeroGameObject.HeroGPUMono.injuriedStrength = 0;
  207. }
  208. }
  209. }
  210. public T This<T>()
  211. {
  212. return (T)(object)this;
  213. }
  214. public override T GetILifetCycleHitPoint<T>(string hitPoinName, bool isStandType, bool isIgnoreHind)
  215. {
  216. return combatHeroGameObject.GetILifetCycleHitPoint<T>(hitPoinName, isStandType, isIgnoreHind);
  217. }
  218. public override T GetMainHotPoin<T>(bool isIgnoreHind = false)
  219. {
  220. return combatHeroGameObject.GetMainHotPoin<T>(isIgnoreHind);
  221. }
  222. public void PlayAnim(string animName, bool isLoop, int layerId, bool repeat, float speed)
  223. {
  224. combatHeroAnimtion.Play(animName, speed);
  225. }
  226. public SpecialDotInfo GetSpecialDotInfo(string specialDotName)
  227. {
  228. return combatHeroGameObject.GetMainHotPoin<CombatHeroHitPoint>(true).GetSpecialDotInfo(specialDotName);
  229. }
  230. public virtual float GetAttSpeed()
  231. {
  232. // CombatHeroSkillControl combatHeroSkillControl = CombatHeroSkillControl as CombatHeroSkillControl;
  233. // if (combatHeroSkillControl != null)
  234. // {
  235. // if (combatHeroSkillControl.useSkillCount > 1)
  236. // {
  237. // return 4;
  238. // }
  239. //
  240. // return CurrCombatHeroInfo.GetAnimationSpeed;
  241. // }
  242. return 1;
  243. }
  244. public void HeroResurrection()
  245. {
  246. isDie = false;
  247. CombatAIBasic.ChangeState(CombatHeroStateType.idle, isQiangZhi: true);
  248. HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create();
  249. heroHpUpdateEventData.combatHeroEntity = this;
  250. CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData);
  251. HeroResurrectionEventData heroResurrectionEventData = HeroResurrectionEventData.Create();
  252. heroResurrectionEventData.combatHeroEntity = this;
  253. CombatEventManager.Instance.Dispatch(CombatEventType.HeroResurrection, heroResurrectionEventData);
  254. }
  255. public void HeroDie(HarmReturnInfo harmReturnInfo)
  256. {
  257. heroDieNodeId = CombatController.currActiveCombat.CombatTypeBasic.allWinNodeCount;
  258. isDie = true;
  259. HeroDieEventData heroDieEventData = HeroDieEventData.Create();
  260. heroDieEventData.combatHeroEntity = this;
  261. heroDieEventData.HarmReturnInfo = harmReturnInfo;
  262. CombatEventManager.Instance.Dispatch(CombatEventType.HeroDie, heroDieEventData);
  263. combatHeroGameObject.HeroDie();
  264. CombatAIBasic.ChangeState(CombatHeroStateType.dile);
  265. CombatEventManager.Instance.Dispatch(CombatEventType.HeroDieFinish, heroDieEventData);
  266. }
  267. /// <summary>
  268. /// 是否被控制
  269. /// </summary>
  270. /// <returns></returns>
  271. public bool IsControl()
  272. {
  273. BuffBasic basic = BuffControl.GetBuffBasicForIdGroup(1006);
  274. if (basic != null)
  275. {
  276. return true;
  277. }
  278. b_1025 b1025 = BuffControl.GetBuffBasicForType<b_1025>();
  279. if (b1025 != null)
  280. {
  281. return true;
  282. }
  283. b_1002 b1002 = BuffControl.GetBuffBasicForType<b_1002>();
  284. if (b1002 != null)
  285. {
  286. return true;
  287. }
  288. return false;
  289. }
  290. /// <summary>
  291. /// 是否不能添加功法
  292. /// </summary>
  293. /// <returns></returns>
  294. public bool IsCantAddGongFa()
  295. {
  296. BuffBasic basic = BuffControl.GetBuffBasicForIdGroup(1006);
  297. if (basic != null)
  298. {
  299. return false;
  300. }
  301. return true;
  302. }
  303. public void HeroHurt(HarmReturnInfo harmReturnInfo)
  304. {
  305. if (isDie)
  306. {
  307. return;
  308. }
  309. b_1015 b1015 = BuffControl.GetBuffBasicForType<b_1015>();
  310. if (b1015 != null)
  311. {
  312. return;
  313. }
  314. long att = harmReturnInfo.att;
  315. IBarrier shieldsBarrier = harmReturnInfo.triggerData.IBarrier as IBarrier;
  316. if (shieldsBarrier != null)
  317. {
  318. att = shieldsBarrier.Harm(harmReturnInfo);
  319. harmReturnInfo.harmType |= HarmType.Shields;
  320. }
  321. else
  322. {
  323. harmReturnInfo.isHitHero = true;
  324. }
  325. if (att > 0)
  326. {
  327. CurrCombatHeroInfo.hp -= att;
  328. }
  329. if (isZhanZhuang)
  330. {
  331. CurrCombatHeroInfo.hp = MaxCombatHeroInfo.hp;
  332. }
  333. UpdateHarmText(harmReturnInfo);
  334. if (combatHeroGameObject.HeroGPUMono != null)
  335. {
  336. _injuriedShowTime = 0.4f;
  337. combatHeroGameObject.HeroGPUMono.injuriedStrength = 0;
  338. _isAddinjuriedShow = true;
  339. }
  340. HeroInjuredEventData heroInjured = HeroInjuredEventData.Create();
  341. heroInjured.HarmReturnInfo = harmReturnInfo;
  342. CombatEventManager.Instance.Dispatch(CombatEventType.HeroInjured, heroInjured);
  343. HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create();
  344. heroHpUpdateEventData.combatHeroEntity = this;
  345. CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData);
  346. if (CurrCombatHeroInfo.hp <= 0)
  347. {
  348. HeroDie(harmReturnInfo);
  349. }
  350. }
  351. private void UpdateHarmText(HarmReturnInfo harmReturnInfo)
  352. {
  353. // float currTime = Time.time;
  354. // // if (currTime - _lasetShowHarmTime < 0.1f)
  355. // // {
  356. // // return;
  357. // // }
  358. // _lasetShowHarmTime = currTime;
  359. HarmUpdateEventData harmUpdateEventData = HarmUpdateEventData.Create();
  360. harmUpdateEventData.HarmReturnInfo = harmReturnInfo;
  361. CombatEventManager.Instance.Dispatch(CombatEventType.HarmUpdate, harmUpdateEventData);
  362. }
  363. public void Recover(HarmReturnInfo harmReturnInfo)
  364. {
  365. CurrCombatHeroInfo.hp += harmReturnInfo.att;
  366. if (CurrCombatHeroInfo.hp > MaxCombatHeroInfo.hp)
  367. {
  368. CurrCombatHeroInfo.hp = MaxCombatHeroInfo.hp;
  369. }
  370. HarmUpdateEventData harmUpdateEventData = HarmUpdateEventData.Create();
  371. harmUpdateEventData.HarmReturnInfo = harmReturnInfo;
  372. CombatEventManager.Instance.Dispatch(CombatEventType.RecoverUpdate, harmUpdateEventData);
  373. HeroHpUpdateEventData heroHpUpdateEventData = HeroHpUpdateEventData.Create();
  374. heroHpUpdateEventData.combatHeroEntity = this;
  375. CombatEventManager.Instance.Dispatch(CombatEventType.HeroHpUpdate, heroHpUpdateEventData);
  376. }
  377. public void CloseLoopFx()
  378. {
  379. for (int i = 0; i < heroLoopParticle.Count; i++)
  380. {
  381. GObjectPool.Instance.Recycle(heroLoopParticle[i]);
  382. }
  383. heroLoopParticle.Clear();
  384. }
  385. public void DisposeForOnetCombat()
  386. {
  387. if (_isDis)
  388. {
  389. return;
  390. }
  391. heroMagicWeaponControl?.Dispose();
  392. _isDis = true;
  393. CombatHeroSkillControl.Dispose();
  394. BuffControl.Dispose();
  395. CombatAIBasic.Dispose();
  396. combatHeroTimeLineControl.Dispose();
  397. combatHeroAnimtion.Dispose();
  398. CloseLoopFx();
  399. ShieldsBarrier?.Dispose();
  400. ShieldsBarrier = null;
  401. heroMagicWeaponControl = null;
  402. }
  403. public void Dispose()
  404. {
  405. if (_isDis)
  406. {
  407. return;
  408. }
  409. heroMagicWeaponControl?.Dispose();
  410. _isDis = true;
  411. combatHeroGameObject.Dispose();
  412. isDie = true;
  413. CombatHeroSkillControl.Dispose();
  414. BuffControl.Dispose();
  415. CombatAIBasic.Dispose();
  416. combatHeroTimeLineControl.Dispose();
  417. combatHeroAnimtion.Dispose();
  418. CloseLoopFx();
  419. ShieldsBarrier?.Dispose();
  420. ShieldsBarrier = null;
  421. heroMagicWeaponControl = null;
  422. }
  423. private void ProDormancyObj()
  424. {
  425. CombatHeroSkillControl?.ProDormancyObj();
  426. }
  427. public override void ActiveObj()
  428. {
  429. isDie = false;
  430. _isDis = false;
  431. }
  432. public override void DormancyObj()
  433. {
  434. Dispose();
  435. ProDormancyObj();
  436. _isDis = false;
  437. CombatAIBasic = null;
  438. combatHeroGameObject = null;
  439. CurrCombatHeroInfo = null;
  440. MaxCombatHeroInfo = null;
  441. combatHeroTimeLineControl = null;
  442. combatHeroAnimtion = null;
  443. CombatHeroSkillControl = null;
  444. isFollowState = false;
  445. heroLoopParticle.Clear();
  446. isDie = true;
  447. }
  448. }