MagicWeaponCollisionInfo.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. protected void SetBesselA()
  86. {
  87. _besselPathA = new BesselPath();
  88. _besselPathA.controlPoints.Add(a.dotPos);
  89. _besselPathA.controlPoints.Add(a.GameObject.transform.TransformPoint(new Vector3(-9.87f, 4, 2)));
  90. _besselPathA.controlPoints.Add(b.GameObject.transform.TransformPoint(new Vector3(12.66f, 1, -5)));
  91. _besselPathA.controlPoints.Add(b.dotPos);
  92. // GameObject G = new GameObject("BesselPathMono11");
  93. // BesselPathMono besselPathMono = G.AddComponent<BesselPathMono>();
  94. // besselPathMono.isRun = true;
  95. // besselPathMono.BesselPath = _besselPathA;
  96. _besselPathB = new BesselPath();
  97. _besselPathB.controlPoints.Add(b.dotPos);
  98. _besselPathB.controlPoints.Add(
  99. b.GameObject.transform.TransformPoint(new Vector3(-11.89f, -0.29f, 3.28f)));
  100. _besselPathB.controlPoints.Add(
  101. a.GameObject.transform.TransformPoint(new Vector3(12.67f, -3.03f, -3.5f)));
  102. _besselPathB.controlPoints.Add(a.dotPos);
  103. // GameObject G2 = new GameObject("BesselPathMono22");
  104. // BesselPathMono besselPathMono2 = G2.AddComponent<BesselPathMono>();
  105. // besselPathMono2.isRun = true;
  106. // besselPathMono2.BesselPath = _besselPathB;
  107. }
  108. protected void SetBesselB()
  109. {
  110. _besselPathA = new BesselPath();
  111. _besselPathA.controlPoints.Add(a.dotPos);
  112. _besselPathA.controlPoints.Add(a.GameObject.transform.TransformPoint(new Vector3(-3.41f, 4, -7.23f)));
  113. _besselPathA.controlPoints.Add(b.GameObject.transform.TransformPoint(new Vector3(2.64f, 1, -5)));
  114. _besselPathA.controlPoints.Add(b.dotPos);
  115. GameObject G = new GameObject("BesselPathMono11");
  116. BesselPathMono besselPathMono = G.AddComponent<BesselPathMono>();
  117. besselPathMono.isRun = true;
  118. besselPathMono.BesselPath = _besselPathA;
  119. _besselPathB = new BesselPath();
  120. _besselPathB.controlPoints.Add(b.dotPos);
  121. _besselPathB.controlPoints.Add(
  122. b.GameObject.transform.TransformPoint(new Vector3(-8.5f, -3.93f, 9.58f)));
  123. _besselPathB.controlPoints.Add(
  124. a.GameObject.transform.TransformPoint(new Vector3(1.45f, -3.03f, 4.6f)));
  125. _besselPathB.controlPoints.Add(a.dotPos);
  126. GameObject G2 = new GameObject("BesselPathMono22");
  127. BesselPathMono besselPathMono2 = G2.AddComponent<BesselPathMono>();
  128. besselPathMono2.isRun = true;
  129. besselPathMono2.BesselPath = _besselPathB;
  130. }
  131. public void Update(float t)
  132. {
  133. if (State == 0)
  134. {
  135. if (a.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.idle) &&
  136. b.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.idle))
  137. {
  138. State = 1;
  139. int odds = Random.Range(0, 100);
  140. if (odds < 50)
  141. {
  142. SetBesselA();
  143. }
  144. else
  145. {
  146. SetBesselB();
  147. }
  148. _unRegister = a.GameObject.OnTriggerEnterEvent(this, OnTriggerEnter);
  149. _isOne = false;
  150. _currTime = 0;
  151. }
  152. }
  153. if (State == 1)
  154. {
  155. _currTime += t * 0.7f;
  156. float v = CustomTweenManager.AnimationCurveLibrary.fabaoDuiPing.Evaluate(_currTime);
  157. BesselPath besselPath = _isOne ? _besselPathB : _besselPathA;
  158. Vector3 a1 = besselPath.CalculatePoint(v);
  159. Vector3 a2 = besselPath.CalculatePoint(v - 0.01f);
  160. Vector3 b1 = besselPath.CalculatePoint(1 - v);
  161. Vector3 b2 = besselPath.CalculatePoint(1 - v + 0.01f);
  162. a.combatHeroGameObject.SetPosition(a1);
  163. a.GameObject.transform.rotation = Quaternion.LookRotation((a1 - a2).normalized);
  164. b.combatHeroGameObject.SetPosition(b1);
  165. b.GameObject.transform.rotation = Quaternion.LookRotation((b1 - b2).normalized);
  166. if (_currTime >= 1)
  167. {
  168. _currTime = 0;
  169. _isOne = !_isOne;
  170. }
  171. }
  172. else if (State == 2)
  173. {
  174. _currTime += t;
  175. if (_currTime > 0.1f)
  176. {
  177. _currTime = 0;
  178. if (a != null)
  179. {
  180. a.ReduceHp(1);
  181. }
  182. if (b != null)
  183. {
  184. b.ReduceHp(1);
  185. }
  186. }
  187. }
  188. }
  189. public void SetState(int state)
  190. {
  191. State = state;
  192. }
  193. public override void ActiveObj()
  194. {
  195. }
  196. public override void DormancyObj()
  197. {
  198. a = null;
  199. b = null;
  200. }
  201. public void Finish()
  202. {
  203. LogTool.Log("碰撞完成");
  204. if (a.HpBl > 0)
  205. {
  206. a.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  207. a.MagicWeaponCollisionId = -1;
  208. b.MagicWeaponCollisionId = -1;
  209. }
  210. if (b.HpBl > 0)
  211. {
  212. b.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  213. a.MagicWeaponCollisionId = -1;
  214. b.MagicWeaponCollisionId = -1;
  215. }
  216. GObjectPool.Instance.Recycle(ParticleSystemPool);
  217. ParticleSystemPool = null;
  218. }
  219. public string tag { get; }
  220. }
  221. }