MagicWeaponCollisionInfo.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. private bool _isPengZhuang;
  26. protected ParticleSystemPool ParticleSystemPool;
  27. private int triigerCount;
  28. public void Init(CombatMagicWeaponEntity a, CombatMagicWeaponEntity b, int id)
  29. {
  30. this.id = id;
  31. if (a.IsEnemy)
  32. {
  33. (a, b) = (b, a);
  34. }
  35. this.a = a;
  36. this.b = b;
  37. a.MagicWeaponCollisionId = id;
  38. b.MagicWeaponCollisionId = id;
  39. State = 0;
  40. }
  41. private void OnTriggerEnter(Collider collider, ITriggerEntity triggerEntity)
  42. {
  43. // HeroEntityMono heroEntityMono = collider.GetComponent<HeroEntityMono>();
  44. // if (heroEntityMono == null || (heroEntityMono.combatHeroEntity != b))
  45. // {
  46. // return;
  47. // }
  48. //
  49. // if (State != 1)
  50. // {
  51. // return;
  52. // }
  53. //
  54. // if (triigerCount >= 2)
  55. // {
  56. // MagicWeaponPingDouState.MagicWeaponPingDouData rollingStateData =
  57. // CObjectPool.Instance.Fetch<MagicWeaponPingDouState.MagicWeaponPingDouData>();
  58. // rollingStateData.target = b;
  59. //
  60. // a.CombatAIBasic.ChangeState(CombatHeroStateType.MagicWeaponPingDou,
  61. // rollingStateData);
  62. // MagicWeaponPingDouState.MagicWeaponPingDouData rollingStateData2 =
  63. // CObjectPool.Instance.Fetch<MagicWeaponPingDouState.MagicWeaponPingDouData>();
  64. // rollingStateData.target = a;
  65. // b.CombatAIBasic.ChangeState(CombatHeroStateType.MagicWeaponPingDou,
  66. // rollingStateData2);
  67. // State = 2;
  68. // _currTime = 0;
  69. // CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle("fx_fb_duipin_dian",
  70. // a.dotPos, null, false, null, delegate(ParticleSystemPool particleSystemPool)
  71. // {
  72. // particleSystemPool.transform.rotation =
  73. // a.GameObject.transform.rotation;
  74. // ParticleSystemPool = particleSystemPool;
  75. // });
  76. // }
  77. // else
  78. // {
  79. // CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle("fx_fb_duipin_hit",
  80. // collider.transform.position, null, false, null, delegate(ParticleSystemPool particleSystemPool)
  81. // {
  82. // particleSystemPool.transform.rotation =
  83. // a.GameObject.transform.rotation;
  84. // });
  85. // triigerCount++;
  86. // // a.ReduceHp(40);
  87. // // _trigger = true;
  88. // // _triggerTime = 0.5f;
  89. // }
  90. }
  91. protected void PongZhuang()
  92. {
  93. if (State != 1||_isPengZhuang)
  94. {
  95. return;
  96. }
  97. _isPengZhuang = true;
  98. if (triigerCount >= 1)
  99. {
  100. MagicWeaponPingDouState.MagicWeaponPingDouData rollingStateData =
  101. CObjectPool.Instance.Fetch<MagicWeaponPingDouState.MagicWeaponPingDouData>();
  102. rollingStateData.target = b;
  103. a.CombatAIBasic.ChangeState(CombatHeroStateType.MagicWeaponPingDou,
  104. rollingStateData);
  105. MagicWeaponPingDouState.MagicWeaponPingDouData rollingStateData2 =
  106. CObjectPool.Instance.Fetch<MagicWeaponPingDouState.MagicWeaponPingDouData>();
  107. rollingStateData.target = a;
  108. b.CombatAIBasic.ChangeState(CombatHeroStateType.MagicWeaponPingDou,
  109. rollingStateData2);
  110. State = 2;
  111. _currTime = 0;
  112. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle("fx_fb_duipin_dian",
  113. a.dotPos, null, false, null, delegate(ParticleSystemPool particleSystemPool)
  114. {
  115. particleSystemPool.transform.rotation =
  116. a.GameObject.transform.rotation;
  117. ParticleSystemPool = particleSystemPool;
  118. });
  119. }
  120. else
  121. {
  122. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle("fx_fb_duipin_hit",
  123. a.dotPos, null, false, null, delegate(ParticleSystemPool particleSystemPool)
  124. {
  125. particleSystemPool.transform.rotation =
  126. a.GameObject.transform.rotation;
  127. });
  128. triigerCount++;
  129. // a.ReduceHp(40);
  130. // _trigger = true;
  131. // _triggerTime = 0.5f;
  132. }
  133. }
  134. protected void SetBesselA()
  135. {
  136. _besselPathA = new BesselPath();
  137. _besselPathA.controlPoints.Add(a.dotPos);
  138. _besselPathA.controlPoints.Add(a.GameObject.transform.TransformPoint(new Vector3(-9.87f, 4, 2)));
  139. _besselPathA.controlPoints.Add(b.GameObject.transform.TransformPoint(new Vector3(-12.66f, 1, 5)));
  140. _besselPathA.controlPoints.Add(b.dotPos);
  141. GameObject G1 = new GameObject("BesselPathMono33");
  142. BesselPathMono besselPathMono1 = G1.AddComponent<BesselPathMono>();
  143. besselPathMono1.isRun = true;
  144. besselPathMono1.BesselPath = _besselPathA;
  145. _besselPathB = new BesselPath();
  146. _besselPathB.controlPoints.Add(b.dotPos);
  147. _besselPathB.controlPoints.Add(
  148. b.GameObject.transform.TransformPoint(new Vector3(11.89f, -0.29f, -3.28f)));
  149. _besselPathB.controlPoints.Add(
  150. a.GameObject.transform.TransformPoint(new Vector3(12.67f, -3.03f, -3.5f)));
  151. _besselPathB.controlPoints.Add(a.dotPos);
  152. GameObject G2 = new GameObject("BesselPathMono44");
  153. BesselPathMono besselPathMono2 = G2.AddComponent<BesselPathMono>();
  154. besselPathMono2.isRun = true;
  155. besselPathMono2.BesselPath = _besselPathB;
  156. }
  157. protected void SetBesselB()
  158. {
  159. _besselPathA = new BesselPath();
  160. _besselPathA.controlPoints.Add(a.dotPos);
  161. _besselPathA.controlPoints.Add(a.GameObject.transform.TransformPoint(new Vector3(-3.41f, 4, -7.23f)));
  162. _besselPathA.controlPoints.Add(b.GameObject.transform.TransformPoint(new Vector3(-2.64f, 1, 5)));
  163. _besselPathA.controlPoints.Add(b.dotPos);
  164. GameObject G = new GameObject("BesselPathMono11");
  165. BesselPathMono besselPathMono = G.AddComponent<BesselPathMono>();
  166. besselPathMono.isRun = true;
  167. besselPathMono.BesselPath = _besselPathA;
  168. _besselPathB = new BesselPath();
  169. _besselPathB.controlPoints.Add(b.dotPos);
  170. _besselPathB.controlPoints.Add(
  171. b.GameObject.transform.TransformPoint(new Vector3(8.5f, -3.93f, -9.58f)));
  172. _besselPathB.controlPoints.Add(
  173. a.GameObject.transform.TransformPoint(new Vector3(1.45f, -3.03f, 4.6f)));
  174. _besselPathB.controlPoints.Add(a.dotPos);
  175. GameObject G2 = new GameObject("BesselPathMono22");
  176. BesselPathMono besselPathMono2 = G2.AddComponent<BesselPathMono>();
  177. besselPathMono2.isRun = true;
  178. besselPathMono2.BesselPath = _besselPathB;
  179. }
  180. public void Update(float t)
  181. {
  182. if (State == 0)
  183. {
  184. if (a.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.idle) &&
  185. b.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.idle))
  186. {
  187. State = 1;
  188. int odds = Random.Range(0, 100);
  189. if (odds < 50)
  190. {
  191. SetBesselA();
  192. }
  193. else
  194. {
  195. SetBesselB();
  196. }
  197. _unRegister = a.GameObject.OnTriggerEnterEvent(this, OnTriggerEnter);
  198. _isOne = false;
  199. _currTime = 0;
  200. }
  201. }
  202. if (State == 1)
  203. {
  204. _currTime += t * CustomTweenManager.AnimationCurveLibrary.fabaoSpeed;
  205. float v = CustomTweenManager.AnimationCurveLibrary.fabaoDuiPing.Evaluate(_currTime);
  206. BesselPath besselPath = _isOne ? _besselPathB : _besselPathA;
  207. Vector3 a1 = besselPath.CalculatePoint(v);
  208. Vector3 a2 = besselPath.CalculatePoint(v - 0.01f);
  209. Vector3 b1 = besselPath.CalculatePoint(1 - v);
  210. Vector3 b2 = besselPath.CalculatePoint(1 - v + 0.01f);
  211. a.combatHeroGameObject.SetPosition(a1);
  212. a.GameObject.transform.rotation = Quaternion.LookRotation((a1 - a2).normalized);
  213. b.combatHeroGameObject.SetPosition(b1);
  214. b.GameObject.transform.rotation = Quaternion.LookRotation((b1 - b2).normalized);
  215. if (_currTime > 0.48f)
  216. {
  217. PongZhuang();
  218. }
  219. if (_currTime >= 1)
  220. {
  221. _currTime = 0;
  222. _isOne = !_isOne;
  223. _isPengZhuang = false;
  224. }
  225. }
  226. else if (State == 2)
  227. {
  228. _currTime += t;
  229. if (_currTime >2)
  230. {
  231. State = 3;
  232. _currTime = 0;
  233. CombatCalculateTool.Instance.FaBaoPengZhuang(a,b);
  234. CombatMagicWeaponEntity combatMagicWeaponEntityA = a;
  235. CombatMagicWeaponEntity combatMagicWeaponEntityB = b;
  236. if (combatMagicWeaponEntityA.HpBl<=0)
  237. {
  238. combatMagicWeaponEntityA.MagicWeaponDie();
  239. }
  240. if (combatMagicWeaponEntityB.HpBl<=0)
  241. {
  242. combatMagicWeaponEntityB.MagicWeaponDie();
  243. }
  244. }
  245. }
  246. }
  247. public void SetState(int state)
  248. {
  249. State = state;
  250. }
  251. public override void ActiveObj()
  252. {
  253. }
  254. public override void DormancyObj()
  255. {
  256. a = null;
  257. b = null;
  258. }
  259. public void Finish()
  260. {
  261. LogTool.Log("碰撞完成");
  262. if (a.HpBl > 0)
  263. {
  264. a.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  265. a.MagicWeaponCollisionId = -1;
  266. b.MagicWeaponCollisionId = -1;
  267. }
  268. if (b.HpBl > 0)
  269. {
  270. b.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  271. a.MagicWeaponCollisionId = -1;
  272. b.MagicWeaponCollisionId = -1;
  273. }
  274. GObjectPool.Instance.Recycle(ParticleSystemPool);
  275. ParticleSystemPool = null;
  276. triigerCount = 0;
  277. _isPengZhuang = false;
  278. }
  279. public string tag { get; }
  280. }
  281. }