MagicWeaponCollisionInfo.cs 13 KB

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