MagicWeaponCollisionInfo.cs 14 KB

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