CombatHeroController.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. }
  48. public void Update(float t)
  49. {
  50. for (int i = 0; i < myHero.Count; i++)
  51. {
  52. myHero[i].Update(t);
  53. }
  54. for (int i = 0; i < enemyHero.Count; i++)
  55. {
  56. enemyHero[i].Update(t);
  57. }
  58. for (int i = 0; i < heroDie.Count; i++)
  59. {
  60. heroDie[i].Update(t);
  61. }
  62. for (int i = 0; i < heroDispose.Count; i++)
  63. {
  64. heroDispose[i].Dispose();
  65. }
  66. heroDispose.Clear();
  67. }
  68. public void AddHeroDie(CombatHeroEntity hero)
  69. {
  70. heroDie.Add(hero);
  71. }
  72. public void AddHero(CombatHeroEntity hero)
  73. {
  74. if (hero.IsEnemy)
  75. {
  76. enemyHero.Add(hero);
  77. }
  78. else
  79. {
  80. myHero.Add(hero);
  81. }
  82. }
  83. public void FindNumberMinHero()
  84. {
  85. int min = 9999;
  86. followTarget = null;
  87. for (int i = 0; i < myHero.Count; i++)
  88. {
  89. CombatHeroEntity c = myHero[i];
  90. if (c.number < min)
  91. {
  92. min = c.number;
  93. followTarget = c;
  94. }
  95. }
  96. }
  97. public void SetFollowTarget()
  98. {
  99. FindNumberMinHero();
  100. for (int i = 0; i < myHero.Count; i++)
  101. {
  102. CombatHeroEntity c = myHero[i];
  103. if (c != followTarget)
  104. {
  105. c.isFollowState = true;
  106. c.CombatAIBasic.ChangeState(CombatHeroStateType.followIdle);
  107. }
  108. }
  109. }
  110. private void CombatUseSkillEventData(IEventData iEventData)
  111. {
  112. CombatUseSkillEventData combatUseSkillEventData = iEventData as CombatUseSkillEventData;
  113. if (combatUseSkillEventData.useSkill.SelfSkillConfig.SkillType == 1)
  114. {
  115. for (int i = 0; i < myHero.Count; i++)
  116. {
  117. CombatHeroEntity c = myHero[i];
  118. if (c.isFollowState)
  119. {
  120. c.isFollowState = false;
  121. c.CombatAIBasic.ChangeState(CombatHeroStateType.idle);
  122. }
  123. }
  124. }
  125. }
  126. public void RemoveHero(CombatHeroEntity hero)
  127. {
  128. if (hero.IsEnemy)
  129. {
  130. enemyHero.Remove(hero);
  131. }
  132. else
  133. {
  134. myHero.Remove(hero);
  135. }
  136. }
  137. public void AddHeroHitPoint(bool isEnemy, ILifetCycleHitPoint hitPoint)
  138. {
  139. if (isEnemy)
  140. {
  141. enemyHeroHitPoint.Add(hitPoint);
  142. }
  143. else
  144. {
  145. myHeroHitPoint.Add(hitPoint);
  146. }
  147. }
  148. public void RemoveHeroHitPoint(bool isEnemy, ILifetCycleHitPoint hitPoint)
  149. {
  150. if (isEnemy)
  151. {
  152. enemyHeroHitPoint.Remove(hitPoint);
  153. }
  154. else
  155. {
  156. myHeroHitPoint.Remove(hitPoint);
  157. }
  158. }
  159. public void Dispose()
  160. {
  161. myHero.Dispose();
  162. enemyHero.Dispose();
  163. CombatEventManager.Instance.RemoveEventListener(CombatEventType.UseSkill, CombatUseSkillEventData);
  164. }
  165. public Vector3 GetFollowPos(CombatHeroEntity combatHeroEntity)
  166. {
  167. int index = combatHeroEntity.number - followTarget.number;
  168. return followTarget.combatHeroGameObject.transform.TransformPoint((followMovePos[index]));
  169. // return followMovePos[index] + .dotPos;
  170. }
  171. public CombatHeroEntity[] GetHero(bool isEnemy)
  172. {
  173. if (isEnemy)
  174. {
  175. return enemyHero.ToArray();
  176. }
  177. else
  178. {
  179. return myHero.ToArray();
  180. }
  181. }
  182. public ILifetCycleHitPoint[] GetHeroHitPoint(bool isEnemy)
  183. {
  184. if (isEnemy)
  185. {
  186. return enemyHeroHitPoint.ToArray();
  187. }
  188. else
  189. {
  190. return myHeroHitPoint.ToArray();
  191. }
  192. }
  193. }
  194. }