CombatHeroEntity.cs 13 KB

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