CombatHeroController.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. EventManager.Instance.AddEventListener(CustomEventType.HeroUpgrade, HeroUpgrade);
  31. }
  32. private void HeroUpgrade(IEventData eventData)
  33. {
  34. HeroLvUpgradeEventData heroLvUpgradeEventData = eventData as HeroLvUpgradeEventData;
  35. int id = heroLvUpgradeEventData.heroModelID;
  36. CombatHeroEntity combatHeroEntity = null;
  37. for (int i = 0; i < myHero.Count; i++)
  38. {
  39. if (myHero[i].CurrCombatHeroInfo.modelID == id)
  40. {
  41. combatHeroEntity = myHero[i];
  42. break;
  43. }
  44. }
  45. if (combatHeroEntity == null)
  46. {
  47. for (int i = 0; i < heroDie.Count; i++)
  48. {
  49. if (heroDie[i].CurrCombatHeroInfo.modelID == id)
  50. {
  51. combatHeroEntity = heroDie[i];
  52. break;
  53. }
  54. }
  55. }
  56. CombatHeroInfo combatHeroInfo = PlayerManager.Instance.GetHeroInfo(id);
  57. long addHp = combatHeroInfo.hp.Value - combatHeroEntity.MaxCombatHeroInfo.hp.Value;
  58. combatHeroEntity.MaxCombatHeroInfo.hp = combatHeroInfo.hp;
  59. combatHeroEntity.MaxCombatHeroInfo.defense = combatHeroInfo.defense;
  60. combatHeroEntity.MaxCombatHeroInfo.attack = combatHeroInfo.attack;
  61. combatHeroEntity.CurrCombatHeroInfo.defense = combatHeroInfo.defense;
  62. combatHeroEntity.CurrCombatHeroInfo.attack = combatHeroInfo.attack;
  63. if (!combatHeroEntity.isDie)
  64. {
  65. if (addHp > 0)
  66. {
  67. combatHeroEntity.CurrCombatHeroInfo.hp += addHp;
  68. }
  69. else
  70. {
  71. }
  72. }
  73. }
  74. public void RemoveDieHero(CombatHeroEntity combatHeroEntity)
  75. {
  76. heroDie.Remove(combatHeroEntity);
  77. if (!heroDispose.Contains(combatHeroEntity))
  78. {
  79. heroDispose.Add(combatHeroEntity);
  80. }
  81. }
  82. /// <summary>
  83. /// 复活死亡的英雄
  84. /// </summary>
  85. public void ResurrectionDieHero(CombatHeroEntity combatHeroEntity)
  86. {
  87. heroDie.Remove(combatHeroEntity);
  88. combatHeroEntity.CurrCombatHeroInfo.hp = combatHeroEntity.MaxCombatHeroInfo.hp;
  89. AddHero(combatHeroEntity);
  90. combatHeroEntity.HeroResurrection();
  91. }
  92. public void Update(float t)
  93. {
  94. for (int i = 0; i < myHero.Count; i++)
  95. {
  96. myHero[i].Update(t);
  97. }
  98. for (int i = 0; i < enemyHero.Count; i++)
  99. {
  100. enemyHero[i].Update(t);
  101. }
  102. for (int i = 0; i < heroDie.Count; i++)
  103. {
  104. heroDie[i].Update(t);
  105. }
  106. for (int i = 0; i < heroDispose.Count; i++)
  107. {
  108. heroDispose[i].Dispose();
  109. }
  110. heroDispose.Clear();
  111. }
  112. public void AddHeroDie(CombatHeroEntity hero)
  113. {
  114. heroDie.Add(hero);
  115. }
  116. public void AddHero(CombatHeroEntity hero)
  117. {
  118. if (hero.IsEnemy)
  119. {
  120. enemyHero.Add(hero);
  121. }
  122. else
  123. {
  124. myHero.Add(hero);
  125. }
  126. }
  127. public void FindNumberMinHero()
  128. {
  129. int min = 9999;
  130. followTarget = null;
  131. for (int i = 0; i < myHero.Count; i++)
  132. {
  133. CombatHeroEntity c = myHero[i];
  134. if (c.number < min)
  135. {
  136. min = c.number;
  137. followTarget = c;
  138. }
  139. }
  140. }
  141. public void SetFollowTarget()
  142. {
  143. FindNumberMinHero();
  144. for (int i = 0; i < myHero.Count; i++)
  145. {
  146. CombatHeroEntity c = myHero[i];
  147. if (c != followTarget)
  148. {
  149. c.isFollowState = true;
  150. c.CombatAIBasic.ChangeState(CombatHeroStateType.followIdle);
  151. }
  152. }
  153. }
  154. private void CombatUseSkillEventData(IEventData iEventData)
  155. {
  156. CombatUseSkillEventData combatUseSkillEventData = iEventData as CombatUseSkillEventData;
  157. if (combatUseSkillEventData.useSkill.SelfSkillConfig.SkillType == 1)
  158. {
  159. for (int i = 0; i < myHero.Count; i++)
  160. {
  161. CombatHeroEntity c = myHero[i];
  162. if (c.isFollowState)
  163. {
  164. c.isFollowState = false;
  165. c.CombatAIBasic.ChangeState(CombatHeroStateType.idle);
  166. }
  167. }
  168. }
  169. }
  170. public void RemoveHero(CombatHeroEntity hero)
  171. {
  172. if (hero.IsEnemy)
  173. {
  174. enemyHero.Remove(hero);
  175. }
  176. else
  177. {
  178. myHero.Remove(hero);
  179. }
  180. }
  181. public void AddHeroHitPoint(bool isEnemy, ILifetCycleHitPoint hitPoint)
  182. {
  183. if (isEnemy)
  184. {
  185. enemyHeroHitPoint.Add(hitPoint);
  186. }
  187. else
  188. {
  189. myHeroHitPoint.Add(hitPoint);
  190. }
  191. }
  192. public void RemoveHeroHitPoint(bool isEnemy, ILifetCycleHitPoint hitPoint)
  193. {
  194. if (isEnemy)
  195. {
  196. enemyHeroHitPoint.Remove(hitPoint);
  197. }
  198. else
  199. {
  200. myHeroHitPoint.Remove(hitPoint);
  201. }
  202. }
  203. public void Dispose()
  204. {
  205. myHero.Dispose();
  206. enemyHero.Dispose();
  207. CombatEventManager.Instance.RemoveEventListener(CombatEventType.UseSkill, CombatUseSkillEventData);
  208. }
  209. public Vector3 GetFollowPos(CombatHeroEntity combatHeroEntity)
  210. {
  211. int index = combatHeroEntity.number - followTarget.number;
  212. return followTarget.combatHeroGameObject.transform.TransformPoint((followMovePos[index]));
  213. // return followMovePos[index] + .dotPos;
  214. }
  215. public CombatHeroEntity[] GetHero(bool isEnemy)
  216. {
  217. if (isEnemy)
  218. {
  219. return enemyHero.ToArray();
  220. }
  221. else
  222. {
  223. return myHero.ToArray();
  224. }
  225. }
  226. public ILifetCycleHitPoint[] GetHeroHitPoint(bool isEnemy)
  227. {
  228. if (isEnemy)
  229. {
  230. return enemyHeroHitPoint.ToArray();
  231. }
  232. else
  233. {
  234. return myHeroHitPoint.ToArray();
  235. }
  236. }
  237. }
  238. }