MagicWeaponCollisionInfo.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. if (!_isPengZhuang)
  119. {
  120. GObjectPool.Instance.Recycle(ParticleSystemPool);
  121. }
  122. });
  123. }
  124. else
  125. {
  126. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle("fx_fb_duipin_hit",
  127. a.dotPos, null, false, null, delegate(ParticleSystemPool particleSystemPool)
  128. {
  129. particleSystemPool.transform.rotation =
  130. a.GameObject.transform.rotation;
  131. });
  132. triigerCount++;
  133. // a.ReduceHp(40);
  134. // _trigger = true;
  135. // _triggerTime = 0.5f;
  136. }
  137. }
  138. protected void SetBesselA()
  139. {
  140. _besselPathA = new BesselPath();
  141. _besselPathA.controlPoints.Add(a.dotPos);
  142. _besselPathA.controlPoints.Add(a.GameObject.transform.TransformPoint(new Vector3(-9.87f, 4, 2)));
  143. _besselPathA.controlPoints.Add(b.GameObject.transform.TransformPoint(new Vector3(-12.66f, 1, 5)));
  144. _besselPathA.controlPoints.Add(b.dotPos);
  145. GameObject G1 = new GameObject("BesselPathMono33");
  146. BesselPathMono besselPathMono1 = G1.AddComponent<BesselPathMono>();
  147. besselPathMono1.isRun = true;
  148. besselPathMono1.BesselPath = _besselPathA;
  149. _besselPathB = new BesselPath();
  150. _besselPathB.controlPoints.Add(b.dotPos);
  151. _besselPathB.controlPoints.Add(
  152. b.GameObject.transform.TransformPoint(new Vector3(11.89f, -0.29f, -3.28f)));
  153. _besselPathB.controlPoints.Add(
  154. a.GameObject.transform.TransformPoint(new Vector3(12.67f, -3.03f, -3.5f)));
  155. _besselPathB.controlPoints.Add(a.dotPos);
  156. GameObject G2 = new GameObject("BesselPathMono44");
  157. BesselPathMono besselPathMono2 = G2.AddComponent<BesselPathMono>();
  158. besselPathMono2.isRun = true;
  159. besselPathMono2.BesselPath = _besselPathB;
  160. }
  161. protected void SetBesselB()
  162. {
  163. _besselPathA = new BesselPath();
  164. _besselPathA.controlPoints.Add(a.dotPos);
  165. _besselPathA.controlPoints.Add(a.GameObject.transform.TransformPoint(new Vector3(-3.41f, 4, -7.23f)));
  166. _besselPathA.controlPoints.Add(b.GameObject.transform.TransformPoint(new Vector3(-2.64f, 1, 5)));
  167. _besselPathA.controlPoints.Add(b.dotPos);
  168. GameObject G = new GameObject("BesselPathMono11");
  169. BesselPathMono besselPathMono = G.AddComponent<BesselPathMono>();
  170. besselPathMono.isRun = true;
  171. besselPathMono.BesselPath = _besselPathA;
  172. _besselPathB = new BesselPath();
  173. _besselPathB.controlPoints.Add(b.dotPos);
  174. _besselPathB.controlPoints.Add(
  175. b.GameObject.transform.TransformPoint(new Vector3(8.5f, -3.93f, -9.58f)));
  176. _besselPathB.controlPoints.Add(
  177. a.GameObject.transform.TransformPoint(new Vector3(1.45f, -3.03f, 4.6f)));
  178. _besselPathB.controlPoints.Add(a.dotPos);
  179. GameObject G2 = new GameObject("BesselPathMono22");
  180. BesselPathMono besselPathMono2 = G2.AddComponent<BesselPathMono>();
  181. besselPathMono2.isRun = true;
  182. besselPathMono2.BesselPath = _besselPathB;
  183. }
  184. public void Update(float t)
  185. {
  186. if (State == 0)
  187. {
  188. if (a.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.idle) &&
  189. b.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.idle))
  190. {
  191. State = 1;
  192. int odds = Random.Range(0, 100);
  193. if (odds < 50)
  194. {
  195. SetBesselA();
  196. }
  197. else
  198. {
  199. SetBesselB();
  200. }
  201. _unRegister = a.GameObject.OnTriggerEnterEvent(this, OnTriggerEnter);
  202. _isOne = false;
  203. _currTime = 0;
  204. }
  205. }
  206. if (State == 1)
  207. {
  208. _currTime += t * CustomTweenManager.AnimationCurveLibrary.fabaoSpeed;
  209. float v = CustomTweenManager.AnimationCurveLibrary.fabaoDuiPing.Evaluate(_currTime);
  210. BesselPath besselPath = _isOne ? _besselPathB : _besselPathA;
  211. Vector3 a1 = besselPath.CalculatePoint(v);
  212. Vector3 a2 = besselPath.CalculatePoint(v - 0.01f);
  213. Vector3 b1 = besselPath.CalculatePoint(1 - v);
  214. Vector3 b2 = besselPath.CalculatePoint(1 - v + 0.01f);
  215. a.combatHeroGameObject.SetPosition(a1);
  216. a.GameObject.transform.rotation = Quaternion.LookRotation((a1 - a2).normalized);
  217. b.combatHeroGameObject.SetPosition(b1);
  218. b.GameObject.transform.rotation = Quaternion.LookRotation((b1 - b2).normalized);
  219. if (_currTime > 0.48f)
  220. {
  221. PongZhuang();
  222. }
  223. if (_currTime >= 1)
  224. {
  225. _currTime = 0;
  226. _isOne = !_isOne;
  227. _isPengZhuang = false;
  228. }
  229. }
  230. else if (State == 2)
  231. {
  232. _currTime += t;
  233. if (_currTime > 2)
  234. {
  235. State = 3;
  236. _currTime = 0;
  237. CombatCalculateTool.Instance.FaBaoPengZhuang(a, b);
  238. CombatMagicWeaponEntity combatMagicWeaponEntityA = a;
  239. CombatMagicWeaponEntity combatMagicWeaponEntityB = b;
  240. if (combatMagicWeaponEntityA.HpBl <= 0)
  241. {
  242. combatMagicWeaponEntityA.MagicWeaponDie();
  243. }
  244. if (combatMagicWeaponEntityB.HpBl <= 0)
  245. {
  246. combatMagicWeaponEntityB.MagicWeaponDie();
  247. }
  248. }
  249. }
  250. }
  251. public void SetState(int state)
  252. {
  253. State = state;
  254. }
  255. public override void ActiveObj()
  256. {
  257. }
  258. public override void DormancyObj()
  259. {
  260. a = null;
  261. b = null;
  262. }
  263. public void Finish()
  264. {
  265. LogTool.Log("碰撞完成");
  266. if (a.HpBl > 0)
  267. {
  268. a.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  269. a.MagicWeaponCollisionId = -1;
  270. b.MagicWeaponCollisionId = -1;
  271. }
  272. if (b.HpBl > 0)
  273. {
  274. b.CombatAIBasic.ChangeState(CombatHeroStateType.att);
  275. a.MagicWeaponCollisionId = -1;
  276. b.MagicWeaponCollisionId = -1;
  277. }
  278. GObjectPool.Instance.Recycle(ParticleSystemPool);
  279. ParticleSystemPool = null;
  280. triigerCount = 0;
  281. _isPengZhuang = false;
  282. }
  283. public string tag { get; }
  284. }
  285. }