EnemyDaoPaoHurt.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. public class EnemyDaoPaoHurt : EnemyBaseHurt
  5. {
  6. protected override void Update()
  7. {
  8. base.Update();
  9. Vector2? vector = this.atkFollowPos;
  10. if (vector != null)
  11. {
  12. Vector3 position = base.player.transform.position;
  13. Vector2? vector2 = this.atkFollowPos;
  14. Vector3 position2 = position - ((vector2 == null) ? default(Vector3) : (Vector3)vector2.GetValueOrDefault());
  15. position2.y = Mathf.Clamp(position2.y, LayerManager.YNum.GetGroundHeight(base.gameObject) + 1f, float.PositiveInfinity);
  16. position2.z = LayerManager.ZNum.MMiddleE(this.eAttr.rankType);
  17. base.transform.position = position2;
  18. this.atkFollowTime += Time.unscaledDeltaTime;
  19. if (this.atkFollowTime >= this.atkFollowEnd)
  20. {
  21. this.atkFollowPos = null;
  22. }
  23. }
  24. }
  25. protected override void Init()
  26. {
  27. this.daoPao = base.GetComponent<DaoPaoAnimEvent>();
  28. this.defaultAnimName = "Hit1";
  29. this.defaultAirAnimName = "HitToFly1";
  30. this.airDieAnimName = "Fall";
  31. this.airDieHitGroundAnimName = "AirDie";
  32. this.flyToFallAnimName = "AirDiePre";
  33. this.hurtData = SingletonMono<EnemyDataPreload>.Instance.hurt[EnemyType.刀炮混合];
  34. }
  35. public override void SetHitSpeed(Vector2 speed)
  36. {
  37. if (this.playerAtkName == "UpRising" || this.playerAtkName == "AtkUpRising" || this.playerAtkName == "AtkRollEnd" || this.playerAtkName == "NewExecute2_1")
  38. {
  39. this.daoPao.maxFlyHeight = 4.5f;
  40. }
  41. else
  42. {
  43. this.daoPao.maxFlyHeight = -1f;
  44. }
  45. base.SetHitSpeed(speed);
  46. }
  47. protected override void SpAttack()
  48. {
  49. if (this.eAttr.currentActionInterruptPoint < this.eAttr.actionInterruptPoint)
  50. {
  51. return;
  52. }
  53. if (this.playerAtkName == "RollEnd")
  54. {
  55. Vector2? vector = this.atkFollowPos;
  56. if (vector != null)
  57. {
  58. this.atkFollowPos = null;
  59. }
  60. return;
  61. }
  62. if (this.playerAtkName == "RollGround")
  63. {
  64. Vector2? vector2 = this.atkFollowPos;
  65. if (vector2 == null)
  66. {
  67. Transform transform = base.player.GetComponentInChildren<PlayerAtk>().transform;
  68. this.atkFollowPos = new Vector2?((transform.position - base.transform.position) * 0.9f);
  69. }
  70. this.atkFollowTime = 0f;
  71. this.atkFollowEnd = 0.2f;
  72. return;
  73. }
  74. if (this.playerAtkName == "RollReady" || this.playerAtkName == "BladeStormReady")
  75. {
  76. Vector2? vector3 = this.atkFollowPos;
  77. if (vector3 == null)
  78. {
  79. this.atkFollowPos = new Vector2?((base.player.transform.position - base.transform.position) * 0.7f);
  80. }
  81. this.atkFollowTime = 0f;
  82. this.atkFollowEnd = 0.2f;
  83. return;
  84. }
  85. if (this.playerAtkName == "Atk4")
  86. {
  87. base.StartCoroutine(this.CloseToPlayer());
  88. return;
  89. }
  90. this.atkFollowTime = 0f;
  91. this.atkFollowEnd = 0f;
  92. }
  93. private IEnumerator CloseToPlayer()
  94. {
  95. this.closeToPlayer.state.SetAnimation(0, "Show", false);
  96. this.closeToPlayer.skeleton.SetToSetupPose();
  97. Vector3 endPos = base.player.transform.position + Vector3.right * (float)base.pAttr.faceDir * UnityEngine.Random.Range(0.8f, 1.5f);
  98. endPos.z = LayerManager.ZNum.MMiddleE(this.eAttr.rankType);
  99. Vector3 startPos = base.transform.position;
  100. for (int i = 0; i < 5; i++)
  101. {
  102. yield return new WaitForFixedUpdate();
  103. }
  104. for (int j = 0; j < 6; j++)
  105. {
  106. base.transform.position = Vector3.Lerp(startPos, endPos, (float)j / 5f);
  107. yield return new WaitForFixedUpdate();
  108. }
  109. yield break;
  110. }
  111. protected override void ExecuteFollow()
  112. {
  113. this.action.AnimChangeState(DaoPaoAction.StateEnum.Execute, 1f);
  114. base.ExecuteFollow();
  115. }
  116. protected override void PlayHurtAudio()
  117. {
  118. R.Audio.PlayEffect(401, new Vector3?(base.transform.position));
  119. if (base.PlaySpHurtAudio())
  120. {
  121. R.Audio.PlayEffect(UnityEngine.Random.Range(57, 59), new Vector3?(base.transform.position));
  122. }
  123. }
  124. protected override void ExecuteDie()
  125. {
  126. base.ExecuteDie();
  127. this.eAttr.timeController.SetGravity(1f);
  128. this.SetHitSpeed(Vector2.zero);
  129. this.SpDieEffect();
  130. }
  131. public override void EnemyDie()
  132. {
  133. if (this.deadFlag)
  134. {
  135. return;
  136. }
  137. base.EnemyDie();
  138. if (this.eAttr.isOnGround)
  139. {
  140. this.SetHitSpeed(Vector2.zero);
  141. base.NormalKill();
  142. this.action.AnimChangeState(DaoPaoAction.StateEnum.Die, 1f);
  143. base.Invoke("DieTimeControl", 0.12f);
  144. }
  145. else
  146. {
  147. base.NormalKill();
  148. base.DieTimeControl();
  149. base.StartCoroutine(this.DeathIEnumerator());
  150. }
  151. }
  152. private void SpDieEffect()
  153. {
  154. Transform transform = R.Effect.Generate(221, null, this.center.position, Vector3.zero, default(Vector3), true);
  155. transform.localScale = base.transform.localScale;
  156. Transform transform2 = R.Effect.Generate(222, null, this.center.position, Vector3.zero, default(Vector3), true);
  157. transform2.localScale = base.transform.localScale;
  158. this.action.AnimChangeState(DaoPaoAction.StateEnum.Null, 1f);
  159. string playerAtkName = this.playerAtkName;
  160. if (playerAtkName != null)
  161. {
  162. if (!(playerAtkName == "NewExecute1_2") && !(playerAtkName == "NewExecute2_2") && !(playerAtkName == "NewExecuteAir2_2"))
  163. {
  164. if (playerAtkName == "NewExecuteAir1_2")
  165. {
  166. transform.GetComponent<Rigidbody2D>().velocity = new Vector2(Mathf.Sign(base.transform.localScale.x) * 2f, 15f);
  167. transform2.GetComponent<Rigidbody2D>().velocity = new Vector2(Mathf.Sign(base.transform.localScale.x) * -2f, 15f);
  168. }
  169. }
  170. else
  171. {
  172. transform.GetComponent<Rigidbody2D>().velocity = new Vector2(Mathf.Sign(base.transform.localScale.x) * 2f, 15f);
  173. transform2.GetComponent<Rigidbody2D>().velocity = new Vector2(Mathf.Sign(base.transform.localScale.x) * -2f, -5f);
  174. }
  175. }
  176. }
  177. protected override IEnumerator DeathIEnumerator()
  178. {
  179. bool deadFly = true;
  180. bool deadFall = false;
  181. while (this.eAttr.isDead)
  182. {
  183. if (deadFly && this.eAttr.timeController.GetCurrentSpeed().y <= 0f)
  184. {
  185. deadFly = false;
  186. deadFall = true;
  187. this.action.AnimChangeState(this.flyToFallAnimName, 1f);
  188. }
  189. if (deadFall && this.eAttr.isOnGround)
  190. {
  191. deadFall = false;
  192. this.action.AnimChangeState(this.airDieHitGroundAnimName, 1f);
  193. base.Invoke("RealDie", 0.5f);
  194. }
  195. yield return new WaitForFixedUpdate();
  196. }
  197. yield break;
  198. }
  199. private void RealDie()
  200. {
  201. this.daoPao.GetUp();
  202. }
  203. private DaoPaoAnimEvent daoPao;
  204. private Vector2? atkFollowPos;
  205. private float atkFollowTime;
  206. private float atkFollowEnd;
  207. [SerializeField]
  208. private SkeletonAnimation closeToPlayer;
  209. }