CombatHeroController.cs 5.9 KB

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