MagicWeaponCollisionInfo.cs 13 KB

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