MagicWeaponCollisionInfo.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using Core.Triiger;
  2. using Core.Utility;
  3. using Fort23.Core;
  4. using Fort23.UTool;
  5. using GameLogic.Combat.Hero;
  6. using GameLogic.Combat.Hero.State;
  7. using UnityEngine;
  8. using Utility.CTween;
  9. namespace GameLogic.Combat.CombatTool
  10. {
  11. public class MagicWeaponCollisionInfo : CObject, ITriggerEntity
  12. {
  13. public CombatMagicWeaponEntity a;
  14. public CombatMagicWeaponEntity b;
  15. public BesselPath _besselPathA;
  16. public BesselPath _besselPathB;
  17. public int id;
  18. protected float _currTime;
  19. /// <summary>
  20. /// 状态 0=等待状态 1=飞行状态 2=碰撞状态
  21. /// </summary>
  22. public int State;
  23. private IUnRegister _unRegister;
  24. protected bool _isOne;
  25. protected ParticleSystemPool ParticleSystemPool;
  26. private int triigerCount;
  27. public void Init(CombatMagicWeaponEntity a, CombatMagicWeaponEntity b, int id)
  28. {
  29. this.id = id;
  30. if (a.IsEnemy)
  31. {
  32. (a, b) = (b, a);
  33. }
  34. this.a = a;
  35. this.b = b;
  36. a.MagicWeaponCollisionId = id;
  37. b.MagicWeaponCollisionId = id;
  38. State = 0;
  39. }
  40. private void OnTriggerEnter(Collider collider, ITriggerEntity triggerEntity)
  41. {
  42. HeroEntityMono heroEntityMono = collider.GetComponent<HeroEntityMono>();
  43. if (heroEntityMono == null || (heroEntityMono.combatHeroEntity != b))
  44. {
  45. return;
  46. }
  47. if (State != 1)
  48. {
  49. return;
  50. }
  51. if (triigerCount >= 2)
  52. {
  53. MagicWeaponPingDouState.MagicWeaponPingDouData rollingStateData =
  54. CObjectPool.Instance.Fetch<MagicWeaponPingDouState.MagicWeaponPingDouData>();
  55. rollingStateData.target = b;
  56. a.CombatAIBasic.ChangeState(CombatHeroStateType.MagicWeaponPingDou,
  57. rollingStateData);
  58. MagicWeaponPingDouState.MagicWeaponPingDouData rollingStateData2 =
  59. CObjectPool.Instance.Fetch<MagicWeaponPingDouState.MagicWeaponPingDouData>();
  60. rollingStateData.target = a;
  61. b.CombatAIBasic.ChangeState(CombatHeroStateType.MagicWeaponPingDou,
  62. rollingStateData2);
  63. State = 2;
  64. _currTime = 0;
  65. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle("fx_fb_duipin_dian",
  66. a.dotPos, null, false, null, delegate(ParticleSystemPool particleSystemPool)
  67. {
  68. particleSystemPool.transform.rotation =
  69. a.GameObject.transform.rotation;
  70. ParticleSystemPool = particleSystemPool;
  71. });
  72. }
  73. else
  74. {
  75. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle("fx_fb_duipin_hit",
  76. collider.transform.position, null, false, null, delegate(ParticleSystemPool particleSystemPool)
  77. {
  78. particleSystemPool.transform.rotation =
  79. a.GameObject.transform.rotation;
  80. });
  81. triigerCount++;
  82. // a.ReduceHp(40);
  83. // _trigger = true;
  84. // _triggerTime = 0.5f;
  85. }
  86. }
  87. protected void SetBesselA()
  88. {
  89. _besselPathA = new BesselPath();
  90. _besselPathA.controlPoints.Add(a.dotPos);
  91. _besselPathA.controlPoints.Add(a.GameObject.transform.TransformPoint(new Vector3(-9.87f, 4, 2)));
  92. _besselPathA.controlPoints.Add(b.GameObject.transform.TransformPoint(new Vector3(-12.66f, 1, 5)));
  93. _besselPathA.controlPoints.Add(b.dotPos);
  94. GameObject G1 = new GameObject("BesselPathMono22");
  95. BesselPathMono besselPathMono1 = G1.AddComponent<BesselPathMono>();
  96. besselPathMono1.isRun = true;
  97. besselPathMono1.BesselPath = _besselPathA;
  98. _besselPathB = new BesselPath();
  99. _besselPathB.controlPoints.Add(b.dotPos);
  100. _besselPathB.controlPoints.Add(
  101. b.GameObject.transform.TransformPoint(new Vector3(11.89f, -0.29f, -3.28f)));
  102. _besselPathB.controlPoints.Add(
  103. a.GameObject.transform.TransformPoint(new Vector3(12.67f, -3.03f, -3.5f)));
  104. _besselPathB.controlPoints.Add(a.dotPos);
  105. GameObject G2 = new GameObject("BesselPathMono22");
  106. BesselPathMono besselPathMono2 = G2.AddComponent<BesselPathMono>();
  107. besselPathMono2.isRun = true;
  108. besselPathMono2.BesselPath = _besselPathB;
  109. }
  110. protected void SetBesselB()
  111. {
  112. _besselPathA = new BesselPath();
  113. _besselPathA.controlPoints.Add(a.dotPos);
  114. _besselPathA.controlPoints.Add(a.GameObject.transform.TransformPoint(new Vector3(-3.41f, 4, -7.23f)));
  115. _besselPathA.controlPoints.Add(b.GameObject.transform.TransformPoint(new Vector3(-2.64f, 1, 5)));
  116. _besselPathA.controlPoints.Add(b.dotPos);
  117. GameObject G = new GameObject("BesselPathMono11");
  118. BesselPathMono besselPathMono = G.AddComponent<BesselPathMono>();
  119. besselPathMono.isRun = true;
  120. besselPathMono.BesselPath = _besselPathA;
  121. _besselPathB = new BesselPath();
  122. _besselPathB.controlPoints.Add(b.dotPos);
  123. _besselPathB.controlPoints.Add(
  124. b.GameObject.transform.TransformPoint(new Vector3(8.5f, -3.93f, -9.58f)));
  125. _besselPathB.controlPoints.Add(
  126. a.GameObject.transform.TransformPoint(new Vector3(1.45f, -3.03f, 4.6f)));
  127. _besselPathB.controlPoints.Add(a.dotPos);
  128. GameObject G2 = new GameObject("BesselPathMono22");
  129. BesselPathMono besselPathMono2 = G2.AddComponent<BesselPathMono>();
  130. besselPathMono2.isRun = true;
  131. besselPathMono2.BesselPath = _besselPathB;
  132. }
  133. public void Update(float t)
  134. {
  135. if (State == 0)
  136. {
  137. if (a.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.idle) &&
  138. b.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.idle))
  139. {
  140. State = 1;
  141. int odds = Random.Range(0, 100);
  142. if (odds < 50)
  143. {
  144. SetBesselA();
  145. }
  146. else
  147. {
  148. SetBesselB();
  149. }
  150. _unRegister = a.GameObject.OnTriggerEnterEvent(this, OnTriggerEnter);
  151. _isOne = false;
  152. _currTime = 0;
  153. }
  154. }
  155. if (State == 1)
  156. {
  157. _currTime += t * CustomTweenManager.AnimationCurveLibrary.fabaoSpeed;
  158. float v = CustomTweenManager.AnimationCurveLibrary.fabaoDuiPing.Evaluate(_currTime);
  159. BesselPath besselPath = _isOne ? _besselPathB : _besselPathA;
  160. Vector3 a1 = besselPath.CalculatePoint(v);
  161. Vector3 a2 = besselPath.CalculatePoint(v - 0.01f);
  162. Vector3 b1 = besselPath.CalculatePoint(1 - v);
  163. Vector3 b2 = besselPath.CalculatePoint(1 - v + 0.01f);
  164. a.combatHeroGameObject.SetPosition(a1);
  165. a.GameObject.transform.rotation = Quaternion.LookRotation((a1 - a2).normalized);
  166. b.combatHeroGameObject.SetPosition(b1);
  167. b.GameObject.transform.rotation = Quaternion.LookRotation((b1 - b2).normalized);
  168. if (_currTime >= 1)
  169. {
  170. _currTime = 0;
  171. _isOne = !_isOne;
  172. }
  173. }
  174. else if (State == 2)
  175. {
  176. _currTime += t;
  177. if (_currTime >2)
  178. {
  179. State = 3;
  180. _currTime = 0;
  181. CombatCalculateTool.Instance.FaBaoPengZhuang(a,b);
  182. CombatMagicWeaponEntity combatMagicWeaponEntityA = a;
  183. CombatMagicWeaponEntity combatMagicWeaponEntityB = b;
  184. if (combatMagicWeaponEntityA.HpBl<=0)
  185. {
  186. combatMagicWeaponEntityA.MagicWeaponDie();
  187. }
  188. if (combatMagicWeaponEntityB.HpBl<=0)
  189. {
  190. combatMagicWeaponEntityB.MagicWeaponDie();
  191. }
  192. }
  193. }
  194. }
  195. public void SetState(int state)
  196. {
  197. State = state;
  198. }
  199. public override void ActiveObj()
  200. {
  201. }
  202. public override void DormancyObj()
  203. {
  204. a = null;
  205. b = null;
  206. }
  207. public void Finish()
  208. {
  209. LogTool.Log("碰撞完成");
  210. if (a.HpBl > 0)
  211. {
  212. a.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  213. a.MagicWeaponCollisionId = -1;
  214. b.MagicWeaponCollisionId = -1;
  215. }
  216. if (b.HpBl > 0)
  217. {
  218. b.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  219. a.MagicWeaponCollisionId = -1;
  220. b.MagicWeaponCollisionId = -1;
  221. }
  222. GObjectPool.Instance.Recycle(ParticleSystemPool);
  223. ParticleSystemPool = null;
  224. triigerCount = 0;
  225. }
  226. public string tag { get; }
  227. }
  228. }