MagicWeaponCollisionInfo.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. public void Init(CombatMagicWeaponEntity a, CombatMagicWeaponEntity b, int id)
  27. {
  28. this.id = id;
  29. if (a.IsEnemy)
  30. {
  31. (a, b) = (b, a);
  32. }
  33. this.a = a;
  34. this.b = b;
  35. a.MagicWeaponCollisionId = id;
  36. b.MagicWeaponCollisionId = id;
  37. State = 0;
  38. }
  39. private void OnTriggerEnter(Collider collider, ITriggerEntity triggerEntity)
  40. {
  41. HeroEntityMono heroEntityMono = collider.GetComponent<HeroEntityMono>();
  42. if (heroEntityMono == null || (heroEntityMono.combatHeroEntity != b))
  43. {
  44. return;
  45. }
  46. if (State != 1)
  47. {
  48. return;
  49. }
  50. if ((a.HpBl <= 30 || b.HpBl < 20))
  51. {
  52. MagicWeaponPingDouState.MagicWeaponPingDouData rollingStateData =
  53. CObjectPool.Instance.Fetch<MagicWeaponPingDouState.MagicWeaponPingDouData>();
  54. rollingStateData.target = b;
  55. a.CombatAIBasic.ChangeState(CombatHeroStateType.MagicWeaponPingDou,
  56. rollingStateData);
  57. MagicWeaponPingDouState.MagicWeaponPingDouData rollingStateData2 =
  58. CObjectPool.Instance.Fetch<MagicWeaponPingDouState.MagicWeaponPingDouData>();
  59. rollingStateData.target = a;
  60. b.CombatAIBasic.ChangeState(CombatHeroStateType.MagicWeaponPingDou,
  61. rollingStateData2);
  62. State = 2;
  63. _currTime = 0;
  64. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle("fx_fb_duipin_dian",
  65. a.dotPos, null, false, null, delegate(ParticleSystemPool particleSystemPool)
  66. {
  67. particleSystemPool.transform.rotation =
  68. a.GameObject.transform.rotation;
  69. ParticleSystemPool = particleSystemPool;
  70. });
  71. }
  72. else
  73. {
  74. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle("fx_fb_duipin_hit",
  75. collider.transform.position, null, false, null, delegate(ParticleSystemPool particleSystemPool)
  76. {
  77. particleSystemPool.transform.rotation =
  78. a.GameObject.transform.rotation;
  79. });
  80. a.ReduceHp(40);
  81. // _trigger = true;
  82. // _triggerTime = 0.5f;
  83. }
  84. }
  85. public void Update(float t)
  86. {
  87. if (State == 0)
  88. {
  89. if (a.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.idle) &&
  90. b.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.idle))
  91. {
  92. State = 1;
  93. _besselPathA = new BesselPath();
  94. _besselPathA.controlPoints.Add(a.dotPos);
  95. _besselPathA.controlPoints.Add(a.GameObject.transform.TransformPoint(new Vector3(-9.87f, 4, 2)));
  96. _besselPathA.controlPoints.Add(b.GameObject.transform.TransformPoint(new Vector3(12.66f, 1, -5)));
  97. _besselPathA.controlPoints.Add(b.dotPos);
  98. GameObject G = new GameObject("BesselPathMono11");
  99. BesselPathMono besselPathMono = G.AddComponent<BesselPathMono>();
  100. besselPathMono.isRun = true;
  101. besselPathMono.BesselPath = _besselPathA;
  102. _besselPathB = new BesselPath();
  103. _besselPathB.controlPoints.Add(b.dotPos);
  104. _besselPathB.controlPoints.Add(
  105. b.GameObject.transform.TransformPoint(new Vector3(-11.89f, -0.29f, 3.28f)));
  106. _besselPathB.controlPoints.Add(
  107. a.GameObject.transform.TransformPoint(new Vector3(12.67f, -3.03f, -3.5f)));
  108. _besselPathB.controlPoints.Add(a.dotPos);
  109. GameObject G2 = new GameObject("BesselPathMono22");
  110. BesselPathMono besselPathMono2 = G2.AddComponent<BesselPathMono>();
  111. besselPathMono2.isRun = true;
  112. besselPathMono2.BesselPath = _besselPathB;
  113. _unRegister = a.GameObject.OnTriggerEnterEvent(this, OnTriggerEnter);
  114. _isOne = false;
  115. _currTime = 0;
  116. }
  117. }
  118. if (State == 1)
  119. {
  120. _currTime += t * 0.7f;
  121. float v= CustomTweenManager.AnimationCurveLibrary.fabaoDuiPing.Evaluate(_currTime);
  122. BesselPath besselPath = _isOne ? _besselPathB : _besselPathA;
  123. Vector3 a1 = besselPath.CalculatePoint(v);
  124. Vector3 a2 = besselPath.CalculatePoint(v - 0.01f);
  125. Vector3 b1 = besselPath.CalculatePoint(1 - v);
  126. Vector3 b2 = besselPath.CalculatePoint(1 - v + 0.01f);
  127. a.combatHeroGameObject.SetPosition(a1);
  128. a.GameObject.transform.rotation = Quaternion.LookRotation((a1 - a2).normalized);
  129. b.combatHeroGameObject.SetPosition(b1);
  130. b.GameObject.transform.rotation = Quaternion.LookRotation((b1 - b2).normalized);
  131. if (_currTime >= 1)
  132. {
  133. _currTime = 0;
  134. _isOne = !_isOne;
  135. }
  136. }
  137. else if (State == 2)
  138. {
  139. _currTime += t;
  140. if (_currTime > 0.1f)
  141. {
  142. _currTime = 0;
  143. if (a != null)
  144. {
  145. a.ReduceHp(1);
  146. }
  147. if (b != null)
  148. {
  149. b.ReduceHp(1);
  150. }
  151. }
  152. }
  153. }
  154. public void SetState(int state)
  155. {
  156. State = state;
  157. }
  158. public override void ActiveObj()
  159. {
  160. }
  161. public override void DormancyObj()
  162. {
  163. a = null;
  164. b = null;
  165. }
  166. public void Finish()
  167. {
  168. LogTool.Log("碰撞完成");
  169. if (a.HpBl > 0)
  170. {
  171. a.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  172. a.MagicWeaponCollisionId = -1;
  173. b.MagicWeaponCollisionId = -1;
  174. }
  175. if (b.HpBl > 0)
  176. {
  177. b.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  178. a.MagicWeaponCollisionId = -1;
  179. b.MagicWeaponCollisionId = -1;
  180. }
  181. GObjectPool.Instance.Recycle(ParticleSystemPool);
  182. ParticleSystemPool = null;
  183. }
  184. public string tag { get; }
  185. }
  186. }