MagicWeaponCollisionInfo.cs 13 KB

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