CombatHeroController.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using System;
  2. using Common.Utility.CombatEvent;
  3. using Fort23.Core;
  4. using GameLogic.Combat.Hero;
  5. using UnityEngine;
  6. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  7. namespace GameLogic.Combat.CombatTool
  8. {
  9. public class CombatHeroController : IDisposable
  10. {
  11. private BetterList<CombatHeroEntity> myHero = new BetterList<CombatHeroEntity>();
  12. private BetterList<CombatHeroEntity> enemyHero = new BetterList<CombatHeroEntity>();
  13. private BetterList<ILifetCycleHitPoint> myHeroHitPoint = new BetterList<ILifetCycleHitPoint>();
  14. private BetterList<ILifetCycleHitPoint> enemyHeroHitPoint = new BetterList<ILifetCycleHitPoint>();
  15. protected CombatController combatController;
  16. private BetterList<CombatHeroEntity> heroDie = new BetterList<CombatHeroEntity>();
  17. private BetterList<CombatHeroEntity> heroDispose = new BetterList<CombatHeroEntity>();
  18. public Vector3[] followMovePos = new Vector3[]
  19. {
  20. new Vector3(0, 0, 0),
  21. new Vector3(-1f, 0, -0.5f),
  22. new Vector3(1f, 0, -0.5f),
  23. new Vector3(0, 0, -2f),
  24. };
  25. public CombatHeroEntity followTarget;
  26. public void Init(CombatController combatController)
  27. {
  28. this.combatController = combatController;
  29. CombatEventManager.Instance.AddEventListener(CombatEventType.UseSkill, CombatUseSkillEventData);
  30. }
  31. public void RemoveDieHero(CombatHeroEntity combatHeroEntity)
  32. {
  33. heroDie.Remove(combatHeroEntity);
  34. if (!heroDispose.Contains(combatHeroEntity))
  35. {
  36. heroDispose.Add(combatHeroEntity);
  37. }
  38. }
  39. /// <summary>
  40. /// 复活死亡的英雄
  41. /// </summary>
  42. public void ResurrectionDieHero(CombatHeroEntity combatHeroEntity)
  43. {
  44. heroDie.Remove(combatHeroEntity);
  45. combatHeroEntity.CurrCombatHeroInfo.hp = combatHeroEntity.MaxCombatHeroInfo.hp;
  46. AddHero(combatHeroEntity);
  47. combatHeroEntity.HeroResurrection();
  48. }
  49. public void Update(float t)
  50. {
  51. for (int i = 0; i < myHero.Count; i++)
  52. {
  53. myHero[i].Update(t);
  54. }
  55. for (int i = 0; i < enemyHero.Count; i++)
  56. {
  57. enemyHero[i].Update(t);
  58. }
  59. for (int i = 0; i < heroDie.Count; i++)
  60. {
  61. heroDie[i].Update(t);
  62. }
  63. for (int i = 0; i < heroDispose.Count; i++)
  64. {
  65. heroDispose[i].Dispose();
  66. }
  67. heroDispose.Clear();
  68. }
  69. public void AddHeroDie(CombatHeroEntity hero)
  70. {
  71. heroDie.Add(hero);
  72. }
  73. public void AddHero(CombatHeroEntity hero)
  74. {
  75. if (hero.IsEnemy)
  76. {
  77. enemyHero.Add(hero);
  78. }
  79. else
  80. {
  81. myHero.Add(hero);
  82. }
  83. }
  84. public void FindNumberMinHero()
  85. {
  86. int min = 9999;
  87. followTarget = null;
  88. for (int i = 0; i < myHero.Count; i++)
  89. {
  90. CombatHeroEntity c = myHero[i];
  91. if (c.number < min)
  92. {
  93. min = c.number;
  94. followTarget = c;
  95. }
  96. }
  97. }
  98. public void SetFollowTarget()
  99. {
  100. FindNumberMinHero();
  101. for (int i = 0; i < myHero.Count; i++)
  102. {
  103. CombatHeroEntity c = myHero[i];
  104. if (c != followTarget)
  105. {
  106. c.isFollowState = true;
  107. c.CombatAIBasic.ChangeState(CombatHeroStateType.followIdle);
  108. }
  109. }
  110. }
  111. private void CombatUseSkillEventData(IEventData iEventData)
  112. {
  113. CombatUseSkillEventData combatUseSkillEventData = iEventData as CombatUseSkillEventData;
  114. if (combatUseSkillEventData.useSkill.SelfSkillConfig.SkillType == 1)
  115. {
  116. for (int i = 0; i < myHero.Count; i++)
  117. {
  118. CombatHeroEntity c = myHero[i];
  119. if (c.isFollowState)
  120. {
  121. c.isFollowState = false;
  122. c.CombatAIBasic.ChangeState(CombatHeroStateType.idle);
  123. }
  124. }
  125. }
  126. }
  127. public void RemoveHero(CombatHeroEntity hero)
  128. {
  129. if (hero.IsEnemy)
  130. {
  131. enemyHero.Remove(hero);
  132. }
  133. else
  134. {
  135. myHero.Remove(hero);
  136. }
  137. }
  138. public void AddHeroHitPoint(bool isEnemy, ILifetCycleHitPoint hitPoint)
  139. {
  140. if (isEnemy)
  141. {
  142. enemyHeroHitPoint.Add(hitPoint);
  143. }
  144. else
  145. {
  146. myHeroHitPoint.Add(hitPoint);
  147. }
  148. }
  149. public void RemoveHeroHitPoint(bool isEnemy, ILifetCycleHitPoint hitPoint)
  150. {
  151. if (isEnemy)
  152. {
  153. enemyHeroHitPoint.Remove(hitPoint);
  154. }
  155. else
  156. {
  157. myHeroHitPoint.Remove(hitPoint);
  158. }
  159. }
  160. public void Dispose()
  161. {
  162. myHero.Dispose();
  163. enemyHero.Dispose();
  164. CombatEventManager.Instance.RemoveEventListener(CombatEventType.UseSkill, CombatUseSkillEventData);
  165. }
  166. public Vector3 GetFollowPos(CombatHeroEntity combatHeroEntity)
  167. {
  168. int index = combatHeroEntity.number - followTarget.number;
  169. return followTarget.combatHeroGameObject.transform.TransformPoint((followMovePos[index]));
  170. // return followMovePos[index] + .dotPos;
  171. }
  172. public CombatHeroEntity[] GetHero(bool isEnemy)
  173. {
  174. if (isEnemy)
  175. {
  176. return enemyHero.ToArray();
  177. }
  178. else
  179. {
  180. return myHero.ToArray();
  181. }
  182. }
  183. public ILifetCycleHitPoint[] GetHeroHitPoint(bool isEnemy)
  184. {
  185. if (isEnemy)
  186. {
  187. return enemyHeroHitPoint.ToArray();
  188. }
  189. else
  190. {
  191. return myHeroHitPoint.ToArray();
  192. }
  193. }
  194. }
  195. }