MagicWeaponCollisionInfo.cs 9.0 KB

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